English | 中文
This package provides Bitso exchange plugin for the bt_api framework. It offers a unified interface for interacting with Bitso, the largest cryptocurrency exchange in Latin America.
Bitso provides trading in Mexican Peso (MXN), USD, BTC, ETH, and other digital assets. This plugin integrates Bitso's REST API v3 into the bt_api unified trading framework.
- Complete REST API Coverage: Ticker, order book, klines, trades, orders, balances
- HMAC-SHA256 Authentication: Secure API key and secret key authentication
- Rate Limit Protection: Built-in rate limiter (60 requests/second per IP)
- Unified Interface: Compatible with bt_api's BtApi, EventBus, and data containers
- Async Support: Full async/await support for concurrent operations
| Item | Value |
|---|---|
| Exchange Name | Bitso |
| Trading Code | BITSO___SPOT |
| REST API URL | https://bitso.com/api/v3 |
| WebSocket URL | wss://ws.bitso.com |
| Asset Type | SPOT |
| Supported Currencies | MXN, USD, BTC, ETH, USDC |
| Rate Limit | 60 requests/second per IP |
| Authentication | Bearer Token + HMAC-SHA256 |
pip install bt_api_bitsogit clone https://github.com/cloudQuant/bt_api_bitso
cd bt_api_bitso
pip install -e .frombt_api_pyimportBtApi# Configure Bitso exchangeexchange_config= {
"BITSO___SPOT": {
"api_key": "your_api_key",
"secret_key": "your_secret_key",
}
}
# Initialize BtApiapi=BtApi(exchange_kwargs=exchange_config)# Get tickerticker=api.get_tick("BITSO___SPOT", "BTC/MXN")
print(ticker)
# Get order book depthdepth=api.get_depth("BITSO___SPOT", "BTC/MXN", limit=20)
print(depth)
# Get kline/candlestick dataklines=api.get_kline("BITSO___SPOT", "BTC/MXN", period="1h", count=100)
print(klines)
# Get recent tradestrades=api.get_trades("BITSO___SPOT", "BTC/MXN")
print(trades)# Place an orderorder=api.make_order(
exchange_name="BITSO___SPOT",
symbol="BTC/MXN",
volume=0.01,
price=500000,
order_type="buy-limit",
)
print(order)
# Cancel an ordercancel_result=api.cancel_order(
exchange_name="BITSO___SPOT",
symbol="BTC/MXN",
order_id="your_order_id",
)
print(cancel_result)
# Query order statusorder_info=api.query_order(
exchange_name="BITSO___SPOT",
symbol="BTC/MXN",
order_id="your_order_id",
)
print(order_info)
# Get open ordersopen_orders=api.get_open_orders("BITSO___SPOT", "BTC/MXN")
print(open_orders)
# Get account balancebalance=api.get_balance("BITSO___SPOT")
print(balance)importasynciofrombt_api_pyimportBtApiasyncdefmain():
api=BtApi(exchange_kwargs={
"BITSO___SPOT": {
"api_key": "your_api_key",
"secret_key": "your_secret_key",
}
})
# Async get tickerticker=awaitapi.async_get_tick("BITSO___SPOT", "BTC/MXN")
print(ticker)
# Async place orderorder=awaitapi.async_make_order(
exchange_name="BITSO___SPOT",
symbol="BTC/MXN",
volume=0.01,
price=500000,
order_type="buy-limit",
)
print(order)
asyncio.run(main())| Operation | REST API | Description |
|---|---|---|
get_tick | GET /ticker | Get ticker data (last price, volume, etc.) |
get_depth | GET /order_book | Get order book depth |
get_kline | GET /ohlc | Get candlestick/kline data |
get_trades | GET /trades | Get recent trades |
make_order | POST /orders | Place a new order |
cancel_order | DELETE /orders | Cancel an order |
query_order | GET /orders | Query order status |
get_open_orders | GET /open_orders | Get all open orders |
get_deals | GET /user_trades | Get user trade history |
get_balance | GET /balance | Get account balance |
get_account | GET /balance | Get account information |
get_server_time | GET /time | Get server time |
get_exchange_info | GET /available_books | Get available trading pairs |
Bitso uses lowercase symbols with underscore separator:
| bt_api Symbol | Bitso Symbol |
|---|---|
BTC/MXN | btc_mxn |
ETH/MXN | eth_mxn |
XRP/MXN | xrp_mxn |
BTC/USD | btc_usd |
The plugin automatically converts between formats.
Bitso supports the following order types:
| Order Type | Description |
|---|---|
buy-limit | Buy limit order |
sell-limit | Sell limit order |
buy-market | Buy market order |
sell-market | Sell market order |
Bitso implements a rate limit of 60 requests per second per IP address. This plugin includes a built-in rate limiter using sliding window algorithm to prevent exceeding the limit.
All API errors are translated to bt_api's standard error types:
frombt_api_py.errorsimport (
RateLimitError,
AuthenticationError,
OrderNotFoundError,
InsufficientBalanceError,
)| Resource | Link |
|---|---|
| English Docs | https://bt-api-bitso.readthedocs.io/ |
| Chinese Docs | https://bt-api-bitso.readthedocs.io/zh/latest/ |
| GitHub Repository | https://github.com/cloudQuant/bt_api_bitso |
| Bitso API Docs | https://bitso.com/api/v3 |
| Issue Tracker | https://github.com/cloudQuant/bt_api_bitso/issues |
bt_api_bitso/
├── src/bt_api_bitso/ # Source code
│ ├── containers/ # Data containers
│ │ ├── balances/ # Balance data containers
│ │ └── orders/ # Order data containers
│ ├── exchange_data/ # Exchange configuration
│ │ └── __init__.py # BitsoExchangeData class
│ ├── feeds/ # API feeds
│ │ └── live_bitso/ # Live trading feed
│ │ ├── __init__.py # BitsoRequestData base class
│ │ └── spot.py # Spot trading feed
│ ├── tickers/ # Ticker data containers
│ ├── errors/ # Error translations
│ └── plugin.py # Plugin registration
├── tests/ # Unit tests
└── docs/ # Documentation
| Dependency | Version | Description |
|---|---|---|
| Python | >= 3.9 | Programming language |
| bt_api_base | >= 0.15 | Core framework |
Contributions are welcome! Please follow these steps:
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add some amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
MIT License - see LICENSE for details.
- Report bugs via GitHub Issues
- Email: yunjinqi@gmail.com
本包为 bt_api 框架提供 Bitso(比特索)交易所插件。Bitso 是拉丁美洲最大的加密货币交易所,提供墨西哥比索(MXN)、美元(USD)、比特币(BTC)、以太坊(ETH)和其他数字资产的交易服务。
本插件将 Bitso 的 REST API v3 集成到 bt_api 统一交易框架中,提供标准化的行情查询、订单管理和账户查询接口。
- 完整 REST API 覆盖:行情、订单簿、K线、交易、订单、余额
- HMAC-SHA256 认证:安全的 API Key 和 Secret Key 认证
- 速率限制保护:内置限流器(每秒 60 请求/IP)
- 统一接口:与 bt_api 的 BtApi、EventBus 和数据容器完全兼容
- 异步支持:完整的 async/await 支持并发操作
| 项目 | 值 |
|---|---|
| 交易所名称 | Bitso(比特索) |
| 交易代码 | BITSO___SPOT |
| REST API 地址 | https://bitso.com/api/v3 |
| WebSocket 地址 | wss://ws.bitso.com |
| 资产类型 | 现货(SPOT) |
| 支持法币 | MXN, USD, BTC, ETH, USDC |
| 速率限制 | 每秒 60 请求/IP |
| 认证方式 | Bearer Token + HMAC-SHA256 |
pip install bt_api_bitsogit clone https://github.com/cloudQuant/bt_api_bitso
cd bt_api_bitso
pip install -e .frombt_api_pyimportBtApi# 配置 Bitso 交易所exchange_config= {
"BITSO___SPOT": {
"api_key": "your_api_key",
"secret_key": "your_secret_key",
}
}
# 初始化 BtApiapi=BtApi(exchange_kwargs=exchange_config)# 获取行情ticker=api.get_tick("BITSO___SPOT", "BTC/MXN")
print(ticker)
# 获取订单簿深度depth=api.get_depth("BITSO___SPOT", "BTC/MXN", limit=20)
print(depth)
# 获取 K 线数据klines=api.get_kline("BITSO___SPOT", "BTC/MXN", period="1h", count=100)
print(klines)
# 获取最近交易trades=api.get_trades("BITSO___SPOT", "BTC/MXN")
print(trades)# 下单order=api.make_order(
exchange_name="BITSO___SPOT",
symbol="BTC/MXN",
volume=0.01,
price=500000,
order_type="buy-limit",
)
print(order)
# 取消订单cancel_result=api.cancel_order(
exchange_name="BITSO___SPOT",
symbol="BTC/MXN",
order_id="your_order_id",
)
print(cancel_result)
# 查询订单状态order_info=api.query_order(
exchange_name="BITSO___SPOT",
symbol="BTC/MXN",
order_id="your_order_id",
)
print(order_info)
# 获取挂单open_orders=api.get_open_orders("BITSO___SPOT", "BTC/MXN")
print(open_orders)
# 获取账户余额balance=api.get_balance("BITSO___SPOT")
print(balance)importasynciofrombt_api_pyimportBtApiasyncdefmain():
api=BtApi(exchange_kwargs={
"BITSO___SPOT": {
"api_key": "your_api_key",
"secret_key": "your_secret_key",
}
})
# 异步获取行情ticker=awaitapi.async_get_tick("BITSO___SPOT", "BTC/MXN")
print(ticker)
# 异步下单order=awaitapi.async_make_order(
exchange_name="BITSO___SPOT",
symbol="BTC/MXN",
volume=0.01,
price=500000,
order_type="buy-limit",
)
print(order)
asyncio.run(main())| 操作 | REST API | 说明 |
|---|---|---|
get_tick | GET /ticker | 获取行情数据(最新价格、成交量等) |
get_depth | GET /order_book | 获取订单簿深度 |
get_kline | GET /ohlc | 获取 K 线/蜡烛图数据 |
get_trades | GET /trades | 获取最近交易 |
make_order | POST /orders | 下新订单 |
cancel_order | DELETE /orders | 取消订单 |
query_order | GET /orders | 查询订单状态 |
get_open_orders | GET /open_orders | 获取所有挂单 |
get_deals | GET /user_trades | 获取用户交易历史 |
get_balance | GET /balance | 获取账户余额 |
get_account | GET /balance | 获取账户信息 |
get_server_time | GET /time | 获取服务器时间 |
get_exchange_info | GET /available_books | 获取可交易交易对 |
Bitso 使用小写字母加下划线分隔符的格式:
| bt_api 交易对 | Bitso 交易对 |
|---|---|
BTC/MXN | btc_mxn |
ETH/MXN | eth_mxn |
XRP/MXN | xrp_mxn |
BTC/USD | btc_usd |
插件会自动转换格式。
Bitso 支持以下订单类型:
| 订单类型 | 说明 |
|---|---|
buy-limit | 买入限价单 |
sell-limit | 卖出限价单 |
buy-market | 买入市价单 |
sell-market | 卖出市价单 |
Bitso 的速率限制为 每秒 60 请求(每个 IP 地址)。本插件内置了滑动窗口算法的限流器,防止超出限制。
所有 API 错误都会转换为 bt_api 的标准错误类型:
frombt_api_py.errorsimport (
RateLimitError, # 速率限制错误AuthenticationError, # 认证错误OrderNotFoundError, # 订单未找到InsufficientBalanceError, # 余额不足
)| 依赖 | 版本 | 说明 |
|---|---|---|
| Python | >= 3.9 | 编程语言 |
| bt_api_base | >= 0.15 | 核心框架 |
欢迎贡献代码!请遵循以下步骤:
- Fork 本仓库
- 创建功能分支 (
git checkout -b feature/amazing-feature) - 提交您的更改 (
git commit -m 'Add some amazing feature') - 推送到分支 (
git push origin feature/amazing-feature) - 开启 Pull Request
MIT 许可证 - 详见 LICENSE。
- 通过 GitHub Issues 反馈问题
- 邮箱: yunjinqi@gmail.com
如果这个项目对您有帮助,请给我们一个 Star!