LUCIT-Systems-and-Development / unicorn-binance-websocket-api

A Python SDK by LUCIT to use the Binance Websocket API`s (com+testnet, com-margin+testnet, com-isolated_margin+testnet, com-futures+testnet, com-coin_futures, us, tr, dex/chain+testnet) in a simple, fast, flexible, robust and fully-featured way.
https://unicorn-binance-websocket-api.docs.lucit.tech/
Other
678 stars 166 forks source link

How to format stream_id for get_stream_info() call #189

Closed jlixfeld closed 2 years ago

jlixfeld commented 2 years ago

Hi Oliver,

I'm so grateful for the hard work that you've put into your Unicorn Binance suite! I'm working on migrated over to it from Sam McHardy's API.

From IPython, I can call print_summary() and get a stream_id, but when I try to call get_stream_info() using the UUID I get False returned. I'm not sure what I'm doing wrong in formatting that call. Do you have any tips?

Thanks!

In [14]: ubwam.print_summary()
====================== unicorn-binance-websocket-api_1.31.0-python_3.8.2 ======================
 exchange: binance.com
 uptime: 19m:47s since 2021-08-14, 12:50:17 UTC
 streams: 1
 active_streams: 1
 subscriptions: 316
 stream_buffer_stored_items: 58132
 stream_buffer_byte_size: 23632844 (22.54 mB)
 current_receiving_speed: 19.39 kB/s
 average_receiving_speed: 19.44 kB/s (per day 1.6 gB)
 highest_receiving_speed: 70.72 kB/s (reached at 2021-08-14, 13:00:46 UTC)
 total_receives: 58132
 total_received_bytes: 23632844 (22.54 mB)
 total_transmitted_payloads: 1
 process_ressource_usage: cpu=18.7%, memory=231.77 mB, threads=10
 ---------------------------------------------------------------------------------------------
               stream_id              |   stream_label  |  last  |  average  |  most  | recon
 ---------------------------------------------------------------------------------------------
 24e798fe-0b9e-4e7b-9802-efc3a36b2830 | stream          |     49 |     48.99 |    183 |      0
 ---------------------------------------------------------------------------------------------
 all_streams                                            |     49 |     48.99 |    183 |      0
===============================================================================================

In [15]: ubwam.get_stream_info(24e798fe-0b9e-4e7b-9802-efc3a36b2830)
  File "<ipython-input-15-ff62a8c69109>", line 1
    ubwam.get_stream_info(24e798fe-0b9e-4e7b-9802-efc3a36b2830)
                                ^
SyntaxError: invalid syntax

In [16]: ubwam.get_stream_info("24e798fe-0b9e-4e7b-9802-efc3a36b2830")
Out[16]: False

In [17]: ubwam.get_stream_id_by_label('stream')
Out[17]: UUID('24e798fe-0b9e-4e7b-9802-efc3a36b2830')

In [18]:
oliver-zehentleitner commented 2 years ago

Thank you :)

I think the problem is that you provide the stream_id in string format!

Just wrap it in UUID() as returned from get_stream_id_by_label():

ubwam.get_stream_info(UUID('24e798fe-0b9e-4e7b-9802-efc3a36b2830'))!

jlixfeld commented 2 years ago

I tried that previously as well, with no success:

In [14]: vars.ubwam.print_summary()
====================== unicorn-binance-websocket-api_1.31.0-python_3.8.2 ======================
 exchange: binance.com
 uptime: 21m:17s since 2021-08-14, 14:36:51 UTC
 streams: 1
 active_streams: 1
 subscriptions: 316
 stream_buffer_stored_items: 71557
 stream_buffer_byte_size: 29311041 (27.95 mB)
 current_receiving_speed: 26.08 kB/s
 average_receiving_speed: 22.4 kB/s (per day 1.85 gB)
 highest_receiving_speed: 44.42 kB/s (reached at 2021-08-14, 14:55:13 UTC)
 total_receives: 71557
 total_received_bytes: 29311041 (27.95 mB)
 total_transmitted_payloads: 1
 process_ressource_usage: cpu=10.3%, memory=259.2 mB, threads=8
 ---------------------------------------------------------------------------------------------
               stream_id              |   stream_label  |  last  |  average  |  most  | recon
 ---------------------------------------------------------------------------------------------
 40ab11e7-4589-4fc8-9544-e3f82660cc9d | stream          |     65 |     56.01 |    111 |      0
 ---------------------------------------------------------------------------------------------
 all_streams                                            |     65 |     56.01 |    111 |      0
===============================================================================================

In [15]: vars.ubwam.get_stream_info(UUID('40ab11e7-4589-4fc8-9544-e3f82660cc9d'))
---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
~/Documents/Development/crypto/binance/main.py in <module>
----> 1 vars.ubwam.get_stream_info(UUID('40ab11e7-4589-4fc8-9544-e3f82660cc9d'))

NameError: name 'UUID' is not defined

In [16]:
oliver-zehentleitner commented 2 years ago

do import uuid before!

jlixfeld commented 2 years ago

Really weird. This doesn't work:

In [13]: ubwam.print_summary()
====================== unicorn-binance-websocket-api_1.31.0-python_3.8.2 ======================
 exchange: binance.com
 uptime: 12m:29s since 2021-08-15, 01:38:23 UTC
 streams: 1
 active_streams: 1
 subscriptions: 316
 stream_buffer_stored_items: 32917
 stream_buffer_byte_size: 13452138 (12.83 mB)
 current_receiving_speed: 11.61 kB/s
 average_receiving_speed: 17.54 kB/s (per day 1.45 gB)
 highest_receiving_speed: 35.54 kB/s (reached at 2021-08-15, 01:41:42 UTC)
 total_receives: 32917
 total_received_bytes: 13452138 (12.83 mB)
 total_transmitted_payloads: 1
 process_ressource_usage: cpu=10.5%, memory=148.39 mB, threads=8
 ---------------------------------------------------------------------------------------------
               stream_id              |   stream_label  |  last  |  average  |  most  | recon
 ---------------------------------------------------------------------------------------------
 34055c58-405f-402a-888f-5a59c96f02fd | stream          |     29 |     43.98 |     89 |      0 
 ---------------------------------------------------------------------------------------------
 all_streams                                            |     29 |     43.98 |     89 |      0 
===============================================================================================

In [14]: ubwam.get_stream_info(UUID('34055c58-405f-402a-888f-5a59c96f02fd'))
---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
~/Documents/Development/crypto/binance/main.py in <module>
----> 1 ubwam.get_stream_info(UUID('34055c58-405f-402a-888f-5a59c96f02fd'))

NameError: name 'UUID' is not defined

In [15]:

But this does work...

In [15]: ubwam.get_stream_info(ubwam.get_stream_id_by_label('stream'))
Out[15]: 
{'exchange': 'binance.com',
 'stream_id': UUID('34055c58-405f-402a-888f-5a59c96f02fd'),
 'recent_socket_id': UUID('c4e86c3d-ae5f-4759-9746-2292af2b5e15'),
 'channels': ['kline_1h'],
 'markets': ['dcrusdt',
  'drepusdt',
  'ardrusdt',
...
...
...