@@ -13,6 +13,7 @@ import {
|
|||||||
PerpOperation,
|
PerpOperation,
|
||||||
PositionDirection,
|
PositionDirection,
|
||||||
ZERO,
|
ZERO,
|
||||||
|
calculateBidAskPrice,
|
||||||
getLimitPrice,
|
getLimitPrice,
|
||||||
isOperationPaused,
|
isOperationPaused,
|
||||||
isVariant,
|
isVariant,
|
||||||
@@ -39,7 +40,7 @@ export type wsMarketArgs = {
|
|||||||
numVammOrders?: number;
|
numVammOrders?: number;
|
||||||
fallbackL2Generators?: L2OrderBookGenerator[];
|
fallbackL2Generators?: L2OrderBookGenerator[];
|
||||||
updateOnChange?: boolean;
|
updateOnChange?: boolean;
|
||||||
tickSize?: BN;
|
tickSize: BN;
|
||||||
};
|
};
|
||||||
|
|
||||||
require('dotenv').config();
|
require('dotenv').config();
|
||||||
@@ -162,13 +163,13 @@ export class DLOBSubscriberIO extends DLOBSubscriber {
|
|||||||
: this.driftClient.getOracleDataForSpotMarket(
|
: this.driftClient.getOracleDataForSpotMarket(
|
||||||
marketArgs.marketIndex
|
marketArgs.marketIndex
|
||||||
);
|
);
|
||||||
const bestBid = dlob.getBestBid(
|
const bestDlobBid = dlob.getBestBid(
|
||||||
marketArgs.marketIndex,
|
marketArgs.marketIndex,
|
||||||
this.slotSource.getSlot(),
|
this.slotSource.getSlot(),
|
||||||
marketArgs.marketType,
|
marketArgs.marketType,
|
||||||
oraclePriceData
|
oraclePriceData
|
||||||
);
|
);
|
||||||
const bestAsk = dlob.getBestAsk(
|
const bestDlobAsk = dlob.getBestAsk(
|
||||||
marketArgs.marketIndex,
|
marketArgs.marketIndex,
|
||||||
this.slotSource.getSlot(),
|
this.slotSource.getSlot(),
|
||||||
marketArgs.marketType,
|
marketArgs.marketType,
|
||||||
@@ -179,6 +180,21 @@ export class DLOBSubscriberIO extends DLOBSubscriber {
|
|||||||
? 'perp'
|
? 'perp'
|
||||||
: 'spot';
|
: 'spot';
|
||||||
|
|
||||||
|
let bestBid = bestDlobBid;
|
||||||
|
let bestAsk = bestDlobAsk;
|
||||||
|
if (marketType === 'perp') {
|
||||||
|
const [bestVammBid, bestVammAsk] = calculateBidAskPrice(
|
||||||
|
this.driftClient.getPerpMarketAccount(marketArgs.marketIndex).amm,
|
||||||
|
oraclePriceData,
|
||||||
|
true
|
||||||
|
);
|
||||||
|
|
||||||
|
bestBid =
|
||||||
|
bestBid && bestBid.gt(bestVammBid) ? bestBid : bestVammBid;
|
||||||
|
bestAsk =
|
||||||
|
bestAsk && bestAsk.lt(bestVammAsk) ? bestAsk : bestVammAsk;
|
||||||
|
}
|
||||||
|
|
||||||
const mms = await this.indicativeQuotesRedisClient.smembers(
|
const mms = await this.indicativeQuotesRedisClient.smembers(
|
||||||
`market_mms_${marketType}_${marketArgs.marketIndex}`
|
`market_mms_${marketType}_${marketArgs.marketIndex}`
|
||||||
);
|
);
|
||||||
@@ -228,19 +244,18 @@ export class DLOBSubscriberIO extends DLOBSubscriber {
|
|||||||
|
|
||||||
if (quote['bid_size'] && quote['bid_price'] != null) {
|
if (quote['bid_size'] && quote['bid_price'] != null) {
|
||||||
// Sanity check bid price and size
|
// Sanity check bid price and size
|
||||||
const indicativeBid: Order = Object.assign(
|
let indicativeBid: Order = Object.assign(
|
||||||
{},
|
{},
|
||||||
indicativeBaseOrder,
|
indicativeBaseOrder,
|
||||||
{
|
{
|
||||||
orderId: indicativeOrderId,
|
orderId: indicativeOrderId,
|
||||||
|
baseAssetAmount: new BN(quote['bid_size']),
|
||||||
oraclePriceOffset: quote['is_oracle_offset']
|
oraclePriceOffset: quote['is_oracle_offset']
|
||||||
? quote['bid_price']
|
? quote['bid_price']
|
||||||
: 0,
|
: 0,
|
||||||
price: quote['is_oracle_offset']
|
price: quote['is_oracle_offset']
|
||||||
? 0
|
? 0
|
||||||
: new BN(quote['bid_price']),
|
: new BN(quote['bid_price']),
|
||||||
baseAssetAmount: new BN(quote['bid_size']),
|
|
||||||
direction: PositionDirection.LONG,
|
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
const limitPrice = getLimitPrice(
|
const limitPrice = getLimitPrice(
|
||||||
@@ -248,7 +263,12 @@ export class DLOBSubscriberIO extends DLOBSubscriber {
|
|||||||
oraclePriceData,
|
oraclePriceData,
|
||||||
this.slotSource.getSlot()
|
this.slotSource.getSlot()
|
||||||
);
|
);
|
||||||
if (limitPrice.lte(bestBid)) {
|
if (bestBid && limitPrice.gt(bestBid)) {
|
||||||
|
indicativeBid = Object.assign({}, indicativeBid, {
|
||||||
|
price: bestBid,
|
||||||
|
oraclePriceOffset: 0,
|
||||||
|
});
|
||||||
|
}
|
||||||
this.dlob.insertOrder(
|
this.dlob.insertOrder(
|
||||||
indicativeBid,
|
indicativeBid,
|
||||||
INDICATIVE_QUOTES_PUBKEY,
|
INDICATIVE_QUOTES_PUBKEY,
|
||||||
@@ -257,9 +277,8 @@ export class DLOBSubscriberIO extends DLOBSubscriber {
|
|||||||
);
|
);
|
||||||
indicativeOrderId += 1;
|
indicativeOrderId += 1;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
if (quote['ask_size'] && quote['ask_price'] != null) {
|
if (quote['ask_size'] && quote['ask_price'] != null) {
|
||||||
const indicativeAsk: Order = Object.assign(
|
let indicativeAsk: Order = Object.assign(
|
||||||
{},
|
{},
|
||||||
indicativeBaseOrder,
|
indicativeBaseOrder,
|
||||||
{
|
{
|
||||||
@@ -279,7 +298,12 @@ export class DLOBSubscriberIO extends DLOBSubscriber {
|
|||||||
oraclePriceData,
|
oraclePriceData,
|
||||||
this.slotSource.getSlot()
|
this.slotSource.getSlot()
|
||||||
);
|
);
|
||||||
if (limitPrice.gte(bestAsk)) {
|
if (bestAsk && limitPrice.lt(bestAsk)) {
|
||||||
|
indicativeAsk = Object.assign({}, indicativeAsk, {
|
||||||
|
price: bestAsk,
|
||||||
|
oraclePriceOffset: 0,
|
||||||
|
});
|
||||||
|
}
|
||||||
this.dlob.insertOrder(
|
this.dlob.insertOrder(
|
||||||
indicativeAsk,
|
indicativeAsk,
|
||||||
INDICATIVE_QUOTES_PUBKEY,
|
INDICATIVE_QUOTES_PUBKEY,
|
||||||
@@ -290,7 +314,6 @@ export class DLOBSubscriberIO extends DLOBSubscriber {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.log('skipping mmQuote: ', error);
|
console.log('skipping mmQuote: ', error);
|
||||||
}
|
}
|
||||||
@@ -419,9 +442,6 @@ export class DLOBSubscriberIO extends DLOBSubscriber {
|
|||||||
lastMarketSlotAndTime &&
|
lastMarketSlotAndTime &&
|
||||||
l2Formatted['marketSlot'] !== lastMarketSlotAndTime.slot
|
l2Formatted['marketSlot'] !== lastMarketSlotAndTime.slot
|
||||||
) {
|
) {
|
||||||
logger.warn(
|
|
||||||
`Updating market slot for ${marketArgs.marketName} from ${lastMarketSlotAndTime.slot} -> ${l2Formatted['marketSlot']}`
|
|
||||||
);
|
|
||||||
this.lastMarketSlotMap
|
this.lastMarketSlotMap
|
||||||
.get(marketArgs.marketType)
|
.get(marketArgs.marketType)
|
||||||
.set(marketArgs.marketIndex, {
|
.set(marketArgs.marketIndex, {
|
||||||
|
|||||||
Reference in New Issue
Block a user