Bybit exchange plugin for bt_api — Unified REST API for Spot and Linear (USDT-M) Futures trading.
bt_api_bybit is a runtime plugin for bt_api that connects to Bybit exchange. It depends on bt_api_base for core infrastructure.
Asset Type Code REST Description Spot BYBIT___SPOT✅ Spot trading Linear Futures BYBIT___LINEAR✅ USDT-margined perpetual futures
Category Operation Spot Linear Market Data get_tick / get_ticker✅ ✅ get_depth✅ ✅ get_kline✅ ✅ get_exchange_info✅ ✅ get_server_time✅ ✅ get_deals✅ ✅ Account get_balance✅ ✅ get_account✅ ✅ Trading make_order✅ ✅ cancel_order✅ ✅ query_order✅ ✅
Auto-registers at import time via ExchangeRegistry. Works seamlessly with BtApi:
from bt_api_py import BtApi api = BtApi (exchange_kwargs = {
"BYBIT___SPOT" : {
"api_key" : "your_api_key" ,
"secret" : "your_secret" ,
},
"BYBIT___LINEAR" : {
"api_key" : "your_api_key" ,
"secret" : "your_secret" ,
},
})
# Spot market data (public - no auth required) ticker = api .get_tick ("BYBIT___SPOT" , "BTCUSDT" )
# Linear futures ticker ticker_swap = api .get_tick ("BYBIT___LINEAR" , "BTCUSDT" )
# Account balance (requires auth) balance = api .get_balance ("BYBIT___SPOT" )
# Place order (requires auth) order = api .make_order (
exchange_name = "BYBIT___SPOT" ,
symbol = "BTCUSDT" ,
volume = 0.001 ,
price = 67000 ,
order_type = "limit" ,
)git clone https://github.com/cloudQuant/bt_api_bybit
cd bt_api_bybit
pip install -e . Python 3.9 – 3.14 bt_api_base >= 0.152. Get ticker (public — no API key needed) from bt_api_py import BtApi api = BtApi ()
ticker = api .get_tick ("BYBIT___SPOT" , "BTCUSDT" )
print (f"BTCUSDT spot price: { ticker } " )3. Place an order (requires API key) from bt_api_py import BtApi api = BtApi (exchange_kwargs = {
"BYBIT___SPOT" : {
"api_key" : "your_api_key" ,
"secret" : "your_secret" ,
}
})
order = api .make_order (
exchange_name = "BYBIT___SPOT" ,
symbol = "BTCUSDT" ,
volume = 0.001 ,
price = 67000 ,
order_type = "limit" ,
)
print (f"Order placed: { order } " )from bt_api_py import BtApi api = BtApi (exchange_kwargs = {
"BYBIT___LINEAR" : {
"api_key" : "your_api_key" ,
"secret" : "your_secret" ,
}
})
# Get linear futures ticker ticker = api .get_tick ("BYBIT___LINEAR" , "BTCUSDT" )
# Place linear futures order order = api .make_order (
exchange_name = "BYBIT___LINEAR" ,
symbol = "BTCUSDT" ,
volume = 0.001 ,
price = 67000 ,
order_type = "limit" ,
)bt_api_bybit/
├── plugin.py # register_plugin() — bt_api plugin entry point
├── registry_registration.py # register_bybit() — feeds / exchange_data registration
├── exchange_data/
│ └── bybit_exchange_data.py # BybitExchangeData base + Spot/Swap subclasses
├── feeds/
│ ├── request_base.py # BybitRequestData — REST base class
│ ├── spot.py # BybitRequestDataSpot — spot operations
│ └── swap.py # BybitRequestDataSwap — linear futures operations
├── containers/
│ ├── tickers/ # Ticker containers
│ ├── orderbooks/ # OrderBook containers
│ ├── orders/ # Order containers
│ └── balances/ # Balance containers
└── errors/
└── bybit_translator.py # BybitErrorTranslator → bt_api_base.ApiError
Spot : BTCUSDT, ETHUSDT, SOLUSDT, XRPUSDT, and 100+ more trading pairsLinear Futures : BTCUSDT, ETHUSDT, SOLUSDT, BNBUSDT, and 100+ perpetual futuresAll Bybit API errors are translated to bt_api_base ApiError subclasses:
Bybit Code Error Description 0Success No error 10001PARAM_ERRORMissing or invalid parameter 10003PARAM_ERRORInvalid request format 10004REQUEST_ERRORInvalid request path 10005RESPONSE_ERRORInvalid response format 10006RATE_LIMITRate limit exceeded 10010ACCOUNT_ERRORAccount error 10012BALANCE_ERRORInsufficient balance 10014SYMBOL_ERRORSymbol not found 10016ORDER_NOT_FOUNDOrder not found 10017ORDER_ERRORInvalid order price or quantity 10020MARKET_ERRORMarket closed 10029ORDER_ERRORDuplicate order 11001LEVERAGE_ERRORInvalid leverage 11003MARGIN_ERRORInsufficient margin 13000API_KEY_ERRORAPI key error 13001AUTH_ERRORSignature verification failed 13002AUTH_ERRORInvalid IP address 13003AUTH_ERRORMissing API key 13004AUTH_ERRORInvalid timestamp 13005AUTH_ERRORPermission denied
Endpoint Limit Public endpoints 600 requests/minute Private endpoints 60 requests/minute Order placement 200 requests/minute
MIT — see LICENSE .
bt_api 的 Bybit 交易所插件 — 为现货 和** USDT 永续合约**交易提供统一的 REST API。
bt_api_bybit 是 bt_api 的运行时插件,连接 Bybit 交易所。依赖 bt_api_base 提供核心基础设施。
资产类型 代码 REST 说明 现货 BYBIT___SPOT✅ 现货交易 线性合约 BYBIT___LINEAR✅ USDT 保证金永续合约
类别 操作 现货 线性合约 行情数据 get_tick / get_ticker✅ ✅ get_depth✅ ✅ get_kline✅ ✅ get_exchange_info✅ ✅ get_server_time✅ ✅ get_deals✅ ✅ 账户 get_balance✅ ✅ get_account✅ ✅ 交易 make_order✅ ✅ cancel_order✅ ✅ query_order✅ ✅
通过 ExchangeRegistry 在导入时自动注册,与 BtApi 无缝协作:
from bt_api_py import BtApi api = BtApi (exchange_kwargs = {
"BYBIT___SPOT" : {
"api_key" : "your_api_key" ,
"secret" : "your_secret" ,
},
"BYBIT___LINEAR" : {
"api_key" : "your_api_key" ,
"secret" : "your_secret" ,
},
})
# 现货行情(公开接口,无需认证) ticker = api .get_tick ("BYBIT___SPOT" , "BTCUSDT" )
# 线性合约行情 ticker_swap = api .get_tick ("BYBIT___LINEAR" , "BTCUSDT" )
# 账户余额(需要认证) balance = api .get_balance ("BYBIT___SPOT" )
# 下单(需要认证) order = api .make_order (
exchange_name = "BYBIT___SPOT" ,
symbol = "BTCUSDT" ,
volume = 0.001 ,
price = 67000 ,
order_type = "limit" ,
)git clone https://github.com/cloudQuant/bt_api_bybit
cd bt_api_bybit
pip install -e . Python 3.9 – 3.14 bt_api_base >= 0.15from bt_api_py import BtApi api = BtApi ()
ticker = api .get_tick ("BYBIT___SPOT" , "BTCUSDT" )
print (f"BTCUSDT 现货价格: { ticker } " )from bt_api_py import BtApi api = BtApi (exchange_kwargs = {
"BYBIT___SPOT" : {
"api_key" : "your_api_key" ,
"secret" : "your_secret" ,
}
})
order = api .make_order (
exchange_name = "BYBIT___SPOT" ,
symbol = "BTCUSDT" ,
volume = 0.001 ,
price = 67000 ,
order_type = "limit" ,
)
print (f"订单已下单: { order } " )from bt_api_py import BtApi api = BtApi (exchange_kwargs = {
"BYBIT___LINEAR" : {
"api_key" : "your_api_key" ,
"secret" : "your_secret" ,
}
})
# 获取线性合约行情 ticker = api .get_tick ("BYBIT___LINEAR" , "BTCUSDT" )
# 下线性合约订单 order = api .make_order (
exchange_name = "BYBIT___LINEAR" ,
symbol = "BTCUSDT" ,
volume = 0.001 ,
price = 67000 ,
order_type = "limit" ,
)bt_api_bybit/
├── plugin.py # register_plugin() — bt_api 插件入口点
├── registry_registration.py # register_bybit() — feeds / exchange_data 注册
├── exchange_data/
│ └── bybit_exchange_data.py # BybitExchangeData 基类 + Spot/Swap 子类
├── feeds/
│ ├── request_base.py # BybitRequestData — REST 基类
│ ├── spot.py # BybitRequestDataSpot — 现货操作
│ └── swap.py # BybitRequestDataSwap — 线性合约操作
├── containers/
│ ├── tickers/ # 行情容器
│ ├── orderbooks/ # 订单簿容器
│ ├── orders/ # 订单容器
│ └── balances/ # 余额容器
└── errors/
└── bybit_translator.py # BybitErrorTranslator → bt_api_base.ApiError
现货 : BTCUSDT, ETHUSDT, SOLUSDT, XRPUSDT 等 100+ 交易对线性合约 : BTCUSDT, ETHUSDT, SOLUSDT, BNBUSDT 等 100+ 永续合约所有 Bybit API 错误均翻译为 bt_api_base ApiError 子类:
Bybit 错误码 错误类型 说明 0成功 无错误 10001PARAM_ERROR缺少或无效参数 10003PARAM_ERROR无效请求格式 10004REQUEST_ERROR无效请求路径 10005RESPONSE_ERROR无效响应格式 10006RATE_LIMIT请求过于频繁 10010ACCOUNT_ERROR账户错误 10012BALANCE_ERROR余额不足 10014SYMBOL_ERROR交易对未找到 10016ORDER_NOT_FOUND订单未找到 10017ORDER_ERROR无效订单价格或数量 10020MARKET_ERROR市场已关闭 10029ORDER_ERROR重复订单 11001LEVERAGE_ERROR无效杠杆 11003MARGIN_ERROR保证金不足 13000API_KEY_ERRORAPI key 错误 13001AUTH_ERROR签名验证失败 13002AUTH_ERRORIP 地址无效 13003AUTH_ERROR缺少 API key 13004AUTH_ERROR无效时间戳 13005AUTH_ERROR权限不足
端点 限制 公开接口 600 次/分钟 私有接口 60 次/分钟 下单接口 200 次/分钟
MIT — 详见 LICENSE 。