Skip to content

Add support for Bybit demo (paper) trading#41

Merged
Romazes merged 1 commit into
QuantConnect:masterfrom
AlexCatarino:feature/demo-trading
Apr 30, 2026
Merged

Add support for Bybit demo (paper) trading#41
Romazes merged 1 commit into
QuantConnect:masterfrom
AlexCatarino:feature/demo-trading

Conversation

@AlexCatarino
Copy link
Copy Markdown
Member

@AlexCatarino AlexCatarino commented Apr 27, 2026

Summary

  • Adds support for Bybit Demo Trading without requiring new config keys: when bybit-websocket-url points at stream-demo.bybit.com, the brokerage automatically routes the public market-data WebSocket back to mainnet (wss://stream.bybit.com), since demo trading only exposes private/trading endpoints and reuses live market data for public streams.
  • Updates the URL comments in BybitBrokerageFactory to list the demo and testnet endpoint pairs alongside the production defaults.
  • Documents the demo and testnet URL pairs in README.md, including the requirement that demo trading needs API keys issued from Bybit's Demo Trading portal (production keys are rejected).

To switch a deployment to demo trading, the user simply sets:

"bybit-api-url":       "https://api-demo.bybit.com",
"bybit-websocket-url": "wss://stream-demo.bybit.com"

Live and testnet behavior are unchanged.

Closes #36

Test plan

Verified end-to-end against Bybit demo trading using a basic-template spot algorithm:

image

What the screenshot above shows, and why it proves each piece works:

  • REST against api-demo.bybit.com — the demo cash book loads (BTC 1.00, ETH 1.00, USDC 50,000, USDT 50,000 — Bybit's standard demo balances), confirming the signed REST calls authenticate against the demo host.
  • Private trading WS connects to demoBrokerageTransactionHandler accepts and fills order ID 46125588 (Buy 0.001 BTCUSDT spot margin, filled at 76,835.6 USDT); the matching fill appears in the Bybit demo Order History panel.
  • Public market-data WS routes to mainnet — the trace logs show WebSocketClientWrapper.Connection opened ... wss://stream.bybit.com/v5/public/spot even though the configured bybit-websocket-url points at stream-demo.bybit.com. This is the demo-detection branch added in BybitBrokerage.Initialize doing its job.
  • OnData stream flowing — minute bars for BTCUSDT/ETHUSDT continue to print after the fill, confirming the public stream stays subscribed.

Notes

  • No new config keys, no new public API. The change is a single conditional inside Initialize, plus comments and docs.
  • Existing testnet usage (which the test suite still relies on) is unaffected — the -demo host check does not match -testnet.

Detect demo trading from the configured WebSocket URL and route the public
market-data stream to mainnet, since Bybit's demo environment exposes only
private/trading endpoints and reuses live market data.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Copy link
Copy Markdown
Contributor

@Romazes Romazes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, thank you 😎

Related PRs

PR Remarks

Bybit environments

URL matrix

Environment REST Private WS Public WS (market data)
Mainnet (real money) https://api.bybit.com wss://stream.bybit.com/v5/private wss://stream.bybit.com/v5/public
Mainnet Demo (paper) https://api-demo.bybit.com wss://stream-demo.bybit.com/v5/private wss://stream.bybit.com/v5/public (mainnet fallback)
Testnet https://api-testnet.bybit.com wss://stream-testnet.bybit.com/v5/private wss://stream-testnet.bybit.com/v5/public

References

@Romazes Romazes merged commit df6952f into QuantConnect:master Apr 30, 2026
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.

Add Support for Demo Accounts

3 participants