hyperquant 0.1.5__tar.gz → 0.1.7__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.5
3
+ Version: 0.1.7
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
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "hyperquant"
3
- version = "0.1.5"
3
+ version = "0.1.7"
4
4
  description = "A minimal yet hyper-efficient backtesting framework for quantitative trading"
5
5
  authors = [
6
6
  { name = "MissinA", email = "1421329142@qq.com" }
@@ -60,3 +60,52 @@ class BinanceSwap:
60
60
  df["number_of_trades"] = df["number_of_trades"].astype(int)
61
61
  return df
62
62
 
63
+ async def get_index_klines(self, pair: str, interval: str, start_time, end_time=None, limit: int = 1500):
64
+ """
65
+ 获取U本位合约指数K线数据,支持获取任意长度(自动分批)
66
+
67
+ :param pair: 指数对, 如 'BTCUSDT'
68
+ :param interval: K线间隔, 如 '1m', '5m', '1h', '1d'
69
+ :param start_time: 开始时间, 毫秒时间戳或datetime/date类型
70
+ :param end_time: 结束时间, 毫秒时间戳或datetime/date类型, 默认为None表示最新
71
+ :param limit: 每次请求最大K线数量, 最大1500
72
+ :return: 指数K线数据DataFrame
73
+ """
74
+ url = "https://fapi.binance.com/fapi/v1/indexPriceKlines"
75
+ all_klines = []
76
+ fetch_start = _to_milliseconds(start_time)
77
+ ms_end_time = _to_milliseconds(end_time) if end_time else None
78
+ while True:
79
+ params = {
80
+ "pair": pair.upper(),
81
+ "interval": interval,
82
+ "startTime": fetch_start,
83
+ "limit": limit
84
+ }
85
+ if ms_end_time:
86
+ params["endTime"] = ms_end_time
87
+ async with self.session.get(url, params=params) as resp:
88
+ resp.raise_for_status()
89
+ data = await resp.json()
90
+ if not data:
91
+ break
92
+ all_klines.extend(data)
93
+ if len(data) < limit:
94
+ break
95
+ last_open_time = data[-1][0]
96
+ fetch_start = last_open_time + 1
97
+ if ms_end_time and fetch_start >= ms_end_time:
98
+ break
99
+ columns = [
100
+ "open_time", "open", "high", "low", "close", "volume",
101
+ "close_time", "quote_asset_volume", "number_of_trades",
102
+ "taker_buy_base_asset_volume", "taker_buy_quote_asset_volume", "ignore"
103
+ ]
104
+ df = pd.DataFrame(all_klines, columns=columns)
105
+ df["open_time"] = pd.to_datetime(df["open_time"], unit="ms")
106
+ df["close_time"] = pd.to_datetime(df["close_time"], unit="ms")
107
+ for col in ["open", "high", "low", "close", "volume", "quote_asset_volume", "taker_buy_base_asset_volume", "taker_buy_quote_asset_volume"]:
108
+ df[col] = pd.to_numeric(df[col], errors="coerce")
109
+ df["number_of_trades"] = df["number_of_trades"].astype(int)
110
+ return df
111
+
@@ -35,7 +35,7 @@ if __name__ == "__main__":
35
35
  # 新增时间参数例子
36
36
  start_date = datetime.now() - timedelta(minutes=5)
37
37
  end_date = datetime.now()
38
- klines = await swap.get_klines(symbol, interval, start_date, end_date)
38
+ klines = await swap.get_index_klines(symbol, interval, start_date, end_date)
39
39
 
40
40
  print(klines)
41
41
 
@@ -482,7 +482,7 @@ wheels = [
482
482
 
483
483
  [[package]]
484
484
  name = "hyperquant"
485
- version = "0.1.4"
485
+ version = "0.1.6"
486
486
  source = { editable = "." }
487
487
  dependencies = [
488
488
  { name = "aiohttp" },
File without changes
File without changes
File without changes
File without changes
File without changes