Skip to content

Commit

Permalink
Add Bybit initial integration guide
Browse files Browse the repository at this point in the history
  • Loading branch information
cjdsellers committed Apr 7, 2024
1 parent 2821c48 commit 2745e09
Show file tree
Hide file tree
Showing 4 changed files with 177 additions and 2 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ into a unified interface. The following integrations are currently supported:
| [Binance](https://binance.com) | `BINANCE` | Crypto Exchange (CEX) | ![status](https://img.shields.io/badge/stable-green) | [Guide](https://docs.nautilustrader.io/integrations/binance.html) |
| [Binance US](https://binance.us) | `BINANCE` | Crypto Exchange (CEX) | ![status](https://img.shields.io/badge/stable-green) | [Guide](https://docs.nautilustrader.io/integrations/binance.html) |
| [Binance Futures](https://www.binance.com/en/futures) | `BINANCE` | Crypto Exchange (CEX) | ![status](https://img.shields.io/badge/stable-green) | [Guide](https://docs.nautilustrader.io/integrations/binance.html) |
| [Bybit](https://www.bybit.com) | `BYBIT` | Crypto Exchange (CEX) | ![status](https://img.shields.io/badge/building-orange) | |
| [Bybit](https://www.bybit.com) | `BYBIT` | Crypto Exchange (CEX) | ![status](https://img.shields.io/badge/beta-yellow) | [Guide](https://docs.nautilustrader.io/integrations/bybit.html) |
| [Databento](https://databento.com) | `DATABENTO` | Data Provider | ![status](https://img.shields.io/badge/beta-yellow) | [Guide](https://docs.nautilustrader.io/integrations/databento.html) |
| [Interactive Brokers](https://www.interactivebrokers.com) | `INTERACTIVE_BROKERS` | Brokerage (multi-venue) | ![status](https://img.shields.io/badge/stable-green) | [Guide](https://docs.nautilustrader.io/integrations/ib.html) |

Expand Down
1 change: 1 addition & 0 deletions docs/integrations/binance.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ pair, and the `BTCUSDT` perpetual futures contract (this symbol is used for _bot
E.g. for Binance Futures, the said instruments symbol is `BTCUSDT-PERP` within the Nautilus system boundary.

## Order types

| | Spot | Margin | Futures |
|------------------------|---------------------------------|---------------------------------|-------------------|
| `MARKET` ||||
Expand Down
173 changes: 173 additions & 0 deletions docs/integrations/bybit.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,173 @@
# Bybit

```{warning}
We are currently working on this integration guide.
```

Founded in 2018, Bybit is one of the largest cryptocurrency exchanges in terms
of daily trading volume, and open interest of crypto assets and crypto
derivative products. This integration supports live market data ingest and order
execution with Bybit.

## Overview

The following documentation assumes a trader is setting up for both live market
data feeds, and trade execution. The full Bybit integration consists of an assortment of components,
which can be used together or separately depending on the users needs.

- `BybitHttpClient` - Low-level HTTP API connectivity
- `BybitWebSocketClient` - Low-level WebSocket API connectivity
- `BybitInstrumentProvider` - Instrument parsing and loading functionality
- `BybitDataClient` - A market data feed manager
- `BybitExecutionClient` - An account management and trade execution gateway
- `BybitLiveDataClientFactory` - Factory for Bybit data clients (used by the trading node builder)
- `BybitLiveExecClientFactory` - Factory for Bybit execution clients (used by the trading node builder)

```{note}
Most users will simply define a configuration for a live trading node (as below),
and won't need to necessarily work with these lower level components directly.
```

## Bybit documentation

Bybit provides extensive documentation for users which can be found in the [Bybit help center](https://www.bybit.com/en/help-center).
It's recommended you also refer to the Bybit documentation in conjunction with this NautilusTrader integration guide.

## Products

A product is an umberalla term for a group of related instrument types.

```{note}
Product is also referred to as `category` in the Bybit v5 API.
```

The following product types are supported on Bybit:

- Spot cryptocurrencies
- Perpetual contracts
- Perpetual inverse contracts
- Futures contracts
- Futures inverse contracts

Options contracts are not currently supported (will be implemented in a future version)

## Symbology

To distinguish between different product types on Bybit, the following instrument ID suffix's are used:

- `-SPOT`: spot cryptocurrencies
- `-LINEAR`: perpeutal and futures contracts
- `-INVERSE`: inverse perpetual and inverse futures contracts
- `-OPTION`: options contracts (not currently supported)

These must be appended to the Bybit raw symbol string to be able to identify the specific
product type for the instrument ID, e.g. the Ether/Tether spot currency pair is identified with:

`ETHUSDT-SPOT`

The BTCUSDT perpetual futures contract is identified with:

`BTCUSDT-LINEAR`

The BTCUSD inverse perpetual futures contract is identified with:

`BTCUSD-INVERSE`

## Order types

```{warning}
Only Market and Limit orders have been tested and are available.
The remaining order types will be added on a best effort basis going forward.
```

| | Spot | Derivatives (Linear, Inverse, Options) |
|------------------------|----------------------|-----------------------------------------|
| `MARKET` |||
| `LIMIT` |||
| `STOP_MARKET` | | |
| `STOP_LIMIT` | | |
| `TRAILING_STOP_MARKET` | | |

## Configuration

The product types for each client must be specified in the configurations.

### Data clients

For data clients, if no product types are specified then all product types will
be loaded and available.

### Execution clients

For execution clients, there is a limitation that
you cannot specify `SPOT` with any of the other derivative product types.

- `CASH` account type will be used for `SPOT` products
- `MARGIN` account type will be used for all other derivative products

The most common use case is to configure a live `TradingNode` to include Bybit
data and execution clients. To achieve this, add a `BYBIT` section to your client
configuration(s):

```python
from nautilus_trader.adapters.bybit.common.enums import BybitProductType
from nautilus_trader.live.node import TradingNode

config = TradingNodeConfig(
..., # Omitted
data_clients={
"BYBIT": {
"api_key": "YOUR_BYBIT_API_KEY",
"api_secret": "YOUR_BYBIT_API_SECRET",
"base_url_http": None, # Override with custom endpoint
"product_types": [BybitProductType.LINEAR]
"testnet": False,
},
},
exec_clients={
"BYBIT": {
"api_key": "YOUR_BYBIT_API_KEY",
"api_secret": "YOUR_BYBIT_API_SECRET",
"base_url_http": None, # Override with custom endpoint
"product_types": [BybitProductType.LINEAR]
"testnet": False,
},
},
)
```

Then, create a `TradingNode` and add the client factories:

```python
from nautilus_trader.adapters.bybit.factories import BybitLiveDataClientFactory
from nautilus_trader.adapters.bybit.factories import BybitLiveExecClientFactory
from nautilus_trader.live.node import TradingNode

# Instantiate the live trading node with a configuration
node = TradingNode(config=config)

# Register the client factories with the node
node.add_data_client_factory("BYBIT", BybitLiveDataClientFactory)
node.add_exec_client_factory("BYBIT", BybitLiveExecClientFactory)

# Finally build the node
node.build()
```

### API credentials

There are two options for supplying your credentials to the Bybit clients.
Either pass the corresponding `api_key` and `api_secret` values to the configuration objects, or
set the following environment variables:

For Bybit live clients, you can set:
- `BYBIT_API_KEY`
- `BYBIT_API_SECRET`

For Bybit testnet clients, you can set:
- `BYBIT_TESTNET_API_KEY`
- `BYBIT_TESTNET_API_SECRET`

When starting the trading node, you'll receive immediate confirmation of whether your
credentials are valid and have trading permissions.

3 changes: 2 additions & 1 deletion docs/integrations/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
betfair.md
binance.md
bybit.md
databento.md
ib.md
```
Expand All @@ -23,7 +24,7 @@ into a unified interface. The following integrations are currently supported:
| [Binance](https://binance.com) | `BINANCE` | Crypto Exchange (CEX) | ![status](https://img.shields.io/badge/stable-green) | [Guide](https://docs.nautilustrader.io/integrations/binance.html) |
| [Binance US](https://binance.us) | `BINANCE` | Crypto Exchange (CEX) | ![status](https://img.shields.io/badge/stable-green) | [Guide](https://docs.nautilustrader.io/integrations/binance.html) |
| [Binance Futures](https://www.binance.com/en/futures) | `BINANCE` | Crypto Exchange (CEX) | ![status](https://img.shields.io/badge/stable-green) | [Guide](https://docs.nautilustrader.io/integrations/binance.html) |
| [Bybit](https://www.bybit.com) | `BYBIT` | Crypto Exchange (CEX) | ![status](https://img.shields.io/badge/building-orange) | |
| [Bybit](https://www.bybit.com) | `BYBIT` | Crypto Exchange (CEX) | ![status](https://img.shields.io/badge/beta-yellow) | [Guide](https://docs.nautilustrader.io/integrations/bybit.html) |
| [Databento](https://databento.com) | `DATABENTO` | Data Provider | ![status](https://img.shields.io/badge/beta-yellow) | [Guide](https://docs.nautilustrader.io/integrations/databento.html) |
| [Interactive Brokers](https://www.interactivebrokers.com) | `INTERACTIVE_BROKERS` | Brokerage (multi-venue) | ![status](https://img.shields.io/badge/stable-green) | [Guide](https://docs.nautilustrader.io/integrations/ib.html) |

Expand Down

0 comments on commit 2745e09

Please sign in to comment.