Bybit Exchange¶
Bybit Account Types¶
Bybit provides multiple account types. For testing environment, you can use account types with _TESTNET suffix.
from nexustrader.exchange.bybit import BybitAccountType
account_type = BybitAccountType.LINEAR # or other account types
BybitAccountType.SPOT: Spot accountBybitAccountType.LINEAR: Linear perpetual accountBybitAccountType.INVERSE: Inverse perpetual accountBybitAccountType.OPTION: Option accountBybitAccountType.UNIFIED: Unified accountBybitAccountType.SPOT_TESTNET: Spot testnet accountBybitAccountType.LINEAR_TESTNET: Linear perpetual testnet accountBybitAccountType.INVERSE_TESTNET: Inverse perpetual testnet accountBybitAccountType.OPTION_TESTNET: Option testnet accountBybitAccountType.UNIFIED_TESTNET: Unified testnet account
Note
For PrivateConnectorConfig, BYBIT Exchange only needs to use BybitAccountType.UNIFIED for live trading, else use BybitAccountType.UNIFIED_TESTNET for testing.
Bybit Config¶
The most important part is the config object. You need to pass the config object to the Engine class. The config receives the following parameters:
strategy_id: The id of the strategyuser_id: The id of the userstrategy: The strategy classbasic_config: The basic config of the exchangepublic_conn_config: The public connector config of the exchangeprivate_conn_config: The private connector config of the exchange
from nexustrader.exchange.bybit import BybitAccountType
from nexustrader.config import Config, PublicConnectorConfig, PrivateConnectorConfig, BasicConfig
# The strategy code....
config = Config(
strategy_id="bybit_buy_and_sell",
user_id="user_test",
strategy=Demo(),
basic_config={
ExchangeType.BYBIT: BasicConfig(
settings_key="BYBIT.TESTNET",
testnet=True,
)
},
public_conn_config={
ExchangeType.BYBIT: [
PublicConnectorConfig(
account_type=BybitAccountType.LINEAR_TESTNET,
),
PublicConnectorConfig(
account_type=BybitAccountType.SPOT_TESTNET,
),
]
},
private_conn_config={
ExchangeType.BYBIT: [
PrivateConnectorConfig(
account_type=BybitAccountType.UNIFIED_TESTNET,
)
]
}
)
engine = Engine(config)
if __name__ == "__main__":
try:
engine.start()
finally:
engine.dispose()