Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for futures WS API #444

Closed
Luke-Rogerson opened this issue Aug 21, 2024 · 3 comments
Closed

Add support for futures WS API #444

Luke-Rogerson opened this issue Aug 21, 2024 · 3 comments
Labels

Comments

@Luke-Rogerson
Copy link

Luke-Rogerson commented Aug 21, 2024

The new Binance API documentation specifies a different websocket endpoint to the one specified in your base URLs.

  • Your one: wss://fstream.binance.com
  • Binance's new one: wss://ws-fapi.binance.com/ws-fapi/v1

Do you know if your one is still valid? If not, is there a planned cutover time? Binance certainly don't write the clearest documentation!

@tiagosiebler
Copy link
Owner

Hi @Luke-Rogerson - yes, the current one is still valid. There's actually two difference concepts here and the naming of the "new" one isn't the most obvious thing.

There's the traditional websockets (event emitters, binance is a producer, you're a consumer) where you subscribe to topics/channels and receive data (one-way), then there's a newer websocket that can be used a bit like a REST API. This is what binance has called WebSocket API. This nifty new system allows you to send orders and other commands over a websocket connection, shaving off some of the latency you would see from a traditional REST API.

If you're looking to consume events (market data, account events, etc), that's fully supported as is with the current WebSocket client. That's either the WebSocket Market Streams, listed here for USDM futures:
https://developers.binance.com/docs/derivatives/usds-margined-futures/websocket-market-streams

Or the user data stream (for account events), listed here:
https://developers.binance.com/docs/derivatives/usds-margined-futures/user-data-streams

I have some minimal examples for both types of events:
https://github.com/tiagosiebler/binance/blob/master/examples/ws-userdata.ts#L128-L131
https://github.com/tiagosiebler/binance/blob/master/examples/ws-public-usdm-funding.ts#L68

All consumer websockets are wrapped up in convenience functions in the ws client, you can see them here:
https://github.com/tiagosiebler/binance/blob/master/src/websocket-client.ts#L1211-L2072

If you're not sure which you need, I'd suggest to check the docs to see which websocket topic/channel has what you want, then search in the websocket-client to see if there's a function mapped to it. We're still in the process of adding some of the newer ones, so if you see anything you're missing - let us know or submit a PR. Otherwise we'll get to updating it all eventually.

@tiagosiebler
Copy link
Owner

Also the WebSocket API is a curious one. While it's not supported in this SDK for binance yet, I will be adding support for it soon. My gate.io SDK is actually the first one to see an implementation of a WS API and I'm likely to bring the same design over to the binance SDK (as well as my other SDKs for exchanges that have a WS API). So if you'd like to see how that can work in practice, take a look at the gate SDK. Some docs here:
https://github.com/tiagosiebler/gateio-api/blob/master/README.md#websocket-api

Also an example here where you can see a minimal implementation in action:
https://github.com/tiagosiebler/gateio-api/blob/master/examples/ws-private-spot-wsapi.ts#L88-L95

It's a great time for feedback/concerns, if you'd like to influence how the final implementation will look/work, so if this is something you will use in future please do take a look and ideally try it out.

@tiagosiebler tiagosiebler changed the title New USD-M futures websocket endpoint? Add support for futures WS API Aug 22, 2024
Repository owner deleted a comment Oct 23, 2024
@tiagosiebler
Copy link
Owner

Closing in favour of #283 - for anyone looking forward to the WS API, feel free to subscribe to #283 for updates.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants