binance-connector-java icon indicating copy to clipboard operation
binance-connector-java copied to clipboard

Track onFailure for websocket and check if websocket connection is alive

Open naserkaka opened this issue 2 years ago • 6 comments

Hi ,

  1. how can I check if my websocket connection is open/running ?

  2. I wonder if the openEvent,closingEvent and FailureEvent variables can return a value other than null ? I would like to know why my websocket is failing sometimes.

          onOpenCallbackMarket = openEvent -> {
    
         };
          onMessageCallbackMarket = (message) -> {
    
        };
         onClosingCallbackMarket = closingEvent -> {
    
         };
         onFailureCallbackMarket = failureEvent -> { 
    
        };
    

naserkaka avatar Jul 29 '22 18:07 naserkaka

https://github.com/binance/binance-connector-java/blob/master/src/test/java/examples/websocket/TradeStreamWithAllCallbacks.java

You can take a look at this example file. It handles callbacks from websocket.

chairz avatar Aug 03 '22 02:08 chairz

@chairz it just restarts the websocket. Is it possible to get a message why it failed ?

naserkaka avatar Aug 27 '22 14:08 naserkaka

@naserkaka I have proposed a PR about this idea, without knowing you had asked for. Maybe you can review it and see if it fits your needs.

Hazard4U avatar Sep 11 '22 11:09 Hazard4U

Hi @Hazard4U , this will help a lot , now I can catch the error for failureOnCallback and see more detailed information why it failed. This was needed, thanks! when will this PR be merged?

naserkaka avatar Sep 11 '22 20:09 naserkaka

Hi @naserkaka, according to WebSocketConnection , there's logging for when connection is opened or gets failure.

We'll look into @Hazard4U PR #51 to see how we'll improve this, might take some time though as it might be a breaking change.

aisling-2 avatar Sep 13 '22 15:09 aisling-2

so this is how I can catch the message in onFailure ? for now.

 onFailureCallbackMarketDataUser = (message) -> {
                logger.error("onFailureCallback() message:" + message);
            };

naserkaka avatar Sep 17 '22 12:09 naserkaka