WebSocket Reconnecting Issue

My team’s algorithm is coded to have a stop time when futures break occurs. The bot goes into an idle state pausing all transactions. There is an issue when reconnecting after being paused for certain duration. The websocket connection reconnects when we pause it for 10 mins and then restarts successfully but the connection does not reconnect after 2 hours of pause. We even renew the token and reauthenticate itbut still does not subscribe again after closing a connection for 2 hours then reopening it.

Any help?

It is possible that your websocket is stuck using old callbacks if you are trying to save the socket instance. Try setting its event handlers to undefined when you shut the socket down (like this socket.onopen = undefined;, etc), and also call socket.close(); manually. Then when you reopen the connection, reinitialize the socket’s event handlers.

As an alternative try this - don’t call close at all, and instead create a set of handlers for both the paused socket and running socket states. The ‘running’ state message handlers will process events as usual, while the ‘paused’ socket handlers will only bother with keeping the connection alive by processing heartbeats.

We tried the solution you suggested by instantiating a new websocket connection when the market opens after futures break with a refreshed token. After authentication, we do not receive market data. We also tested starting the subscription again and same error. Anything else we can try?

@Alexander, it’s been almost two weeks with no response and we are still having this issue. Any other solution we could try in means to fix this? It is crucial for this to not happen as we aim to run our algorithm 24/7.

@Alexander, could we get some help with this? We tried your solution and it did not work. It’s been around 3 weeks now since the last response.