hyperquant 0.1.2__py3-none-any.whl → 0.1.3__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.
@@ -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()
@@ -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
@@ -0,0 +1,10 @@
1
+ hyperquant/__init__.py,sha256=ogwPnRZdsCG5VqMpb_BOtmsKW64G9YmZ7t4AMGttLAE,108
2
+ hyperquant/core.py,sha256=vKv8KElo1eGhr_aw0I-j6ZxPOneDx86KqAoOI-wbq0A,18838
3
+ hyperquant/draw.py,sha256=jweENVzf0nWHogzUliwJHI2PgbeQ3V2H749cMJ256k0,54614
4
+ hyperquant/logkit.py,sha256=WALpXpIA3Ywr5DxKKK3k5EKubZ2h-ISGfc5dUReQUBQ,7795
5
+ hyperquant/datavison/_util.py,sha256=92qk4vO856RqycO0YqEIHJlEg-W9XKapDVqAMxe6rbw,533
6
+ hyperquant/datavison/binance.py,sha256=r6GzIDBTyOEpyZsWy7zWV8qUUVvVrsdyXeci8py98Os,2651
7
+ hyperquant/datavison/coinglass.py,sha256=PEjdjISP9QUKD_xzXNzhJ9WFDTlkBrRQlVL-5pxD5mo,10482
8
+ hyperquant-0.1.3.dist-info/METADATA,sha256=NBrXAtEpamDFslToJbaBnr_LuerjxEQ4B-eBeLzJouQ,4258
9
+ hyperquant-0.1.3.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
10
+ hyperquant-0.1.3.dist-info/RECORD,,
@@ -1,8 +0,0 @@
1
- hyperquant/__init__.py,sha256=ogwPnRZdsCG5VqMpb_BOtmsKW64G9YmZ7t4AMGttLAE,108
2
- hyperquant/core.py,sha256=vKv8KElo1eGhr_aw0I-j6ZxPOneDx86KqAoOI-wbq0A,18838
3
- hyperquant/draw.py,sha256=jweENVzf0nWHogzUliwJHI2PgbeQ3V2H749cMJ256k0,54614
4
- hyperquant/logkit.py,sha256=WALpXpIA3Ywr5DxKKK3k5EKubZ2h-ISGfc5dUReQUBQ,7795
5
- hyperquant/datavison/coinglass.py,sha256=6kh1S2R1jINFvneUSzXkFksbQcWmJJNT_dzt0yZ-zxk,10492
6
- hyperquant-0.1.2.dist-info/METADATA,sha256=svaRs3u6gLXQoz9-_ukmrMZBjxSV9e3y_4bcjLVJzes,4229
7
- hyperquant-0.1.2.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
8
- hyperquant-0.1.2.dist-info/RECORD,,