hyperquant 1.39__tar.gz → 1.42__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.
Files changed (44) hide show
  1. {hyperquant-1.39 → hyperquant-1.42}/PKG-INFO +1 -1
  2. {hyperquant-1.39 → hyperquant-1.42}/pyproject.toml +1 -1
  3. {hyperquant-1.39 → hyperquant-1.42}/src/hyperquant/broker/models/polymarket.py +51 -35
  4. {hyperquant-1.39 → hyperquant-1.42}/src/hyperquant/broker/polymarket.py +45 -12
  5. {hyperquant-1.39 → hyperquant-1.42}/uv.lock +1 -1
  6. {hyperquant-1.39 → hyperquant-1.42}/.gitignore +0 -0
  7. {hyperquant-1.39 → hyperquant-1.42}/README.md +0 -0
  8. {hyperquant-1.39 → hyperquant-1.42}/requirements-dev.lock +0 -0
  9. {hyperquant-1.39 → hyperquant-1.42}/requirements.lock +0 -0
  10. {hyperquant-1.39 → hyperquant-1.42}/src/hyperquant/__init__.py +0 -0
  11. {hyperquant-1.39 → hyperquant-1.42}/src/hyperquant/broker/auth.py +0 -0
  12. {hyperquant-1.39 → hyperquant-1.42}/src/hyperquant/broker/bitget.py +0 -0
  13. {hyperquant-1.39 → hyperquant-1.42}/src/hyperquant/broker/bitmart.py +0 -0
  14. {hyperquant-1.39 → hyperquant-1.42}/src/hyperquant/broker/coinw.py +0 -0
  15. {hyperquant-1.39 → hyperquant-1.42}/src/hyperquant/broker/deepcoin.py +0 -0
  16. {hyperquant-1.39 → hyperquant-1.42}/src/hyperquant/broker/edgex.py +0 -0
  17. {hyperquant-1.39 → hyperquant-1.42}/src/hyperquant/broker/hyperliquid.py +0 -0
  18. {hyperquant-1.39 → hyperquant-1.42}/src/hyperquant/broker/lbank.py +0 -0
  19. {hyperquant-1.39 → hyperquant-1.42}/src/hyperquant/broker/lib/edgex_sign.py +0 -0
  20. {hyperquant-1.39 → hyperquant-1.42}/src/hyperquant/broker/lib/hpstore.py +0 -0
  21. {hyperquant-1.39 → hyperquant-1.42}/src/hyperquant/broker/lib/hyper_types.py +0 -0
  22. {hyperquant-1.39 → hyperquant-1.42}/src/hyperquant/broker/lib/util.py +0 -0
  23. {hyperquant-1.39 → hyperquant-1.42}/src/hyperquant/broker/lighter.py +0 -0
  24. {hyperquant-1.39 → hyperquant-1.42}/src/hyperquant/broker/models/apexpro.py +0 -0
  25. {hyperquant-1.39 → hyperquant-1.42}/src/hyperquant/broker/models/bitget.py +0 -0
  26. {hyperquant-1.39 → hyperquant-1.42}/src/hyperquant/broker/models/bitmart.py +0 -0
  27. {hyperquant-1.39 → hyperquant-1.42}/src/hyperquant/broker/models/coinw.py +0 -0
  28. {hyperquant-1.39 → hyperquant-1.42}/src/hyperquant/broker/models/deepcoin.py +0 -0
  29. {hyperquant-1.39 → hyperquant-1.42}/src/hyperquant/broker/models/edgex.py +0 -0
  30. {hyperquant-1.39 → hyperquant-1.42}/src/hyperquant/broker/models/hyperliquid.py +0 -0
  31. {hyperquant-1.39 → hyperquant-1.42}/src/hyperquant/broker/models/lbank.py +0 -0
  32. {hyperquant-1.39 → hyperquant-1.42}/src/hyperquant/broker/models/lighter.py +0 -0
  33. {hyperquant-1.39 → hyperquant-1.42}/src/hyperquant/broker/models/ourbit.py +0 -0
  34. {hyperquant-1.39 → hyperquant-1.42}/src/hyperquant/broker/ourbit.py +0 -0
  35. {hyperquant-1.39 → hyperquant-1.42}/src/hyperquant/broker/ws.py +0 -0
  36. {hyperquant-1.39 → hyperquant-1.42}/src/hyperquant/core.py +0 -0
  37. {hyperquant-1.39 → hyperquant-1.42}/src/hyperquant/datavison/_util.py +0 -0
  38. {hyperquant-1.39 → hyperquant-1.42}/src/hyperquant/datavison/binance.py +0 -0
  39. {hyperquant-1.39 → hyperquant-1.42}/src/hyperquant/datavison/coinglass.py +0 -0
  40. {hyperquant-1.39 → hyperquant-1.42}/src/hyperquant/datavison/okx.py +0 -0
  41. {hyperquant-1.39 → hyperquant-1.42}/src/hyperquant/db.py +0 -0
  42. {hyperquant-1.39 → hyperquant-1.42}/src/hyperquant/draw.py +0 -0
  43. {hyperquant-1.39 → hyperquant-1.42}/src/hyperquant/logkit.py +0 -0
  44. {hyperquant-1.39 → hyperquant-1.42}/src/hyperquant/notikit.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: hyperquant
3
- Version: 1.39
3
+ Version: 1.42
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
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "hyperquant"
3
- version = "1.39"
3
+ version = "1.42"
4
4
  description = "A minimal yet hyper-efficient backtesting framework for quantitative trading"
5
5
  authors = [
6
6
  { name = "MissinA", email = "1421329142@qq.com" }
@@ -18,7 +18,9 @@ class Position(DataStore):
18
18
  _KEYS = ["asset", "outcome"]
19
19
 
20
20
  def _on_response(self, msg: Item) -> None:
21
- self._update(msg)
21
+ if msg:
22
+ self._clear()
23
+ self._update(msg)
22
24
 
23
25
  def on_trade(self, trade: Item) -> None:
24
26
  status = str(trade.get("status") or "").upper()
@@ -223,17 +225,22 @@ class MyTrade(DataStore):
223
225
  class Trade(DataStore):
224
226
  """User trades keyed by trade id."""
225
227
 
226
- _KEYS = ["asset_id"]
228
+ _KEYS = ["hash"]
227
229
  _MAXLEN = 500
228
230
 
229
-
230
231
  def _on_message(self, msg: dict[str, Any]) -> None:
231
232
  payload = msg or {}
232
233
  if payload:
233
- size = float(payload.get("size"))
234
- price = float(payload.get("price"))
235
- # share = size / price
236
- # payload['shares'] = share
234
+ if payload.get("event_type") == "last_trade_price":
235
+ transaction_hash = payload.get("transaction_hash")
236
+ if transaction_hash:
237
+ payload.update({"hash": transaction_hash})
238
+ payload.pop("transaction_hash", None)
239
+ else:
240
+ if payload.get("transactionHash"):
241
+ payload.update({"hash": payload.get("transactionHash")})
242
+ payload.pop("transactionHash", None)
243
+
237
244
  self._insert([payload])
238
245
 
239
246
  class Book(DataStore):
@@ -859,33 +866,25 @@ class PolymarketDataStore(DataStoreCollection):
859
866
  _key asset
860
867
  MATCHED进行快速捕捉
861
868
  .. code:: json
862
- {
863
- "asset_id": "52114319501245915516055106046884209969926127482827954674443846427813813222426",
864
- "event_type": "trade",
865
- "id": "28c4d2eb-bbea-40e7-a9f0-b2fdb56b2c2e",
866
- "last_update": "1672290701",
867
- "maker_orders": [
868
- {
869
- "asset_id": "52114319501245915516055106046884209969926127482827954674443846427813813222426",
870
- "matched_amount": "10",
871
- "order_id": "0xff354cd7ca7539dfa9c28d90943ab5779a4eac34b9b37a757d7b32bdfb11790b",
872
- "outcome": "YES",
873
- "owner": "9180014b-33c8-9240-a14b-bdca11c0a465",
874
- "price": "0.57"
875
- }
876
- ],
877
- "market": "0xbd31dc8a20211944f6b70f31557f1001557b59905b7738480ca09bd4532f84af",
878
- "matchtime": "1672290701",
879
- "outcome": "YES",
880
- "owner": "9180014b-33c8-9240-a14b-bdca11c0a465",
881
- "price": "0.57",
869
+ {
870
+ "asset": "12819879685513143002408869746992985182419696851931617234615358342350852997413",
871
+ "bio": "",
872
+ "conditionId": "0xea609d2c6bc2cb20e328be7c89f258b84b35bbe119b44e0a2cfc5f15e6642b3b",
873
+ "eventSlug": "btc-updown-15m-1763865000",
874
+ "icon": "https://polymarket-upload.s3.us-east-2.amazonaws.com/BTC+fullsize.png",
875
+ "name": "infusion",
876
+ "outcome": "Up",
877
+ "outcomeIndex": 0,
878
+ "price": 0.7,
879
+ "profileImage": "",
880
+ "proxyWallet": "0x2C060830B6F6B43174b1Cf8B4475db07703c1543",
881
+ "pseudonym": "Frizzy-Graduate",
882
882
  "side": "BUY",
883
- "size": "10",
884
- "status": "MATCHED",
885
- "taker_order_id": "0x06bc63e346ed4ceddce9efd6b3af37c8f8f440c92fe7da6b2d0f9e4ccbc50c42",
886
- "timestamp": "1672290701",
887
- "trade_owner": "9180014b-33c8-9240-a14b-bdca11c0a465",
888
- "type": "TRADE"
883
+ "size": 5,
884
+ "slug": "btc-updown-15m-1763865000",
885
+ "timestamp": 1763865085,
886
+ "title": "Bitcoin Up or Down - November 22, 9:30PM-9:45PM ET",
887
+ "hash": "0xddea11d695e811686f83379d9269accf1be581fbcb542809c6c67a3cc3002488"
889
888
  }
890
889
  """
891
890
  return self._get("trade")
@@ -910,11 +909,17 @@ class PolymarketDataStore(DataStoreCollection):
910
909
  elif msg_type == "order":
911
910
  self.orders._on_message(m)
912
911
  elif msg_type == "trade":
913
- self.trade._on_message(m)
912
+ self.mytrade._on_message(m)
914
913
  self.fill._on_trade(m)
915
914
  self.position.on_trade(m)
916
915
  elif msg_type == 'orders_matched':
917
- self.trade._on_message(m)
916
+ payload = m.get("payload") or {}
917
+ if not payload:
918
+ continue
919
+ trade_msg = dict(payload)
920
+ if "asset_id" not in trade_msg and "asset" in trade_msg:
921
+ trade_msg["asset_id"] = trade_msg["asset"]
922
+ self.trade._on_message(trade_msg)
918
923
 
919
924
  def onmessage_for_bbo(self, msg: Any, ws: ClientWebSocketResponse | None = None) -> None:
920
925
  # 判定msg是否为list
@@ -926,3 +931,14 @@ class PolymarketDataStore(DataStoreCollection):
926
931
  msg_type = str(raw_type).lower()
927
932
  if msg_type in {"book", "price_change"}:
928
933
  self.bbo._on_message(m)
934
+
935
+ def onmessage_for_last_trade(self, msg, ws = None):
936
+ # 判定msg是否为list
937
+ lst_msg = msg if isinstance(msg, list) else [msg]
938
+ for m in lst_msg:
939
+ raw_type = m.get("event_type") or m.get("type")
940
+ if not raw_type:
941
+ continue
942
+ msg_type = str(raw_type).lower()
943
+ if msg_type == "last_trade_price":
944
+ self.trade._on_message(m)
@@ -156,7 +156,7 @@ class Polymarket:
156
156
  token_ids: Sequence[str] | str | None = None,
157
157
  limit: int | None = None,
158
158
  funder: str | None = None,
159
-
159
+ event_id: str | None = None
160
160
  ) -> None:
161
161
  """Refresh cached data using Polymarket REST endpoints."""
162
162
 
@@ -195,6 +195,9 @@ class Polymarket:
195
195
  if include_position or include_history_position:
196
196
  funder = funder or self.funder
197
197
  path = '/positions' if include_position else '/closed-positions'
198
+ params = {"user": funder, 'sizeThreshold': 0.1}
199
+ if event_id:
200
+ params.update({'eventId': event_id})
198
201
  tasks.append(
199
202
  (
200
203
  "position",
@@ -202,7 +205,7 @@ class Polymarket:
202
205
  self._rest(
203
206
  "GET",
204
207
  path,
205
- params={"user": funder},
208
+ params=params,
206
209
  host=DEFAULT_DATA_ENDPOINT
207
210
  )
208
211
  ),
@@ -330,6 +333,7 @@ class Polymarket:
330
333
  token_ids: Sequence[str] | str,
331
334
  wsapp: pybotters.ws.WebSocketApp | None = None,
332
335
  only_bbo: bool = False,
336
+ with_trades: bool = False
333
337
  ) -> pybotters.ws.WebSocketApp:
334
338
  """Subscribe to public order-book updates for the provided token ids."""
335
339
 
@@ -338,11 +342,14 @@ class Polymarket:
338
342
  if wsapp:
339
343
  await wsapp.current_ws.send_json(payload)
340
344
  hdrl_json = self.store.onmessage_for_bbo if only_bbo else self.store.onmessage
345
+ hd_lst = [hdrl_json]
346
+ if with_trades:
347
+ hd_lst.append(self.store.onmessage_for_last_trade)
341
348
 
342
349
  self._ws_public = self.client.ws_connect(
343
350
  self.ws_public,
344
351
  send_json=payload,
345
- hdlr_json=hdrl_json,
352
+ hdlr_json=hd_lst
346
353
  )
347
354
  await self._ws_public._event.wait()
348
355
  return self._ws_public
@@ -385,37 +392,42 @@ class Polymarket:
385
392
  return self._ws_personal
386
393
 
387
394
  async def sub_trades(self, slug: str):
388
-
395
+ """订阅activate trades"""
389
396
  payload = {
390
397
  "action": "subscribe",
391
398
  "subscriptions": [
392
399
  {
393
400
  "topic": "activity",
394
401
  "type": "orders_matched",
402
+ "filters": json.dumps({"event_slug": slug}, separators=(',', ':'))
395
403
  # "filters": "{\"event_slug\":\"btc-updown-15m-1762951500\"}"
396
- "filters": f'{{"event_slug":"{slug}"}}'
397
404
  }
398
405
  ]
399
406
  }
400
-
407
+ print(payload)
401
408
  def callback(msg, ws):
409
+ if not msg:
410
+ return
402
411
  try:
403
- # self.store.onmessage(msg, ws)
404
412
  data = json.loads(msg)
405
- self.store.onmessage(data, ws)
406
- except Exception:
407
- pass
413
+ except json.JSONDecodeError:
414
+ return
415
+
416
+ self.store.onmessage(data, ws)
408
417
 
409
418
 
410
419
  wsapp = self.client.ws_connect(
411
420
  RTS_DATA_ENDPOINT,
412
421
  hdlr_str=callback,
413
- heartbeat=30
422
+ heartbeat=5
414
423
  )
415
424
  await wsapp._event.wait()
416
425
  await wsapp.current_ws.send_json(payload)
417
426
  return wsapp
418
-
427
+
428
+
429
+
430
+
419
431
  # ------------------------------------------------------------------
420
432
  # Public REST endpoints
421
433
 
@@ -1171,6 +1183,27 @@ class Polymarket:
1171
1183
  return await self._signed_request_via_session("DELETE", "/cancel-market-orders", body)
1172
1184
 
1173
1185
  async def get_order(self, order_id: str) -> Any:
1186
+ """
1187
+ {
1188
+ "id": "0x4c47db1458b36d535106cdb450f20a27f4ec6ba458b9a86dc4a69afb8a81215c",
1189
+ "status": "MATCHED",
1190
+ "owner": "d6dba4d1-b21d-4272-ab9a-5ef8e8bf23bb",
1191
+ "maker_address": "0x03C3B0236c5a01051381482E77f2210349073A1d",
1192
+ "market": "0x42dc093dfcdd9ba2962baab1bb5de6c7209b14ed5d3d1f7d19dec12c14cbb489",
1193
+ "asset_id": "16982568567216474731533472146787083736159238827774998324575366977332426392345",
1194
+ "side": "BUY",
1195
+ "original_size": "1.8518",
1196
+ "size_matched": "1.85185",
1197
+ "price": "0.54",
1198
+ "outcome": "Up",
1199
+ "expiration": "0",
1200
+ "order_type": "FOK",
1201
+ "associate_trades": [
1202
+ "e16c9c49-7f4e-492e-9cb0-8778e54ad38a"
1203
+ ],
1204
+ "created_at": 1763701801
1205
+ }
1206
+ """
1174
1207
  return await self._rest("GET", f"/data/order/{order_id}")
1175
1208
 
1176
1209
  async def get_orders(self, params: Mapping[str, Any] | None = None) -> list[Any]:
@@ -945,7 +945,7 @@ wheels = [
945
945
 
946
946
  [[package]]
947
947
  name = "hyperquant"
948
- version = "1.38"
948
+ version = "1.41"
949
949
  source = { editable = "." }
950
950
  dependencies = [
951
951
  { name = "aiohttp" },
File without changes
File without changes
File without changes