nodejs spot market data WebSocket stops working after a few minutes with no error

I have a WebSocket connected to wss://stream.binance.com:9443/ws that subscribes to “!bookTicker” only. The application simply prints out 1 in 10000 events and does nothing else.

It works fine for a few minutes (sometimes up to an hour maybe), but eventually the data stops arriving. There is no error messages and the WebSocket remains in an open state. I do not receive error or close events.

I have a thing the periodically logs the socket state and it’s always ‘1’ (open) even after the market data stops being delivered.

I am using nodejs 14, and the WS library (v7.4.4).

I also log the ping messages that are received from the server, they also stop arriving.

I’m sure the WS library handles the ping/pong protocol, but I have also tried responding to the pings in the application code but it made no difference.

Why does the market data stop being delivered? And why is there no error message?

I have a similar issue in that by subscribing to !bookTicker the ws client gets disconnected very often, about every minute or so

Sounds like a slightly different problem to me, but possible related. Mine stays connected for a while (5 to 100 mins is guess). But I don’t get disconnected at all, the data jus stops flowing.

Have you tried it in the binance-api-node lib?

Do you get the same issue? This lib handles the sockets in the background and i haven’t these kind of issues so far (though i haven’t used this specific stream).

Maybe it helps :slight_smile:

1 Like

Great advice.

@npomfret you can also follow the examples they have in their examples folder. For the most part the provided library should work without problems.