Skip to content

Repository files navigation

Bitso Exchange Plugin for bt_api

Bitso | 比特索

PyPI VersionPython VersionsLicenseCIDocs


English | 中文

Overview

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.

Key Features

  • 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

Exchange Information

ItemValue
Exchange NameBitso
Trading CodeBITSO___SPOT
REST API URLhttps://bitso.com/api/v3
WebSocket URLwss://ws.bitso.com
Asset TypeSPOT
Supported CurrenciesMXN, USD, BTC, ETH, USDC
Rate Limit60 requests/second per IP
AuthenticationBearer Token + HMAC-SHA256

Installation

From PyPI (Recommended)

pip install bt_api_bitso

From Source

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

Quick Start

Initialize the Exchange

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 Market Data

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

Trading Operations

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

Asynchronous Operations

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

Supported Operations

OperationREST APIDescription
get_tickGET /tickerGet ticker data (last price, volume, etc.)
get_depthGET /order_bookGet order book depth
get_klineGET /ohlcGet candlestick/kline data
get_tradesGET /tradesGet recent trades
make_orderPOST /ordersPlace a new order
cancel_orderDELETE /ordersCancel an order
query_orderGET /ordersQuery order status
get_open_ordersGET /open_ordersGet all open orders
get_dealsGET /user_tradesGet user trade history
get_balanceGET /balanceGet account balance
get_accountGET /balanceGet account information
get_server_timeGET /timeGet server time
get_exchange_infoGET /available_booksGet available trading pairs

Symbol Format

Bitso uses lowercase symbols with underscore separator:

bt_api SymbolBitso Symbol
BTC/MXNbtc_mxn
ETH/MXNeth_mxn
XRP/MXNxrp_mxn
BTC/USDbtc_usd

The plugin automatically converts between formats.

Order Types

Bitso supports the following order types:

Order TypeDescription
buy-limitBuy limit order
sell-limitSell limit order
buy-marketBuy market order
sell-marketSell market order

Rate Limiting

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.

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-bitso.readthedocs.io/
Chinese Docshttps://bt-api-bitso.readthedocs.io/zh/latest/
GitHub Repositoryhttps://github.com/cloudQuant/bt_api_bitso
Bitso API Docshttps://bitso.com/api/v3
Issue Trackerhttps://github.com/cloudQuant/bt_api_bitso/issues

Architecture

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

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 框架提供 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

安装

从 PyPI 安装(推荐)

pip install bt_api_bitso

从源码安装

git 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_tickGET /ticker获取行情数据(最新价格、成交量等)
get_depthGET /order_book获取订单簿深度
get_klineGET /ohlc获取 K 线/蜡烛图数据
get_tradesGET /trades获取最近交易
make_orderPOST /orders下新订单
cancel_orderDELETE /orders取消订单
query_orderGET /orders查询订单状态
get_open_ordersGET /open_orders获取所有挂单
get_dealsGET /user_trades获取用户交易历史
get_balanceGET /balance获取账户余额
get_accountGET /balance获取账户信息
get_server_timeGET /time获取服务器时间
get_exchange_infoGET /available_books获取可交易交易对

交易对格式

Bitso 使用小写字母加下划线分隔符的格式:

bt_api 交易对Bitso 交易对
BTC/MXNbtc_mxn
ETH/MXNeth_mxn
XRP/MXNxrp_mxn
BTC/USDbtc_usd

插件会自动转换格式。

订单类型

Bitso 支持以下订单类型:

订单类型说明
buy-limit买入限价单
sell-limit卖出限价单
buy-market买入市价单
sell-market卖出市价单

速率限制

Bitso 的速率限制为 每秒 60 请求(每个 IP 地址)。本插件内置了滑动窗口算法的限流器,防止超出限制。

错误处理

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

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

在线文档

资源链接
英文文档https://bt-api-bitso.readthedocs.io/
中文文档https://bt-api-bitso.readthedocs.io/zh/latest/
GitHub 仓库https://github.com/cloudQuant/bt_api_bitso
Bitso API 文档https://bitso.com/api/v3
问题反馈https://github.com/cloudQuant/bt_api_bitso/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