Пример #1
0
def main():
    f = FeedHandler()

    # Deribit can't handle 400+ simultaneous requests, so if all
    # instruments are needed they should be fed in the different calls

    config = {
        TRADES: ["BTC-PERPETUAL"],
        TICKER: ['ETH-PERPETUAL'],
        FUNDING: ['ETH-PERPETUAL'],
        OPEN_INTEREST: ['ETH-PERPETUAL']
    }
    f.add_feed(
        Deribit(config=config,
                callbacks={
                    OPEN_INTEREST: oi,
                    FUNDING: funding,
                    TICKER: TickerCallback(ticker),
                    TRADES: TradeCallback(trade)
                }))
    f.add_feed(
        Deribit(pairs=['BTC-PERPETUAL'],
                channels=[L2_BOOK],
                callbacks={L2_BOOK: BookCallback(book)}))

    f.add_feed(
        Deribit(pairs=['BTC-26JUN20', 'BTC-25SEP20-11000-P'],
                channels=[TICKER],
                callbacks={TICKER: TickerCallback(ticker)}))

    f.run()
Пример #2
0
def main():
    f = FeedHandler()

    # Deribit can't handle 400+ simultaneous requests, so if all
    # instruments are needed they should be fed in the different calls

    sub = {
        TRADES: ["BTC-PERPETUAL"],
        TICKER: ['ETH-PERPETUAL'],
        FUNDING: ['ETH-PERPETUAL'],
        OPEN_INTEREST: ['ETH-PERPETUAL']
    }
    f.add_feed(
        Deribit(subscription=sub,
                callbacks={
                    OPEN_INTEREST: oi,
                    FUNDING: funding,
                    TICKER: TickerCallback(ticker),
                    TRADES: TradeCallback(trade)
                }))
    f.add_feed(
        Deribit(symbols=['BTC-PERPETUAL'],
                channels=[L2_BOOK],
                callbacks={L2_BOOK: BookCallback(book)}))

    f.run()
Пример #3
0
def main():
    f = FeedHandler()

    # Deribit can't handle 400+ simultaneous requests, so if all
    # instruments are needed they should be fed in the different calls

    config = {TRADES: ['BTC-28JUN19', "ETH-27SEP19", "BTC-PERPETUAL"], TICKER: ['ETH-27SEP19']}
    f.add_feed(Deribit(config=config, callbacks={TICKER: TickerCallback(ticker), TRADES: TradeCallback(trade)}))

    f.add_feed(Deribit(pairs=['BTC-PERPETUAL'], channels=[L2_BOOK], callbacks={L2_BOOK: BookCallback(book)}))
    f.run()
Пример #4
0
def main():
    f = FeedHandler()
    f.add_feed(
        FTX(pairs=ftx_pairs(),
            channels=[OPEN_INTEREST, LIQUIDATIONS],
            callbacks={
                OPEN_INTEREST: OpenInterestCallback(oi),
                LIQUIDATIONS: LiquidationCallback(liquidations)
            }))

    f.add_feed(
        BinanceFutures(pairs=binance_futures_pairs(),
                       channels=[OPEN_INTEREST, LIQUIDATIONS],
                       callbacks={
                           OPEN_INTEREST: OpenInterestCallback(oi),
                           LIQUIDATIONS: LiquidationCallback(liquidations)
                       }))

    f.add_feed(
        Deribit(pairs=['BTC-PERPETUAL'],
                channels=[OPEN_INTEREST, LIQUIDATIONS],
                callbacks={
                    OPEN_INTEREST: OpenInterestCallback(oi),
                    LIQUIDATIONS: LiquidationCallback(liquidations)
                }))
    f.run()
Пример #5
0
def main():
    f = FeedHandler()
    f.add_feed(
        FTX(symbols=FTX.info()['symbols'],
            channels=[OPEN_INTEREST, LIQUIDATIONS],
            callbacks={
                OPEN_INTEREST: OpenInterestCallback(oi),
                LIQUIDATIONS: LiquidationCallback(liquidations)
            }))
    symbols = [
        s for s in BinanceFutures.info()['symbols'] if 'PINDEX' not in s
    ]
    f.add_feed(
        BinanceFutures(symbols=symbols,
                       channels=[OPEN_INTEREST, LIQUIDATIONS],
                       callbacks={
                           OPEN_INTEREST: OpenInterestCallback(oi),
                           LIQUIDATIONS: LiquidationCallback(liquidations)
                       }))

    f.add_feed(
        Deribit(symbols=['BTC-USD-PERPETUAL', 'ETH-USD-PERPETUAL'],
                channels=[LIQUIDATIONS, OPEN_INTEREST],
                callbacks={
                    OPEN_INTEREST: OpenInterestCallback(oi),
                    LIQUIDATIONS: LiquidationCallback(liquidations)
                }))
    f.run()
Пример #6
0
def main():
    try:
        # p = Process(target=receiver, args=(5678,))
        # p.start()

        f = FeedHandler(config="config.yaml")
        all_subscription = get_new_subscription()
        for key, value in other_subscription.items():
            all_subscription[key].update(value)
        print(all_subscription)
        deribit = Deribit(config="config.yaml",
                          max_depth=1,
                          subscription=all_subscription,
                          callbacks=callbacks)
        f.add_feed(deribit)
        # f.add_feed(Deribit(max_depth=1, channels=[L2_BOOK], symbols=['BTC-PERPETUAL'], callbacks={L2_BOOK: BookZMQ(port=5678)}))
        # f.add_feed(Coinbase(channels=[TICKER], symbols=['BTC-USD'], callbacks={TICKER: TickerZMQ(port=5678)}))
        f.run(start_loop=True,
              tasks=[
                  do_periodically_at(
                      8, 1, 1,
                      functools.partial(subscribe_to_new_subscription,
                                        deribit))
              ])

    finally:
        p.terminate()
Пример #7
0
def main():
    f = FeedHandler()
    symbols = Deribit.get_instruments()
    print(len(symbols))
    # symbols = [symbol for symbol in symbols if symbol.endswith("-C") or symbol.endswith("-P")]
    print(len(symbols))
    f.add_feed(Deribit(channels=[TICKER, TRADES], symbols=symbols, callbacks={TICKER: DeribitTickerPostgres(**postgres_cfg), TRADES: DeribitTradePostgres(**postgres_cfg)}))
    f.run()
Пример #8
0
def main():
    f = FeedHandler()

    deribit_ex = Deribit(['BTC-PERPETUAL', 'ETH-PERPETUAL'])
    instruments = deribit_ex.get_instruments()
    timestamps = [get_expiry_date_of_instrument(x) for x in instruments]
    timestamps = [x for x in timestamps if x != None]
    timestamps_set_list = list(set(timestamps))
    timestamps_set_list.sort()
    result = list(zip(instruments, timestamps))
    result = [x for x in result if not x[1] == None]
    result = sorted(result, key=operator.itemgetter(1))
    first_timestamp = result[0][1]
    result_latest_3 = [x for x in result if x[1] in timestamps_set_list[0:3]]
    instruments_lastest_3 = [x[0] for x in result_latest_3]
    # timestamps = [x[1] for x in result]

    # Deribit can't handle 400+ simultaneous requests, so if all
    # instruments are needed they should be fed in the different calls

    # config = {TRADES: ["BTC-PERPETUAL"], TICKER: ['ETH-PERPETUAL'], FUNDING: ['ETH-PERPETUAL'], OPEN_INTEREST: ['ETH-PERPETUAL']}
    # f.add_feed(Deribit(config=config, callbacks={OPEN_INTEREST: oi, FUNDING: funding, TICKER: TickerCallback(ticker), TRADES: TradeCallback(trade)}))
    # f.add_feed(Deribit(pairs=['BTC-PERPETUAL'], channels=[L2_BOOK], callbacks={L2_BOOK: BookCallback(book)}))

    # f.add_feed(Deribit(pairs=['BTC-PERPETUAL', 'BTC-27DEC20-26500-C'], channels=[TICKER], callbacks={TICKER: TickerCallback(ticker)}))
    f.add_feed(
        Deribit(pairs=['BTC-PERPETUAL', 'ETH-PERPETUAL'],
                channels=[TRADES],
                callbacks={TRADES: TradeCallback(trade)}))
    # f.add_feed(Deribit(pairs=['BTC-28DEC20-26500-C'], channels=[L2_BOOK], callbacks={L2_BOOK: BookCallback(book)} ))
    f.add_feed(
        Deribit(pairs=instruments_lastest_3,
                channels=[L2_BOOK],
                callbacks={L2_BOOK: BookCallback(book)}))

    f.run()
Пример #9
0
def main():
    f = FeedHandler(config="config.yaml")
    all_subscription = get_new_subscription()
    for key, value in other_subscription.items():
        all_subscription[key].update(value)
    print(all_subscription)
    deribit = Deribit(config="config.yaml",
                      max_depth=1,
                      subscription=all_subscription,
                      callbacks=callbacks)
    f.add_feed(deribit)
    f.run(start_loop=True,
          tasks=[
              do_periodically_at(
                  8, 1, 1,
                  functools.partial(subscribe_to_new_subscription, deribit))
          ])
Пример #10
0
def main():
    config = Config(
        config={'log': {
            'filename': 'ingester.log',
            'level': 'DEBUG'
        }})
    get_logger('ingester', config.log.filename, config.log.level)
    f = FeedHandler(config=config)
    callbacks = {
        TICKER: DeribitTickerPostgres(**postgres_cfg, cache_size=1000),
        TRADES: DeribitTradePostgres(**postgres_cfg),
        L2_BOOK: DeribitBookPostgres(**postgres_cfg, cache_size=1000)
    }
    deribit = Deribit(max_depth=2,
                      subscription=get_new_subscription(),
                      callbacks=callbacks)
    f.add_feed(deribit)
    f.run(start_loop=True,
          tasks=[
              do_periodically_at(
                  8, 1, 1,
                  functools.partial(subscribe_to_new_subscription, deribit))
          ])
Пример #11
0
'''
Copyright (C) 2017-2022 Bryant Moscon - [email protected]

Please see the LICENSE file for the terms and conditions
associated with this software.
'''
import asyncio
from cryptofeed.defines import ASK, BID
from datetime import datetime as dt, timedelta
from decimal import Decimal

from cryptofeed.exchanges import Deribit

d = Deribit()


def teardown_module(module):
    try:
        loop = asyncio.get_running_loop()
    except RuntimeError:
        loop = asyncio.new_event_loop()

    loop.run_until_complete(d.shutdown())


class TestDeribitRest:
    def test_trade(self):
        ret = []
        for data in d.trades_sync('BTC-USD-PERP'):
            ret.extend(data)
        assert len(ret) > 1