Пример #1
0
def main():
    f = FeedHandler()
    f.add_feed(
        Bitmex(channels=[TRADES, FUNDING, OPEN_INTEREST],
               pairs=['XBTUSD'],
               callbacks={
                   TRADES: TradeRedis(),
                   FUNDING: FundingRedis(),
                   OPEN_INTEREST: OpenInterestRedis()
               }))
    f.add_feed(
        Bitfinex(channels=[TRADES],
                 pairs=['BTC-USD'],
                 callbacks={TRADES: TradeRedis()}))
    f.add_feed(
        Coinbase(channels=[TRADES],
                 pairs=['BTC-USD'],
                 callbacks={TRADES: TradeRedis()}))
    f.add_feed(
        Coinbase(max_depth=10,
                 channels=[L2_BOOK],
                 pairs=['BTC-USD'],
                 callbacks={L2_BOOK: BookRedis()}))
    f.add_feed(Gemini(pairs=['BTC-USD'], callbacks={TRADES: TradeRedis()}))

    f.run()
Пример #2
0
def main():
    f = FeedHandler()
    f.add_feed(
        Bitmex(channels=[TRADES, FUNDING, OPEN_INTEREST],
               symbols=['BTC-USD'],
               callbacks={
                   TRADES: TradeRedis(),
                   FUNDING: FundingRedis(),
                   OPEN_INTEREST: OpenInterestRedis()
               }))
    f.add_feed(
        Bitfinex(channels=[TRADES],
                 symbols=['BTC-USD'],
                 callbacks={TRADES: TradeRedis()}))
    f.add_feed(
        Coinbase(channels=[TRADES],
                 symbols=['BTC-USD'],
                 callbacks={TRADES: TradeRedis()}))
    f.add_feed(
        Coinbase(max_depth=10,
                 channels=[L2_BOOK],
                 symbols=['BTC-USD'],
                 callbacks={L2_BOOK: BookRedis()}))
    f.add_feed(Gemini(symbols=['BTC-USD'], callbacks={TRADES: TradeRedis()}))
    f.add_feed(
        Binance(symbols=['BTC-USDT'],
                channels=[CANDLES],
                callbacks={CANDLES: CandlesStream()}))

    f.run()
Пример #3
0
def main():
    f = FeedHandler()
    f.add_feed(Bitmex(channels=[TRADES, FUNDING], pairs=['XBTUSD'], callbacks={TRADES: TradeRedis(), FUNDING: FundingRedis()}))
    f.add_feed(Bitfinex(channels=[TRADES], pairs=['BTC-USD'], callbacks={TRADES: TradeRedis()}))
    f.add_feed(GDAX(channels=[TRADES], pairs=['BTC-USD'], callbacks={TRADES: TradeRedis()}))
    f.add_feed(Gemini(pairs=['BTC-USD'], callbacks={TRADES: TradeRedis()}))

    f.run()
Пример #4
0
def main():
    f = FeedHandler()
    f.add_feed(Bitmex(channels=[TRADES, FUNDING], pairs=['XBTUSD'], callbacks={TRADES: TradeRedis(), FUNDING: FundingRedis()}))
    f.add_feed(Bitfinex(channels=[TRADES], pairs=['BTC-USD'], callbacks={TRADES: TradeRedis()}))
    f.add_feed(Coinbase(channels=[TRADES], pairs=['BTC-USD'], callbacks={TRADES: TradeRedis()}))
    f.add_feed(Coinbase(channels=[L2_BOOK], pairs=['BTC-USD'], callbacks={L2_BOOK: BookRedis(depth=10)}))
    f.add_feed(Gemini(pairs=['BTC-USD'], callbacks={TRADES: TradeRedis()}))

    f.run()
Пример #5
0
def main():
    f = FeedHandler()
    f.add_feed(Bitmex(channels=[TRADES, FUNDING, OPEN_INTEREST], symbols=['BTC-USD'], callbacks={TRADES: TradeRedis(), FUNDING: FundingRedis(), OPEN_INTEREST: OpenInterestRedis()}))
    f.add_feed(Bitfinex(channels=[TRADES], symbols=['BTC-USD'], callbacks={TRADES: TradeRedis()}))
    f.add_feed(Coinbase(channels=[TRADES], symbols=['BTC-USD'], callbacks={TRADES: TradeRedis()}))
    f.add_feed(Coinbase(channels=[L2_BOOK], symbols=['BTC-USD'], callbacks={BOOK_DELTA: BookDeltaStream(), L2_BOOK: BookStream()}))
    f.add_feed(Gemini(symbols=['BTC-USD'], callbacks={TRADES: TradeRedis()}))
    f.add_feed(Binance(candle_closed_only=True, symbols=['BTC-USDT'], channels=[CANDLES], callbacks={CANDLES: CandlesRedis(score_key='start')}))

    f.run()
Пример #6
0
def main():
    config = {'log': {'filename': 'redis-demo.log', 'level': 'INFO'}}
    f = FeedHandler(config=config)
    f.add_feed(Bitmex(channels=[TRADES, FUNDING, OPEN_INTEREST], symbols=['BTC-USD-PERP'], callbacks={TRADES: TradeRedis(), FUNDING: FundingRedis(), OPEN_INTEREST: OpenInterestRedis()}))
    f.add_feed(Bitfinex(channels=[TRADES], symbols=['BTC-USD'], callbacks={TRADES: TradeRedis()}))
    f.add_feed(Coinbase(channels=[TRADES], symbols=['BTC-USD'], callbacks={TRADES: TradeRedis()}))
    f.add_feed(Coinbase(channels=[L2_BOOK], symbols=['BTC-USD'], callbacks={L2_BOOK: BookStream()}))
    f.add_feed(Gemini(symbols=['BTC-USD'], callbacks={TRADES: TradeRedis()}))
    f.add_feed(Binance(candle_closed_only=True, symbols=['BTC-USDT'], channels=[CANDLES], callbacks={CANDLES: CandlesRedis(score_key='start')}))
    f.add_feed(Binance(max_depth=10, symbols=['BTC-USDT'], channels=[L2_BOOK], callbacks={L2_BOOK: BookRedis(snapshots_only=True)}))

    f.run()
Пример #7
0
def load_config() -> Feed:
    exchange = os.environ.get('EXCHANGE')
    symbols = os.environ.get('SYMBOLS')

    if symbols is None:
        raise ValueError("Symbols must be specified")
    symbols = symbols.split(",")

    channels = os.environ.get('CHANNELS')
    if channels is None:
        raise ValueError("Channels must be specified")
    channels = channels.split(",")

    config = os.environ.get('CONFIG')
    backend = os.environ.get('BACKEND')
    snap_only = os.environ.get('SNAPSHOT_ONLY', False)
    if snap_only:
        if snap_only.lower().startswith('f'):
            snap_only = False
        elif snap_only.lower().startswith('t'):
            snap_only = True
        else:
            raise ValueError('Invalid value specified for SNAPSHOT_ONLY')
    snap_interval = os.environ.get('SNAPSHOT_INTERVAL', 1000)
    snap_interval = int(snap_interval)
    host = os.environ.get('HOST', '127.0.0.1')
    port = os.environ.get('PORT')
    if port:
        port = int(port)
    candle_interval = os.environ.get('CANDLE_INTERVAL', '1m')
    database = os.environ.get('DATABASE')
    user = os.environ.get('USER')
    password = os.environ.get('PASSWORD')
    org = os.environ.get('ORG')
    bucket = os.environ.get('BUCKET')
    token = os.environ.get('TOKEN')

    cbs = None
    if backend == 'REDIS' or backend == 'REDISSTREAM':
        kwargs = {'host': host, 'port': port if port else 6379}
        cbs = {
            L2_BOOK:
            BookRedis(snapshot_interval=snap_interval,
                      snapshots_only=snap_only,
                      **kwargs) if backend == 'REDIS' else BookStream(
                          snapshot_interval=snap_interval,
                          snapshots_only=snap_only,
                          **kwargs),
            TRADES:
            TradeRedis(**kwargs) if backend == 'REDIS' else TradeStream(
                **kwargs),
            TICKER:
            TickerRedis(**kwargs) if backend == 'REDIS' else TickerStream(
                **kwargs),
            FUNDING:
            FundingRedis(**kwargs) if backend == 'REDIS' else FundingStream(
                **kwargs),
            CANDLES:
            CandlesRedis(**kwargs) if backend == 'REDIS' else CandlesStream(
                **kwargs),
            OPEN_INTEREST:
            OpenInterestRedis(**kwargs)
            if backend == 'REDIS' else OpenInterestStream(**kwargs),
            LIQUIDATIONS:
            LiquidationsRedis(**kwargs)
            if backend == 'REDIS' else LiquidationsStream(**kwargs)
        }
    elif backend == 'MONGO':
        kwargs = {'host': host, 'port': port if port else 27101}
        cbs = {
            L2_BOOK:
            BookMongo(database,
                      snapshot_interval=snap_interval,
                      snapshots_only=snap_only,
                      **kwargs),
            TRADES:
            TradeMongo(database, **kwargs),
            TICKER:
            TickerMongo(database, **kwargs),
            FUNDING:
            FundingMongo(database, **kwargs),
            CANDLES:
            CandlesMongo(database, **kwargs),
            OPEN_INTEREST:
            OpenInterestMongo(database, **kwargs),
            LIQUIDATIONS:
            LiquidationsMongo(database, **kwargs)
        }
    elif backend == 'POSTGRES':
        kwargs = {
            'db': database,
            'host': host,
            'port': port if port else 5432,
            'user': user,
            'pw': password
        }
        cbs = {
            L2_BOOK:
            BookPostgres(snapshot_interval=snap_interval,
                         snapshots_only=snap_only,
                         **kwargs),
            TRADES:
            TradePostgres(**kwargs),
            TICKER:
            TickerPostgres(**kwargs),
            FUNDING:
            FundingPostgres(**kwargs),
            CANDLES:
            CandlesPostgres(**kwargs),
            OPEN_INTEREST:
            OpenInterestPostgres(**kwargs),
            LIQUIDATIONS:
            LiquidationsPostgres(**kwargs)
        }
    elif backend in ('TCP', 'UDP', 'UDS'):
        kwargs = {'port': port}
        cbs = {
            L2_BOOK:
            BookSocket(host,
                       snapshot_interval=snap_interval,
                       snapshots_only=snap_only,
                       **kwargs),
            TRADES:
            TradeSocket(host, **kwargs),
            TICKER:
            TickerSocket(host, **kwargs),
            FUNDING:
            FundingSocket(host, **kwargs),
            CANDLES:
            CandlesSocket(host, **kwargs),
            OPEN_INTEREST:
            OpenInterestSocket(host, **kwargs),
            LIQUIDATIONS:
            LiquidationsSocket(host, **kwargs)
        }
    elif backend == 'INFLUX':
        args = (host, org, bucket, token)
        cbs = {
            L2_BOOK:
            BookInflux(*args,
                       snapshot_interval=snap_interval,
                       snapshots_only=snap_only),
            TRADES:
            TradeInflux(*args),
            TICKER:
            TickerInflux(*args),
            FUNDING:
            FundingInflux(*args),
            CANDLES:
            CandlesInflux(*args),
            OPEN_INTEREST:
            OpenInterestInflux(*args),
            LIQUIDATIONS:
            LiquidationsInflux(*args)
        }
    elif backend == 'QUEST':
        kwargs = {'host': host, 'port': port if port else 9009}
        cbs = {
            L2_BOOK: BookQuest(**kwargs),
            TRADES: TradeQuest(**kwargs),
            TICKER: TickerQuest(**kwargs),
            FUNDING: FundingQuest(**kwargs),
            CANDLES: CandlesQuest(**kwargs),
            OPEN_INTEREST: OpenInterestQuest(**kwargs),
            LIQUIDATIONS: LiquidationsQuest(**kwargs)
        }
    elif backend == 'TTY':
        cbs = {
            L2_BOOK: tty,
            TRADES: tty,
            TICKER: tty,
            FUNDING: tty,
            CANDLES: tty,
            OPEN_INTEREST: tty,
            LIQUIDATIONS: tty
        }
    else:
        raise ValueError('Invalid backend specified')

    # Prune unused callbacks
    remove = [chan for chan in cbs if chan not in channels]
    for r in remove:
        del cbs[r]

    return EXCHANGE_MAP[exchange](candle_intterval=candle_interval,
                                  symbols=symbols,
                                  channels=channels,
                                  config=config,
                                  callbacks=cbs)