hyperquant 0.72__py3-none-any.whl → 0.74__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.
@@ -206,7 +206,7 @@ class Bitget:
206
206
  submsg = {"op": "subscribe", "args": []}
207
207
  for symbol in symbols:
208
208
  submsg["args"].append(
209
- {"instType": "SPOT", "channel": channel, "instId": symbol}
209
+ {"instType": "USDT-FUTURES", "channel": channel, "instId": symbol}
210
210
  )
211
211
 
212
212
  self.client.ws_connect(
@@ -136,6 +136,138 @@ class Lbank:
136
136
 
137
137
  await self.store.initialize(*requests)
138
138
 
139
+ async def query_trade(
140
+ self,
141
+ order_id: str | None = None,
142
+ *,
143
+ product_group: str = "SwapU",
144
+ page_index: int = 1,
145
+ page_size: int = 20,
146
+ ) -> list[dict[str, Any]]:
147
+ """Fetch trade executions linked to a given OrderSysID.
148
+
149
+ Example response payload::
150
+
151
+ [
152
+ {
153
+ "TradeUnitID": "e1b03fb1-6849-464f-a",
154
+ "ProductGroup": "SwapU",
155
+ "CloseProfit": 0,
156
+ "BusinessNo": 1001770339345505,
157
+ "TradeID": "1000162046503720",
158
+ "PositionID": "1000632926272299",
159
+ "DeriveSource": "0",
160
+ "OrderID": "",
161
+ "Direction": "0",
162
+ "InstrumentID": "SOLUSDT",
163
+ "OffsetFlag": "0",
164
+ "Remark": "def",
165
+ "DdlnTime": "0",
166
+ "UseMargin": 0.054213,
167
+ "Currency": "USDT",
168
+ "Turnover": 5.4213,
169
+ "SettlementGroup": "SwapU",
170
+ "Leverage": 100,
171
+ "OrderSysID": "1000632948114584",
172
+ "ExchangeID": "Exchange",
173
+ "AccountID": "e1b03fb1-6849-464f-a986-94b9a6e625e6",
174
+ "TradeTime": 1760161085,
175
+ "Fee": 0.00325278,
176
+ "OrderPrice": 180.89,
177
+ "InsertTime": 1760161085,
178
+ "MemberID": "e1b03fb1-6849-464f-a986-94b9a6e625e6",
179
+ "MatchRole": "1",
180
+ "ClearCurrency": "USDT",
181
+ "Price": 180.71,
182
+ "Volume": 0.03,
183
+ "OpenPrice": 182.94,
184
+ "MasterAccountID": "",
185
+ "PriceCurrency": "USDT",
186
+ "FeeCurrency": "USDT"
187
+ }
188
+ ]
189
+ """
190
+
191
+ if not order_id:
192
+ raise ValueError("order_id is required to query order executions")
193
+
194
+ params = {
195
+ "ProductGroup": product_group,
196
+ "OrderSysID": order_id,
197
+ "pageIndex": page_index,
198
+ "pageSize": page_size,
199
+ }
200
+
201
+ res = await self.client.get(
202
+ f"{self.front_api}/cfd/query/v1.0/Trade",
203
+ params=params,
204
+ headers=self._rest_headers,
205
+ )
206
+ data = await res.json()
207
+ payload = self._ensure_ok("query_trade", data)
208
+
209
+ if isinstance(payload, dict):
210
+ rows = payload.get("data")
211
+ if isinstance(rows, list):
212
+ return rows
213
+ elif isinstance(payload, list): # pragma: no cover - defensive fallback
214
+ return payload
215
+
216
+ return []
217
+
218
+ async def query_order(
219
+ self,
220
+ order_id: str | None = None,
221
+ *,
222
+ product_group: str = "SwapU",
223
+ page_index: int = 1,
224
+ page_size: int = 20,
225
+ ) -> dict[str, Any]:
226
+ """Aggregate trade executions to summarize overall order statistics."""
227
+
228
+ if not order_id:
229
+ raise ValueError("order_id is required to query order statistics")
230
+
231
+ trades = await self.query_trade(
232
+ order_id,
233
+ product_group=product_group,
234
+ page_index=page_index,
235
+ page_size=page_size,
236
+ )
237
+
238
+ if not trades:
239
+ return {
240
+ "order_id": order_id,
241
+ "trade_count": 0,
242
+ }
243
+
244
+ def _to_float(value: Any) -> float:
245
+ try:
246
+ return float(value)
247
+ except (TypeError, ValueError):
248
+ return 0.0
249
+
250
+ total_volume = sum(_to_float(trade.get("Volume")) for trade in trades)
251
+ total_turnover = sum(_to_float(trade.get("Turnover")) for trade in trades)
252
+ total_fee = sum(_to_float(trade.get("Fee")) for trade in trades)
253
+
254
+ avg_price = total_turnover / total_volume if total_volume else None
255
+ last_trade = trades[-1]
256
+
257
+ return {
258
+ "order_id": order_id,
259
+ "instrument_id": last_trade.get("InstrumentID"),
260
+ "position_id": last_trade.get("PositionID"),
261
+ "direction": last_trade.get("Direction"),
262
+ "offset_flag": last_trade.get("OffsetFlag"),
263
+ "trade_time": last_trade.get("TradeTime"),
264
+ "avg_price": avg_price,
265
+ "volume": total_volume,
266
+ "turnover": total_turnover,
267
+ "fee": total_fee,
268
+ "trade_count": len(trades),
269
+ }
270
+
139
271
  def _resolve_instrument(self) -> str | None:
140
272
  detail_entries = self.store.detail.find()
141
273
  if detail_entries:
@@ -212,7 +344,71 @@ class Lbank:
212
344
  order_proportion: str = "0.0000",
213
345
  client_order_id: str | None = None,
214
346
  ) -> dict[str, Any]:
215
- """Create an order using documented REST parameters."""
347
+ """Create an order using documented REST parameters.
348
+
349
+ 返回示例:
350
+
351
+ .. code:: json
352
+
353
+ {
354
+ "offsetFlag": "5",
355
+ "orderType": "1",
356
+ "reserveMode": "0",
357
+ "fee": "0.0066042",
358
+ "frozenFee": "0",
359
+ "ddlnTime": "0",
360
+ "userID": "lbank_exchange_user",
361
+ "masterAccountID": "",
362
+ "exchangeID": "Exchange",
363
+ "accountID": "e1b03fb1-6849-464f-a986-94b9a6e625e6",
364
+ "orderSysID": "1000633129818889",
365
+ "volumeRemain": "0",
366
+ "price": "183.36",
367
+ "businessValue": "1760183423813",
368
+ "frozenMargin": "0",
369
+ "instrumentID": "SOLUSDT",
370
+ "posiDirection": "2",
371
+ "volumeMode": "1",
372
+ "volume": "0.06",
373
+ "insertTime": "1760183423",
374
+ "copyMemberID": "",
375
+ "position": "0.06",
376
+ "tradePrice": "183.45",
377
+ "leverage": "100",
378
+ "businessResult": "",
379
+ "availableUse": "0",
380
+ "orderStatus": "1",
381
+ "openPrice": "182.94",
382
+ "frozenMoney": "0",
383
+ "remark": "def",
384
+ "reserveUse": "0",
385
+ "sessionNo": "41",
386
+ "isCrossMargin": "1",
387
+ "closeProfit": "0.0306",
388
+ "businessNo": "1001770756852986", # 订单有成交会并入仓位 businessNo
389
+ "relatedOrderSysID": "",
390
+ "positionID": "1000632926272299",
391
+ "mockResp": false,
392
+ "deriveSource": "0",
393
+ "copyOrderID": "",
394
+ "currency": "USDT",
395
+ "turnover": "11.007",
396
+ "frontNo": "-68",
397
+ "direction": "1",
398
+ "orderPriceType": "4",
399
+ "volumeCancled": "0",
400
+ "updateTime": "1760183423",
401
+ "localID": "1000633129818889",
402
+ "volumeTraded": "0.06",
403
+ "appid": "WEB",
404
+ "tradeUnitID": "e1b03fb1-6849-464f-a",
405
+ "businessType": "P",
406
+ "memberID": "e1b03fb1-6849-464f-a986-94b9a6e625e6",
407
+ "timeCondition": "0",
408
+ "copyProfit": "0"
409
+ }
410
+
411
+ """
216
412
 
217
413
  direction_code = self._normalize_direction(direction)
218
414
  offset_code = self._normalize_offset(offset_flag)
@@ -286,3 +286,74 @@ class BitgetDataStore(BitgetV2DataStore):
286
286
  ]
287
287
  """
288
288
  return self._get("book")
289
+
290
+ @property
291
+ def account(self) -> DataStore:
292
+ """
293
+ _KEYS = ["instType", "marginCoin"]
294
+
295
+ Data Structure:
296
+
297
+ .. code:: json
298
+
299
+ [
300
+ {
301
+ "marginCoin": "USDT",
302
+ "frozen": "0.00000000",
303
+ "available": "13.98545761",
304
+ "maxOpenPosAvailable": "13.98545761",
305
+ "maxTransferOut": "13.98545761",
306
+ "equity": "13.98545761",
307
+ "usdtEquity": "13.985457617660",
308
+ "crossedRiskRate": "0",
309
+ "unrealizedPL": "0.000000000000",
310
+ "unionTotalMargin": "100",
311
+ "unionAvailable": "20",
312
+ "unionMm": "15",
313
+ "assetMode": "union"
314
+ }
315
+ ]
316
+ """
317
+ return self._get("account")
318
+
319
+ @property
320
+ def position(self) -> DataStore:
321
+ """
322
+ _KEYS = ["instType", "instId", "posId"]
323
+
324
+ Data Structure:
325
+
326
+ .. code:: json
327
+
328
+ [
329
+ {
330
+ "posId": "1",
331
+ "instId": "ETHUSDT",
332
+ "marginCoin": "USDT",
333
+ "marginSize": "9.5",
334
+ "marginMode": "crossed",
335
+ "holdSide": "short",
336
+ "posMode": "hedge_mode",
337
+ "total": "0.1",
338
+ "available": "0.1",
339
+ "frozen": "0",
340
+ "openPriceAvg": "1900",
341
+ "leverage": 20,
342
+ "achievedProfits": "0",
343
+ "unrealizedPL": "0",
344
+ "unrealizedPLR": "0",
345
+ "liquidationPrice": "5788.108475905242",
346
+ "keepMarginRate": "0.005",
347
+ "marginRate": "0.004416374196",
348
+ "cTime": "1695649246169",
349
+ "breakEvenPrice": "24778.97",
350
+ "totalFee": "1.45",
351
+ "deductedFee": "0.388",
352
+ "markPrice": "2500",
353
+ "assetMode": "union",
354
+ "uTime": "1695711602568",
355
+ "autoMargin": "off"
356
+ }
357
+ ]
358
+ """
359
+ return self._get("position")
@@ -271,6 +271,7 @@ class Position(DataStore):
271
271
  if not entry:
272
272
  return None
273
273
  position_id = entry.get("PositionID")
274
+ bus_id = entry.get("BusinessNo")
274
275
  if not position_id:
275
276
  return None
276
277
 
@@ -279,6 +280,7 @@ class Position(DataStore):
279
280
 
280
281
  return {
281
282
  "position_id": position_id,
283
+ "bus_id": bus_id,
282
284
  "symbol": entry.get("InstrumentID"),
283
285
  "side": side,
284
286
  "quantity": entry.get("Position"),
@@ -473,6 +475,7 @@ class LbankDataStore(DataStoreCollection):
473
475
  [
474
476
  {
475
477
  "position_id": <仓位ID>,
478
+ "bus_id": <订单ID覆盖>,
476
479
  "symbol": <合约ID>,
477
480
  "side": "long" / "short" / "net",
478
481
  "quantity": <持仓数量>,
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: hyperquant
3
- Version: 0.72
3
+ Version: 0.74
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
@@ -5,25 +5,25 @@ hyperquant/draw.py,sha256=up_lQ3pHeVLoNOyh9vPjgNwjD0M-6_IetSGviQUgjhY,54624
5
5
  hyperquant/logkit.py,sha256=nUo7nx5eONvK39GOhWwS41zNRL756P2J7-5xGzwXnTY,8462
6
6
  hyperquant/notikit.py,sha256=x5yAZ_tAvLQRXcRbcg-VabCaN45LUhvlTZnUqkIqfAA,3596
7
7
  hyperquant/broker/auth.py,sha256=Wst7mTBuUS2BQ5hZd0a8FNNs5Uc01ac9WzJpseTuyAY,7673
8
- hyperquant/broker/bitget.py,sha256=n0McsEUStwtQaLaIxyJoGlougn2tmd4p7SQfA8Gumiw,9174
8
+ hyperquant/broker/bitget.py,sha256=PEzULGJJQeQ91TKa4F56WhEpcnUHC3WpIx1pi5UXpVQ,9182
9
9
  hyperquant/broker/edgex.py,sha256=TqUO2KRPLN_UaxvtLL6HnA9dAQXC1sGxOfqTHd6W5k8,18378
10
10
  hyperquant/broker/hyperliquid.py,sha256=7MxbI9OyIBcImDelPJu-8Nd53WXjxPB5TwE6gsjHbto,23252
11
- hyperquant/broker/lbank.py,sha256=dZUbi0a_Vhkp4pJ1V11X6nEM7I4HhQIVRgpSMeGcAMU,11681
11
+ hyperquant/broker/lbank.py,sha256=TdDNuhOyB-lvayJHQwWByiqhxxMk4MZjwENicwtFej8,18495
12
12
  hyperquant/broker/ourbit.py,sha256=NUcDSIttf-HGWzoW1uBTrGLPHlkuemMjYCm91MigTno,18228
13
13
  hyperquant/broker/ws.py,sha256=9Zu5JSLj-ylYEVmFmRwvZDDnVYKwb37cLHfZzA0AZGc,2200
14
14
  hyperquant/broker/lib/edgex_sign.py,sha256=lLUCmY8HHRLfLKyGrlTJYaBlSHPsIMWg3EZnQJKcmyk,95785
15
15
  hyperquant/broker/lib/hpstore.py,sha256=LnLK2zmnwVvhEbLzYI-jz_SfYpO1Dv2u2cJaRAb84D8,8296
16
16
  hyperquant/broker/lib/hyper_types.py,sha256=HqjjzjUekldjEeVn6hxiWA8nevAViC2xHADOzDz9qyw,991
17
17
  hyperquant/broker/lib/util.py,sha256=iMU1qF0CHj5zzlIMEQGwjz-qtEVosEe7slXOCuB7Rcw,566
18
- hyperquant/broker/models/bitget.py,sha256=P-dADalyIxYbSNLqXTSu23h7JMS_0FfOH899imVp1aA,9119
18
+ hyperquant/broker/models/bitget.py,sha256=0RwDY75KrJb-c-oYoMxbqxWfsILe-n_Npojz4UFUq7c,11389
19
19
  hyperquant/broker/models/edgex.py,sha256=vPAkceal44cjTYKQ_0BoNAskOpmkno_Yo1KxgMLPc6Y,33954
20
20
  hyperquant/broker/models/hyperliquid.py,sha256=c4r5739ibZfnk69RxPjQl902AVuUOwT8RNvKsMtwXBY,9459
21
- hyperquant/broker/models/lbank.py,sha256=_ztqhYGDqEHpmSITfYp_cpEJiJrhfJ9dwZ52K_PhE2A,18969
21
+ hyperquant/broker/models/lbank.py,sha256=2RkhwA8vpC1ex5TslNcfNpL0CcPhtg1KXv2uZjPc0q0,19088
22
22
  hyperquant/broker/models/ourbit.py,sha256=xMcbuCEXd3XOpPBq0RYF2zpTFNnxPtuNJZCexMZVZ1k,41965
23
23
  hyperquant/datavison/_util.py,sha256=92qk4vO856RqycO0YqEIHJlEg-W9XKapDVqAMxe6rbw,533
24
24
  hyperquant/datavison/binance.py,sha256=3yNKTqvt_vUQcxzeX4ocMsI5k6Q6gLZrvgXxAEad6Kc,5001
25
25
  hyperquant/datavison/coinglass.py,sha256=PEjdjISP9QUKD_xzXNzhJ9WFDTlkBrRQlVL-5pxD5mo,10482
26
26
  hyperquant/datavison/okx.py,sha256=yg8WrdQ7wgWHNAInIgsWPM47N3Wkfr253169IPAycAY,6898
27
- hyperquant-0.72.dist-info/METADATA,sha256=YCqf-2q7ieiCqAHbUfOhrAPrqnFMzz6ZvAs5f4_PTAU,4317
28
- hyperquant-0.72.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
29
- hyperquant-0.72.dist-info/RECORD,,
27
+ hyperquant-0.74.dist-info/METADATA,sha256=xEBYMDRIS-3ViFktvBg5IaWOxUmXRl5n-CHWTu-E9JQ,4317
28
+ hyperquant-0.74.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
29
+ hyperquant-0.74.dist-info/RECORD,,