chore: add dlob offload

This commit is contained in:
Jack Waller
2025-06-17 16:17:26 +10:00
parent 8529337e39
commit 1d722e1675
5 changed files with 1173 additions and 220 deletions

View File

@@ -25,6 +25,7 @@ import {
parsePositiveIntArray,
} from '../utils/utils';
import { setHealthStatus, HEALTH_STATUS } from '../core/metrics';
import { OffloadQueue } from '../utils/offload';
type wsMarketArgs = {
marketIndex: number;
@@ -69,12 +70,15 @@ export class DLOBSubscriberIO extends DLOBSubscriber {
MarketType,
Map<number, { slot: number; ts: number }>
>;
public offloadQueue?: ReturnType<typeof OffloadQueue>;
public enableOffload: boolean;
constructor(
config: DLOBSubscriptionConfig & {
env: DriftEnv;
redisClient: RedisClient;
indicativeQuotesRedisClient?: RedisClient;
enableOffloadQueue?: boolean
perpMarketInfos: wsMarketInfo[];
spotMarketInfos: wsMarketInfo[];
spotMarketSubscribers: SubscriberLookup;
@@ -88,6 +92,11 @@ export class DLOBSubscriberIO extends DLOBSubscriber {
this.killSwitchSlotDiffThreshold =
config.killSwitchSlotDiffThreshold || 200;
this.enableOffload = config.enableOffloadQueue || false;
if (this.enableOffload) {
this.offloadQueue = OffloadQueue();
}
// Set up appropriate maps
this.lastSeenL2Formatted = new Map();
this.lastSeenL2Formatted.set(MarketType.SPOT, new Map());
@@ -392,6 +401,19 @@ export class DLOBSubscriberIO extends DLOBSubscriber {
}`,
l2Formatted
);
if (this.offloadQueue) {
try {
this.offloadQueue.addMessage(Object.assign({}, l2Formatted, {
bids: l2Formatted.bids.slice(0, 20),
asks: l2Formatted.asks.slice(0, 20),
ts: Math.floor(new Date().getTime() / 1000),
}));
} catch (error) {
logger.error('Error adding message to offload queue:', error);
}
}
this.redisClient.set(
`last_update_orderbook_${marketType}_${marketArgs.marketIndex}${
this.indicativeQuotesRedisClient ? '_indicative' : ''