akshare 1.12.99__py3-none-any.whl → 1.15.73__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.

Potentially problematic release.


This version of akshare might be problematic. Click here for more details.

Files changed (236) hide show
  1. akshare/__init__.py +442 -138
  2. akshare/air/air_hebei.py +79 -53
  3. akshare/air/air_zhenqi.py +29 -43
  4. akshare/air/sunrise_tad.py +32 -17
  5. akshare/bank/bank_cbirc_2020.py +12 -9
  6. akshare/bond/bond_cb_ths.py +17 -9
  7. akshare/bond/bond_china.py +38 -39
  8. akshare/bond/bond_china_money.py +75 -48
  9. akshare/bond/bond_info_cm.py +28 -8
  10. akshare/bond/bond_issue_cninfo.py +73 -30
  11. akshare/bond/bond_zh_cov.py +1 -1
  12. akshare/bond/bond_zh_sina.py +57 -51
  13. akshare/cal/__init__.py +0 -0
  14. akshare/cal/rv.py +170 -0
  15. akshare/cost/cost_living.py +7 -5
  16. akshare/currency/currency_safe.py +7 -6
  17. akshare/data/cninfo.js +15 -0
  18. akshare/datasets.py +10 -21
  19. akshare/economic/macro_bank.py +95 -653
  20. akshare/economic/macro_china.py +772 -1024
  21. akshare/economic/macro_china_hk.py +65 -243
  22. akshare/economic/macro_china_nbs.py +24 -7
  23. akshare/economic/macro_constitute.py +17 -12
  24. akshare/economic/macro_euro.py +13 -6
  25. akshare/economic/macro_finance_ths.py +133 -0
  26. akshare/economic/macro_info_ws.py +100 -0
  27. akshare/economic/macro_japan.py +5 -4
  28. akshare/economic/macro_other.py +12 -9
  29. akshare/economic/macro_usa.py +376 -1940
  30. akshare/economic/marco_cnbs.py +11 -6
  31. akshare/energy/energy_carbon.py +94 -125
  32. akshare/event/migration.py +3 -2
  33. akshare/exceptions.py +43 -0
  34. akshare/file_fold/calendar.json +245 -2
  35. akshare/fortune/fortune_500.py +15 -48
  36. akshare/fund/fund_amac.py +157 -75
  37. akshare/fund/fund_em.py +191 -184
  38. akshare/fund/fund_etf_em.py +16 -15
  39. akshare/fund/fund_etf_sina.py +71 -23
  40. akshare/fund/fund_etf_ths.py +93 -0
  41. akshare/fund/fund_fee_em.py +98 -0
  42. akshare/fund/fund_portfolio_em.py +60 -50
  43. akshare/fund/fund_rank_em.py +91 -82
  44. akshare/fund/fund_report_cninfo.py +63 -48
  45. akshare/fund/fund_scale_sina.py +20 -10
  46. akshare/fund/fund_xq.py +139 -109
  47. akshare/futures/cons.py +8 -31
  48. akshare/futures/cot.py +185 -137
  49. akshare/futures/futures_basis.py +97 -32
  50. akshare/futures/futures_comm_ctp.py +37 -0
  51. akshare/futures/futures_comm_qihuo.py +74 -45
  52. akshare/futures/futures_daily_bar.py +121 -184
  53. akshare/futures/futures_hf_em.py +66 -61
  54. akshare/futures/futures_hq_sina.py +79 -61
  55. akshare/futures/futures_index_ccidx.py +6 -3
  56. akshare/futures/futures_inventory_99.py +61 -272
  57. akshare/futures/futures_news_shmet.py +4 -2
  58. akshare/futures/futures_roll_yield.py +12 -25
  59. akshare/futures/futures_spot_stock_em.py +19 -13
  60. akshare/futures/futures_stock_js.py +14 -12
  61. akshare/futures/futures_to_spot.py +38 -33
  62. akshare/futures/futures_warehouse_receipt.py +75 -71
  63. akshare/futures/futures_zh_sina.py +5 -5
  64. akshare/futures/symbol_var.py +18 -13
  65. akshare/futures_derivative/futures_contract_info_czce.py +60 -52
  66. akshare/futures_derivative/futures_contract_info_ine.py +43 -34
  67. akshare/futures_derivative/futures_contract_info_shfe.py +46 -35
  68. akshare/futures_derivative/futures_cot_sina.py +26 -19
  69. akshare/futures_derivative/futures_spot_sys.py +21 -8
  70. akshare/fx/currency_investing.py +19 -285
  71. akshare/index/index_cflp.py +29 -26
  72. akshare/index/index_cni.py +86 -88
  73. akshare/index/index_cons.py +26 -10
  74. akshare/index/index_cx.py +248 -47
  75. akshare/index/index_drewry.py +17 -16
  76. akshare/index/index_option_qvix.py +329 -0
  77. akshare/index/index_research_fund_sw.py +134 -0
  78. akshare/index/{index_sw_research.py → index_research_sw.py} +122 -58
  79. akshare/index/index_spot.py +9 -5
  80. akshare/index/index_stock_hk.py +35 -16
  81. akshare/index/index_stock_us_sina.py +1 -1
  82. akshare/index/index_stock_zh.py +180 -89
  83. akshare/index/index_stock_zh_csindex.py +15 -369
  84. akshare/index/index_sw.py +62 -34
  85. akshare/index/index_yw.py +46 -23
  86. akshare/index/index_zh_a_scope.py +48 -0
  87. akshare/index/index_zh_em.py +6 -4
  88. akshare/interest_rate/interbank_rate_em.py +14 -9
  89. akshare/movie/artist_yien.py +32 -5
  90. akshare/movie/movie_yien.py +92 -18
  91. akshare/movie/video_yien.py +28 -5
  92. akshare/news/news_baidu.py +78 -44
  93. akshare/news/news_cctv.py +38 -38
  94. akshare/news/news_stock.py +6 -3
  95. akshare/nlp/nlp_interface.py +7 -8
  96. akshare/option/cons.py +11 -11
  97. akshare/option/option_comm_qihuo.py +86 -0
  98. akshare/option/option_commodity.py +178 -51
  99. akshare/option/option_daily_stats_sse_szse.py +146 -0
  100. akshare/option/option_em.py +147 -138
  101. akshare/option/option_finance_sina.py +160 -137
  102. akshare/option/option_lhb_em.py +62 -56
  103. akshare/option/option_risk_indicator_sse.py +17 -14
  104. akshare/other/other_car_cpca.py +934 -0
  105. akshare/other/{other_car.py → other_car_gasgoo.py} +15 -54
  106. akshare/qdii/__init__.py +0 -0
  107. akshare/qdii/qdii_jsl.py +233 -0
  108. akshare/request.py +117 -0
  109. akshare/spot/spot_hog_soozhu.py +232 -0
  110. akshare/spot/spot_price_qh.py +121 -0
  111. akshare/spot/spot_sge.py +63 -10
  112. akshare/stock/stock_allotment_cninfo.py +10 -9
  113. akshare/stock/stock_board_concept_em.py +23 -14
  114. akshare/stock/stock_board_industry_em.py +40 -34
  115. akshare/stock/stock_cg_equity_mortgage.py +15 -11
  116. akshare/stock/stock_cg_guarantee.py +41 -51
  117. akshare/stock/stock_cg_lawsuit.py +36 -35
  118. akshare/stock/stock_dividend_cninfo.py +12 -6
  119. akshare/stock/stock_dzjy_em.py +347 -260
  120. akshare/stock/stock_fund_em.py +332 -84
  121. akshare/stock/stock_hk_famous.py +108 -0
  122. akshare/stock/stock_hk_sina.py +8 -7
  123. akshare/stock/stock_hold_control_cninfo.py +100 -15
  124. akshare/stock/stock_hold_control_em.py +4 -3
  125. akshare/stock/stock_hold_num_cninfo.py +18 -12
  126. akshare/stock/stock_hot_rank_em.py +2 -1
  127. akshare/stock/stock_hot_search_baidu.py +5 -2
  128. akshare/stock/stock_industry_cninfo.py +24 -18
  129. akshare/stock/stock_industry_pe_cninfo.py +45 -31
  130. akshare/stock/stock_industry_sw.py +9 -10
  131. akshare/stock/stock_info.py +25 -15
  132. akshare/stock/stock_info_em.py +5 -2
  133. akshare/stock/stock_intraday_em.py +5 -2
  134. akshare/stock/stock_intraday_sina.py +22 -18
  135. akshare/stock/stock_ipo_summary_cninfo.py +25 -10
  136. akshare/stock/stock_new_cninfo.py +32 -19
  137. akshare/stock/stock_news_cx.py +39 -0
  138. akshare/stock/stock_profile_cninfo.py +9 -8
  139. akshare/stock/stock_rank_forecast.py +8 -6
  140. akshare/stock/stock_share_changes_cninfo.py +18 -14
  141. akshare/stock/stock_share_hold.py +24 -19
  142. akshare/stock/stock_summary.py +54 -26
  143. akshare/stock/stock_us_famous.py +15 -6
  144. akshare/stock/stock_us_pink.py +7 -5
  145. akshare/stock/stock_us_sina.py +15 -12
  146. akshare/stock/stock_xq.py +38 -12
  147. akshare/stock/stock_zh_a_sina.py +53 -78
  148. akshare/stock/stock_zh_b_sina.py +32 -55
  149. akshare/stock/stock_zh_kcb_report.py +11 -9
  150. akshare/stock/stock_zh_kcb_sina.py +67 -64
  151. akshare/stock_feature/stock_a_below_net_asset_statistics.py +5 -2
  152. akshare/stock_feature/stock_a_high_low.py +5 -2
  153. akshare/stock_feature/stock_a_indicator.py +12 -9
  154. akshare/stock_feature/stock_a_pe_and_pb.py +27 -6
  155. akshare/stock_feature/stock_account_em.py +58 -40
  156. akshare/stock_feature/stock_analyst_em.py +36 -27
  157. akshare/stock_feature/stock_board_industry_ths.py +136 -400
  158. akshare/stock_feature/stock_comment_em.py +118 -85
  159. akshare/stock_feature/stock_concept_futu.py +183 -0
  160. akshare/stock_feature/stock_cyq_em.py +58 -54
  161. akshare/stock_feature/stock_disclosure_cninfo.py +147 -102
  162. akshare/stock_feature/stock_esg_sina.py +216 -11
  163. akshare/stock_feature/stock_fhps_em.py +60 -25
  164. akshare/stock_feature/stock_fhps_ths.py +25 -6
  165. akshare/stock_feature/stock_fund_flow.py +38 -25
  166. akshare/stock_feature/stock_gdfx_em.py +180 -95
  167. akshare/stock_feature/stock_gdhs.py +73 -49
  168. akshare/stock_feature/stock_gpzy_em.py +78 -46
  169. akshare/stock_feature/stock_hist_em.py +55 -23
  170. akshare/stock_feature/stock_hk_valuation_baidu.py +20 -8
  171. akshare/stock_feature/stock_hsgt_em.py +184 -452
  172. akshare/stock_feature/stock_info.py +52 -29
  173. akshare/stock_feature/stock_inner_trade_xq.py +39 -31
  174. akshare/stock_feature/stock_irm_cninfo.py +32 -9
  175. akshare/stock_feature/stock_jgdy_em.py +41 -38
  176. akshare/stock_feature/stock_lh_yybpm.py +36 -37
  177. akshare/stock_feature/stock_lhb_em.py +135 -71
  178. akshare/stock_feature/stock_lhb_sina.py +93 -46
  179. akshare/stock_feature/stock_margin_em.py +102 -0
  180. akshare/stock_feature/{stock_sse_margin.py → stock_margin_sse.py} +21 -15
  181. akshare/stock_feature/{stock_szse_margin.py → stock_margin_szse.py} +23 -19
  182. akshare/stock_feature/stock_market_legu.py +13 -8
  183. akshare/stock_feature/stock_pankou_em.py +72 -34
  184. akshare/stock_feature/stock_report_em.py +244 -54
  185. akshare/stock_feature/stock_research_report_em.py +48 -19
  186. akshare/stock_feature/stock_sns_sseinfo.py +15 -12
  187. akshare/stock_feature/stock_sy_em.py +86 -33
  188. akshare/stock_feature/stock_technology_ths.py +152 -120
  189. akshare/stock_feature/stock_tfp_em.py +35 -13
  190. akshare/stock_feature/stock_three_report_em.py +119 -77
  191. akshare/stock_feature/stock_ttm_lyr.py +4 -7
  192. akshare/stock_feature/stock_value_em.py +83 -0
  193. akshare/stock_feature/stock_wencai.py +21 -9
  194. akshare/stock_feature/stock_yjyg_em.py +63 -28
  195. akshare/stock_feature/stock_zf_pg.py +61 -38
  196. akshare/stock_feature/stock_zh_valuation_baidu.py +3 -2
  197. akshare/stock_feature/stock_ztb_em.py +62 -40
  198. akshare/stock_fundamental/stock_finance.py +150 -58
  199. akshare/stock_fundamental/stock_finance_ths.py +116 -31
  200. akshare/stock_fundamental/stock_mda_ym.py +5 -3
  201. akshare/stock_fundamental/stock_notice.py +29 -15
  202. akshare/stock_fundamental/stock_profit_forecast_em.py +31 -13
  203. akshare/stock_fundamental/stock_profit_forecast_ths.py +19 -10
  204. akshare/stock_fundamental/stock_register_em.py +448 -0
  205. akshare/stock_fundamental/stock_restricted_em.py +79 -32
  206. akshare/stock_fundamental/stock_zygc.py +10 -8
  207. akshare/stock_fundamental/stock_zyjs_ths.py +5 -3
  208. akshare/tool/trade_date_hist.py +4 -3
  209. akshare/utils/cons.py +10 -0
  210. akshare/utils/context.py +43 -0
  211. akshare/utils/demjson.py +2 -2
  212. akshare/utils/func.py +26 -0
  213. akshare/utils/tqdm.py +13 -3
  214. {akshare-1.12.99.dist-info → akshare-1.15.73.dist-info}/METADATA +52 -69
  215. akshare-1.15.73.dist-info/RECORD +385 -0
  216. {akshare-1.12.99.dist-info → akshare-1.15.73.dist-info}/WHEEL +1 -1
  217. tests/test_func.py +3 -5
  218. akshare/bond/bond_futures.py +0 -50
  219. akshare/bond/bond_investing.py +0 -139
  220. akshare/crypto/crypto_hist_investing.py +0 -249
  221. akshare/fortune/fortune_it_juzi.py +0 -123
  222. akshare/futures/futures_international.py +0 -170
  223. akshare/futures/futures_news_baidu.py +0 -54
  224. akshare/futures/inventory_data.py +0 -100
  225. akshare/futures_derivative/futures_index_price_nh.py +0 -61
  226. akshare/futures_derivative/futures_index_return_nh.py +0 -47
  227. akshare/futures_derivative/futures_index_volatility_nh.py +0 -51
  228. akshare/futures_derivative/futures_other_index_nh.py +0 -145
  229. akshare/index/index_fear_greed_funddb.py +0 -71
  230. akshare/index/index_investing.py +0 -232
  231. akshare/sport/sport_olympic_winter.py +0 -39
  232. akshare/stock_feature/stock_board_concept_ths.py +0 -422
  233. akshare/stock_fundamental/stock_register.py +0 -292
  234. akshare-1.12.99.dist-info/RECORD +0 -374
  235. {akshare-1.12.99.dist-info → akshare-1.15.73.dist-info}/LICENSE +0 -0
  236. {akshare-1.12.99.dist-info → akshare-1.15.73.dist-info}/top_level.txt +0 -0
@@ -1,17 +1,18 @@
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
  """
8
+
8
9
  import json
9
10
  import re
10
11
  from functools import lru_cache
11
12
 
12
13
  import pandas as pd
13
14
  import requests
14
- from py_mini_racer import py_mini_racer
15
+ import py_mini_racer
15
16
 
16
17
  from akshare.stock.cons import (
17
18
  zh_sina_a_stock_url,
@@ -32,7 +33,10 @@ def _get_zh_b_page_count() -> int:
32
33
  :return: 需要采集的股票总页数
33
34
  :rtype: int
34
35
  """
35
- 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
+ )
36
40
  r = requests.get(url)
37
41
  page_count = int(re.findall(re.compile(r"\d+"), r.text)[0]) / 80
38
42
  if isinstance(page_count, int):
@@ -44,7 +48,7 @@ def _get_zh_b_page_count() -> int:
44
48
  def stock_zh_b_spot() -> pd.DataFrame:
45
49
  """
46
50
  新浪财经-所有 B 股的实时行情数据; 重复运行本函数会被新浪暂时封 IP
47
- https://vip.stock.finance.sina.com.cn/mkt/#qbgg_hk
51
+ https://vip.stock.finance.sina.com.cn/mkt/#hs_b
48
52
  :return: 所有股票的实时行情数据
49
53
  :rtype: pandas.DataFrame
50
54
  """
@@ -63,7 +67,7 @@ def stock_zh_b_spot() -> pd.DataFrame:
63
67
  zh_sina_stock_payload_copy.update({"page": page})
64
68
  r = requests.get(zh_sina_a_stock_url, params=zh_sina_stock_payload_copy)
65
69
  data_json = demjson.decode(r.text)
66
- 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)
67
71
  big_df.columns = [
68
72
  "代码",
69
73
  "_",
@@ -125,14 +129,14 @@ def stock_zh_b_daily(
125
129
  ) -> pd.DataFrame:
126
130
  """
127
131
  新浪财经-B 股-个股的历史行情数据, 大量抓取容易封 IP
128
- https://finance.sina.com.cn/realstock/company/sh689009/nc.shtml
132
+ https://finance.sina.com.cn/realstock/company/sh900901/nc.shtml
129
133
  :param start_date: 20201103; 开始日期
130
134
  :type start_date: str
131
135
  :param end_date: 20201103; 结束日期
132
136
  :type end_date: str
133
137
  :param symbol: sh600000
134
138
  :type symbol: str
135
- :param adjust: 默认为空: 返回不复权的数据; qfq: 返回前复权后的数据; hfq: 返回后复权后的数据; hfq-factor: 返回后复权因子; hfq-factor: 返回前复权因子
139
+ :param adjust: 默认为空: 返回不复权的数据; qfq: 返回前复权后的数据; hfq: 返回后复权后的数据; hfq-factor: 返回后复权因子; qfq-factor: 返回前复权因子
136
140
  :type adjust: str
137
141
  :return: specific data
138
142
  :rtype: pandas.DataFrame
@@ -140,9 +144,9 @@ def stock_zh_b_daily(
140
144
 
141
145
  def _fq_factor(method: str) -> pd.DataFrame:
142
146
  if method == "hfq":
143
- res = requests.get(zh_sina_a_stock_hfq_url.format(symbol))
147
+ r = requests.get(zh_sina_a_stock_hfq_url.format(symbol))
144
148
  hfq_factor_df = pd.DataFrame(
145
- eval(res.text.split("=")[1].split("\n")[0])["data"]
149
+ eval(r.text.split("=")[1].split("\n")[0])["data"]
146
150
  )
147
151
  if hfq_factor_df.shape[0] == 0:
148
152
  raise ValueError("sina hfq factor not available")
@@ -152,9 +156,9 @@ def stock_zh_b_daily(
152
156
  hfq_factor_df.reset_index(inplace=True)
153
157
  return hfq_factor_df
154
158
  else:
155
- res = requests.get(zh_sina_a_stock_qfq_url.format(symbol))
159
+ r = requests.get(zh_sina_a_stock_qfq_url.format(symbol))
156
160
  qfq_factor_df = pd.DataFrame(
157
- eval(res.text.split("=")[1].split("\n")[0])["data"]
161
+ eval(r.text.split("=")[1].split("\n")[0])["data"]
158
162
  )
159
163
  if qfq_factor_df.shape[0] == 0:
160
164
  raise ValueError("sina hfq factor not available")
@@ -167,15 +171,18 @@ def stock_zh_b_daily(
167
171
  if adjust in ("hfq-factor", "qfq-factor"):
168
172
  return _fq_factor(adjust.split("-")[0])
169
173
 
170
- res = requests.get(zh_sina_a_stock_hist_url.format(symbol))
174
+ r = requests.get(zh_sina_a_stock_hist_url.format(symbol))
171
175
  js_code = py_mini_racer.MiniRacer()
172
176
  js_code.eval(hk_js_decode)
173
177
  dict_list = js_code.call(
174
- "d", res.text.split("=")[1].split(";")[0].replace('"', "")
178
+ "d", r.text.split("=")[1].split(";")[0].replace('"', "")
175
179
  ) # 执行js解密代码
176
180
  data_df = pd.DataFrame(dict_list)
177
181
  data_df.index = pd.to_datetime(data_df["date"]).dt.date
178
182
  del data_df["date"]
183
+ del data_df["amount"]
184
+ del data_df["prevclose"]
185
+
179
186
  data_df = data_df.astype("float")
180
187
  r = requests.get(zh_sina_a_stock_amount_url.format(symbol, symbol))
181
188
  amount_data_json = demjson.decode(r.text[r.text.find("[") : r.text.rfind("]") + 1])
@@ -185,15 +192,7 @@ def stock_zh_b_daily(
185
192
  temp_df = pd.merge(
186
193
  data_df, amount_data_df, left_index=True, right_index=True, how="outer"
187
194
  )
188
- try:
189
- # try for pandas >= 2.1.0
190
- temp_df.ffill(inplace=True)
191
- except Exception as e:
192
- try:
193
- # try for pandas < 2.1.0
194
- temp_df.fillna(method="ffill", inplace=True)
195
- except Exception as e:
196
- print("Error:", e)
195
+ temp_df.ffill(inplace=True)
197
196
  temp_df = temp_df.astype(float)
198
197
  temp_df["amount"] = temp_df["amount"] * 10000
199
198
  temp_df["turnover"] = temp_df["volume"] / temp_df["amount"]
@@ -221,25 +220,15 @@ def stock_zh_b_daily(
221
220
  return temp_df
222
221
 
223
222
  if adjust == "hfq":
224
- res = requests.get(zh_sina_a_stock_hfq_url.format(symbol))
225
- hfq_factor_df = pd.DataFrame(
226
- eval(res.text.split("=")[1].split("\n")[0])["data"]
227
- )
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"])
228
225
  hfq_factor_df.columns = ["date", "hfq_factor"]
229
226
  hfq_factor_df.index = pd.to_datetime(hfq_factor_df.date)
230
227
  del hfq_factor_df["date"]
231
228
  temp_df = pd.merge(
232
229
  temp_df, hfq_factor_df, left_index=True, right_index=True, how="outer"
233
230
  )
234
- try:
235
- # try for pandas >= 2.1.0
236
- temp_df.ffill(inplace=True)
237
- except Exception as e:
238
- try:
239
- # try for pandas < 2.1.0
240
- temp_df.fillna(method="ffill", inplace=True)
241
- except Exception as e:
242
- print("Error:", e)
231
+ temp_df.ffill(inplace=True)
243
232
  temp_df = temp_df.astype(float)
244
233
  temp_df.dropna(inplace=True)
245
234
  temp_df.drop_duplicates(
@@ -260,26 +249,15 @@ def stock_zh_b_daily(
260
249
  return temp_df
261
250
 
262
251
  if adjust == "qfq":
263
- res = requests.get(zh_sina_a_stock_qfq_url.format(symbol))
264
- qfq_factor_df = pd.DataFrame(
265
- eval(res.text.split("=")[1].split("\n")[0])["data"]
266
- )
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"])
267
254
  qfq_factor_df.columns = ["date", "qfq_factor"]
268
255
  qfq_factor_df.index = pd.to_datetime(qfq_factor_df.date)
269
256
  del qfq_factor_df["date"]
270
-
271
257
  temp_df = pd.merge(
272
258
  temp_df, qfq_factor_df, left_index=True, right_index=True, how="outer"
273
259
  )
274
- try:
275
- # try for pandas >= 2.1.0
276
- temp_df.ffill(inplace=True)
277
- except Exception as e:
278
- try:
279
- # try for pandas < 2.1.0
280
- temp_df.fillna(method="ffill", inplace=True)
281
- except Exception as e:
282
- print("Error:", e)
260
+ temp_df.ffill(inplace=True)
283
261
  temp_df = temp_df.astype(float)
284
262
  temp_df.dropna(inplace=True)
285
263
  temp_df.drop_duplicates(
@@ -321,16 +299,15 @@ def stock_zh_b_minute(
321
299
  params = {
322
300
  "symbol": symbol,
323
301
  "scale": period,
324
- "datalen": "20000",
302
+ "datalen": "1970",
325
303
  }
326
304
  r = requests.get(url, params=params)
327
305
  temp_df = pd.DataFrame(json.loads(r.text.split("=(")[1].split(");")[0])).iloc[:, :6]
328
306
  if temp_df.empty:
329
- print(f"{symbol} 股票数据不存在,请检查是否已退市")
330
- return None
307
+ return pd.DataFrame()
331
308
  try:
332
309
  stock_zh_b_daily(symbol=symbol, adjust="qfq")
333
- except:
310
+ except: # noqa: E722
334
311
  return temp_df
335
312
 
336
313
  if adjust == "":
@@ -390,12 +367,12 @@ def stock_zh_b_minute(
390
367
 
391
368
  if __name__ == "__main__":
392
369
  stock_zh_b_daily_hfq_df_one = stock_zh_b_daily(
393
- symbol="sh900901", start_date="20171103", end_date="20210908", adjust=""
370
+ symbol="sh900901", start_date="20071103", end_date="20240916", adjust=""
394
371
  )
395
372
  print(stock_zh_b_daily_hfq_df_one)
396
373
 
397
374
  stock_zh_b_daily_hfq_df_three = stock_zh_b_daily(
398
- symbol="sh900901", start_date="19900103", end_date="20210118", adjust="qfq"
375
+ symbol="sh900901", start_date="19900103", end_date="20240722", adjust="hfq"
399
376
  )
400
377
  print(stock_zh_b_daily_hfq_df_three)
401
378
 
@@ -1,10 +1,11 @@
1
1
  #!/usr/bin/env python
2
2
  # -*- coding:utf-8 -*-
3
3
  """
4
- Date: 2021/8/20 19:00
4
+ Date: 2024/7/21 18:00
5
5
  Desc: 科创板报告
6
- http://data.eastmoney.com/notices/kcb.html
6
+ https://data.eastmoney.com/notices/kcb.html
7
7
  """
8
+
8
9
  import pandas as pd
9
10
  import requests
10
11
  from tqdm import tqdm
@@ -13,11 +14,11 @@ from tqdm import tqdm
13
14
  def _stock_zh_kcb_report_em_page() -> int:
14
15
  """
15
16
  科创板报告的页数
16
- http://data.eastmoney.com/notices/kcb.html
17
+ https://data.eastmoney.com/notices/kcb.html
17
18
  :return: 科创板报告的页数
18
19
  :rtype: int
19
20
  """
20
- url = "http://np-anotice-stock.eastmoney.com/api/security/ann"
21
+ url = "https://np-anotice-stock.eastmoney.com/api/security/ann"
21
22
  params = {
22
23
  "sr": "-1",
23
24
  "page_size": "100",
@@ -38,7 +39,7 @@ def _stock_zh_kcb_report_em_page() -> int:
38
39
  def stock_zh_kcb_report_em(from_page: int = 1, to_page: int = 100) -> pd.DataFrame:
39
40
  """
40
41
  科创板报告内容
41
- http://data.eastmoney.com/notices/kcb.html
42
+ https://data.eastmoney.com/notices/kcb.html
42
43
  :param from_page: 开始获取的页码
43
44
  :type from_page: int
44
45
  :param to_page: 结束获取的页码
@@ -46,9 +47,9 @@ def stock_zh_kcb_report_em(from_page: int = 1, to_page: int = 100) -> pd.DataFra
46
47
  :return: 科创板报告内容
47
48
  :rtype: pandas.DataFrame
48
49
  """
49
- big_df = pd.DataFrame()
50
- url = "http://np-anotice-stock.eastmoney.com/api/security/ann"
50
+ url = "https://np-anotice-stock.eastmoney.com/api/security/ann"
51
51
  total_page = _stock_zh_kcb_report_em_page()
52
+ big_df = pd.DataFrame()
52
53
  if to_page >= total_page:
53
54
  to_page = total_page
54
55
  for i in tqdm(range(from_page, to_page + 1), leave=False):
@@ -76,7 +77,8 @@ def stock_zh_kcb_report_em(from_page: int = 1, to_page: int = 100) -> pd.DataFra
76
77
  [item["art_code"] for item in data_json["data"]["list"]],
77
78
  ]
78
79
  ).T
79
- big_df = big_df.append(temp_df, ignore_index=True)
80
+ big_df = pd.concat(objs=[big_df, temp_df], ignore_index=True)
81
+
80
82
  big_df.columns = [
81
83
  "代码",
82
84
  "名称",
@@ -85,7 +87,7 @@ def stock_zh_kcb_report_em(from_page: int = 1, to_page: int = 100) -> pd.DataFra
85
87
  "公告日期",
86
88
  "公告代码",
87
89
  ]
88
- big_df['公告日期'] = pd.to_datetime(big_df['公告日期']).dt.date
90
+ big_df["公告日期"] = pd.to_datetime(big_df["公告日期"], errors="coerce").dt.date
89
91
  return big_df
90
92
 
91
93
 
@@ -4,6 +4,7 @@
4
4
  Date: 2023/7/6 19:28
5
5
  Desc: 新浪财经-科创板-实时行情数据和历史行情数据(包含前复权和后复权因子)
6
6
  """
7
+
7
8
  import datetime
8
9
  import re
9
10
 
@@ -61,59 +62,61 @@ def stock_zh_kcb_spot() -> pd.DataFrame:
61
62
  "最新价",
62
63
  "涨跌额",
63
64
  "涨跌幅",
64
- '买入',
65
- '卖出',
66
- '昨收',
67
- '今开',
68
- '最高',
69
- '最低',
70
- '成交量',
71
- '成交额',
72
- '时点',
73
- '市盈率',
74
- '市净率',
75
- '流通市值',
76
- '总市值',
77
- '换手率',
65
+ "买入",
66
+ "卖出",
67
+ "昨收",
68
+ "今开",
69
+ "最高",
70
+ "最低",
71
+ "成交量",
72
+ "成交额",
73
+ "时点",
74
+ "市盈率",
75
+ "市净率",
76
+ "流通市值",
77
+ "总市值",
78
+ "换手率",
79
+ ]
80
+ big_df = big_df[
81
+ [
82
+ "代码",
83
+ "名称",
84
+ "最新价",
85
+ "涨跌额",
86
+ "涨跌幅",
87
+ "买入",
88
+ "卖出",
89
+ "昨收",
90
+ "今开",
91
+ "最高",
92
+ "最低",
93
+ "成交量",
94
+ "成交额",
95
+ "时点",
96
+ "市盈率",
97
+ "市净率",
98
+ "流通市值",
99
+ "总市值",
100
+ "换手率",
101
+ ]
78
102
  ]
79
- big_df = big_df[[
80
- "代码",
81
- "名称",
82
- "最新价",
83
- "涨跌额",
84
- "涨跌幅",
85
- '买入',
86
- '卖出',
87
- '昨收',
88
- '今开',
89
- '最高',
90
- '最低',
91
- '成交量',
92
- '成交额',
93
- '时点',
94
- '市盈率',
95
- '市净率',
96
- '流通市值',
97
- '总市值',
98
- '换手率',
99
- ]]
100
103
 
101
- big_df['最新价'] = pd.to_numeric(big_df['最新价'])
102
- big_df['涨跌额'] = pd.to_numeric(big_df['涨跌额'])
103
- big_df['涨跌幅'] = pd.to_numeric(big_df['涨跌幅'])
104
- big_df['买入'] = pd.to_numeric(big_df['买入'])
105
- big_df['卖出'] = pd.to_numeric(big_df['卖出'])
106
- big_df['昨收'] = pd.to_numeric(big_df['昨收'])
107
- big_df['今开'] = pd.to_numeric(big_df['今开'])
108
- big_df['最高'] = pd.to_numeric(big_df['最高'])
109
- big_df['最低'] = pd.to_numeric(big_df['最低'])
110
- big_df['成交量'] = pd.to_numeric(big_df['成交量'])
111
- big_df['成交额'] = pd.to_numeric(big_df['成交额'])
112
- big_df['市盈率'] = pd.to_numeric(big_df['市盈率'])
113
- big_df['市净率'] = pd.to_numeric(big_df['市净率'])
114
- big_df['流通市值'] = pd.to_numeric(big_df['流通市值'])
115
- big_df['总市值'] = pd.to_numeric(big_df['总市值'])
116
- big_df['换手率'] = pd.to_numeric(big_df['换手率'])
104
+ big_df["最新价"] = pd.to_numeric(big_df["最新价"])
105
+ big_df["涨跌额"] = pd.to_numeric(big_df["涨跌额"])
106
+ big_df["涨跌幅"] = pd.to_numeric(big_df["涨跌幅"])
107
+ big_df["买入"] = pd.to_numeric(big_df["买入"])
108
+ big_df["卖出"] = pd.to_numeric(big_df["卖出"])
109
+ big_df["昨收"] = pd.to_numeric(big_df["昨收"])
110
+ big_df["今开"] = pd.to_numeric(big_df["今开"])
111
+ big_df["最高"] = pd.to_numeric(big_df["最高"])
112
+ big_df["最低"] = pd.to_numeric(big_df["最低"])
113
+ big_df["成交量"] = pd.to_numeric(big_df["成交量"])
114
+ big_df["成交额"] = pd.to_numeric(big_df["成交额"])
115
+ big_df["市盈率"] = pd.to_numeric(big_df["市盈率"])
116
+ big_df["市净率"] = pd.to_numeric(big_df["市净率"])
117
+ big_df["流通市值"] = pd.to_numeric(big_df["流通市值"])
118
+ big_df["总市值"] = pd.to_numeric(big_df["总市值"])
119
+ big_df["换手率"] = pd.to_numeric(big_df["换手率"])
117
120
  return big_df
118
121
 
119
122
 
@@ -123,7 +126,7 @@ def stock_zh_kcb_daily(symbol: str = "sh688399", adjust: str = "") -> pd.DataFra
123
126
  https://finance.sina.com.cn/realstock/company/sh688005/nc.shtml
124
127
  :param symbol: 股票代码; 带市场标识的股票代码
125
128
  :type symbol: str
126
- :param adjust: 默认不复权的数据; qfq: 返回前复权后的数据; hfq: 返回后复权后的数据; hfq-factor: 返回后复权因子; hfq-factor: 返回前复权因子
129
+ :param adjust: 默认不复权的数据; qfq: 返回前复权后的数据; hfq: 返回后复权后的数据; hfq-factor: 返回后复权因子; qfq-factor: 返回前复权因子
127
130
  :type adjust: str
128
131
  :return: 科创板股票的历史行情数据
129
132
  :rtype: pandas.DataFrame
@@ -150,12 +153,12 @@ def stock_zh_kcb_daily(symbol: str = "sh688399", adjust: str = "") -> pd.DataFra
150
153
  try:
151
154
  # try for pandas >= 2.1.0
152
155
  temp_df.ffill(inplace=True)
153
- except Exception as e:
156
+ except Exception:
154
157
  try:
155
- # try for pandas < 2.1.0
158
+ # try for pandas < 2.1.0
156
159
  temp_df.fillna(method="ffill", inplace=True)
157
160
  except Exception as e:
158
- print("Error:", e)
161
+ print("Error:", e)
159
162
  temp_df = temp_df.astype(float)
160
163
  temp_df["amount"] = temp_df["amount"] * 10000
161
164
  temp_df["turnover"] = temp_df["v"] / temp_df["amount"]
@@ -173,7 +176,7 @@ def stock_zh_kcb_daily(symbol: str = "sh688399", adjust: str = "") -> pd.DataFra
173
176
 
174
177
  if not adjust:
175
178
  temp_df.reset_index(inplace=True)
176
- temp_df['date'] = pd.to_datetime(temp_df['date']).dt.date
179
+ temp_df["date"] = pd.to_datetime(temp_df["date"]).dt.date
177
180
  return temp_df
178
181
 
179
182
  if adjust == "hfq":
@@ -191,9 +194,9 @@ def stock_zh_kcb_daily(symbol: str = "sh688399", adjust: str = "") -> pd.DataFra
191
194
  try:
192
195
  # try for pandas >= 2.1.0
193
196
  temp_df.ffill(inplace=True)
194
- except Exception as e:
197
+ except Exception:
195
198
  try:
196
- # try for pandas < 2.1.0
199
+ # try for pandas < 2.1.0
197
200
  temp_df.fillna(method="ffill", inplace=True)
198
201
  except Exception as e:
199
202
  print("Error:", e)
@@ -204,7 +207,7 @@ def stock_zh_kcb_daily(symbol: str = "sh688399", adjust: str = "") -> pd.DataFra
204
207
  temp_df["low"] = temp_df["low"] * temp_df["hfq_factor"]
205
208
  temp_df = temp_df.iloc[:, :-1]
206
209
  temp_df.reset_index(inplace=True)
207
- temp_df['date'] = pd.to_datetime(temp_df['date']).dt.date
210
+ temp_df["date"] = pd.to_datetime(temp_df["date"]).dt.date
208
211
  return temp_df
209
212
 
210
213
  if adjust == "qfq":
@@ -222,9 +225,9 @@ def stock_zh_kcb_daily(symbol: str = "sh688399", adjust: str = "") -> pd.DataFra
222
225
  try:
223
226
  # try for pandas >= 2.1.0
224
227
  temp_df.ffill(inplace=True)
225
- except Exception as e:
228
+ except Exception:
226
229
  try:
227
- # try for pandas < 2.1.0
230
+ # try for pandas < 2.1.0
228
231
  temp_df.fillna(method="ffill", inplace=True)
229
232
  except Exception as e:
230
233
  print("Error:", e)
@@ -235,7 +238,7 @@ def stock_zh_kcb_daily(symbol: str = "sh688399", adjust: str = "") -> pd.DataFra
235
238
  temp_df["low"] = temp_df["low"] / temp_df["qfq_factor"]
236
239
  temp_df = temp_df.iloc[:, :-1]
237
240
  temp_df.reset_index(inplace=True)
238
- temp_df['date'] = pd.to_datetime(temp_df['date']).dt.date
241
+ temp_df["date"] = pd.to_datetime(temp_df["date"]).dt.date
239
242
  return temp_df
240
243
 
241
244
  if adjust == "hfq-factor":
@@ -247,7 +250,7 @@ def stock_zh_kcb_daily(symbol: str = "sh688399", adjust: str = "") -> pd.DataFra
247
250
  hfq_factor_df.index = pd.to_datetime(hfq_factor_df.date)
248
251
  del hfq_factor_df["date"]
249
252
  hfq_factor_df.reset_index(inplace=True)
250
- hfq_factor_df['date'] = pd.to_datetime(hfq_factor_df['date']).dt.date
253
+ hfq_factor_df["date"] = pd.to_datetime(hfq_factor_df["date"]).dt.date
251
254
  return hfq_factor_df
252
255
 
253
256
  if adjust == "qfq-factor":
@@ -259,7 +262,7 @@ def stock_zh_kcb_daily(symbol: str = "sh688399", adjust: str = "") -> pd.DataFra
259
262
  qfq_factor_df.index = pd.to_datetime(qfq_factor_df.date)
260
263
  del qfq_factor_df["date"]
261
264
  qfq_factor_df.reset_index(inplace=True)
262
- qfq_factor_df['date'] = pd.to_datetime(qfq_factor_df['date']).dt.date
265
+ qfq_factor_df["date"] = pd.to_datetime(qfq_factor_df["date"]).dt.date
263
266
  return qfq_factor_df
264
267
 
265
268
 
@@ -1,13 +1,16 @@
1
1
  #!/usr/bin/env python
2
2
  # -*- coding:utf-8 -*-
3
3
  """
4
- Date: 2023/9/10 15:30
4
+ Date: 2024/4/30 10:30
5
5
  Desc: 破净股统计历史走势
6
6
  https://www.legulegu.com/stockdata/below-net-asset-statistics
7
7
  """
8
+
8
9
  import pandas as pd
9
10
  import requests
10
11
 
12
+ from akshare.utils.cons import headers
13
+
11
14
 
12
15
  def stock_a_below_net_asset_statistics(symbol: str = "全部A股") -> pd.DataFrame:
13
16
  """
@@ -29,7 +32,7 @@ def stock_a_below_net_asset_statistics(symbol: str = "全部A股") -> pd.DataFra
29
32
  "marketId": symbol_map[symbol],
30
33
  "token": "325843825a2745a2a8f9b9e3355cb864",
31
34
  }
32
- r = requests.get(url, params=params)
35
+ r = requests.get(url, params=params, headers=headers)
33
36
  data_json = r.json()
34
37
  temp_df = pd.DataFrame(data_json)
35
38
  temp_df["date"] = pd.to_datetime(temp_df["date"], unit="ms").dt.date
@@ -5,9 +5,12 @@ Date: 2023/9/10 15:32
5
5
  Desc: 乐咕乐股-创新高、新低的股票数量
6
6
  https://www.legulegu.com/stockdata/high-low-statistics
7
7
  """
8
+
8
9
  import pandas as pd
9
10
  import requests
10
11
 
12
+ from akshare.utils.cons import headers
13
+
11
14
 
12
15
  def stock_a_high_low_statistics(symbol: str = "all") -> pd.DataFrame:
13
16
  """
@@ -19,7 +22,7 @@ def stock_a_high_low_statistics(symbol: str = "all") -> pd.DataFrame:
19
22
  :rtype: pandas.DataFrame
20
23
  """
21
24
  url = f"https://www.legulegu.com/stockdata/member-ship/get-high-low-statistics/{symbol}"
22
- r = requests.get(url)
25
+ r = requests.get(url, headers=headers)
23
26
  data_json = r.json()
24
27
  temp_df = pd.DataFrame(data_json)
25
28
  del temp_df["indexCode"]
@@ -31,7 +34,7 @@ def stock_a_high_low_statistics(symbol: str = "all") -> pd.DataFrame:
31
34
  temp_df["low60"] = pd.to_numeric(temp_df["low60"], errors="coerce")
32
35
  temp_df["high120"] = pd.to_numeric(temp_df["high120"], errors="coerce")
33
36
  temp_df["low120"] = pd.to_numeric(temp_df["low120"], errors="coerce")
34
- temp_df.sort_values(["date"], inplace=True, ignore_index=True)
37
+ temp_df.sort_values(by=["date"], inplace=True, ignore_index=True)
35
38
  return temp_df
36
39
 
37
40
 
@@ -1,11 +1,12 @@
1
1
  #!/usr/bin/env python
2
2
  # -*- coding:utf-8 -*-
3
3
  """
4
- Date: 2024/02/14 01:24
4
+ Date: 2024/4/25 20:24
5
5
  Desc: 市盈率, 市净率和股息率查询
6
6
  https://www.legulegu.com/stocklist
7
7
  https://www.legulegu.com/s/000001
8
8
  """
9
+
9
10
  from datetime import datetime
10
11
  from hashlib import md5
11
12
 
@@ -13,6 +14,8 @@ import pandas as pd
13
14
  import requests
14
15
  from bs4 import BeautifulSoup
15
16
 
17
+ from akshare.utils.cons import headers
18
+
16
19
 
17
20
  def get_cookie_csrf(url: str = "") -> dict:
18
21
  """
@@ -21,11 +24,11 @@ def get_cookie_csrf(url: str = "") -> dict:
21
24
  :return: 指定市场的市盈率数据
22
25
  :rtype: pandas.DataFrame
23
26
  """
24
- r = requests.get(url)
27
+ r = requests.get(url, headers=headers)
25
28
  soup = BeautifulSoup(r.text, features="lxml")
26
29
  csrf_tag = soup.find(name="meta", attrs={"name": "_csrf"})
27
30
  csrf_token = csrf_tag.attrs["content"]
28
- headers = {"X-CSRF-Token": csrf_token}
31
+ headers.update({"X-CSRF-Token": csrf_token})
29
32
  return {"cookies": r.cookies, "headers": headers}
30
33
 
31
34
 
@@ -43,7 +46,7 @@ def get_token_lg() -> str:
43
46
  return token
44
47
 
45
48
 
46
- def stock_a_indicator_lg(symbol: str = "002174") -> pd.DataFrame:
49
+ def stock_a_indicator_lg(symbol: str = "000001") -> pd.DataFrame:
47
50
  """
48
51
  市盈率, 市净率, 股息率数据接口
49
52
  https://legulegu.com/stocklist
@@ -54,7 +57,7 @@ def stock_a_indicator_lg(symbol: str = "002174") -> pd.DataFrame:
54
57
  """
55
58
  if symbol == "all":
56
59
  url = "https://legulegu.com/stocklist"
57
- r = requests.get(url)
60
+ r = requests.get(url, headers=headers)
58
61
  soup = BeautifulSoup(r.text, features="lxml")
59
62
  node_list = soup.find_all(attrs={"class": "col-xs-6"})
60
63
  href_list = [item.find("a")["href"] for item in node_list]
@@ -82,13 +85,13 @@ def stock_a_indicator_lg(symbol: str = "002174") -> pd.DataFrame:
82
85
  temp_df["trade_date"] = pd.to_datetime(temp_df["trade_date"]).dt.date
83
86
  temp_df[temp_df.columns[1:]] = temp_df[temp_df.columns[1:]].astype(float)
84
87
  temp_df.sort_values(by=["trade_date"], inplace=True, ignore_index=True)
85
- if len(set(temp_df['trade_date'])) <= 0:
88
+ if len(set(temp_df["trade_date"])) <= 0:
86
89
  raise ValueError("数据获取失败, 请检查是否输入正确的股票代码")
87
90
  return temp_df
88
91
 
89
92
 
90
93
  def stock_hk_indicator_eniu(
91
- symbol: str = "hk01093", indicator: str = "市盈率"
94
+ symbol: str = "hk01093", indicator: str = "市盈率"
92
95
  ) -> pd.DataFrame:
93
96
  """
94
97
  亿牛网-港股指标
@@ -102,7 +105,7 @@ def stock_hk_indicator_eniu(
102
105
  """
103
106
  if indicator == "港股":
104
107
  url = "https://eniu.com/static/data/stock_list.json"
105
- r = requests.get(url)
108
+ r = requests.get(url, headers=headers)
106
109
  data_json = r.json()
107
110
  temp_df = pd.DataFrame(data_json)
108
111
  temp_df = temp_df[temp_df["stock_id"].str.contains("hk")]
@@ -118,7 +121,7 @@ def stock_hk_indicator_eniu(
118
121
  url = f"https://eniu.com/chart/roeh/{symbol}"
119
122
  else:
120
123
  url = f"https://eniu.com/chart/marketvalueh/{symbol}"
121
- r = requests.get(url)
124
+ r = requests.get(url, headers=headers)
122
125
  data_json = r.json()
123
126
  temp_df = pd.DataFrame(data_json)
124
127
  return temp_df