def main():
    try:
        # p = Process(target=receiver, args=(5678,))
        # p.start()

        f = FeedHandler()
        # print(binance_delivery_data_info)
        # print(binance_futures_data_info)
        binance_futures_symbols = defaultdict(list)
        for instrument in BinanceFutures.get_instrument_objects():
            binance_futures_symbols[instrument.instrument_type].append(
                instrument.instrument_name)
        print(binance_futures_symbols)

        binance_delivery_symbols = defaultdict(list)
        for instrument in BinanceDelivery.get_instrument_objects():
            binance_delivery_symbols[instrument.instrument_type].append(
                instrument.instrument_name)
        print(binance_delivery_symbols)

        # f.add_feed(BinanceDelivery(symbols=binance_delivery_symbols[PERPETUAL], channels=[FUNDING], callbacks={FUNDING: FundingZMQ(port=5678)}))
        f.add_feed(
            BinanceFutures(symbols=binance_futures_symbols[PERPETUAL],
                           channels=[FUNDING],
                           callbacks={FUNDING: FundingZMQ(port=5679)}))
        f.run()

    finally:
        p.terminate()
Esempio n. 2
0
def main():
    try:
        # p = Process(target=receiver, args=(5678,))
        # p.start()

        path_to_config = os.path.join(Path.home(), 'config.yaml')

        f = FeedHandler()
        binance_futures_symbols = defaultdict(list)
        for instrument in BinanceFutures.get_instrument_objects():
            binance_futures_symbols[instrument.instrument_type].append(instrument.instrument_name)
        print(binance_futures_symbols)

        binance_delivery_symbols = defaultdict(list)
        for instrument in BinanceDelivery.get_instrument_objects():
            binance_delivery_symbols[instrument.instrument_type].append(instrument.instrument_name)
        print(binance_delivery_symbols)

        # binance_symbols = set()
        # for instrument in BinanceDelivery.get_instrument_objects():
        #     binance_symbols.add(instrument.base + '-USDT')
        # print(binance_symbols)
        binance_symbols = []
        for instrument in Binance.info()['symbols']:
            if instrument.endswith('-USDT'):
                binance_symbols.append(instrument)
        print(binance_symbols)

        feeds = []
        feeds.append(BinanceDelivery(candle_interval='1d', symbols=binance_delivery_symbols[PERPETUAL], channels=[FUTURES_INDEX, FUNDING, TICKER, TRADES, VOLUME], callbacks={
            FUNDING: FundingZMQ(port=5678), 
            TICKER: TickerZMQ(port=5679), 
            TRADES: TradeZMQ(port=5682), 
            FUTURES_INDEX: FuturesIndexZMQ(port=5684),
            VOLUME: VolumeZMQ(port=5685)}))
        feeds.append(BinanceDelivery(candle_interval='1d', symbols=binance_delivery_symbols[FUTURE], channels=[FUTURES_INDEX, TICKER, TRADES, VOLUME], callbacks={
            TICKER: TickerZMQ(port=5687), 
            TRADES: TradeZMQ(port=5688), 
            FUTURES_INDEX: FuturesIndexZMQ(port=5689),
            VOLUME: VolumeZMQ(port=5690)}))
        feeds.append(BinanceDelivery(config=path_to_config, channels=[USER_BALANCE, USER_POSITION], symbols=[], callbacks={
            USER_BALANCE: UserBalanceZMQ(port=5691),
            USER_POSITION: UserPositionZMQ(port=5692)}))

        feeds.append(BinanceFutures(symbols=binance_futures_symbols[PERPETUAL], channels=[FUNDING], callbacks={FUNDING: FundingZMQ(port=5680)}))
        
        feeds.append(Binance(symbols=list(binance_symbols), channels=[TICKER, TRADES, VOLUME], callbacks={
            TICKER: TickerZMQ(port=5681), 
            TRADES: TradeZMQ(port=5683),
            VOLUME: VolumeZMQ(port=5686)}))
        feeds.append(Binance(config=path_to_config, channels=[USER_BALANCE], symbols=[], callbacks={
            USER_BALANCE: UserBalanceZMQ(port=5693)}))
        
        tasks = []
        for feed in feeds:
            if feed.requires_authentication:
                tasks.append(do_periodically_every(0, 30, 0, feed.auth.refresh_token))
            f.add_feed(feed)
        f.run(tasks=tasks)
    
    finally:
        p.terminate()