Skip to content

Repository files navigation

Bitunix Exchange Plugin for bt_api

Bitunix | 比特统一

PyPI VersionPython VersionsLicenseCIDocs


English | 中文

Overview

This package provides Bitunix exchange plugin for the bt_api framework. It offers a unified interface for interacting with Bitunix, a cryptocurrency exchange offering futures trading.

Bitunix provides trading in USDT and USD with various cryptocurrency pairs. This plugin integrates Bitunix's REST API into the bt_api unified trading framework.

Key Features

  • Complete REST API Coverage: Ticker, order book, klines, orders, balances
  • HMAC-SHA256 Authentication: Secure double SHA256 signature authentication
  • Unified Interface: Compatible with bt_api's BtApi, EventBus, and data containers
  • Async Support: Full async/await support for concurrent operations

Exchange Information

ItemValue
Exchange NameBitunix
Trading CodeBITUNIX___SPOT
REST API URLhttps://fapi.bitunix.com
WebSocket URLwss://fapi.bitunix.com/public
Asset TypeSPOT
Supported CurrenciesUSDT, USD
AuthenticationHMAC-SHA256 (double hash)

Installation

From PyPI (Recommended)

pip install bt_api_bitunix

From Source

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

Quick Start

Initialize the Exchange

frombt_api_pyimportBtApi# Configure Bitunix exchangeexchange_config= {
"BITUNIX___SPOT": {
"api_key": "your_api_key",
"secret_key": "your_secret_key",
}
}
# Initialize BtApiapi=BtApi(exchange_kwargs=exchange_config)

Get Market Data

# Get tickerticker=api.get_tick("BITUNIX___SPOT", "BTCUSDT")
print(ticker)
# Get order book depthdepth=api.get_depth("BITUNIX___SPOT", "BTCUSDT", limit=20)
print(depth)
# Get kline/candlestick dataklines=api.get_kline("BITUNIX___SPOT", "BTCUSDT", period="1h", count=100)
print(klines)
# Get exchange info (available trading pairs)exchange_info=api.get_exchange_info("BITUNIX___SPOT")
print(exchange_info)

Trading Operations

# Place an orderorder=api.make_order(
exchange_name="BITUNIX___SPOT",
symbol="BTCUSDT",
volume=0.01,
price=50000,
order_type="limit",
)
print(order)
# Cancel an ordercancel_result=api.cancel_order(
exchange_name="BITUNIX___SPOT",
symbol="BTCUSDT",
order_id="your_order_id",
)
print(cancel_result)
# Query order statusorder_info=api.query_order(
exchange_name="BITUNIX___SPOT",
symbol="BTCUSDT",
order_id="your_order_id",
)
print(order_info)
# Get open ordersopen_orders=api.get_open_orders("BITUNIX___SPOT", "BTCUSDT")
print(open_orders)
# Get account balancebalance=api.get_balance("BITUNIX___SPOT")
print(balance)
# Get account infoaccount=api.get_account("BITUNIX___SPOT")
print(account)

Asynchronous Operations

importasynciofrombt_api_pyimportBtApiasyncdefmain():
api=BtApi(exchange_kwargs={
"BITUNIX___SPOT": {
"api_key": "your_api_key",
"secret_key": "your_secret_key",
}
})
# Async get tickerticker=awaitapi.async_get_tick("BITUNIX___SPOT", "BTCUSDT")
print(ticker)
# Async place orderorder=awaitapi.async_make_order(
exchange_name="BITUNIX___SPOT",
symbol="BTCUSDT",
volume=0.01,
price=50000,
order_type="limit",
)
print(order)
asyncio.run(main())

Supported Operations

OperationREST APIDescription
get_tickGET /api/v1/futures/market/tickersGet ticker data
get_depthGET /api/v1/futures/market/depthGet order book depth
get_klineGET /api/v1/futures/market/klinesGet candlestick/kline data
get_exchange_infoGET /api/v1/futures/market/symbolsGet available trading pairs
make_orderPOST /api/v1/futures/trade/place_orderPlace a new order
cancel_orderPOST /api/v1/futures/trade/cancel_orderCancel an order
query_orderGET /api/v1/futures/trade/get_orderQuery order status
get_open_ordersGET /api/v1/futures/trade/get_open_ordersGet all open orders
get_balanceGET /api/v1/futures/account/balanceGet account balance
get_accountGET /api/v1/futures/accountGet account information

Symbol Format

Bitunix uses standard symbol format:

bt_api SymbolBitunix Symbol
BTCUSDTBTCUSDT
ETHUSDTETHUSDT
XRPUSDTXRPUSDT

The plugin automatically handles symbol formatting.

Authentication

Bitunix API uses HMAC-SHA256 double hash authentication:

Step 1: hash1 = SHA256(nonce + timestamp + api_key + query_params + body)
Step 2: signature = SHA256(hash1 + api_secret)

Required headers:

  • api-key — API key
  • nonce — UUID (32 characters)
  • timestamp — Unix timestamp in milliseconds
  • sign — HMAC-SHA256 signature

Kline Periods

PeriodBitunix Code
1 minute1m
5 minutes5m
15 minutes15m
30 minutes30m
1 hour1h
4 hours4h
1 day1d
1 week1w

Error Handling

All API errors are translated to bt_api's standard error types:

frombt_api_py.errorsimport (
RateLimitError,
AuthenticationError,
OrderNotFoundError,
InsufficientBalanceError,
)

Online Documentation

ResourceLink
English Docshttps://bt-api-bitunix.readthedocs.io/
Chinese Docshttps://bt-api-bitunix.readthedocs.io/zh/latest/
GitHub Repositoryhttps://github.com/cloudQuant/bt_api_bitunix
Issue Trackerhttps://github.com/cloudQuant/bt_api_bitunix/issues

Architecture

bt_api_bitunix/
├── src/bt_api_bitunix/ # Source code
│ ├── containers/ # Data containers
│ │ ├── balances/ # Balance data containers
│ │ ├── orders/ # Order data containers
│ │ ├── tickers/ # Ticker data containers
│ │ ├── bars/ # Bar data containers
│ │ ├── orderbooks/ # OrderBook data containers
│ │ └── accounts/ # Account data containers
│ ├── exchange_data/ # Exchange configuration
│ │ └── __init__.py # BitunixExchangeData class
│ ├── feeds/ # API feeds
│ │ └── live_bitunix/ # Live trading feed
│ │ ├── __init__.py # BitunixRequestData base class
│ │ ├── spot.py # Spot trading feed
│ │ └── request_base.py # Request base with signature logic
│ ├── errors/ # Error translations
│ └── plugin.py # Plugin registration
├── tests/ # Unit tests
└── docs/ # Documentation

Requirements

DependencyVersionDescription
Python>= 3.9Programming language
bt_api_base>= 0.15Core framework

Contributing

Contributions are welcome! Please follow these steps:

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add some amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

License

MIT License - see LICENSE for details.

Support


中文

概述

本包为 bt_api 框架提供 Bitunix(比特统一)交易所插件。Bitunix 是一家提供期货交易的加密货币交易所。

Bitunix 提供 USDT 和 USD 交易,以及各种加密货币交易对。本插件将 Bitunix 的 REST API 集成到 bt_api 统一交易框架中。

核心功能

  • 完整 REST API 覆盖:行情、订单簿、K线、订单、余额
  • HMAC-SHA256 认证:安全的双重 SHA256 签名认证
  • 统一接口:与 bt_api 的 BtApi、EventBus 和数据容器完全兼容
  • 异步支持:完整的 async/await 支持并发操作

交易所信息

项目
交易所名称Bitunix(比特统一)
交易代码BITUNIX___SPOT
REST API 地址https://fapi.bitunix.com
WebSocket 地址wss://fapi.bitunix.com/public
资产类型现货(SPOT)
支持法币USDT, USD
认证方式HMAC-SHA256(双重哈希)

安装

从 PyPI 安装(推荐)

pip install bt_api_bitunix

从源码安装

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

快速开始

初始化交易所

frombt_api_pyimportBtApi# 配置 Bitunix 交易所exchange_config= {
"BITUNIX___SPOT": {
"api_key": "your_api_key",
"secret_key": "your_secret_key",
}
}
# 初始化 BtApiapi=BtApi(exchange_kwargs=exchange_config)

获取市场数据

# 获取行情ticker=api.get_tick("BITUNIX___SPOT", "BTCUSDT")
print(ticker)
# 获取订单簿深度depth=api.get_depth("BITUNIX___SPOT", "BTCUSDT", limit=20)
print(depth)
# 获取 K 线数据klines=api.get_kline("BITUNIX___SPOT", "BTCUSDT", period="1h", count=100)
print(klines)
# 获取交易所信息(可用交易对)exchange_info=api.get_exchange_info("BITUNIX___SPOT")
print(exchange_info)

交易操作

# 下单order=api.make_order(
exchange_name="BITUNIX___SPOT",
symbol="BTCUSDT",
volume=0.01,
price=50000,
order_type="limit",
)
print(order)
# 取消订单cancel_result=api.cancel_order(
exchange_name="BITUNIX___SPOT",
symbol="BTCUSDT",
order_id="your_order_id",
)
print(cancel_result)
# 查询订单状态order_info=api.query_order(
exchange_name="BITUNIX___SPOT",
symbol="BTCUSDT",
order_id="your_order_id",
)
print(order_info)
# 获取挂单open_orders=api.get_open_orders("BITUNIX___SPOT", "BTCUSDT")
print(open_orders)
# 获取账户余额balance=api.get_balance("BITUNIX___SPOT")
print(balance)
# 获取账户信息account=api.get_account("BITUNIX___SPOT")
print(account)

异步操作

importasynciofrombt_api_pyimportBtApiasyncdefmain():
api=BtApi(exchange_kwargs={
"BITUNIX___SPOT": {
"api_key": "your_api_key",
"secret_key": "your_secret_key",
}
})
# 异步获取行情ticker=awaitapi.async_get_tick("BITUNIX___SPOT", "BTCUSDT")
print(ticker)
# 异步下单order=awaitapi.async_make_order(
exchange_name="BITUNIX___SPOT",
symbol="BTCUSDT",
volume=0.01,
price=50000,
order_type="limit",
)
print(order)
asyncio.run(main())

支持的操作

操作REST API说明
get_tickGET /api/v1/futures/market/tickers获取行情数据
get_depthGET /api/v1/futures/market/depth获取订单簿深度
get_klineGET /api/v1/futures/market/klines获取 K 线/蜡烛图数据
get_exchange_infoGET /api/v1/futures/market/symbols获取可用交易对
make_orderPOST /api/v1/futures/trade/place_order下新订单
cancel_orderPOST /api/v1/futures/trade/cancel_order取消订单
query_orderGET /api/v1/futures/trade/get_order查询订单状态
get_open_ordersGET /api/v1/futures/trade/get_open_orders获取所有挂单
get_balanceGET /api/v1/futures/account/balance获取账户余额
get_accountGET /api/v1/futures/account获取账户信息

交易对格式

Bitunix 使用标准交易对格式:

bt_api 交易对Bitunix 交易对
BTCUSDTBTCUSDT
ETHUSDTETHUSDT
XRPUSDTXRPUSDT

插件自动处理交易对格式。

认证方式

Bitunix API 使用 HMAC-SHA256 双重哈希认证:

第一步: hash1 = SHA256(nonce + timestamp + api_key + query_params + body)
第二步: signature = SHA256(hash1 + api_secret)

必需请求头:

  • api-key — API 密钥
  • nonce — UUID(32 个字符)
  • timestamp — 毫秒级 Unix 时间戳
  • sign — HMAC-SHA256 签名

K 线周期

周期Bitunix 代码
1 分钟1m
5 分钟5m
15 分钟15m
30 分钟30m
1 小时1h
4 小时4h
1 天1d
1 周1w

错误处理

所有 API 错误都会转换为 bt_api 的标准错误类型:

frombt_api_py.errorsimport (
RateLimitError, # 速率限制错误AuthenticationError, # 认证错误OrderNotFoundError, # 订单未找到InsufficientBalanceError, # 余额不足
)

在线文档

资源链接
英文文档https://bt-api-bitunix.readthedocs.io/
中文文档https://bt-api-bitunix.readthedocs.io/zh/latest/
GitHub 仓库https://github.com/cloudQuant/bt_api_bitunix
问题反馈https://github.com/cloudQuant/bt_api_bitunix/issues

系统要求

依赖版本说明
Python>= 3.9编程语言
bt_api_base>= 0.15核心框架

贡献

欢迎贡献代码!请遵循以下步骤:

  1. Fork 本仓库
  2. 创建功能分支 (git checkout -b feature/amazing-feature)
  3. 提交您的更改 (git commit -m 'Add some amazing feature')
  4. 推送到分支 (git push origin feature/amazing-feature)
  5. 开启 Pull Request

许可证

MIT 许可证 - 详见 LICENSE

技术支持


如果这个项目对您有帮助,请给我们一个 Star!

Star History Chart

About

Exchange adapter package for bt_api

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages