cache top makers

This commit is contained in:
Nour Alharithi
2024-03-06 11:14:47 -08:00
parent 823581c58d
commit 9c63ffb4a9
2 changed files with 76 additions and 21 deletions

View File

@@ -4,6 +4,7 @@ import {
DLOBSubscriptionConfig,
L2OrderBookGenerator,
MarketType,
PositionDirection,
groupL2,
isVariant,
} from '@drift-labs/sdk';
@@ -248,6 +249,35 @@ export class DLOBSubscriberIO extends DLOBSubscriber {
`last_update_orderbook_${marketType}_${marketArgs.marketIndex}_depth_5`,
JSON.stringify(l2Formatted_depth5)
);
const oraclePriceData =
marketType === 'spot'
? this.driftClient.getOracleDataForSpotMarket(marketArgs.marketIndex)
: this.driftClient.getOracleDataForPerpMarket(marketArgs.marketIndex);
const bids = this.dlob
.getBestMakers({
marketIndex: marketArgs.marketIndex,
marketType: marketArgs.marketType,
direction: PositionDirection.LONG,
slot: slot,
oraclePriceData,
numMakers: 4,
})
.map((x) => x.toString());
const asks = this.dlob
.getBestMakers({
marketIndex: marketArgs.marketIndex,
marketType: marketArgs.marketType,
direction: PositionDirection.SHORT,
slot,
oraclePriceData,
numMakers: 4,
})
.map((x) => x.toString());
this.redisClient.client.set(
`last_update_orderbook_best_makers_${marketType}_${marketArgs.marketIndex}`,
JSON.stringify({ bids, asks, slot })
);
}
getL3AndSendMsg(marketArgs: wsMarketArgs): void {