Coinbase exchange plugin for bt_api — Unified REST API for Spot trading via Coinbase Advanced Trade API.
bt_api_coinbase is a runtime plugin for bt_api that connects to Coinbase exchange using the Advanced Trade API v3. It depends on bt_api_base for core infrastructure.
| Resource | Link |
|---|---|
| English Docs | https://bt-api-coinbase.readthedocs.io/ |
| Chinese Docs | https://bt-api-coinbase.readthedocs.io/zh/latest/ |
| GitHub | https://github.com/cloudQuant/bt_api_coinbase |
| PyPI | https://pypi.org/project/bt_api_coinbase/ |
| Issues | https://github.com/cloudQuant/bt_api_coinbase/issues |
| bt_api_base | https://bt-api-base.readthedocs.io/ |
| Main Project | https://github.com/cloudQuant/bt_api_py |
| Asset Type | Code | REST | WebSocket | Description |
|---|---|---|---|---|
| Spot | COINBASE___SPOT | ✅ | — | Spot trading via Advanced Trade API |
- REST API — Synchronous polling for order management, balance queries, historical data
- WebSocket API — Real-time streaming (placeholder for future implementation)
Auto-registers at import time via ExchangeRegistry. Works seamlessly with BtApi:
frombt_api_pyimportBtApiapi=BtApi(exchange_kwargs={
"COINBASE___SPOT": {
"api_key": "your_api_key",
"private_key": "your_private_key",
}
})
ticker=api.get_tick("COINBASE___SPOT", "BTC-USD")
balance=api.get_balance("COINBASE___SPOT")
order=api.make_order(exchange_name="COINBASE___SPOT", symbol="BTC-USD", vol=0.001, price=50000, order_type="buy-limit")All exchange responses normalized to bt_api_base container types:
CoinbaseRequestTickerData— 24hr rolling tickerCoinbaseRequestOrderBookData— Order book depthCoinbaseRequestBarData— K-line/candlestickCoinbaseRequestOrderData— Order status and fillsCoinbaseRequestAccountData— Account and balance info
pip install bt_api_coinbasegit clone https://github.com/cloudQuant/bt_api_coinbase
cd bt_api_coinbase
pip install -e .- Python
3.9–3.14 bt_api_base >= 0.15httpxfor HTTP client
pip install bt_api_coinbasefrombt_api_pyimportBtApiapi=BtApi()
ticker=api.get_tick("COINBASE___SPOT", "BTC-USD")
print(f"BTC-USD price: {ticker.last_price}")frombt_api_pyimportBtApiapi=BtApi(exchange_kwargs={
"COINBASE___SPOT": {
"api_key": "your_api_key",
"private_key": "your_private_key",
}
})
order=api.make_order(
exchange_name="COINBASE___SPOT",
symbol="BTC-USD",
vol=0.001,
price=50000,
order_type="buy-limit",
)
print(f"Order placed: {order}")frombt_api_pyimportBtApiapi=BtApi(exchange_kwargs={
"COINBASE___SPOT": {
"api_key": "your_api_key",
"private_key": "your_private_key",
}
})
balance=api.get_balance("COINBASE___SPOT")
print(f"Balance: {balance}")bt_api_coinbase/
├── src/bt_api_coinbase/
│ ├── __init__.py
│ ├── exchange_registers/
│ │ ├── __init__.py
│ │ └── register_coinbase.py # Feed/exchange_data registration
│ ├── containers/
│ │ ├── __init__.py
│ │ ├── exchanges/
│ │ │ ├── __init__.py
│ │ │ └── coinbase_exchange_data.py # CoinbaseExchangeData, CoinbaseExchangeDataSpot
│ │ ├── tickers/
│ │ │ ├── __init__.py
│ │ │ └── coinbase_ticker.py # CoinbaseRequestTickerData
│ │ ├── orderbooks/
│ │ │ ├── __init__.py
│ │ │ └── coinbase_orderbook.py # CoinbaseRequestOrderBookData
│ │ ├── bars/
│ │ │ ├── __init__.py
│ │ │ └── coinbase_bar.py # CoinbaseRequestBarData
│ │ ├── orders/
│ │ │ ├── __init__.py
│ │ │ └── coinbase_order.py # CoinbaseRequestOrderData
│ │ ├── accounts/
│ │ │ ├── __init__.py
│ │ │ └── coinbase_account.py # CoinbaseRequestAccountData
│ │ ├── balances/
│ │ │ ├── __init__.py
│ │ │ └── coinbase_balance.py # CoinbaseRequestBalanceData
│ │ └── trades/
│ │ ├── __init__.py
│ │ └── coinbase_trade.py # CoinbaseRequestTradeData
│ └── feeds/
│ ├── __init__.py
│ └── live_coinbase/
│ ├── __init__.py
│ ├── request_base.py # CoinbaseRequestData base class
│ └── spot.py # CoinbaseRequestDataSpot
├── tests/
├── docs/
├── pyproject.toml
└── README.md
| Category | Operation | Notes |
|---|---|---|
| Market Data | get_ticker / get_tick | 24hr rolling ticker |
get_orderbook / get_depth | Depth up to 100 levels | |
get_kline / get_bars | Intervals: 1m/5m/15m/30m/1h/6h/1d | |
get_exchange_info | Trading rules and symbol info | |
get_server_time | Server time synchronization | |
| Account | get_balance | All asset balances |
get_account | Full account info | |
| Trading | make_order | LIMIT/MARKET orders (buy/sell) |
cancel_order | Cancel order by ID | |
query_order | Query order by ID | |
get_open_orders | All open orders |
Coinbase Advanced Trade API uses HMAC SHA256 authentication:
message = timestamp + method + request_path + body
signature = Base64(HMAC-SHA256(secret_key, message))
Required headers:
CB-ACCESS-KEY— API keyCB-ACCESS-SIGN— Base64 encoded HMAC SHA256 signatureCB-ACCESS-TIMESTAMP— Request timestamp (seconds)
| Endpoint Type | Limit |
|---|---|
| Public endpoints | 10 requests/second |
| Private endpoints | 15 requests/second |
Coinbase uses hyphenated symbols (e.g., BTC-USD, ETH-USD, SOL-USD).
Popular pairs:
BTC-USD,ETH-USD,SOL-USD,XRP-USDBTC-EUR,ETH-EUR,EUR-USDGBP-USD,ETH-BTC
MIT — see LICENSE.
- GitHub Issues — bug reports, feature requests
- Email: yunjinqi@gmail.com
bt_api 的 Coinbase 交易所插件 — 通过 Coinbase Advanced Trade API 为现货交易提供统一的 REST API。
bt_api_coinbase 是 bt_api 的运行时插件,通过 Advanced Trade API v3 连接 Coinbase 交易所。依赖 bt_api_base 提供核心基础设施。
| 资产类型 | 代码 | REST | WebSocket | 说明 |
|---|---|---|---|---|
| 现货 | COINBASE___SPOT | ✅ | — | 通过 Advanced Trade API 进行现货交易 |
- REST API — 同步轮询:订单管理、余额查询、历史数据
- WebSocket API — 实时流(为未来实现预留)
通过 ExchangeRegistry 在导入时自动注册,与 BtApi 无缝协作:
frombt_api_pyimportBtApiapi=BtApi(exchange_kwargs={
"COINBASE___SPOT": {
"api_key": "your_api_key",
"private_key": "your_private_key",
}
})
ticker=api.get_tick("COINBASE___SPOT", "BTC-USD")
balance=api.get_balance("COINBASE___SPOT")
order=api.make_order(exchange_name="COINBASE___SPOT", symbol="BTC-USD", vol=0.001, price=50000, order_type="buy-limit")所有交易所响应规范化为 bt_api_base 容器类型:
CoinbaseRequestTickerData— 24小时滚动行情CoinbaseRequestOrderBookData— 订单簿深度CoinbaseRequestBarData— K线/蜡烛图CoinbaseRequestOrderData— 订单状态和成交CoinbaseRequestAccountData— 账户和余额信息
pip install bt_api_coinbasegit clone https://github.com/cloudQuant/bt_api_coinbase
cd bt_api_coinbase
pip install -e .- Python
3.9–3.14 bt_api_base >= 0.15httpxHTTP 客户端
pip install bt_api_coinbasefrombt_api_pyimportBtApiapi=BtApi()
ticker=api.get_tick("COINBASE___SPOT", "BTC-USD")
print(f"BTC-USD 价格: {ticker.last_price}")frombt_api_pyimportBtApiapi=BtApi(exchange_kwargs={
"COINBASE___SPOT": {
"api_key": "your_api_key",
"private_key": "your_private_key",
}
})
order=api.make_order(
exchange_name="COINBASE___SPOT",
symbol="BTC-USD",
vol=0.001,
price=50000,
order_type="buy-limit",
)
print(f"订单已下单: {order}")frombt_api_pyimportBtApiapi=BtApi(exchange_kwargs={
"COINBASE___SPOT": {
"api_key": "your_api_key",
"private_key": "your_private_key",
}
})
balance=api.get_balance("COINBASE___SPOT")
print(f"余额: {balance}")bt_api_coinbase/
├── src/bt_api_coinbase/
│ ├── __init__.py
│ ├── exchange_registers/
│ │ ├── __init__.py
│ │ └── register_coinbase.py # Feed/exchange_data 注册
│ ├── containers/
│ │ ├── __init__.py
│ │ ├── exchanges/
│ │ │ ├── __init__.py
│ │ │ └── coinbase_exchange_data.py # CoinbaseExchangeData, CoinbaseExchangeDataSpot
│ │ ├── tickers/
│ │ │ ├── __init__.py
│ │ │ └── coinbase_ticker.py # CoinbaseRequestTickerData
│ │ ├── orderbooks/
│ │ │ ├── __init__.py
│ │ │ └── coinbase_orderbook.py # CoinbaseRequestOrderBookData
│ │ ├── bars/
│ │ │ ├── __init__.py
│ │ │ └── coinbase_bar.py # CoinbaseRequestBarData
│ │ ├── orders/
│ │ │ ├── __init__.py
│ │ │ └── coinbase_order.py # CoinbaseRequestOrderData
│ │ ├── accounts/
│ │ │ ├── __init__.py
│ │ │ └── coinbase_account.py # CoinbaseRequestAccountData
│ │ ├── balances/
│ │ │ ├── __init__.py
│ │ │ └── coinbase_balance.py # CoinbaseRequestBalanceData
│ │ └── trades/
│ │ ├── __init__.py
│ │ └── coinbase_trade.py # CoinbaseRequestTradeData
│ └── feeds/
│ ├── __init__.py
│ └── live_coinbase/
│ ├── __init__.py
│ ├── request_base.py # CoinbaseRequestData 基类
│ └── spot.py # CoinbaseRequestDataSpot
├── tests/
├── docs/
├── pyproject.toml
└── README.md
| 类别 | 操作 | 说明 |
|---|---|---|
| 行情数据 | get_ticker / get_tick | 24小时滚动行情 |
get_orderbook / get_depth | 深度最高100档 | |
get_kline / get_bars | 周期: 1m/5m/15m/30m/1h/6h/1d | |
get_exchange_info | 交易规则和交易对信息 | |
get_server_time | 服务器时间同步 | |
| 账户 | get_balance | 所有资产余额 |
get_account | 完整账户信息 | |
| 交易 | make_order | 限价/市价订单(买入/卖出) |
cancel_order | 按ID撤销订单 | |
query_order | 按ID查询订单 | |
get_open_orders | 所有挂单 |
Coinbase Advanced Trade API 使用 HMAC SHA256 认证:
message = timestamp + method + request_path + body
signature = Base64(HMAC-SHA256(secret_key, message))
必需请求头:
CB-ACCESS-KEY— API 密钥CB-ACCESS-SIGN— Base64 编码的 HMAC SHA256 签名CB-ACCESS-TIMESTAMP— 请求时间戳(秒)
| 端点类型 | 限制 |
|---|---|
| 公开接口 | 10 次/秒 |
| 私有接口 | 15 次/秒 |
Coinbase 使用连字符格式的交易对(例如 BTC-USD、ETH-USD、SOL-USD)。
热门交易对:
BTC-USD,ETH-USD,SOL-USD,XRP-USDBTC-EUR,ETH-EUR,EUR-USDGBP-USD,ETH-BTC
| 文档 | 链接 |
|---|---|
| 英文文档 | https://bt-api-coinbase.readthedocs.io/ |
| 中文文档 | https://bt-api-coinbase.readthedocs.io/zh/latest/ |
| bt_api_base | https://bt-api-base.readthedocs.io/ |
| 主项目 | https://cloudquant.github.io/bt_api_py/ |
MIT — 详见 LICENSE。
- GitHub Issues — bug 报告、功能请求
- 邮箱: yunjinqi@gmail.com