53
53
from flask import Flask , redirect
54
54
from flask_restful import Api
55
55
from operator import itemgetter
56
- from typing import Optional , Union , Callable
56
+ from typing import Optional , Union , Callable , List , Set
57
57
try :
58
58
# python <=3.7 support
59
59
from typing import Literal
@@ -237,24 +237,23 @@ def __init__(self,
237
237
close_timeout_default : int = 1 ,
238
238
ping_interval_default : int = 5 ,
239
239
ping_timeout_default : int = 10 ,
240
- high_performance : Optional [ bool ] = False ,
241
- debug : Optional [ bool ] = False ,
242
- restful_base_uri : Optional [ str ] = None ,
243
- websocket_base_uri : Optional [ str ] = None ,
244
- websocket_api_base_uri : Optional [ str ] = None ,
240
+ high_performance : bool = False ,
241
+ debug : bool = False ,
242
+ restful_base_uri : str = None ,
243
+ websocket_base_uri : str = None ,
244
+ websocket_api_base_uri : str = None ,
245
245
max_subscriptions_per_stream : Optional [int ] = None ,
246
246
exchange_type : Literal ['cex' , 'dex' , None ] = None ,
247
- socks5_proxy_server : Optional [ str ] = None ,
248
- socks5_proxy_user : Optional [ str ] = None ,
249
- socks5_proxy_pass : Optional [ str ] = None ,
250
- socks5_proxy_ssl_verification : Optional [ bool ] = True ,
247
+ socks5_proxy_server : str = None ,
248
+ socks5_proxy_user : str = None ,
249
+ socks5_proxy_pass : str = None ,
250
+ socks5_proxy_ssl_verification : bool = True ,
251
251
auto_data_cleanup_stopped_streams : bool = False ,
252
252
lucit_api_secret : str = None ,
253
253
lucit_license_ini : str = None ,
254
254
lucit_license_profile : str = None ,
255
255
lucit_license_token : str = None ,
256
- ubra_manager : Optional [BinanceRestApiManager ] = None ,
257
- ):
256
+ ubra_manager : BinanceRestApiManager = None ):
258
257
threading .Thread .__init__ (self )
259
258
self .name = __app_name__
260
259
self .version = __version__
@@ -347,8 +346,8 @@ def __init__(self,
347
346
self .socks5_proxy_server = socks5_proxy_server
348
347
if socks5_proxy_server is None :
349
348
self .socks5_proxy_address = None
350
- self .socks5_proxy_user : Optional [ str ] = None
351
- self .socks5_proxy_pass : Optional [ str ] = None
349
+ self .socks5_proxy_user : str = None
350
+ self .socks5_proxy_pass : str = None
352
351
self .socks5_proxy_port = None
353
352
else :
354
353
# Prepare Socks Proxy usage
@@ -379,8 +378,8 @@ def __init__(self,
379
378
self .keepalive_streams_list = {}
380
379
self .last_entry_added_to_stream_buffer = 0
381
380
self .last_monitoring_check = time .time ()
382
- self .last_update_check_github = {'timestamp' : time .time (), 'status' : {'tag_name' : "" }}
383
- self .last_update_check_github_check_command = {'timestamp' : time .time (), 'status' : {'tag_name' : "" }}
381
+ self .last_update_check_github = {'timestamp' : time .time (), 'status' : {'tag_name' : None }}
382
+ self .last_update_check_github_check_command = {'timestamp' : time .time (), 'status' : {'tag_name' : None }}
384
383
self .listen_key_refresh_interval = 15 * 60
385
384
self .max_send_messages_per_second = 5
386
385
self .max_send_messages_per_second_reserve = 2
@@ -715,9 +714,9 @@ def _add_stream_to_stream_list(self,
715
714
:param stream_id: provide a stream_id - only needed for userData Streams (acquiring a listenKey)
716
715
:type stream_id: str
717
716
:param channels: provide the channels to create the URI
718
- :type channels: str, tuple, list, set
717
+ :type channels: str, list, set
719
718
:param markets: provide the markets to create the URI
720
- :type markets: str, tuple, list, set
719
+ :type markets: str, list, set
721
720
:param stream_label: provide a stream_label for the stream
722
721
:type stream_label: str
723
722
:param stream_buffer_name: If `False` the data is going to get written to the default stream_buffer,
@@ -861,9 +860,9 @@ def _create_stream_thread(self,
861
860
:param stream_id: provide a stream_id - only needed for userData Streams (acquiring a listenKey)
862
861
:type stream_id: str
863
862
:param channels: provide the channels to create the URI
864
- :type channels: str, tuple, list, set
863
+ :type channels: str, list, set
865
864
:param markets: provide the markets to create the URI
866
- :type markets: str, tuple, list, set
865
+ :type markets: str, list, set
867
866
:param stream_buffer_name: If `False` the data is going to get written to the default stream_buffer,
868
867
set to `True` to read the data via `pop_stream_data_from_stream_buffer(stream_id)` or
869
868
provide a string to create and use a shared stream_buffer and read it via
@@ -1469,9 +1468,9 @@ def create_payload(self, stream_id, method, channels=None, markets=None):
1469
1468
:param method: `SUBSCRIBE` or `UNSUBSCRIBE`
1470
1469
:type method: str
1471
1470
:param channels: provide the channels to create the URI
1472
- :type channels: str, tuple, list, set
1471
+ :type channels: str, list, set
1473
1472
:param markets: provide the markets to create the URI
1474
- :type markets: str, tuple, list, set
1473
+ :type markets: str, list, set
1475
1474
:return: payload (list) or False
1476
1475
"""
1477
1476
logger .info ("BinanceWebSocketApiManager.create_payload(" + str (stream_id ) + ", " + str (channels ) + ", " +
@@ -1621,20 +1620,20 @@ def create_payload(self, stream_id, method, channels=None, markets=None):
1621
1620
return payload
1622
1621
1623
1622
def create_stream (self ,
1624
- channels = None ,
1625
- markets = None ,
1623
+ channels : Union [ str , List [ str ], Set [ str ], None ] = None ,
1624
+ markets : Union [ str , List [ str ], Set [ str ], None ] = None ,
1626
1625
stream_label : str = None ,
1627
- stream_buffer_name = False ,
1626
+ stream_buffer_name : Union [ bool , str ] = False ,
1628
1627
api_key : str = None ,
1629
1628
api_secret : str = None ,
1630
- symbols = None ,
1629
+ symbols : Union [ str , List [ str ], Set [ str ], None ] = None ,
1631
1630
output : Optional [Literal ['dict' , 'raw_data' , 'UnicornFy' ]] = "raw_data" ,
1632
- ping_interval = None ,
1633
- ping_timeout = None ,
1634
- close_timeout = None ,
1631
+ ping_interval : int = None ,
1632
+ ping_timeout : int = None ,
1633
+ close_timeout : int = None ,
1635
1634
listen_key : str = None ,
1636
1635
keep_listen_key_alive : bool = True ,
1637
- stream_buffer_maxlen = None ,
1636
+ stream_buffer_maxlen : int = None ,
1638
1637
api : bool = False ,
1639
1638
process_stream_data : Optional [Callable ] = None ,
1640
1639
process_stream_data_async : Optional [Callable ] = None ,
@@ -1685,9 +1684,9 @@ def create_stream(self,
1685
1684
``binance_websocket_api_manager.create_stream(["arr"], ["!miniTicker"])``
1686
1685
1687
1686
:param channels: provide the channels you wish to stream
1688
- :type channels: str, tuple, list, set
1687
+ :type channels: str, list, set
1689
1688
:param markets: provide the markets you wish to stream
1690
- :type markets: str, tuple, list, set
1689
+ :type markets: str, list, set
1691
1690
:param stream_label: provide a stream_label to identify the stream
1692
1691
:type stream_label: str
1693
1692
:param stream_buffer_name: If `False` the data is going to get written to the default stream_buffer,
@@ -1700,7 +1699,7 @@ def create_stream(self,
1700
1699
:param api_secret: provide a valid Binance API secret
1701
1700
:type api_secret: str
1702
1701
:param symbols: provide the symbols for isolated_margin user_data streams
1703
- :type symbols: str
1702
+ :type symbols: str, list, set
1704
1703
:param output: the default setting `raw_data` can be globaly overwritten with the parameter
1705
1704
`output_default <https://unicorn-binance-websocket-api.docs.lucit.tech/unicorn_binance_websocket_api.html?highlight=output_default#module-unicorn_binance_websocket_api.unicorn_binance_websocket_api_manager>`__
1706
1705
of BinanceWebSocketApiManager`. To overrule the `output_default` value for this specific stream,
@@ -1879,9 +1878,9 @@ def create_websocket_uri(self, channels, markets, stream_id=None, symbols=None,
1879
1878
Create a websocket URI
1880
1879
1881
1880
:param channels: provide the channels to create the URI
1882
- :type channels: str, tuple, list, set
1881
+ :type channels: str, list, set
1883
1882
:param markets: provide the markets to create the URI
1884
- :type markets: str, tuple, list, set
1883
+ :type markets: str, list, set
1885
1884
:param stream_id: provide a stream_id - only needed for userData Streams (acquiring a listenKey)
1886
1885
:type stream_id: str
1887
1886
:param symbols: provide the symbols for isolated_margin user_data streams
@@ -2561,7 +2560,7 @@ def get_latest_version(self):
2561
2560
:return: str or False
2562
2561
"""
2563
2562
# Do a fresh request if status is None or last timestamp is older 1 hour
2564
- if self .last_update_check_github ['status' ][ 'tag_name' ] == "" or \
2563
+ if self .last_update_check_github ['status' ]. get ( 'tag_name' ) is None or \
2565
2564
(self .last_update_check_github ['timestamp' ] + (60 * 60 ) < time .time ()):
2566
2565
self .last_update_check_github ['status' ] = self .get_latest_release_info ()
2567
2566
if self .last_update_check_github ['status' ]:
@@ -2580,7 +2579,7 @@ def get_latest_version_check_command(self):
2580
2579
:return: str or False
2581
2580
"""
2582
2581
# Do a fresh request if status is None or last timestamp is older 1 hour
2583
- if self .last_update_check_github_check_command ['status' ][ 'tag_name' ] == "" or \
2582
+ if self .last_update_check_github_check_command ['status' ]. get ( 'tag_name' ) is None or \
2584
2583
(self .last_update_check_github_check_command ['timestamp' ] + (60 * 60 ) < time .time ()):
2585
2584
self .last_update_check_github_check_command ['status' ] = self .get_latest_release_info_check_command ()
2586
2585
if self .last_update_check_github_check_command ['status' ]:
@@ -3060,7 +3059,7 @@ def get_stream_buffer_length(self, stream_buffer_name=False):
3060
3059
number += len (self .stream_buffers [stream_buffer_name ])
3061
3060
return number
3062
3061
3063
- def get_stream_id_by_label (self , stream_label : str = None ) -> Optional [ str ] :
3062
+ def get_stream_id_by_label (self , stream_label : str = None ) -> str :
3064
3063
"""
3065
3064
Get the stream_id of a specific stream by stream label
3066
3065
@@ -3285,7 +3284,7 @@ def get_stream_statistic(self, stream_id):
3285
3284
except KeyError :
3286
3285
return None
3287
3286
3288
- def get_the_one_active_websocket_api (self ) -> Optional [ str ] :
3287
+ def get_the_one_active_websocket_api (self ) -> str :
3289
3288
"""
3290
3289
This function is needed to simplify the access to the websocket API, if only one API stream exists it is clear
3291
3290
that only this stream can be used for the requests and therefore will be used.
@@ -4555,9 +4554,9 @@ def subscribe_to_stream(self, stream_id: str = None, channels=None, markets=None
4555
4554
:param stream_id: id of a stream
4556
4555
:type stream_id: str
4557
4556
:param channels: provide the channels you wish to subscribe
4558
- :type channels: str, tuple, list, set
4557
+ :type channels: str, list, set
4559
4558
:param markets: provide the markets you wish to subscribe
4560
- :type markets: str, tuple, list, set
4559
+ :type markets: str, list, set
4561
4560
:return: bool
4562
4561
"""
4563
4562
logger .info (f"BinanceWebSocketApiManager.subscribe_to_stream(" + str (stream_id ) + ", " + str (channels ) +
@@ -4665,9 +4664,9 @@ def unsubscribe_from_stream(self, stream_id: str = None, channels=None, markets=
4665
4664
:param stream_id: id of a stream
4666
4665
:type stream_id: str
4667
4666
:param channels: provide the channels you wish to unsubscribe
4668
- :type channels: str, tuple, list, set
4667
+ :type channels: str, list, set
4669
4668
:param markets: provide the markets you wish to unsubscribe
4670
- :type markets: str, tuple, list, set
4669
+ :type markets: str, list, set
4671
4670
:return: bool
4672
4671
"""
4673
4672
logger .info (f"BinanceWebSocketApiManager.unsubscribe_from_stream(" + str (stream_id ) + ", " + str (channels ) +
0 commit comments