Websocket connections not getting data after some time

Hello,

i have 200 symbols each one have one socket and after a while it stops working and gives me the following error message
“sent 1011 (unexpected error) keepalive ping timeout; no close frame received”

this is my websocket code

Can anyone help me please?

Hello man.

It is my first post here.

Are you using the combined strams feature? If not, subscribing to 200 symbols simultaneously, it’s possible that the sheer volume of data or the number of connections is causing some strain.
To use the combined strams feature :

wss://stream.binance.com:443/stream?streams=symbol1@kline_1m/symbol2@kline_1m/...

Also, the error suggests a problem with keepalive pings. WebSockets often have a ping/pong mechanism to keep the connection alive. You can consider setting the ping_interval and ping_timeout parameters in websockets.connect() to manage the keepalive pings:

self.websocket = await websockets.connect("wss://stream.binance.com:443/ws", ping_interval=60, ping_timeout=180) 

Hope my answer will help you,

Nick Tsili

Hi Nick,

Thanks for your answer but i try to add ping_interval and ping_timeout and give me the same error

Relative to streams, after create the url i need to send the subscribers?

I would do two things:

  • Try logging data
  • Try limiting the number of symbols you’re subscribing to see if error stops
  • I don’t know if I understand your question, but here is an example: wss://stream.binance.com:443/stream?streams=BTCUSDT@kline_1m/ETHUSDT@kline_1m/