How to check if Binance websocket is disconnected?

Hello, if I keep the websocket open for some days and listen market ticks, sometimes it stops sending data and when I reconnect it start working again

The problem is how do I know when I need to reconnect if the server just stops sending data?
Anyone has similar issue?

I’m using node.js

It depends on your handling of the websocket connection locally.

Our node.js connector has callbacks for the websocket connection, you can explore more at

I’m using this GitHub - tiagosiebler/binance: Node.js SDK for the Binance APIs and WebSockets, with TypeScript & browser support, integration tests, beautification & more.
the most famous one

This happens on any client, if the websocket is open for long time and receiving data, Binance will close it.

It’s possible to receive a close event so we can open it again?

Hi, with this SDK the websocket will automatically reconnect when a dropped connection is detected. You will see an error containing “pong timeout” “closing socket to reconnect” (info level log), and it should immediately kill the old connection and open a new one to replace it. When this happens, you will also have the option of adding an event listener on the “reconnecting” and the “reconnected” events:

The latter can be a good opportunity to trigger any REST API calls to ensure your local state isn’t out of sync (e.g. fetch balance, positions, orders).

1 Like

Any good websocket, be it an object, connector or library, must provide methods or events to catch errors and closures of the websocket.

And any good system doesn’t stop sending data on the websocket connection without sending a disconnect event