add a websocket callback: on_disconnected()
I want to reconnect to websocket server, but can't catch the disconnected exception raised by the BinanceSocketManager thread. So add the on_disconnected() callback to solve this problem.
Does anyone maintain this repo? Quite critical issue is resolved here.....
I want to reconnect to websocket server, but can't catch the disconnected exception raised by the BinanceSocketManager thread. So add the on_disconnected() callback to solve this problem.
Hi @daboooooo ,
Thanks a lot for your idea.
Why just not to use: self._callback(self.on_error, e) as it already exist instead of creating new event: on_disconnected?
In this case we need to patch: binance_socket_manager.py only.
And also to add self.ws.connected = False when any exception is raised in binance_socket_manager.py?
Later on, we will be able to intercept/catch the Websocket exception and can check status of self.ws.connected like this guy propose: #120
Something like this?
except WebSocketException as e:
if isinstance(e, WebSocketConnectionClosedException):
self.logger.error("Lost websocket connection")
else:
self.logger.error("Websocket exception: {}".format(e))
if self.ws.connected:
self.ws.send_close()
self.ws.connected = False
self._callback(self.on_error, e)
break
except Exception as e:
self.logger.error("Exception in read_data: {}".format(e))
if self.ws.connected:
self.ws.send_close()
self.ws.connected = False
self._callback(self.on_error, e)
break
Just for your information, the new version of websocket-client introduced a on_reconnect callback which might be helpful for this issue.
Just for your information, the new version of websocket-client introduced a
on_reconnectcallback which might be helpful for this issue.
Can you point to this in code. Not able to find it in latest
Just for your information, the new version of websocket-client introduced a
on_reconnectcallback which might be helpful for this issue.Can you point to this in code. Not able to find it in latest
https://github.com/websocket-client/websocket-client/blob/52329c4956f88133f45ecd510668776cd8a96ebf/websocket/_app.py#L59
The latest version is 1.8.0 which already supports this.
We have released a new modularised version of the Python Connector and the binance-futures-connector-python will not be maintained anymore. I suggest you to start using the new one and open a new issue at the modularised connector, if you still encounter it.