Not receiving ping frame from binance for Websocket Futures Market Stream

Hi. I have a few questions about Websocket Market Streams for Futures:

  1. I get disconnected pretty often some days more often then others can be every 5-8 minutes. I don’t seem to receive the ping frames so I don’t send pongs back. Can this be an issue for the disconnects?
  2. Is it ok to connect to many Futures Websocket Market Streams from a single machine? Can this be an issue for the disconnects?

For futures, Ping frame is not available yet, it’s fine to have multi streams subscribed from one client.

Have you tried with different client tool to subscribe the stream?

Our websocket connection is quite stable,
maybe this tool can be useful to verify the connection.

Thanks for the reply. I wrote the javascript client using native browser WebSocket API.
I am connecting to ‘wss://’. On top of it stream '‘wss://{symbol}@depth’ also disconnects many times sporadically. I am having disconnects way to often. What can I do to improve this aspect? If I lose User Data Stream I am missing the important order updates. There’s gotta be a solution to this. Please advise.

This is the implementation I have. I decided to use a single WebSocket connection for @depth and account updates. Some days are worse than others. I connected over the wire now rather than wife and still get disconnected sporadically. Here is the code. Please let me know where it can be improved.

let refreshInterval;
const listenKey = // getting a listenKey here using POST /fapi/v1/listenKey
const ws = new WebSocket(“wss://” + listenKey);

ws.onopen = () => {
refreshInterval = setInterval(() => {
// doing PUT /fapi/v1/listenKey to keep the listenkey alive
}, 1000 * 60 * 29);
method: ‘SUBSCRIBE’,
params: [someTicker + ‘@depth’],
id: 1,

ws.onclose = async () => {
// handling reconnect here. it happens many very randomly sometimes multiple times an hour - sometimes not as often - the least is probably a few times a day.

FYI I tried to connect to and after a few hours got [“Websocket connection closed”] message.

I’ve run into the same issue and found a workaround. I shared the link below incase you are interested.

1 Like

When I use ClientWebSocket in C# I still get disconnected even though it handles the PING/PONG for me.

One thing that I figured out is that I need to space my subscriptions out a little bit (200ms) in order for the connection to not get reset. The docs mention that you can only send 5 messages per second:

WebSocket connections have a limit of 5 incoming messages per second. A message is considered:

I suspect this was causing my issues because I was subscribing in a loop without a delay between each sub.

There’re three things you can do to keep your stability:

  1. Always confirm if your network environment is in stable status
  2. If you don’t receive Ping Frame, send it from your end and you should expect a Pong
  3. If you don’t receive a Pong or if you lost your connection, reconnect it

From my testing, always sends Ping; Please confirm if you receive it by defining actions in on_ping()

a few hours is much better than every 5-8 minutes, will forward to client for review.

So you recommend to connect to USER_DATA_STREAM and MARKET_STREAM separately? What kind of ping frames you recommend to send for USER_DATA_STREAM - something like this is ok ws.send(‘ping’) ?

The reason I connected them in a single ws connection was b/c both were closing frequently and I needed reconnect so it was easier to deal with a single connection. Thanks for the advice!