hyperquant 0.3__tar.gz → 0.4__tar.gz
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-0.3 → hyperquant-0.4}/PKG-INFO +1 -1
- {hyperquant-0.3 → hyperquant-0.4}/pyproject.toml +1 -1
- hyperquant-0.4/src/hyperquant/broker/auth.py +88 -0
- {hyperquant-0.3 → hyperquant-0.4}/src/hyperquant/broker/hyperliquid.py +0 -2
- hyperquant-0.4/src/hyperquant/broker/models/ourbit.py +1054 -0
- hyperquant-0.4/src/hyperquant/broker/ourbit.py +500 -0
- hyperquant-0.4/src/hyperquant/broker/ws.py +48 -0
- {hyperquant-0.3 → hyperquant-0.4}/test.py +16 -2
- hyperquant-0.4/tmp.py +131 -0
- {hyperquant-0.3 → hyperquant-0.4}/uv.lock +1 -1
- hyperquant-0.3/src/hyperquant/broker/auth.py +0 -51
- hyperquant-0.3/src/hyperquant/broker/models/ourbit.py +0 -502
- hyperquant-0.3/src/hyperquant/broker/ourbit.py +0 -234
- hyperquant-0.3/src/hyperquant/broker/ws.py +0 -12
- {hyperquant-0.3 → hyperquant-0.4}/.gitignore +0 -0
- {hyperquant-0.3 → hyperquant-0.4}/.python-version +0 -0
- {hyperquant-0.3 → hyperquant-0.4}/README.md +0 -0
- {hyperquant-0.3 → hyperquant-0.4}/data/logs/notikit.log +0 -0
- {hyperquant-0.3 → hyperquant-0.4}/pub.sh +0 -0
- {hyperquant-0.3 → hyperquant-0.4}/requirements-dev.lock +0 -0
- {hyperquant-0.3 → hyperquant-0.4}/requirements.lock +0 -0
- {hyperquant-0.3 → hyperquant-0.4}/src/hyperquant/__init__.py +0 -0
- {hyperquant-0.3 → hyperquant-0.4}/src/hyperquant/broker/lib/hpstore.py +0 -0
- {hyperquant-0.3 → hyperquant-0.4}/src/hyperquant/broker/lib/hyper_types.py +0 -0
- {hyperquant-0.3 → hyperquant-0.4}/src/hyperquant/broker/models/hyperliquid.py +0 -0
- {hyperquant-0.3 → hyperquant-0.4}/src/hyperquant/core.py +0 -0
- {hyperquant-0.3 → hyperquant-0.4}/src/hyperquant/datavison/_util.py +0 -0
- {hyperquant-0.3 → hyperquant-0.4}/src/hyperquant/datavison/binance.py +0 -0
- {hyperquant-0.3 → hyperquant-0.4}/src/hyperquant/datavison/coinglass.py +0 -0
- {hyperquant-0.3 → hyperquant-0.4}/src/hyperquant/datavison/okx.py +0 -0
- {hyperquant-0.3 → hyperquant-0.4}/src/hyperquant/db.py +0 -0
- {hyperquant-0.3 → hyperquant-0.4}/src/hyperquant/draw.py +0 -0
- {hyperquant-0.3 → hyperquant-0.4}/src/hyperquant/logkit.py +0 -0
- {hyperquant-0.3 → hyperquant-0.4}/src/hyperquant/notikit.py +0 -0
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.4
|
2
2
|
Name: hyperquant
|
3
|
-
Version: 0.
|
3
|
+
Version: 0.4
|
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
|
@@ -0,0 +1,88 @@
|
|
1
|
+
import time
|
2
|
+
import hashlib
|
3
|
+
from typing import Any
|
4
|
+
from aiohttp import ClientWebSocketResponse
|
5
|
+
from multidict import CIMultiDict
|
6
|
+
from yarl import URL
|
7
|
+
import pybotters
|
8
|
+
import json as pyjson
|
9
|
+
from urllib.parse import urlencode
|
10
|
+
|
11
|
+
|
12
|
+
def md5_hex(s: str) -> str:
|
13
|
+
return hashlib.md5(s.encode("utf-8")).hexdigest()
|
14
|
+
|
15
|
+
|
16
|
+
# 🔑 Ourbit 的鉴权函数
|
17
|
+
class Auth:
|
18
|
+
@staticmethod
|
19
|
+
def ourbit(args: tuple[str, URL], kwargs: dict[str, Any]) -> tuple[str, URL]:
|
20
|
+
method: str = args[0]
|
21
|
+
url: URL = args[1]
|
22
|
+
data = kwargs.get("data") or {}
|
23
|
+
headers: CIMultiDict = kwargs["headers"]
|
24
|
+
|
25
|
+
# 从 session 里取 token
|
26
|
+
session = kwargs["session"]
|
27
|
+
token = session.__dict__["_apis"][pybotters.auth.Hosts.items[url.host].name][0]
|
28
|
+
|
29
|
+
# 时间戳 & body
|
30
|
+
now_ms = int(time.time() * 1000)
|
31
|
+
raw_body_for_sign = (
|
32
|
+
data
|
33
|
+
if isinstance(data, str)
|
34
|
+
else pyjson.dumps(data, separators=(",", ":"), ensure_ascii=False)
|
35
|
+
)
|
36
|
+
|
37
|
+
# 签名
|
38
|
+
mid_hash = md5_hex(f"{token}{now_ms}")[7:]
|
39
|
+
final_hash = md5_hex(f"{now_ms}{raw_body_for_sign}{mid_hash}")
|
40
|
+
|
41
|
+
# 设置 headers
|
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
|
+
)
|
52
|
+
|
53
|
+
# 更新 kwargs.body,保证发出去的与签名一致
|
54
|
+
kwargs.update({"data": raw_body_for_sign})
|
55
|
+
|
56
|
+
return args
|
57
|
+
|
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
|
+
)
|