From 5ec515b178f92306e64700ce7d7bca4db01ffb0d Mon Sep 17 00:00:00 2001 From: Nour Alharithi Date: Thu, 18 Jan 2024 13:52:45 -0800 Subject: [PATCH 1/2] strip slot from dlob diff check --- src/dlob-subscriber/DLOBSubscriberIO.ts | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/dlob-subscriber/DLOBSubscriberIO.ts b/src/dlob-subscriber/DLOBSubscriberIO.ts index a630ada..ee984c9 100644 --- a/src/dlob-subscriber/DLOBSubscriberIO.ts +++ b/src/dlob-subscriber/DLOBSubscriberIO.ts @@ -96,6 +96,10 @@ export class DLOBSubscriberIO extends DLOBSubscriber { const grouping = l2Args.grouping; const { marketName, ...l2FuncArgs } = l2Args; const l2 = this.getL2(l2FuncArgs); + const slot = l2.slot; + if (slot) { + delete l2.slot; + } const marketType = isVariant(l2Args.marketType, 'perp') ? 'perp' : 'spot'; let l2Formatted: any; if (grouping) { @@ -119,6 +123,7 @@ export class DLOBSubscriberIO extends DLOBSubscriber { l2Formatted['marketName'] = marketName?.toUpperCase(); l2Formatted['marketType'] = marketType?.toLowerCase(); l2Formatted['marketIndex'] = l2Args.marketIndex; + l2Formatted['slot'] = slot; addOracletoResponse( l2Formatted, this.driftClient, From 1d7d8754e8970445911471afd10e41d9ca6be2c0 Mon Sep 17 00:00:00 2001 From: Nour Alharithi Date: Thu, 18 Jan 2024 15:40:53 -0800 Subject: [PATCH 2/2] add market slot to response' --- src/dlob-subscriber/DLOBSubscriberIO.ts | 9 ++++++++- src/utils/utils.ts | 15 +++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/src/dlob-subscriber/DLOBSubscriberIO.ts b/src/dlob-subscriber/DLOBSubscriberIO.ts index ee984c9..b67b1b4 100644 --- a/src/dlob-subscriber/DLOBSubscriberIO.ts +++ b/src/dlob-subscriber/DLOBSubscriberIO.ts @@ -10,6 +10,7 @@ import { import { RedisClient } from '../utils/redisClient'; import { SubscriberLookup, + addMarketSlotToResponse, addOracletoResponse, l2WithBNToStrings, } from '../utils/utils'; @@ -130,7 +131,13 @@ export class DLOBSubscriberIO extends DLOBSubscriber { l2Args.marketType, l2Args.marketIndex ); - + addMarketSlotToResponse( + l2Formatted, + this.driftClient, + l2Args.marketType, + l2Args.marketIndex + ); + const l2Formatted_depth100 = Object.assign({}, l2Formatted, { bids: l2Formatted.bids.slice(0, 100), asks: l2Formatted.asks.slice(0, 100), diff --git a/src/utils/utils.ts b/src/utils/utils.ts index d8530ba..831a7fb 100644 --- a/src/utils/utils.ts +++ b/src/utils/utils.ts @@ -132,6 +132,21 @@ export const addOracletoResponse = ( } }; +export const addMarketSlotToResponse = ( + response: L2OrderBook | L3OrderBook, + driftClient: DriftClient, + marketType: MarketType, + marketIndex: number +): void => { + let marketSlot: number; + if (isVariant(marketType, 'perp')) { + marketSlot = driftClient.accountSubscriber.getMarketAccountAndSlot(marketIndex).slot; + } else { + marketSlot = driftClient.accountSubscriber.getSpotMarketAccountAndSlot(marketIndex).slot; + } + response['marketSlot'] = marketSlot; +}; + /** * Takes in a req.query like: `{ * marketName: 'SOL-PERP,BTC-PERP,ETH-PERP',