tiagosiebler / binance

Node.js & JavaScript SDK for Binance REST APIs & WebSockets, with TypeScript & browser support, integration tests, beautification & more.
MIT License
757 stars 266 forks source link

User Data Streams #421

Closed MartoMcfly closed 5 months ago

MartoMcfly commented 5 months ago

Hello Tiago, thank you very much for keeping this protect up to date

I wanted to ask/request if it's possible to have user data streams available with this library? https://binance-docs.github.io/apidocs/spot/en/#user-data-streams

Best,

Martin

tiagosiebler commented 5 months ago

Hi Martin, already supported - this was actually one of the original motivations for making my own SDK. Every other SDK I've tried had damaging issues with how they handled the user data stream, some issues only manifested themselves after hours or more of uptime.

Here's an example showing both the setup of the user data stream (via the websocket client) and then some basic event handling using a typeguard (makes it much easier if you're using typescript): https://github.com/tiagosiebler/binance/blob/master/examples/ws-userdata.ts#L90-L92

The wsClient.subscribeSpotUserDataStream(); call opens the connection. The rest of the connection life cycle (including listen key handling and connection health) is all handled automatically by the WS client. Just subscribe once and listen to events.

MartoMcfly commented 5 months ago

Hi Tiago, you never cease to amaze me haha. Thank you for maintaining this library! Thank you for sharing your experience and the example! It's great to hear that you've found a solution that addresses the issues you've encountered with other SDKs. The code snippet you provided looks straightforward and the use of a typeguard is definitely a plus. I appreciate the simplicity of the setup

tiagosiebler commented 5 months ago

Glad it's helping. Will close this for now, but feel free to reopen or post new issues if needed.