How to check the websocket connection status with the Binance Java connector ?


I’m using the Binance Java connector.

Can anyone tell me how can I check the websocket connection?

I need to detect when it fails to stop activities when that happens .


Data should be pushed constantly when you connect to a stream. If you fail to receive message based on the Update Speed in the API documentation, you should attempt a reconnect.

Thank you Chai, but that doesn’t calm my concerns.

For example, I can’t rely on balance updates from websocket, whose connection may get broken at any time, as I’ve no mean to know whether my data is up to date to use it or stale an go get it from api.

I need a way, a realiable way, of checking the ws connection status.

Or, at least.

We need to have the possibility to have callbacks of our own, for connection failure or closure events, get called when such things happen.

That way, as long as my ‘failure’ callbacks hasn’t been called, I can consider that the program is in sync with the exchange and it can continue doing its job safely.

The binance java SDK websocket client doesn’t provide such thing.

Hi Aymes, my solution to this is to add this in

boolean var1 = false;
onMessageCallbackMarket = (message) → {
if(var1 = true){
// log / print out “message”
// var1=false;

then from somewhere in your code, if you want to check if the websocket is streaming, do just var1 = true

Hi naserkaka, yes it would do it!

But while I was waiting at that time, I did them a PR with what I needed. They’ve accepted it.

It should appear on some version of the Java connector, if not already.


Hi Aymens! great! will look into it. Thanks , naser