hyperquant 0.3__py3-none-any.whl → 0.4__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/auth.py CHANGED
@@ -1,6 +1,7 @@
1
1
  import time
2
2
  import hashlib
3
3
  from typing import Any
4
+ from aiohttp import ClientWebSocketResponse
4
5
  from multidict import CIMultiDict
5
6
  from yarl import URL
6
7
  import pybotters
@@ -27,25 +28,61 @@ class Auth:
27
28
 
28
29
  # 时间戳 & body
29
30
  now_ms = int(time.time() * 1000)
30
- raw_body_for_sign = data if isinstance(data, str) else pyjson.dumps(data, separators=(",", ":"), ensure_ascii=False)
31
+ raw_body_for_sign = (
32
+ data
33
+ if isinstance(data, str)
34
+ else pyjson.dumps(data, separators=(",", ":"), ensure_ascii=False)
35
+ )
31
36
 
32
37
  # 签名
33
38
  mid_hash = md5_hex(f"{token}{now_ms}")[7:]
34
39
  final_hash = md5_hex(f"{now_ms}{raw_body_for_sign}{mid_hash}")
35
40
 
36
41
  # 设置 headers
37
- headers.update({
38
- "Authorization": token,
39
- "Language": "Chinese",
40
- "language": "Chinese",
41
- "Content-Type": "application/json",
42
- "x-ourbit-sign": final_hash,
43
- "x-ourbit-nonce": str(now_ms),
44
- })
42
+ headers.update(
43
+ {
44
+ "Authorization": token,
45
+ "Language": "Chinese",
46
+ "language": "Chinese",
47
+ "Content-Type": "application/json",
48
+ "x-ourbit-sign": final_hash,
49
+ "x-ourbit-nonce": str(now_ms),
50
+ }
51
+ )
45
52
 
46
53
  # 更新 kwargs.body,保证发出去的与签名一致
47
54
  kwargs.update({"data": raw_body_for_sign})
48
55
 
49
56
  return args
50
57
 
51
- pybotters.auth.Hosts.items['futures.ourbit.com'] = pybotters.auth.Item("ourbit", Auth.ourbit)
58
+ @staticmethod
59
+ def ourbit_spot(args: tuple[str, URL], kwargs: dict[str, Any]) -> tuple[str, URL]:
60
+ method: str = args[0]
61
+ url: URL = args[1]
62
+ data = kwargs.get("data") or {}
63
+ headers: CIMultiDict = kwargs["headers"]
64
+
65
+ # 从 session 里取 token
66
+ session = kwargs["session"]
67
+ token = session.__dict__["_apis"][pybotters.auth.Hosts.items[url.host].name][0]
68
+ cookie = f"uc_token={token}; u_id={token}; "
69
+ headers.update({"cookie": cookie})
70
+
71
+ # wss消息增加参数
72
+ # if headers.get("Upgrade") == "websocket":
73
+ # args = (method, url)
74
+ # # 拼接 token
75
+ # q = dict(url.query)
76
+ # q["token"] = token
77
+ # url = url.with_query(q)
78
+
79
+
80
+ return args
81
+
82
+
83
+ pybotters.auth.Hosts.items["futures.ourbit.com"] = pybotters.auth.Item(
84
+ "ourbit", Auth.ourbit
85
+ )
86
+ pybotters.auth.Hosts.items["www.ourbit.com"] = pybotters.auth.Item(
87
+ "ourbit", Auth.ourbit_spot
88
+ )
@@ -27,8 +27,6 @@ import pybotters
27
27
  from yarl import URL
28
28
 
29
29
  from .models.hyperliquid import MyHyperStore
30
- import uuid
31
-
32
30
 
33
31
  def to_cloid(s: str) -> str:
34
32
  """