Skip to content

Repository files navigation

bt_api_bybit

PyPI VersionPython VersionsLicenseCIDocs


bt_api_bybit

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.

ResourceLink
English Docshttps://bt-api-bybit.readthedocs.io/
Chinese Docshttps://bt-api-bybit.readthedocs.io/zh/latest/
GitHubhttps://github.com/cloudQuant/bt_api_bybit
PyPIhttps://pypi.org/project/bt_api_bybit/
Issueshttps://github.com/cloudQuant/bt_api_bybit/issues
bt_api_basehttps://bt-api-base.readthedocs.io/
Main Projecthttps://github.com/cloudQuant/bt_api_py

Features

2 Asset Types

Asset TypeCodeRESTDescription
SpotBYBIT___SPOTSpot trading
Linear FuturesBYBIT___LINEARUSDT-margined perpetual futures

Supported Operations

CategoryOperationSpotLinear
Market Dataget_tick / get_ticker
get_depth
get_kline
get_exchange_info
get_server_time
get_deals
Accountget_balance
get_account
Tradingmake_order
cancel_order
query_order

Plugin Architecture

Auto-registers at import time via ExchangeRegistry. Works seamlessly with BtApi:

frombt_api_pyimportBtApiapi=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 tickerticker_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",
)

Installation

From PyPI (Recommended)

pip install bt_api_bybit

From Source

git clone https://github.com/cloudQuant/bt_api_bybit
cd bt_api_bybit
pip install -e .

Requirements

  • Python 3.93.14
  • bt_api_base >= 0.15

Quick Start

1. Install

pip install bt_api_bybit

2. Get ticker (public — no API key needed)

frombt_api_pyimportBtApiapi=BtApi()
ticker=api.get_tick("BYBIT___SPOT", "BTCUSDT")
print(f"BTCUSDT spot price: {ticker}")

3. Place an order (requires API key)

frombt_api_pyimportBtApiapi=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}")

4. Linear Futures

frombt_api_pyimportBtApiapi=BtApi(exchange_kwargs={
"BYBIT___LINEAR": {
"api_key": "your_api_key",
"secret": "your_secret",
}
})
# Get linear futures tickerticker=api.get_tick("BYBIT___LINEAR", "BTCUSDT")
# Place linear futures orderorder=api.make_order(
exchange_name="BYBIT___LINEAR",
symbol="BTCUSDT",
volume=0.001,
price=67000,
order_type="limit",
)

Architecture

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

Supported Symbols

  • Spot: BTCUSDT, ETHUSDT, SOLUSDT, XRPUSDT, and 100+ more trading pairs
  • Linear Futures: BTCUSDT, ETHUSDT, SOLUSDT, BNBUSDT, and 100+ perpetual futures

Error Handling

All Bybit API errors are translated to bt_api_base ApiError subclasses:

Bybit CodeErrorDescription
0SuccessNo 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

Rate Limits

EndpointLimit
Public endpoints600 requests/minute
Private endpoints60 requests/minute
Order placement200 requests/minute

Documentation

DocLink
Englishhttps://bt-api-bybit.readthedocs.io/
中文https://bt-api-bybit.readthedocs.io/zh/latest/
bt_api_basehttps://bt-api-base.readthedocs.io/
Main Projecthttps://cloudquant.github.io/bt_api_py/

License

MIT — see LICENSE.


Support



中文

bt_api 的 Bybit 交易所插件 — 为现货和** USDT 永续合约**交易提供统一的 REST API。

bt_api_bybitbt_api 的运行时插件,连接 Bybit 交易所。依赖 bt_api_base 提供核心基础设施。

资源链接
英文文档https://bt-api-bybit.readthedocs.io/
中文文档https://bt-api-bybit.readthedocs.io/zh/latest/
GitHubhttps://github.com/cloudQuant/bt_api_bybit
PyPIhttps://pypi.org/project/bt_api_bybit/
问题反馈https://github.com/cloudQuant/bt_api_bybit/issues
bt_api_basehttps://bt-api-base.readthedocs.io/
主项目https://github.com/cloudQuant/bt_api_py

功能特点

2 种资产类型

资产类型代码REST说明
现货BYBIT___SPOT现货交易
线性合约BYBIT___LINEARUSDT 保证金永续合约

支持的操作

类别操作现货线性合约
行情数据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 无缝协作:

frombt_api_pyimportBtApiapi=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",
)

安装

从 PyPI 安装(推荐)

pip install bt_api_bybit

从源码安装

git clone https://github.com/cloudQuant/bt_api_bybit
cd bt_api_bybit
pip install -e .

系统要求

  • Python 3.93.14
  • bt_api_base >= 0.15

快速开始

1. 安装

pip install bt_api_bybit

2. 获取行情(公开接口,无需 API key)

frombt_api_pyimportBtApiapi=BtApi()
ticker=api.get_tick("BYBIT___SPOT", "BTCUSDT")
print(f"BTCUSDT 现货价格: {ticker}")

3. 下单交易(需要 API key)

frombt_api_pyimportBtApiapi=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}")

4. 线性合约

frombt_api_pyimportBtApiapi=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 次/分钟

文档

文档链接
英文文档https://bt-api-bybit.readthedocs.io/
中文文档https://bt-api-bybit.readthedocs.io/zh/latest/
bt_api_basehttps://bt-api-base.readthedocs.io/
主项目https://cloudquant.github.io/bt_api_py/

许可证

MIT — 详见 LICENSE


技术支持

About

Exchange adapter package for bt_api

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages