binance-connector-java
binance-connector-java copied to clipboard
Track onFailure for websocket and check if websocket connection is alive
Hi ,
-
how can I check if my websocket connection is open/running ?
-
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 -> { };
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 it just restarts the websocket. Is it possible to get a message why it failed ?
@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.
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?
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.
so this is how I can catch the message in onFailure ? for now.
onFailureCallbackMarketDataUser = (message) -> {
logger.error("onFailureCallback() message:" + message);
};