diff --git a/src/dlob-subscriber/DLOBSubscriberIO.ts b/src/dlob-subscriber/DLOBSubscriberIO.ts index 41491e7..97b063f 100644 --- a/src/dlob-subscriber/DLOBSubscriberIO.ts +++ b/src/dlob-subscriber/DLOBSubscriberIO.ts @@ -36,6 +36,7 @@ export class DLOBSubscriberIO extends DLOBSubscriber { public marketL2Args: wsMarketL2Args[] = []; public lastSeenL2Formatted: Map>; redisClient: RedisClient; + public killSwitchSlotDiffThreshold: number; constructor( config: DLOBSubscriptionConfig & { @@ -43,10 +44,13 @@ export class DLOBSubscriberIO extends DLOBSubscriber { perpMarketInfos: wsMarketInfo[]; spotMarketInfos: wsMarketInfo[]; spotMarketSubscribers: SubscriberLookup; + killSwitchSlotDiffThreshold?: number; } ) { super(config); this.redisClient = config.redisClient; + this.killSwitchSlotDiffThreshold = + config.killSwitchSlotDiffThreshold || 200; // Set up appropriate maps this.lastSeenL2Formatted = new Map(); @@ -139,6 +143,18 @@ export class DLOBSubscriberIO extends DLOBSubscriber { l2Args.marketIndex ); + if ( + Math.abs(slot - parseInt(l2Formatted['oracleData']['slot'])) > + this.killSwitchSlotDiffThreshold + ) { + console.log(`Killing process due to slot diffs for market ${marketName}: + dlobProvider slot: ${slot} + oracle slot: ${l2Formatted['oracleData']['slot']} + market slot: ${l2Formatted['marketSlot']} + `); + process.exit(1); + } + const l2Formatted_depth100 = Object.assign({}, l2Formatted, { bids: l2Formatted.bids.slice(0, 100), asks: l2Formatted.asks.slice(0, 100), diff --git a/src/publishers/dlobPublisher.ts b/src/publishers/dlobPublisher.ts index 10d9504..4181a9b 100644 --- a/src/publishers/dlobPublisher.ts +++ b/src/publishers/dlobPublisher.ts @@ -71,6 +71,9 @@ const ORDERBOOK_UPDATE_INTERVAL = parseInt(process.env.ORDERBOOK_UPDATE_INTERVAL) || 1000; const WS_FALLBACK_FETCH_INTERVAL = 10_000; +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 @@ -395,6 +398,7 @@ const main = async () => { spotMarketSubscribers: MARKET_SUBSCRIBERS, perpMarketInfos, spotMarketInfos, + killSwitchSlotDiffThreshold: KILLSWITCH_SLOT_DIFF_THRESHOLD, }); await dlobSubscriber.subscribe(); if (useWebsocket && !FEATURE_FLAGS.DISABLE_GPA_REFRESH) {