crypto-ws-api 2.1.0__tar.gz → 2.1.2__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,3 +1,10 @@
1
+ ## 2.1.2 - 2025-08-10
2
+ ♻️ refactor(demo/demo_loop): Store demo_loop coroutines in variables for reference
3
+
4
+ ## 2.1.1 - 2025-08-10
5
+ ♻️ refactor(ws_session): introduce `tasks_manage` for centralized task handling
6
+ ♻️ chore(deps): update platformdirs and cryptography to latest versions
7
+
1
8
  ## 2.1.0 - 2025-06-22
2
9
  ✨ refactor(ws_session.py): simplify `ws_login` and `request` methods by removing redundant `send_api_key` parameter.
3
10
 
@@ -1,6 +1,6 @@
1
- Metadata-Version: 2.3
1
+ Metadata-Version: 2.4
2
2
  Name: crypto-ws-api
3
- Version: 2.1.0
3
+ Version: 2.1.2
4
4
  Summary: Crypto WS API connector for ASYNC requests
5
5
  Author-email: Jerry Fedorenko <jerry.fedorenko@yahoo.com>
6
6
  Requires-Python: >=3.10
@@ -11,12 +11,13 @@ Classifier: License :: OSI Approved :: MIT License
11
11
  Classifier: Operating System :: Unix
12
12
  Classifier: Operating System :: Microsoft :: Windows
13
13
  Classifier: Operating System :: MacOS
14
+ License-File: LICENSE.md
14
15
  Requires-Dist: shortuuid~=1.0.13
15
- Requires-Dist: platformdirs==4.3.6
16
+ Requires-Dist: platformdirs==4.3.8
16
17
  Requires-Dist: toml~=0.10.2
17
18
  Requires-Dist: websockets==15.0.1
18
19
  Requires-Dist: ujson~=5.10.0
19
- Requires-Dist: cryptography~=44.0.2
20
+ Requires-Dist: cryptography~=45.0.6
20
21
  Project-URL: Source, https://github.com/DogsTailFarmer/crypto-ws-api
21
22
 
22
23
  <h1 align="center"><img align="center" src="https://user-images.githubusercontent.com/77513676/250364389-cbedc171-a930-4467-a0cd-21627a6a41ed.svg" width="75">Crypto WS API connector for ASYNC requests</h1>
@@ -13,7 +13,7 @@ __maintainer__ = "Jerry Fedorenko"
13
13
  __contact__ = "https://github.com/DogsTailFarmer"
14
14
  __email__ = "jerry.fedorenko@yahoo.com"
15
15
  __credits__ = ["https://github.com/DanyaSWorlD"]
16
- __version__ = "2.1.0"
16
+ __version__ = "2.1.2"
17
17
 
18
18
  from pathlib import Path
19
19
  import shutil
@@ -43,8 +43,8 @@ async def main(account_name):
43
43
 
44
44
  # Demo method's calling
45
45
  await account_information(user_session, trade_id)
46
- asyncio.ensure_future(demo_loop(user_session, get_time, trade_id, 2))
47
- asyncio.ensure_future(demo_loop(user_session, current_average_price, trade_id, 3))
46
+ _t1 = asyncio.ensure_future(demo_loop(user_session, get_time, trade_id, 2))
47
+ _t2 = asyncio.ensure_future(demo_loop(user_session, current_average_price, trade_id, 3))
48
48
 
49
49
  await asyncio.sleep(20)
50
50
 
@@ -16,6 +16,7 @@ import random
16
16
  from datetime import datetime, timezone
17
17
  from urllib.parse import urlencode, urlparse
18
18
  from cryptography.hazmat.primitives.serialization import load_pem_private_key
19
+ import inspect
19
20
 
20
21
  from websockets.asyncio.client import connect
21
22
  from websockets import ConnectionClosed
@@ -102,6 +103,13 @@ def compose_htx_ws_auth(endpoint, exchange, api_key, api_secret):
102
103
  "params": _params
103
104
  }
104
105
 
106
+ def tasks_manage(tasks_set: set, coro, name=None, add_done_callback=True):
107
+ _t = asyncio.create_task(coro, name=name or inspect.stack()[1][3])
108
+ tasks_set.add(_t)
109
+ if add_done_callback:
110
+ _t.add_done_callback(tasks_set.discard)
111
+
112
+
105
113
  # https://binance-docs.github.io/apidocs/websocket_api/en/#rate-limits
106
114
  class RateLimitInterval(Enum):
107
115
  SECOND = 1
@@ -159,13 +167,8 @@ class UserWSS:
159
167
  else:
160
168
  self.logger = logger
161
169
 
162
- def tasks_manage(self, coro, name=None):
163
- _t = asyncio.create_task(coro, name=name)
164
- self.tasks.add(_t)
165
- _t.add_done_callback(self.tasks.discard)
166
-
167
- async def _ws_listener(self):
168
- self.tasks_manage(self.ws_login())
170
+ async def _ws_listener(self): #NOSONAR
171
+ tasks_manage(self.tasks, self.ws_login(), f"ws_login-{self.ws_id}")
169
172
  async for msg in self._ws:
170
173
  # logger.info(f"_ws_listener: ws_id: {self.ws_id} msg: {msg}")
171
174
  if isinstance(msg, str):
@@ -224,11 +227,11 @@ class UserWSS:
224
227
  await self.stop()
225
228
  else:
226
229
  if self.exchange == 'huobi':
227
- self.tasks_manage(self.htx_keepalive(), f"htx_keepalive-{self.ws_id}")
230
+ tasks_manage(self.tasks, self.htx_keepalive(), f"htx_keepalive-{self.ws_id}")
228
231
 
229
232
  self.operational_status = True
230
233
  self.order_handling = True
231
- self.tasks_manage(self._keepalive(), f"keepalive-{self.ws_id}")
234
+ tasks_manage(self.tasks, self._keepalive(), f"keepalive-{self.ws_id}")
232
235
  logger.info(f"UserWSS: 'logged in' for {self.ws_id}")
233
236
 
234
237
  async def request(self, method, _params=None, _signed=False):
@@ -247,7 +250,7 @@ class UserWSS:
247
250
  logger.warning("UserWSS: exceeded order placement limit, try later")
248
251
  return None
249
252
  params = _params.copy() if _params else None
250
- r_id = f"{self.exchange}{method}{''.join(random.choices(ALPHABET, k=8))}"
253
+ r_id = f"{self.exchange}{method}{''.join(random.choices(ALPHABET, k=8))}" #NOSONAR
251
254
  if self.exchange in ("okx", "bitfinex", "huobi") and method == CONST_WS_START:
252
255
  _id = self.ws_id
253
256
  else:
@@ -553,9 +556,7 @@ class UserWSSession:
553
556
  if user_wss.init:
554
557
  user_wss.init = False
555
558
  user_wss.operational_status = False
556
- _t = asyncio.create_task(user_wss.start_wss())
557
- self.tasks_wss.add(_t)
558
- _t.add_done_callback(self.tasks_wss.discard)
559
+ tasks_manage(self.tasks_wss, user_wss.start_wss(), f"start_wss-{ws_id}")
559
560
 
560
561
  duration = 0
561
562
  while not (user_wss.operational_status and user_wss.order_handling):
@@ -18,11 +18,11 @@ requires-python = ">=3.10"
18
18
 
19
19
  dependencies = [
20
20
  "shortuuid~=1.0.13",
21
- "platformdirs==4.3.6",
21
+ "platformdirs==4.3.8",
22
22
  "toml~=0.10.2",
23
23
  "websockets==15.0.1",
24
24
  "ujson~=5.10.0",
25
- "cryptography~=44.0.2"
25
+ "cryptography~=45.0.6"
26
26
  ]
27
27
 
28
28
  [tool.flit.module]
@@ -1,6 +1,6 @@
1
1
  shortuuid~=1.0.13
2
- platformdirs==4.3.6
2
+ platformdirs==4.3.8
3
3
  toml~=0.10.2
4
4
  websockets==15.0.1
5
5
  ujson~=5.10.0
6
- cryptography~=44.0.2
6
+ cryptography~=45.0.6
File without changes
File without changes