Skip to content

Commit

Permalink
Merge pull request #80 from drift-labs/master
Browse files Browse the repository at this point in the history
oracle kill switch
  • Loading branch information
NourAlharithi authored Jan 23, 2024
2 parents a0b0a2b + 6eb9532 commit 4658ca3
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/dlob-subscriber/DLOBSubscriberIO.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,17 +36,21 @@ export class DLOBSubscriberIO extends DLOBSubscriber {
public marketL2Args: wsMarketL2Args[] = [];
public lastSeenL2Formatted: Map<MarketType, Map<number, any>>;
redisClient: RedisClient;
public killSwitchSlotDiffThreshold: number;

constructor(
config: DLOBSubscriptionConfig & {
redisClient: RedisClient;
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();
Expand Down Expand Up @@ -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),
Expand Down
4 changes: 4 additions & 0 deletions src/publishers/dlobPublisher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 4658ca3

Please sign in to comment.