Handles multiple cryptocurrency exchange data feeds and returns normalized and standardized results to client registered callbacks for events like trades, book updates, ticker updates, etc. Utilizes websockets when possible, but can also poll data via REST endpoints if a websocket is not provided.
- Bitfinex
- bitFlyer
- Bithumb
- Bitstamp
- Bybit
- Binance
- Binance Delivery
- Binance Futures
- Binance US
- Bitget
- Coinbase
- Crypto.com
- Deribit
- Gate
- Gate Futures
- dYdX v4
- Gemini
- Hyperliquid
- HTX (formerly Huobi)
- HTX Swap (Coin-M and USDT-M)
- Independent Reserve
- Kraken
- MEXC (spot)
- Kraken Futures
- KuCoin
- OKX
- Phemex
- Poloniex
- Upbit
Create a FeedHandler object and add subscriptions. For the various data channels that an exchange supports, you can supply callbacks for data events, or use provided backends (described below) to handle the data for you. Start the feed handler and you're done!
from cryptofeed import FeedHandler
# not all imports shown for clarity
fh = FeedHandler()
# ticker, trade and book are user defined coroutine functions, each taking the
# normalized object and the timestamp cryptofeed received the message at:
#
# async def trade(t, receipt_timestamp):
# print(f'{t.exchange} {t.symbol} {t.side} {t.amount} @ {t.price}')
#
# a callback must be async - wrap a synchronous one in cryptofeed.callback.ExecutorCallback
ticker_cb = {TICKER: ticker}
trade_cb = {TRADES: trade}
gemini_cb = {TRADES: trade, L2_BOOK: book}
fh.add_feed(Coinbase(symbols=['BTC-USD'], channels=[TICKER], callbacks=ticker_cb))
fh.add_feed(Bitfinex(symbols=['BTC-USD'], channels=[TICKER], callbacks=ticker_cb))
fh.add_feed(Poloniex(symbols=['BTC-USDT'], channels=[TRADES], callbacks=trade_cb))
fh.add_feed(Gemini(symbols=['BTC-USD', 'ETH-USD'], channels=[TRADES, L2_BOOK], callbacks=gemini_cb))
fh.run()Cryptofeed also provides a synthetic NBBO (National Best Bid/Offer) feed that aggregates the best bids and asks from the user specified feeds.