hyperquant 0.1.2__tar.gz → 0.1.3__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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: hyperquant
3
- Version: 0.1.2
3
+ Version: 0.1.3
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
@@ -12,10 +12,11 @@ Classifier: Intended Audience :: Developers
12
12
  Classifier: License :: OSI Approved :: MIT License
13
13
  Classifier: Programming Language :: Python :: 3
14
14
  Classifier: Topic :: Office/Business :: Financial :: Investment
15
- Requires-Python: >=3.8
15
+ Requires-Python: >=3.9
16
16
  Requires-Dist: aiohttp>=3.11.16
17
17
  Requires-Dist: colorama>=0.4.6
18
18
  Requires-Dist: cryptography>=44.0.2
19
+ Requires-Dist: numpy>=1.21.0
19
20
  Requires-Dist: pandas>=2.2.3
20
21
  Requires-Dist: pyecharts>=2.0.8
21
22
  Description-Content-Type: text/markdown
@@ -3,11 +3,11 @@ echo "清理旧的构建文件..."
3
3
  rm -rf dist/* build/*
4
4
 
5
5
  echo "重新构建包..."
6
- rye build
6
+ uv build
7
7
 
8
8
  echo "发布到 PyPI..."
9
9
  # 从 .pypirc 文件读取 token
10
10
  TOKEN=$(grep "password" .pypirc | cut -d "=" -f2 | tr -d ' ')
11
11
 
12
12
  # 使用 token 发布
13
- TWINE_USERNAME=__token__ TWINE_PASSWORD=$TOKEN rye run twine upload dist/*
13
+ TWINE_USERNAME=__token__ TWINE_PASSWORD=$TOKEN uv run twine upload dist/*
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "hyperquant"
3
- version = "0.1.2"
3
+ version = "0.1.3"
4
4
  description = "A minimal yet hyper-efficient backtesting framework for quantitative trading"
5
5
  authors = [
6
6
  { name = "MissinA", email = "1421329142@qq.com" }
@@ -11,9 +11,10 @@ dependencies = [
11
11
  "colorama>=0.4.6",
12
12
  "aiohttp>=3.11.16",
13
13
  "cryptography>=44.0.2",
14
+ "numpy>=1.21.0", # Added numpy as a new dependency
14
15
  ]
15
16
  readme = "README.md"
16
- requires-python = ">= 3.8"
17
+ requires-python = ">= 3.9"
17
18
  keywords = ["quant", "backtesting", "trading", "hyperquant"]
18
19
  license = {text = "MIT"}
19
20
  classifiers = [
@@ -32,12 +33,13 @@ Issues = "https://github.com/yourusername/hyperquant/issues"
32
33
  requires = ["hatchling"]
33
34
  build-backend = "hatchling.build"
34
35
 
35
- [tool.rye]
36
- managed = true
37
- dev-dependencies = ["twine>=6.1.0"]
38
-
39
36
  [tool.hatch.metadata]
40
37
  allow-direct-references = true
41
38
 
42
39
  [tool.hatch.build.targets.wheel]
43
40
  packages = ["src/hyperquant"]
41
+
42
+ [dependency-groups]
43
+ dev = [
44
+ "twine>=6.1.0",
45
+ ]
@@ -0,0 +1,18 @@
1
+ from datetime import date, datetime
2
+
3
+
4
+ def _to_milliseconds( t):
5
+ """
6
+ 支持毫秒时间戳或datetime/date类型,返回毫秒时间戳
7
+ """
8
+ if t is None:
9
+ return None
10
+ if isinstance(t, int):
11
+ return t
12
+ if isinstance(t, float):
13
+ return int(t * 1000)
14
+ if isinstance(t, datetime):
15
+ return int(t.timestamp() * 1000)
16
+ if isinstance(t, date):
17
+ return int(datetime.combine(t, datetime.min.time()).timestamp() * 1000)
18
+ raise ValueError(f"不支持的时间类型: {type(t)}")
@@ -0,0 +1,62 @@
1
+ import aiohttp
2
+ import asyncio
3
+ from datetime import datetime, date, timedelta
4
+ # from _util import _to_milliseconds
5
+ from ._util import _to_milliseconds
6
+ import pandas as pd
7
+
8
+ class BinanceSwap:
9
+ def __init__(self) -> None:
10
+ self.session = aiohttp.ClientSession()
11
+
12
+ async def get_klines(self, symbol: str, interval: str, start_time, end_time = None, limit: int = 1500):
13
+ """
14
+ 获取U本位合约K线数据,支持获取任意长度(自动分批)
15
+
16
+ :param symbol: 交易对, 如 'BTCUSDT'
17
+ :param interval: K线间隔, 如 '1m', '5m', '1h', '1d'
18
+ :param start_time: 开始时间, 毫秒时间戳或datetime/date类型
19
+ :param end_time: 结束时间, 毫秒时间戳或datetime/date类型, 默认为None表示最新
20
+ :param limit: 每次请求最大K线数量, 最大1500
21
+ :return: K线数据DataFrame
22
+ """
23
+ url = "https://fapi.binance.com/fapi/v1/klines"
24
+ all_klines = []
25
+ fetch_start = _to_milliseconds(start_time)
26
+ ms_end_time = _to_milliseconds(end_time) if end_time else None
27
+ while True:
28
+ params = {
29
+ "symbol": symbol.upper(),
30
+ "interval": interval,
31
+ "startTime": fetch_start,
32
+ "limit": limit
33
+ }
34
+ if ms_end_time:
35
+ params["endTime"] = ms_end_time
36
+ async with self.session.get(url, params=params) as resp:
37
+ resp.raise_for_status()
38
+ data = await resp.json()
39
+ if not data:
40
+ break
41
+ all_klines.extend(data)
42
+ if len(data) < limit:
43
+ break
44
+ last_open_time = data[-1][0]
45
+ fetch_start = last_open_time + 1
46
+ if ms_end_time and fetch_start >= ms_end_time:
47
+ break
48
+ # 转为DataFrame
49
+ columns = [
50
+ "open_time", "open", "high", "low", "close", "volume",
51
+ "close_time", "quote_asset_volume", "number_of_trades",
52
+ "taker_buy_base_asset_volume", "taker_buy_quote_asset_volume", "ignore"
53
+ ]
54
+ df = pd.DataFrame(all_klines, columns=columns)
55
+ # 类型转换
56
+ df["open_time"] = pd.to_datetime(df["open_time"], unit="ms")
57
+ df["close_time"] = pd.to_datetime(df["close_time"], unit="ms")
58
+ for col in ["open", "high", "low", "close", "volume", "quote_asset_volume", "taker_buy_base_asset_volume", "taker_buy_quote_asset_volume"]:
59
+ df[col] = pd.to_numeric(df[col], errors="coerce")
60
+ df["number_of_trades"] = df["number_of_trades"].astype(int)
61
+ return df
62
+
@@ -16,8 +16,7 @@ import hmac
16
16
  import hashlib
17
17
  from datetime import datetime, timedelta
18
18
  from typing import Any, Dict, List, Optional, Union
19
-
20
- import pandas as pd
19
+ import pandas as pd # type: ignore
21
20
  from cryptography.hazmat.primitives.ciphers import Cipher, algorithms, modes
22
21
  from cryptography.hazmat.primitives import padding as crypto_padding
23
22
  from cryptography.hazmat.backends import default_backend
@@ -230,7 +229,6 @@ class CoinglassApi:
230
229
  # ------------------ 主程序 ------------------
231
230
  async def main():
232
231
  api = CoinglassApi()
233
- await api.connect()
234
232
  df = await api.fetch_price_klines('Binance_BTCUSDT', datetime.now() - timedelta(days=1))
235
233
  print(df)
236
234
  await api.stop()
@@ -0,0 +1,44 @@
1
+ # import asyncio
2
+ # from datetime import datetime, timedelta
3
+ # from src.hyperquant.core import Exchange
4
+ # from src.hyperquant.datavison.coinglass import CoinglassApi
5
+
6
+
7
+ # async def main():
8
+ # api = CoinglassApi()
9
+ # await api.connect()
10
+ # df = await api.fetch_price_klines('Binance_BTCUSDT', datetime.now() - timedelta(days=1))
11
+ # print(df)
12
+ # await api.stop()
13
+
14
+ # if __name__ == '__main__':
15
+ # asyncio.run(main())
16
+
17
+
18
+ import asyncio
19
+ from datetime import datetime, timedelta
20
+ from hyperquant.datavison.binance import BinanceSwap
21
+
22
+
23
+ if __name__ == "__main__":
24
+ import time
25
+
26
+ async def main():
27
+ symbol = "BTCUSDT"
28
+ interval = "1m"
29
+ # 取最近10分钟的K线
30
+ end_time = int(time.time() * 1000)
31
+ start_time = end_time - 10 * 60 * 1000
32
+ swap = BinanceSwap()
33
+
34
+
35
+ # 新增时间参数例子
36
+ start_date = datetime.now() - timedelta(minutes=5)
37
+ end_date = datetime.now()
38
+ klines = await swap.get_klines(symbol, interval, start_date, end_date)
39
+
40
+ print(klines)
41
+
42
+ await swap.session.close()
43
+
44
+ asyncio.run(main())