How to use the cryptofeed.FeedHandler function in cryptofeed

To help you get started, we’ve selected a few cryptofeed examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github bmoscon / cryptofeed / examples / demo_bybit.py View on Github external
def main():
    f = FeedHandler()

    f.add_feed(Bybit(pairs=['BTC-USD', 'ETH-USD', 'XRP-USD', 'EOS-USD'], channels=[TRADES], callbacks={TRADES: TradeCallback(trade)}))
    f.add_feed(Bybit(pairs=['BTC-USD', 'ETH-USD', 'XRP-USD', 'EOS-USD'], channels=[L2_BOOK], callbacks={L2_BOOK: BookCallback(book)}))

    f.run()
github bmoscon / cryptofeed / examples / demo_existing_loop.py View on Github external
def main():
    f = FeedHandler()
    # Note: EXX is extremely unreliable - sometimes a connection can take many many retries
    # f.add_feed(EXX(pairs=['BTC-USDT'], channels=[L2_BOOK, TRADES], callbacks={L2_BOOK: BookCallback(book), TRADES: TradeCallback(trade)}))
    f.add_feed(Binance(pairs=['BTC-USDT'], channels=[TRADES, TICKER, L2_BOOK], callbacks={L2_BOOK: BookCallback(book), TRADES: TradeCallback(trade), TICKER: TickerCallback(ticker)}))
    f.add_feed(COINBASE, pairs=['BTC-USD'], channels=[TICKER], callbacks={TICKER: TickerCallback(ticker)})
    f.add_feed(Coinbase(pairs=['BTC-USD'], channels=[TRADES], callbacks={TRADES: TradeCallback(trade)}))
    f.add_feed(Coinbase(config={L2_BOOK: ['BTC-USD', 'ETH-USD'], TRADES: ['ETH-USD', 'BTC-USD']}, callbacks={TRADES: TradeCallback(trade), L2_BOOK: BookCallback(book)}))

    f.run(start_loop=False)

    loop = asyncio.get_event_loop()
    loop.create_task(aio_task())
    loop.run_forever()
github BitcoinExchangeFH / BitcoinExchangeFH / befh / exchange / websocket_exchange.py View on Github external
def load(self, **kwargs):
        """Load.
        """
        super().load(is_initialize_instmt=False, **kwargs)
        self._feed_handler = FeedHandler()
        self._instrument_mapping = self._create_instrument_mapping()
        try:
            exchange = getattr(
                cryptofeed_exchanges,
                self._get_exchange_name(self._name))
        except AttributeError as e:
            raise ImportError(
                'Cannot load exchange %s from websocket' % self._name)

        callbacks = {
            L2_BOOK: BookCallback(self._update_order_book_callback),
            TRADES: TradeCallback(self._update_trade_callback)
        }

        if self._name.lower() == 'poloniex':
            self._feed_handler.add_feed(
github bmoscon / cryptofeed / examples / demo_influxdb.py View on Github external
def main():

    f = FeedHandler()
    f.add_feed(Bitmex(channels=[FUNDING, L2_BOOK], pairs=['XBTUSD'], callbacks={FUNDING: FundingInflux('http://localhost:8086', 'example'), L2_BOOK: BookInflux('http://localhost:8086', 'example', numeric_type=float), BOOK_DELTA: BookDeltaInflux('http://localhost:8086', 'example', numeric_type=float)}))
    f.add_feed(Coinbase(channels=[TRADES], pairs=['BTC-USD'], callbacks={TRADES: TradeInflux('http://localhost:8086', 'example')}))
    f.add_feed(Coinbase(channels=[L2_BOOK], pairs=['BTC-USD'], callbacks={L2_BOOK: BookInflux('http://localhost:8086', 'example', numeric_type=float), BOOK_DELTA: BookDeltaInflux('http://localhost:8086', 'example', numeric_type=float)}))
    f.add_feed(Coinbase(channels=[TICKER], pairs=['BTC-USD'], callbacks={TICKER: TickerInflux('http://localhost:8086', 'example', numeric_type=float)}))

    """
    # Uncomment Here When Using InfluxDB 2.0
    # For InfluxDB 2.0, provide additional org, bucket(instead of db), token and precision(optional)
    # [Note] In order to use visualization and aggregation, numeric_type with float is strongly recommended.

    ADDR = 'https://localhost:9999'
    ORG='my-org'
    BUCKET = 'my-bucket'
    TOKEN = 'token-something-like-end-with-=='

    f = FeedHandler()
github bmoscon / cryptofeed / examples / demo_arctic.py View on Github external
def main():
    f = FeedHandler()
    f.add_feed(Bitmex(channels=[TRADES, FUNDING], pairs=['XBTUSD'], callbacks={TRADES: TradeArctic('cryptofeed-test'), FUNDING: FundingArctic('cryptofeed-test')}))
    f.add_feed(Bitfinex(channels=[TRADES], pairs=['BTC-USD'], callbacks={TRADES: TradeArctic('cryptofeed-test')}))
    f.add_feed(Coinbase(channels=[TICKER], pairs=['BTC-USD'], callbacks={TICKER: TickerArctic('cryptofeed-test')}))
    f.run()
github bmoscon / cryptofeed / examples / demo_mongo.py View on Github external
def main():
    """
    Because periods cannot be in keys in documents in mongo, the bids and asks dictionaries
    are converted to BSON. They will need to be decoded after being read
    """
    f = FeedHandler()
    f.add_feed(Coinbase(max_depth=10, channels=[L2_BOOK],
                        pairs=['BTC-USD'],
                        callbacks={TRADES: TradeMongo('coinbase', collection='trades'),
                                   L2_BOOK: BookMongo('coinbase', collection='l2_book'),
                                   BOOK_DELTA: BookDeltaMongo('coinbase', collection='l2_book')}))

    f.run()
github bmoscon / cryptofeed / examples / demo_udp.py View on Github external
def main():
    try:
        p = Process(target=receiver, args=(5555,))
        p.start()

        f = FeedHandler()
        f.add_feed(Coinbase(channels=[L2_BOOK, TRADES], pairs=['BTC-USD'],
                            callbacks={TRADES: TradeSocket('udp://127.0.0.1', port=5555),
                                       L2_BOOK: BookSocket('udp://127.0.0.1', port=5555),
                                       BOOK_DELTA: BookDeltaSocket('udp://127.0.0.1', port=5555)
                                       }))

        f.run()
    finally:
        p.terminate()
github bmoscon / cryptofeed / examples / demo_config.py View on Github external
def main():
    f = FeedHandler()

    f.add_feed(Coinbase(config={TRADES: ['BTC-USD'], L3_BOOK: ['ETH-USD']}, callbacks={TRADES: TradeCallback(trade), L3_BOOK: BookCallback(book)}))

    f.run()
github bmoscon / cryptofeed / examples / demo_ftx_funding.py View on Github external
def main():
    f = FeedHandler()
    f.add_feed(FTX(pairs=['BTC-PERP', 'THETA-PERP'], channels=[FUNDING], callbacks={FUNDING: FundingCallback(funding)}))
    f.run()
github bmoscon / cryptofeed / examples / demo_zmq.py View on Github external
def main():
    try:
        p = Process(target=receiver, args=(5678,))

        p.start()

        f = FeedHandler()
        f.add_feed(Kraken(max_depth=1, channels=[L2_BOOK], pairs=['ETH-USD'], callbacks={L2_BOOK: BookZMQ(port=5678)}))
        f.add_feed(Coinbase(channels=[TICKER], pairs=['BTC-USD'], callbacks={TICKER: TickerZMQ(port=5678)}))

        f.run()

    finally:
        p.terminate()