def test_isolated_margin(self):
     binance_websocket_api_manager = BinanceWebSocketApiManager(exchange="binance.com-isolated_margin", high_performance=True)
     stream_id = binance_websocket_api_manager.create_stream('arr', '!userData', symbols="CELRBTC", api_key="key", api_secret="secret")
     time.sleep(10)
     print("\r\n")
     binance_websocket_api_manager.print_stream_info(stream_id)
     binance_websocket_api_manager.stop_manager_with_all_streams()
    def test_live_run(self):
        binance_websocket_api_manager = BinanceWebSocketApiManager(enable_stream_signal_buffer=True, high_performance=True)
        binance_websocket_api_manager.get_active_stream_list()
        binance_websocket_api_manager.get_limit_of_subscriptions_per_stream()
        binance_websocket_api_manager.get_stream_list()

        markets = ['xrpbearbusd', 'zeceth', 'cndbtc', 'dashbtc', 'atompax', 'perlbtc', 'ardreth', 'zecbnb',
                   'bchabctusd',
                   'usdsbusdt', 'winbnb', 'xzcxrp', 'bchusdc', 'wavesbnb', 'kavausdt', 'btsusdt', 'chzbnb', 'tusdbnb',
                   'xtzbusd', 'bcptusdc', 'dogebnb', 'eosbearusdt', 'ambbnb', 'wrxbnb', 'poabtc', 'wanbtc', 'ardrbtc',
                   'icnbtc',
                   'tusdusdt', 'atombusd', 'nxseth', 'bnbusdt', 'trxxrp', 'erdpax', 'erdbtc', 'icxbusd', 'nulsbtc',
                   'hotusdt',
                   'wavespax', 'zilbnb', 'arnbtc', 'nulsusdt', 'wintrx', 'npxsbtc', 'busdtry', 'qtumbnb', 'eosbtc',
                   'xlmpax',
                   'tomobnb', 'eosbnb', 'engbtc', 'linketh', 'xrpbtc', 'fetbtc', 'stratusdt', 'navbnb', 'bcneth',
                   'yoyobtc',
                   'nanobnb', 'saltbtc', 'tfuelusdc', 'skybnb', 'fuelbtc', 'bnbusdc', 'inseth', 'btcpax', 'batbtc',
                   'rlceth',
                   'arketh', 'ltcpax', 'ltcbusd', 'duskbtc', 'mftusdt', 'bntusdt', 'mdabtc', 'enjbtc', 'poabnb',
                   'nanobusd',
                   'paxtusd', 'hotbtc', 'bcdbtc', 'beambnb', 'trxeth', 'omgbnb', 'cdtbtc', 'eosusdc', 'dashbusd',
                   'cocosbtc',
                   'dasheth', 'xrptusd', 'atomtusd', 'rcneth', 'rpxeth', 'xlmusdc', 'aionbusd', 'nxsbtc', 'chateth',
                   'repbtc',
                   'tctusdt', 'linkusdt', 'nasbtc', 'usdsusdc', 'xvgbtc', 'elfeth', 'ctxcbtc', 'cmteth', 'gnteth',
                   'usdspax',
                   'zilbtc', 'batpax', 'stratbtc', 'xzcbtc', 'iotausdt', 'etcbnb', 'ankrusdt', 'xlmeth', 'loombtc',
                   'erdusdc',
                   'rdnbnb', 'icneth', 'vetbtc', 'cvcusdt', 'ftmpax', 'ethbullusdt', 'edoeth', 'steemeth', 'gobnb',
                   'hsrbtc',
                   'ambbtc', 'bchabcbtc', 'dntbtc', 'btctusd', 'denteth', 'snglsbtc', 'eosbullusdt', 'xlmtusd',
                   'tnteth',
                   'sysbnb', 'renusdt', 'zrxusdt', 'xlmbtc', 'stormbtc', 'ncashbnb', 'omgusdt', 'troyusdt', 'venbtc',
                   'modbtc',
                   'dogepax', 'ontusdc', 'eurbusd', 'tctbnb', 'gxsbtc', 'celrbnb', 'adausdt', 'beambtc', 'elfbtc',
                   'celrbtc',
                   'rvnusdt', 'poaeth', 'wavesusdc', 'trxbnb', 'trxusdc', 'ethbearusdt', 'ethpax', 'bateth', 'kavabtc',
                   'paxbtc', 'trigbnb', 'btcusdc', 'oneusdc', 'xrptry', 'stxusdt', 'strateth', 'lendeth', 'neousdc',
                   'mithusdt', 'btcngn', 'blzeth', 'evxeth', 'dnteth', 'grsbtc', 'arneth', 'iotabnb', 'waneth',
                   'xtzbnb',
                   'subeth', 'btsbtc', 'cvceth', 'ethusdc', 'etctusd', 'cloakbtc', 'grseth', 'eospax', 'cdteth',
                   'bchusdt',
                   'lskusdt', 'enjbusd', 'drepbtc', 'manaeth', 'tomousdt', 'algobnb', 'wtceth', 'linkpax', 'batbnb',
                   'sceth',
                   'rvnbusd', 'cvcbnb', 'manabtc', 'gasbtc', 'stxbtc', 'cloaketh', 'neotusd', 'lrceth', 'thetabtc',
                   'dogeusdt',
                   'aionbnb', 'viabtc', 'keyeth', 'nanoeth', 'ncasheth', 'bgbpusdc', 'ltobnb', 'snmeth', 'adabtc',
                   'btseth',
                   'qtumbusd', 'wtcbnb', 'dcrbtc', 'fttbnb', 'paxbnb', 'insbtc', 'gntbnb', 'etheur', 'dashusdt',
                   'rcnbtc',
                   'btcusdt', 'wanusdt', 'powrbnb', 'xmrbnb', 'trigeth', 'xzceth', 'bchbtc', 'qspbnb', 'scbnb',
                   'mcoeth',
                   'powrbtc', 'algotusd', 'ankrbtc', 'tusdeth', 'keybtc', 'usdcusdt', 'ftmusdc', 'atombnb', 'zenbtc',
                   'dockbtc',
                   'neobtc', 'phbbnb', 'bnbpax', 'brdbnb', 'trxusdt', 'trxbusd', 'mtlbtc', 'ftmtusd', 'perlusdc',
                   'mithbnb',
                   'eosbullbusd', 'reqeth', 'bccbnb', 'veneth', 'loombnb', 'trxpax', 'usdcpax', 'stormusdt', 'ognbtc',
                   'gvtbtc',
                   'iotaeth', 'naseth', 'drepusdt', 'gvteth', 'wrxusdt', 'bchabcpax', 'ongbtc', 'usdcbnb', 'dgdeth',
                   'salteth',
                   'mtleth', 'bcnbnb', 'neblbnb', 'wanbnb', 'ontusdt', 'npxsusdt', 'mftbtc', 'eosbearbusd', 'bntbtc',
                   'gtoeth',
                   'modeth', 'etcusdc', 'veteth', 'bcptpax', 'atomusdc', 'duskpax', 'kavabnb', 'lunbtc', 'adxbtc',
                   'bnteth',
                   'funbtc', 'knceth', 'dogebtc', 'bchsvpax', 'bcpttusd', 'osteth', 'oaxeth', 'wabibtc', 'appcbtc',
                   'qkcbtc',
                   'nanousdt', 'wingsbtc', 'hbarusdt', 'eurusdt', 'waveseth', 'asteth', 'linkbusd', 'btttusd',
                   'zecusdc',
                   'bnbusds', 'linkbtc', 'venusdt', 'hotbnb', 'usdtrub', 'tctbtc', 'ankrpax', 'btctry', 'adabnb',
                   'polybtc',
                   'bcceth', 'enjeth', 'bnbbusd', 'repbnb', 'bullusdt', 'vitebtc', 'btgbtc', 'renbtc', 'thetausdt',
                   'troybtc',
                   'dentbtc', 'ostbtc', 'nxsbnb', 'mithbtc', 'xmrbtc', 'tomobtc', 'nulseth', 'phbbtc', 'duskbnb',
                   'yoyoeth',
                   'ontbusd', 'btgeth', 'etcusdt', 'atomusdt', 'hcbtc', 'brdbtc', 'fttbtc', 'celrusdt', 'lskbnb',
                   'phbpax',
                   'xtzbtc', 'batusdt', 'viteusdt', 'trxbtc', 'bchtusd', 'xtzusdt', 'ftmbtc', 'enjbnb', 'arkbtc',
                   'wavesusdt',
                   'ftmusdt', 'neobusd', 'stormbnb', 'luneth', 'gntbtc', 'gtousdt', 'chzusdt', 'sntbtc', 'bandbnb',
                   'hoteth',
                   'wingseth', 'mcobtc', 'docketh', 'drepbnb', 'eosusdt', 'eostusd', 'npxseth', 'thetaeth', 'iotxbtc',
                   'phxbnb',
                   'enjusdt', 'tfuelbnb', 'mcobnb', 'ontpax', 'dcrbnb', 'batusdc', 'snglseth', 'qlcbtc', 'qspeth',
                   'cndeth',
                   'appcbnb', 'wprbtc', 'sysbtc', 'iostusdt', 'btceur', 'mtlusdt', 'ethrub', 'tfuelpax', 'maticusdt',
                   'ftmbnb',
                   'xrpbusd', 'iotxusdt', 'tusdbtusd', 'trigbtc', 'atombtc', 'bchpax', 'eosbusd', 'zileth', 'gtotusd',
                   'xrpbullusdt', 'onetusd', 'algobtc', 'bchsvusdt', 'gtopax', 'etceth', 'vibebtc', 'bttusdt', 'repeth',
                   'iostbnb', 'usdttry', 'btsbnb', 'ankrbnb', 'dltbnb', 'snteth', 'linktusd', 'nknusdt', 'rpxbtc',
                   'rdneth',
                   'cocosusdt', 'etcbusd', 'btttrx', 'bandbtc', 'steembnb', 'zecpax', 'viabnb', 'cosbnb', 'mtheth',
                   'xrpusdc',
                   'xemeth', 'pivxbnb', 'phxbtc', 'zilusdt', 'poeeth', 'bnbeur', 'bandusdt', 'vetbnb', 'lendbtc',
                   'xlmbnb',
                   'duskusdt', 'mfteth', 'funusdt', 'adabusd', 'perlbnb', 'btcbusd', 'ltobtc', 'nasbnb', 'algousdt',
                   'zeneth',
                   'bchsvusdc', 'mcousdt', 'venbnb', 'hceth', 'fetusdt', 'edobtc', 'mftbnb', 'cosusdt', 'arpausdt',
                   'xmrusdt',
                   'ctxcusdt', 'bqxbtc', 'npxsusdc', 'icxbnb', 'bchbnb', 'phbusdc', 'tomousdc', 'nulsbnb', 'rcnbnb',
                   'arpabnb',
                   'qtumbtc', 'keyusdt', 'agibtc', 'mblbtc', 'eoseth', 'tusdbtc', 'aioneth', 'storjbtc', 'lsketh',
                   'bchsvbtc',
                   'bntbusd', 'ncashbtc', 'mblbnb', 'polybnb', 'aebnb', 'ltceth', 'dogeusdc', 'wpreth', 'syseth',
                   'bcnbtc',
                   'ognusdt', 'nanobtc', 'astbtc', 'zrxeth', 'adxeth', 'gxseth', 'ethbearbusd', 'onepax', 'scbtc',
                   'icxbtc',
                   'ontbnb', 'qlceth', 'btsbusd', 'rlcbtc', 'chatbtc', 'wabibnb', 'renbnb', 'xrpbullbusd', 'wavesbtc',
                   'funeth',
                   'rlcbnb', 'phxeth', 'winbtc', 'storjeth', 'wavesbusd', 'iostbtc', 'icxeth', 'adatusd', 'nknbnb',
                   'btcrub',
                   'pivxbtc', 'perlusdt', 'bullbusd', 'bttusdc', 'bcptbtc', 'aebtc', 'ethusdt', 'ltousdt', 'subbtc',
                   'thetabnb',
                   'blzbtc', 'tfuelusdt', 'evxbtc', 'hbarbtc', 'ambeth', 'winusdt', 'qtumeth', 'dgdbtc', 'adaeth',
                   'busdusdt',
                   'xrpbnb', 'adapax', 'usdsbusds', 'cocosbnb', 'navbtc', 'rvnbtc', 'tnbbtc', 'bnbbtc', 'neopax',
                   'bearusdt',
                   'usdstusd', 'snmbtc', 'rvnbnb', 'gtobnb', 'phbtusd', 'hcusdt', 'btcusds', 'reqbtc', 'ognbnb',
                   'lrcbtc',
                   'xrpeth', 'loometh', 'zectusd', 'vibeeth', 'gobtc', 'bnbtry', 'bcdeth', 'qkceth', 'neoeth',
                   'paxusdt',
                   'bchsvtusd', 'fetbnb', 'yoyobnb', 'xlmbusd', 'skyeth', 'paxeth', 'ltcbtc', 'xvgeth', 'tnbeth',
                   'stratbusd',
                   'agieth', 'xlmusdt', 'lskbtc', 'bearbusd', 'hsreth', 'ctxcbnb', 'oaxbtc', 'qspbtc', 'iotxeth',
                   'qlcbnb',
                   'algousdc', 'etcpax', 'fueleth', 'aionusdt', 'xmreth', 'maticbtc', 'dashbnb', 'oneusdt', 'brdeth',
                   'viaeth',
                   'omgeth', 'ankrtusd', 'usdsusdt', 'ethtusd', 'wavestusd', 'iosteth', 'cmtbnb', 'ostbnb', 'ltcusdt',
                   'ethtry',
                   'zrxbtc', 'bchabcusdt', 'onebnb', 'beamusdt', 'nebleth', 'bcptbnb', 'adxbnb', 'ontbtc', 'bttbnb',
                   'dockusdt',
                   'bccbtc', 'omgbtc', 'algopax', 'neousdt', 'xrprub', 'busdngn', 'appceth', 'dentusdt', 'xzcbnb',
                   'tfueltusd',
                   'xembnb', 'arpabtc', 'ankrusdc', 'adausdc', 'kmdeth', 'troybnb', 'bnbeth', 'ltcusdc', 'databtc',
                   'blzbnb',
                   'naveth', 'btcbbtc', 'battusd', 'bnbngn', 'bchbusd', 'busdrub', 'ltctusd', 'vetbusd', 'ongbnb',
                   'fttusdt',
                   'bccusdt', 'ongusdt', 'engeth', 'usdctusd', 'etcbtc', 'gtousdc', 'mdaeth', 'vitebnb', 'erdusdt',
                   'dltbtc',
                   'bnbtusd', 'wtcbtc', 'xrpusdt', 'xrpeur', 'agibnb', 'trxtusd', 'ethbullbusd', 'iotabtc', 'xembtc',
                   'bchabcusdc', 'duskusdc', 'xrppax', 'mblusdt', 'kmdbtc', 'neblbtc', 'maticbnb', 'bnbrub', 'bcpteth',
                   'bttbtc', 'stxbnb', 'dlteth', 'onteth', 'vetusdt', 'ppteth', 'ethbtc', 'onebtc', 'ethbusd', 'zecbtc',
                   'erdbnb', 'xrpbearusdt', 'stratbnb', 'cmtbtc', 'cvcbtc', 'kncbtc', 'rpxbnb', 'zenbnb', 'cndbnb',
                   'ardrbnb',
                   'bchabcbusd', 'ltcbnb', 'pivxeth', 'skybtc', 'tntbtc', 'poebtc', 'steembtc', 'icxusdt', 'tfuelbtc',
                   'chzbtc',
                   'vibeth', 'winusdc', 'gtobtc', 'linkusdc', 'batbusd', 'rdnbtc', 'dataeth', 'bttpax', 'zrxbnb',
                   'vibbtc',
                   'neobnb', 'cosbtc', 'powreth', 'rlcusdt', 'hbarbnb', 'wabieth', 'bqxeth', 'aionbtc', 'aeeth',
                   'mthbtc',
                   'wrxbtc', 'pptbtc', 'nknbtc', 'zecusdt', 'stormeth', 'qtumusdt']

        channels = ['kline_1m', 'kline_5m', 'kline_15m', 'kline_30m', 'kline_1h', 'kline_12h', 'kline_1w', 'trade',
                    'miniTicker', 'depth20']

        binance_websocket_api_manager.create_stream(False, False, stream_label="error")

        stream_id1 = ""
        for channel in channels:
            stream_id1 = binance_websocket_api_manager.create_stream(channel, markets, output="UnicornFy")

        time.sleep(5)
        binance_websocket_api_manager.set_restart_request(stream_id1)
        time.sleep(10)
        binance_websocket_api_manager.set_restart_request(stream_id1)

        restserver = BinanceWebSocketApiRestServer(binance_websocket_api_manager)
        restserver.get("icinga")
        restserver.get("invalid")
        del restserver

        markets = ['xrpbearbusd', 'zeceth', 'cndbtc', 'dashbtc', 'atompax', 'perlbtc', 'ardreth', 'zecbnb',
                   'erdbnb', 'xrpbearusdt', 'stratbnb', 'cmtbtc', 'cvcbtc', 'kncbtc', 'rpxbnb', 'zenbnb', 'cndbnb',
                   'wrxbtc', 'pptbtc', 'nknbtc', 'zecusdt', 'stormeth', 'qtumusdt']

        for channel in channels:
            stream_id2 = binance_websocket_api_manager.create_stream(channel, markets, stream_buffer_name=channel,
                                                                     ping_interval=10, ping_timeout=10, close_timeout=5)

        stream_id3 = binance_websocket_api_manager.create_stream(channel, markets, stream_buffer_name=True)
        time.sleep(10)
        binance_websocket_api_manager.stop_stream_as_crash(stream_id3)
        binance_websocket_api_manager.create_websocket_uri(False, False, stream_id1)
        binance_websocket_api_manager.unsubscribe_from_stream(stream_id2, markets="erdbnb")
        binance_websocket_api_manager.unsubscribe_from_stream(stream_id2, channels="trade")
        binance_websocket_api_manager.pop_stream_data_from_stream_buffer()
        binance_websocket_api_manager.pop_stream_data_from_stream_buffer()
        binance_websocket_api_manager.pop_stream_data_from_stream_buffer()
        binance_websocket_api_manager.pop_stream_data_from_stream_buffer(stream_buffer_name="invalid")
        stream_id_1_1 = binance_websocket_api_manager.replace_stream(stream_id1, 'trade', 'kncbtc', "name")
        binance_websocket_api_manager.replace_stream(stream_id_1_1, 'trade', 'kncbtc', "name",
                                                     new_ping_interval=10, new_ping_timeout=10, new_close_timeout=5)
        binance_websocket_api_manager.get_results_from_endpoints()
        binance_websocket_api_manager.get_binance_api_status()
        binance_websocket_api_manager.get_start_time()
        binance_websocket_api_manager.get_stream_label(stream_id1)
        binance_websocket_api_manager.get_stream_label(False)
        binance_websocket_api_manager.get_keep_max_received_last_second_entries()
        request_id = binance_websocket_api_manager.get_stream_subscriptions(stream_id2)
        binance_websocket_api_manager.get_result_by_request_id(request_id)
        binance_websocket_api_manager.get_reconnects()
        binance_websocket_api_manager.get_errors_from_endpoints()
        binance_websocket_api_manager.get_monitoring_status_plain()
        binance_websocket_api_manager.get_ringbuffer_error_max_size()
        binance_websocket_api_manager.get_ringbuffer_result_max_size()
        binance_websocket_api_manager.set_ringbuffer_error_max_size(200)
        binance_websocket_api_manager.set_ringbuffer_result_max_size(300)
        binance_websocket_api_manager.set_stream_label(stream_id2, "blub")
        binance_websocket_api_manager._add_stream_to_stream_list(binance_websocket_api_manager.get_new_uuid_id(),
                                                                 'trade', 'btceth')
        binance_websocket_api_manager._restart_stream((stream_id1))
        binance_websocket_api_manager.delete_stream_from_stream_list(stream_id1)
        binance_websocket_api_manager.delete_listen_key_by_stream_id(stream_id1)
        binance_websocket_api_manager.is_update_availabe_unicorn_fy()
        binance_websocket_api_manager.get_version_unicorn_fy()
        binance_websocket_api_manager.create_payload(stream_id2, "invalid", channels="trade")
        time.sleep(10)
        binance_websocket_api_manager.get_result_by_request_id(request_id)
        binance_websocket_api_manager.get_result_by_request_id()
        binance_websocket_api_manager.set_keep_max_received_last_second_entries(30)
        binance_websocket_api_manager.stop_stream_as_crash(stream_id2)
        binance_websocket_api_manager.stop_stream(stream_id2)
        binance_websocket_api_manager.add_to_ringbuffer_error("test")
        binance_websocket_api_manager.add_to_ringbuffer_result("test")
        binance_websocket_api_manager.get_number_of_free_subscription_slots(stream_id2)
        binance_websocket_api_manager.get_most_receives_per_second()
        binance_websocket_api_manager.get_number_of_streams_in_stream_list()
        binance_websocket_api_manager.is_update_availabe_check_command()
        binance_websocket_api_manager.wait_till_stream_has_stopped(stream_id2)
        binance_websocket_api_manager.print_stream_info(stream_id2)
        binance_websocket_api_manager.print_summary()
        binance_websocket_api_manager.print_summary_to_png(".", 12.5)
        binance_websocket_api_manager.get_latest_release_info()
        binance_websocket_api_manager.get_latest_release_info_check_command()
        binance_websocket_api_manager.set_private_dex_config("bnb1v566f3avl2ud5z0jepazsrguzkj367snlx4jm6")
        binance_websocket_api_manager.get_version()
        binance_websocket_api_manager.help()
        binance_websocket_api_manager.get_current_receiving_speed_global()
        binance_websocket_api_manager.wait_till_stream_has_started(stream_id2)
        binance_websocket_api_manager.remove_ansi_escape_codes("test text")
        binance_websocket_api_manager.pop_stream_signal_from_stream_signal_buffer()

        # test to many subscriptions
        import unicorn_binance_rest_api

        binance_api_key = ""
        binance_api_secret = ""
        binance_rest_client = unicorn_binance_rest_api.BinanceRestApiManager(binance_api_key, binance_api_secret)
        markets = []
        data = binance_rest_client.get_all_tickers()
        for item in data:
            markets.append(item['symbol'])
        binance_websocket_api_manager.create_stream("trade", markets, stream_label="too much!")
        time.sleep(10)
        binance_websocket_api_manager.stop_manager_with_all_streams()
        UBWA.stop_manager_with_all_streams()
        UBWA2.stop_manager_with_all_streams()
        UBWA3.stop_manager_with_all_streams()
        UBWA4.stop_manager_with_all_streams()
        print(f"threads:")
        for thread in threading.enumerate():
            print(thread.name)
        print(f"stopping ...")
            exit(0)
        oldest_stream_data_from_stream_buffer = binance_websocket_api_manager.pop_stream_data_from_stream_buffer(
        )
        if oldest_stream_data_from_stream_buffer is False:
            time.sleep(0.01)


logging.getLogger("unicorn_binance_websocket_api")
logging.basicConfig(
    level=logging.DEBUG,
    filename=os.path.basename(__file__) + '.log',
    format="{asctime} [{levelname:8}] {process} {thread} {module}: {message}",
    style="{")

# create instance of BinanceWebSocketApiManager for Binance Jersey
binance_websocket_api_manager = BinanceWebSocketApiManager(
    exchange="jex.com", high_performance=True)

# set api key and secret for userData stream
userdata_stream_id = binance_websocket_api_manager.create_stream(
    ["arr"], ["!userData"], api_key="aaa", api_secret="bb")

omt_stream_id = binance_websocket_api_manager.create_stream(
    ["arr"], ["!optionMiniTicker"])
smt_stream_id = binance_websocket_api_manager.create_stream(
    ["arr"], ["!spotMiniTicker"])
st_stream_id = binance_websocket_api_manager.create_stream(["arr"],
                                                           ["!spotTicker"])

spot_markets = {'eosbtc', 'ltcbtc', 'ethbtc', 'dashbtc'}
spot_channels = {
    'spotTrade', 'spotMiniTicker', 'spotDepth20', 'spotDepthUpdate',
    while True:
        if binance_websocket_api_manager.is_manager_stopping():
            exit(0)
        oldest_stream_data_from_stream_buffer = binance_websocket_api_manager.pop_stream_data_from_stream_buffer()
        if oldest_stream_data_from_stream_buffer is False:
            time.sleep(0.01)
        else:
            print(oldest_stream_data_from_stream_buffer)


# configure api key and secret for binance.com
api_key = ""
api_secret = ""

# create instances of BinanceWebSocketApiManager
ubwa_com = BinanceWebSocketApiManager(exchange="binance.com")

# create the userData streams
user_stream_id = ubwa_com.create_stream('arr', '!userData', api_key=api_key, api_secret=api_secret)

# start a worker process to move the received stream_data from the stream_buffer to a print function
worker_thread = threading.Thread(target=print_stream_data_from_stream_buffer, args=(ubwa_com,))
worker_thread.start()

# configure api key and secret for binance.com Isolated Margin
api_key = ""
api_secret = ""

# create instances of BinanceWebSocketApiManager
ubwa_com_im = BinanceWebSocketApiManager(exchange="binance.com-isolated_margin")
コード例 #5
0
def print_stream_data_from_stream_buffer(binance_websocket_api_manager):
    time.sleep(30)
    while True:
        if binance_websocket_api_manager.is_manager_stopping():
            exit(0)
        oldest_stream_data_from_stream_buffer = binance_websocket_api_manager.pop_stream_data_from_stream_buffer(
        )
        if oldest_stream_data_from_stream_buffer is False:
            time.sleep(0.01)


try:
    binance_rest_client = unicorn_binance_rest_api.BinanceRestApiManager(
        binance_api_key, binance_api_secret)
    binance_websocket_api_manager = BinanceWebSocketApiManager(
        high_performance=True,
        ping_interval_default=20,
        ping_timeout_default=20)
except requests.exceptions.ConnectionError:
    print("No internet connection?")
    sys.exit(1)

print("starting monitoring api!")
binance_websocket_api_manager.start_monitoring_api()

# start a worker process to move the received stream_data from the stream_buffer to a print function
worker_thread = threading.Thread(target=print_stream_data_from_stream_buffer,
                                 args=(binance_websocket_api_manager, ))
worker_thread.start()

markets = []
data = binance_rest_client.get_all_tickers()
        if binance_websocket_api_manager.is_manager_stopping():
            exit(0)
        oldest_stream_data_from_stream_buffer = binance_websocket_api_manager.pop_stream_data_from_stream_buffer(
        )
        if oldest_stream_data_from_stream_buffer is False:
            time.sleep(0.01)
        else:
            try:
                print(oldest_stream_data_from_stream_buffer)
            except Exception:
                # not able to process the data? write it back to the stream_buffer
                binance_websocket_api_manager.add_to_stream_buffer(
                    oldest_stream_data_from_stream_buffer)


if __name__ == '__main__':
    binance_websocket_api_manager = BinanceWebSocketApiManager(
        exchange="binance.com")
    worker_thread = threading.Thread(
        target=print_stream_data_from_stream_buffer,
        args=(binance_websocket_api_manager, ))
    worker_thread.start()
    kline_stream_id = binance_websocket_api_manager.create_stream(
        ['kline', 'kline_1m'], ['btcusdt'])
    try:
        while True:
            time.sleep(60)
    except KeyboardInterrupt:
        print("\nStopping ... just wait a few seconds!")
        binance_websocket_api_manager.stop_manager_with_all_streams()
コード例 #7
0
            'ticker', 'bookTicker', 'depth5', 'depth10', 'depth20', 'depth', 'depth@100ms'}
arr_channels = {'!miniTicker', '!ticker', '!bookTicker'}

logging.getLogger("unicorn_binance_websocket_api")
logging.basicConfig(level=logging.INFO,
                    filename=os.path.basename(__file__) + '.log',
                    format="{asctime} [{levelname:8}] {process} {thread} {module}: {message}",
                    style="{")


def print_stream_data(stream_data, stream_buffer_name=False):
    print(str(stream_data))

try:
    binance_rest_client = unicorn_binance_rest_api.BinanceRestApiManager(binance_api_key, binance_api_secret)
    binance_websocket_api_manager = BinanceWebSocketApiManager(high_performance=True)
except requests.exceptions.ConnectionError:
    print("No internet connection?")
    sys.exit(1)


markets = []
data = binance_rest_client.get_all_tickers()
for item in data:
    markets.append(item['symbol'])

private_stream_id = binance_websocket_api_manager.create_stream(["!userData"],
                                                                ["arr"],
                                                                api_key=binance_api_key,
                                                                api_secret=binance_api_secret,
                                                                stream_label="userData stream!",
コード例 #8
0
def print_stream_data_from_stream_buffer(binance_websocket_api_manager):
    while True:
        if binance_websocket_api_manager.is_manager_stopping():
            exit(0)
        oldest_stream_data_from_stream_buffer = binance_websocket_api_manager.pop_stream_data_from_stream_buffer(
        )
        if oldest_stream_data_from_stream_buffer is False:
            time.sleep(0.01)
        else:
            #print(oldest_stream_data_from_stream_buffer)
            pass


# create instance of BinanceWebSocketApiManager for Binance Chain DEX
binance_websocket_api_manager = BinanceWebSocketApiManager(
    exchange="binance.com")

# start a worker process to move the received stream_data from the stream_buffer to a print function
worker_thread = threading.Thread(target=print_stream_data_from_stream_buffer,
                                 args=(binance_websocket_api_manager, ))
worker_thread.start()

#markets = ['xrpusdt', 'rvnbtc']
markets = ['xrpusdt']
stream_id = binance_websocket_api_manager.create_stream(["kline_1m"], markets)

time.sleep(2)
binance_websocket_api_manager.get_stream_subscriptions(stream_id)
#binance_websocket_api_manager.subscribe_to_stream(stream_id,
#                                                  channels=['kline_1m', 'kline_5m', 'marketDepth',
#                                                            'ticker', 'miniTicker', 'marketDiff'])
コード例 #9
0
logging.basicConfig(level=logging.DEBUG,
                    filename=os.path.basename(__file__) + '.log',
                    format="{asctime} [{levelname:8}] {process} {thread} {module}: {message}",
                    style="{")


def print_stream_data_from_stream_buffer(binance_websocket_api_manager):
    while True:
        if binance_websocket_api_manager.is_manager_stopping():
            exit(0)
        oldest_stream_data_from_stream_buffer = binance_websocket_api_manager.pop_stream_data_from_stream_buffer()
        if oldest_stream_data_from_stream_buffer is False:
            time.sleep(0.01)

# create instance of BinanceWebSocketApiManager for Binance.com Futures
binance_websocket_api_manager = BinanceWebSocketApiManager(exchange="binance.com-futures")

# set api key and secret for userData stream
binance_api_key = ""
binance_api_secret = ""
userdata_stream_id = binance_websocket_api_manager.create_stream(["arr"],
                                                                 ["!userData"],
                                                                 api_key=binance_api_key,
                                                                 api_secret=binance_api_secret)

bookticker_all_stream_id = binance_websocket_api_manager.create_stream(["arr"], ["!bookTicker"])

# https://binance-docs.github.io/apidocs/futures/en/#mark-price-stream-for-all-market
binance_websocket_api_manager.create_stream(["!markPrice"], "arr@1s", stream_label="!markPrice@arr@1s")

markets = {'btcusdt', 'bchusdt', 'ethusdt'}
コード例 #10
0
logging.basicConfig(level=logging.DEBUG,
                    filename=os.path.basename(__file__) + '.log',
                    format="{asctime} [{levelname:8}] {process} {thread} {module}: {message}",
                    style="{")


def print_stream_data_from_stream_buffer(binance_websocket_api_manager):
    while True:
        if binance_websocket_api_manager.is_manager_stopping():
            exit(0)
        oldest_stream_data_from_stream_buffer = binance_websocket_api_manager.pop_stream_data_from_stream_buffer()
        if oldest_stream_data_from_stream_buffer is False:
            time.sleep(0.01)
        else:
            print(oldest_stream_data_from_stream_buffer)


# create instance of BinanceWebSocketApiManager and provide the function for stream processing
binance_websocket_api_manager = BinanceWebSocketApiManager(exchange="binance.com-futures")

# start one worker process (or more) to move the received stream_data from the stream_buffer to a print function
worker_thread = threading.Thread(target=print_stream_data_from_stream_buffer, args=(binance_websocket_api_manager,))
worker_thread.start()

# create streams
bookTicker_arr_stream_id = binance_websocket_api_manager.create_stream("arr", "!bookTicker")

while True:
    binance_websocket_api_manager.print_stream_info(bookTicker_arr_stream_id)
    time.sleep(1)
コード例 #11
0

def print_stream_data_from_stream_buffer(binance_websocket_api_manager):
    while True:
        if binance_websocket_api_manager.is_manager_stopping():
            exit(0)
        oldest_stream_data_from_stream_buffer = binance_websocket_api_manager.pop_stream_data_from_stream_buffer()
        if oldest_stream_data_from_stream_buffer is False:
            time.sleep(0.01)
        else:
            pass
            #print(oldest_stream_data_from_stream_buffer)


# create instance of BinanceWebSocketApiManager for Binance Chain DEX
binance_websocket_api_manager = BinanceWebSocketApiManager(exchange="binance.org-testnet")

# start a worker process to move the received stream_data from the stream_buffer to a print function
worker_thread = threading.Thread(target=print_stream_data_from_stream_buffer, args=(binance_websocket_api_manager,))
worker_thread.start()

# userAddress streams
binance_dex_user_address = "bnb1v566f3avl2ud5z0jepazsrguzkj367snlx4jm6"
id = binance_websocket_api_manager.create_stream('orders', binance_dex_user_address)
binance_websocket_api_manager.create_stream('accounts', binance_dex_user_address)
binance_websocket_api_manager.create_stream('transfers', binance_dex_user_address)
user_address_multi_stream_id = binance_websocket_api_manager.create_stream(['orders', 'transfers', 'accounts'],
                                                                           binance_dex_user_address)

binance_websocket_api_manager.create_stream(["allTickers"], ["$all"])
binance_websocket_api_manager.create_stream(["allMiniTickers"], ["$all"])
コード例 #12
0
channels = {
    'aggTrade', 'trade', 'kline_1m', 'kline_5m', 'kline_15m', 'kline_30m',
    'kline_1h', 'kline_2h', 'kline_4h', 'kline_6h', 'kline_8h', 'kline_12h',
    'kline_1d', 'kline_3d', 'kline_1w', 'kline_1M', 'miniTicker', 'ticker',
    'bookTicker', 'depth5', 'depth10', 'depth20', 'depth', 'depth@100ms'
}
arr_channels = {'!miniTicker', '!ticker', '!bookTicker'}
markets = []

try:
    binance_api_key = ""
    binance_api_secret = ""
    binance_rest_client = unicorn_binance_rest_api.BinanceRestApiManager(
        binance_api_key, binance_api_secret)
    binance_websocket_api_manager = BinanceWebSocketApiManager(
        high_performance=True)
except requests.exceptions.ConnectionError:
    print("No internet connection?")
    sys.exit(1)

# start a worker process to move the received stream_data from the stream_buffer to a print function
worker_thread = threading.Thread(target=print_stream_data_from_stream_buffer,
                                 args=(binance_websocket_api_manager, ))
worker_thread.start()

print_summary_thread = threading.Thread(target=print_stream,
                                        args=(binance_websocket_api_manager, ))
print_summary_thread.start()

data = binance_rest_client.get_all_tickers()
コード例 #13
0
from unicorn_binance_websocket_api.manager import BinanceWebSocketApiManager
import logging
import os

# import class to process stream data
from example_process_streams import BinanceWebSocketApiProcessStreams

logging.getLogger("unicorn_binance_websocket_api")
logging.basicConfig(
    level=logging.DEBUG,
    filename=os.path.basename(__file__) + '.log',
    format="{asctime} [{levelname:8}] {process} {thread} {module}: {message}",
    style="{")

# create instance of BinanceWebSocketApiManager and provide the function for stream processing
binance_websocket_api_manager = BinanceWebSocketApiManager(
    BinanceWebSocketApiProcessStreams.process_stream_data)

# define channels
channels = {'trade'}

# define markets
markets = {
    'bnbbtc', 'ethbtc', 'btcusdt', 'bchabcusdt', 'xrpusdt', 'rvnbtc',
    'ltcusdt', 'adausdt', 'eosusdt', 'neousdt', 'bnbusdt', 'adabtc', 'ethusdt',
    'trxbtc', 'bchabcbtc', 'ltcbtc', 'xrpbtc', 'ontbtc', 'bttusdt', 'eosbtc',
    'xlmbtc', 'bttbtc', 'tusdusdt', 'xlmusdt', 'qkcbtc', 'zrxbtc', 'neobtc',
    'adaeth', 'icxusdt', 'btctusd', 'icxbtc', 'btcusdc', 'wanbtc', 'zecbtc',
    'wtcbtc', 'batbtc', 'adabnb', 'etcusdt', 'qtumusdt', 'xmrbtc', 'trxeth',
    'adatusd', 'trxxrp', 'trxbnb', 'dashbtc', 'rvnbnb', 'bchabctusd', 'etcbtc',
    'bnbeth', 'ethpax', 'nanobtc', 'xembtc', 'xrpbnb', 'bchabcpax', 'xrpeth',
    'bttbnb', 'ltcbnb', 'agibtc', 'zrxusdt', 'xlmbnb', 'ltceth', 'eoseth',
コード例 #14
0
    import pandas_ta as ta
except ImportError:
    print("Please install `pandas_ta`!")
    exit(1)

data_list = []
min_items = 11

logging.getLogger("unicorn_binance_websocket_api")
logging.basicConfig(
    level=logging.DEBUG,
    filename=os.path.basename(__file__) + '.log',
    format="{asctime} [{levelname:8}] {process} {thread} {module}: {message}",
    style="{")

ubwa = BinanceWebSocketApiManager(exchange="binance.com",
                                  output_default="UnicornFy")
ubwa.create_stream('kline_1m', 'btcusdt')

print(
    f"For our calculations we need the klines_1m of the last 10 minutes. Normally we would download the history\r\n"
    f"via REST API. In this demo, we wait 10 minutes for the websocket connection to receive 10 klines and then\r\n"
    f"output the entire dataframe to the console every minute from then on.")
print(f"Learn about pandas-ta: https://twopirllc.github.io/pandas-ta")

while True:
    ohlcv = False
    data = ubwa.pop_stream_data_from_stream_buffer()
    if data is False:
        time.sleep(0.1)
    else:
        try:
コード例 #15
0
import os
import time
import threading
import logging

# import class to process stream data
from example_process_streams import BinanceWebSocketApiProcessStreams

logging.getLogger("unicorn_binance_websocket_api")
logging.basicConfig(level=logging.DEBUG,
                    filename=os.path.basename(__file__) + '.log',
                    format="{asctime} [{levelname:8}] {process} {thread} {module}: {message}",
                    style="{")

# create instance of BinanceWebSocketApiManager and provide the function for stream processing
binance_websocket_api_manager = BinanceWebSocketApiManager(BinanceWebSocketApiProcessStreams.process_stream_data)
# binance_websocket_api_manager = BinanceWebSocketApiManager(exchange="binance.com")


def print_stream_data_from_stream_buffer(binance_websocket_api_manager):
    while True:
        if binance_websocket_api_manager.is_manager_stopping():
            exit(0)
        oldest_stream_data_from_stream_buffer = binance_websocket_api_manager.pop_stream_data_from_stream_buffer()
        if oldest_stream_data_from_stream_buffer is False:
            time.sleep(0.01)
        else:
            #pass
            print(oldest_stream_data_from_stream_buffer)

# WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
# IN THE SOFTWARE.

from unicorn_binance_websocket_api.manager import BinanceWebSocketApiManager
import logging
import os

logging.getLogger("unicorn_binance_websocket_api")
logging.basicConfig(
    level=logging.DEBUG,
    filename=os.path.basename(__file__) + '.log',
    format="{asctime} [{levelname:8}] {process} {thread} {module}: {message}",
    style="{")

binance_websocket_api_manager = BinanceWebSocketApiManager(
    exchange="binance.com")

markets = [
    'bnbbtc', 'ethbtc', 'btcusdt', 'bchabcusdt', 'xrpusdt', 'rvnbtc',
    'ltcusdt', 'adausdt', 'eosusdt', 'neousdt', 'bnbusdt', 'adabtc', 'ethusdt',
    'trxbtc', 'trxbtc', 'bchabcbtc', 'ltcbtc', 'xrpbtc', 'ontbtc', 'bttusdt',
    'eosbtc', 'xlmbtc', 'bttbtc', 'tusdusdt', 'xlmusdt', 'qkcbtc', 'zrxbtc',
    'neobtc', 'adaeth', 'icxusdt', 'btctusd', 'icxbtc', 'btcusdc', 'wanbtc',
    'zecbtc', 'wtcbtc'
]

channels = [
    'trade', 'kline_1m', 'kline_5m', 'kline_15m', 'kline_30m', 'kline_1h',
    'kline_12h', 'depth5'
]
コード例 #17
0
def print_stream_data_from_stream_buffer(ubwa):
    while True:
        if ubwa.is_manager_stopping():
            exit(0)
        oldest_stream_data_from_stream_buffer = ubwa.pop_stream_data_from_stream_buffer()
        if oldest_stream_data_from_stream_buffer is False:
            time.sleep(0.01)


logging.getLogger("unicorn_binance_websocket_api")
logging.basicConfig(level=logging.DEBUG,
                    filename=os.path.basename(__file__) + '.log',
                    format="{asctime} [{levelname:8}] {process} {thread} {module}: {message}",
                    style="{")

# create instance of BinanceWebSocketApiManager for Binance Jersey
ubwa = BinanceWebSocketApiManager(exchange="trbinance.com")

stream_id = ubwa.create_stream("trade", ['btctry', 'ethtry', 'bnbtry', 'xrptry', 'usdttry'])

# start a worker process to move the received stream_data from the stream_buffer to a print function
worker_thread = threading.Thread(target=print_stream_data_from_stream_buffer, args=(ubwa,))
worker_thread.start()

# show an overview
while True:
    ubwa.print_summary()
    #ubwa.print_stream_info(userdata_stream_id)
    time.sleep(1)

from __future__ import print_function
from unicorn_binance_websocket_api.manager import BinanceWebSocketApiManager
import logging
import time
import threading
import os

logging.getLogger("unicorn_binance_websocket_api")
logging.basicConfig(
    level=logging.INFO,
    filename=os.path.basename(__file__) + '.log',
    format="{asctime} [{levelname:8}] {process} {thread} {module}: {message}",
    style="{")

# create instance of BinanceWebSocketApiManager
binance_websocket_api_manager = BinanceWebSocketApiManager()

markets = [
    'xrpbearbusd', 'zeceth', 'cndbtc', 'dashbtc', 'atompax', 'perlbtc',
    'ardreth', 'zecbnb', 'bchabctusd', 'usdsbusdt', 'winbnb', 'xzcxrp',
    'bchusdc', 'wavesbnb', 'kavausdt', 'btsusdt', 'chzbnb', 'tusdbnb',
    'xtzbusd', 'bcptusdc', 'dogebnb', 'eosbearusdt', 'ambbnb', 'wrxbnb',
    'poabtc', 'wanbtc', 'ardrbtc', 'icnbtc', 'tusdusdt', 'atombusd', 'nxseth',
    'bnbusdt', 'trxxrp', 'erdpax', 'erdbtc', 'icxbusd', 'nulsbtc', 'hotusdt',
    'wavespax', 'zilbnb', 'arnbtc', 'nulsusdt', 'wintrx', 'npxsbtc', 'busdtry',
    'qtumbnb', 'eosbtc', 'xlmpax', 'tomobnb', 'eosbnb', 'engbtc', 'linketh',
    'xrpbtc', 'fetbtc', 'stratusdt', 'navbnb', 'bcneth', 'yoyobtc', 'nanobnb',
    'saltbtc', 'tfuelusdc', 'skybnb', 'fuelbtc', 'bnbusdc', 'inseth', 'btcpax',
    'batbtc', 'rlceth', 'arketh', 'ltcpax', 'ltcbusd', 'duskbtc', 'mftusdt',
    'bntusdt', 'mdabtc', 'enjbtc', 'poabnb', 'nanobusd', 'paxtusd', 'hotbtc',
    'bcdbtc', 'beambnb', 'trxeth', 'omgbnb', 'cdtbtc', 'eosusdc', 'dashbusd',
コード例 #19
0
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
# IN THE SOFTWARE.

from unicorn_binance_websocket_api.manager import BinanceWebSocketApiManager
import logging
import time
import os

logging.getLogger("unicorn_binance_websocket_api")
logging.basicConfig(level=logging.INFO,
                    filename=os.path.basename(__file__) + '.log',
                    format="{asctime} [{levelname:8}] {process} {thread} {module}: {message}",
                    style="{")

# create instance of BinanceWebSocketApiManager and provide the function for stream processing
binance_websocket_api_manager = BinanceWebSocketApiManager()

# define some markets
markets = {'bnbbtc', 'ethbtc', 'btcusdt', 'bchabcusdt', 'xrpusdt', 'rvnbtc', 'ltcusdt', 'adausdt', 'eosusdt',
           'neousdt', 'bnbusdt', 'adabtc', 'ethusdt', 'trxbtc', 'bchabcbtc', 'ltcbtc', 'xrpbtc',
           'ontbtc', 'bttusdt', 'eosbtc', 'xlmbtc', 'bttbtc', 'tusdusdt', 'xlmusdt', 'qkcbtc', 'zrxbtc',
           'neobtc', 'adaeth', 'icxusdt', 'btctusd', 'icxbtc', 'btcusdc', 'wanbtc', 'zecbtc', 'wtcbtc',
           'ethtusd', 'batusdt', 'mcobtc', 'neoeth', 'bntbtc', 'eostusd', 'lrcbtc', 'funbtc', 'zecusdt',
           'bnbpax', 'linkusdt', 'hceth', 'zrxeth', 'icxeth', 'xmreth', 'neobnb', 'etceth', 'zeceth', 'xmrbnb',
           'wanbnb', 'zrxbnb', 'agibnb', 'funeth', 'arketh', 'engeth'}

# create stream 1
binance_get_ticker_stream_id = binance_websocket_api_manager.create_stream("arr", "!ticker")

# create stream 2
binance_get_kline_stream_id = binance_websocket_api_manager.create_stream(['kline_1m', 'kline_5m', 'kline_30m', 'kline_1h', 'kline_15m'], markets)
コード例 #20
0
binance_com_api_key = ""
binance_com_api_secret = ""
binance_com_api_key = ""
binance_com_api_secret = ""


# configure api key and secret for binance.us
binance_us_api_key = ""
binance_us_api_secret = ""

# configure api key and secret for binance.us
binance_com_iso_api_key = binance_com_api_key
binance_com_iso_api_secret = binance_com_api_secret

# create instances of BinanceWebSocketApiManager
binance_com_websocket_api_manager = BinanceWebSocketApiManager(exchange="binance.com",
                                                               throw_exception_if_unrepairable=True)
binance_us_websocket_api_manager = BinanceWebSocketApiManager(exchange="binance.us")
binance_com_isolated_websocket_api_manager = BinanceWebSocketApiManager(exchange="binance.com-isolated_margin")

# create the userData streams
binance_com_user_data_stream_id = binance_com_websocket_api_manager.create_stream('arr', '!userData',
                                                                                  api_key=binance_com_api_key,
                                                                                  api_secret=binance_com_api_secret)
binance_us_user_data_stream_id = binance_us_websocket_api_manager.create_stream('arr', '!userData',
                                                                                api_key=binance_us_api_key,
                                                                                api_secret=binance_us_api_secret)
binance_com_iso_user_data_stream_id = binance_com_isolated_websocket_api_manager.create_stream('arr', '!userData',
                                                                                               symbols="LUNAUSDT",
                                                                                               api_key=binance_com_iso_api_key,
                                                                                               api_secret=binance_com_iso_api_secret)
コード例 #21
0
import logging
import os
import time

# import class to process stream data
from example_process_streams import BinanceWebSocketApiProcessStreams

logging.getLogger("unicorn_binance_websocket_api")
logging.basicConfig(
    level=logging.DEBUG,
    filename=os.path.basename(__file__) + '.log',
    format="{asctime} [{levelname:8}] {process} {thread} {module}: {message}",
    style="{")

# create instance of BinanceWebSocketApiManager and provide the function for stream processing
binance_websocket_api_manager = BinanceWebSocketApiManager(
    BinanceWebSocketApiProcessStreams.process_stream_data)

# define markets
markets = {
    'bnbbtc', 'ethbtc', 'btcusdt', 'bchabcusdt', 'xrpusdt', 'rvnbtc',
    'ltcusdt', 'adausdt', 'eosusdt', 'neousdt', 'bnbusdt', 'adabtc', 'ethusdt',
    'trxbtc', 'bchabcbtc', 'ltcbtc', 'xrpbtc', 'ontbtc', 'bttusdt', 'eosbtc',
    'xlmbtc', 'bttbtc', 'tusdusdt', 'xlmusdt', 'qkcbtc', 'zrxbtc', 'neobtc',
    'adaeth', 'icxusdt', 'btctusd', 'icxbtc', 'btcusdc', 'wanbtc', 'zecbtc',
    'wtcbtc', 'dashbtc', 'rvnbnb', 'bchabctusd', 'etcbtc', 'bnbeth', 'ethpax',
    'nanobtc', 'xembtc', 'xrpbnb', 'bchabcpax', 'xrpeth', 'bttbnb', 'ltcbnb',
    'agibtc', 'zrxusdt', 'xlmbnb', 'ltceth', 'eoseth'
}

# define stream channels
channels = {
コード例 #22
0
# IN THE SOFTWARE.

from unicorn_binance_websocket_api.manager import BinanceWebSocketApiManager
import logging
import os
import time
import threading

logging.getLogger("unicorn_binance_websocket_api")
logging.basicConfig(
    level=logging.DEBUG,
    filename=os.path.basename(__file__) + '.log',
    format="{asctime} [{levelname:8}] {process} {thread} {module}: {message}",
    style="{")

binance_websocket_api_manager = BinanceWebSocketApiManager()


def print_stream_data_from_stream_buffer(binance_websocket_api_manager):
    while True:
        if binance_websocket_api_manager.is_manager_stopping():
            exit(0)
        oldest_stream_data_from_stream_buffer = binance_websocket_api_manager.pop_stream_data_from_stream_buffer(
        )
        if oldest_stream_data_from_stream_buffer is False:
            time.sleep(0.01)
        else:
            try:
                # remove # to activate the print function:
                print(oldest_stream_data_from_stream_buffer)
            except Exception:
import logging
import os
import time

# import class to process stream data
from example_process_streams import BinanceWebSocketApiProcessStreams

logging.getLogger("unicorn_binance_websocket_api")
logging.basicConfig(
    level=logging.DEBUG,
    filename=os.path.basename(__file__) + '.log',
    format="{asctime} [{levelname:8}] {process} {thread} {module}: {message}",
    style="{")

# create instance of BinanceWebSocketApiManager and provide the function for stream processing
binance_websocket_api_manager = BinanceWebSocketApiManager(
    BinanceWebSocketApiProcessStreams.process_stream_data)

# define markets
markets = {'bnbbtc', 'ethbtc', 'btcusdt', 'bchabcusdt', 'eosusdt'}

markets_mega_list = {
    'xrpusdt', 'rvnbtc', 'ltcusdt', 'adausdt', 'eosusdt', 'xmrusdt', 'xmrbnb',
    'neousdt', 'bnbusdt', 'adabtc', 'ethusdt', 'trxbtc', 'bchabcbtc', 'ltcbtc',
    'xrpbtc', 'ontbtc', 'bttusdt', 'eosbtc', 'xlmbtc', 'bttbtc', 'tusdusdt',
    'xlmusdt', 'qkcbtc', 'zrxbtc', 'neobtc', 'adaeth', 'icxusdt', 'btctusd',
    'icxbtc', 'btcusdc', 'wanbtc', 'zecbtc', 'wtcbtc', 'batbtc', 'adabnb',
    'etcusdt', 'qtumusdt', 'xmrbtc', 'trxeth', 'adatusd', 'trxxrp', 'trxbnb',
    'dashbtc', 'rvnbnb', 'bchabctusd', 'etcbtc', 'bnbeth', 'ethpax', 'nanobtc',
    'xembtc', 'xrpbnb', 'bchabcpax', 'xrpeth', 'bttbnb', 'ltcbnb', 'agibtc',
    'zrxusdt', 'xlmbnb', 'ltceth', 'eoseth', 'ltctusd', 'polybnb', 'scbtc',
    'steembtc', 'trxtusd', 'npxseth', 'kmdbtc', 'polybtc', 'gasbtc', 'engbtc',
import os
import time

logging.getLogger("unicorn_binance_websocket_api")
logging.basicConfig(level=logging.DEBUG,
                    filename=os.path.basename(__file__) + '.log',
                    format="{asctime} [{levelname:8}] {process} {thread} {module}: {message}",
                    style="{")


def callback_data(stream_data):
    print(f"DATA: {stream_data}")


def callback_signals(signal_type=False, stream_id=False, data_record=False):
    print(f"SIGNAL: {signal_type} - {stream_id} - {data_record}")


ubwa = BinanceWebSocketApiManager(exchange="binance.com", process_stream_signals=callback_signals)
stream_id = ubwa.create_stream('depth20@1000ms', 'BNBBUSD', output='dict', process_stream_data=callback_data)
time.sleep(5)

ubwa.stop_stream(stream_id)

time.sleep(5)

print(f"waiting till stream has stopped")
if ubwa.wait_till_stream_has_stopped(stream_id):
    deleted = ubwa.delete_stream_from_stream_list(stream_id)
    print(f"deleted stream_id {stream_id} from stream_list")
コード例 #25
0
            sys.exit(0)
        oldest_stream_data_from_stream_buffer = binance_websocket_api_manager.pop_stream_data_from_stream_buffer()
        if oldest_stream_data_from_stream_buffer is False:
            time.sleep(0.01)
        else:
            try:
                # remove # to activate the print function:
                print(oldest_stream_data_from_stream_buffer)
            except KeyError:
                # Any kind of error...
                # not able to process the data? write it back to the stream_buffer
                binance_websocket_api_manager.add_to_stream_buffer(oldest_stream_data_from_stream_buffer)


# create instance of BinanceWebSocketApiManager and provide the function for stream processing
binance_websocket_api_manager = BinanceWebSocketApiManager()

# create streams
ticker_all_stream_id = binance_websocket_api_manager.create_stream(["arr"], ["!ticker"])
miniticker_stream_id = binance_websocket_api_manager.create_stream(["arr"], ["!miniTicker"])

markets = {'bnbbtc', 'ethbtc', 'btcusdt', 'bchabcusdt', 'xrpusdt', 'rvnbtc', 'ltcusdt', 'adausdt', 'eosusdt',
           'neousdt', 'bnbusdt', 'adabtc', 'ethusdt', 'trxbtc', 'bchabcbtc', 'ltcbtc', 'xrpbtc',
           'ontbtc', 'bttusdt', 'eosbtc', 'xlmbtc', 'bttbtc', 'tusdusdt', 'xlmusdt', 'qkcbtc', 'zrxbtc',
           'neobtc', 'adaeth', 'icxusdt', 'btctusd', 'icxbtc', 'btcusdc', 'wanbtc', 'zecbtc', 'wtcbtc',
           'batbtc', 'adabnb', 'etcusdt', 'qtumusdt', 'xmrbtc', 'trxeth', 'adatusd', 'trxxrp', 'trxbnb',
           'dashbtc', 'rvnbnb', 'bchabctusd', 'etcbtc', 'bnbeth', 'ethpax', 'nanobtc', 'xembtc', 'xrpbnb',
           'bchabcpax', 'xrpeth', 'bttbnb', 'ltcbnb', 'agibtc', 'zrxusdt', 'xlmbnb', 'ltceth', 'eoseth',
           'ltctusd', 'polybnb', 'scbtc', 'steembtc', 'trxtusd', 'npxseth', 'kmdbtc', 'polybtc', 'gasbtc',
           'engbtc', 'zileth', 'xlmeth', 'eosbnb', 'xrppax', 'lskbtc', 'npxsbtc', 'xmrusdt', 'ltcpax',
           'ethtusd', 'batusdt', 'mcobtc', 'neoeth', 'bntbtc', 'eostusd', 'lrcbtc', 'funbtc', 'zecusdt',
コード例 #26
0

def print_stream_buffer_data(binance_websocket_api_manager, stream_id):
    while True:
        if binance_websocket_api_manager.is_manager_stopping():
            exit(0)
        oldest_stream_data_from_stream_buffer = binance_websocket_api_manager.pop_stream_data_from_stream_buffer(
            stream_id)
        if oldest_stream_data_from_stream_buffer is False:
            time.sleep(0.01)
        else:
            print(oldest_stream_data_from_stream_buffer)


# create instances of BinanceWebSocketApiManager
binance_com_websocket_api_manager = BinanceWebSocketApiManager(
    exchange="binance.com")

# configure api key and secret for binance.com for Alice
alice_api_key = "aaaa"
alice_api_secret = "bbbb"
# create the userData streams
alice_stream_id = binance_com_websocket_api_manager.create_stream(
    'arr',
    '!userData',
    stream_label="Alice",
    stream_buffer_name=True,
    api_key=alice_api_key,
    api_secret=alice_api_secret)
# start a worker process to move the received stream_data from the stream_buffer to a print function
worker_thread = threading.Thread(target=print_stream_buffer_data,
                                 args=(binance_com_websocket_api_manager,
コード例 #27
0
            exit(0)
        oldest_stream_data_from_stream_buffer = binance_websocket_api_manager.pop_stream_data_from_stream_buffer(
        )
        if oldest_stream_data_from_stream_buffer is False:
            time.sleep(0.01)
        else:
            try:
                print(oldest_stream_data_from_stream_buffer)
            except Exception:
                # not able to process the data? write it back to the stream_buffer
                binance_websocket_api_manager.add_to_stream_buffer(
                    oldest_stream_data_from_stream_buffer)


# create instance of BinanceWebSocketApiManager and provide the function for stream processing
binance_websocket_api_manager = BinanceWebSocketApiManager()

# start a worker process to process to move the received stream_data from the stream_buffer to a print function
worker_thread = threading.Thread(target=print_stream_data_from_stream_buffer,
                                 args=(binance_websocket_api_manager, ))
worker_thread.start()

print("testing ws/ single streams")

print(
    "\r\n========================================== Starting ticker all ========================================\r\n"
)
ticker_all_stream_id = binance_websocket_api_manager.create_stream(["arr"],
                                                                   ["!ticker"])
time.sleep(6)
binance_websocket_api_manager.stop_stream(ticker_all_stream_id)
    while True:
        if binance_websocket_api_manager.is_manager_stopping():
            exit(0)
        oldest_stream_data_from_stream_buffer = binance_websocket_api_manager.pop_stream_data_from_stream_buffer()
        if oldest_stream_data_from_stream_buffer is False:
            time.sleep(0.01)


logging.getLogger("unicorn_binance_websocket_api")
logging.basicConfig(level=logging.INFO,
                    filename=os.path.basename(__file__) + '.log',
                    format="{asctime} [{levelname:8}] {process} {thread} {module}: {message}",
                    style="{")

# create instance of BinanceWebSocketApiManager for Binance Jersey
binance_websocket_api_manager = BinanceWebSocketApiManager(exchange="binance.us")

userdata_stream_id = binance_websocket_api_manager.create_stream(["arr"], ["!userData"], api_key="aaa", api_secret="bb")

ticker_all_stream_id = binance_websocket_api_manager.create_stream(["arr"], ["!ticker"])
miniticker_stream_id = binance_websocket_api_manager.create_stream(["arr"], ["!miniTicker"])

markets = {'btcusd', 'btcxrp', 'ethusd', 'bnbusd', 'busdusd'}

binance_websocket_api_manager.create_stream(["aggTrade"], markets)
binance_websocket_api_manager.create_stream(["trade"], markets)
binance_websocket_api_manager.create_stream(["kline_1m"], markets)
binance_websocket_api_manager.create_stream(["kline_5m"], markets)
binance_websocket_api_manager.create_stream(["kline_15m"], markets)
binance_websocket_api_manager.create_stream(["kline_1h"], markets)
binance_websocket_api_manager.create_stream(["kline_12h"], markets)
from unicorn_binance_websocket_api.manager import BinanceWebSocketApiManager
import time

api_key = ""
api_secret = ""


def book_ticker(msg):
    print("book_ticker: " + str(msg))


def order_status(msg):
    print("order_status: " + str(msg))


bwsm = BinanceWebSocketApiManager()

book_ticker_id = bwsm.create_stream("bookTicker",
                                    'bnbbusd',
                                    stream_buffer_name=True)
user_stream_id = bwsm.create_stream('arr',
                                    '!userData',
                                    api_key=api_key,
                                    api_secret=api_secret,
                                    stream_buffer_name=True)

while True:
    msg = bwsm.pop_stream_data_from_stream_buffer(book_ticker_id)
    if msg:
        book_ticker(msg)
    msg = bwsm.pop_stream_data_from_stream_buffer(user_stream_id)
コード例 #30
0
    format="{asctime} [{levelname:8}] {process} {thread} {module}: {message}",
    style="{")


def print_stream_data_from_stream_buffer(binance_websocket_api_manager):
    while True:
        if binance_websocket_api_manager.is_manager_stopping():
            exit(0)
        oldest_stream_data_from_stream_buffer = binance_websocket_api_manager.pop_stream_data_from_stream_buffer(
        )
        if oldest_stream_data_from_stream_buffer is False:
            time.sleep(0.01)


# create instance of BinanceWebSocketApiManager for Binance.com Futures
binance_websocket_api_manager = BinanceWebSocketApiManager(
    exchange="binance.com-futures")

# https://binance-docs.github.io/apidocs/futures/en/#mark-price-stream-for-all-market
stream_id = binance_websocket_api_manager.create_stream(
    ["!markPrice"], "arr@1s", stream_label="!markPrice@arr@1s")

# start a worker process to move the received stream_data from the stream_buffer to a print function
worker_thread = threading.Thread(target=print_stream_data_from_stream_buffer,
                                 args=(binance_websocket_api_manager, ))
worker_thread.start()

time.sleep(5)
binance_websocket_api_manager.get_stream_subscriptions(stream_id)
time.sleep(3)
print(str(binance_websocket_api_manager.get_results_from_endpoints()))
time.sleep(5)