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 +47 -10
- hyperquant/broker/hyperliquid.py +0 -2
- hyperquant/broker/models/ourbit.py +635 -83
- hyperquant/broker/ourbit.py +277 -11
- hyperquant/broker/ws.py +37 -1
- {hyperquant-0.3.dist-info → hyperquant-0.4.dist-info}/METADATA +1 -1
- {hyperquant-0.3.dist-info → hyperquant-0.4.dist-info}/RECORD +8 -8
- {hyperquant-0.3.dist-info → hyperquant-0.4.dist-info}/WHEEL +0 -0
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 =
|
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
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
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
|
-
|
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
|
+
)
|