From 59b88f753d062b73c3641ff254f94ec4ac598164 Mon Sep 17 00:00:00 2001 From: Nour Alharithi Date: Tue, 12 Dec 2023 09:56:14 -0800 Subject: [PATCH] send heartbeat and detect redis cache better --- src/index.ts | 4 ++-- src/wsConnectionManager.ts | 7 +++++++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/index.ts b/src/index.ts index e13e351..d68990a 100644 --- a/src/index.ts +++ b/src/index.ts @@ -941,7 +941,7 @@ const main = async () => { let l2Formatted: any; if (useRedis) { if ( - marketType === 'perp' && + !isSpot && normedParam['includeVamm'].toLowerCase() === 'true' && normedParam['includeOracle'].toLowerCase() === 'true' && !normedParam['grouping'] @@ -966,7 +966,7 @@ const main = async () => { l2Formatted = parsedRedisL2; } } else if ( - marketType === 'spot' && + isSpot && normedParam['includePhoenix'].toLowerCase() === 'true' && normedParam['includeSerum'].toLowerCase() === 'true' && !normedParam['grouping'] diff --git a/src/wsConnectionManager.ts b/src/wsConnectionManager.ts index 26eb4b3..43e219f 100644 --- a/src/wsConnectionManager.ts +++ b/src/wsConnectionManager.ts @@ -257,6 +257,13 @@ async function main() { ws.on('error', (error) => { console.error('Socket error:', error); }); + + // Set interval to send heartbeat every 5 seconds + setInterval(() => { + ws.send(JSON.stringify({ + channel: 'heartbeat' + })); + }, 5000); }); server.listen(WS_PORT, () => {