akshare 1.14.38__py3-none-any.whl → 1.14.39__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.
akshare/__init__.py CHANGED
@@ -2849,9 +2849,10 @@ amac_manager_cancelled_info # 中国证券投资基金业协会-信息公示-诚
2849
2849
  1.14.36 fix: fix option_czce_daily interface
2850
2850
  1.14.37 fix: fix stock_zh_kcb_report_em interface
2851
2851
  1.14.38 fix: fix stock_industry_clf_hist_sw interface
2852
+ 1.14.39 fix: fix stock_zh_b_daily interface
2852
2853
  """
2853
2854
 
2854
- __version__ = "1.14.38"
2855
+ __version__ = "1.14.39"
2855
2856
  __author__ = "AKFamily"
2856
2857
 
2857
2858
  import sys
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env python
2
2
  # -*- coding:utf-8 -*-
3
3
  """
4
- Date: 2023/7/20 13:28
4
+ Date: 2024/7/22 18:30
5
5
  Desc: 新浪财经-B股-实时行情数据和历史行情数据(包含前复权和后复权因子)
6
6
  https://finance.sina.com.cn/realstock/company/sh689009/nc.shtml
7
7
  """
@@ -33,7 +33,10 @@ def _get_zh_b_page_count() -> int:
33
33
  :return: 需要采集的股票总页数
34
34
  :rtype: int
35
35
  """
36
- url = "https://vip.stock.finance.sina.com.cn/quotes_service/api/json_v2.php/Market_Center.getHQNodeStockCount?node=hs_b"
36
+ url = (
37
+ "https://vip.stock.finance.sina.com.cn/quotes_service/api/json_v2.php/"
38
+ "Market_Center.getHQNodeStockCount?node=hs_b"
39
+ )
37
40
  r = requests.get(url)
38
41
  page_count = int(re.findall(re.compile(r"\d+"), r.text)[0]) / 80
39
42
  if isinstance(page_count, int):
@@ -45,7 +48,7 @@ def _get_zh_b_page_count() -> int:
45
48
  def stock_zh_b_spot() -> pd.DataFrame:
46
49
  """
47
50
  新浪财经-所有 B 股的实时行情数据; 重复运行本函数会被新浪暂时封 IP
48
- https://vip.stock.finance.sina.com.cn/mkt/#qbgg_hk
51
+ https://vip.stock.finance.sina.com.cn/mkt/#hs_b
49
52
  :return: 所有股票的实时行情数据
50
53
  :rtype: pandas.DataFrame
51
54
  """
@@ -64,7 +67,7 @@ def stock_zh_b_spot() -> pd.DataFrame:
64
67
  zh_sina_stock_payload_copy.update({"page": page})
65
68
  r = requests.get(zh_sina_a_stock_url, params=zh_sina_stock_payload_copy)
66
69
  data_json = demjson.decode(r.text)
67
- big_df = pd.concat([big_df, pd.DataFrame(data_json)], ignore_index=True)
70
+ big_df = pd.concat(objs=[big_df, pd.DataFrame(data_json)], ignore_index=True)
68
71
  big_df.columns = [
69
72
  "代码",
70
73
  "_",
@@ -126,7 +129,7 @@ def stock_zh_b_daily(
126
129
  ) -> pd.DataFrame:
127
130
  """
128
131
  新浪财经-B 股-个股的历史行情数据, 大量抓取容易封 IP
129
- https://finance.sina.com.cn/realstock/company/sh689009/nc.shtml
132
+ https://finance.sina.com.cn/realstock/company/sh900901/nc.shtml
130
133
  :param start_date: 20201103; 开始日期
131
134
  :type start_date: str
132
135
  :param end_date: 20201103; 结束日期
@@ -141,9 +144,9 @@ def stock_zh_b_daily(
141
144
 
142
145
  def _fq_factor(method: str) -> pd.DataFrame:
143
146
  if method == "hfq":
144
- res = requests.get(zh_sina_a_stock_hfq_url.format(symbol))
147
+ r = requests.get(zh_sina_a_stock_hfq_url.format(symbol))
145
148
  hfq_factor_df = pd.DataFrame(
146
- eval(res.text.split("=")[1].split("\n")[0])["data"]
149
+ eval(r.text.split("=")[1].split("\n")[0])["data"]
147
150
  )
148
151
  if hfq_factor_df.shape[0] == 0:
149
152
  raise ValueError("sina hfq factor not available")
@@ -153,9 +156,9 @@ def stock_zh_b_daily(
153
156
  hfq_factor_df.reset_index(inplace=True)
154
157
  return hfq_factor_df
155
158
  else:
156
- res = requests.get(zh_sina_a_stock_qfq_url.format(symbol))
159
+ r = requests.get(zh_sina_a_stock_qfq_url.format(symbol))
157
160
  qfq_factor_df = pd.DataFrame(
158
- eval(res.text.split("=")[1].split("\n")[0])["data"]
161
+ eval(r.text.split("=")[1].split("\n")[0])["data"]
159
162
  )
160
163
  if qfq_factor_df.shape[0] == 0:
161
164
  raise ValueError("sina hfq factor not available")
@@ -168,15 +171,18 @@ def stock_zh_b_daily(
168
171
  if adjust in ("hfq-factor", "qfq-factor"):
169
172
  return _fq_factor(adjust.split("-")[0])
170
173
 
171
- res = requests.get(zh_sina_a_stock_hist_url.format(symbol))
174
+ r = requests.get(zh_sina_a_stock_hist_url.format(symbol))
172
175
  js_code = py_mini_racer.MiniRacer()
173
176
  js_code.eval(hk_js_decode)
174
177
  dict_list = js_code.call(
175
- "d", res.text.split("=")[1].split(";")[0].replace('"', "")
178
+ "d", r.text.split("=")[1].split(";")[0].replace('"', "")
176
179
  ) # 执行js解密代码
177
180
  data_df = pd.DataFrame(dict_list)
178
181
  data_df.index = pd.to_datetime(data_df["date"]).dt.date
179
182
  del data_df["date"]
183
+ del data_df["amount"]
184
+ del data_df["prevclose"]
185
+
180
186
  data_df = data_df.astype("float")
181
187
  r = requests.get(zh_sina_a_stock_amount_url.format(symbol, symbol))
182
188
  amount_data_json = demjson.decode(r.text[r.text.find("[") : r.text.rfind("]") + 1])
@@ -186,15 +192,7 @@ def stock_zh_b_daily(
186
192
  temp_df = pd.merge(
187
193
  data_df, amount_data_df, left_index=True, right_index=True, how="outer"
188
194
  )
189
- try:
190
- # try for pandas >= 2.1.0
191
- temp_df.ffill(inplace=True)
192
- except Exception:
193
- try:
194
- # try for pandas < 2.1.0
195
- temp_df.fillna(method="ffill", inplace=True)
196
- except Exception as e:
197
- print("Error:", e)
195
+ temp_df.ffill(inplace=True)
198
196
  temp_df = temp_df.astype(float)
199
197
  temp_df["amount"] = temp_df["amount"] * 10000
200
198
  temp_df["turnover"] = temp_df["volume"] / temp_df["amount"]
@@ -222,25 +220,15 @@ def stock_zh_b_daily(
222
220
  return temp_df
223
221
 
224
222
  if adjust == "hfq":
225
- res = requests.get(zh_sina_a_stock_hfq_url.format(symbol))
226
- hfq_factor_df = pd.DataFrame(
227
- eval(res.text.split("=")[1].split("\n")[0])["data"]
228
- )
223
+ r = requests.get(zh_sina_a_stock_hfq_url.format(symbol))
224
+ hfq_factor_df = pd.DataFrame(eval(r.text.split("=")[1].split("\n")[0])["data"])
229
225
  hfq_factor_df.columns = ["date", "hfq_factor"]
230
226
  hfq_factor_df.index = pd.to_datetime(hfq_factor_df.date)
231
227
  del hfq_factor_df["date"]
232
228
  temp_df = pd.merge(
233
229
  temp_df, hfq_factor_df, left_index=True, right_index=True, how="outer"
234
230
  )
235
- try:
236
- # try for pandas >= 2.1.0
237
- temp_df.ffill(inplace=True)
238
- except Exception:
239
- try:
240
- # try for pandas < 2.1.0
241
- temp_df.fillna(method="ffill", inplace=True)
242
- except Exception as e:
243
- print("Error:", e)
231
+ temp_df.ffill(inplace=True)
244
232
  temp_df = temp_df.astype(float)
245
233
  temp_df.dropna(inplace=True)
246
234
  temp_df.drop_duplicates(
@@ -261,26 +249,15 @@ def stock_zh_b_daily(
261
249
  return temp_df
262
250
 
263
251
  if adjust == "qfq":
264
- res = requests.get(zh_sina_a_stock_qfq_url.format(symbol))
265
- qfq_factor_df = pd.DataFrame(
266
- eval(res.text.split("=")[1].split("\n")[0])["data"]
267
- )
252
+ r = requests.get(zh_sina_a_stock_qfq_url.format(symbol))
253
+ qfq_factor_df = pd.DataFrame(eval(r.text.split("=")[1].split("\n")[0])["data"])
268
254
  qfq_factor_df.columns = ["date", "qfq_factor"]
269
255
  qfq_factor_df.index = pd.to_datetime(qfq_factor_df.date)
270
256
  del qfq_factor_df["date"]
271
-
272
257
  temp_df = pd.merge(
273
258
  temp_df, qfq_factor_df, left_index=True, right_index=True, how="outer"
274
259
  )
275
- try:
276
- # try for pandas >= 2.1.0
277
- temp_df.ffill(inplace=True)
278
- except Exception:
279
- try:
280
- # try for pandas < 2.1.0
281
- temp_df.fillna(method="ffill", inplace=True)
282
- except Exception as e:
283
- print("Error:", e)
260
+ temp_df.ffill(inplace=True)
284
261
  temp_df = temp_df.astype(float)
285
262
  temp_df.dropna(inplace=True)
286
263
  temp_df.drop_duplicates(
@@ -322,13 +299,12 @@ def stock_zh_b_minute(
322
299
  params = {
323
300
  "symbol": symbol,
324
301
  "scale": period,
325
- "datalen": "20000",
302
+ "datalen": "1970",
326
303
  }
327
304
  r = requests.get(url, params=params)
328
305
  temp_df = pd.DataFrame(json.loads(r.text.split("=(")[1].split(");")[0])).iloc[:, :6]
329
306
  if temp_df.empty:
330
- print(f"{symbol} 股票数据不存在,请检查是否已退市")
331
- return None
307
+ return pd.DataFrame()
332
308
  try:
333
309
  stock_zh_b_daily(symbol=symbol, adjust="qfq")
334
310
  except: # noqa: E722
@@ -396,7 +372,7 @@ if __name__ == "__main__":
396
372
  print(stock_zh_b_daily_hfq_df_one)
397
373
 
398
374
  stock_zh_b_daily_hfq_df_three = stock_zh_b_daily(
399
- symbol="sh900901", start_date="19900103", end_date="20210118", adjust="qfq"
375
+ symbol="sh900901", start_date="19900103", end_date="20240722", adjust="hfq"
400
376
  )
401
377
  print(stock_zh_b_daily_hfq_df_three)
402
378
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: akshare
3
- Version: 1.14.38
3
+ Version: 1.14.39
4
4
  Summary: AKShare is an elegant and simple financial data interface library for Python, built for human beings!
5
5
  Home-page: https://github.com/akfamily/akshare
6
6
  Author: AKFamily
@@ -1,4 +1,4 @@
1
- akshare/__init__.py,sha256=KuVHbQrRpRIbDiULhOy24EbaR_mq9xB-zwnQavPdRmo,179699
1
+ akshare/__init__.py,sha256=wa7kk7t3wz4KGFZsDd4wdPRXTY0mRVJw_Q3Az_7hbco,179743
2
2
  akshare/datasets.py,sha256=oIu1zC7o_LMHY22lQmdM7vCnryHibKrJLBqJwQiitlI,1167
3
3
  akshare/air/__init__.py,sha256=RMTf1bT5EOE3ttWpn3hGu1LtUmsVxDoa0W7W0gXHOy8,81
4
4
  akshare/air/air_hebei.py,sha256=xIXNGLK7IGYqrkteM9fxnHAwWqk6PCQs6D9-ggZ7byY,4442
@@ -281,7 +281,7 @@ akshare/stock/stock_zh_a_sina.py,sha256=gryRmUwqF9PyNl-fPhD72y5nfNmLVEnvzjZDhAe-
281
281
  akshare/stock/stock_zh_a_special.py,sha256=RRXkeZtRWm_maIPWgxvhBdX6eNybECjhSuEesZHRFJI,10294
282
282
  akshare/stock/stock_zh_a_tick_tx.py,sha256=TJUAWLKAeoLEaVVJQlj0t-1smZGoAO0X0rPsUPVhZZ4,2131
283
283
  akshare/stock/stock_zh_ah_tx.py,sha256=nq-dFlgHcgFS8in4HsbGyACTjfSTcixLaJC0yrQccbQ,9204
284
- akshare/stock/stock_zh_b_sina.py,sha256=91qUf8o5unDfK2en9-aVurm6obR6EZ_dXwlSBjUq3PE,16883
284
+ akshare/stock/stock_zh_b_sina.py,sha256=fF0D8ADXD2BmSy_CYi0enxSZs1wahJ18tODA6jGzmVY,16058
285
285
  akshare/stock/stock_zh_kcb_report.py,sha256=7zRovNGqXrPIYtUj9C3ivlYzfiudkaeBNiYPYlzDWkQ,2914
286
286
  akshare/stock/stock_zh_kcb_sina.py,sha256=rpEOkqaOX5ebjs8B3teA1npBL8DpCQQXH8GRFu1ZY6o,9804
287
287
  akshare/stock_feature/__init__.py,sha256=c2VDBGyg8nWZYLvtnnSqUoQ92Cu6dJ7UFOeJsB2Gff8,82
@@ -380,8 +380,8 @@ akshare/utils/token_process.py,sha256=K4rGXjh_tgugbRcyOK2h2x0jP3PT65IIK7nxhUKhOe
380
380
  akshare/utils/tqdm.py,sha256=MuPNwcswkOGjwWQOMWXi9ZvQ_RmW4obCWRj2i7HM7FE,847
381
381
  tests/__init__.py,sha256=gNzhlO0UPjFq6Ieb38kaVIODXv4cTDByrdohAZnDYt4,82
382
382
  tests/test_func.py,sha256=tfvy_YnYmDra2dkKZ5JvprU1gNW5X9T634PszdSdH1A,944
383
- akshare-1.14.38.dist-info/LICENSE,sha256=mmSZCPgfHiVw34LXuFArd-SUgQtBJ_QsIlh-kWlDHfs,1073
384
- akshare-1.14.38.dist-info/METADATA,sha256=3gcrwAnoUB81SWms6E7pG9zAZRLRehbvq0v_aeJ-7fE,13976
385
- akshare-1.14.38.dist-info/WHEEL,sha256=Wyh-_nZ0DJYolHNn1_hMa4lM7uDedD_RGVwbmTjyItk,91
386
- akshare-1.14.38.dist-info/top_level.txt,sha256=jsf9ZzZPmHaISTVumQPsAw7vv7Yv-PdEVW70SMEelQQ,14
387
- akshare-1.14.38.dist-info/RECORD,,
383
+ akshare-1.14.39.dist-info/LICENSE,sha256=mmSZCPgfHiVw34LXuFArd-SUgQtBJ_QsIlh-kWlDHfs,1073
384
+ akshare-1.14.39.dist-info/METADATA,sha256=qxv-2dm72_INlEhq1CUTsLS5Z8CfaaStqpqr0NuSYHM,13976
385
+ akshare-1.14.39.dist-info/WHEEL,sha256=Wyh-_nZ0DJYolHNn1_hMa4lM7uDedD_RGVwbmTjyItk,91
386
+ akshare-1.14.39.dist-info/top_level.txt,sha256=jsf9ZzZPmHaISTVumQPsAw7vv7Yv-PdEVW70SMEelQQ,14
387
+ akshare-1.14.39.dist-info/RECORD,,