CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/pypi-cryptofeed

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

Pending
Overview
Eval results
Files

exchanges.mddocs/

Exchange Support

Pre-built exchange implementations supporting websocket and REST API access for 30+ major cryptocurrency exchanges, with unified interfaces and automatic data normalization across all supported venues.

Capabilities

Supported Exchanges

Complete list of all supported cryptocurrency exchanges with both websocket feeds and REST API access.

# Major Spot Exchanges
class Coinbase(Feed): ...
class Binance(Feed): ...
class Kraken(Feed): ...
class Bitfinex(Feed): ...
class Bitstamp(Feed): ...
class Gemini(Feed): ...
class KuCoin(Feed): ...
class HitBTC(Feed): ...
class Poloniex(Feed): ...

# Futures and Derivatives
class BinanceFutures(Feed): ...
class BinanceDelivery(Feed): ...
class KrakenFutures(Feed): ...
class Deribit(Feed): ...
class BitMEX(Feed): ...
class Bybit(Feed): ...
class OKX(Feed): ...
class Phemex(Feed): ...
class Delta(Feed): ...

# Regional Exchanges
class BinanceUS(Feed): ...
class BinanceTR(Feed): ...
class Bithumb(Feed): ...
class Upbit(Feed): ...
class IndependentReserve(Feed): ...

# Additional Exchanges
class AscendEX(Feed): ...
class AscendEXFutures(Feed): ...
class Bequant(Feed): ...
class BitDotCom(Feed): ...
class Bitflyer(Feed): ...
class Bitget(Feed): ...
class Blockchain(Feed): ...
class CryptoDotCom(Feed): ...
class dYdX(Feed): ...
class EXX(Feed): ...
class FMFW(Feed): ...
class Gateio(Feed): ...
class GateioFutures(Feed): ...
class Huobi(Feed): ...
class HuobiDM(Feed): ...
class HuobiSwap(Feed): ...
class OKCoin(Feed): ...
class Probit(Feed): ...

Exchange Base Classes

Base classes that provide common functionality for all exchange implementations.

class Exchange:
    def __init__(self, config=None, sandbox=False, subaccount=None, **kwargs):
        """
        Initialize exchange with configuration and credentials.
        
        Args:
            config (Config, optional): Configuration object or file path
            sandbox (bool): Whether to use sandbox/testnet environment
            subaccount (str, optional): Subaccount name for multi-account support
            **kwargs: Additional exchange-specific parameters
        """
    
    def symbols(self, refresh=False):
        """Get supported symbols for the exchange."""
    
    def symbol_mapping(self, refresh=False, headers=None):
        """Get symbol mapping between exchange and standard formats."""
    
    def info(self):
        """Get exchange information and supported features."""
    
    def std_channel_to_exchange(self, channel):
        """Convert standard channel name to exchange-specific format."""
    
    def exchange_channel_to_std(self, channel):
        """Convert exchange channel name to standard format."""
    
    @classmethod
    def timestamp_normalize(cls, ts):
        """Normalize datetime to UTC timestamp."""
    
    @classmethod
    def normalize_order_options(cls, option):
        """Normalize order options to exchange-specific format."""

class Feed(Exchange):
    def __init__(self, symbols=None, channels=None, callbacks=None, **kwargs):
        """
        Initialize exchange feed.
        
        Args:
            symbols (List[str]): List of symbols to subscribe to
            channels (List[str]): List of channels to subscribe to
            callbacks (Dict[str, callable]): Channel to callback mapping
            **kwargs: Exchange-specific configuration
        """
    
    async def start(self, loop):
        """Start the websocket feed."""
    
    async def stop(self):
        """Stop the websocket feed."""

REST API Support

Synchronous and asynchronous REST API methods for historical data and trading operations.

class RestExchange(Exchange):
    # Market Data Methods
    def ticker_sync(self, symbol, **kwargs):
        """Get ticker data synchronously."""
    
    async def ticker(self, symbol, **kwargs):
        """Get ticker data asynchronously."""
    
    def trades_sync(self, symbol, start=None, end=None, **kwargs):
        """Get trade history synchronously."""
    
    async def trades(self, symbol, start=None, end=None, **kwargs):
        """Get trade history asynchronously."""
    
    def candles_sync(self, symbol, start=None, end=None, interval='1m', **kwargs):
        """Get candle/OHLCV data synchronously."""
    
    async def candles(self, symbol, start=None, end=None, interval='1m', **kwargs):
        """Get candle/OHLCV data asynchronously."""
    
    def l2_book_sync(self, symbol, **kwargs):
        """Get L2 order book synchronously."""
    
    async def l2_book(self, symbol, **kwargs):
        """Get L2 order book asynchronously."""
    
    # Trading Methods (where supported)
    def place_order_sync(self, symbol, side, order_type, amount, price=None, **kwargs):
        """Place order synchronously."""
    
    async def place_order(self, symbol, side, order_type, amount, price=None, **kwargs):
        """Place order asynchronously."""
    
    def cancel_order_sync(self, order_id, symbol=None, **kwargs):
        """Cancel order synchronously."""
    
    async def cancel_order(self, order_id, symbol=None, **kwargs):
        """Cancel order asynchronously."""
    
    def order_status_sync(self, order_id, symbol=None, **kwargs):
        """Get order status synchronously."""
    
    async def order_status(self, order_id, symbol=None, **kwargs):
        """Get order status asynchronously."""
    
    def balances_sync(self, **kwargs):
        """Get account balances synchronously."""
    
    async def balances(self, **kwargs):
        """Get account balances asynchronously."""

Usage Examples

Basic Exchange Feed

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

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

fh = FeedHandler()
fh.add_feed(Coinbase(
    symbols=['BTC-USD', 'ETH-USD'],
    channels=[TRADES, TICKER],
    callbacks={TRADES: trade_handler}
))
fh.run()

Multiple Exchanges

from cryptofeed import FeedHandler
from cryptofeed.exchanges import Coinbase, Binance, Kraken
from cryptofeed.defines import TRADES

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

fh = FeedHandler()

# Different exchanges may use different symbol formats
fh.add_feed(Coinbase(symbols=['BTC-USD'], channels=[TRADES], callbacks={TRADES: trade_handler}))
fh.add_feed(Binance(symbols=['BTCUSDT'], channels=[TRADES], callbacks={TRADES: trade_handler}))
fh.add_feed(Kraken(symbols=['XBT/USD'], channels=[TRADES], callbacks={TRADES: trade_handler}))

fh.run()

Exchange Information

from cryptofeed.exchanges import Coinbase, Binance

# Get exchange capabilities
coinbase = Coinbase()
print(coinbase.info())  # Shows supported channels, authentication, etc.

# Get supported symbols
symbols = coinbase.symbols()
print(f'Coinbase supports {len(symbols)} symbols')

# Check symbol mapping
mapping = coinbase.symbol_mapping()
print(mapping['BTC-USD'])  # Shows exchange-specific symbol format

REST API Usage

import asyncio
from cryptofeed.exchanges import Coinbase

async def get_market_data():
    exchange = Coinbase()
    
    # Get current ticker
    ticker = await exchange.ticker('BTC-USD')
    print(f'BTC-USD: bid={ticker.bid}, ask={ticker.ask}')
    
    # Get recent trades
    trades = await exchange.trades('BTC-USD')
    print(f'Latest trade: {trades[-1].price}')
    
    # Get order book
    book = await exchange.l2_book('BTC-USD')
    print(f'Best bid: {list(book.book.bids.keys())[0]}')

asyncio.run(get_market_data())

Authenticated Channels

from cryptofeed import FeedHandler
from cryptofeed.exchanges import Coinbase
from cryptofeed.defines import ORDER_INFO, FILLS, BALANCES

def order_handler(order):
    print(f'Order update: {order.symbol} {order.side} {order.status}')

def fill_handler(fill):
    print(f'Fill: {fill.symbol} {fill.side} {fill.amount}@{fill.price}')

# Configure with API credentials
config = {
    'coinbase': {
        'key_id': 'your-api-key',
        'secret': 'your-secret',
        'passphrase': 'your-passphrase',
        'sandbox': False
    }
}

fh = FeedHandler()
fh.add_feed(Coinbase(
    symbols=['BTC-USD'],
    channels=[ORDER_INFO, FILLS],
    callbacks={
        ORDER_INFO: order_handler,
        FILLS: fill_handler
    },
    config=config
))
fh.run()

Channel Support by Exchange

from cryptofeed.exchanges import Coinbase, Binance
from cryptofeed.defines import *

# Check what channels each exchange supports
coinbase = Coinbase()
binance = Binance()

# Coinbase supports
coinbase_channels = [TRADES, TICKER, L2_BOOK, L3_BOOK, ORDER_INFO, FILLS]

# Binance supports  
binance_channels = [TRADES, TICKER, L1_BOOK, L2_BOOK, CANDLES, FUNDING, OPEN_INTEREST]

# Use exchange.info() to get definitive channel support
print(coinbase.info())
print(binance.info())

Install with Tessl CLI

npx tessl i tessl/pypi-cryptofeed

docs

backends.md

constants.md

exchanges.md

feed-management.md

index.md

types.md

tile.json