hyperquant 1.38__tar.gz → 1.41__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.
- {hyperquant-1.38 → hyperquant-1.41}/PKG-INFO +1 -1
- {hyperquant-1.38 → hyperquant-1.41}/pyproject.toml +1 -1
- {hyperquant-1.38 → hyperquant-1.41}/src/hyperquant/broker/models/polymarket.py +31 -3
- {hyperquant-1.38 → hyperquant-1.41}/src/hyperquant/broker/polymarket.py +35 -9
- {hyperquant-1.38 → hyperquant-1.41}/uv.lock +1 -1
- {hyperquant-1.38 → hyperquant-1.41}/.gitignore +0 -0
- {hyperquant-1.38 → hyperquant-1.41}/README.md +0 -0
- {hyperquant-1.38 → hyperquant-1.41}/requirements-dev.lock +0 -0
- {hyperquant-1.38 → hyperquant-1.41}/requirements.lock +0 -0
- {hyperquant-1.38 → hyperquant-1.41}/src/hyperquant/__init__.py +0 -0
- {hyperquant-1.38 → hyperquant-1.41}/src/hyperquant/broker/auth.py +0 -0
- {hyperquant-1.38 → hyperquant-1.41}/src/hyperquant/broker/bitget.py +0 -0
- {hyperquant-1.38 → hyperquant-1.41}/src/hyperquant/broker/bitmart.py +0 -0
- {hyperquant-1.38 → hyperquant-1.41}/src/hyperquant/broker/coinw.py +0 -0
- {hyperquant-1.38 → hyperquant-1.41}/src/hyperquant/broker/deepcoin.py +0 -0
- {hyperquant-1.38 → hyperquant-1.41}/src/hyperquant/broker/edgex.py +0 -0
- {hyperquant-1.38 → hyperquant-1.41}/src/hyperquant/broker/hyperliquid.py +0 -0
- {hyperquant-1.38 → hyperquant-1.41}/src/hyperquant/broker/lbank.py +0 -0
- {hyperquant-1.38 → hyperquant-1.41}/src/hyperquant/broker/lib/edgex_sign.py +0 -0
- {hyperquant-1.38 → hyperquant-1.41}/src/hyperquant/broker/lib/hpstore.py +0 -0
- {hyperquant-1.38 → hyperquant-1.41}/src/hyperquant/broker/lib/hyper_types.py +0 -0
- {hyperquant-1.38 → hyperquant-1.41}/src/hyperquant/broker/lib/util.py +0 -0
- {hyperquant-1.38 → hyperquant-1.41}/src/hyperquant/broker/lighter.py +0 -0
- {hyperquant-1.38 → hyperquant-1.41}/src/hyperquant/broker/models/apexpro.py +0 -0
- {hyperquant-1.38 → hyperquant-1.41}/src/hyperquant/broker/models/bitget.py +0 -0
- {hyperquant-1.38 → hyperquant-1.41}/src/hyperquant/broker/models/bitmart.py +0 -0
- {hyperquant-1.38 → hyperquant-1.41}/src/hyperquant/broker/models/coinw.py +0 -0
- {hyperquant-1.38 → hyperquant-1.41}/src/hyperquant/broker/models/deepcoin.py +0 -0
- {hyperquant-1.38 → hyperquant-1.41}/src/hyperquant/broker/models/edgex.py +0 -0
- {hyperquant-1.38 → hyperquant-1.41}/src/hyperquant/broker/models/hyperliquid.py +0 -0
- {hyperquant-1.38 → hyperquant-1.41}/src/hyperquant/broker/models/lbank.py +0 -0
- {hyperquant-1.38 → hyperquant-1.41}/src/hyperquant/broker/models/lighter.py +0 -0
- {hyperquant-1.38 → hyperquant-1.41}/src/hyperquant/broker/models/ourbit.py +0 -0
- {hyperquant-1.38 → hyperquant-1.41}/src/hyperquant/broker/ourbit.py +0 -0
- {hyperquant-1.38 → hyperquant-1.41}/src/hyperquant/broker/ws.py +0 -0
- {hyperquant-1.38 → hyperquant-1.41}/src/hyperquant/core.py +0 -0
- {hyperquant-1.38 → hyperquant-1.41}/src/hyperquant/datavison/_util.py +0 -0
- {hyperquant-1.38 → hyperquant-1.41}/src/hyperquant/datavison/binance.py +0 -0
- {hyperquant-1.38 → hyperquant-1.41}/src/hyperquant/datavison/coinglass.py +0 -0
- {hyperquant-1.38 → hyperquant-1.41}/src/hyperquant/datavison/okx.py +0 -0
- {hyperquant-1.38 → hyperquant-1.41}/src/hyperquant/db.py +0 -0
- {hyperquant-1.38 → hyperquant-1.41}/src/hyperquant/draw.py +0 -0
- {hyperquant-1.38 → hyperquant-1.41}/src/hyperquant/logkit.py +0 -0
- {hyperquant-1.38 → hyperquant-1.41}/src/hyperquant/notikit.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: hyperquant
|
|
3
|
-
Version: 1.
|
|
3
|
+
Version: 1.41
|
|
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
|
|
@@ -18,7 +18,9 @@ class Position(DataStore):
|
|
|
18
18
|
_KEYS = ["asset", "outcome"]
|
|
19
19
|
|
|
20
20
|
def _on_response(self, msg: Item) -> None:
|
|
21
|
-
|
|
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()
|
|
@@ -29,6 +31,7 @@ class Position(DataStore):
|
|
|
29
31
|
outcome = trade.get("outcome")
|
|
30
32
|
side = str(trade.get("side") or "").upper()
|
|
31
33
|
size_raw = trade.get("size")
|
|
34
|
+
price_raw = trade.get("price")
|
|
32
35
|
|
|
33
36
|
if not asset_id or not outcome or side not in {"BUY", "SELL"}:
|
|
34
37
|
return
|
|
@@ -37,19 +40,37 @@ class Position(DataStore):
|
|
|
37
40
|
size = float(size_raw)
|
|
38
41
|
except (TypeError, ValueError):
|
|
39
42
|
return
|
|
43
|
+
try:
|
|
44
|
+
price = float(price_raw)
|
|
45
|
+
except (TypeError, ValueError):
|
|
46
|
+
price = None
|
|
40
47
|
|
|
41
48
|
key = {"asset": asset_id, "outcome": outcome}
|
|
42
49
|
existing = self.get(key) or {}
|
|
43
50
|
|
|
44
51
|
cur_size = float(existing.get("size") or 0.0)
|
|
45
52
|
cur_total_bought = float(existing.get("totalBought") or 0.0)
|
|
53
|
+
cur_avg_price = float(existing.get("avgPrice") or 0.0)
|
|
54
|
+
cur_cost = cur_size * cur_avg_price
|
|
46
55
|
|
|
47
56
|
if side == "BUY":
|
|
48
57
|
new_size = cur_size + size
|
|
49
58
|
total_bought = cur_total_bought + size
|
|
59
|
+
# 未拿到成交价时使用当前均价兜底,避免均价被拉低
|
|
60
|
+
effective_price = price if price is not None else cur_avg_price
|
|
61
|
+
new_cost = cur_cost + size * effective_price
|
|
50
62
|
else: # SELL
|
|
51
63
|
new_size = cur_size - size
|
|
52
64
|
total_bought = cur_total_bought
|
|
65
|
+
# 卖出按照当前均价释放成本
|
|
66
|
+
new_cost = cur_cost - min(size, cur_size) * cur_avg_price
|
|
67
|
+
|
|
68
|
+
if new_size <= 0:
|
|
69
|
+
new_size = 0.0
|
|
70
|
+
avg_price = 0.0
|
|
71
|
+
new_cost = 0.0
|
|
72
|
+
else:
|
|
73
|
+
avg_price = max(new_cost, 0.0) / new_size
|
|
53
74
|
|
|
54
75
|
rec: dict[str, Any] = {
|
|
55
76
|
"asset": asset_id,
|
|
@@ -57,6 +78,7 @@ class Position(DataStore):
|
|
|
57
78
|
"side": side,
|
|
58
79
|
"size": new_size,
|
|
59
80
|
"totalBought": total_bought,
|
|
81
|
+
"avgPrice": avg_price,
|
|
60
82
|
}
|
|
61
83
|
|
|
62
84
|
if existing:
|
|
@@ -203,7 +225,7 @@ class MyTrade(DataStore):
|
|
|
203
225
|
class Trade(DataStore):
|
|
204
226
|
"""User trades keyed by trade id."""
|
|
205
227
|
|
|
206
|
-
_KEYS = ["
|
|
228
|
+
_KEYS = ["transactionHash"]
|
|
207
229
|
_MAXLEN = 500
|
|
208
230
|
|
|
209
231
|
|
|
@@ -894,7 +916,13 @@ class PolymarketDataStore(DataStoreCollection):
|
|
|
894
916
|
self.fill._on_trade(m)
|
|
895
917
|
self.position.on_trade(m)
|
|
896
918
|
elif msg_type == 'orders_matched':
|
|
897
|
-
|
|
919
|
+
payload = m.get("payload") or {}
|
|
920
|
+
if not payload:
|
|
921
|
+
continue
|
|
922
|
+
trade_msg = dict(payload)
|
|
923
|
+
if "asset_id" not in trade_msg and "asset" in trade_msg:
|
|
924
|
+
trade_msg["asset_id"] = trade_msg["asset"]
|
|
925
|
+
self.trade._on_message(trade_msg)
|
|
898
926
|
|
|
899
927
|
def onmessage_for_bbo(self, msg: Any, ws: ClientWebSocketResponse | None = None) -> None:
|
|
900
928
|
# 判定msg是否为list
|
|
@@ -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=
|
|
208
|
+
params=params,
|
|
206
209
|
host=DEFAULT_DATA_ENDPOINT
|
|
207
210
|
)
|
|
208
211
|
),
|
|
@@ -392,25 +395,27 @@ class Polymarket:
|
|
|
392
395
|
{
|
|
393
396
|
"topic": "activity",
|
|
394
397
|
"type": "orders_matched",
|
|
398
|
+
"filters": json.dumps({"event_slug": slug}, separators=(',', ':'))
|
|
395
399
|
# "filters": "{\"event_slug\":\"btc-updown-15m-1762951500\"}"
|
|
396
|
-
"filters": f'{{"event_slug":"{slug}"}}'
|
|
397
400
|
}
|
|
398
401
|
]
|
|
399
402
|
}
|
|
400
|
-
|
|
403
|
+
print(payload)
|
|
401
404
|
def callback(msg, ws):
|
|
405
|
+
if not msg:
|
|
406
|
+
return
|
|
402
407
|
try:
|
|
403
|
-
# self.store.onmessage(msg, ws)
|
|
404
408
|
data = json.loads(msg)
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
409
|
+
except json.JSONDecodeError:
|
|
410
|
+
return
|
|
411
|
+
|
|
412
|
+
self.store.onmessage(data, ws)
|
|
408
413
|
|
|
409
414
|
|
|
410
415
|
wsapp = self.client.ws_connect(
|
|
411
416
|
RTS_DATA_ENDPOINT,
|
|
412
417
|
hdlr_str=callback,
|
|
413
|
-
heartbeat=
|
|
418
|
+
heartbeat=5
|
|
414
419
|
)
|
|
415
420
|
await wsapp._event.wait()
|
|
416
421
|
await wsapp.current_ws.send_json(payload)
|
|
@@ -1171,6 +1176,27 @@ class Polymarket:
|
|
|
1171
1176
|
return await self._signed_request_via_session("DELETE", "/cancel-market-orders", body)
|
|
1172
1177
|
|
|
1173
1178
|
async def get_order(self, order_id: str) -> Any:
|
|
1179
|
+
"""
|
|
1180
|
+
{
|
|
1181
|
+
"id": "0x4c47db1458b36d535106cdb450f20a27f4ec6ba458b9a86dc4a69afb8a81215c",
|
|
1182
|
+
"status": "MATCHED",
|
|
1183
|
+
"owner": "d6dba4d1-b21d-4272-ab9a-5ef8e8bf23bb",
|
|
1184
|
+
"maker_address": "0x03C3B0236c5a01051381482E77f2210349073A1d",
|
|
1185
|
+
"market": "0x42dc093dfcdd9ba2962baab1bb5de6c7209b14ed5d3d1f7d19dec12c14cbb489",
|
|
1186
|
+
"asset_id": "16982568567216474731533472146787083736159238827774998324575366977332426392345",
|
|
1187
|
+
"side": "BUY",
|
|
1188
|
+
"original_size": "1.8518",
|
|
1189
|
+
"size_matched": "1.85185",
|
|
1190
|
+
"price": "0.54",
|
|
1191
|
+
"outcome": "Up",
|
|
1192
|
+
"expiration": "0",
|
|
1193
|
+
"order_type": "FOK",
|
|
1194
|
+
"associate_trades": [
|
|
1195
|
+
"e16c9c49-7f4e-492e-9cb0-8778e54ad38a"
|
|
1196
|
+
],
|
|
1197
|
+
"created_at": 1763701801
|
|
1198
|
+
}
|
|
1199
|
+
"""
|
|
1174
1200
|
return await self._rest("GET", f"/data/order/{order_id}")
|
|
1175
1201
|
|
|
1176
1202
|
async def get_orders(self, params: Mapping[str, Any] | None = None) -> list[Any]:
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|