or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

backends.mdconstants.mdexchanges.mdfeed-management.mdindex.mdtypes.md
tile.json

tessl/pypi-cryptofeed

Cryptocurrency Exchange Websocket Data Feed Handler for normalized market data across 30+ exchanges

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
pypipkg:pypi/cryptofeed@2.4.x

To install, run

npx @tessl/cli install tessl/pypi-cryptofeed@2.4.0

index.mddocs/

Cryptofeed

A comprehensive Python library for cryptocurrency exchange data feeds that provides normalized and standardized market data from 30+ major cryptocurrency exchanges through websockets and REST APIs. Supports real-time data streaming, historical data access, multi-exchange NBBO calculation, and flexible data storage backends.

Package Information

  • Package Name: cryptofeed
  • Language: Python
  • Installation: pip install cryptofeed
  • Minimum Python Version: 3.8+
  • Optional Dependencies: pip install cryptofeed[all] for all backend support

Core Imports

from cryptofeed import FeedHandler

For exchanges and data types:

from cryptofeed.exchanges import Coinbase, Binance, Kraken, Bitfinex
from cryptofeed.defines import L1_BOOK, L2_BOOK, L3_BOOK, TRADES, TICKER, FUNDING
from cryptofeed.types import Trade, Ticker, OrderBook, Candle

For backends:

from cryptofeed.backends.redis import TradeRedis, BookRedis
from cryptofeed.backends.mongo import TradeMongo
from cryptofeed.backends.postgres import TradePostgres

Basic Usage

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

def trade_handler(trade):
    print(f'Trade: {trade.exchange} {trade.symbol} {trade.side} {trade.amount} @ {trade.price}')

def ticker_handler(ticker):
    print(f'Ticker: {ticker.exchange} {ticker.symbol} bid: {ticker.bid} ask: {ticker.ask}')

def book_handler(book):
    print(f'Book: {book.exchange} {book.symbol} best bid: {list(book.book.bids.keys())[0]}')

# Create feed handler
fh = FeedHandler()

# Add exchange feeds with callbacks
fh.add_feed(Coinbase(
    symbols=['BTC-USD', 'ETH-USD'], 
    channels=[TRADES, TICKER], 
    callbacks={TRADES: trade_handler, TICKER: ticker_handler}
))

fh.add_feed(Binance(
    symbols=['BTCUSDT', 'ETHUSDT'], 
    channels=[L2_BOOK], 
    callbacks={L2_BOOK: book_handler}
))

# Start processing feeds
fh.run()

Architecture

Cryptofeed uses an event-driven architecture with these key components:

  • FeedHandler: Central orchestrator managing multiple exchange feeds and event loops
  • Exchange Classes: Individual implementations for each supported exchange, handling websocket connections and data normalization
  • Data Types: Cython-based classes (Trade, Ticker, OrderBook, etc.) providing fast, standardized data structures
  • Callbacks: User-defined functions or backend classes that process incoming data
  • Backends: Storage and streaming interfaces for databases, message queues, and other systems
  • Symbol Management: Unified symbol handling across exchanges with automatic normalization

The architecture enables high-throughput data processing with minimal latency while abstracting away exchange-specific details.

Capabilities

Feed Management

Core functionality for managing cryptocurrency data feeds from multiple exchanges, including feed lifecycle management, connection handling, and event processing.

class FeedHandler:
    def __init__(self, config=None, raw_data_collection=None): ...
    def add_feed(self, feed, loop=None, **kwargs): ...
    def run(self, start_loop=True, install_signal_handlers=True, exception_handler=None): ...
    def stop(self, loop=None): ...
    def add_nbbo(self, feeds, symbols, callback, config=None): ...

Core Feed Management

Exchange Implementations

Pre-built exchange implementations supporting websocket and REST API access for major cryptocurrency exchanges, with unified interfaces and automatic data normalization.

# Example exchange classes
class Coinbase(Feed): ...
class Binance(Feed): ...
class Kraken(Feed): ...
class Bitfinex(Feed): ...
# ... 30+ more exchanges

Exchange Support

Data Types and Structures

Fast Cython-based data structures representing different types of market data with standardized formats across all exchanges.

class Trade:
    exchange: str
    symbol: str
    side: str
    amount: float
    price: float
    timestamp: float
    id: str
    
class Ticker:
    exchange: str
    symbol: str
    bid: float
    ask: float
    timestamp: float
    
class OrderBook:
    exchange: str
    symbol: str
    book: dict
    timestamp: float

Data Types

Storage Backends

Built-in backend implementations for storing and streaming data to various databases, message queues, and other systems with minimal setup.

# Redis backends
class TradeRedis(BackendCallback): ...
class BookRedis(BackendCallback): ...

# Database backends  
class TradeMongo(BackendCallback): ...
class TradePostgres(BackendCallback): ...
class TradeInflux(BackendCallback): ...

# Streaming backends
class TradeKafka(BackendCallback): ...
class TradeZMQ(BackendCallback): ...

Storage Backends

REST API Access

Synchronous and asynchronous REST API methods for historical data retrieval, order management, and account operations across all supported exchanges.

# Market Data REST Methods
def ticker_sync(self, symbol, **kwargs): ...
async def ticker(self, symbol, **kwargs): ...
def trades_sync(self, symbol, start=None, end=None, **kwargs): ...
async def trades(self, symbol, start=None, end=None, **kwargs): ...
def candles_sync(self, symbol, start=None, end=None, interval='1m', **kwargs): ...
async def candles(self, symbol, start=None, end=None, interval='1m', **kwargs): ...
def l2_book_sync(self, symbol, **kwargs): ...
async def l2_book(self, symbol, **kwargs): ...

# Trading REST Methods
def place_order_sync(self, symbol, side, order_type, amount, price=None, **kwargs): ...
async def place_order(self, symbol, side, order_type, amount, price=None, **kwargs): ...
def cancel_order_sync(self, order_id, symbol=None, **kwargs): ...
async def cancel_order(self, order_id, symbol=None, **kwargs): ...
def order_status_sync(self, order_id, symbol=None, **kwargs): ...
async def order_status(self, order_id, symbol=None, **kwargs): ...
def balances_sync(self, **kwargs): ...
async def balances(self, **kwargs): ...

Exchange Support

Constants and Configuration

Standard constants for exchanges, channels, trading sides, and other enumerations, plus configuration management for feeds and authentication.

# Channel constants
L1_BOOK: str
L2_BOOK: str
L3_BOOK: str
TRADES: str
TICKER: str
FUNDING: str
OPEN_INTEREST: str
LIQUIDATIONS: str

# Exchange constants
COINBASE: str
BINANCE: str
KRAKEN: str
# ... all supported exchanges

# Trading constants
BUY: str
SELL: str
MAKER: str
TAKER: str

Constants and Configuration