-
Notifications
You must be signed in to change notification settings - Fork 0
Bybit
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.
Bybit 成立于 2018 年,是全球交易量最大的加密货币交易所之一,拥有大量的加密资产和加密衍生品未平仓合约。此集成支持 Bybit 的实时市场数据获取和订单执行。
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.
以下文档假定交易者正在设置实时市场数据馈送和交易执行。完整的 Bybit 集成由各种组件组成,可以根据用户的需求一起使用或单独使用。
BybitHttpClient
: Low-level HTTP API connectivity.BybitHttpClient
:低级 HTTP API 连接。BybitWebSocketClient
: Low-level WebSocket API connectivity.BybitWebSocketClient
:低级 WebSocket API 连接。BybitInstrumentProvider
: Instrument parsing and loading functionality.BybitInstrumentProvider
:Instrument解析和加载功能。BybitDataClient
: A market data feed manager.BybitDataClient
:市场数据馈送管理器。BybitExecutionClient
: An account management and trade execution gateway.BybitExecutionClient
:账户管理和交易执行网关。BybitLiveDataClientFactory
: Factory for Bybit data clients (used by the trading node builder).BybitLiveDataClientFactory
:Bybit 数据客户端的工厂(由交易节点构建器使用)。BybitLiveExecClientFactory
: Factory for Bybit execution clients (used by the trading node builder).BybitLiveExecClientFactory
:Bybit 执行客户端的工厂(由交易节点构建器使用)。
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 provides extensive documentation for users which can be found in the Bybit help center. It’s recommended you also refer to the Bybit documentation in conjunction with this NautilusTrader integration guide.
Bybit 为用户提供了大量的文档,可以在 Bybit 帮助中心找到。建议您还参考 Bybit 文档以及此 NautilusTrader 集成指南。
A product is an umbrella term for a group of related instrument types.
产品是相关Instrument类型组的总称。
Product is also referred to as category in the Bybit v5 API.
在 Bybit v5 API 中,产品也称为类别。
The following product types are supported on Bybit:
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).
期权合约目前不受支持(将在未来版本中实现)。
To distinguish between different product types on Bybit, the following instrument ID suffix’s are used:
为了区分 Bybit 上的不同产品类型,使用以下Instrument ID 后缀:
-SPOT
: Spot cryptocurrencies.-SPOT
:现货加密货币。-LINEAR
: Perpetual and futures contracts.-LINEAR
:永续合约和期货合约。-INVERSE
: Inverse perpetual and inverse futures contracts.-INVERSE
:反向永续合约和反向期货合约。-OPTION
: Options contracts (not currently supported).-OPTION
:期权合约(当前不受支持)。
These suffixes must be appended to the Bybit raw symbol string to identify the specific product type for the instrument ID. For example:
这些后缀必须附加到 Bybit 原始符号字符串以标识Instrument ID 的特定产品类型。例如:
- The Ether/Tether spot currency pair is identified with
-SPOT
, such asETHUSDT-SPOT
. 以太坊/泰达币现货货币对用-SPOT
标识,例如ETHUSDT-SPOT
。- The BTCUSDT perpetual futures contract is identified with
-LINEAR
, such asBTCUSDT-LINEAR
. BTCUSDT 永续期货合约用-LINEAR
标识,例如BTCUSDT-LINEAR
。- The BTCUSD inverse perpetual futures contract is identified with
-INVERSE
, such asBTCUSD-INVERSE
. BTCUSD 反向永续期货合约用-INVERSE
标识,例如BTCUSD-INVERSE
。
Bybit offers a flexible combination of trigger types, enabling a broader range of Nautilus orders. All the order types listed below can be used as either entries or exits, except for trailing stops (which utilize a position-related API).
Bybit 提供灵活的触发类型组合,支持更广泛的 Nautilus 订单。下面列出的所有订单类型都可以用作入场或出场,除了追踪止损(使用与头寸相关的 API)。
Spot | Derivatives (Linear, Inverse, Options) | |
---|---|---|
MARKET | ✓ | ✓ |
LIMIT | ✓ | ✓ |
STOP_MARKET | ✓ | ✓ |
STOP_LIMIT | ✓ | ✓ |
MARKET_IF_TOUCHED | ✓ | ✓ |
LIMIT_IF_TOUCHED | ✓ | ✓ |
TRAILING_STOP_MARKET | ✓ |
The following limitations apply to SPOT products, as positions are not tracked on the venue side:
以下限制适用于现货产品,因为交易平台端不跟踪头寸:
reduce_only
orders are not supported. 不支持reduce_only
订单。- Trailing stop orders are not supported. 不支持追踪止损订单。
Trailing stops on Bybit do not have a client order ID on the venue side (though there is a
venue_order_id
). This is because trailing stops are associated with a netted position for an instrument. Consider the following points when using trailing stops on Bybit:Bybit 上的追踪止损在交易平台端没有客户端订单 ID(尽管有一个
venue_order_id
)。这是因为追踪止损与Instrument的净头寸相关联。在 Bybit 上使用追踪止损时,请考虑以下几点:
reduce_only
instruction is available. 可以使用reduce_only
指令。- When the position associated with a trailing stop is closed, the trailing stop is automatically "deactivated" (closed) on the venue side. 当与追踪止损相关联的头寸平仓时,追踪止损会在交易平台端自动“停用”(关闭)。
- You cannot query trailing stop orders that are not already open (the
venue_order_id
is unknown until then). 您无法查询尚未打开的追踪止损订单(在此之前venue_order_id
未知)。- You can manually adjust the trigger price in the GUI, which will update the Nautilus order. 您可以在 GUI 中手动调整触发价格,这将更新 Nautilus 订单。
The product types for each client must be specified in the configurations.
每个客户端的产品类型必须在配置中指定。
If no product types are specified then all product types will be loaded and available.
如果未指定产品类型,则将加载所有产品类型并使其可用。
Because Nautilus does not support a "unified" account, the account type must be either cash or margin. This means there is a limitation that you cannot specify
SPOT
with any of the other derivative product types.由于 Nautilus 不支持“统一”账户,因此账户类型必须是现金或保证金。这意味着您不能将
SPOT
与任何其他衍生产品类型一起指定。
CASH
account type will be used forSPOT
products.CASH
账户类型将用于SPOT
产品。MARGIN
account type will be used for all other derivative products.MARGIN
账户类型将用于所有其他衍生产品。
The most common use case is to configure a live
TradingNode
to include Bybit data and execution clients. To achieve this, add aBYBIT
section to your client configuration(s):最常见的用例是配置实时
TradingNode
以包含 Bybit 数据和执行客户端。为此,请将BYBIT
部分添加到您的客户端配置中:
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:然后,创建一个
TradingNode
并添加客户端工厂:
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()
There are two options for supplying your credentials to the Bybit clients. Either pass the corresponding
api_key
andapi_secret
values to the configuration objects, or set the following environment variables:向 Bybit 客户端提供凭据有两种选择。将相应的
api_key
和api_secret
值传递给配置对象,或者设置以下环境变量:
For Bybit live clients, you can set:
对于 Bybit 实时客户端,您可以设置:
BYBIT_API_KEY
BYBIT_API_SECRET
For Bybit demo clients, you can set:
对于 Bybit 演示客户端,您可以设置:
BYBIT_DEMO_API_KEY
BYBIT_DEMO_API_SECRET
For Bybit testnet clients, you can set:
对于 Bybit 测试网客户端,您可以设置:
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.
启动交易节点时,您将立即收到您的凭据是否有效以及是否具有交易权限的确认。