add market slot to response'

This commit is contained in:
Nour Alharithi
2024-01-18 15:40:53 -08:00
parent 5ec515b178
commit 1d7d8754e8
2 changed files with 23 additions and 1 deletions

View File

@@ -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),

View File

@@ -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',