From 4157cd8e5b2e9174ec912693d44260c03b85144c Mon Sep 17 00:00:00 2001 From: moosecat Date: Thu, 10 Jul 2025 10:27:12 -0700 Subject: [PATCH] filter indicative + random prettify (#443) * filter indicative + random prettify * bug fix * update to filter orders that arent as good as resting orders --- src/dlob-subscriber/DLOBSubscriberIO.ts | 60 +++++++++++++++++++------ src/publishers/dlobPublisher.ts | 4 +- src/wsConnectionManager.ts | 5 ++- 3 files changed, 52 insertions(+), 17 deletions(-) diff --git a/src/dlob-subscriber/DLOBSubscriberIO.ts b/src/dlob-subscriber/DLOBSubscriberIO.ts index d692901..db7636b 100644 --- a/src/dlob-subscriber/DLOBSubscriberIO.ts +++ b/src/dlob-subscriber/DLOBSubscriberIO.ts @@ -1,6 +1,5 @@ import { BN, - BigNum, DLOBSubscriber, DLOBSubscriptionConfig, DriftEnv, @@ -11,10 +10,10 @@ import { OrderStatus, OrderTriggerCondition, OrderType, - PRICE_PRECISION, PerpOperation, PositionDirection, ZERO, + getLimitPrice, isOperationPaused, isVariant, } from '@drift-labs/sdk'; @@ -151,10 +150,31 @@ export class DLOBSubscriberIO extends DLOBSubscriber { override async updateDLOB(): Promise { await super.updateDLOB(); + const dlob = this.getDLOB(); let indicativeOrderId = 0; for (const marketArgs of this.marketArgs) { try { 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') ? 'perp' : 'spot'; @@ -208,7 +228,6 @@ export class DLOBSubscriberIO extends DLOBSubscriber { if (quote['bid_size'] && quote['bid_price'] != null) { // Sanity check bid price and size - const indicativeBid: Order = Object.assign( {}, indicativeBaseOrder, @@ -224,15 +243,21 @@ export class DLOBSubscriberIO extends DLOBSubscriber { direction: PositionDirection.LONG, } ); - this.dlob.insertOrder( + const limitPrice = getLimitPrice( indicativeBid, - INDICATIVE_QUOTES_PUBKEY, - this.slotSource.getSlot(), - false + oraclePriceData, + this.slotSource.getSlot() ); - 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) { const indicativeAsk: Order = Object.assign( {}, @@ -249,13 +274,20 @@ export class DLOBSubscriberIO extends DLOBSubscriber { direction: PositionDirection.SHORT, } ); - this.dlob.insertOrder( + const limitPrice = getLimitPrice( indicativeAsk, - INDICATIVE_QUOTES_PUBKEY, - this.slotSource.getSlot(), - false + oraclePriceData, + this.slotSource.getSlot() ); - indicativeOrderId += 1; + if (limitPrice.gte(bestAsk)) { + this.dlob.insertOrder( + indicativeAsk, + INDICATIVE_QUOTES_PUBKEY, + this.slotSource.getSlot(), + false + ); + indicativeOrderId += 1; + } } } } diff --git a/src/publishers/dlobPublisher.ts b/src/publishers/dlobPublisher.ts index 1b5f545..c4e4bc8 100644 --- a/src/publishers/dlobPublisher.ts +++ b/src/publishers/dlobPublisher.ts @@ -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; @@ -527,7 +527,7 @@ const main = async () => { killSwitchSlotDiffThreshold: KILLSWITCH_SLOT_DIFF_THRESHOLD, protectedMakerView: false, indicativeQuotesRedisClient: indicativeRedisClient, - enableOffloadQueue + enableOffloadQueue, }); await dlobSubscriberIndicative.subscribe(); diff --git a/src/wsConnectionManager.ts b/src/wsConnectionManager.ts index f37b7a9..7e63771 100644 --- a/src/wsConnectionManager.ts +++ b/src/wsConnectionManager.ts @@ -96,7 +96,10 @@ const getRedisChannelFromMessage = (message: any): string => { case 'orderbook': return `orderbook_${marketType}_${marketIndex}`; 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}_indicative`;