Skip to content

Repository files navigation

bt_api_coinbase

PyPI VersionPython VersionsLicenseCIDocs


bt_api_coinbase

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.

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

Features

Asset Types

Asset TypeCodeRESTWebSocketDescription
SpotCOINBASE___SPOTSpot trading via Advanced Trade API

Dual API Modes

  • REST API — Synchronous polling for order management, balance queries, historical data
  • WebSocket API — Real-time streaming (placeholder for future implementation)

Plugin Architecture

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

Unified Data Containers

All exchange responses normalized to bt_api_base container types:

  • CoinbaseRequestTickerData — 24hr rolling ticker
  • CoinbaseRequestOrderBookData — Order book depth
  • CoinbaseRequestBarData — K-line/candlestick
  • CoinbaseRequestOrderData — Order status and fills
  • CoinbaseRequestAccountData — Account and balance info

Installation

From PyPI (Recommended)

pip install bt_api_coinbase

From Source

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

Requirements

  • Python 3.93.14
  • bt_api_base >= 0.15
  • httpx for HTTP client

Quick Start

1. Install

pip install bt_api_coinbase

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

frombt_api_pyimportBtApiapi=BtApi()
ticker=api.get_tick("COINBASE___SPOT", "BTC-USD")
print(f"BTC-USD price: {ticker.last_price}")

3. Place an order (requires API key)

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

4. Get balance

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

Architecture

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

Supported Operations

CategoryOperationNotes
Market Dataget_ticker / get_tick24hr rolling ticker
get_orderbook / get_depthDepth up to 100 levels
get_kline / get_barsIntervals: 1m/5m/15m/30m/1h/6h/1d
get_exchange_infoTrading rules and symbol info
get_server_timeServer time synchronization
Accountget_balanceAll asset balances
get_accountFull account info
Tradingmake_orderLIMIT/MARKET orders (buy/sell)
cancel_orderCancel order by ID
query_orderQuery order by ID
get_open_ordersAll open orders

API Authentication

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 key
  • CB-ACCESS-SIGN — Base64 encoded HMAC SHA256 signature
  • CB-ACCESS-TIMESTAMP — Request timestamp (seconds)

Rate Limits

Endpoint TypeLimit
Public endpoints10 requests/second
Private endpoints15 requests/second

Supported Symbols

Coinbase uses hyphenated symbols (e.g., BTC-USD, ETH-USD, SOL-USD).

Popular pairs:

  • BTC-USD, ETH-USD, SOL-USD, XRP-USD
  • BTC-EUR, ETH-EUR, EUR-USD
  • GBP-USD, ETH-BTC

Documentation

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

License

MIT — see LICENSE.


Support



中文

bt_api 的 Coinbase 交易所插件 — 通过 Coinbase Advanced Trade API 为现货交易提供统一的 REST API。

bt_api_coinbasebt_api 的运行时插件,通过 Advanced Trade API v3 连接 Coinbase 交易所。依赖 bt_api_base 提供核心基础设施。

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

功能特点

资产类型

资产类型代码RESTWebSocket说明
现货COINBASE___SPOT通过 Advanced Trade API 进行现货交易

双 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 — 账户和余额信息

安装

从 PyPI 安装(推荐)

pip install bt_api_coinbase

从源码安装

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

系统要求

  • Python 3.93.14
  • bt_api_base >= 0.15
  • httpx HTTP 客户端

快速开始

1. 安装

pip install bt_api_coinbase

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

frombt_api_pyimportBtApiapi=BtApi()
ticker=api.get_tick("COINBASE___SPOT", "BTC-USD")
print(f"BTC-USD 价格: {ticker.last_price}")

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

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

4. 获取余额

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_tick24小时滚动行情
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所有挂单

API 认证

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-USDETH-USDSOL-USD)。

热门交易对:

  • BTC-USD, ETH-USD, SOL-USD, XRP-USD
  • BTC-EUR, ETH-EUR, EUR-USD
  • GBP-USD, ETH-BTC

文档

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