binance-exchange / binance-java-api

binance-java-api is a lightweight Java library for the Binance API, supporting synchronous and asynchronous requests, as well as event streaming using WebSockets.
MIT License
831 stars 628 forks source link

websocket auto-reconnect #352

Open ramarro123 opened 3 years ago

ramarro123 commented 3 years ago

websocket doens't auto reconnect in case of errors, i got a couple of socket timeout and the websocket doens't reconnect, this even't aren't even easy to catch since are generated by low level library, shouldn't the library deal with that?

NFS002 commented 3 years ago

I found they are actually pretty easy to catch ...

if (cause.getMessage().startsWith("sent ping but didn't receive pong") ) { // restart websocket stream }

is this what you mean ?

ramarro123 commented 3 years ago

yep, i handle that in the same way, but still i belive it's something library should handle internally, or via a factory config like .autoreconnect(true).... what if the lib decide to change the implmentation of websocket from OKHTTP to another lib?

getting a specific error message from a lib (okhttp) used by a lib, it's not my ideal way of dealing it.

even a custom exception should be fine, like if (e instanceof webscoketClosed)) should just work probbly, and library handle wrapping the exception in a proper way?

just some random ideas :)

NFS002 commented 3 years ago

Check out this pr https://github.com/binance-exchange/binance-java-api/pull/292 ... think it could fix the issue at the lib level