hyperquant 1.1__py3-none-any.whl → 1.2__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.
@@ -510,3 +510,101 @@ class Bitmart:
510
510
  if resp.get("success") is False or resp.get("errno") not in (None, "OK"):
511
511
  raise ValueError(f"Bitmart cancelOrders error: {resp}")
512
512
  return resp
513
+
514
+ async def get_leverage(
515
+ self,
516
+ *,
517
+ symbol: str | None = None,
518
+ contract_id: int | str | None = None,
519
+ ) -> dict[str, Any]:
520
+ """
521
+ 获取指定合约的杠杆信息(可通过 contract_id 或 symbol 查询)。
522
+
523
+ 参数:
524
+ symbol (str | None): 合约符号,例如 "BTCUSDT"。如果未传入 contract_id,则会自动解析。
525
+ contract_id (int | str | None): 合约 ID,可直接指定。
526
+
527
+ 返回:
528
+ dict[str, Any]: 杠杆信息字典,典型返回结构如下:
529
+ {
530
+ "contract_id": 1,
531
+ "leverage": 96, # 当前杠杆倍数
532
+ "open_type": 2, # 开仓类型 (1=全仓, 2=逐仓)
533
+ "max_leverage": {
534
+ "contract_id": 1,
535
+ "leverage": "200", # 最大可用杠杆倍数
536
+ "open_type": 0,
537
+ "imr": "0.005", # 初始保证金率
538
+ "mmr": "0.0025", # 维持保证金率
539
+ "value": "0"
540
+ }
541
+ }
542
+
543
+ 异常:
544
+ ValueError: 当未提供 symbol 或 contract_id,或接口返回错误时抛出。
545
+
546
+ 示例:
547
+ data = await bitmart.get_leverage(symbol="BTCUSDT")
548
+ print(data["leverage"]) # 输出当前杠杆倍数
549
+ """
550
+ if contract_id is None:
551
+ if symbol is not None:
552
+ contract_id = self.get_contract_id(symbol)
553
+ if contract_id is None:
554
+ raise ValueError("Either contract_id or a valid symbol must be provided to get leverage info.")
555
+ res = await self.client.get(
556
+ f"{self.forward_api}/v1/ifcontract/getLeverage",
557
+ params={"contract_id": contract_id},
558
+ )
559
+ resp = await res.json()
560
+ if resp.get("success") is False or resp.get("errno") not in (None, "OK"):
561
+ raise ValueError(f"Bitmart getLeverage error: {resp}")
562
+ return resp.get("data")
563
+
564
+ async def bind_leverage(
565
+ self,
566
+ *,
567
+ symbol: str | None = None,
568
+ contract_id: int | str | None = None,
569
+ leverage: int | str,
570
+ open_type: Literal[1, 2] = 2,
571
+ ) -> None:
572
+ """
573
+ 绑定(设置)指定合约的杠杆倍数。
574
+
575
+ 参数:
576
+ symbol (str | None): 合约符号,例如 "BTCUSDT"。若未传入 contract_id,会自动解析。
577
+ contract_id (int | str | None): 合约 ID,可直接指定。
578
+ leverage (int | str): 要设置的杠杆倍数,如 20、50、100。
579
+ open_type (int): 开仓模式,1=全仓(Cross),2=逐仓(Isolated)。
580
+
581
+ 返回:
582
+ None — 如果接口调用成功,不返回任何内容。
583
+ 若失败则抛出 ValueError。
584
+
585
+ 异常:
586
+ ValueError: 当未提供 symbol 或 contract_id,或接口返回错误时抛出。
587
+
588
+ 示例:
589
+ await bitmart.bind_leverage(symbol="BTCUSDT", leverage=50, open_type=2)
590
+ """
591
+ if contract_id is None:
592
+ if symbol is not None:
593
+ contract_id = self.get_contract_id(symbol)
594
+ if contract_id is None:
595
+ raise ValueError("Either contract_id or a valid symbol must be provided to bind leverage.")
596
+
597
+ payload = {
598
+ "contract_id": int(contract_id),
599
+ "leverage": leverage,
600
+ "open_type": open_type,
601
+ }
602
+
603
+ res = await self.client.post(
604
+ f"{self.forward_api}/v1/ifcontract/bindLeverage",
605
+ json=payload,
606
+ )
607
+ resp = await res.json()
608
+ if resp.get("success") is False or resp.get("errno") not in (None, "OK"):
609
+ raise ValueError(f"Bitmart bindLeverage error: {resp}")
610
+ return None
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: hyperquant
3
- Version: 1.1
3
+ Version: 1.2
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,7 +6,7 @@ hyperquant/logkit.py,sha256=nUo7nx5eONvK39GOhWwS41zNRL756P2J7-5xGzwXnTY,8462
6
6
  hyperquant/notikit.py,sha256=x5yAZ_tAvLQRXcRbcg-VabCaN45LUhvlTZnUqkIqfAA,3596
7
7
  hyperquant/broker/auth.py,sha256=C8B5-x8Qcaeafm4ZwPCVFR7GRURmHC3CE4_vdg00Qgw,12139
8
8
  hyperquant/broker/bitget.py,sha256=X_S0LKZ7FZAEb6oEMr1vdGP1fondzK74BhmNTpRDSEA,9488
9
- hyperquant/broker/bitmart.py,sha256=gOMh_w22vd0L-rMLLCLvtBDqHpXPKeru6bnd9hx1u-M,17604
9
+ hyperquant/broker/bitmart.py,sha256=wHot_CwaRNituj0Rpn60Kv5bU5YQquDIMPDFzlzbFws,21443
10
10
  hyperquant/broker/coinup.py,sha256=eOr8BTRXiTb5tCU2FDmvBdXXgqiwVmCbP5pdeA1ORJ8,20390
11
11
  hyperquant/broker/coinw.py,sha256=SnJU0vASh77rfcpMGWaIfTblQSjQk3vjlW_4juYdbcs,17214
12
12
  hyperquant/broker/edgex.py,sha256=TqUO2KRPLN_UaxvtLL6HnA9dAQXC1sGxOfqTHd6W5k8,18378
@@ -32,6 +32,6 @@ hyperquant/datavison/_util.py,sha256=92qk4vO856RqycO0YqEIHJlEg-W9XKapDVqAMxe6rbw
32
32
  hyperquant/datavison/binance.py,sha256=3yNKTqvt_vUQcxzeX4ocMsI5k6Q6gLZrvgXxAEad6Kc,5001
33
33
  hyperquant/datavison/coinglass.py,sha256=PEjdjISP9QUKD_xzXNzhJ9WFDTlkBrRQlVL-5pxD5mo,10482
34
34
  hyperquant/datavison/okx.py,sha256=yg8WrdQ7wgWHNAInIgsWPM47N3Wkfr253169IPAycAY,6898
35
- hyperquant-1.1.dist-info/METADATA,sha256=6HPHF63atspmUAmbE3Gig8F3TwhHFSPe74kPgX2zglQ,4408
36
- hyperquant-1.1.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
37
- hyperquant-1.1.dist-info/RECORD,,
35
+ hyperquant-1.2.dist-info/METADATA,sha256=sWjVioqvlZhhPPOx0AiD6t29SR4xXRR56ebM09hhLKM,4408
36
+ hyperquant-1.2.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
37
+ hyperquant-1.2.dist-info/RECORD,,