hyperquant 1.57__tar.gz → 1.58__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 (46) hide show
  1. {hyperquant-1.57 → hyperquant-1.58}/PKG-INFO +1 -1
  2. {hyperquant-1.57 → hyperquant-1.58}/pyproject.toml +1 -1
  3. {hyperquant-1.57 → hyperquant-1.58}/src/hyperquant/broker/polymarket.py +141 -4
  4. {hyperquant-1.57 → hyperquant-1.58}/uv.lock +1 -1
  5. {hyperquant-1.57 → hyperquant-1.58}/.gitignore +0 -0
  6. {hyperquant-1.57 → hyperquant-1.58}/README.md +0 -0
  7. {hyperquant-1.57 → hyperquant-1.58}/requirements-dev.lock +0 -0
  8. {hyperquant-1.57 → hyperquant-1.58}/requirements.lock +0 -0
  9. {hyperquant-1.57 → hyperquant-1.58}/src/hyperquant/__init__.py +0 -0
  10. {hyperquant-1.57 → hyperquant-1.58}/src/hyperquant/broker/auth.py +0 -0
  11. {hyperquant-1.57 → hyperquant-1.58}/src/hyperquant/broker/bitget.py +0 -0
  12. {hyperquant-1.57 → hyperquant-1.58}/src/hyperquant/broker/bitmart.py +0 -0
  13. {hyperquant-1.57 → hyperquant-1.58}/src/hyperquant/broker/coinw.py +0 -0
  14. {hyperquant-1.57 → hyperquant-1.58}/src/hyperquant/broker/deepcoin.py +0 -0
  15. {hyperquant-1.57 → hyperquant-1.58}/src/hyperquant/broker/edgex.py +0 -0
  16. {hyperquant-1.57 → hyperquant-1.58}/src/hyperquant/broker/hyperliquid.py +0 -0
  17. {hyperquant-1.57 → hyperquant-1.58}/src/hyperquant/broker/lbank.py +0 -0
  18. {hyperquant-1.57 → hyperquant-1.58}/src/hyperquant/broker/lib/edgex_sign.py +0 -0
  19. {hyperquant-1.57 → hyperquant-1.58}/src/hyperquant/broker/lib/hpstore.py +0 -0
  20. {hyperquant-1.57 → hyperquant-1.58}/src/hyperquant/broker/lib/hyper_types.py +0 -0
  21. {hyperquant-1.57 → hyperquant-1.58}/src/hyperquant/broker/lib/polymarket/ctfAbi.py +0 -0
  22. {hyperquant-1.57 → hyperquant-1.58}/src/hyperquant/broker/lib/polymarket/safeAbi.py +0 -0
  23. {hyperquant-1.57 → hyperquant-1.58}/src/hyperquant/broker/lib/util.py +0 -0
  24. {hyperquant-1.57 → hyperquant-1.58}/src/hyperquant/broker/lighter.py +0 -0
  25. {hyperquant-1.57 → hyperquant-1.58}/src/hyperquant/broker/models/apexpro.py +0 -0
  26. {hyperquant-1.57 → hyperquant-1.58}/src/hyperquant/broker/models/bitget.py +0 -0
  27. {hyperquant-1.57 → hyperquant-1.58}/src/hyperquant/broker/models/bitmart.py +0 -0
  28. {hyperquant-1.57 → hyperquant-1.58}/src/hyperquant/broker/models/coinw.py +0 -0
  29. {hyperquant-1.57 → hyperquant-1.58}/src/hyperquant/broker/models/deepcoin.py +0 -0
  30. {hyperquant-1.57 → hyperquant-1.58}/src/hyperquant/broker/models/edgex.py +0 -0
  31. {hyperquant-1.57 → hyperquant-1.58}/src/hyperquant/broker/models/hyperliquid.py +0 -0
  32. {hyperquant-1.57 → hyperquant-1.58}/src/hyperquant/broker/models/lbank.py +0 -0
  33. {hyperquant-1.57 → hyperquant-1.58}/src/hyperquant/broker/models/lighter.py +0 -0
  34. {hyperquant-1.57 → hyperquant-1.58}/src/hyperquant/broker/models/ourbit.py +0 -0
  35. {hyperquant-1.57 → hyperquant-1.58}/src/hyperquant/broker/models/polymarket.py +0 -0
  36. {hyperquant-1.57 → hyperquant-1.58}/src/hyperquant/broker/ourbit.py +0 -0
  37. {hyperquant-1.57 → hyperquant-1.58}/src/hyperquant/broker/ws.py +0 -0
  38. {hyperquant-1.57 → hyperquant-1.58}/src/hyperquant/core.py +0 -0
  39. {hyperquant-1.57 → hyperquant-1.58}/src/hyperquant/datavison/_util.py +0 -0
  40. {hyperquant-1.57 → hyperquant-1.58}/src/hyperquant/datavison/binance.py +0 -0
  41. {hyperquant-1.57 → hyperquant-1.58}/src/hyperquant/datavison/coinglass.py +0 -0
  42. {hyperquant-1.57 → hyperquant-1.58}/src/hyperquant/datavison/okx.py +0 -0
  43. {hyperquant-1.57 → hyperquant-1.58}/src/hyperquant/db.py +0 -0
  44. {hyperquant-1.57 → hyperquant-1.58}/src/hyperquant/draw.py +0 -0
  45. {hyperquant-1.57 → hyperquant-1.58}/src/hyperquant/logkit.py +0 -0
  46. {hyperquant-1.57 → hyperquant-1.58}/src/hyperquant/notikit.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: hyperquant
3
- Version: 1.57
3
+ Version: 1.58
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.57"
3
+ version = "1.58"
4
4
  description = "A minimal yet hyper-efficient backtesting framework for quantitative trading"
5
5
  authors = [
6
6
  { name = "MissinA", email = "1421329142@qq.com" }
@@ -8,7 +8,7 @@ from functools import lru_cache
8
8
  import os
9
9
  import time
10
10
  from typing import Any, Awaitable, Callable, Iterable, Iterator, Literal, Mapping, Sequence
11
- from urllib.parse import urlsplit, urlunsplit
11
+ from urllib.parse import urlencode, urlsplit, urlunsplit
12
12
 
13
13
  import json
14
14
 
@@ -232,7 +232,8 @@ class Polymarket:
232
232
  private_key: str | None = None,
233
233
  chain_id: int | None = None,
234
234
  signature_type: int | None = None,
235
- funder: str | None = None
235
+ funder: str | None = None,
236
+ forward_url: str | None = None, # geoblock转发
236
237
  ) -> None:
237
238
  # Logger (per-class, safe default)
238
239
  self.logger = logging.getLogger(f"{API_NAME}.{self.__class__.__name__}")
@@ -247,6 +248,7 @@ class Polymarket:
247
248
  self.client = client
248
249
  self.rest_api = (rest_api or DEFAULT_REST_ENDPOINT).rstrip("/")
249
250
  self.ws_public = ws_public or DEFAULT_WS_ENDPOINT
251
+ self.forward_url = forward_url
250
252
 
251
253
  self.chain_id = chain_id or 137
252
254
  # Default to POLY_GNOSIS_SAFE (2) to match common proxy flows used in examples/tests.
@@ -802,13 +804,19 @@ class Polymarket:
802
804
 
803
805
  async def create_api_key(self, nonce: int | None = None) -> dict[str, Any]:
804
806
  params = {"nonce": nonce} if nonce is not None else None
805
- data = await self._rest("POST", "/auth/api-key", params=params)
807
+ if self.forward_url:
808
+ data = await self._forward_l1_auth_request("POST", "/auth/api-key", params=params)
809
+ else:
810
+ data = await self._rest("POST", "/auth/api-key", params=params)
806
811
  self._store_api_creds(data)
807
812
  return data
808
813
 
809
814
  async def derive_api_key(self, nonce: int | None = None) -> dict[str, Any]:
810
815
  params = {"nonce": nonce} if nonce is not None else None
811
- data = await self._rest("GET", "/auth/derive-api-key", params=params)
816
+ if self.forward_url:
817
+ data = await self._forward_l1_auth_request("GET", "/auth/derive-api-key", params=params)
818
+ else:
819
+ data = await self._rest("GET", "/auth/derive-api-key", params=params)
812
820
  self._store_api_creds(data)
813
821
  return data
814
822
 
@@ -1506,6 +1514,135 @@ class Polymarket:
1506
1514
  "Content-Type": "application/json",
1507
1515
  }
1508
1516
 
1517
+ def _build_l1_signed_headers(self, *, nonce: int = 0) -> dict[str, str]:
1518
+ from eth_account import Account as _A
1519
+ try:
1520
+ from eth_account.messages import encode_typed_data as _enc
1521
+ except ImportError:
1522
+ from eth_account.messages import encode_structured_data as _enc
1523
+
1524
+ private_key, _, signer_addr = self._get_signing_context()
1525
+ timestamp = int(time.time())
1526
+ typed_data = {
1527
+ "types": {
1528
+ "EIP712Domain": [
1529
+ {"name": "name", "type": "string"},
1530
+ {"name": "version", "type": "string"},
1531
+ {"name": "chainId", "type": "uint256"},
1532
+ ],
1533
+ "ClobAuth": [
1534
+ {"name": "address", "type": "address"},
1535
+ {"name": "timestamp", "type": "string"},
1536
+ {"name": "nonce", "type": "uint256"},
1537
+ {"name": "message", "type": "string"},
1538
+ ],
1539
+ },
1540
+ "domain": {
1541
+ "name": "ClobAuthDomain",
1542
+ "version": "1",
1543
+ "chainId": int(self.chain_id),
1544
+ },
1545
+ "primaryType": "ClobAuth",
1546
+ "message": {
1547
+ "address": signer_addr,
1548
+ "timestamp": str(timestamp),
1549
+ "nonce": int(nonce),
1550
+ "message": "This message attests that I control the given wallet",
1551
+ },
1552
+ }
1553
+ encoded = _enc(full_message=typed_data)
1554
+ signature = _A.sign_message(encoded, private_key).signature.hex()
1555
+ if not signature.startswith("0x"):
1556
+ signature = f"0x{signature}"
1557
+ return {
1558
+ "POLY_ADDRESS": signer_addr,
1559
+ "POLY_SIGNATURE": signature,
1560
+ "POLY_TIMESTAMP": str(timestamp),
1561
+ "POLY_NONCE": str(int(nonce)),
1562
+ "Content-Type": "application/json",
1563
+ }
1564
+
1565
+ async def _forward_l1_auth_request(
1566
+ self,
1567
+ method: str,
1568
+ path: str,
1569
+ *,
1570
+ params: Mapping[str, Any] | None = None,
1571
+ ) -> dict[str, Any]:
1572
+ session: aiohttp.ClientSession = getattr(self.client, "_session", None)
1573
+ if session is None:
1574
+ raise RuntimeError("pybotters client session missing")
1575
+ if not self.forward_url:
1576
+ raise RuntimeError("forward_url is required for forward auth request")
1577
+
1578
+ nonce = 0
1579
+ if params and "nonce" in params:
1580
+ try:
1581
+ nonce = int(params["nonce"])
1582
+ except (TypeError, ValueError):
1583
+ nonce = 0
1584
+
1585
+ query = urlencode(dict(params), doseq=True) if params else ""
1586
+ url = f"{self.rest_api.rstrip('/')}{path}"
1587
+ if query:
1588
+ url = f"{url}?{query}"
1589
+ req = {
1590
+ "method": method.upper(),
1591
+ "url": url,
1592
+ "headers": self._build_l1_signed_headers(nonce=nonce),
1593
+ "body": None,
1594
+ }
1595
+
1596
+ endpoint = self._normalize_forward_batch_url(self.forward_url)
1597
+ async with session.post(endpoint, json={"requests": [req]}) as resp:
1598
+ if resp.status >= 400:
1599
+ text = await resp.text()
1600
+ raise RuntimeError(f"Forward auth request failed: {resp.status} {text}")
1601
+ payload = await resp.json(content_type=None)
1602
+
1603
+ first: Any
1604
+ if isinstance(payload, list):
1605
+ first = payload[0] if payload else {}
1606
+ elif isinstance(payload, dict):
1607
+ for key in ("responses", "results", "data"):
1608
+ value = payload.get(key)
1609
+ if isinstance(value, list):
1610
+ first = value[0] if value else {}
1611
+ break
1612
+ else:
1613
+ first = payload
1614
+ else:
1615
+ raise RuntimeError(f"Unexpected forward response: {payload!r}")
1616
+
1617
+ def _parse_maybe_json(data: Any) -> Any:
1618
+ if isinstance(data, str):
1619
+ text = data.strip()
1620
+ try:
1621
+ return json.loads(text)
1622
+ except Exception:
1623
+ return text
1624
+ return data
1625
+
1626
+ if isinstance(first, dict):
1627
+ # worker forwarder shape: { ok, status, bodyPreview }
1628
+ if first.get("ok") is False or int(first.get("status", 200)) >= 400:
1629
+ detail = _parse_maybe_json(first.get("bodyPreview") or first.get("body") or first)
1630
+ raise RuntimeError(
1631
+ f"Forward upstream auth failed: status={first.get('status')} detail={detail!r}"
1632
+ )
1633
+
1634
+ body = _parse_maybe_json(first.get("body"))
1635
+ if isinstance(body, dict):
1636
+ return body
1637
+
1638
+ preview = _parse_maybe_json(first.get("bodyPreview"))
1639
+ if isinstance(preview, dict):
1640
+ return preview
1641
+
1642
+ if all(k in first for k in ("apiKey", "secret", "passphrase")):
1643
+ return first
1644
+ raise RuntimeError(f"Forward response missing auth body: {payload!r}")
1645
+
1509
1646
  async def _submit_forward_requests(self, requests_payload: Sequence[Mapping[str, Any]]) -> Any:
1510
1647
  cfg = self._forward_orders_cfg
1511
1648
  if not cfg:
@@ -694,7 +694,7 @@ wheels = [
694
694
 
695
695
  [[package]]
696
696
  name = "hyperquant"
697
- version = "1.56"
697
+ version = "1.57"
698
698
  source = { editable = "." }
699
699
  dependencies = [
700
700
  { name = "aiohttp" },
File without changes
File without changes
File without changes