Skip to content

Repository files navigation

Bitstamp Exchange Plugin for bt_api

Bitstamp | 比特戳

PyPI VersionPython VersionsLicenseCIDocs


English | 中文

Overview

This package provides Bitstamp exchange plugin for the bt_api framework. It offers a unified interface for interacting with Bitstamp, one of the oldest and most trusted cryptocurrency exchanges in Europe.

Bitstamp provides trading in USD, EUR, GBP, and various cryptocurrencies. This plugin integrates Bitstamp's REST API v2 into the bt_api unified trading framework.

Key Features

  • Complete REST API Coverage: Ticker, order book, klines, trades, orders, balances
  • Basic Authentication: Secure API key and secret key authentication via Base64 encoding
  • Rate Limit Protection: Built-in rate limiter (200 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 NameBitstamp
Trading CodeBITSTAMP___SPOT
REST API URLhttps://www.bitstamp.net/api/v2
WebSocket URLwss://ws.bitstamp.net
Asset TypeSPOT
Supported CurrenciesUSD, EUR, GBP, USDC
Rate Limit200 requests/second per IP
AuthenticationBasic Auth (Base64)

Installation

From PyPI (Recommended)

pip install bt_api_bitstamp

From Source

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

Quick Start

Initialize the Exchange

frombt_api_pyimportBtApi# Configure Bitstamp exchangeexchange_config= {
"BITSTAMP___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("BITSTAMP___SPOT", "BTCUSD")
print(ticker)
# Get order book depthdepth=api.get_depth("BITSTAMP___SPOT", "BTCUSD", limit=20)
print(depth)
# Get kline/candlestick dataklines=api.get_kline("BITSTAMP___SPOT", "BTCUSD", period="1h", count=100)
print(klines)
# Get recent tradestrades=api.get_trades("BITSTAMP___SPOT", "BTCUSD")
print(trades)

Trading Operations

# Place an order (buy limit)order=api.make_order(
exchange_name="BITSTAMP___SPOT",
symbol="BTCUSD",
volume=0.01,
price=50000,
order_type="buy-limit",
)
print(order)
# Place an order (sell limit)order=api.make_order(
exchange_name="BITSTAMP___SPOT",
symbol="BTCUSD",
volume=0.01,
price=60000,
order_type="sell-limit",
)
print(order)
# Cancel an ordercancel_result=api.cancel_order(
exchange_name="BITSTAMP___SPOT",
symbol="BTCUSD",
order_id="your_order_id",
)
print(cancel_result)
# Query order statusorder_info=api.query_order(
exchange_name="BITSTAMP___SPOT",
symbol="BTCUSD",
order_id="your_order_id",
)
print(order_info)
# Get open ordersopen_orders=api.get_open_orders("BITSTAMP___SPOT", "BTCUSD")
print(open_orders)
# Get account balancebalance=api.get_balance("BITSTAMP___SPOT")
print(balance)

Asynchronous Operations

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

Supported Operations

OperationREST APIDescription
get_tickGET /ticker/{symbol}Get ticker data (last price, volume, etc.)
get_depthGET /order_book/{symbol}Get order book depth
get_klineGET /ohlc/{symbol}Get candlestick/kline data
get_tradesGET /transactions/{symbol}Get recent trades
make_orderPOST /buy, POST /sellPlace a new order
cancel_orderPOST /cancel_orderCancel an order
query_orderPOST /order_statusQuery order status
get_open_ordersPOST /open_orders/allGet all open orders
get_dealsPOST /user_transactionsGet user transaction history
get_balancePOST /balanceGet account balance
get_accountPOST /balanceGet account information
get_server_timeGET /server_time_utcGet server time
get_exchange_infoGET /trading-pairs-infoGet available trading pairs

Symbol Format

Bitstamp uses lowercase symbols with no separator:

bt_api SymbolBitstamp Symbol
BTCUSDbtcusd
ETHUSDethusd
EURUSDeurusd
XRPUSDxrpusd
BTCGBPbtcgbp

The plugin automatically converts between formats.

Order Types

Bitstamp 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

Bitstamp implements a rate limit of 200 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-bitstamp.readthedocs.io/
Chinese Docshttps://bt-api-bitstamp.readthedocs.io/zh/latest/
GitHub Repositoryhttps://github.com/cloudQuant/bt_api_bitstamp
Bitstamp API Docshttps://www.bitstamp.net/api/
Issue Trackerhttps://github.com/cloudQuant/bt_api_bitstamp/issues

Architecture

bt_api_bitstamp/
├── src/bt_api_bitstamp/ # Source code
│ ├── containers/ # Data containers
│ │ ├── balances/ # Balance data containers
│ │ └── orders/ # Order data containers
│ ├── exchange_data/ # Exchange configuration
│ │ └── __init__.py # BitstampExchangeData class
│ ├── feeds/ # API feeds
│ │ └── live_bitstamp/ # Live trading feed
│ │ ├── __init__.py # BitstampRequestData 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 框架提供 Bitstamp(比特戳)交易所插件。Bitstamp 是欧洲最古老、最可信赖的加密货币交易所之一,提供美元(USD)、欧元(EUR)、英镑(GBP)和各种加密货币的交易服务。

本插件将 Bitstamp 的 REST API v2 集成到 bt_api 统一交易框架中,提供标准化的行情查询、订单管理和账户查询接口。

核心功能

  • 完整 REST API 覆盖:行情、订单簿、K线、交易、订单、余额
  • Basic 认证:通过 Base64 编码的安全 API Key 和 Secret Key 认证
  • 速率限制保护:内置限流器(每秒 200 请求/IP)
  • 统一接口:与 bt_api 的 BtApi、EventBus 和数据容器完全兼容
  • 异步支持:完整的 async/await 支持并发操作

交易所信息

项目
交易所名称Bitstamp(比特戳)
交易代码BITSTAMP___SPOT
REST API 地址https://www.bitstamp.net/api/v2
WebSocket 地址wss://ws.bitstamp.net
资产类型现货(SPOT)
支持法币USD, EUR, GBP, USDC
速率限制每秒 200 请求/IP
认证方式Basic Auth(Base64)

安装

从 PyPI 安装(推荐)

pip install bt_api_bitstamp

从源码安装

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

快速开始

初始化交易所

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

获取市场数据

# 获取行情ticker=api.get_tick("BITSTAMP___SPOT", "BTCUSD")
print(ticker)
# 获取订单簿深度depth=api.get_depth("BITSTAMP___SPOT", "BTCUSD", limit=20)
print(depth)
# 获取 K 线数据klines=api.get_kline("BITSTAMP___SPOT", "BTCUSD", period="1h", count=100)
print(klines)
# 获取最近交易trades=api.get_trades("BITSTAMP___SPOT", "BTCUSD")
print(trades)

交易操作

# 下单(买入限价单)order=api.make_order(
exchange_name="BITSTAMP___SPOT",
symbol="BTCUSD",
volume=0.01,
price=50000,
order_type="buy-limit",
)
print(order)
# 下单(卖出限价单)order=api.make_order(
exchange_name="BITSTAMP___SPOT",
symbol="BTCUSD",
volume=0.01,
price=60000,
order_type="sell-limit",
)
print(order)
# 取消订单cancel_result=api.cancel_order(
exchange_name="BITSTAMP___SPOT",
symbol="BTCUSD",
order_id="your_order_id",
)
print(cancel_result)
# 查询订单状态order_info=api.query_order(
exchange_name="BITSTAMP___SPOT",
symbol="BTCUSD",
order_id="your_order_id",
)
print(order_info)
# 获取挂单open_orders=api.get_open_orders("BITSTAMP___SPOT", "BTCUSD")
print(open_orders)
# 获取账户余额balance=api.get_balance("BITSTAMP___SPOT")
print(balance)

异步操作

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

支持的操作

操作REST API说明
get_tickGET /ticker/{symbol}获取行情数据(最新价格、成交量等)
get_depthGET /order_book/{symbol}获取订单簿深度
get_klineGET /ohlc/{symbol}获取 K 线/蜡烛图数据
get_tradesGET /transactions/{symbol}获取最近交易
make_orderPOST /buy, POST /sell下新订单
cancel_orderPOST /cancel_order取消订单
query_orderPOST /order_status查询订单状态
get_open_ordersPOST /open_orders/all获取所有挂单
get_dealsPOST /user_transactions获取用户交易历史
get_balancePOST /balance获取账户余额
get_accountPOST /balance获取账户信息
get_server_timeGET /server_time_utc获取服务器时间
get_exchange_infoGET /trading-pairs-info获取可交易交易对

交易对格式

Bitstamp 使用小写字母无分隔符的格式:

bt_api 交易对Bitstamp 交易对
BTCUSDbtcusd
ETHUSDethusd
EURUSDeurusd
XRPUSDxrpusd
BTCGBPbtcgbp

插件会自动转换格式。

订单类型

Bitstamp 支持以下订单类型:

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

速率限制

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

错误处理

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

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

在线文档

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