wisespace-io / binance-rs

Rust Library for the Binance API
Other
665 stars 297 forks source link

Keep WS User Stream Alive #35

Closed fredfortier closed 4 years ago

fredfortier commented 4 years ago

I'm subscribing to the WS user stream as per the "WEBSOCKETS - USER STREAM" section of the README. I noticed that it seems to disconnect (no longer receiving updates) after several hours. I also subscribe to the !ticker@arr stream in the same connection (like this:format!("{}/!ticker@arr", answer.listen_key)) but the ticker stream stays connected.

Where do you suggest I begin troubleshooting this?

fredfortier commented 4 years ago

I see that there is a keep_alive method in UserStream. Is the idea that I should periodically call this method on a separate thread? Any pointers on how to properly use this method would be appreciated.

wisespace-io commented 4 years ago

@fredfortier Yes, it should be called periodically, see the link below

https://binance-docs.github.io/apidocs/spot/en/#listen-key-spot

Keepalive a user data stream to prevent a time out.
User data streams will close after 60 minutes.
It's recommended to send a ping about every 30 minutes.
fredfortier commented 4 years ago

I tested this overnight and confirm that it works.