filter indicative + random prettify (#443)
* filter indicative + random prettify * bug fix * update to filter orders that arent as good as resting orders
This commit is contained in:
@@ -1,6 +1,5 @@
|
|||||||
import {
|
import {
|
||||||
BN,
|
BN,
|
||||||
BigNum,
|
|
||||||
DLOBSubscriber,
|
DLOBSubscriber,
|
||||||
DLOBSubscriptionConfig,
|
DLOBSubscriptionConfig,
|
||||||
DriftEnv,
|
DriftEnv,
|
||||||
@@ -11,10 +10,10 @@ import {
|
|||||||
OrderStatus,
|
OrderStatus,
|
||||||
OrderTriggerCondition,
|
OrderTriggerCondition,
|
||||||
OrderType,
|
OrderType,
|
||||||
PRICE_PRECISION,
|
|
||||||
PerpOperation,
|
PerpOperation,
|
||||||
PositionDirection,
|
PositionDirection,
|
||||||
ZERO,
|
ZERO,
|
||||||
|
getLimitPrice,
|
||||||
isOperationPaused,
|
isOperationPaused,
|
||||||
isVariant,
|
isVariant,
|
||||||
} from '@drift-labs/sdk';
|
} from '@drift-labs/sdk';
|
||||||
@@ -151,10 +150,31 @@ export class DLOBSubscriberIO extends DLOBSubscriber {
|
|||||||
|
|
||||||
override async updateDLOB(): Promise<void> {
|
override async updateDLOB(): Promise<void> {
|
||||||
await super.updateDLOB();
|
await super.updateDLOB();
|
||||||
|
const dlob = this.getDLOB();
|
||||||
let indicativeOrderId = 0;
|
let indicativeOrderId = 0;
|
||||||
for (const marketArgs of this.marketArgs) {
|
for (const marketArgs of this.marketArgs) {
|
||||||
try {
|
try {
|
||||||
if (this.indicativeQuotesRedisClient) {
|
if (this.indicativeQuotesRedisClient) {
|
||||||
|
const oraclePriceData = isVariant(marketArgs.marketType, 'perp')
|
||||||
|
? this.driftClient.getOracleDataForPerpMarket(
|
||||||
|
marketArgs.marketIndex
|
||||||
|
)
|
||||||
|
: this.driftClient.getOracleDataForSpotMarket(
|
||||||
|
marketArgs.marketIndex
|
||||||
|
);
|
||||||
|
const bestBid = dlob.getBestBid(
|
||||||
|
marketArgs.marketIndex,
|
||||||
|
this.slotSource.getSlot(),
|
||||||
|
marketArgs.marketType,
|
||||||
|
oraclePriceData
|
||||||
|
);
|
||||||
|
const bestAsk = dlob.getBestAsk(
|
||||||
|
marketArgs.marketIndex,
|
||||||
|
this.slotSource.getSlot(),
|
||||||
|
marketArgs.marketType,
|
||||||
|
oraclePriceData
|
||||||
|
);
|
||||||
|
|
||||||
const marketType = isVariant(marketArgs.marketType, 'perp')
|
const marketType = isVariant(marketArgs.marketType, 'perp')
|
||||||
? 'perp'
|
? 'perp'
|
||||||
: 'spot';
|
: 'spot';
|
||||||
@@ -208,7 +228,6 @@ 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(
|
const indicativeBid: Order = Object.assign(
|
||||||
{},
|
{},
|
||||||
indicativeBaseOrder,
|
indicativeBaseOrder,
|
||||||
@@ -224,15 +243,21 @@ export class DLOBSubscriberIO extends DLOBSubscriber {
|
|||||||
direction: PositionDirection.LONG,
|
direction: PositionDirection.LONG,
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
this.dlob.insertOrder(
|
const limitPrice = getLimitPrice(
|
||||||
indicativeBid,
|
indicativeBid,
|
||||||
INDICATIVE_QUOTES_PUBKEY,
|
oraclePriceData,
|
||||||
this.slotSource.getSlot(),
|
this.slotSource.getSlot()
|
||||||
false
|
|
||||||
);
|
);
|
||||||
indicativeOrderId += 1;
|
if (limitPrice.lte(bestBid)) {
|
||||||
|
this.dlob.insertOrder(
|
||||||
|
indicativeBid,
|
||||||
|
INDICATIVE_QUOTES_PUBKEY,
|
||||||
|
this.slotSource.getSlot(),
|
||||||
|
false
|
||||||
|
);
|
||||||
|
indicativeOrderId += 1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (quote['ask_size'] && quote['ask_price'] != null) {
|
if (quote['ask_size'] && quote['ask_price'] != null) {
|
||||||
const indicativeAsk: Order = Object.assign(
|
const indicativeAsk: Order = Object.assign(
|
||||||
{},
|
{},
|
||||||
@@ -249,13 +274,20 @@ export class DLOBSubscriberIO extends DLOBSubscriber {
|
|||||||
direction: PositionDirection.SHORT,
|
direction: PositionDirection.SHORT,
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
this.dlob.insertOrder(
|
const limitPrice = getLimitPrice(
|
||||||
indicativeAsk,
|
indicativeAsk,
|
||||||
INDICATIVE_QUOTES_PUBKEY,
|
oraclePriceData,
|
||||||
this.slotSource.getSlot(),
|
this.slotSource.getSlot()
|
||||||
false
|
|
||||||
);
|
);
|
||||||
indicativeOrderId += 1;
|
if (limitPrice.gte(bestAsk)) {
|
||||||
|
this.dlob.insertOrder(
|
||||||
|
indicativeAsk,
|
||||||
|
INDICATIVE_QUOTES_PUBKEY,
|
||||||
|
this.slotSource.getSlot(),
|
||||||
|
false
|
||||||
|
);
|
||||||
|
indicativeOrderId += 1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -303,7 +303,7 @@ const initializeAllMarketSubscribers = async (driftClient: DriftClient) => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
markets[market.marketIndex].tickSize = market?.orderTickSize ?? ONE
|
markets[market.marketIndex].tickSize = market?.orderTickSize ?? ONE;
|
||||||
}
|
}
|
||||||
|
|
||||||
return markets;
|
return markets;
|
||||||
@@ -527,7 +527,7 @@ const main = async () => {
|
|||||||
killSwitchSlotDiffThreshold: KILLSWITCH_SLOT_DIFF_THRESHOLD,
|
killSwitchSlotDiffThreshold: KILLSWITCH_SLOT_DIFF_THRESHOLD,
|
||||||
protectedMakerView: false,
|
protectedMakerView: false,
|
||||||
indicativeQuotesRedisClient: indicativeRedisClient,
|
indicativeQuotesRedisClient: indicativeRedisClient,
|
||||||
enableOffloadQueue
|
enableOffloadQueue,
|
||||||
});
|
});
|
||||||
await dlobSubscriberIndicative.subscribe();
|
await dlobSubscriberIndicative.subscribe();
|
||||||
|
|
||||||
|
|||||||
@@ -96,7 +96,10 @@ const getRedisChannelFromMessage = (message: any): string => {
|
|||||||
case 'orderbook':
|
case 'orderbook':
|
||||||
return `orderbook_${marketType}_${marketIndex}`;
|
return `orderbook_${marketType}_${marketIndex}`;
|
||||||
case 'orderbook_indicative': {
|
case 'orderbook_indicative': {
|
||||||
if (message.grouping && GROUPING_OPTIONS.includes(parseInt(message.grouping))) {
|
if (
|
||||||
|
message.grouping &&
|
||||||
|
GROUPING_OPTIONS.includes(parseInt(message.grouping))
|
||||||
|
) {
|
||||||
return `orderbook_${marketType}_${marketIndex}_grouped_${message.grouping}_indicative`;
|
return `orderbook_${marketType}_${marketIndex}_grouped_${message.grouping}_indicative`;
|
||||||
}
|
}
|
||||||
return `orderbook_${marketType}_${marketIndex}_indicative`;
|
return `orderbook_${marketType}_${marketIndex}_indicative`;
|
||||||
|
|||||||
Reference in New Issue
Block a user