From 6522990333754e1ff8e72cb3b137c502dca6f541 Mon Sep 17 00:00:00 2001 From: Jack Waller Date: Tue, 10 Jun 2025 17:08:27 +1000 Subject: [PATCH 01/28] chore: reduce number of levels sent to UI --- src/dlob-subscriber/DLOBSubscriberIO.ts | 32 + src/publishers/dlobPublisher.ts | 8 +- src/templates/full.html | 787 ++++++++++++++++++++++++ src/utils/utils.ts | 50 ++ src/wsConnectionManager.ts | 7 +- 5 files changed, 879 insertions(+), 5 deletions(-) create mode 100644 src/templates/full.html diff --git a/src/dlob-subscriber/DLOBSubscriberIO.ts b/src/dlob-subscriber/DLOBSubscriberIO.ts index 5acbc7a..0287d78 100644 --- a/src/dlob-subscriber/DLOBSubscriberIO.ts +++ b/src/dlob-subscriber/DLOBSubscriberIO.ts @@ -1,14 +1,17 @@ import { BN, + BigNum, DLOBSubscriber, DLOBSubscriptionConfig, DriftEnv, L2OrderBookGenerator, MarketType, + ONE, Order, OrderStatus, OrderTriggerCondition, OrderType, + PRICE_PRECISION, PerpOperation, PositionDirection, ZERO, @@ -21,6 +24,7 @@ import { SubscriberLookup, addMarketSlotToResponse, addOracletoResponse, + aggregatePrices, l2WithBNToStrings, parsePositiveIntArray, } from '../utils/utils'; @@ -35,10 +39,12 @@ type wsMarketArgs = { numVammOrders?: number; fallbackL2Generators?: L2OrderBookGenerator[]; updateOnChange?: boolean; + tickSize?: BN }; require('dotenv').config(); +export const GROUPING_OPTIONS = [1, 10, 100, 500, 1000]; const PERP_MAKRET_STALENESS_THRESHOLD = 30 * 60 * 1000; const SPOT_MAKRET_STALENESS_THRESHOLD = 60 * 60 * 1000; const STALE_ORACLE_REMOVE_VAMM_THRESHOLD = 160; @@ -114,6 +120,7 @@ export class DLOBSubscriberIO extends DLOBSubscriber { includeVamm, updateOnChange: false, fallbackL2Generators: [], + tickSize: perpMarket?.amm?.orderTickSize ?? ONE }); } for (const market of config.spotMarketInfos) { @@ -128,6 +135,7 @@ export class DLOBSubscriberIO extends DLOBSubscriber { config.spotMarketSubscribers[market.marketIndex].phoenix, config.spotMarketSubscribers[market.marketIndex].openbook, ].filter((a) => !!a), + tickSize: config.spotMarketSubscribers[market.marketIndex].tickSize ?? ONE }); } } @@ -391,6 +399,30 @@ export class DLOBSubscriberIO extends DLOBSubscriber { }`, l2Formatted_depth100 ); + + GROUPING_OPTIONS.forEach(group => { + const pricePrecision = BigNum.from(group).mul(marketArgs.tickSize).toNum() + const aggregatedBids = aggregatePrices(l2Formatted.bids, 'bid', pricePrecision) + .sort((a, b) => b[0] - a[0]) + .slice(0, 20) + + const aggregatedAsks = aggregatePrices(l2Formatted.asks, 'ask', pricePrecision) + .sort((a, b) => a[0] - b[0]) + .slice(0, 20) + + const l2Formatted_grouped20 = Object.assign({}, l2Formatted, { + bids: aggregatedBids, + asks: aggregatedAsks, + }); + + this.redisClient.publish( + `${clientPrefix}orderbook_${marketType}_${marketArgs.marketIndex}_grouped_${group}${ + this.indicativeQuotesRedisClient ? '_indicative' : '' + }`, + l2Formatted_grouped20 + ); + }) + if (!this.indicativeQuotesRedisClient) { const bids = this.dlob diff --git a/src/publishers/dlobPublisher.ts b/src/publishers/dlobPublisher.ts index 2432be0..694b457 100644 --- a/src/publishers/dlobPublisher.ts +++ b/src/publishers/dlobPublisher.ts @@ -20,6 +20,7 @@ import { PhoenixSubscriber, MarketType, OraclePriceData, + ONE, } from '@drift-labs/sdk'; import { RedisClient, RedisClientPrefix } from '@drift/common/clients'; @@ -114,10 +115,7 @@ const KILLSWITCH_SLOT_DIFF_THRESHOLD = parseInt(process.env.KILLSWITCH_SLOT_DIFF_THRESHOLD) || 200; // comma separated list of perp market indexes to load: i.e. 0,1,2,3 -const PERP_MARKETS_TO_LOAD = - process.env.PERP_MARKETS_TO_LOAD !== undefined - ? parsePositiveIntArray(process.env.PERP_MARKETS_TO_LOAD) - : undefined; +const PERP_MARKETS_TO_LOAD = [0] // comma separated list of spot market indexes to load: i.e. 0,1,2,3 const SPOT_MARKETS_TO_LOAD = @@ -299,6 +297,8 @@ const initializeAllMarketSubscribers = async (driftClient: DriftClient) => { } } } + + markets[market.marketIndex].tickSize = market?.orderTickSize ?? ONE } return markets; diff --git a/src/templates/full.html b/src/templates/full.html new file mode 100644 index 0000000..ae8c50c --- /dev/null +++ b/src/templates/full.html @@ -0,0 +1,787 @@ + + + + + + Drift Orderbook (full) + + + + + +
Disconnected
+ +
+
+
Bids
+
+ Price + Size + Total +
+
+
+
+
Asks
+
+ Price + Size + Total +
+
+
+
+ +
+
+ Connection Log + Show Log +
+
+
+ + + + diff --git a/src/utils/utils.ts b/src/utils/utils.ts index 329a95c..b80257b 100644 --- a/src/utils/utils.ts +++ b/src/utils/utils.ts @@ -1,6 +1,8 @@ import { + BN, DriftClient, DriftEnv, + L2Level, L2OrderBook, L3OrderBook, MarketType, @@ -171,6 +173,53 @@ export const addMarketSlotToResponse = ( response['marketSlot'] = marketSlot; }; +export function aggregatePrices(entries, side, pricePrecision) { + const isAsk = side === 'ask'; + const result = new Map(); + + entries.forEach((entry) => { + const price = parseFloat(entry.price); + const data = { + size: parseFloat(entry.size), + sources: entry.sources || {} + }; + + let bucketPrice, displayPrice; + if (isAsk) { + displayPrice = Math.ceil(price / pricePrecision) * pricePrecision; + bucketPrice = displayPrice; + } else { + displayPrice = Math.floor(price / pricePrecision) * pricePrecision; + bucketPrice = displayPrice; + } + + const bucketKey = Math.round(bucketPrice); + + if (!result.has(bucketKey)) { + result.set(bucketKey, { + size: 0, + price: displayPrice, + sources: {}, + }); + } + + const bucketData = result.get(bucketKey); + bucketData.size += data.size; + + if (data.sources) { + Object.entries(data.sources).forEach(([sourceKey, sourceSize]: [string, string]) => { + if (!bucketData.sources[sourceKey]) { + bucketData.sources[sourceKey] = 0; + } + bucketData.sources[sourceKey] += parseFloat(sourceSize); + }); + } + + }); + + return Array.from(result.values()); +} + /** * Takes in a req.query like: `{ * marketName: 'SOL-PERP,BTC-PERP,ETH-PERP', @@ -484,6 +533,7 @@ export type SubscriberLookup = { phoenix?: PhoenixSubscriber; serum?: SerumSubscriber; openbook?: OpenbookV2Subscriber; + tickSize?: BN; }; }; diff --git a/src/wsConnectionManager.ts b/src/wsConnectionManager.ts index 39bf659..9fcb521 100644 --- a/src/wsConnectionManager.ts +++ b/src/wsConnectionManager.ts @@ -7,6 +7,7 @@ import { sleep, selectMostRecentBySlot } from './utils/utils'; import { register, Gauge, Counter } from 'prom-client'; import { DriftEnv, PerpMarkets, SpotMarkets } from '@drift-labs/sdk'; import { RedisClient, RedisClientPrefix } from '@drift/common/clients'; +import { GROUPING_OPTIONS } from './dlob-subscriber/DLOBSubscriberIO'; // Set up env constants require('dotenv').config(); @@ -95,8 +96,12 @@ const getRedisChannelFromMessage = (message: any): string => { return `trades_${marketType}_${marketIndex}`; case 'orderbook': return `orderbook_${marketType}_${marketIndex}`; - case 'orderbook_indicative': + case 'orderbook_indicative': { + if (message.grouping && GROUPING_OPTIONS.includes(parseInt(message.grouping))) { + return `orderbook_${marketType}_${marketIndex}_grouped_${message.grouping}_indicative`; + } return `orderbook_${marketType}_${marketIndex}_indicative`; + } case 'priorityfees': return `priorityFees_${marketType}_${marketIndex}`; case undefined: From a9bdf07cfa0e5406d6a02cae87c052260652b515 Mon Sep 17 00:00:00 2001 From: Jack Waller Date: Tue, 10 Jun 2025 17:09:08 +1000 Subject: [PATCH 02/28] chore: remove testing --- src/publishers/dlobPublisher.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/publishers/dlobPublisher.ts b/src/publishers/dlobPublisher.ts index 694b457..d444350 100644 --- a/src/publishers/dlobPublisher.ts +++ b/src/publishers/dlobPublisher.ts @@ -115,7 +115,10 @@ const KILLSWITCH_SLOT_DIFF_THRESHOLD = parseInt(process.env.KILLSWITCH_SLOT_DIFF_THRESHOLD) || 200; // comma separated list of perp market indexes to load: i.e. 0,1,2,3 -const PERP_MARKETS_TO_LOAD = [0] +const PERP_MARKETS_TO_LOAD = + process.env.PERP_MARKETS_TO_LOAD !== undefined + ? parsePositiveIntArray(process.env.PERP_MARKETS_TO_LOAD) + : undefined; // comma separated list of spot market indexes to load: i.e. 0,1,2,3 const SPOT_MARKETS_TO_LOAD = From acc695052d78af35136bb07a50e64290ac896703 Mon Sep 17 00:00:00 2001 From: Jack Waller Date: Wed, 11 Jun 2025 10:08:58 +1000 Subject: [PATCH 03/28] chore: use previous groupings for calc --- src/dlob-subscriber/DLOBSubscriberIO.ts | 43 ++++-------- src/utils/utils.ts | 92 ++++++++++++++++++++++--- src/wsConnectionManager.ts | 3 +- 3 files changed, 99 insertions(+), 39 deletions(-) diff --git a/src/dlob-subscriber/DLOBSubscriberIO.ts b/src/dlob-subscriber/DLOBSubscriberIO.ts index 0287d78..455da7c 100644 --- a/src/dlob-subscriber/DLOBSubscriberIO.ts +++ b/src/dlob-subscriber/DLOBSubscriberIO.ts @@ -24,13 +24,13 @@ import { SubscriberLookup, addMarketSlotToResponse, addOracletoResponse, - aggregatePrices, l2WithBNToStrings, parsePositiveIntArray, + publishGroupings, } from '../utils/utils'; import { setHealthStatus, HEALTH_STATUS } from '../core/metrics'; -type wsMarketArgs = { +export type wsMarketArgs = { marketIndex: number; marketType: MarketType; marketName: string; @@ -39,12 +39,11 @@ type wsMarketArgs = { numVammOrders?: number; fallbackL2Generators?: L2OrderBookGenerator[]; updateOnChange?: boolean; - tickSize?: BN + tickSize?: BN; }; require('dotenv').config(); -export const GROUPING_OPTIONS = [1, 10, 100, 500, 1000]; const PERP_MAKRET_STALENESS_THRESHOLD = 30 * 60 * 1000; const SPOT_MAKRET_STALENESS_THRESHOLD = 60 * 60 * 1000; const STALE_ORACLE_REMOVE_VAMM_THRESHOLD = 160; @@ -120,7 +119,7 @@ export class DLOBSubscriberIO extends DLOBSubscriber { includeVamm, updateOnChange: false, fallbackL2Generators: [], - tickSize: perpMarket?.amm?.orderTickSize ?? ONE + tickSize: perpMarket?.amm?.orderTickSize ?? ONE, }); } for (const market of config.spotMarketInfos) { @@ -135,7 +134,8 @@ export class DLOBSubscriberIO extends DLOBSubscriber { config.spotMarketSubscribers[market.marketIndex].phoenix, config.spotMarketSubscribers[market.marketIndex].openbook, ].filter((a) => !!a), - tickSize: config.spotMarketSubscribers[market.marketIndex].tickSize ?? ONE + tickSize: + config.spotMarketSubscribers[market.marketIndex].tickSize ?? ONE, }); } } @@ -399,30 +399,15 @@ export class DLOBSubscriberIO extends DLOBSubscriber { }`, l2Formatted_depth100 ); - - GROUPING_OPTIONS.forEach(group => { - const pricePrecision = BigNum.from(group).mul(marketArgs.tickSize).toNum() - const aggregatedBids = aggregatePrices(l2Formatted.bids, 'bid', pricePrecision) - .sort((a, b) => b[0] - a[0]) - .slice(0, 20) - - const aggregatedAsks = aggregatePrices(l2Formatted.asks, 'ask', pricePrecision) - .sort((a, b) => a[0] - b[0]) - .slice(0, 20) - - const l2Formatted_grouped20 = Object.assign({}, l2Formatted, { - bids: aggregatedBids, - asks: aggregatedAsks, - }); - - this.redisClient.publish( - `${clientPrefix}orderbook_${marketType}_${marketArgs.marketIndex}_grouped_${group}${ - this.indicativeQuotesRedisClient ? '_indicative' : '' - }`, - l2Formatted_grouped20 - ); - }) + publishGroupings( + l2Formatted, + marketArgs, + this.redisClient, + clientPrefix, + marketType, + this.indicativeQuotesRedisClient + ); if (!this.indicativeQuotesRedisClient) { const bids = this.dlob diff --git a/src/utils/utils.ts b/src/utils/utils.ts index b80257b..1257e95 100644 --- a/src/utils/utils.ts +++ b/src/utils/utils.ts @@ -1,8 +1,8 @@ import { BN, + BigNum, DriftClient, DriftEnv, - L2Level, L2OrderBook, L3OrderBook, MarketType, @@ -21,6 +21,16 @@ import { logger } from './logger'; import { NextFunction, Request, Response } from 'express'; import FEATURE_FLAGS from './featureFlags'; import { Connection } from '@solana/web3.js'; +import { wsMarketArgs } from 'src/dlob-subscriber/DLOBSubscriberIO'; + +export const GROUPING_OPTIONS = [1, 10, 100, 500, 1000]; +export const GROUPING_DEPENDENCIES = { + 1: null, + 10: 1, + 100: 10, + 500: 100, + 1000: 100, +}; export const l2WithBNToStrings = (l2: L2OrderBook): any => { for (const key of Object.keys(l2)) { @@ -181,7 +191,7 @@ export function aggregatePrices(entries, side, pricePrecision) { const price = parseFloat(entry.price); const data = { size: parseFloat(entry.size), - sources: entry.sources || {} + sources: entry.sources || {}, }; let bucketPrice, displayPrice; @@ -207,19 +217,85 @@ export function aggregatePrices(entries, side, pricePrecision) { bucketData.size += data.size; if (data.sources) { - Object.entries(data.sources).forEach(([sourceKey, sourceSize]: [string, string]) => { - if (!bucketData.sources[sourceKey]) { - bucketData.sources[sourceKey] = 0; + Object.entries(data.sources).forEach( + ([sourceKey, sourceSize]: [string, string]) => { + if (!bucketData.sources[sourceKey]) { + bucketData.sources[sourceKey] = 0; + } + bucketData.sources[sourceKey] += parseFloat(sourceSize); } - bucketData.sources[sourceKey] += parseFloat(sourceSize); - }); + ); } - }); return Array.from(result.values()); } +export function publishGroupings( + l2Formatted, + marketArgs: wsMarketArgs, + redisClient: RedisClient, + clientPrefix: string, + marketType: string, + indicativeQuotesRedisClient: RedisClient +) { + const groupingResults = new Map(); + + GROUPING_OPTIONS.forEach((group) => { + const pricePrecision = BigNum.from(group).mul(marketArgs.tickSize).toNum(); + const dependency = GROUPING_DEPENDENCIES[group]; + + let fullAggregatedBids, fullAggregatedAsks; + + if (dependency && groupingResults.has(dependency)) { + const previousResults = groupingResults.get(dependency); + + fullAggregatedBids = aggregatePrices( + previousResults.bids, + 'bid', + pricePrecision + ).sort((a, b) => b[0] - a[0]); + + fullAggregatedAsks = aggregatePrices( + previousResults.asks, + 'ask', + pricePrecision + ).sort((a, b) => a[0] - b[0]); + } else { + fullAggregatedBids = aggregatePrices( + l2Formatted.bids, + 'bid', + pricePrecision + ).sort((a, b) => b[0] - a[0]); + + fullAggregatedAsks = aggregatePrices( + l2Formatted.asks, + 'ask', + pricePrecision + ).sort((a, b) => a[0] - b[0]); + } + + groupingResults.set(group, { + bids: fullAggregatedBids, + asks: fullAggregatedAsks, + }); + + const aggregatedBids = fullAggregatedBids.slice(0, 20); + const aggregatedAsks = fullAggregatedAsks.slice(0, 20); + const l2Formatted_grouped20 = Object.assign({}, l2Formatted, { + bids: aggregatedBids, + asks: aggregatedAsks, + }); + + redisClient.publish( + `${clientPrefix}orderbook_${marketType}_${ + marketArgs.marketIndex + }_grouped_${group}${indicativeQuotesRedisClient ? '_indicative' : ''}`, + l2Formatted_grouped20 + ); + }); +} + /** * Takes in a req.query like: `{ * marketName: 'SOL-PERP,BTC-PERP,ETH-PERP', diff --git a/src/wsConnectionManager.ts b/src/wsConnectionManager.ts index 9fcb521..f37b7a9 100644 --- a/src/wsConnectionManager.ts +++ b/src/wsConnectionManager.ts @@ -3,11 +3,10 @@ import express from 'express'; import * as http from 'http'; import compression from 'compression'; import { WebSocket, WebSocketServer } from 'ws'; -import { sleep, selectMostRecentBySlot } from './utils/utils'; +import { sleep, selectMostRecentBySlot, GROUPING_OPTIONS } from './utils/utils'; import { register, Gauge, Counter } from 'prom-client'; import { DriftEnv, PerpMarkets, SpotMarkets } from '@drift-labs/sdk'; import { RedisClient, RedisClientPrefix } from '@drift/common/clients'; -import { GROUPING_OPTIONS } from './dlob-subscriber/DLOBSubscriberIO'; // Set up env constants require('dotenv').config(); From d0dc1c3a4c334dd7bab737798a46b800ef0cb2f7 Mon Sep 17 00:00:00 2001 From: GitHub Actions <41898282+github-actions[bot]@users.noreply.github.com> Date: Mon, 30 Jun 2025 09:55:12 +0000 Subject: [PATCH 04/28] Bumping drift-common to cbc673a62a00dd66d1ccf980b9f74832da462eed --- drift-common | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drift-common b/drift-common index 7917618..cbc673a 160000 --- a/drift-common +++ b/drift-common @@ -1 +1 @@ -Subproject commit 7917618ae6a03e37d58f2084aeb5698bd0788250 +Subproject commit cbc673a62a00dd66d1ccf980b9f74832da462eed From 040811d2015284e16f161b3a4296b36a5b2732bd Mon Sep 17 00:00:00 2001 From: GitHub Actions <41898282+github-actions[bot]@users.noreply.github.com> Date: Mon, 30 Jun 2025 16:54:42 +0000 Subject: [PATCH 05/28] Bumping drift-common to 5aa54e7a4ab9c608678f9e8753180978366cf85c --- drift-common | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drift-common b/drift-common index cbc673a..5aa54e7 160000 --- a/drift-common +++ b/drift-common @@ -1 +1 @@ -Subproject commit cbc673a62a00dd66d1ccf980b9f74832da462eed +Subproject commit 5aa54e7a4ab9c608678f9e8753180978366cf85c From 6e113b2b0ef2d0cfba31deed8ee89aa56edd86e2 Mon Sep 17 00:00:00 2001 From: GitHub Actions <41898282+github-actions[bot]@users.noreply.github.com> Date: Mon, 30 Jun 2025 23:32:34 +0000 Subject: [PATCH 06/28] Bumping drift-common to bfe834bf7646f6f31c3fddc76827341bc3b94a26 --- drift-common | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drift-common b/drift-common index 5aa54e7..bfe834b 160000 --- a/drift-common +++ b/drift-common @@ -1 +1 @@ -Subproject commit 5aa54e7a4ab9c608678f9e8753180978366cf85c +Subproject commit bfe834bf7646f6f31c3fddc76827341bc3b94a26 From 04f4cefbb9b7a95fdece05377070c34afa30b4d7 Mon Sep 17 00:00:00 2001 From: GitHub Actions <41898282+github-actions[bot]@users.noreply.github.com> Date: Tue, 1 Jul 2025 20:26:08 +0000 Subject: [PATCH 07/28] Bumping drift-common to 1ab548a6e115fdffc2161b52884d66de0a83da78 --- drift-common | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drift-common b/drift-common index bfe834b..40a00a9 160000 --- a/drift-common +++ b/drift-common @@ -1 +1 @@ -Subproject commit bfe834bf7646f6f31c3fddc76827341bc3b94a26 +Subproject commit 40a00a9ffe1df3f976e123766f5aff2eb15c4f16 From aa73e79b857367389c56463e001f349b512e5dbe Mon Sep 17 00:00:00 2001 From: GitHub Actions <41898282+github-actions[bot]@users.noreply.github.com> Date: Tue, 1 Jul 2025 21:50:43 +0000 Subject: [PATCH 08/28] Bumping drift-common to 7d8d8660001b5c2bd04b9a24b91cf0799ac210f8 --- drift-common | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drift-common b/drift-common index 40a00a9..7d8d866 160000 --- a/drift-common +++ b/drift-common @@ -1 +1 @@ -Subproject commit 40a00a9ffe1df3f976e123766f5aff2eb15c4f16 +Subproject commit 7d8d8660001b5c2bd04b9a24b91cf0799ac210f8 From 0b066655e3c3aa8470f0d56991a753d5482999c6 Mon Sep 17 00:00:00 2001 From: GitHub Actions <41898282+github-actions[bot]@users.noreply.github.com> Date: Wed, 2 Jul 2025 12:26:36 +0000 Subject: [PATCH 09/28] Bumping drift-common to a531d30abbc9301390e4b4a2b1a5d89811152f75 --- drift-common | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drift-common b/drift-common index 7d8d866..a531d30 160000 --- a/drift-common +++ b/drift-common @@ -1 +1 @@ -Subproject commit 7d8d8660001b5c2bd04b9a24b91cf0799ac210f8 +Subproject commit a531d30abbc9301390e4b4a2b1a5d89811152f75 From 49db04242ac918c8d7026f7077bb0545662a8621 Mon Sep 17 00:00:00 2001 From: GitHub Actions <41898282+github-actions[bot]@users.noreply.github.com> Date: Wed, 2 Jul 2025 12:33:26 +0000 Subject: [PATCH 10/28] Bumping drift-common to a298099a054d81cf27e63d42de117d693fee635e --- drift-common | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drift-common b/drift-common index a531d30..a298099 160000 --- a/drift-common +++ b/drift-common @@ -1 +1 @@ -Subproject commit a531d30abbc9301390e4b4a2b1a5d89811152f75 +Subproject commit a298099a054d81cf27e63d42de117d693fee635e From a7ee0a67579a503d952cd2e117765d0db0cc5217 Mon Sep 17 00:00:00 2001 From: GitHub Actions <41898282+github-actions[bot]@users.noreply.github.com> Date: Thu, 3 Jul 2025 09:44:00 +0000 Subject: [PATCH 11/28] Bumping drift-common to df196347450cf48ca6d18703dc9cbd08f048a27a --- drift-common | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drift-common b/drift-common index a298099..df19634 160000 --- a/drift-common +++ b/drift-common @@ -1 +1 @@ -Subproject commit a298099a054d81cf27e63d42de117d693fee635e +Subproject commit df196347450cf48ca6d18703dc9cbd08f048a27a From 1a5fff27f540c8dab21d2486a6096071ecf5c1a5 Mon Sep 17 00:00:00 2001 From: GitHub Actions <41898282+github-actions[bot]@users.noreply.github.com> Date: Thu, 3 Jul 2025 15:30:26 +0000 Subject: [PATCH 12/28] Bumping drift-common to 43cca01b9b1ab1866395d77d924b0660905fd940 --- drift-common | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drift-common b/drift-common index df19634..43cca01 160000 --- a/drift-common +++ b/drift-common @@ -1 +1 @@ -Subproject commit df196347450cf48ca6d18703dc9cbd08f048a27a +Subproject commit 43cca01b9b1ab1866395d77d924b0660905fd940 From df5579d81ce5dad98c1a523e04b6efee14aeecf7 Mon Sep 17 00:00:00 2001 From: GitHub Actions <41898282+github-actions[bot]@users.noreply.github.com> Date: Thu, 3 Jul 2025 15:45:11 +0000 Subject: [PATCH 13/28] Bumping drift-common to 08dccc04aa60ca577e5ec3ffe0a7acc378a6e340 --- drift-common | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drift-common b/drift-common index 43cca01..08dccc0 160000 --- a/drift-common +++ b/drift-common @@ -1 +1 @@ -Subproject commit 43cca01b9b1ab1866395d77d924b0660905fd940 +Subproject commit 08dccc04aa60ca577e5ec3ffe0a7acc378a6e340 From fd94a33e66cffee9b15bd4d69b3de63b8f75f583 Mon Sep 17 00:00:00 2001 From: GitHub Actions <41898282+github-actions[bot]@users.noreply.github.com> Date: Thu, 3 Jul 2025 22:50:45 +0000 Subject: [PATCH 14/28] Bumping drift-common to e50e2c48b23007c1ec6176f774374e88946fc1ed --- drift-common | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drift-common b/drift-common index 08dccc0..e50e2c4 160000 --- a/drift-common +++ b/drift-common @@ -1 +1 @@ -Subproject commit 08dccc04aa60ca577e5ec3ffe0a7acc378a6e340 +Subproject commit e50e2c48b23007c1ec6176f774374e88946fc1ed From 9851c8c82d7d0f9936b5b520de1b91303ba44095 Mon Sep 17 00:00:00 2001 From: GitHub Actions <41898282+github-actions[bot]@users.noreply.github.com> Date: Fri, 4 Jul 2025 07:26:11 +0000 Subject: [PATCH 15/28] Bumping drift-common to b58b976104d6e6d3c40fbc1b89bb78fd4be4750c --- drift-common | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drift-common b/drift-common index e50e2c4..b58b976 160000 --- a/drift-common +++ b/drift-common @@ -1 +1 @@ -Subproject commit e50e2c48b23007c1ec6176f774374e88946fc1ed +Subproject commit b58b976104d6e6d3c40fbc1b89bb78fd4be4750c From 25f09665c1ebb8e34727fcaabd031500a594862a Mon Sep 17 00:00:00 2001 From: GitHub Actions <41898282+github-actions[bot]@users.noreply.github.com> Date: Fri, 4 Jul 2025 08:32:41 +0000 Subject: [PATCH 16/28] Bumping drift-common to 33cdbd43f33a8433975fde638304c5f410406f3e --- drift-common | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drift-common b/drift-common index b58b976..33cdbd4 160000 --- a/drift-common +++ b/drift-common @@ -1 +1 @@ -Subproject commit b58b976104d6e6d3c40fbc1b89bb78fd4be4750c +Subproject commit 33cdbd43f33a8433975fde638304c5f410406f3e From 0910f73d47e07679e478ef4b52a638e9c25c91c2 Mon Sep 17 00:00:00 2001 From: GitHub Actions <41898282+github-actions[bot]@users.noreply.github.com> Date: Mon, 7 Jul 2025 02:49:50 +0000 Subject: [PATCH 17/28] Bumping drift-common to 804f8d1d395ed848291a695298686620d54ec17d --- drift-common | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drift-common b/drift-common index 33cdbd4..804f8d1 160000 --- a/drift-common +++ b/drift-common @@ -1 +1 @@ -Subproject commit 33cdbd43f33a8433975fde638304c5f410406f3e +Subproject commit 804f8d1d395ed848291a695298686620d54ec17d From c8475a85b3f7b51d19a43107c856bdd637ed2bbe Mon Sep 17 00:00:00 2001 From: GitHub Actions <41898282+github-actions[bot]@users.noreply.github.com> Date: Mon, 7 Jul 2025 22:09:34 +0000 Subject: [PATCH 18/28] Bumping drift-common to b4c0872e276b8f6f66f54e0e87b67faa4e7de42a --- drift-common | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drift-common b/drift-common index 804f8d1..b4c0872 160000 --- a/drift-common +++ b/drift-common @@ -1 +1 @@ -Subproject commit 804f8d1d395ed848291a695298686620d54ec17d +Subproject commit b4c0872e276b8f6f66f54e0e87b67faa4e7de42a From dae168a5b270fa1defcc95d20f72c6f8108440ac Mon Sep 17 00:00:00 2001 From: GitHub Actions <41898282+github-actions[bot]@users.noreply.github.com> Date: Tue, 8 Jul 2025 06:10:38 +0000 Subject: [PATCH 19/28] Bumping drift-common to fe74e3b76468ab2b4b33509110c35adc24b4f3d7 --- drift-common | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drift-common b/drift-common index b4c0872..fe74e3b 160000 --- a/drift-common +++ b/drift-common @@ -1 +1 @@ -Subproject commit b4c0872e276b8f6f66f54e0e87b67faa4e7de42a +Subproject commit fe74e3b76468ab2b4b33509110c35adc24b4f3d7 From 304379ca7e1b2aaa9bc012896a9b2a64b99bdc8b Mon Sep 17 00:00:00 2001 From: GitHub Actions <41898282+github-actions[bot]@users.noreply.github.com> Date: Tue, 8 Jul 2025 06:23:51 +0000 Subject: [PATCH 20/28] Bumping drift-common to 02d1b82e6d487bf3eb8ba9fc5e6cd85241cb1d4b --- drift-common | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drift-common b/drift-common index fe74e3b..02d1b82 160000 --- a/drift-common +++ b/drift-common @@ -1 +1 @@ -Subproject commit fe74e3b76468ab2b4b33509110c35adc24b4f3d7 +Subproject commit 02d1b82e6d487bf3eb8ba9fc5e6cd85241cb1d4b From b18f7e1ab4d9b9c11f79d922f33b1f850551e38b Mon Sep 17 00:00:00 2001 From: GitHub Actions <41898282+github-actions[bot]@users.noreply.github.com> Date: Tue, 8 Jul 2025 11:38:17 +0000 Subject: [PATCH 21/28] Bumping drift-common to 64c5dc124ffccd97c5ea2da0c6463ae24e329785 --- drift-common | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drift-common b/drift-common index 02d1b82..64c5dc1 160000 --- a/drift-common +++ b/drift-common @@ -1 +1 @@ -Subproject commit 02d1b82e6d487bf3eb8ba9fc5e6cd85241cb1d4b +Subproject commit 64c5dc124ffccd97c5ea2da0c6463ae24e329785 From a0e5aa3cc263c972119b20f7e9a72d1a5396dd82 Mon Sep 17 00:00:00 2001 From: GitHub Actions <41898282+github-actions[bot]@users.noreply.github.com> Date: Tue, 8 Jul 2025 20:18:30 +0000 Subject: [PATCH 22/28] Bumping drift-common to 27b54206e2614baff1a46237ce3f50b12708c05c --- drift-common | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drift-common b/drift-common index 64c5dc1..27b5420 160000 --- a/drift-common +++ b/drift-common @@ -1 +1 @@ -Subproject commit 64c5dc124ffccd97c5ea2da0c6463ae24e329785 +Subproject commit 27b54206e2614baff1a46237ce3f50b12708c05c From f0baaf14de86d907bdc803926205fc24407d2b8b Mon Sep 17 00:00:00 2001 From: GitHub Actions <41898282+github-actions[bot]@users.noreply.github.com> Date: Tue, 8 Jul 2025 20:44:52 +0000 Subject: [PATCH 23/28] Bumping drift-common to 9e7156dde93f933b090cb9cb5b56e4c660e1b2d2 --- drift-common | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drift-common b/drift-common index 27b5420..9e7156d 160000 --- a/drift-common +++ b/drift-common @@ -1 +1 @@ -Subproject commit 27b54206e2614baff1a46237ce3f50b12708c05c +Subproject commit 9e7156dde93f933b090cb9cb5b56e4c660e1b2d2 From 8f650fcd667cade3b372c7a83c0b29075e49c7ff Mon Sep 17 00:00:00 2001 From: GitHub Actions <41898282+github-actions[bot]@users.noreply.github.com> Date: Wed, 9 Jul 2025 05:34:16 +0000 Subject: [PATCH 24/28] Bumping drift-common to cabb3ee8cbd2e8d955154cbe5e308fe8b2817c08 --- drift-common | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drift-common b/drift-common index 9e7156d..cabb3ee 160000 --- a/drift-common +++ b/drift-common @@ -1 +1 @@ -Subproject commit 9e7156dde93f933b090cb9cb5b56e4c660e1b2d2 +Subproject commit cabb3ee8cbd2e8d955154cbe5e308fe8b2817c08 From e963cb084be6b85b5a838f7df67f06dca7cff6c9 Mon Sep 17 00:00:00 2001 From: GitHub Actions <41898282+github-actions[bot]@users.noreply.github.com> Date: Wed, 9 Jul 2025 11:04:08 +0000 Subject: [PATCH 25/28] Bumping drift-common to 65616c28fdf30e367116d7f664294d7550faf37a --- drift-common | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drift-common b/drift-common index cabb3ee..65616c2 160000 --- a/drift-common +++ b/drift-common @@ -1 +1 @@ -Subproject commit cabb3ee8cbd2e8d955154cbe5e308fe8b2817c08 +Subproject commit 65616c28fdf30e367116d7f664294d7550faf37a From b673b297050773ede86c2829420b35aedb052287 Mon Sep 17 00:00:00 2001 From: GitHub Actions <41898282+github-actions[bot]@users.noreply.github.com> Date: Wed, 9 Jul 2025 13:30:22 +0000 Subject: [PATCH 26/28] Bumping drift-common to 48378b0dc4adc7d5c907d536a69d9dd088299e9e --- drift-common | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drift-common b/drift-common index 65616c2..48378b0 160000 --- a/drift-common +++ b/drift-common @@ -1 +1 @@ -Subproject commit 65616c28fdf30e367116d7f664294d7550faf37a +Subproject commit 48378b0dc4adc7d5c907d536a69d9dd088299e9e From e7aedb839cce28b1870e7a0008a9bc470b62ac2b Mon Sep 17 00:00:00 2001 From: GitHub Actions <41898282+github-actions[bot]@users.noreply.github.com> Date: Thu, 10 Jul 2025 12:32:43 +0000 Subject: [PATCH 27/28] Bumping drift-common to 91bcf1a17eac80d2ce479be5839bdd87a9d26397 --- drift-common | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drift-common b/drift-common index 48378b0..91bcf1a 160000 --- a/drift-common +++ b/drift-common @@ -1 +1 @@ -Subproject commit 48378b0dc4adc7d5c907d536a69d9dd088299e9e +Subproject commit 91bcf1a17eac80d2ce479be5839bdd87a9d26397 From 4157cd8e5b2e9174ec912693d44260c03b85144c Mon Sep 17 00:00:00 2001 From: moosecat Date: Thu, 10 Jul 2025 10:27:12 -0700 Subject: [PATCH 28/28] 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`;