Add support for Bybit demo (paper) trading#41
Merged
Conversation
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>
Romazes
approved these changes
Apr 30, 2026
Contributor
There was a problem hiding this comment.
Nice, thank you 😎
Related PRs
PR Remarks
- Wrong the PR description template, check pull_request_template
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
11 tasks
Martin-Molinero
approved these changes
Apr 30, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
bybit-websocket-urlpoints atstream-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.BybitBrokerageFactoryto list the demo and testnet endpoint pairs alongside the production defaults.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:
Live and testnet behavior are unchanged.
Closes #36
Test plan
Verified end-to-end against Bybit demo trading using a basic-template spot algorithm:
What the screenshot above shows, and why it proves each piece works:
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.BrokerageTransactionHandleraccepts and fills order ID46125588(Buy 0.001 BTCUSDT spot margin, filled at 76,835.6 USDT); the matching fill appears in the Bybit demo Order History panel.WebSocketClientWrapper.Connection opened ... wss://stream.bybit.com/v5/public/spoteven though the configuredbybit-websocket-urlpoints atstream-demo.bybit.com. This is the demo-detection branch added inBybitBrokerage.Initializedoing its job.Notes
Initialize, plus comments and docs.-demohost check does not match-testnet.