From 064f596f61259fb32ead3675abf71136881ab216 Mon Sep 17 00:00:00 2001 From: Nour Alharithi Date: Wed, 10 Jul 2024 16:16:45 -0700 Subject: [PATCH] add undefined guard --- src/index.ts | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/index.ts b/src/index.ts index 7df554b..bfde7c9 100644 --- a/src/index.ts +++ b/src/index.ts @@ -684,8 +684,8 @@ const main = async (): Promise => { const redisClient = perpMarketRedisMap.get(normedMarketIndex).client; const redisL2 = await redisClient.get(`last_update_orderbook_perp_${normedMarketIndex}`); const depth = Math.min(parseInt(adjustedDepth as string) ?? 1, 100); - redisL2['bids'] = redisL2['bids'].slice(0, depth); - redisL2['asks'] = redisL2['asks'].slice(0, depth); + redisL2['bids'] = redisL2['bids']?.slice(0, depth); + redisL2['asks'] = redisL2['asks']?.slice(0, depth); if ( redisL2 && @@ -708,8 +708,8 @@ const main = async (): Promise => { const redisClient = spotMarketRedisMap.get(normedMarketIndex).client; const redisL2 = await redisClient.get(`last_update_orderbook_spot_${normedMarketIndex}`); const depth = Math.min(parseInt(adjustedDepth as string) ?? 1, 100); - redisL2['bids'] = redisL2['bids'].slice(0, depth); - redisL2['asks'] = redisL2['asks'].slice(0, depth); + redisL2['bids'] = redisL2['bids']?.slice(0, depth); + redisL2['asks'] = redisL2['asks']?.slice(0, depth); if ( redisL2 && dlobProvider.getSlot() - parseInt(redisL2['slot']) < @@ -838,8 +838,8 @@ const main = async (): Promise => { perpMarketRedisMap.get(normedMarketIndex).client; const redisL2 = await redisClient.get(`last_update_orderbook_perp_${normedMarketIndex}`); const depth = Math.min(parseInt(adjustedDepth as string) ?? 1, 100); - redisL2['bids'] = redisL2['bids'].slice(0, depth); - redisL2['asks'] = redisL2['asks'].slice(0, depth); + redisL2['bids'] = redisL2['bids']?.slice(0, depth); + redisL2['asks'] = redisL2['asks']?.slice(0, depth); if (redisL2) { if ( dlobProvider.getSlot() - parseInt(redisL2['slot']) < @@ -863,8 +863,8 @@ const main = async (): Promise => { spotMarketRedisMap.get(normedMarketIndex).client; const redisL2 = await redisClient.get(`last_update_orderbook_spot_${normedMarketIndex}`); const depth = Math.min(parseInt(adjustedDepth as string) ?? 1, 100); - redisL2['bids'] = redisL2['bids'].slice(0, depth); - redisL2['asks'] = redisL2['asks'].slice(0, depth); + redisL2['bids'] = redisL2['bids']?.slice(0, depth); + redisL2['asks'] = redisL2['asks']?.slice(0, depth); if (redisL2) { if ( dlobProvider.getSlot() - parseInt(redisL2['slot']) <