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 the new Websocket API #344

Closed
tiagosiebler opened this issue May 7, 2024 · 3 comments
Closed

Add support for the new Websocket API #344

tiagosiebler opened this issue May 7, 2024 · 3 comments
Assignees
Labels
enhancement New feature or request

Comments

@tiagosiebler
Copy link
Owner

tiagosiebler commented May 7, 2024

https://bybit-exchange.github.io/docs/v5/websocket/trade/guideline

Note: as of Dec 2024, demo trading does not support the WS API: https://t.me/BybitAPI/280348

Testnet is supported though.

@tiagosiebler tiagosiebler self-assigned this May 7, 2024
@tiagosiebler tiagosiebler added the enhancement New feature or request label May 7, 2024
@tiagosiebler
Copy link
Owner Author

I will be adding support for this 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 bybit 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
Copy link
Owner Author

I wouldn’t say it’s finished yet. Still cleaning up, readme updates, and a million sanity checks, stress tests, robustness tests, etc. However, if you’re interested or even slightly curious in working with Bybit’s WebSocket API (submitting orders over WS), here’s an early peek into how it’s going to work!

If you’ve seen our newer Gate.io SDK and how the WS API is integrated there, it’s very similar and I plan on upgrading all my SDKs to support each exchange’s WS API this way, where available.

There are essentially two ways you can use it.

  • Option 1: The “hard” way, which works how you would expect WebSockets to work. Fire & forget a command, and the response eventually comes back asynchronously via the EventEmitter. Well suited for already sophisticated systems that were designed for this anyway.
  • Option 2: The REST-like way, which works very much how a REST API “feels”. Send a command and await a response. The WebsocketClient handles promise and async event tracking for you, so you don’t have to care.

Amazingly, the request parameters for the WS API follow the exact same structure as the corresponding REST API call. So if you wanted, you can just swap your await order submit call with the await sendWSAPIRequest(…new order…) and it works almost the same way (via WS instead, and the response is nested within an object). All the convenience and speed without any of the hassle (of working with WebSockets).

Anyway, text aside, if you’re curious - take a look:

Once I’m happy with some of the remaining things to work through, I’ll likely release a beta version to npm before the major release. Would very much appreciate extra help in stress testing it, in the off chance anything slipped through the cracks. I’ll post another update here and in the Node.js Algo Traders community in Telegram.

Feedback/thoughts/concerns are always welcome - now is the best time for it, before the next release is GA.

@tiagosiebler
Copy link
Owner Author

Help test the latest generation of the Bybit SDK, currently in public beta, before the major release!

More info here in the open PR:
#398 (comment)

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

No branches or pull requests

1 participant