From 63367eb28383cce5cb875d366f28b74cb996ac58 Mon Sep 17 00:00:00 2001 From: Daler <48939169+daler-sz@users.noreply.github.com> Date: Thu, 18 May 2023 22:07:38 +0500 Subject: [PATCH 1/5] replaced lamda: {} by dict --- pybit/_http_manager.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pybit/_http_manager.py b/pybit/_http_manager.py index d070a80..93b307d 100644 --- a/pybit/_http_manager.py +++ b/pybit/_http_manager.py @@ -37,11 +37,11 @@ class _V5HTTPManager: recv_window: bool = field(default=5000) force_retry: bool = field(default=False) retry_codes: defaultdict[dict] = field( - default_factory=lambda: {}, + default_factory=dict, init=False, ) ignore_codes: dict = field( - default_factory=lambda: {}, + default_factory=dict, init=False, ) max_retries: bool = field(default=3) From 80bfc524ffaef8a2cb047fc73611ebc8581bda1e Mon Sep 17 00:00:00 2001 From: Adde Stromberg Date: Sat, 24 Jun 2023 12:03:56 +0200 Subject: [PATCH 2/5] Added setting for expiretime in private websocket. --- pybit/_websocket_stream.py | 6 +++++- tests/test_pybit.py | 18 ++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/pybit/_websocket_stream.py b/pybit/_websocket_stream.py index f93302a..b46178f 100644 --- a/pybit/_websocket_stream.py +++ b/pybit/_websocket_stream.py @@ -33,6 +33,7 @@ def __init__( retries=10, restart_on_error=True, trace_logging=False, + private_auth_expire=1 ): self.testnet = testnet self.domain = domain @@ -45,6 +46,9 @@ def __init__( self.ws_name = ws_name if api_key: self.ws_name += " (Auth)" + + # Deltatime for private auth expiration in seconds + self.private_auth_expire = private_auth_expire # Setup the callback directory following the format: # { @@ -183,7 +187,7 @@ def _auth(self): """ # Generate expires. - expires = _helpers.generate_timestamp() + 1000 + expires = _helpers.generate_timestamp() + (self.private_auth_expire * 1000) # Generate signature. _val = f"GET/realtime{expires}" diff --git a/tests/test_pybit.py b/tests/test_pybit.py index c16de51..9fc326f 100644 --- a/tests/test_pybit.py +++ b/tests/test_pybit.py @@ -80,3 +80,21 @@ def test_topic_category_mismatch(self): ) ws.order_stream(callback=self._callback_function) + +class PrivateWebSocketTest(unittest.TestCase): + # Connect to private websocket and see if we can auth. + def _callback_function(msg): + print(msg) + + def test_private_websocket_connect(self): + ws_private = WebSocket( + testnet=True, + channel_type="private", + api_key="QjrxRZzwZLHGWkNUae", + api_secret="BeKzaWbdOLz7sAnllwSInDO43v9CgvDQLRl3", + trace_logging=True, + #private_auth_expire=10 + ) + + ws_private.position_stream(callback=self._callback_function) + #time.sleep(10) From 6ab120b903d20ddad5e35ed9417002b9d547e407 Mon Sep 17 00:00:00 2001 From: Adde Stromberg Date: Sat, 24 Jun 2023 12:07:46 +0200 Subject: [PATCH 3/5] Added setting for expiretime in private websocket. --- tests/test_pybit.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/test_pybit.py b/tests/test_pybit.py index 9fc326f..67159d1 100644 --- a/tests/test_pybit.py +++ b/tests/test_pybit.py @@ -90,8 +90,8 @@ def test_private_websocket_connect(self): ws_private = WebSocket( testnet=True, channel_type="private", - api_key="QjrxRZzwZLHGWkNUae", - api_secret="BeKzaWbdOLz7sAnllwSInDO43v9CgvDQLRl3", + api_key="...", + api_secret="...", trace_logging=True, #private_auth_expire=10 ) From 78cabfe0687f0811302bb252f361133ff0204cf8 Mon Sep 17 00:00:00 2001 From: dextertd Date: Mon, 25 Sep 2023 16:34:57 +0100 Subject: [PATCH 4/5] adjust comment --- pybit/_websocket_stream.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pybit/_websocket_stream.py b/pybit/_websocket_stream.py index ecbcc3e..a119819 100644 --- a/pybit/_websocket_stream.py +++ b/pybit/_websocket_stream.py @@ -52,7 +52,7 @@ def __init__( if api_key: self.ws_name += " (Auth)" - # Deltatime for private auth expiration in seconds + # Delta time for private auth expiration in seconds self.private_auth_expire = private_auth_expire # Setup the callback directory following the format: From b3a91d52c305879b8e28f47bdfbeb4829cb86090 Mon Sep 17 00:00:00 2001 From: dextertd Date: Mon, 25 Sep 2023 16:35:05 +0100 Subject: [PATCH 5/5] update changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 16c39df..1b8701e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Your `api_secret` is the private key (RSA) you generate - Learn more [here](https://www.bybit.com/en-US/help-center/bybitHC_Article?id=000001923&language=en_US) - See examples files: [HTTP](https://github.com/bybit-exchange/pybit/blob/master/examples/http_example_rsa_authentication.py) and [WebSocket](https://github.com/bybit-exchange/pybit/blob/master/examples/websocket_example_rsa_authentication.py) +- Add optional `private_auth_expire` arg for WebSocket (https://github.com/bybit-exchange/pybit/pull/154) ## [5.5.0] - 2023-07-17 ### Added