Bybit
Config
class BybitDataClientConfig
Bases: LiveDataClientConfig
Configuration for BybitDataClient
instances.
- Parameters:
- api_key (str , optional) – The Bybit API public key.
If
None
then will source the BYBIT_API_KEY or BYBIT_TESTNET_API_KEY environment variables. - api_secret (str , optional) – The Bybit API public key.
If
None
then will source the BYBIT_API_SECRET or BYBIT_TESTNET_API_SECRET environment variables. - product_types (list [BybitProductType ] , optional) – The Bybit product type for the client. If not specified then will use all products.
- 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.
- api_key (str , optional) – The Bybit API public key.
If
api_key : str | None
api_secret : str | None
product_types : list[BybitProductType] | None
base_url_http : str | None
demo : bool
testnet : bool
update_instruments_interval_mins : Annotated[int, msgspec.Meta(gt=0)] | 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 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
None
then will source the BYBIT_API_KEY or BYBIT_TESTNET_API_KEY environment variables. - api_secret (str , optional) – The Bybit API public key.
If
None
then will source the BYBIT_API_KEY or BYBIT_TESTNET_API_KEY environment variables. - product_type (list [BybitProductType ] , optional) – The Bybit product type 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.
- 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).
- max_retries (PositiveInt , optional) – The maximum number of times a submit, cancel or modify order request will be retried.
- retry_delay (PositiveFloat , optional) – The delay (seconds) between retries. Short delays with frequent retries may result in account bans.
- 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
product_types : list[BybitProductType] | None
base_url_http : str | None
base_url_ws : str | None
demo : bool
testnet : bool
use_gtd : bool
max_retries : Annotated[int, msgspec.Meta(gt=0)] | None
retry_delay : Annotated[float, msgspec.Meta(gt=0.0)] | 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 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
Factories
get_bybit_http_client(clock: LiveClock, key: str | None = None, secret: str | None = None, base_url: str | None = None, is_demo: bool = False, is_testnet: bool = False) → BybitHttpClient
Cache and return a Bybit HTTP client with the given key and secret.
If a cached client with matching parameters already exists, the cached client will be returned.
- Parameters:
- clock (LiveClock) – The clock for the client.
- key (str , optional) – The API key for the client.
- secret (str , optional) – The API secret for the client.
- base_url (str , optional) – The base URL for the API endpoints.
- is_demo (bool , default False) – If the client is connecting to the demo API.
- is_testnet (bool , default False) – If the client is connecting to the testnet API.
- Return type: BybitHttpClient
get_bybit_instrument_provider(client: BybitHttpClient, clock: LiveClock, product_types: frozenset[BybitProductType], config: InstrumentProviderConfig) → BybitInstrumentProvider
Cache and return a Bybit instrument provider.
If a cached provider already exists, then that cached provider will be returned.
- Parameters:
- client (BybitHttpClient) – The client for the instrument provider.
- clock (LiveClock) – The clock for the instrument provider.
- product_types (list [BybitProductType ]) – The product types to load.
- is_testnet (bool) – If the provider is for the Spot testnet.
- config (InstrumentProviderConfig) – The configuration for the instrument provider.
- Return type: BybitInstrumentProvider
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
Enums
raise_error(error)
class BybitPositionIdx
Bases: Enum
ONE_WAY = 0
BUY_HEDGE = 1
SELL_HEDGE = 2
class BybitAccountType
Bases: Enum
UNIFIED = 'UNIFIED'
class BybitProductType
Bases: Enum
SPOT = 'spot'
LINEAR = 'linear'
INVERSE = 'inverse'
OPTION = 'option'
property is_spot : bool
property is_linear : bool
property is_inverse : bool
property is_option : bool
class BybitContractType
Bases: Enum
LINEAR_PERPETUAL = 'LinearPerpetual'
LINEAR_FUTURE = 'LinearFutures'
INVERSE_PERPETUAL = 'InversePerpetual'
INVERSE_FUTURE = 'InverseFutures'
class BybitOptionType
Bases: Enum
CALL = 'Call'
PUT = 'Put'
class BybitPositionSide
Bases: Enum
FLAT = ''
BUY = 'Buy'
SELL = 'Sell'
parse_to_position_side() → PositionSide
class BybitKlineInterval
Bases: Enum
MINUTE_1 = '1'
MINUTE_3 = '3'
MINUTE_5 = '5'
MINUTE_15 = '15'
MINUTE_30 = '30'
HOUR_1 = '60'
HOUR_2 = '120'
HOUR_4 = '240'
HOUR_6 = '360'
HOUR_12 = '720'
DAY_1 = 'D'
WEEK_1 = 'W'
MONTH_1 = 'M'
class BybitOrderStatus
Bases: Enum
CREATED = 'Created'
NEW = 'New'
REJECTED = 'Rejected'
PARTIALLY_FILLED = 'PartiallyFilled'
PARTIALLY_FILLED_CANCELED = 'PartiallyFilledCanceled'
FILLED = 'Filled'
CANCELED = 'Cancelled'
UNTRIGGERED = 'Untriggered'
TRIGGERED = 'Triggered'
DEACTIVATED = 'Deactivated'
class BybitOrderSide
Bases: Enum
BUY = 'Buy'
SELL = 'Sell'
class BybitOrderType
Bases: Enum
MARKET = 'Market'
LIMIT = 'Limit'
UNKNOWN = 'UNKNOWN'
class BybitStopOrderType
Bases: Enum