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()
Exemplo n.º 2
0
worker_thread = threading.Thread(target=print_stream_data_from_stream_buffer,
                                 args=(ws_manager, ))
worker_thread.start()

export_thread = threading.Thread(target=print_stream_to_png,
                                 args=(ws_manager, ))
export_thread.start()

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

userdata_stream_id = ws_manager.create_stream(["!userData"], ["arr"],
                                              "userData stream",
                                              api_key=binance_api_key,
                                              api_secret=binance_api_secret)
arr_stream_id = ws_manager.create_stream(arr_channels, "arr", "arr channels")

divisor = math.ceil(
    len(markets) / ws_manager.get_limit_of_subscriptions_per_stream())
max_subscriptions = math.ceil(len(markets) / divisor)

for channel in channels:
    if len(markets) <= max_subscriptions:
        ws_manager.create_stream(channel, markets, stream_label=channel)
    else:
        loops = 1
        i = 1
        markets_sub = []
        for market in markets:
            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',
    'spotTicker'
}
binance_websocket_api_manager.create_stream(["spotTrade"], spot_markets)
binance_websocket_api_manager.create_stream(["spotDepth10"], spot_markets)
        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")

# create the userData streams
user_stream_id_im = ubwa_com_im.create_stream('arr', '!userData', symbols="trxbtc", api_key=api_key, api_secret=api_secret)
Exemplo n.º 5
0
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()
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!")

binance_websocket_api_manager.create_stream(arr_channels,
                                            "arr",
                                            stream_label="`arr` channels")

divisor = math.ceil(
    len(markets) /
    binance_websocket_api_manager.get_limit_of_subscriptions_per_stream())
max_subscriptions = math.ceil(len(markets) / divisor)

for channel in channels:
    if len(markets) <= max_subscriptions:
        binance_websocket_api_manager.create_stream(channel,
        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()
Exemplo n.º 7
0
                    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)
binance_get_trade_stream_id = binance_websocket_api_manager.create_stream(['trade'], markets)

time.sleep(5)

# replace stream 1 with stream 3 (stream 1 will not get stopped till stream 3 received its first data row
binance_get_multi_stream_id = binance_websocket_api_manager.replace_stream(binance_get_ticker_stream_id, ['trade', 'depth', 'depth10', 'aggTrade', 'miniTicker'], markets)

# subscribe new markets to a stream
markets = ['engbtc', 'zileth', 'xlmeth', 'eosbnb', 'xrppax', 'lskbtc', 'npxsbtc', 'xmrusdt', 'ltcpax', 'xmrusdt',
           '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']
Exemplo n.º 8
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)

Exemplo n.º 9
0
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()

for item in data:
    markets.append(item['symbol'])
    if len(
            markets
    ) == binance_websocket_api_manager.get_limit_of_subscriptions_per_stream():
        break

#binance_websocket_api_manager.create_stream(["!userData"], ["arr"], "Alice userData stream",
#                                            api_key="aaa", api_secret="bbb")
#binance_websocket_api_manager.create_stream(["!userData"], ["arr"], "Bobs userData stream",
#                                            api_key="ccc", api_secret="ddd")

binance_websocket_api_manager.create_stream(arr_channels,
                                            "arr",
                                            stream_label="arr channels")

#for channel in channels:
#    binance_websocket_api_manager.create_stream(channel, markets, stream_label=channel)

ubwa = binance_websocket_api_manager

IPython.embed()
Exemplo n.º 10
0
    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:
            # Use only the closing kline
Exemplo n.º 11
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:
            #pass
            print(oldest_stream_data_from_stream_buffer)


# 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()

# create streams
print("\r\n========================================== Starting ticker all ========================================\r\n")
ticker_arr_stream_id = binance_websocket_api_manager.create_stream("arr", "!ticker")
time.sleep(7)
binance_websocket_api_manager.stop_stream(ticker_arr_stream_id)
time.sleep(2)
print("\r\n=========================================== Stopp ticker all ==========================================\r\n")

print("\r\n============================================ Starting ticker ==========================================\r\n")
ticker_stream_id = binance_websocket_api_manager.create_stream("ticker", ['bnbbtc', 'ethbtc'])
time.sleep(7)
binance_websocket_api_manager.stop_stream(ticker_stream_id)
time.sleep(2)
print("\r\n============================================== Stop ticker  ===========================================\r\n")

print("\r\n======================================== Starting !miniTicker arr =====================================\r\n")
miniTicker_arr_stream_id = binance_websocket_api_manager.create_stream("arr", "!miniTicker")
time.sleep(7)
    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 ...")
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-coin_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/delivery/en/#mark-price-of-all-symbols-of-a-pair
stream_id = binance_websocket_api_manager.create_stream(["markPrice@1s"], "btcusd", stream_label="BTCUSD@arr@1s")

symbols = {'btcusd_perp', 'ethusd_perp', 'bnbusd_perp'}
pairs = {'btcusd', 'ethusd', 'bnbusd'}
binance_websocket_api_manager.create_stream(["aggTrade"], symbols)
binance_websocket_api_manager.create_stream(["markPrice"], pairs)
binance_websocket_api_manager.create_stream(["markPriceKline_1m"], symbols)
binance_websocket_api_manager.create_stream(["indexPriceKline_5m"], symbols)
binance_websocket_api_manager.create_stream(["depth5@100ms"], symbols)
binance_websocket_api_manager.create_stream(["depth10"], symbols)
Exemplo n.º 14
0
    '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', 'bnbpax',
    'linkusdt', 'hceth', 'zrxeth', 'icxeth', 'xmreth', 'neobnb', 'etceth',
    'zeceth', 'xmrbnb', 'wanbnb', 'zrxbnb', 'agibnb', 'funeth', 'arketh',
    'engeth'
}

binance_websocket_api_manager.create_stream('kline_1m',
                                            markets,
                                            stream_label="UnicornFy",
                                            output="UnicornFy")

binance_websocket_api_manager.create_stream('kline_1m',
                                            markets,
                                            stream_label="dict",
                                            output="dict")

binance_websocket_api_manager.create_stream('kline_1m',
                                            markets,
                                            stream_label="raw_data",
                                            output="raw_data")

print(f"Printing the closing klines:")

while True:
            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)
binance_websocket_api_manager.create_stream(["kline_1w"], markets)
binance_websocket_api_manager.create_stream(["ticker"], markets)
Exemplo n.º 16
0
            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"])
binance_websocket_api_manager.create_stream(["blockheight"], ["$all"])

markets = ['0KI-0AF_BNB', '000-0E1_BNB', '1KVOLUME-D65_BNB', '81JIAN-3E8_BNB', 'AAA-B50_BNB', 'AAAAAA-BBA_BNB']
binance_websocket_api_manager.create_stream(["trades"], markets)
binance_websocket_api_manager.create_stream(["marketDepth"], markets)
binance_websocket_api_manager.create_stream(["kline_1m"], markets)
binance_websocket_api_manager.create_stream(["kline_1h"], markets)
binance_websocket_api_manager.create_stream(["ticker"], markets)
Exemplo n.º 17
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)


# 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)
# show an overview
while True:
    binance_websocket_api_manager.print_stream_info(stream_id)
    time.sleep(1)
Exemplo n.º 18
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)
Exemplo n.º 19
0
            #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'])

#binance_websocket_api_manager.subscribe_to_stream(stream_id, channels="arr", markets="!miniTicker")

#time.sleep(5)
#binance_websocket_api_manager.get_stream_subscriptions(stream_id)

markets = [
    'xrpbearbusd', 'zeceth', 'cndbtc', 'dashbtc', 'atompax', 'perlbtc',
    'ardreth', 'zecbnb', 'bchabctusd', 'usdsbusdt', 'winbnb', 'xzcxrp',
Exemplo n.º 20
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)

# 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'}
binance_websocket_api_manager.create_stream(["aggTrade"], markets)
binance_websocket_api_manager.create_stream(["markPrice"], 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)
Exemplo n.º 21
0
    '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 = {
    'trade', 'kline_1', 'kline_5', 'kline_15', 'kline_30', 'kline_1h',
    'kline_12h', 'kline_1w', 'miniTicker'
}

# create and start the stream
print("please wait 10 seconds!")
time.sleep(3)
multi_stream_id = binance_websocket_api_manager.create_stream(
    channels, markets)
binance_websocket_api_manager.print_stream_info(multi_stream_id)
time.sleep(10)

# stop the stream
binance_websocket_api_manager.stop_stream(multi_stream_id)
time.sleep(3)

# print info about the stream
print("\r\n\r\n")
binance_websocket_api_manager.print_stream_info(multi_stream_id)

print(
    "\r\n=============================== Stopping BinanceWebSocketManager ======================================\r\n"
)
binance_websocket_api_manager.stop_manager_with_all_streams()
    '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'
]

for channel in channels:
    binance_websocket_api_manager.create_stream(channel, markets)


def print_stream_data_from_stream_buffer(binance_websocket_api_manager):
    print("waiting 30 seconds, then we start flushing the stream_buffer")
    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)
        else:
            try:
                # remove # to activate the print function:
markets_mega_list.update(
    markets)  # merge elements of set `markets` to set `markets_mega_list`

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

print(
    "############################################################################################################\r\n"
)

# create and start some streams
first_multi_stream_id = binance_websocket_api_manager.create_stream(
    channels, markets, stream_label="test1")
ticker_stream_id = binance_websocket_api_manager.create_stream(
    ["arr"], ["!miniTicker"], stream_label="ticker")
miniticker_stream_id = binance_websocket_api_manager.create_stream(["arr"],
                                                                   ["!ticker"])
time.sleep(4)

first_multi_stream_info = binance_websocket_api_manager.get_stream_info(
    first_multi_stream_id)
print(binance_websocket_api_manager.get_stream_label(first_multi_stream_id),
      "received", first_multi_stream_info['processed_receives_total'],
      "records till now! ##\r\n")

# stop the streams
binance_websocket_api_manager.stop_stream(first_multi_stream_id)
binance_websocket_api_manager.stop_stream(miniticker_stream_id)
Exemplo n.º 24
0
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)

# 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_com_websocket_api_manager,))
worker_thread.start()
worker_thread = threading.Thread(target=print_stream_data_from_stream_buffer, args=(binance_us_websocket_api_manager,))
worker_thread.start()
worker_thread = threading.Thread(target=print_stream_data_from_stream_buffer,
Exemplo n.º 25
0
            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',
           'bnbpax', 'linkusdt', 'hceth', 'zrxeth', 'icxeth', 'xmreth', 'neobnb', 'etceth', 'zeceth', 'xmrbnb',
           'wanbnb', 'zrxbnb', 'agibnb', 'funeth', 'arketh', 'engeth'}
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")
Exemplo n.º 27
0

# 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)
time.sleep(2)
print(
    "\r\n=========================================== Stopped ticker all ========================================\r\n"
)

print(
    "\r\n========================================= Starting !miniticker ========================================\r\n"
)
miniticker_stream_id = binance_websocket_api_manager.create_stream(
    ["arr"], ["!miniTicker"])
time.sleep(5)
binance_websocket_api_manager.stop_stream(miniticker_stream_id)
time.sleep(2)
Exemplo n.º 28
0
        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,
                                       alice_stream_id))
worker_thread.start()

# configure api key and secret for binance.com for Bob
bob_api_key = "cccc"
bob_api_secret = "dddd"
# create the userData streams
bob_stream_id = binance_com_websocket_api_manager.create_stream(
    'arr',
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)
    if msg:
        order_status(msg)
    time.sleep(0.01)
    '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'
]

for channel in channels:
    ubwa.create_stream(channel, markets, stream_buffer_name=channel)


def print_stream_data_from_stream_buffer(ubwa):
    print("print trades only")
    time.sleep(10)
    while True:
        if ubwa.is_manager_stopping():
            exit(0)
        oldest_stream_data_from_stream_buffer = ubwa.pop_stream_data_from_stream_buffer(
            "trade")
        if oldest_stream_data_from_stream_buffer is False:
            time.sleep(0.01)
        else:
            try:
                print(oldest_stream_data_from_stream_buffer)