BitMart exchange plugin for bt_api — Unified REST API for Spot trading with market data, trading operations, and account management.
bt_api_bitmart is a runtime plugin for bt_api that connects to BitMart exchange. It depends on bt_api_base for core infrastructure.
| Resource | Link |
|---|---|
| English Docs | https://bt-api-bitmart.readthedocs.io/ |
| Chinese Docs | https://bt-api-bitmart.readthedocs.io/zh/latest/ |
| GitHub | https://github.com/cloudQuant/bt_api_bitmart |
| PyPI | https://pypi.org/project/bt_api_bitmart/ |
| Issues | https://github.com/cloudQuant/bt_api_bitmart/issues |
| bt_api_base | https://bt-api-base.readthedocs.io/ |
| Main Project | https://github.com/cloudQuant/bt_api_py |
| Asset Type | Code | REST | Description |
|---|---|---|---|
| Spot | BITMART___SPOT | ✅ | Spot trading |
- Market Data — Ticker, order book depth, k-lines, trade history
- Trading — Place orders, cancel orders, query order status, get open orders
- Account — Account info, balance queries
Auto-registers at import time via ExchangeRegistry. Works seamlessly with BtApi:
frombt_api_pyimportBtApiapi=BtApi(exchange_kwargs={
"BITMART___SPOT": {
"api_key": "your_key",
"secret": "your_secret",
"memo": "your_memo",
}
})
ticker=api.get_tick("BITMART___SPOT", "BTCUSDT")
balance=api.get_balance("BITMART___SPOT")
order=api.make_order(exchange_name="BITMART___SPOT", symbol="BTCUSDT", volume=0.001, price=50000, order_type="limit")All exchange responses normalized to bt_api_base container types:
TickContainer— 24hr rolling tickerOrderBookContainer— Order book depthBarContainer— K-line/candlestickTradeContainer— Individual tradesOrderContainer— Order status and fillsAccountBalanceContainer— Asset balances
pip install bt_api_bitmartgit clone https://github.com/cloudQuant/bt_api_bitmart
cd bt_api_bitmart
pip install -e .- Python
3.9–3.14 bt_api_base >= 0.15requestsfor HTTP clientwebsocket-clientfor WebSocket (future)aiohttpfor async HTTP
pip install bt_api_bitmartfrombt_api_pyimportBtApiapi=BtApi()
ticker=api.get_tick("BITMART___SPOT", "BTCUSDT")
print(f"BTCUSDT price: {ticker}")frombt_api_pyimportBtApiapi=BtApi(exchange_kwargs={
"BITMART___SPOT": {
"api_key": "your_api_key",
"secret": "your_api_secret",
"memo": "your_memo",
}
})
order=api.make_order(
exchange_name="BITMART___SPOT",
symbol="BTCUSDT",
volume=0.001,
price=50000,
order_type="limit",
)
print(f"Order placed: {order}")frombt_api_pyimportBtApiapi=BtApi(exchange_kwargs={
"BITMART___SPOT": {
"api_key": "your_api_key",
"secret": "your_api_secret",
"memo": "your_memo",
}
})
# Query specific orderorder=api.query_order(exchange_name="BITMART___SPOT", order_id="your_order_id")
print(f"Order status: {order}")
# Get all open ordersopen_orders=api.get_open_orders("BITMART___SPOT")
print(f"Open orders: {open_orders}")frombt_api_pyimportBtApiapi=BtApi(exchange_kwargs={
"BITMART___SPOT": {
"api_key": "your_api_key",
"secret": "your_api_secret",
"memo": "your_memo",
}
})
balance=api.get_balance("BITMART___SPOT")
print(f"Balance: {balance}")bt_api_bitmart/
├── plugin.py # register_plugin() — bt_api plugin entry point
├── registry_registration.py # register() — feeds / exchange_data registration
├── __init__.py # Package exports
├── exchange_data/
│ └── __init__.py # BitmartExchangeData, BitmartExchangeDataSpot
├── feeds/
│ └── live_bitmart/
│ ├── __init__.py # Module exports
│ ├── spot.py # BitmartRequestDataSpot — all SPOT REST endpoints
│ └── request_base.py # BitmartRequestData — base class with signature logic
├── containers/
│ ├── __init__.py
│ ├── orders/__init__.py
│ ├── balances/__init__.py
│ ├── accounts/__init__.py
│ ├── bars/__init__.py
│ ├── tickers/__init__.py
│ └── orderbooks/__init__.py
└── errors/
└── __init__.py
| Category | Operation | Notes |
|---|---|---|
| Market Data | get_ticker / get_tick | 24hr rolling ticker |
get_depth | Order book depth (max 50 levels) | |
get_kline / get_bars | K-line/candlestick (1m to 1M) | |
get_trades / get_trade_history | Recent trade history | |
get_server_time | Server time sync | |
get_exchange_info | Exchange symbol info | |
| Account | get_balance | Asset balances |
get_account | Full account info | |
| Trading | make_order | Place limit/market orders |
cancel_order | Cancel single order | |
query_order | Query order by ID | |
get_open_orders | All open orders | |
get_deals | Order deal history |
| Environment | REST API | WebSocket |
|---|---|---|
| Production | https://api-cloud.bitmart.com | wss://ws-manager-compress.bitmart.com/api?protocol=1.1 |
BitMart API uses HMAC-SHA256 signature:
Message = timestamp#memo#body_str
Signature = HMAC-SHA256(api_secret, Message)
Required headers:
X-BM-KEY— API keyX-BM-TIMESTAMP— Timestamp in millisecondsX-BM-SIGN— HMAC-SHA256 signature
BitMart uses underscore format: BTCUSDT, ETHUSDT
| Period | BitMart Code |
|---|---|
| 1m | 1 |
| 3m | 3 |
| 5m | 5 |
| 15m | 15 |
| 30m | 30 |
| 45m | 45 |
| 1h | 60 |
| 2h | 120 |
| 3h | 180 |
| 4h | 240 |
| 1d | 1440 |
| 1w | 10080 |
| 1M | 43200 |
All BitMart API errors are translated to bt_api_base ApiError subclasses. Common error codes:
| Code | Description |
|---|---|
| 1000 | Success |
| 50000-59999 | API error |
| 50002 | Invalid signature |
| 50003 | Invalid API key |
| 50004 | Invalid timestamp |
| 50005 | Permission denied |
| 50006 | Too many requests |
| Endpoint Type | Limit |
|---|---|
| Public endpoints | 200 requests/10s |
| Private endpoints | 100 requests/10s |
| Order placement | 200 requests/10s |
| Doc | Link |
|---|---|
| English | https://bt-api-bitmart.readthedocs.io/ |
| 中文 | https://bt-api-bitmart.readthedocs.io/zh/latest/ |
| API Reference | https://bt-api-bitmart.readthedocs.io/api/ |
| bt_api_base | https://bt-api-base.readthedocs.io/ |
| Main Project | https://cloudquant.github.io/bt_api_py/ |
MIT — see LICENSE.
- GitHub Issues — bug reports, feature requests
- Email: yunjinqi@gmail.com
bt_api 的 BitMart 交易所插件 — 为现货交易提供统一的 REST API,包括市场数据、交易操作和账户管理。
bt_api_bitmart 是 bt_api 的运行时插件,连接 BitMart 交易所。依赖 bt_api_base 提供核心基础设施。
| 资产类型 | 代码 | REST | 说明 |
|---|---|---|---|
| 现货 | BITMART___SPOT | ✅ | 现货交易 |
- 市场数据 — 行情、订单簿深度、K线、成交历史
- 交易 — 下单、撤单、查询订单状态、获取挂单
- 账户 — 账户信息、余额查询
通过 ExchangeRegistry 在导入时自动注册,与 BtApi 无缝协作:
frombt_api_pyimportBtApiapi=BtApi(exchange_kwargs={
"BITMART___SPOT": {
"api_key": "your_key",
"secret": "your_secret",
"memo": "your_memo",
}
})
ticker=api.get_tick("BITMART___SPOT", "BTCUSDT")
balance=api.get_balance("BITMART___SPOT")
order=api.make_order(exchange_name="BITMART___SPOT", symbol="BTCUSDT", volume=0.001, price=50000, order_type="limit")所有交易所响应规范化为 bt_api_base 容器类型:
TickContainer— 24小时滚动行情OrderBookContainer— 订单簿深度BarContainer— K线/蜡烛图TradeContainer— 逐笔成交OrderContainer— 订单状态和成交AccountBalanceContainer— 资产余额
pip install bt_api_bitmartgit clone https://github.com/cloudQuant/bt_api_bitmart
cd bt_api_bitmart
pip install -e .- Python
3.9–3.14 bt_api_base >= 0.15requestsHTTP 客户端websocket-clientWebSocket(未来)aiohttp异步 HTTP
pip install bt_api_bitmartfrombt_api_pyimportBtApiapi=BtApi()
ticker=api.get_tick("BITMART___SPOT", "BTCUSDT")
print(f"BTCUSDT 价格: {ticker}")frombt_api_pyimportBtApiapi=BtApi(exchange_kwargs={
"BITMART___SPOT": {
"api_key": "your_api_key",
"secret": "your_api_secret",
"memo": "your_memo",
}
})
order=api.make_order(
exchange_name="BITMART___SPOT",
symbol="BTCUSDT",
volume=0.001,
price=50000,
order_type="limit",
)
print(f"订单已下单: {order}")frombt_api_pyimportBtApiapi=BtApi(exchange_kwargs={
"BITMART___SPOT": {
"api_key": "your_api_key",
"secret": "your_api_secret",
"memo": "your_memo",
}
})
# 查询指定订单order=api.query_order(exchange_name="BITMART___SPOT", order_id="your_order_id")
print(f"订单状态: {order}")
# 获取所有挂单open_orders=api.get_open_orders("BITMART___SPOT")
print(f"挂单: {open_orders}")frombt_api_pyimportBtApiapi=BtApi(exchange_kwargs={
"BITMART___SPOT": {
"api_key": "your_api_key",
"secret": "your_api_secret",
"memo": "your_memo",
}
})
balance=api.get_balance("BITMART___SPOT")
print(f"余额: {balance}")bt_api_bitmart/
├── plugin.py # register_plugin() — bt_api 插件入口
├── registry_registration.py # register() — feeds / exchange_data 注册
├── __init__.py # 包导出
├── exchange_data/
│ └── __init__.py # BitmartExchangeData, BitmartExchangeDataSpot
├── feeds/
│ └── live_bitmart/
│ ├── __init__.py # 模块导出
│ ├── spot.py # BitmartRequestDataSpot — 所有 SPOT REST 端点
│ └── request_base.py # BitmartRequestData — 带签名逻辑的基类
├── containers/
│ ├── __init__.py
│ ├── orders/__init__.py
│ ├── balances/__init__.py
│ ├── accounts/__init__.py
│ ├── bars/__init__.py
│ ├── tickers/__init__.py
│ └── orderbooks/__init__.py
└── errors/
└── __init__.py
| 类别 | 操作 | 说明 |
|---|---|---|
| 市场数据 | get_ticker / get_tick | 24小时滚动行情 |
get_depth | 订单簿深度(最大50档) | |
get_kline / get_bars | K线(1分钟到1月) | |
get_trades / get_trade_history | 近期成交历史 | |
get_server_time | 服务器时间同步 | |
get_exchange_info | 交易所交易对信息 | |
| 账户 | get_balance | 资产余额 |
get_account | 完整账户信息 | |
| 交易 | make_order | 下限价/市价单 |
cancel_order | 撤销订单 | |
query_order | 按ID查询订单 | |
get_open_orders | 所有挂单 | |
get_deals | 订单成交历史 |
| 环境 | REST API | WebSocket |
|---|---|---|
| 生产环境 | https://api-cloud.bitmart.com | wss://ws-manager-compress.bitmart.com/api?protocol=1.1 |
BitMart API 使用 HMAC-SHA256 签名:
Message = timestamp#memo#body_str
Signature = HMAC-SHA256(api_secret, Message)
必需请求头:
X-BM-KEY— API 密钥X-BM-TIMESTAMP— 毫秒级时间戳X-BM-SIGN— HMAC-SHA256 签名
BitMart 使用下划线格式:BTCUSDT、ETHUSDT
| 周期 | BitMart 代码 |
|---|---|
| 1分钟 | 1 |
| 3分钟 | 3 |
| 5分钟 | 5 |
| 15分钟 | 15 |
| 30分钟 | 30 |
| 45分钟 | 45 |
| 1小时 | 60 |
| 2小时 | 120 |
| 3小时 | 180 |
| 4小时 | 240 |
| 1天 | 1440 |
| 1周 | 10080 |
| 1月 | 43200 |
所有 BitMart API 错误均翻译为 bt_api_base ApiError 子类。常见错误码:
| 代码 | 说明 |
|---|---|
| 1000 | 成功 |
| 50000-59999 | API 错误 |
| 50002 | 签名无效 |
| 50003 | API 密钥无效 |
| 50004 | 时间戳无效 |
| 50005 | 权限被拒绝 |
| 50006 | 请求过于频繁 |
| 端点类型 | 限制 |
|---|---|
| 公开接口 | 200 请求/10秒 |
| 私有接口 | 100 请求/10秒 |
| 下单接口 | 200 请求/10秒 |
MIT — 详见 LICENSE。
- GitHub Issues — bug 报告、功能请求
- 邮箱: yunjinqi@gmail.com