Ejemplo n.º 1
0
def main():
    f = FeedHandler()
    f.add_feed(Bitmex(channels=[FUNDING, L3_BOOK], pairs=['XBTUSD'], callbacks={FUNDING: FundingInflux('http://localhost:8086', 'example'), L3_BOOK: BookInflux('http://localhost:8086', 'example', depth=10)}))
    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', depth=10)}))

    f.run()
Ejemplo n.º 2
0
def main():

    f = FeedHandler()
    f.add_feed(
        Bitmex(channels=[FUNDING, L2_BOOK],
               symbols=['BTC-USD-PERP'],
               callbacks={
                   FUNDING: FundingInflux(INFLUX_ADDR, ORG, BUCKET, TOKEN),
                   L2_BOOK: BookInflux(INFLUX_ADDR, ORG, BUCKET, TOKEN)
               }))
    f.add_feed(
        Coinbase(
            channels=[TRADES],
            symbols=['BTC-USD'],
            callbacks={TRADES: TradeInflux(INFLUX_ADDR, ORG, BUCKET, TOKEN)}))
    f.add_feed(
        Coinbase(
            channels=[L2_BOOK],
            symbols=['BTC-USD'],
            callbacks={L2_BOOK: BookInflux(INFLUX_ADDR, ORG, BUCKET, TOKEN)}))
    f.add_feed(
        Coinbase(
            channels=[TICKER],
            symbols=['BTC-USD'],
            callbacks={TICKER: TickerInflux(INFLUX_ADDR, ORG, BUCKET, TOKEN)}))

    f.run()
def main(pairs):
    f = FeedHandler()
    trade_influx = TradeInflux('http://localhost:8086',
                               'trades',
                               create_db=False,
                               numeric_type=float)
    f.add_feed(FTX(channels=[TRADES],
                   pairs=pairs,
                   callbacks={TRADES: trade_influx}),
               timeout=120)
    f.run()
Ejemplo n.º 4
0
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)
                 }))

    f.run()
Ejemplo n.º 5
0
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()
    funding_influx = FundingInflux(ADDR, org=ORG, bucket=BUCKET, token=TOKEN, numeric_type=float) 
    trade_influx = TradeInflux(ADDR, org=ORG, bucket=BUCKET, token=TOKEN, numeric_type=float) 
    book_influx = BookInflux(ADDR, org=ORG, bucket=BUCKET, token=TOKEN, numeric_type=float) 
    bookdelta_influx = BookDeltaInflux(ADDR, org=ORG, bucket=BUCKET, token=TOKEN, numeric_type=float) 
    ticker_influx = TickerInflux(ADDR, org=ORG, bucket=BUCKET, token=TOKEN, numeric_type=float) 
    
    f.add_feed(Bitmex(channels=[FUNDING, L2_BOOK],pairs=['XBTUSD'], callbacks={FUNDING: funding_influx, L2_BOOK: book_influx, BOOK_DELTA: bookdelta_influx}))
    f.add_feed(Coinbase(channels=[TRADES], pairs=['BTC-USD'], callbacks={TRADES: trade_influx}))
    f.add_feed(Coinbase(channels=[L2_BOOK], pairs=['BTC-USD'], callbacks={L2_BOOK: book_influx, BOOK_DELTA: bookdelta_influx}))
    f.add_feed(Coinbase(channels=[TICKER], pairs=['BTC-USD'], callbacks={TICKER: ticker_influx}))
    """

    f.run()
Ejemplo n.º 6
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)