rquote 0.4.9__py3-none-any.whl → 0.5.0__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.
rquote/api/price.py CHANGED
@@ -38,7 +38,7 @@ def _normalize_dataframe_index(df: pd.DataFrame) -> pd.DataFrame:
38
38
  return df
39
39
 
40
40
 
41
- def get_price(i: str, sdate: str = '', edate: str = '', freq: str = 'day',
41
+ def get_price(i: str, sdate: str = '', edate: str = '', freq: str = 'day',
42
42
  days: int = 320, fq: str = 'qfq', dd=None) -> Tuple[str, str, pd.DataFrame]:
43
43
  '''
44
44
  获取价格数据
@@ -84,19 +84,24 @@ def get_price(i: str, sdate: str = '', edate: str = '', freq: str = 'day',
84
84
  return symbol, name, df
85
85
 
86
86
 
87
- def get_price_longer(i: str, l: int = 2, dd=None) -> Tuple[str, str, pd.DataFrame]:
87
+ def get_price_longer(i: str, l: int = 2, edate: str = '', freq: str = 'day',
88
+ fq: str = 'qfq', dd=None) -> Tuple[str, str, pd.DataFrame]:
88
89
  """
89
90
  获取更长时间的历史数据
90
91
 
91
92
  Args:
92
93
  i: 股票代码
93
94
  l: 年数
95
+ edate: 结束日期,同 ``get_price``
96
+ freq: 频率,同 ``get_price``
97
+ fq: 复权方式,同 ``get_price``
94
98
  dd: 缓存对象
95
99
 
96
100
  Returns:
97
101
  (symbol, name, DataFrame)
98
102
  """
99
- _, name, a = get_price(i, dd=dd)
103
+ # 首段数据直接复用 get_price,透传 edate/freq/fq 参数
104
+ _, name, a = get_price(i, edate=edate, freq=freq, fq=fq, dd=dd)
100
105
  # 使用 DatetimeIndex 的格式化方法(get_price 已统一转换为 DatetimeIndex)
101
106
  if isinstance(a.index, pd.DatetimeIndex) and len(a.index) > 0:
102
107
  d1 = a.index[0].strftime('%Y%m%d')
@@ -104,12 +109,16 @@ def get_price_longer(i: str, l: int = 2, dd=None) -> Tuple[str, str, pd.DataFram
104
109
  # 降级处理:如果索引不是 DatetimeIndex(理论上不应该发生),尝试格式化
105
110
  try:
106
111
  d1 = str(a.index[0])[:8] if len(str(a.index[0])) >= 8 else str(a.index[0])
107
- except:
112
+ except Exception:
108
113
  d1 = a.index.format()[0] if hasattr(a.index, 'format') else str(a.index[0])
109
114
 
110
115
  for y in range(1, l):
111
116
  d0 = str(int(d1[:4]) - 1) + d1[4:]
112
- a = pd.concat((get_price(i, d0, d1, dd=dd)[2], a), 0).drop_duplicates()
117
+ # 逐年向前补数据,保持与 get_price 相同的 freq/fq 配置
118
+ a = pd.concat(
119
+ (get_price(i, d0, d1, freq=freq, fq=fq, dd=dd)[2], a),
120
+ 0
121
+ ).drop_duplicates()
113
122
  d1 = d0
114
123
  return i, name, a
115
124
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: rquote
3
- Version: 0.4.9
3
+ Version: 0.5.0
4
4
  Summary: Mostly day quotes of cn/hk/us/fund/future markets, side with quote list fetch
5
5
  Requires-Python: >=3.9.0
6
6
  Description-Content-Type: text/markdown
@@ -18,7 +18,7 @@ Requires-Dist: duckdb>=0.9.0; extra == "persistent"
18
18
 
19
19
  ## 版本信息
20
20
 
21
- 当前版本:**0.4.9**
21
+ 当前版本:**0.5.0**
22
22
 
23
23
  ## 主要特性
24
24
 
@@ -172,15 +172,18 @@ sid, nm, df = get_price('fuM2601', freq='min')
172
172
  | 2024-02-06 | 2680.48 | 2789.49 | 2802.93 | 2669.67 | 502849313 |
173
173
  | 2024-02-07 | 2791.51 | 2829.70 | 2829.70 | 2770.53 | 547117439 |
174
174
 
175
- #### `get_price_longer(i, l=2, dd={})`
175
+ #### `get_price_longer(i, l=2, edate='', freq='day', fq='qfq', dd=None)`
176
176
 
177
- 获取更长时间的历史数据,默认获取2年数据
177
+ 获取更长时间的历史数据,默认获取2年数据,并且参数与 `get_price` 保持一致
178
178
 
179
179
  ```python
180
180
  from rquote import get_price_longer
181
181
 
182
- # 获取3年的历史数据
182
+ # 获取3年的历史数据(默认日线、前复权,以最新交易日为结束)
183
183
  sid, nm, df = get_price_longer('sh000001', l=3)
184
+
185
+ # 指定结束日期与频率(例如获取到 2024-02-01 的周线数据)
186
+ sid, nm, df = get_price_longer('sh000001', l=3, edate='2024-02-01', freq='week', fq='qfq')
184
187
  ```
185
188
 
186
189
  ### 股票列表获取
@@ -238,8 +241,11 @@ zz1000_stocks = get_cnindex_stocks('zz1000')
238
241
 
239
242
  支持的指数类型:
240
243
  - `'hs300'`: 沪深300
244
+ - `'sz50'`: 上证50
241
245
  - `'zz500'`: 中证500
246
+ - `'kc500'`: 科创500
242
247
  - `'zz1000'`: 中证1000
248
+ - `'zz2000'`: 中证2000
243
249
 
244
250
  ### 基金和期货
245
251
 
@@ -5,7 +5,7 @@ rquote/plots.py,sha256=UQn4sjhIzVwagfhUDM738b2HHjKo4tRdU2UCs_1-FbY,2341
5
5
  rquote/utils.py,sha256=bH0ZFIo-ZelNztzPS6BXFShXE3yGA9USI_P9INN0Y-s,310
6
6
  rquote/api/__init__.py,sha256=17VgPOKsbQX8kKcuU8fKqn4qOHxMamV9GBTXTCcbdvw,706
7
7
  rquote/api/lists.py,sha256=uCOESePsrWGfY8gZE70aqk8xJS8nMqOK1dD8zTPrpi4,8676
8
- rquote/api/price.py,sha256=I5lZl6cUQRlE4AtzNbR-uGZt1ho9vgP1cgNFDjaigMA,3575
8
+ rquote/api/price.py,sha256=eBaoghKuXA3PRDJ2BHcRg2DGmg9XJEYYoJv1l0l9FGE,4025
9
9
  rquote/api/stock_info.py,sha256=h_AbgsR8CLWz5zA2PtGsS3ROQ3qcw_hnRAtG3USeMos,2988
10
10
  rquote/api/tick.py,sha256=nEcjuAjtBHUaD8KPRLg643piVa21PhKDQvkVWNwvvME,1431
11
11
  rquote/cache/__init__.py,sha256=S393I5Wmp0QooaRka9n7bvDUdEbg3jUhm6u815T86rM,317
@@ -33,7 +33,7 @@ rquote/utils/helpers.py,sha256=V07n9BtRS8bEJH023Kca78-unk7iD3B9hn2UjELetYs,354
33
33
  rquote/utils/http.py,sha256=X0Alhnu0CNqyQeOt6ivUWmh2XwrWxXd2lSpQOKDdnzw,3249
34
34
  rquote/utils/logging.py,sha256=fs2YF1Srux4LLTdk_Grjm5g1f4mzewI38VVSAI82goA,1471
35
35
  rquote/utils/web.py,sha256=I8_pcThW6VUvahuRHdtp32iZwr85hEt1hB6TgznMy_U,3854
36
- rquote-0.4.9.dist-info/METADATA,sha256=QjWXGAaetxCapZOpA6GZHR-NykNLKSnZRJ6hStkVNwc,14478
37
- rquote-0.4.9.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
38
- rquote-0.4.9.dist-info/top_level.txt,sha256=CehAiaZx7Fo8HGoV2zd5GhILUW1jQEN8YS-cWMlrK9Y,7
39
- rquote-0.4.9.dist-info/RECORD,,
36
+ rquote-0.5.0.dist-info/METADATA,sha256=eZd_daJo1pDFuvvdubNSdFRotFh6mqv8xK8n6tfbtV8,14854
37
+ rquote-0.5.0.dist-info/WHEEL,sha256=wUyA8OaulRlbfwMtmQsvNngGrxQHAvkKcvRmdizlJi0,92
38
+ rquote-0.5.0.dist-info/top_level.txt,sha256=CehAiaZx7Fo8HGoV2zd5GhILUW1jQEN8YS-cWMlrK9Y,7
39
+ rquote-0.5.0.dist-info/RECORD,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: setuptools (80.9.0)
2
+ Generator: setuptools (80.10.2)
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
5
5