Skip to content

Commit 1f6d055

Browse files
2.7.0 RC1
1 parent 0ec8c6a commit 1f6d055

File tree

2 files changed

+44
-45
lines changed

2 files changed

+44
-45
lines changed

unicorn_binance_websocket_api/manager.py

Lines changed: 42 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353
from flask import Flask, redirect
5454
from flask_restful import Api
5555
from operator import itemgetter
56-
from typing import Optional, Union, Callable
56+
from typing import Optional, Union, Callable, List, Set
5757
try:
5858
# python <=3.7 support
5959
from typing import Literal
@@ -237,24 +237,23 @@ def __init__(self,
237237
close_timeout_default: int = 1,
238238
ping_interval_default: int = 5,
239239
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,
245245
max_subscriptions_per_stream: Optional[int] = None,
246246
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,
251251
auto_data_cleanup_stopped_streams: bool = False,
252252
lucit_api_secret: str = None,
253253
lucit_license_ini: str = None,
254254
lucit_license_profile: str = None,
255255
lucit_license_token: str = None,
256-
ubra_manager: Optional[BinanceRestApiManager] = None,
257-
):
256+
ubra_manager: BinanceRestApiManager = None):
258257
threading.Thread.__init__(self)
259258
self.name = __app_name__
260259
self.version = __version__
@@ -347,8 +346,8 @@ def __init__(self,
347346
self.socks5_proxy_server = socks5_proxy_server
348347
if socks5_proxy_server is None:
349348
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
352351
self.socks5_proxy_port = None
353352
else:
354353
# Prepare Socks Proxy usage
@@ -379,8 +378,8 @@ def __init__(self,
379378
self.keepalive_streams_list = {}
380379
self.last_entry_added_to_stream_buffer = 0
381380
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}}
384383
self.listen_key_refresh_interval = 15*60
385384
self.max_send_messages_per_second = 5
386385
self.max_send_messages_per_second_reserve = 2
@@ -715,9 +714,9 @@ def _add_stream_to_stream_list(self,
715714
:param stream_id: provide a stream_id - only needed for userData Streams (acquiring a listenKey)
716715
:type stream_id: str
717716
:param channels: provide the channels to create the URI
718-
:type channels: str, tuple, list, set
717+
:type channels: str, list, set
719718
:param markets: provide the markets to create the URI
720-
:type markets: str, tuple, list, set
719+
:type markets: str, list, set
721720
:param stream_label: provide a stream_label for the stream
722721
:type stream_label: str
723722
: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,
861860
:param stream_id: provide a stream_id - only needed for userData Streams (acquiring a listenKey)
862861
:type stream_id: str
863862
:param channels: provide the channels to create the URI
864-
:type channels: str, tuple, list, set
863+
:type channels: str, list, set
865864
:param markets: provide the markets to create the URI
866-
:type markets: str, tuple, list, set
865+
:type markets: str, list, set
867866
:param stream_buffer_name: If `False` the data is going to get written to the default stream_buffer,
868867
set to `True` to read the data via `pop_stream_data_from_stream_buffer(stream_id)` or
869868
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):
14691468
:param method: `SUBSCRIBE` or `UNSUBSCRIBE`
14701469
:type method: str
14711470
:param channels: provide the channels to create the URI
1472-
:type channels: str, tuple, list, set
1471+
:type channels: str, list, set
14731472
:param markets: provide the markets to create the URI
1474-
:type markets: str, tuple, list, set
1473+
:type markets: str, list, set
14751474
:return: payload (list) or False
14761475
"""
14771476
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):
16211620
return payload
16221621

16231622
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,
16261625
stream_label: str = None,
1627-
stream_buffer_name=False,
1626+
stream_buffer_name: Union[bool, str] = False,
16281627
api_key: str = None,
16291628
api_secret: str = None,
1630-
symbols=None,
1629+
symbols: Union[str, List[str], Set[str], None] = None,
16311630
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,
16351634
listen_key: str = None,
16361635
keep_listen_key_alive: bool = True,
1637-
stream_buffer_maxlen=None,
1636+
stream_buffer_maxlen: int = None,
16381637
api: bool = False,
16391638
process_stream_data: Optional[Callable] = None,
16401639
process_stream_data_async: Optional[Callable] = None,
@@ -1685,9 +1684,9 @@ def create_stream(self,
16851684
``binance_websocket_api_manager.create_stream(["arr"], ["!miniTicker"])``
16861685
16871686
:param channels: provide the channels you wish to stream
1688-
:type channels: str, tuple, list, set
1687+
:type channels: str, list, set
16891688
:param markets: provide the markets you wish to stream
1690-
:type markets: str, tuple, list, set
1689+
:type markets: str, list, set
16911690
:param stream_label: provide a stream_label to identify the stream
16921691
:type stream_label: str
16931692
: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,
17001699
:param api_secret: provide a valid Binance API secret
17011700
:type api_secret: str
17021701
:param symbols: provide the symbols for isolated_margin user_data streams
1703-
:type symbols: str
1702+
:type symbols: str, list, set
17041703
:param output: the default setting `raw_data` can be globaly overwritten with the parameter
17051704
`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>`__
17061705
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,
18791878
Create a websocket URI
18801879
18811880
:param channels: provide the channels to create the URI
1882-
:type channels: str, tuple, list, set
1881+
:type channels: str, list, set
18831882
:param markets: provide the markets to create the URI
1884-
:type markets: str, tuple, list, set
1883+
:type markets: str, list, set
18851884
:param stream_id: provide a stream_id - only needed for userData Streams (acquiring a listenKey)
18861885
:type stream_id: str
18871886
:param symbols: provide the symbols for isolated_margin user_data streams
@@ -2561,7 +2560,7 @@ def get_latest_version(self):
25612560
:return: str or False
25622561
"""
25632562
# 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 \
25652564
(self.last_update_check_github['timestamp'] + (60 * 60) < time.time()):
25662565
self.last_update_check_github['status'] = self.get_latest_release_info()
25672566
if self.last_update_check_github['status']:
@@ -2580,7 +2579,7 @@ def get_latest_version_check_command(self):
25802579
:return: str or False
25812580
"""
25822581
# 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 \
25842583
(self.last_update_check_github_check_command['timestamp'] + (60 * 60) < time.time()):
25852584
self.last_update_check_github_check_command['status'] = self.get_latest_release_info_check_command()
25862585
if self.last_update_check_github_check_command['status']:
@@ -3060,7 +3059,7 @@ def get_stream_buffer_length(self, stream_buffer_name=False):
30603059
number += len(self.stream_buffers[stream_buffer_name])
30613060
return number
30623061

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:
30643063
"""
30653064
Get the stream_id of a specific stream by stream label
30663065
@@ -3285,7 +3284,7 @@ def get_stream_statistic(self, stream_id):
32853284
except KeyError:
32863285
return None
32873286

3288-
def get_the_one_active_websocket_api(self) -> Optional[str]:
3287+
def get_the_one_active_websocket_api(self) -> str:
32893288
"""
32903289
This function is needed to simplify the access to the websocket API, if only one API stream exists it is clear
32913290
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
45554554
:param stream_id: id of a stream
45564555
:type stream_id: str
45574556
:param channels: provide the channels you wish to subscribe
4558-
:type channels: str, tuple, list, set
4557+
:type channels: str, list, set
45594558
:param markets: provide the markets you wish to subscribe
4560-
:type markets: str, tuple, list, set
4559+
:type markets: str, list, set
45614560
:return: bool
45624561
"""
45634562
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=
46654664
:param stream_id: id of a stream
46664665
:type stream_id: str
46674666
:param channels: provide the channels you wish to unsubscribe
4668-
:type channels: str, tuple, list, set
4667+
:type channels: str, list, set
46694668
:param markets: provide the markets you wish to unsubscribe
4670-
:type markets: str, tuple, list, set
4669+
:type markets: str, list, set
46714670
:return: bool
46724671
"""
46734672
logger.info(f"BinanceWebSocketApiManager.unsubscribe_from_stream(" + str(stream_id) + ", " + str(channels) +

unittest_binance_websocket_api.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -887,7 +887,7 @@ def test_live_run(self):
887887
'trade', 'btceth')
888888
self.__class__.ubwa.delete_stream_from_stream_list(stream_id1)
889889
self.__class__.ubwa.delete_listen_key_by_stream_id(stream_id1)
890-
self.__class__.ubwa.is_update_availabe_unicorn_fy()
890+
self.__class__.ubwa.is_update_available_unicorn_fy()
891891
self.__class__.ubwa.get_version_unicorn_fy()
892892
self.__class__.ubwa.create_payload(stream_id2, "invalid", channels="trade")
893893
time.sleep(6)
@@ -909,7 +909,7 @@ def test_live_run(self):
909909
self.__class__.ubwa.get_number_of_free_subscription_slots(stream_id2)
910910
self.__class__.ubwa.get_most_receives_per_second()
911911
self.__class__.ubwa.get_number_of_streams_in_stream_list()
912-
self.__class__.ubwa.is_update_availabe_check_command()
912+
self.__class__.ubwa.is_update_available_check_command()
913913
print(f"Waiting for {stream_id2} has stopped")
914914
self.__class__.ubwa.wait_till_stream_has_stopped(stream_id2)
915915
print(f"Done!")

0 commit comments

Comments
 (0)