hyperquant 0.97__py3-none-any.whl → 0.99__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.
    
        hyperquant/broker/bitmart.py
    CHANGED
    
    | 
         @@ -4,7 +4,7 @@ import asyncio 
     | 
|
| 
       4 
4 
     | 
    
         
             
            import json
         
     | 
| 
       5 
5 
     | 
    
         
             
            import random
         
     | 
| 
       6 
6 
     | 
    
         
             
            import time
         
     | 
| 
       7 
     | 
    
         
            -
            from typing import Any, Literal, Sequence
         
     | 
| 
      
 7 
     | 
    
         
            +
            from typing import Any, Literal, Optional, Sequence
         
     | 
| 
       8 
8 
     | 
    
         | 
| 
       9 
9 
     | 
    
         
             
            import pybotters
         
     | 
| 
       10 
10 
     | 
    
         | 
| 
         @@ -33,10 +33,19 @@ class Bitmart: 
     | 
|
| 
       33 
33 
     | 
    
         | 
| 
       34 
34 
     | 
    
         
             
                    self.account_index = account_index
         
     | 
| 
       35 
35 
     | 
    
         
             
                    self.apis = apis
         
     | 
| 
      
 36 
     | 
    
         
            +
                    self.symbol_to_contract_id: dict[str, str] = {}
         
     | 
| 
       36 
37 
     | 
    
         | 
| 
       37 
38 
     | 
    
         
             
                async def __aenter__(self) -> "Bitmart":
         
     | 
| 
       38 
39 
     | 
    
         
             
                    await self.update("detail")
         
     | 
| 
       39 
40 
     | 
    
         
             
                    asyncio.create_task(self.auto_refresh())
         
     | 
| 
      
 41 
     | 
    
         
            +
                    
         
     | 
| 
      
 42 
     | 
    
         
            +
                    for entry in self.store.detail.find():
         
     | 
| 
      
 43 
     | 
    
         
            +
                        contract_id = entry.get("contract_id")
         
     | 
| 
      
 44 
     | 
    
         
            +
                        symbol = entry.get("name") or entry.get("display_name")
         
     | 
| 
      
 45 
     | 
    
         
            +
                        if contract_id is None or symbol is None:
         
     | 
| 
      
 46 
     | 
    
         
            +
                            continue
         
     | 
| 
      
 47 
     | 
    
         
            +
                        self.symbol_to_contract_id[str(symbol)] = str(contract_id)
         
     | 
| 
      
 48 
     | 
    
         
            +
             
     | 
| 
       40 
49 
     | 
    
         
             
                    return self
         
     | 
| 
       41 
50 
     | 
    
         | 
| 
       42 
51 
     | 
    
         
             
                async def auto_refresh(self, sec=3600, test=False) -> None:
         
     | 
| 
         @@ -325,8 +334,9 @@ class Bitmart: 
     | 
|
| 
       325 
334 
     | 
    
         
             
                    *,
         
     | 
| 
       326 
335 
     | 
    
         
             
                    category: Literal[1,2,"limit","market"] = "limit",
         
     | 
| 
       327 
336 
     | 
    
         
             
                    price: float,
         
     | 
| 
       328 
     | 
    
         
            -
                     
     | 
| 
       329 
     | 
    
         
            -
                     
     | 
| 
      
 337 
     | 
    
         
            +
                    qty: float,
         
     | 
| 
      
 338 
     | 
    
         
            +
                    qty_contract: Optional[int] = None,
         
     | 
| 
      
 339 
     | 
    
         
            +
                    side: Literal[1, 2, 3, 4, "open_long", "close_short", "close_long", "open_short", "buy", "sell"] = "open_long",
         
     | 
| 
       330 
340 
     | 
    
         
             
                    mode: Literal[1, 2, 3, 4, "gtc", "ioc", "fok", "maker_only", "maker-only", "post_only"] = "gtc",
         
     | 
| 
       331 
341 
     | 
    
         
             
                    open_type: Literal[1, 2, "cross", "isolated"] = "isolated",
         
     | 
| 
       332 
342 
     | 
    
         
             
                    leverage: int | str = 10,
         
     | 
| 
         @@ -334,8 +344,9 @@ class Bitmart: 
     | 
|
| 
       334 
344 
     | 
    
         
             
                    trigger_price: float | None = None,
         
     | 
| 
       335 
345 
     | 
    
         
             
                    custom_id: int | str | None = None,
         
     | 
| 
       336 
346 
     | 
    
         
             
                    extra_params: dict[str, Any] | None = None,
         
     | 
| 
       337 
     | 
    
         
            -
                ) ->  
     | 
| 
      
 347 
     | 
    
         
            +
                ) -> int:
         
     | 
| 
       338 
348 
     | 
    
         
             
                    """Submit an order via ``submitOrder``.
         
     | 
| 
      
 349 
     | 
    
         
            +
                    返回值: order_id (int)
         
     | 
| 
       339 
350 
     | 
    
         
             
                    """
         
     | 
| 
       340 
351 
     | 
    
         | 
| 
       341 
352 
     | 
    
         
             
                    contract_id = self.get_contract_id(symbol)
         
     | 
| 
         @@ -351,25 +362,31 @@ class Bitmart: 
     | 
|
| 
       351 
362 
     | 
    
         
             
                        raise ValueError(f"Market metadata unavailable for symbol: {symbol}")
         
     | 
| 
       352 
363 
     | 
    
         | 
| 
       353 
364 
     | 
    
         | 
| 
       354 
     | 
    
         
            -
                     
     | 
| 
       355 
     | 
    
         
            -
             
     | 
| 
       356 
     | 
    
         
            -
                         
     | 
| 
       357 
     | 
    
         
            -
             
     | 
| 
       358 
     | 
    
         
            -
             
     | 
| 
       359 
     | 
    
         
            -
             
     | 
| 
       360 
     | 
    
         
            -
             
     | 
| 
       361 
     | 
    
         
            -
             
     | 
| 
       362 
     | 
    
         
            -
             
     | 
| 
       363 
     | 
    
         
            -
             
     | 
| 
       364 
     | 
    
         
            -
             
     | 
| 
       365 
     | 
    
         
            -
                         
     | 
| 
       366 
     | 
    
         
            -
             
     | 
| 
       367 
     | 
    
         
            -
             
     | 
| 
       368 
     | 
    
         
            -
             
     | 
| 
       369 
     | 
    
         
            -
             
     | 
| 
       370 
     | 
    
         
            -
             
     | 
| 
       371 
     | 
    
         
            -
                             
     | 
| 
       372 
     | 
    
         
            -
             
     | 
| 
      
 365 
     | 
    
         
            +
                    if qty_contract is not None:
         
     | 
| 
      
 366 
     | 
    
         
            +
             
     | 
| 
      
 367 
     | 
    
         
            +
                        contract_size_str = detail.get("contract_size") or detail.get("vol_unit") or "1"
         
     | 
| 
      
 368 
     | 
    
         
            +
                        try:
         
     | 
| 
      
 369 
     | 
    
         
            +
                            contract_size_val = float(contract_size_str)
         
     | 
| 
      
 370 
     | 
    
         
            +
                        except (TypeError, ValueError):
         
     | 
| 
      
 371 
     | 
    
         
            +
                            contract_size_val = 1.0
         
     | 
| 
      
 372 
     | 
    
         
            +
                        if contract_size_val <= 0:
         
     | 
| 
      
 373 
     | 
    
         
            +
                            raise ValueError(f"Invalid contract_size for {symbol}: {contract_size_str}")
         
     | 
| 
      
 374 
     | 
    
         
            +
             
     | 
| 
      
 375 
     | 
    
         
            +
                        contracts_float = float(qty) / contract_size_val
         
     | 
| 
      
 376 
     | 
    
         
            +
                        contracts_int = int(round(contracts_float))
         
     | 
| 
      
 377 
     | 
    
         
            +
                        if contracts_int <= 0:
         
     | 
| 
      
 378 
     | 
    
         
            +
                            raise ValueError(
         
     | 
| 
      
 379 
     | 
    
         
            +
                                f"Volume too small for contract size ({contract_size_val}): volume={qty}"
         
     | 
| 
      
 380 
     | 
    
         
            +
                            )
         
     | 
| 
      
 381 
     | 
    
         
            +
                        if abs(contracts_float - contracts_int) > 1e-8:
         
     | 
| 
      
 382 
     | 
    
         
            +
                            raise ValueError(
         
     | 
| 
      
 383 
     | 
    
         
            +
                                f"Volume must be a multiple of contract_size ({contract_size_val}). "
         
     | 
| 
      
 384 
     | 
    
         
            +
                                f"Received volume={qty} -> {contracts_float} contracts."
         
     | 
| 
      
 385 
     | 
    
         
            +
                            )
         
     | 
| 
      
 386 
     | 
    
         
            +
                    else:
         
     | 
| 
      
 387 
     | 
    
         
            +
                        contracts_int = int(qty)
         
     | 
| 
      
 388 
     | 
    
         
            +
                        if contracts_int <= 0:
         
     | 
| 
      
 389 
     | 
    
         
            +
                            raise ValueError(f"Volume must be positive integer contracts: volume={qty}")
         
     | 
| 
       373 
390 
     | 
    
         | 
| 
       374 
391 
     | 
    
         
             
                    price_unit = detail.get("price_unit") or 1
         
     | 
| 
       375 
392 
     | 
    
         
             
                    try:
         
     | 
| 
         @@ -396,7 +413,7 @@ class Bitmart: 
     | 
|
| 
       396 
413 
     | 
    
         
             
                    price_fmt = f"{adjusted_price:.15f}".rstrip("0").rstrip(".") or "0"
         
     | 
| 
       397 
414 
     | 
    
         | 
| 
       398 
415 
     | 
    
         
             
                    way_value = self._normalize_enum(
         
     | 
| 
       399 
     | 
    
         
            -
                         
     | 
| 
      
 416 
     | 
    
         
            +
                        side,
         
     | 
| 
       400 
417 
     | 
    
         
             
                        {
         
     | 
| 
       401 
418 
     | 
    
         
             
                            "open_long": 1,
         
     | 
| 
       402 
419 
     | 
    
         
             
                            "close_short": 2,
         
     | 
| 
         @@ -460,7 +477,10 @@ class Bitmart: 
     | 
|
| 
       460 
477 
     | 
    
         | 
| 
       461 
478 
     | 
    
         
             
                    if resp.get("success") is False or resp.get("errno") not in (None, "OK"):
         
     | 
| 
       462 
479 
     | 
    
         
             
                        raise ValueError(f"Bitmart submitOrder error: {resp}")
         
     | 
| 
       463 
     | 
    
         
            -
                     
     | 
| 
      
 480 
     | 
    
         
            +
                    
         
     | 
| 
      
 481 
     | 
    
         
            +
                    # {"errno":"OK","message":"Success","data":{"order_id":3000236525013551},"success":true}
         
     | 
| 
      
 482 
     | 
    
         
            +
                    # 直接取order_id返回
         
     | 
| 
      
 483 
     | 
    
         
            +
                    return resp.get("data", {}).get("order_id")
         
     | 
| 
       464 
484 
     | 
    
         | 
| 
       465 
485 
     | 
    
         
             
                async def cancel_order(
         
     | 
| 
       466 
486 
     | 
    
         
             
                    self,
         
     | 
| 
         @@ -381,7 +381,7 @@ class BitmartDataStore(DataStoreCollection): 
     | 
|
| 
       381 
381 
     | 
    
         
             
                @property
         
     | 
| 
       382 
382 
     | 
    
         
             
                def orders(self) -> Orders:
         
     | 
| 
       383 
383 
     | 
    
         
             
                    """用户订单 (`userAllOrders`)。
         
     | 
| 
       384 
     | 
    
         
            -
             
     | 
| 
      
 384 
     | 
    
         
            +
                    key: order_id
         
     | 
| 
       385 
385 
     | 
    
         
             
                    .. code:: json
         
     | 
| 
       386 
386 
     | 
    
         | 
| 
       387 
387 
     | 
    
         
             
                        [
         
     | 
| 
         @@ -510,19 +510,19 @@ class BitmartDataStore(DataStoreCollection): 
     | 
|
| 
       510 
510 
     | 
    
         
             
                            {
         
     | 
| 
       511 
511 
     | 
    
         
             
                                "account_id": 14794011,
         
     | 
| 
       512 
512 
     | 
    
         
             
                                "coin_code": "USDT",
         
     | 
| 
       513 
     | 
    
         
            -
                                "available_vol": " 
     | 
| 
       514 
     | 
    
         
            -
                                "cash_vol": " 
     | 
| 
      
 513 
     | 
    
         
            +
                                "available_vol": "10.970977797397999999",
         
     | 
| 
      
 514 
     | 
    
         
            +
                                "cash_vol": "11.000536099457999999",
         
     | 
| 
       515 
515 
     | 
    
         
             
                                "freeze_vol": "0",
         
     | 
| 
       516 
     | 
    
         
            -
                                "realised_vol": "0",
         
     | 
| 
       517 
     | 
    
         
            -
                                "un_realised_vol": "0",
         
     | 
| 
       518 
     | 
    
         
            -
                                "earnings_vol": "0",
         
     | 
| 
      
 516 
     | 
    
         
            +
                                "realised_vol": "0.000536099457999999",
         
     | 
| 
      
 517 
     | 
    
         
            +
                                "un_realised_vol": "-0.00001502",
         
     | 
| 
      
 518 
     | 
    
         
            +
                                "earnings_vol": "0.000536099457999999",
         
     | 
| 
       519 
519 
     | 
    
         
             
                                "total_im": "",
         
     | 
| 
       520 
520 
     | 
    
         
             
                                "margin_balance": "",
         
     | 
| 
       521 
521 
     | 
    
         
             
                                "available_balance": "",
         
     | 
| 
       522 
522 
     | 
    
         
             
                                "trans_out_balance": "",
         
     | 
| 
       523 
523 
     | 
    
         
             
                                "status": 0,
         
     | 
| 
       524 
524 
     | 
    
         
             
                                "total_balance": "",
         
     | 
| 
       525 
     | 
    
         
            -
                                "account_rights": " 
     | 
| 
      
 525 
     | 
    
         
            +
                                "account_rights": "11.000521079457999999",
         
     | 
| 
       526 
526 
     | 
    
         
             
                                "bonus_voucher_vol": "",
         
     | 
| 
       527 
527 
     | 
    
         
             
                                "freeze_bonus_voucher_vol": ""
         
     | 
| 
       528 
528 
     | 
    
         
             
                            }
         
     | 
| 
         @@ -1,6 +1,6 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            Metadata-Version: 2.4
         
     | 
| 
       2 
2 
     | 
    
         
             
            Name: hyperquant
         
     | 
| 
       3 
     | 
    
         
            -
            Version: 0. 
     | 
| 
      
 3 
     | 
    
         
            +
            Version: 0.99
         
     | 
| 
       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= 
     | 
| 
      
 9 
     | 
    
         
            +
            hyperquant/broker/bitmart.py,sha256=d9eEWCskoRRAH0knjyT8K-3ob0MK_0uQ9h_0UnQSOJM,17708
         
     | 
| 
       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
         
     | 
| 
         @@ -20,7 +20,7 @@ hyperquant/broker/lib/hpstore.py,sha256=LnLK2zmnwVvhEbLzYI-jz_SfYpO1Dv2u2cJaRAb8 
     | 
|
| 
       20 
20 
     | 
    
         
             
            hyperquant/broker/lib/hyper_types.py,sha256=HqjjzjUekldjEeVn6hxiWA8nevAViC2xHADOzDz9qyw,991
         
     | 
| 
       21 
21 
     | 
    
         
             
            hyperquant/broker/lib/util.py,sha256=iMU1qF0CHj5zzlIMEQGwjz-qtEVosEe7slXOCuB7Rcw,566
         
     | 
| 
       22 
22 
     | 
    
         
             
            hyperquant/broker/models/bitget.py,sha256=0RwDY75KrJb-c-oYoMxbqxWfsILe-n_Npojz4UFUq7c,11389
         
     | 
| 
       23 
     | 
    
         
            -
            hyperquant/broker/models/bitmart.py,sha256= 
     | 
| 
      
 23 
     | 
    
         
            +
            hyperquant/broker/models/bitmart.py,sha256=6lOpQXLcuR7MEayvMt_e-okE2A8CCUvpzAT6aCxWSaM,20455
         
     | 
| 
       24 
24 
     | 
    
         
             
            hyperquant/broker/models/coinup.py,sha256=X_ngB2_sgTOdfAZqTyeWvCN03j-0_inZ6ugZKW6hR7k,11173
         
     | 
| 
       25 
25 
     | 
    
         
             
            hyperquant/broker/models/coinw.py,sha256=LvLMVP7i-qkkTK1ubw8eBkMK2RQmFoKPxdKqmC4IToY,22157
         
     | 
| 
       26 
26 
     | 
    
         
             
            hyperquant/broker/models/edgex.py,sha256=vPAkceal44cjTYKQ_0BoNAskOpmkno_Yo1KxgMLPc6Y,33954
         
     | 
| 
         @@ -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-0. 
     | 
| 
       36 
     | 
    
         
            -
            hyperquant-0. 
     | 
| 
       37 
     | 
    
         
            -
            hyperquant-0. 
     | 
| 
      
 35 
     | 
    
         
            +
            hyperquant-0.99.dist-info/METADATA,sha256=Xp8eYdpew89TrwNCR-NUygnlHVMwrQ3SkG8kCogxm28,4409
         
     | 
| 
      
 36 
     | 
    
         
            +
            hyperquant-0.99.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
         
     | 
| 
      
 37 
     | 
    
         
            +
            hyperquant-0.99.dist-info/RECORD,,
         
     | 
| 
         
            File without changes
         
     |