my bot sometimes doesnt receive data via websocket

I use binance tr api for my trading bot ; Some days my bot works perfectly and i get all data via websocket. Some days ( or sometimes ) bot cannot receive data.

I use Nodejs on window 11.

const wsgonder={"method":"SUBSCRIBE","params":["!miniTicker@arr@3000ms"]};

    var alinacak={};
const ws = new WebSocket("wss://stream-cloud.binance.tr/stream");
ws.on('open', function open() {


  ws.send(JSON.stringify(wsgonder));
});

ws.on("ping",(e)=>{
    console.log(e.toString());
    ws.pong();
})
var count=0;
ws.on("message", async function incoming(data) {
    
count++;
console.log(count)

})

For example : sometimes count stop at 20 , sometimes stop at 10… Sometimes works perfectly all day long.

Hi @Sefer_Eken,

Have you also tried with wss://stream.binance.com:9443 or wss://stream.binance.com:443 and getting the same behaviour?

Also can you please add a listener for the error and close events and share any details you get from them.

Let me know when you have more info!

I try 443 and 9443 but same behaviour.
And i cant listen close and error event.
For example

ws.on(‘error’, console.error);
ws.on(‘close’, function close() {
console.log(‘disconnected’);
});
But i cant get any message.

@Sefer_Eken What do you mean by “can’t get any message”? Are the callbacks not invoked?

Note that 'close' also gets two arguments for close code and message, those can provide some hints about the disconnection reason.

Hey @Sefer_Eken,

What is your network topology? Are you using a VPN or any proxy server? Do you use a stable internet connection, and if yes have you encountered ever any issues with HTTP calls or any other websocket servers?

I dont use VPN or proxy .
I dont get any error on other websites that use websocket.
Sometimes it works all day long without any problems. I don’t understand why I don’t get any errors

Hi @Sefer_Eken,

Do you also use the REST API or any WebSocket API calls?

This is my own bot . I use only ws module and nodejs ( only for binance API )

Side note: you shouldn’t need to send pongs yourself. WebSocket normally has autoPong enabled, responding with pongs properly and promptly after receiving them. You might still want to log the pings to confirm they are received and processed.

Yes i know it.

But i dont understand why my bot sometimes works perfectly all day .
Sometimes works 10 second , sometimes 30 …
I dont get any error .