Handles multiple feeds and returns normalized and standardized results across exchanges to client registered callbacks for events like trades, book updates, ticker updates, etc.
from cryptofeed import FeedHandler
fh = FeedHandler()
# ticker, trade, and book are user defined functions that
# will be called when ticker, trade and book updates are received
ticker_cb = {TICKER: TickerCallback(ticker)}
trade_cb = {TRADES: TradeCallback(trade)}
gemini_cb = {TRADES: TradeCallback(trade), L3_BOOK: BookCallback(book)}
fh.add_feed(GDAX(pairs=['BTC-USD'], channels=[TICKER], callbacks=ticker_cb)
fh.add_feed(Bitfinex(pairs=['BTC-USD'], channels=[TICKER], callbacks=ticker_cb)
fh.add_feed(Poloniex(channels=['USDT-BTC'], callbacks=trade_cb))
fh.add_feed(Gemini(pairs=['BTC-USD'], callbacks=gemini_cb)
fh.run()
Supports the following exchanges:
- Bitfinex
- GDAX
- Poloniex
- Gemini
- HitBTC
- Bitstamp
- BitMEX
Also provides a synthetic NBBO (National Best Bid/Offer) feed that aggregates the best bids and asks from the user specified feeds.
from cryptofeed.feedhandler import FeedHandler
from cryptofeed import GDAX, Bitfinex, HitBTC
def nbbo_ticker(pair, bid, ask, bid_feed, ask_feed):
print('Pair: {} Bid: {} Bid Feed: {} Ask: {} Ask Feed: {}'.format(pair,
bid,
bid_feed,
ask,
ask_feed))
fh = FeedHandler()
fh.add_nbbo([GDAX, Bitfinex, HitBTC], ['BTC-USD'], nbbo_ticker)
fh.run()
- EXX
- CEX
- BTCC
- Many more...
Some feeds do not support websocket. A framework for supporting non websocket feeds is planned.
Support for registering databases and writing directly to them via the handler (as opposed to client provided callbacks).
- Unix Domain Sockets
- Redis
- ZMQ