Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion QuantConnect.BybitBrokerage/BybitBrokerage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
6 changes: 4 additions & 2 deletions QuantConnect.BybitBrokerage/BybitBrokerageFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 18 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 <value>` 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.
Expand Down