Bybit
Bybit cryptocurreny exchange integration adapter.
This subpackage provides an instrument provider, data and execution clients, configurations, data types and constants for connecting to and interacting with Bybit’s API.
For convenience, the most commonly used symbols are re-exported at the
subpackage’s top level, so downstream code can simply import from
nautilus_trader.adapters.bybit.
class BybitDataClientConfig
Bases: LiveDataClientConfig
Configuration for BybitDataClient instances.
- Parameters:
- api_key (str , optional) – The Bybit API public key.
If 
Nonethen will source the BYBIT_API_KEY or BYBIT_TESTNET_API_KEY environment variables. - api_secret (str , optional) – The Bybit API public key.
If 
Nonethen will source the BYBIT_API_SECRET or BYBIT_TESTNET_API_SECRET environment variables. - product_types (tuple [BybitProductType , ... ] , optional) – The Bybit product types for the client. If not specified then will use all products.
 - base_url_http (str , optional) – The base URL for Bybit HTTP API.
If 
Nonethen will use the default URL based on environment. - http_proxy_url (str , optional) – Optional HTTP proxy URL.
 - ws_proxy_url (str , optional) – Optional WebSocket proxy URL. Note: WebSocket proxy support is not yet implemented. This field is reserved for future functionality. Use http_proxy_url for REST API proxy support.
 - demo (bool , default False) – If the client is connecting to the Bybit demo API.
 - testnet (bool , default False) – If the client is connecting to the Bybit testnet API.
 - update_instruments_interval_mins (PositiveInt or None , default 60) – The interval (minutes) between reloading instruments from the venue.
 - max_retries (PositiveInt , optional) – The maximum number of times an HTTP request will be retried.
 - retry_delay_initial_ms (PositiveInt , optional) – The initial delay (milliseconds) between retries.
 - retry_delay_max_ms (PositiveInt , optional) – The maximum delay (milliseconds) between retries.
 - recv_window_ms (PositiveInt , default 5000) – The receive window (milliseconds) for Bybit HTTP requests.
 - bars_timestamp_on_close (bool , default True) – If the ts_event timestamp for bars should be on the open or close or the bar. If True, then ts_event will be on the close of the bar.
 
 - api_key (str , optional) – The Bybit API public key.
If 
 
api_key : str | None
api_secret : str | None
bars_timestamp_on_close : bool
base_url_http : str | None
demo : bool
http_proxy_url : str | None
max_retries : PositiveInt | None
product_types : tuple[BybitProductType, ...] | None
recv_window_ms : PositiveInt
retry_delay_initial_ms : PositiveInt | None
retry_delay_max_ms : PositiveInt | None
testnet : bool
update_instruments_interval_mins : PositiveInt | None
ws_proxy_url : str | None
dict() → dict[str, Any]
Return a dictionary representation of the configuration.
- Return type: dict[str, Any]
 
classmethod fully_qualified_name() → str
Return the fully qualified name for the NautilusConfig class.
- Return type: str
 
handle_revised_bars : bool
property id : str
Return the hashed identifier for the configuration.
- Return type: str
 
instrument_provider : InstrumentProviderConfig
json() → bytes
Return serialized JSON encoded bytes.
- Return type: bytes
 
json_primitives() → dict[str, Any]
Return a dictionary representation of the configuration with JSON primitive types as values.
- Return type: dict[str, Any]
 
classmethod json_schema() → dict[str, Any]
Generate a JSON schema for this configuration class.
- Return type: dict[str, Any]
 
classmethod parse(raw: bytes | str) → Any
Return a decoded object of the given cls.
- Parameters:
- cls (type) – The type to decode to.
 - raw (bytes or str) – The raw bytes or JSON string to decode.
 
 - Return type: Any
 
routing : RoutingConfig
validate() → bool
Return whether the configuration can be represented as valid JSON.
- Return type: bool
 
class BybitExecClientConfig
Bases: LiveExecClientConfig
Configuration for BybitExecutionClient instances.
- Parameters:
- api_key (str , optional) – The Bybit API public key.
If 
Nonethen will source the BYBIT_API_KEY or BYBIT_TESTNET_API_KEY environment variables. - api_secret (str , optional) – The Bybit API public key.
If 
Nonethen will source the BYBIT_API_KEY or BYBIT_TESTNET_API_KEY environment variables. - product_types (tuple [BybitProductType , ... ] , optional) – The Bybit product types for the client. If None then will default to ‘SPOT’, you also cannot mix ‘SPOT’ with any other product type for execution, and it will use a CASH account type, vs MARGIN for the other derivative products.
 - base_url_http (str , optional) – The base URL for Bybit HTTP API.
If 
Nonethen will use the default URL based on environment. - base_url_ws_private (str , optional) – The base URL for the private WebSocket client.
 - base_url_ws_trade (str , optional) – The base URL for the trade WebSocket client.
 - http_proxy_url (str , optional) – Optional HTTP proxy URL.
 - ws_proxy_url (str , optional) – Optional WebSocket proxy URL. Note: WebSocket proxy support is not yet implemented. This field is reserved for future functionality. Use http_proxy_url for REST API proxy support.
 - demo (bool , default False) – If the client is connecting to the Bybit demo API.
 - testnet (bool , default False) – If the client is connecting to the Bybit testnet API.
 - use_gtd (bool , default False) – If False, then GTD time in force will be remapped to GTC (this is useful if managing GTD orders locally).
 - use_ws_execution_fast (bool , default False) – If use fast execution stream.
 - use_http_batch_api (bool , default False) – If the client is using http api to send batch order requests (deprecated).
 - use_spot_position_reports (bool , default False) – If True, wallet balances for SPOT instruments will be reported as positions:
- Positive balances are reported as LONG positions.
 - Negative balances (borrowing) are reported as SHORT positions.
 - Zero balances (after rounding to instrument precision) are reported as FLAT. WARNING: This may lead to unintended liquidation of wallet assets if strategies are not designed to handle spot positions appropriately.
 
 - ignore_uncached_instrument_executions (bool , default False) – If True, execution message for instruments not contained in the cache are ignored instead of raising an error.
 - max_retries (PositiveInt , optional) – The maximum number of times a submit, cancel or modify order request will be retried.
 - retry_delay_initial_ms (PositiveInt , optional) – The initial delay (milliseconds) between retries. Short delays with frequent retries may result in account bans.
 - retry_delay_max_ms (PositiveInt , optional) – The maximum delay (milliseconds) between retries.
 - recv_window_ms (PositiveInt , default 5000) – The receive window (milliseconds) for Bybit HTTP requests.
 - ws_trade_timeout_secs (PositiveFloat , default 5.0) – The timeout for trade websocket messages.
 - ws_auth_timeout_secs (PositiveFloat , default 5.0) – The timeout for auth websocket messages.
 - futures_leverages (dict *[*str , PositiveInt ] , optional) – The leverages for futures.
 - position_mode (dict *[*str , BybitPositionMode ] , optional) – The position mode for USDT perpetual and Inverse futures.
 - margin_mode (BybitMarginMode , optional) – Set Margin Mode.
 
 - api_key (str , optional) – The Bybit API public key.
If 
 
WARNING
A short retry_delay with frequent retries may result in account bans.
api_key : str | None
api_secret : str | None
base_url_http : str | None
base_url_ws_private : str | None
base_url_ws_trade : str | None
demo : bool
futures_leverages : dict[str, PositiveInt] | None
http_proxy_url : str | None
ignore_uncached_instrument_executions : bool
margin_mode : BybitMarginMode | None
max_retries : PositiveInt | None
position_mode : dict[str, BybitPositionMode] | None
product_types : tuple[BybitProductType, ...] | None
recv_window_ms : PositiveInt
retry_delay_initial_ms : PositiveInt | None
retry_delay_max_ms : PositiveInt | None
testnet : bool
use_gtd : bool
use_http_batch_api : bool
use_spot_position_reports : bool
use_ws_execution_fast : bool
ws_auth_timeout_secs : PositiveFloat | None
ws_proxy_url : str | None
ws_trade_timeout_secs : PositiveFloat | None
dict() → dict[str, Any]
Return a dictionary representation of the configuration.
- Return type: dict[str, Any]
 
classmethod fully_qualified_name() → str
Return the fully qualified name for the NautilusConfig class.
- Return type: str
 
property id : str
Return the hashed identifier for the configuration.
- Return type: str
 
instrument_provider : InstrumentProviderConfig
json() → bytes
Return serialized JSON encoded bytes.
- Return type: bytes
 
json_primitives() → dict[str, Any]
Return a dictionary representation of the configuration with JSON primitive types as values.
- Return type: dict[str, Any]
 
classmethod json_schema() → dict[str, Any]
Generate a JSON schema for this configuration class.
- Return type: dict[str, Any]
 
classmethod parse(raw: bytes | str) → Any
Return a decoded object of the given cls.
- Parameters:
- cls (type) – The type to decode to.
 - raw (bytes or str) – The raw bytes or JSON string to decode.
 
 - Return type: Any
 
routing : RoutingConfig
validate() → bool
Return whether the configuration can be represented as valid JSON.
- Return type: bool
 
class BybitInstrumentProvider
Bases: InstrumentProvider
Provides Nautilus instrument definitions from Bybit.
- Parameters:
- client (nautilus_pyo3.BybitHttpClient) – The Bybit HTTP client.
 - product_types (tuple [BybitProductType , ... ]) – The product types to load.
 - config (InstrumentProviderConfig , optional) – The instrument provider configuration, by default None.
 
 
add(instrument: Instrument) → None
Add the given instrument to the provider.
- Parameters: instrument (Instrument) – The instrument to add.
 
add_bulk(instruments: list[Instrument]) → None
Add the given instruments bulk to the provider.
- Parameters: instruments (list [Instrument ]) – The instruments to add.
 
add_currency(currency: Currency) → None
Add the given currency to the provider.
- Parameters: currency (Currency) – The currency to add.
 
property count : int
Return the count of instruments held by the provider.
- Return type: int
 
currencies() → dict[str, Currency]
Return all currencies held by the instrument provider.
- Return type: dict[str, Currency]
 
currency(code: str) → Currency | None
Return the currency with the given code (if found).
- Parameters: code (str) – The currency code.
 - Return type:
Currency or 
None - Raises: ValueError – If code is not a valid string.
 
find(instrument_id: InstrumentId) → Instrument | None
Return the instrument for the given instrument ID (if found).
- Parameters: instrument_id (InstrumentId) – The ID for the instrument
 - Return type:
Instrument or 
None 
get_all() → dict[InstrumentId, Instrument]
Return all loaded instruments as a map keyed by instrument ID.
If no instruments loaded, will return an empty dict.
- Return type: dict[InstrumentId, Instrument]
 
async initialize(reload: bool = False) → None
Initialize the instrument provider.
- Parameters: reload (bool , default False) – If True, then will always reload instruments. If False, then will immediately return if already loaded.
 
instruments_pyo3() → list[Any]
Return all Bybit PyO3 instrument definitions held by the provider.
- Return type: list[nautilus_pyo3.Instrument]
 
list_all() → list[Instrument]
Return all loaded instruments.
- Return type: list[Instrument]
 
load(instrument_id: InstrumentId, filters: dict | None = None) → None
Load the instrument for the given ID into the provider, optionally applying the given filters.
- Parameters:
- instrument_id (InstrumentId) – The instrument ID to load.
 - filters (frozendict *[*str , Any ] or dict *[*str , Any ] , optional) – The venue specific instrument loading filters to apply.
 
 
load_all(filters: dict | None = None) → None
Load the latest instruments into the provider, optionally applying the given filters.
- Parameters: filters (frozendict *[*str , Any ] or dict *[*str , Any ] , optional) – The venue specific instrument loading filters to apply.
 
async load_all_async(filters: dict | None = None) → None
Load the latest instruments into the provider asynchronously, optionally applying the given filters.
async load_async(instrument_id: InstrumentId, filters: dict | None = None) → None
Load the instrument for the given ID into the provider asynchronously, optionally applying the given filters.
- Parameters:
- instrument_id (InstrumentId) – The instrument ID to load.
 - filters (frozendict *[*str , Any ] or dict *[*str , Any ] , optional) – The venue specific instrument loading filters to apply.
 
 - Raises: ValueError – If instrument_id.venue is not equal to self.venue.
 
load_ids(instrument_ids: list[InstrumentId], filters: dict | None = None) → None
Load the instruments for the given IDs into the provider, optionally applying the given filters.
- Parameters:
- instrument_ids (list [InstrumentId ]) – The instrument IDs to load.
 - filters (frozendict *[*str , Any ] or dict *[*str , Any ] , optional) – The venue specific instrument loading filters to apply.
 
 
async load_ids_async(instrument_ids: list[InstrumentId], filters: dict | None = None) → None
Load the instruments for the given IDs into the provider, optionally applying the given filters.
- Parameters:
- instrument_ids (list [InstrumentId ]) – The instrument IDs to load.
 - filters (frozendict *[*str , Any ] or dict *[*str , Any ] , optional) – The venue specific instrument loading filters to apply.
 
 - Raises: ValueError – If any instrument_id.venue is not equal to self.venue.
 
property product_types : tuple[BybitProductType, ...]
Return the Bybit product types configured for the provider.
- Return type: tuple[BybitProductType, …]
 
class BybitLiveDataClientFactory
Bases: LiveDataClientFactory
Provides a Bybit live data client factory.
static create(loop: AbstractEventLoop, name: str, config: BybitDataClientConfig, msgbus: MessageBus, cache: Cache, clock: LiveClock) → BybitDataClient
Create a new Bybit data client.
- Parameters:
- loop (asyncio.AbstractEventLoop) – The event loop for the client.
 - name (str) – The custom client ID.
 - config (BybitDataClientConfig) – The client configuration.
 - msgbus (MessageBus) – The message bus for the client.
 - cache (Cache) – The cache for the client.
 - clock (LiveClock) – The clock for the instrument provider.
 
 - Return type: BybitDataClient
 
class BybitLiveExecClientFactory
Bases: LiveExecClientFactory
Provides a Bybit live execution client factory.
static create(loop: AbstractEventLoop, name: str, config: BybitExecClientConfig, msgbus: MessageBus, cache: Cache, clock: LiveClock) → BybitExecutionClient
Create a new Bybit execution client.
- Parameters:
- loop (asyncio.AbstractEventLoop) – The event loop for the client.
 - name (str) – The custom client ID.
 - config (BybitExecClientConfig) – The client configuration.
 - msgbus (MessageBus) – The message bus for the client.
 - cache (Cache) – The cache for the client.
 - clock (LiveClock) – The clock for the client.
 
 - Return type: BybitExecutionClient
 
class BybitOrderBookDeltaDataLoader
Bases: object
Provides a means of loading Bybit order book data.
classmethod load(file_path: PathLike[str] | str, nrows: int | None = None, product_type: BybitProductType = <BybitProductType.Linear: 'linear'>) → pd.DataFrame
Return the deltas pandas.DataFrame loaded from the given Zip file_path.
- Parameters:
- file_path (str , path object or file-like object) – The path to the Zip file.
 - nrows (int , optional) – The maximum number of rows to load.
 - product_type (BybitProductType , optional) – The product type to load.
 
 - Return type: pd.DataFrame
 
classmethod map_actions(update_type: str, size: float) → str
classmethod map_flags(update_type: str) → int
classmethod map_sides(side: str) → str
class BybitProductType
Bases: object
Product categories supported by the v5 API.
INVERSE = <BybitProductType.Inverse: 'inverse'>
Inverse = <BybitProductType.Inverse: 'inverse'>
LINEAR = <BybitProductType.Linear: 'linear'>
Linear = <BybitProductType.Linear: 'linear'>
OPTION = <BybitProductType.Option: 'option'>
Option = <BybitProductType.Option: 'option'>
SPOT = <BybitProductType.Spot: 'spot'>
Spot = <BybitProductType.Spot: 'spot'>
classmethod from_str(data)
name
value
static variants()
class BybitTickerData
Bases: object
Unified ticker data structure containing common fields across all product types.
This simplified ticker structure is designed to work across SPOT, LINEAR, and OPTION products, containing only the most commonly used fields.