What reasons are there for Binance to close a websocket connection?

I’m connecting to a websocket (Spot) and receiving market data. I am not sending orders. Every 5 minutes I send a ping, to keep the connection alive.

Sometimes when I try to send a ping, the socket has been closed and I get a broken pipe error.

What reasons are there for Binance to close the connection?

How long the connection got closed since it’s connected?

Websockets can be quite unstable depending on many aspects of your network, binance servers, and everything in between. It’s important to have logic monitoring your websocket health and handling it if the websocket seems to be dead. Here’s one approach to doing this in node.js: