Skip to content

Repository files navigation

bt_api_bitmart

PyPI VersionPython VersionsLicenseCIDocs


bt_api_bitmart

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.

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

Features

1 Asset Type

Asset TypeCodeRESTDescription
SpotBITMART___SPOTSpot trading

REST API

  • 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

Plugin Architecture

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")

Unified Data Containers

All exchange responses normalized to bt_api_base container types:

  • TickContainer — 24hr rolling ticker
  • OrderBookContainer — Order book depth
  • BarContainer — K-line/candlestick
  • TradeContainer — Individual trades
  • OrderContainer — Order status and fills
  • AccountBalanceContainer — Asset balances

Installation

From PyPI (Recommended)

pip install bt_api_bitmart

From Source

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

Requirements

  • Python 3.93.14
  • bt_api_base >= 0.15
  • requests for HTTP client
  • websocket-client for WebSocket (future)
  • aiohttp for async HTTP

Quick Start

1. Install

pip install bt_api_bitmart

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

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

3. Place an order (requires API key)

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

4. Query order status

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

5. Get account balance

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

Architecture

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

Supported Operations

CategoryOperationNotes
Market Dataget_ticker / get_tick24hr rolling ticker
get_depthOrder book depth (max 50 levels)
get_kline / get_barsK-line/candlestick (1m to 1M)
get_trades / get_trade_historyRecent trade history
get_server_timeServer time sync
get_exchange_infoExchange symbol info
Accountget_balanceAsset balances
get_accountFull account info
Tradingmake_orderPlace limit/market orders
cancel_orderCancel single order
query_orderQuery order by ID
get_open_ordersAll open orders
get_dealsOrder deal history

BitMart API Details

Base URLs

EnvironmentREST APIWebSocket
Productionhttps://api-cloud.bitmart.comwss://ws-manager-compress.bitmart.com/api?protocol=1.1

Authentication

BitMart API uses HMAC-SHA256 signature:

Message = timestamp#memo#body_str
Signature = HMAC-SHA256(api_secret, Message)

Required headers:

  • X-BM-KEY — API key
  • X-BM-TIMESTAMP — Timestamp in milliseconds
  • X-BM-SIGN — HMAC-SHA256 signature

Symbol Format

BitMart uses underscore format: BTCUSDT, ETHUSDT

Supported Periods for K-lines

PeriodBitMart Code
1m1
3m3
5m5
15m15
30m30
45m45
1h60
2h120
3h180
4h240
1d1440
1w10080
1M43200

Error Handling

All BitMart API errors are translated to bt_api_base ApiError subclasses. Common error codes:

CodeDescription
1000Success
50000-59999API error
50002Invalid signature
50003Invalid API key
50004Invalid timestamp
50005Permission denied
50006Too many requests

Rate Limits

Endpoint TypeLimit
Public endpoints200 requests/10s
Private endpoints100 requests/10s
Order placement200 requests/10s

Documentation

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

License

MIT — see LICENSE.


Support



中文

bt_api 的 BitMart 交易所插件 — 为现货交易提供统一的 REST API,包括市场数据、交易操作和账户管理。

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

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

功能特点

1 种资产类型

资产类型代码REST说明
现货BITMART___SPOT现货交易

REST API

  • 市场数据 — 行情、订单簿深度、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 — 资产余额

安装

从 PyPI 安装(推荐)

pip install bt_api_bitmart

从源码安装

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

系统要求

  • Python 3.93.14
  • bt_api_base >= 0.15
  • requests HTTP 客户端
  • websocket-client WebSocket(未来)
  • aiohttp 异步 HTTP

快速开始

1. 安装

pip install bt_api_bitmart

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

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

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

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

4. 查询订单状态

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

5. 获取账户余额

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_tick24小时滚动行情
get_depth订单簿深度(最大50档)
get_kline / get_barsK线(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订单成交历史

BitMart API 详情

基础 URL

环境REST APIWebSocket
生产环境https://api-cloud.bitmart.comwss://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 使用下划线格式:BTCUSDTETHUSDT

K线周期

周期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-59999API 错误
50002签名无效
50003API 密钥无效
50004时间戳无效
50005权限被拒绝
50006请求过于频繁

限流配置

端点类型限制
公开接口200 请求/10秒
私有接口100 请求/10秒
下单接口200 请求/10秒

文档

文档链接
英文文档https://bt-api-bitmart.readthedocs.io/
中文文档https://bt-api-bitmart.readthedocs.io/zh/latest/
API 参考https://bt-api-bitmart.readthedocs.io/api/
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