class Triangle: def __init__(self, coin_a: str, coin_b: str, tri_coins: list, fee, redis_obj, Exchange): self.coin_a = coin_a self.coin_b = coin_b self.tri_coins = tri_coins self.redis_obj = redis_obj self.Exchange = Exchange self.sep = '-' self.root = self.coin_a + self.sep + self.coin_b self.redis_tree = RedisTree( coin_a=self.coin_a, coin_b=self.coin_b, tri_coins=self.tri_coins, fee=fee, redis_obj=self.redis_obj ) self.all_symbols = self._prepare_symbols() self.feed = FeedHandler() def _prepare_symbols(self): all_symbols = [self.coin_a + self.sep + self.coin_b] for coin in self.tri_coins: all_symbols.extend( [coin + self.sep + self.coin_a, coin + self.sep + self.coin_b] ) return all_symbols def _process_feed(self, pair, bid, bid_size, ask, ask_size, bid_feed, ask_feed): coin_a, coin_b = pair.split(self.sep) if pair == self.root: print('Updating Root | {} | {}'.format(pair, ask)) self.redis_tree.update_root(bid, bid_size, ask, ask_size, time.time_ns()) else: print('Updating Branch | {} | {}'.format(pair, bid)) self.redis_tree.update_branch(coin_a, coin_b, bid, bid_size, ask, ask_size, time.time_ns()) def build(self): self.redis_tree.prepare_tree() self.feed.add_nbbo( [self.Exchange], self.all_symbols, self._process_feed ) self.feed.run()
def main(): f = FeedHandler() f.add_nbbo([Coinbase, Kraken, Gemini], ['BTC-USD'], nbbo_update) f.run()
def main(): f = FeedHandler() #BitFinex f.add_feed( Bitfinex(pairs=['BTC-USD'], channels=[L2_BOOK, TICKER], callbacks={ L2_BOOK: BookCallback(book), TICKER: TickerCallback(ticker) })) f.add_feed( Bitfinex(pairs=['BTC-USD'], channels=[TRADES], callbacks={TRADES: TradeCallback(trade)})) f.add_nbbo([Bitfinex, Gemini, HitBTC, Bitstamp], ['BTC-USD'], nbbo_ticker) f.add_feed( Poloniex(channels=['USDT-BTC', 'USDC-BTC'], callbacks={TICKER: TickerCallback(ticker)})) f.add_feed( Poloniex(channels=['USDT-BTC', 'USDC-BTC'], callbacks={L2_BOOK: BookCallback(book)})) f.add_feed( Poloniex(channels=['USDT-BTC', 'USDC-BTC'], callbacks={TRADES: TradeCallback(trade)})) f.add_feed( Gemini(pairs=['BTC-USD'], callbacks={ L2_BOOK: BookCallback(book), TRADES: TradeCallback(trade) })) f.add_feed( HitBTC(channels=[TRADES], pairs=['BTC-USD'], callbacks={TRADES: TradeCallback(trade)})) f.add_feed( HitBTC(channels=[L2_BOOK], pairs=['BTC-USD'], callbacks={L2_BOOK: BookCallback(book)})) f.add_feed( Bitmex(pairs=['XBTUSD'], channels=[TRADES], callbacks={TRADES: TradeCallback(trade)})) f.add_feed( Bitmex(pairs=['XBTUSD'], channels=[L3_BOOK], callbacks={L3_BOOK: BookCallback(book)})) f.add_feed( Bitstamp(channels=[L2_BOOK, TRADES], pairs=['BTC-USD'], callbacks={ L2_BOOK: BookCallback(book), TRADES: TradeCallback(trade) })) #f.add_nbbo([Bitfinex, Gemini], ['BTC-USD'], nbbo_ticker) f.add_feed( Bitfinex(pairs=['BTC-USD'], channels=[TICKER], callbacks={TICKER: TickerCallback(ticker)})) f.add_feed( Gemini(pairs=['BTC-USD'], callbacks={TICKER: TickerCallback(ticker)})) f.add_feed( HitBTC(pairs=['BTC-USD'], channels=[TICKER], callbacks={TICKER: TickerCallback(ticker)})) #f.add_feed(Bitmex(Bitstamp=['BTC-USD'], channels=[TICKER], callbacks={TICKER: TickerCallback(ticker)})) f.run()
from cryptofeed import FeedHandler from cryptofeed.exchanges import Coinbase def nbbo_update(symbol, bid, bid_size, ask, ask_size, bid_feed, ask_feed): print(f'Pair: {symbol} ' + f'Bid Price: {bid:.2f} ' + f'Bid Size: {bid_size:.6f} ' + f'Bid Feed: {bid_feed} ' + f'Ask Price: {ask:.2f} ' + f'Ask Size: {ask_size:.6f} ' + f'Ask Feed: {ask_feed}') feed = FeedHandler() feed.add_nbbo([Coinbase], ['BTC-USD'], nbbo_update) feed.run()
def main(): f = FeedHandler() f.add_nbbo([Coinbase, HitBTC, Bitfinex, Bitstamp, Gemini], ['BTC-USD'], nbbo_update) f.run()