cryptofeed

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Cryptofeed Skill

Cryptofeed 技能

Comprehensive assistance with Cryptofeed development - a Python library for handling cryptocurrency exchange data feeds with normalized and standardized results.
为Cryptofeed开发提供全面支持——这是一款用于处理加密货币交易所数据馈送的Python库,可提供标准化的结果。

When to Use This Skill

何时使用该技能

This skill should be triggered when:
  • Working with real-time cryptocurrency market data
  • Implementing WebSocket streaming from crypto exchanges
  • Building algorithmic trading systems
  • Processing order book updates, trades, or ticker data
  • Connecting to 40+ cryptocurrency exchanges
  • Using normalized exchange APIs
  • Implementing market data backends (Redis, MongoDB, Kafka, etc.)
满足以下场景时可触发该技能:
  • 处理实时加密货币市场数据时
  • 从加密货币交易所实现WebSocket流时
  • 构建算法交易系统时
  • 处理订单簿更新、交易或行情数据时
  • 连接至40余家加密货币交易所时
  • 使用标准化的交易所API时
  • 实现市场数据后端(Redis、MongoDB、Kafka等)时

Quick Reference

快速参考

Installation

安装

python
undefined
python
undefined

Basic installation

Basic installation

pip install cryptofeed
pip install cryptofeed

With all optional backends

With all optional backends

pip install cryptofeed[all]
undefined
pip install cryptofeed[all]
undefined

Basic Usage Pattern

基本使用模式

python
from cryptofeed import FeedHandler
from cryptofeed.exchanges import Coinbase, Bitfinex
from cryptofeed.defines import TICKER, TRADES, L2_BOOK
python
from cryptofeed import FeedHandler
from cryptofeed.exchanges import Coinbase, Bitfinex
from cryptofeed.defines import TICKER, TRADES, L2_BOOK

Define callbacks

Define callbacks

def ticker_callback(data): print(f"Ticker: {data}")
def trade_callback(data): print(f"Trade: {data}")
def ticker_callback(data): print(f"Ticker: {data}")
def trade_callback(data): print(f"Trade: {data}")

Create feed handler

Create feed handler

fh = FeedHandler()
fh = FeedHandler()

Add exchange feeds

Add exchange feeds

fh.add_feed(Coinbase( symbols=['BTC-USD'], channels=[TICKER], callbacks={TICKER: ticker_callback} ))
fh.add_feed(Bitfinex( symbols=['BTC-USD'], channels=[TRADES], callbacks={TRADES: trade_callback} ))
fh.add_feed(Coinbase( symbols=['BTC-USD'], channels=[TICKER], callbacks={TICKER: ticker_callback} ))
fh.add_feed(Bitfinex( symbols=['BTC-USD'], channels=[TRADES], callbacks={TRADES: trade_callback} ))

Start receiving data

Start receiving data

fh.run()
undefined
fh.run()
undefined

National Best Bid/Offer (NBBO)

全国最优买卖报价(NBBO)

python
from cryptofeed import FeedHandler
from cryptofeed.exchanges import Coinbase, Gemini, Kraken

def nbbo_update(symbol, bid, bid_size, ask, ask_size, bid_feed, ask_feed):
    print(f'Pair: {symbol} Bid: {bid:.2f} ({bid_size:.6f}) from {bid_feed}')
    print(f'Ask: {ask:.2f} ({ask_size:.6f}) from {ask_feed}')

f = FeedHandler()
f.add_nbbo([Coinbase, Kraken, Gemini], ['BTC-USD'], nbbo_update)
f.run()
python
from cryptofeed import FeedHandler
from cryptofeed.exchanges import Coinbase, Gemini, Kraken

def nbbo_update(symbol, bid, bid_size, ask, ask_size, bid_feed, ask_feed):
    print(f'Pair: {symbol} Bid: {bid:.2f} ({bid_size:.6f}) from {bid_feed}')
    print(f'Ask: {ask:.2f} ({ask_size:.6f}) from {ask_feed}')

f = FeedHandler()
f.add_nbbo([Coinbase, Kraken, Gemini], ['BTC-USD'], nbbo_update)
f.run()

Supported Exchanges (40+)

支持的交易所(40+家)

Major Exchanges

主流交易所

  • Binance (Spot, Futures, Delivery, US)
  • Coinbase, Kraken (Spot, Futures), Bitfinex
  • Gemini, OKX, Bybit
  • Huobi (Spot, DM, Swap), Gate.io (Spot, Futures)
  • KuCoin, Deribit, BitMEX, dYdX
  • Binance(现货、期货、交割合约、US合约)
  • CoinbaseKraken(现货、期货)、Bitfinex
  • GeminiOKXBybit
  • Huobi(现货、交割合约、永续合约)、Gate.io(现货、期货)
  • KuCoinDeribitBitMEXdYdX

Additional Exchanges

其他交易所

AscendEX, Bequant, bitFlyer, Bithumb, Bitstamp, Blockchain.com, Bit.com, Bitget, Crypto.com, Delta, EXX, FMFW.io, HitBTC, Independent Reserve, OKCoin, Phemex, Poloniex, ProBit, Upbit
AscendEX, Bequant, bitFlyer, Bithumb, Bitstamp, Blockchain.com, Bit.com, Bitget, Crypto.com, Delta, EXX, FMFW.io, HitBTC, Independent Reserve, OKCoin, Phemex, Poloniex, ProBit, Upbit

Supported Data Channels

支持的数据通道

Market Data (Public)

公开市场数据

  • L1_BOOK - Top of order book
  • L2_BOOK - Price aggregated sizes
  • L3_BOOK - Price aggregated orders
  • TRADES - Executed trades (taker side)
  • TICKER - Price ticker updates
  • FUNDING - Funding rate data
  • OPEN_INTEREST - Open interest statistics
  • LIQUIDATIONS - Liquidation events
  • INDEX - Index price data
  • CANDLES - Candlestick/K-line data
  • L1_BOOK - 订单簿顶层数据
  • L2_BOOK - 按价格聚合的委托量
  • L3_BOOK - 按价格聚合的订单
  • TRADES - 已执行交易(Taker方)
  • TICKER - 行情价格更新
  • FUNDING - 资金费率数据
  • OPEN_INTEREST - 持仓量统计
  • LIQUIDATIONS - 爆仓事件
  • INDEX - 指数价格数据
  • CANDLES - K线数据

Authenticated Channels (Private)

私有认证通道

  • ORDER_INFO - Order status updates
  • TRANSACTIONS - Deposits and withdrawals
  • BALANCES - Wallet balance updates
  • FILLS - User's executed trades
  • ORDER_INFO - 订单状态更新
  • TRANSACTIONS - 充提记录
  • BALANCES - 钱包余额更新
  • FILLS - 用户已执行交易

Supported Backends

支持的后端存储

Write data directly to storage:
  • Redis (Streams and Sorted Sets)
  • Arctic - Time-series database
  • ZeroMQ, InfluxDB v2, MongoDB
  • Kafka, RabbitMQ, PostgreSQL
  • QuasarDB, GCP Pub/Sub, QuestDB
  • UDP/TCP/Unix Sockets
可直接将数据写入以下存储系统:
  • Redis(流和有序集合)
  • Arctic - 时间序列数据库
  • ZeroMQInfluxDB v2MongoDB
  • KafkaRabbitMQPostgreSQL
  • QuasarDBGCP Pub/SubQuestDB
  • UDP/TCP/Unix Sockets

Key Features

核心特性

Real-time Data Normalization

实时数据标准化

Cryptofeed normalizes data across all exchanges, providing consistent:
  • Symbol formatting
  • Timestamp handling
  • Data structures
  • Channel names
Cryptofeed对所有交易所的数据进行标准化处理,提供一致的:
  • 符号格式
  • 时间戳处理
  • 数据结构
  • 通道名称

WebSocket + REST Fallback

WebSocket + REST降级方案

  • Primarily uses WebSockets for real-time data
  • Falls back to REST polling when WebSocket unavailable
  • Automatic reconnection handling
  • 优先使用WebSocket获取实时数据
  • 当WebSocket不可用时,自动降级为REST轮询
  • 自动重连处理

NBBO Aggregation

NBBO聚合

Create synthetic National Best Bid/Offer feeds by aggregating data across multiple exchanges to find arbitrage opportunities.
通过聚合多家交易所的数据创建合成的全国最优买卖报价馈送,以发现套利机会。

Backend Integration

后端集成

Direct data writing to various storage systems without custom integration code.
无需自定义集成代码,即可直接将数据写入各种存储系统。

Requirements

环境要求

  • Python: 3.8 or higher
  • Installation: Via pip or from source
  • Optional Dependencies: Install backends as needed
  • Python:3.8或更高版本
  • 安装方式:通过pip或源代码安装
  • 可选依赖:根据需要安装对应后端存储的依赖

Common Use Cases

常见用例

Multi-Exchange Price Monitoring

多交易所价格监控

python
fh = FeedHandler()
fh.add_feed(Binance(symbols=['BTC-USDT'], channels=[TICKER], callbacks=ticker_cb))
fh.add_feed(Coinbase(symbols=['BTC-USD'], channels=[TICKER], callbacks=ticker_cb))
fh.add_feed(Kraken(symbols=['BTC-USD'], channels=[TICKER], callbacks=ticker_cb))
fh.run()
python
fh = FeedHandler()
fh.add_feed(Binance(symbols=['BTC-USDT'], channels=[TICKER], callbacks=ticker_cb))
fh.add_feed(Coinbase(symbols=['BTC-USD'], channels=[TICKER], callbacks=ticker_cb))
fh.add_feed(Kraken(symbols=['BTC-USD'], channels=[TICKER], callbacks=ticker_cb))
fh.run()

Order Book Depth Analysis

订单簿深度分析

python
def book_callback(book, receipt_timestamp):
    print(f"Bids: {len(book.book.bids)} | Asks: {len(book.book.asks)}")

fh.add_feed(Coinbase(
    symbols=['BTC-USD'],
    channels=[L2_BOOK],
    callbacks={L2_BOOK: book_callback}
))
python
def book_callback(book, receipt_timestamp):
    print(f"Bids: {len(book.book.bids)} | Asks: {len(book.book.asks)}")

fh.add_feed(Coinbase(
    symbols=['BTC-USD'],
    channels=[L2_BOOK],
    callbacks={L2_BOOK: book_callback}
))

Trade Flow Analysis

交易流分析

python
def trade_callback(trade, receipt_timestamp):
    print(f"{trade.exchange} - {trade.symbol}: {trade.side} {trade.amount} @ {trade.price}")

fh.add_feed(Binance(
    symbols=['BTC-USDT', 'ETH-USDT'],
    channels=[TRADES],
    callbacks={TRADES: trade_callback}
))
python
def trade_callback(trade, receipt_timestamp):
    print(f"{trade.exchange} - {trade.symbol}: {trade.side} {trade.amount} @ {trade.price}")

fh.add_feed(Binance(
    symbols=['BTC-USDT', 'ETH-USDT'],
    channels=[TRADES],
    callbacks={TRADES: trade_callback}
))

Reference Files

参考文件

This skill includes documentation in
references/
:
  • getting_started.md - Installation and basic usage
  • README.md - Complete overview and examples
Use
view
to read specific reference files when detailed information is needed.
该技能在
references/
目录下包含以下文档:
  • getting_started.md - 安装和基本使用指南
  • README.md - 完整概述和示例
需要详细信息时,使用
view
命令查看特定参考文件。

Working with This Skill

使用该技能的建议

For Beginners

针对初学者

Start with basic FeedHandler setup and single exchange connections before adding multiple feeds.
先从基本的FeedHandler设置和单交易所连接开始,再逐步添加多个数据馈送。

For Advanced Users

针对高级用户

Explore NBBO feeds, authenticated channels, and backend integrations for production systems.
探索NBBO馈送、认证通道和后端集成,以构建生产级系统。

For Code Examples

针对代码示例

See the quick reference section above and the reference files for complete working examples.
查看上方的快速参考部分和参考文件,获取完整的可用示例。

Resources

相关资源

Notes

注意事项

  • Requires Python 3.8+
  • WebSocket-first approach with REST fallback
  • Normalized data across all exchanges
  • Active development and community support
  • 40+ supported exchanges and growing
  • 需要Python 3.8及以上版本
  • 优先采用WebSocket方案,REST作为降级备选
  • 所有交易所的数据均已标准化
  • 项目处于活跃开发状态,拥有社区支持
  • 支持40余家交易所,且数量持续增加