hyperquant 0.85__py3-none-any.whl → 0.86__py3-none-any.whl

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.

Potentially problematic release.


This version of hyperquant might be problematic. Click here for more details.

@@ -2,6 +2,7 @@ from __future__ import annotations
2
2
 
3
3
  import asyncio
4
4
  import logging
5
+ import time
5
6
  from typing import Any, Literal, Sequence
6
7
 
7
8
  import pybotters
@@ -307,6 +308,7 @@ class Coinw:
307
308
  *,
308
309
  depth_limit: int | None = 1,
309
310
  biz: str = "futures",
311
+ stale_timeout: float = 5,
310
312
  ) -> pybotters.ws.WebSocketApp:
311
313
  """订阅 ``type=depth`` 订单簿数据,批量控制发送频率。"""
312
314
 
@@ -332,12 +334,50 @@ class Coinw:
332
334
  await ws_app._event.wait()
333
335
 
334
336
  chunk_size = 10
335
- for idx in range(0, len(subscriptions), chunk_size):
336
- batch = subscriptions[idx : idx + chunk_size]
337
- for msg in batch:
338
- await ws_app.current_ws.send_json(msg)
339
- if idx + chunk_size < len(subscriptions):
340
- await asyncio.sleep(2.05)
337
+
338
+ async def send_subs(target: pybotters.ws.WebSocketApp) -> None:
339
+ for idx in range(0, len(subscriptions), chunk_size):
340
+ batch = subscriptions[idx : idx + chunk_size]
341
+ for msg in batch:
342
+ await target.current_ws.send_json(msg)
343
+ if idx + chunk_size < len(subscriptions):
344
+ await asyncio.sleep(2.05)
345
+
346
+ await send_subs(ws_app)
347
+
348
+ ws_ref: dict[str, pybotters.ws.WebSocketApp] = {"app": ws_app}
349
+
350
+ async def monitor() -> None:
351
+ while True:
352
+ await asyncio.sleep(stale_timeout)
353
+ last_update = self.store.book.last_update
354
+ if not last_update:
355
+ continue
356
+ if time.time() - last_update < stale_timeout:
357
+ continue
358
+ logger.warning(
359
+ "CoinW order book idle for %.1f seconds, reconnecting.", stale_timeout
360
+ )
361
+ try:
362
+ current = ws_ref["app"]
363
+ if current.current_ws and not current.current_ws.closed:
364
+ await current.current_ws.close()
365
+ except Exception:
366
+ logger.exception("Error closing stale CoinW orderbook websocket")
367
+
368
+ try:
369
+ new_ws = self.client.ws_connect(
370
+ self.ws_url_public,
371
+ hdlr_json=self.store.onmessage,
372
+ headers=self._ws_headers,
373
+ )
374
+ await new_ws._event.wait()
375
+ await send_subs(new_ws)
376
+ ws_ref["app"] = new_ws
377
+ except Exception:
378
+ logger.exception("Failed to reconnect CoinW orderbook websocket")
379
+
380
+ asyncio.create_task(monitor())
341
381
 
342
382
  return ws_app
343
383
 
@@ -1,6 +1,7 @@
1
1
  from __future__ import annotations
2
2
 
3
3
  import asyncio
4
+ import time
4
5
  from typing import TYPE_CHECKING, Any, Awaitable
5
6
 
6
7
  import aiohttp
@@ -35,6 +36,7 @@ class Book(DataStore):
35
36
 
36
37
  def _init(self) -> None:
37
38
  self.limit: int | None = None
39
+ self._last_update: float = 0.0
38
40
 
39
41
  def _on_message(self, msg: dict[str, Any]) -> None:
40
42
  data = msg.get("data")
@@ -80,6 +82,7 @@ class Book(DataStore):
80
82
 
81
83
  self._find_and_delete({"s": str(symbol)})
82
84
  self._insert(entries)
85
+ self._last_update = time.time()
83
86
 
84
87
  def sorted(
85
88
  self, query: Item | None = None, limit: int | None = None
@@ -93,6 +96,10 @@ class Book(DataStore):
93
96
  limit=limit,
94
97
  )
95
98
 
99
+ @property
100
+ def last_update(self) -> float:
101
+ return self._last_update
102
+
96
103
 
97
104
  class Detail(DataStore):
98
105
  """CoinW 合约信息数据存储。
hyperquant/broker/ws.py CHANGED
@@ -36,7 +36,7 @@ class Heartbeat:
36
36
  async def coinw(ws: ClientWebSocketResponse):
37
37
  while not ws.closed:
38
38
  await ws.send_json({"event": "ping"})
39
- await asyncio.sleep(10.0)
39
+ await asyncio.sleep(3.0)
40
40
 
41
41
  pybotters.ws.HeartbeatHosts.items['futures.ourbit.com'] = Heartbeat.ourbit
42
42
  pybotters.ws.HeartbeatHosts.items['www.ourbit.com'] = Heartbeat.ourbit_spot
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: hyperquant
3
- Version: 0.85
3
+ Version: 0.86
4
4
  Summary: A minimal yet hyper-efficient backtesting framework for quantitative trading
5
5
  Project-URL: Homepage, https://github.com/yourusername/hyperquant
6
6
  Project-URL: Issues, https://github.com/yourusername/hyperquant/issues
@@ -6,18 +6,18 @@ hyperquant/logkit.py,sha256=nUo7nx5eONvK39GOhWwS41zNRL756P2J7-5xGzwXnTY,8462
6
6
  hyperquant/notikit.py,sha256=x5yAZ_tAvLQRXcRbcg-VabCaN45LUhvlTZnUqkIqfAA,3596
7
7
  hyperquant/broker/auth.py,sha256=xNZEQP0LRRV9BkT2uXBJ-vFfeahUnRVq1bjIT6YbQu8,10089
8
8
  hyperquant/broker/bitget.py,sha256=X_S0LKZ7FZAEb6oEMr1vdGP1fondzK74BhmNTpRDSEA,9488
9
- hyperquant/broker/coinw.py,sha256=XvJMWbQBAcIU5Q9LRTXqwADoGopxBuC9TqqetEVImj0,14281
9
+ hyperquant/broker/coinw.py,sha256=cGYwH-4-kWXnsDARh1rfVMhgXz_Y2nu18Vv0FWGEf1U,15857
10
10
  hyperquant/broker/edgex.py,sha256=TqUO2KRPLN_UaxvtLL6HnA9dAQXC1sGxOfqTHd6W5k8,18378
11
11
  hyperquant/broker/hyperliquid.py,sha256=7MxbI9OyIBcImDelPJu-8Nd53WXjxPB5TwE6gsjHbto,23252
12
12
  hyperquant/broker/lbank.py,sha256=98M5wmSoeHwbBYMA3rh25zqLb6fQKVaEmwqALF5nOvY,22181
13
13
  hyperquant/broker/ourbit.py,sha256=NUcDSIttf-HGWzoW1uBTrGLPHlkuemMjYCm91MigTno,18228
14
- hyperquant/broker/ws.py,sha256=Ozr5gBzVQ7cnxajT0MdpyKNyVgoCUu6LLjErU9fZxgc,4080
14
+ hyperquant/broker/ws.py,sha256=NS71Do-62mtVrGcyNE-AtHJkDecsSxdz_KU1yNBr_BQ,4079
15
15
  hyperquant/broker/lib/edgex_sign.py,sha256=lLUCmY8HHRLfLKyGrlTJYaBlSHPsIMWg3EZnQJKcmyk,95785
16
16
  hyperquant/broker/lib/hpstore.py,sha256=LnLK2zmnwVvhEbLzYI-jz_SfYpO1Dv2u2cJaRAb84D8,8296
17
17
  hyperquant/broker/lib/hyper_types.py,sha256=HqjjzjUekldjEeVn6hxiWA8nevAViC2xHADOzDz9qyw,991
18
18
  hyperquant/broker/lib/util.py,sha256=iMU1qF0CHj5zzlIMEQGwjz-qtEVosEe7slXOCuB7Rcw,566
19
19
  hyperquant/broker/models/bitget.py,sha256=0RwDY75KrJb-c-oYoMxbqxWfsILe-n_Npojz4UFUq7c,11389
20
- hyperquant/broker/models/coinw.py,sha256=r1iGdZ6K0CPY_y54cilFbj0lWzmPnb-V9aiD96zDWww,21089
20
+ hyperquant/broker/models/coinw.py,sha256=p86bzwBf-9GsRPMrtY7hWXkJphfSm7kN-_FRwEF9ZQ8,21264
21
21
  hyperquant/broker/models/edgex.py,sha256=vPAkceal44cjTYKQ_0BoNAskOpmkno_Yo1KxgMLPc6Y,33954
22
22
  hyperquant/broker/models/hyperliquid.py,sha256=c4r5739ibZfnk69RxPjQl902AVuUOwT8RNvKsMtwXBY,9459
23
23
  hyperquant/broker/models/lbank.py,sha256=vHkNKxIMzpoC_EwcZnEOPOupizF92yGWi9GKxvYYFUQ,19181
@@ -26,6 +26,6 @@ hyperquant/datavison/_util.py,sha256=92qk4vO856RqycO0YqEIHJlEg-W9XKapDVqAMxe6rbw
26
26
  hyperquant/datavison/binance.py,sha256=3yNKTqvt_vUQcxzeX4ocMsI5k6Q6gLZrvgXxAEad6Kc,5001
27
27
  hyperquant/datavison/coinglass.py,sha256=PEjdjISP9QUKD_xzXNzhJ9WFDTlkBrRQlVL-5pxD5mo,10482
28
28
  hyperquant/datavison/okx.py,sha256=yg8WrdQ7wgWHNAInIgsWPM47N3Wkfr253169IPAycAY,6898
29
- hyperquant-0.85.dist-info/METADATA,sha256=I2wU6hugR-i8hKEO4DJ1mbmdEH349ez9A0xdh8ozKcU,4317
30
- hyperquant-0.85.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
31
- hyperquant-0.85.dist-info/RECORD,,
29
+ hyperquant-0.86.dist-info/METADATA,sha256=y78vtlHcheCmgLLKNu3nkv_RYOf35Xn8qhvoWpiNI_g,4317
30
+ hyperquant-0.86.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
31
+ hyperquant-0.86.dist-info/RECORD,,