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 WebSocket API trading support for Bybit #2129

Merged
merged 6 commits into from
Dec 18, 2024

Conversation

sunlei
Copy link
Collaborator

@sunlei sunlei commented Dec 18, 2024

Pull Request

This PR introduces the ability to trade on Bybit using the WebSocket API.
The implementation is controlled by the following parameters in BybitExecClientConfig:

  • use_ws_trade_api : bool, default False
    • Enable or disable the use of the WebSocket API for trading. Use WS API if True else HTTP API.
  • use_http_batch_api : bool, default False
    • Bybit's WebSocket trading API currently does not support batch operations, only single-order handling. This parameter provides a toggle to use the HTTP batch API for order batch operations instead of the WebSocket API.
  • ws_trade_timeout_secs : float, default 5.0
    • Specifies the timeout in seconds to wait for ACK message from the WebSocket trading API.
  • base_url_ws_private : str, optional
    • Customizable WebSocket URL for private channel.
  • base_url_ws_trade : str, optional
    • Customizable WebSocket URL for trading channel.

Type of change

  • New feature (non-breaking change which adds functionality)

How has this change been tested?

I replaced nautilus_trader.adapters.bybit and all its submodules with the local monkey_patch.adapters.bybit using monkey patching.
This setup has been running in my production strategy environment for about a week without any issues observed so far.

@sunlei sunlei changed the title Add WebSocket API Trading Support for Bybit Add WebSocket API trading support for Bybit Dec 18, 2024
Copy link

codspeed-hq bot commented Dec 18, 2024

CodSpeed Performance Report

Merging #2129 will not alter performance

Comparing sunlei/bybit-add-ws-trading (029e646) with develop (2d572e2)

Summary

✅ 52 untouched benchmarks

@cjdsellers
Copy link
Member

Many thanks @sunlei these are great changes!

@cjdsellers cjdsellers merged commit 7f6b566 into develop Dec 18, 2024
11 checks passed
@cjdsellers cjdsellers deleted the sunlei/bybit-add-ws-trading branch December 18, 2024 20:55
@filipmacek
Copy link
Member

@sunlei Awesome job. Do you have any metrics around the round-trip latency difference between HTTP API and WSS API when placing orders? It would be interesting to compare them. @cjdsellers and I were actually talking about this a few weeks ago.

@sunlei
Copy link
Collaborator Author

sunlei commented Dec 19, 2024

@filipmacek

I haven’t measured the round-trip latency yet. Currently, the metrics in my strategy focus primarily on internal computation time and overall operation duration.

These statistics are written to a file, and then I use Vector to convert the JSON-formatted log files into the Logfmt format, which is eventually sent to VictoriaMetrics.

My original plan was to calculate the round-trip latency after implementing WebSocket-based order placement by tracking events like on_order_accepted, on_order_canceled, and on_order_submitted.

Once I gather these statistics, I can share the results publicly.

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

Successfully merging this pull request may close these issues.

3 participants