BitMEX / api-connectors

Libraries for connecting to the BitMEX API.
https://www.bitmex.com/app/restAPI
910 stars 795 forks source link

[Python] Websocket - how to implement Heartbeat? #397

Open mattkc7 opened 5 years ago

mattkc7 commented 5 years ago

I'm at a loss of how to edit the Bitmex websocket client code (https://github.com/BitMEX/api-connectors/blob/master/official-ws/python/bitmex_websocket.py) to have a heartbeat (https://www.bitmex.com/app/wsAPI#Heartbeats) so that i can re-establish a dropped connection.

Upon inspection of the websocket-client python code, i passed in ping_interval and ping_timeout to run_forever(), but i don't see how a connection is re-established if the current one is dropped.

See https://github.com/websocket-client/websocket-client/blob/master/websocket/_app.py#L176-L193

and

https://github.com/websocket-client/websocket-client/blob/master/websocket/_app.py#L293-L303

Assuming it's the developer's responsibility to handle it, where would i fit this in?

I was tryign to figure out how to do something like:

while True:
self.ws.run_forever(ping_interval=30, ping_timeout=15)

Any advice or clarification? Thanks

whiletruefranz commented 3 years ago

Did you find a solution?