diff --git a/QuantConnect.BybitBrokerage/BybitBrokerage.cs b/QuantConnect.BybitBrokerage/BybitBrokerage.cs index b7534cc..a47d597 100644 --- a/QuantConnect.BybitBrokerage/BybitBrokerage.cs +++ b/QuantConnect.BybitBrokerage/BybitBrokerage.cs @@ -242,7 +242,12 @@ private void Initialize(string baseWssUrl, string restApiUrl, string apiKey, str ValidateSubscription(); _privateWebSocketUrl = $"{baseWssUrl}/v5/private"; - var basePublicWebSocketUrl = $"{baseWssUrl}/v5/public"; + // Bybit demo trading exposes only private/trading endpoints and reuses mainnet for public market data. + // See https://bybit-exchange.github.io/docs/v5/demo + var publicWssUrl = baseWssUrl.Contains("-demo", StringComparison.OrdinalIgnoreCase) + ? "wss://stream.bybit.com" + : baseWssUrl; + var basePublicWebSocketUrl = $"{publicWssUrl}/v5/public"; Initialize(_privateWebSocketUrl, new BybitWebSocketWrapper(), httpClient: null, apiKey, apiSecret); diff --git a/QuantConnect.BybitBrokerage/BybitBrokerageFactory.cs b/QuantConnect.BybitBrokerage/BybitBrokerageFactory.cs index ea6529e..f7e8475 100644 --- a/QuantConnect.BybitBrokerage/BybitBrokerageFactory.cs +++ b/QuantConnect.BybitBrokerage/BybitBrokerageFactory.cs @@ -46,9 +46,11 @@ public class BybitBrokerageFactory : BrokerageFactory { { "bybit-api-secret", Config.Get("bybit-api-secret") }, { "bybit-api-key", Config.Get("bybit-api-key") }, - // paper trading available using https://api-testnet.bybit.com + // demo (paper) trading: https://api-demo.bybit.com (https://bybit-exchange.github.io/docs/v5/demo) + // testnet: https://api-testnet.bybit.com { "bybit-api-url", Config.Get("bybit-api-url", "https://api.bybit.com") }, - // paper trading available using wss://stream-testnet.bybit.com + // demo (paper) trading: wss://stream-demo.bybit.com + // testnet: wss://stream-testnet.bybit.com { "bybit-websocket-url", Config.Get("bybit-websocket-url", "wss://stream.bybit.com") }, { "bybit-vip-level", Config.Get("bybit-vip-level", "VIP0") }, // load holdings if available diff --git a/README.md b/README.md index 7668372..6eebd31 100644 --- a/README.md +++ b/README.md @@ -131,6 +131,24 @@ Follow these steps to start local live trading with the Bybit brokerage: If you already have a live environment configured in your [Lean configuration file](https://www.quantconnect.com/docs/v2/lean-cli/initialization/configuration#03-Lean-Configuration), you can skip the interactive wizard by providing the `--environment ` option in step 2. The value of this option must be the name of an environment which has `live-mode` set to true. +### Demo (paper) and testnet trading + +To trade against [Bybit's Demo Trading](https://bybit-exchange.github.io/docs/v5/demo) — a sandboxed account that uses real mainnet market data — set the following in your Lean configuration and use API keys issued from Bybit's Demo Trading portal: + +``` +"bybit-api-url": "https://api-demo.bybit.com", +"bybit-websocket-url": "wss://stream-demo.bybit.com" +``` + +Public market data automatically falls back to mainnet (`wss://stream.bybit.com`), since demo trading does not expose its own public stream. + +To use the fully isolated [Bybit testnet](https://testnet.bybit.com/) (separate market data and accounts) instead, set: + +``` +"bybit-api-url": "https://api-testnet.bybit.com", +"bybit-websocket-url": "wss://stream-testnet.bybit.com" +``` + ## Account Types Bybit supports cash and margin accounts.