akshare 1.12.95__py3-none-any.whl → 1.15.72__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 (240) hide show
  1. akshare/__init__.py +446 -139
  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_convert.py +40 -16
  10. akshare/bond/bond_info_cm.py +28 -8
  11. akshare/bond/bond_issue_cninfo.py +73 -30
  12. akshare/bond/{bond_zh_cov_sina.py → bond_zh_cov.py} +41 -17
  13. akshare/bond/bond_zh_sina.py +57 -51
  14. akshare/cal/__init__.py +0 -0
  15. akshare/cal/rv.py +170 -0
  16. akshare/cost/cost_living.py +7 -5
  17. akshare/currency/currency_safe.py +7 -6
  18. akshare/data/cninfo.js +15 -0
  19. akshare/datasets.py +10 -21
  20. akshare/economic/macro_bank.py +95 -653
  21. akshare/economic/macro_china.py +772 -1024
  22. akshare/economic/macro_china_hk.py +65 -243
  23. akshare/economic/macro_china_nbs.py +24 -7
  24. akshare/economic/macro_constitute.py +17 -12
  25. akshare/economic/macro_euro.py +13 -6
  26. akshare/economic/macro_finance_ths.py +133 -0
  27. akshare/economic/macro_info_ws.py +100 -0
  28. akshare/economic/macro_japan.py +5 -4
  29. akshare/economic/macro_other.py +12 -9
  30. akshare/economic/macro_usa.py +376 -1940
  31. akshare/economic/marco_cnbs.py +11 -6
  32. akshare/energy/energy_carbon.py +94 -125
  33. akshare/event/migration.py +3 -2
  34. akshare/exceptions.py +43 -0
  35. akshare/file_fold/calendar.json +245 -2
  36. akshare/fortune/fortune_500.py +15 -48
  37. akshare/fund/fund_amac.py +157 -75
  38. akshare/fund/fund_em.py +191 -184
  39. akshare/fund/fund_etf_em.py +20 -19
  40. akshare/fund/fund_etf_sina.py +71 -23
  41. akshare/fund/fund_etf_ths.py +93 -0
  42. akshare/fund/fund_fee_em.py +98 -0
  43. akshare/fund/fund_lof_em.py +10 -8
  44. akshare/fund/fund_portfolio_em.py +60 -50
  45. akshare/fund/fund_rank_em.py +91 -82
  46. akshare/fund/fund_report_cninfo.py +63 -48
  47. akshare/fund/fund_scale_sina.py +20 -10
  48. akshare/fund/fund_xq.py +139 -109
  49. akshare/futures/cons.py +8 -31
  50. akshare/futures/cot.py +185 -137
  51. akshare/futures/futures_basis.py +97 -32
  52. akshare/futures/futures_comm_ctp.py +37 -0
  53. akshare/futures/futures_comm_qihuo.py +74 -45
  54. akshare/futures/futures_daily_bar.py +121 -184
  55. akshare/futures/futures_hf_em.py +66 -61
  56. akshare/futures/futures_hq_sina.py +79 -61
  57. akshare/futures/futures_index_ccidx.py +6 -3
  58. akshare/futures/futures_inventory_99.py +61 -272
  59. akshare/futures/futures_news_shmet.py +4 -2
  60. akshare/futures/futures_roll_yield.py +12 -25
  61. akshare/futures/futures_spot_stock_em.py +19 -13
  62. akshare/futures/futures_stock_js.py +14 -12
  63. akshare/futures/futures_to_spot.py +38 -33
  64. akshare/futures/futures_warehouse_receipt.py +75 -71
  65. akshare/futures/futures_zh_sina.py +73 -50
  66. akshare/futures/symbol_var.py +18 -13
  67. akshare/futures_derivative/futures_contract_info_czce.py +60 -52
  68. akshare/futures_derivative/futures_contract_info_ine.py +43 -34
  69. akshare/futures_derivative/futures_contract_info_shfe.py +46 -35
  70. akshare/futures_derivative/futures_cot_sina.py +26 -19
  71. akshare/futures_derivative/futures_spot_sys.py +21 -8
  72. akshare/fx/currency_investing.py +19 -285
  73. akshare/index/index_cflp.py +29 -26
  74. akshare/index/index_cni.py +86 -88
  75. akshare/index/index_cons.py +26 -10
  76. akshare/index/index_cx.py +248 -47
  77. akshare/index/index_drewry.py +17 -16
  78. akshare/index/index_hog.py +27 -26
  79. akshare/index/index_option_qvix.py +329 -0
  80. akshare/index/index_research_fund_sw.py +134 -0
  81. akshare/index/{index_sw_research.py → index_research_sw.py} +122 -58
  82. akshare/index/index_spot.py +9 -5
  83. akshare/index/index_stock_hk.py +35 -16
  84. akshare/index/index_stock_us_sina.py +1 -1
  85. akshare/index/index_stock_zh.py +180 -89
  86. akshare/index/index_stock_zh_csindex.py +15 -369
  87. akshare/index/index_sw.py +62 -34
  88. akshare/index/index_yw.py +46 -23
  89. akshare/index/index_zh_a_scope.py +48 -0
  90. akshare/index/index_zh_em.py +17 -14
  91. akshare/interest_rate/interbank_rate_em.py +14 -9
  92. akshare/movie/artist_yien.py +32 -5
  93. akshare/movie/movie_yien.py +92 -18
  94. akshare/movie/video_yien.py +28 -5
  95. akshare/news/news_baidu.py +78 -44
  96. akshare/news/news_cctv.py +38 -38
  97. akshare/news/news_stock.py +6 -3
  98. akshare/nlp/nlp_interface.py +7 -8
  99. akshare/option/cons.py +11 -11
  100. akshare/option/option_comm_qihuo.py +86 -0
  101. akshare/option/option_commodity.py +178 -51
  102. akshare/option/option_daily_stats_sse_szse.py +146 -0
  103. akshare/option/option_em.py +147 -138
  104. akshare/option/option_finance_sina.py +160 -137
  105. akshare/option/option_lhb_em.py +62 -56
  106. akshare/option/option_risk_indicator_sse.py +17 -14
  107. akshare/other/other_car_cpca.py +934 -0
  108. akshare/other/{other_car.py → other_car_gasgoo.py} +15 -54
  109. akshare/qdii/__init__.py +0 -0
  110. akshare/qdii/qdii_jsl.py +233 -0
  111. akshare/request.py +117 -0
  112. akshare/spot/spot_hog_soozhu.py +232 -0
  113. akshare/spot/spot_price_qh.py +121 -0
  114. akshare/spot/spot_sge.py +63 -10
  115. akshare/stock/stock_allotment_cninfo.py +10 -9
  116. akshare/stock/stock_ask_bid_em.py +27 -3
  117. akshare/stock/stock_board_concept_em.py +23 -14
  118. akshare/stock/stock_board_industry_em.py +40 -34
  119. akshare/stock/stock_cg_equity_mortgage.py +15 -11
  120. akshare/stock/stock_cg_guarantee.py +41 -51
  121. akshare/stock/stock_cg_lawsuit.py +36 -35
  122. akshare/stock/stock_dividend_cninfo.py +12 -6
  123. akshare/stock/stock_dzjy_em.py +347 -260
  124. akshare/stock/stock_fund_em.py +332 -84
  125. akshare/stock/stock_hk_famous.py +108 -0
  126. akshare/stock/stock_hk_sina.py +8 -7
  127. akshare/stock/stock_hold_control_cninfo.py +100 -15
  128. akshare/stock/stock_hold_control_em.py +4 -3
  129. akshare/stock/stock_hold_num_cninfo.py +18 -12
  130. akshare/stock/stock_hot_rank_em.py +2 -1
  131. akshare/stock/stock_hot_search_baidu.py +5 -2
  132. akshare/stock/stock_industry_cninfo.py +24 -18
  133. akshare/stock/stock_industry_pe_cninfo.py +45 -31
  134. akshare/stock/stock_industry_sw.py +9 -10
  135. akshare/stock/stock_info.py +25 -15
  136. akshare/stock/stock_info_em.py +5 -2
  137. akshare/stock/stock_intraday_em.py +5 -2
  138. akshare/stock/stock_intraday_sina.py +22 -18
  139. akshare/stock/stock_ipo_summary_cninfo.py +25 -10
  140. akshare/stock/stock_new_cninfo.py +32 -19
  141. akshare/stock/stock_news_cx.py +39 -0
  142. akshare/stock/stock_profile_cninfo.py +9 -8
  143. akshare/stock/stock_rank_forecast.py +8 -6
  144. akshare/stock/stock_share_changes_cninfo.py +18 -14
  145. akshare/stock/stock_share_hold.py +24 -19
  146. akshare/stock/stock_summary.py +54 -26
  147. akshare/stock/stock_us_famous.py +15 -6
  148. akshare/stock/stock_us_pink.py +7 -5
  149. akshare/stock/stock_us_sina.py +15 -12
  150. akshare/stock/stock_xq.py +38 -12
  151. akshare/stock/stock_zh_a_sina.py +53 -78
  152. akshare/stock/stock_zh_b_sina.py +32 -55
  153. akshare/stock/stock_zh_kcb_report.py +11 -9
  154. akshare/stock/stock_zh_kcb_sina.py +67 -64
  155. akshare/stock_feature/stock_a_below_net_asset_statistics.py +5 -2
  156. akshare/stock_feature/stock_a_high_low.py +5 -2
  157. akshare/stock_feature/stock_a_indicator.py +12 -9
  158. akshare/stock_feature/stock_a_pe_and_pb.py +27 -6
  159. akshare/stock_feature/stock_account_em.py +58 -40
  160. akshare/stock_feature/stock_analyst_em.py +36 -27
  161. akshare/stock_feature/stock_board_industry_ths.py +136 -400
  162. akshare/stock_feature/stock_comment_em.py +118 -85
  163. akshare/stock_feature/stock_concept_futu.py +183 -0
  164. akshare/stock_feature/stock_cyq_em.py +58 -54
  165. akshare/stock_feature/stock_disclosure_cninfo.py +147 -102
  166. akshare/stock_feature/stock_esg_sina.py +216 -11
  167. akshare/stock_feature/stock_fhps_em.py +60 -25
  168. akshare/stock_feature/stock_fhps_ths.py +25 -6
  169. akshare/stock_feature/stock_fund_flow.py +38 -25
  170. akshare/stock_feature/stock_gdfx_em.py +180 -95
  171. akshare/stock_feature/stock_gdhs.py +73 -49
  172. akshare/stock_feature/stock_gpzy_em.py +78 -46
  173. akshare/stock_feature/stock_hist_em.py +164 -111
  174. akshare/stock_feature/stock_hk_valuation_baidu.py +20 -8
  175. akshare/stock_feature/stock_hsgt_em.py +184 -452
  176. akshare/stock_feature/stock_info.py +52 -29
  177. akshare/stock_feature/stock_inner_trade_xq.py +39 -31
  178. akshare/stock_feature/stock_irm_cninfo.py +32 -9
  179. akshare/stock_feature/stock_jgdy_em.py +41 -38
  180. akshare/stock_feature/stock_lh_yybpm.py +36 -37
  181. akshare/stock_feature/stock_lhb_em.py +135 -71
  182. akshare/stock_feature/stock_lhb_sina.py +93 -46
  183. akshare/stock_feature/stock_margin_em.py +102 -0
  184. akshare/stock_feature/{stock_sse_margin.py → stock_margin_sse.py} +21 -15
  185. akshare/stock_feature/{stock_szse_margin.py → stock_margin_szse.py} +23 -19
  186. akshare/stock_feature/stock_market_legu.py +13 -8
  187. akshare/stock_feature/stock_pankou_em.py +72 -34
  188. akshare/stock_feature/stock_report_em.py +244 -54
  189. akshare/stock_feature/stock_research_report_em.py +48 -19
  190. akshare/stock_feature/stock_sns_sseinfo.py +15 -12
  191. akshare/stock_feature/stock_sy_em.py +86 -33
  192. akshare/stock_feature/stock_technology_ths.py +152 -120
  193. akshare/stock_feature/stock_tfp_em.py +35 -13
  194. akshare/stock_feature/stock_three_report_em.py +119 -77
  195. akshare/stock_feature/stock_ttm_lyr.py +4 -7
  196. akshare/stock_feature/stock_value_em.py +83 -0
  197. akshare/stock_feature/stock_wencai.py +21 -9
  198. akshare/stock_feature/stock_yjyg_em.py +63 -28
  199. akshare/stock_feature/stock_zf_pg.py +61 -38
  200. akshare/stock_feature/stock_zh_valuation_baidu.py +3 -2
  201. akshare/stock_feature/stock_ztb_em.py +62 -40
  202. akshare/stock_fundamental/stock_finance.py +150 -58
  203. akshare/stock_fundamental/stock_finance_ths.py +116 -31
  204. akshare/stock_fundamental/stock_mda_ym.py +5 -3
  205. akshare/stock_fundamental/stock_notice.py +29 -15
  206. akshare/stock_fundamental/stock_profit_forecast_em.py +31 -13
  207. akshare/stock_fundamental/stock_profit_forecast_ths.py +19 -10
  208. akshare/stock_fundamental/stock_register_em.py +448 -0
  209. akshare/stock_fundamental/stock_restricted_em.py +79 -32
  210. akshare/stock_fundamental/stock_zygc.py +10 -8
  211. akshare/stock_fundamental/stock_zyjs_ths.py +5 -3
  212. akshare/tool/trade_date_hist.py +4 -3
  213. akshare/utils/cons.py +10 -0
  214. akshare/utils/context.py +43 -0
  215. akshare/utils/demjson.py +2 -2
  216. akshare/utils/func.py +26 -0
  217. akshare/utils/tqdm.py +13 -3
  218. {akshare-1.12.95.dist-info → akshare-1.15.72.dist-info}/METADATA +52 -69
  219. akshare-1.15.72.dist-info/RECORD +385 -0
  220. {akshare-1.12.95.dist-info → akshare-1.15.72.dist-info}/WHEEL +1 -1
  221. tests/test_func.py +3 -5
  222. akshare/bond/bond_futures.py +0 -50
  223. akshare/bond/bond_investing.py +0 -139
  224. akshare/crypto/crypto_hist_investing.py +0 -249
  225. akshare/fortune/fortune_it_juzi.py +0 -123
  226. akshare/futures/futures_international.py +0 -170
  227. akshare/futures/futures_news_baidu.py +0 -54
  228. akshare/futures/inventory_data.py +0 -100
  229. akshare/futures_derivative/futures_index_price_nh.py +0 -61
  230. akshare/futures_derivative/futures_index_return_nh.py +0 -47
  231. akshare/futures_derivative/futures_index_volatility_nh.py +0 -51
  232. akshare/futures_derivative/futures_other_index_nh.py +0 -145
  233. akshare/index/index_fear_greed_funddb.py +0 -71
  234. akshare/index/index_investing.py +0 -232
  235. akshare/sport/sport_olympic_winter.py +0 -39
  236. akshare/stock_feature/stock_board_concept_ths.py +0 -422
  237. akshare/stock_fundamental/stock_register.py +0 -292
  238. akshare-1.12.95.dist-info/RECORD +0 -374
  239. {akshare-1.12.95.dist-info → akshare-1.15.72.dist-info}/LICENSE +0 -0
  240. {akshare-1.12.95.dist-info → akshare-1.15.72.dist-info}/top_level.txt +0 -0
@@ -1,10 +1,11 @@
1
1
  #!/usr/bin/env python
2
2
  # -*- coding:utf-8 -*-
3
3
  """
4
- Date: 2023/12/11 17:00
4
+ Date: 2024/7/13 18:00
5
5
  Desc: 东方财富网-行情首页-沪深京 A 股
6
6
  https://quote.eastmoney.com/
7
7
  """
8
+
8
9
  from functools import lru_cache
9
10
 
10
11
  import pandas as pd
@@ -18,7 +19,7 @@ def stock_zh_a_spot_em() -> pd.DataFrame:
18
19
  :return: 实时行情
19
20
  :rtype: pandas.DataFrame
20
21
  """
21
- url = "http://82.push2.eastmoney.com/api/qt/clist/get"
22
+ url = "https://82.push2.eastmoney.com/api/qt/clist/get"
22
23
  params = {
23
24
  "pn": "1",
24
25
  "pz": "50000",
@@ -29,10 +30,11 @@ def stock_zh_a_spot_em() -> pd.DataFrame:
29
30
  "invt": "2",
30
31
  "fid": "f3",
31
32
  "fs": "m:0 t:6,m:0 t:80,m:1 t:2,m:1 t:23,m:0 t:81 s:2048",
32
- "fields": "f1,f2,f3,f4,f5,f6,f7,f8,f9,f10,f12,f13,f14,f15,f16,f17,f18,f20,f21,f23,f24,f25,f22,f11,f62,f128,f136,f115,f152",
33
+ "fields": "f1,f2,f3,f4,f5,f6,f7,f8,f9,f10,f12,f13,f14,f15,f16,f17,f18,"
34
+ "f20,f21,f23,f24,f25,f22,f11,f62,f128,f136,f115,f152",
33
35
  "_": "1623833739532",
34
36
  }
35
- r = requests.get(url, params=params)
37
+ r = requests.get(url, timeout=15, params=params)
36
38
  data_json = r.json()
37
39
  if not data_json["data"]["diff"]:
38
40
  return pd.DataFrame()
@@ -119,7 +121,9 @@ def stock_zh_a_spot_em() -> pd.DataFrame:
119
121
  temp_df["涨速"] = pd.to_numeric(temp_df["涨速"], errors="coerce")
120
122
  temp_df["5分钟涨跌"] = pd.to_numeric(temp_df["5分钟涨跌"], errors="coerce")
121
123
  temp_df["60日涨跌幅"] = pd.to_numeric(temp_df["60日涨跌幅"], errors="coerce")
122
- temp_df["年初至今涨跌幅"] = pd.to_numeric(temp_df["年初至今涨跌幅"], errors="coerce")
124
+ temp_df["年初至今涨跌幅"] = pd.to_numeric(
125
+ temp_df["年初至今涨跌幅"], errors="coerce"
126
+ )
123
127
  return temp_df
124
128
 
125
129
 
@@ -130,7 +134,7 @@ def stock_sh_a_spot_em() -> pd.DataFrame:
130
134
  :return: 实时行情
131
135
  :rtype: pandas.DataFrame
132
136
  """
133
- url = "http://82.push2.eastmoney.com/api/qt/clist/get"
137
+ url = "https://82.push2.eastmoney.com/api/qt/clist/get"
134
138
  params = {
135
139
  "pn": "1",
136
140
  "pz": "50000",
@@ -141,10 +145,11 @@ def stock_sh_a_spot_em() -> pd.DataFrame:
141
145
  "invt": "2",
142
146
  "fid": "f3",
143
147
  "fs": "m:1 t:2,m:1 t:23",
144
- "fields": "f1,f2,f3,f4,f5,f6,f7,f8,f9,f10,f12,f13,f14,f15,f16,f17,f18,f20,f21,f23,f24,f25,f22,f11,f62,f128,f136,f115,f152",
148
+ "fields": "f1,f2,f3,f4,f5,f6,f7,f8,f9,f10,f12,f13,f14,f15,f16,f17,f18,f20,f21,f23,"
149
+ "f24,f25,f22,f11,f62,f128,f136,f115,f152",
145
150
  "_": "1623833739532",
146
151
  }
147
- r = requests.get(url, params=params)
152
+ r = requests.get(url, timeout=15, params=params)
148
153
  data_json = r.json()
149
154
  if not data_json["data"]["diff"]:
150
155
  return pd.DataFrame()
@@ -231,7 +236,9 @@ def stock_sh_a_spot_em() -> pd.DataFrame:
231
236
  temp_df["涨速"] = pd.to_numeric(temp_df["涨速"], errors="coerce")
232
237
  temp_df["5分钟涨跌"] = pd.to_numeric(temp_df["5分钟涨跌"], errors="coerce")
233
238
  temp_df["60日涨跌幅"] = pd.to_numeric(temp_df["60日涨跌幅"], errors="coerce")
234
- temp_df["年初至今涨跌幅"] = pd.to_numeric(temp_df["年初至今涨跌幅"], errors="coerce")
239
+ temp_df["年初至今涨跌幅"] = pd.to_numeric(
240
+ temp_df["年初至今涨跌幅"], errors="coerce"
241
+ )
235
242
  return temp_df
236
243
 
237
244
 
@@ -242,7 +249,7 @@ def stock_sz_a_spot_em() -> pd.DataFrame:
242
249
  :return: 实时行情
243
250
  :rtype: pandas.DataFrame
244
251
  """
245
- url = "http://82.push2.eastmoney.com/api/qt/clist/get"
252
+ url = "https://82.push2.eastmoney.com/api/qt/clist/get"
246
253
  params = {
247
254
  "pn": "1",
248
255
  "pz": "50000",
@@ -253,10 +260,11 @@ def stock_sz_a_spot_em() -> pd.DataFrame:
253
260
  "invt": "2",
254
261
  "fid": "f3",
255
262
  "fs": "m:0 t:6,m:0 t:80",
256
- "fields": "f1,f2,f3,f4,f5,f6,f7,f8,f9,f10,f12,f13,f14,f15,f16,f17,f18,f20,f21,f23,f24,f25,f22,f11,f62,f128,f136,f115,f152",
263
+ "fields": "f1,f2,f3,f4,f5,f6,f7,f8,f9,f10,f12,f13,f14,f15,f16,f17,f18,f20,f21,f23,f24,"
264
+ "f25,f22,f11,f62,f128,f136,f115,f152",
257
265
  "_": "1623833739532",
258
266
  }
259
- r = requests.get(url, params=params)
267
+ r = requests.get(url, timeout=15, params=params)
260
268
  data_json = r.json()
261
269
  if not data_json["data"]["diff"]:
262
270
  return pd.DataFrame()
@@ -343,7 +351,9 @@ def stock_sz_a_spot_em() -> pd.DataFrame:
343
351
  temp_df["涨速"] = pd.to_numeric(temp_df["涨速"], errors="coerce")
344
352
  temp_df["5分钟涨跌"] = pd.to_numeric(temp_df["5分钟涨跌"], errors="coerce")
345
353
  temp_df["60日涨跌幅"] = pd.to_numeric(temp_df["60日涨跌幅"], errors="coerce")
346
- temp_df["年初至今涨跌幅"] = pd.to_numeric(temp_df["年初至今涨跌幅"], errors="coerce")
354
+ temp_df["年初至今涨跌幅"] = pd.to_numeric(
355
+ temp_df["年初至今涨跌幅"], errors="coerce"
356
+ )
347
357
  return temp_df
348
358
 
349
359
 
@@ -354,7 +364,7 @@ def stock_bj_a_spot_em() -> pd.DataFrame:
354
364
  :return: 实时行情
355
365
  :rtype: pandas.DataFrame
356
366
  """
357
- url = "http://82.push2.eastmoney.com/api/qt/clist/get"
367
+ url = "https://82.push2.eastmoney.com/api/qt/clist/get"
358
368
  params = {
359
369
  "pn": "1",
360
370
  "pz": "50000",
@@ -365,10 +375,11 @@ def stock_bj_a_spot_em() -> pd.DataFrame:
365
375
  "invt": "2",
366
376
  "fid": "f3",
367
377
  "fs": "m:0 t:81 s:2048",
368
- "fields": "f1,f2,f3,f4,f5,f6,f7,f8,f9,f10,f12,f13,f14,f15,f16,f17,f18,f20,f21,f23,f24,f25,f22,f11,f62,f128,f136,f115,f152",
378
+ "fields": "f1,f2,f3,f4,f5,f6,f7,f8,f9,f10,f12,f13,f14,f15,f16,f17,f18,f20,f21,f23,f24"
379
+ ",f25,f22,f11,f62,f128,f136,f115,f152",
369
380
  "_": "1623833739532",
370
381
  }
371
- r = requests.get(url, params=params)
382
+ r = requests.get(url, timeout=15, params=params)
372
383
  data_json = r.json()
373
384
  if not data_json["data"]["diff"]:
374
385
  return pd.DataFrame()
@@ -455,7 +466,9 @@ def stock_bj_a_spot_em() -> pd.DataFrame:
455
466
  temp_df["涨速"] = pd.to_numeric(temp_df["涨速"], errors="coerce")
456
467
  temp_df["5分钟涨跌"] = pd.to_numeric(temp_df["5分钟涨跌"], errors="coerce")
457
468
  temp_df["60日涨跌幅"] = pd.to_numeric(temp_df["60日涨跌幅"], errors="coerce")
458
- temp_df["年初至今涨跌幅"] = pd.to_numeric(temp_df["年初至今涨跌幅"], errors="coerce")
469
+ temp_df["年初至今涨跌幅"] = pd.to_numeric(
470
+ temp_df["年初至今涨跌幅"], errors="coerce"
471
+ )
459
472
  return temp_df
460
473
 
461
474
 
@@ -466,7 +479,7 @@ def stock_new_a_spot_em() -> pd.DataFrame:
466
479
  :return: 实时行情
467
480
  :rtype: pandas.DataFrame
468
481
  """
469
- url = "http://82.push2.eastmoney.com/api/qt/clist/get"
482
+ url = "https://82.push2.eastmoney.com/api/qt/clist/get"
470
483
  params = {
471
484
  "pn": "1",
472
485
  "pz": "50000",
@@ -478,10 +491,11 @@ def stock_new_a_spot_em() -> pd.DataFrame:
478
491
  "wbp2u": "|0|0|0|web",
479
492
  "fid": "f26",
480
493
  "fs": "m:0 f:8,m:1 f:8",
481
- "fields": "f1,f2,f3,f4,f5,f6,f7,f8,f9,f10,f12,f13,f14,f15,f16,f17,f18,f20,f21,f23,f24,f25,f26,f22,f11,f62,f128,f136,f115,f152",
494
+ "fields": "f1,f2,f3,f4,f5,f6,f7,f8,f9,f10,f12,f13,f14,f15,f16,f17,f18,f20,f21,f23,f24,"
495
+ "f25,f26,f22,f11,f62,f128,f136,f115,f152",
482
496
  "_": "1623833739532",
483
497
  }
484
- r = requests.get(url, params=params)
498
+ r = requests.get(url, timeout=15, params=params)
485
499
  data_json = r.json()
486
500
  if not data_json["data"]["diff"]:
487
501
  return pd.DataFrame()
@@ -570,7 +584,9 @@ def stock_new_a_spot_em() -> pd.DataFrame:
570
584
  temp_df["涨速"] = pd.to_numeric(temp_df["涨速"], errors="coerce")
571
585
  temp_df["5分钟涨跌"] = pd.to_numeric(temp_df["5分钟涨跌"], errors="coerce")
572
586
  temp_df["60日涨跌幅"] = pd.to_numeric(temp_df["60日涨跌幅"], errors="coerce")
573
- temp_df["年初至今涨跌幅"] = pd.to_numeric(temp_df["年初至今涨跌幅"], errors="coerce")
587
+ temp_df["年初至今涨跌幅"] = pd.to_numeric(
588
+ temp_df["年初至今涨跌幅"], errors="coerce"
589
+ )
574
590
 
575
591
  temp_df["上市日期"] = pd.to_datetime(temp_df["上市日期"], format="%Y%m%d").dt.date
576
592
  return temp_df
@@ -583,7 +599,7 @@ def stock_cy_a_spot_em() -> pd.DataFrame:
583
599
  :return: 实时行情
584
600
  :rtype: pandas.DataFrame
585
601
  """
586
- url = "http://7.push2.eastmoney.com/api/qt/clist/get"
602
+ url = "https://7.push2.eastmoney.com/api/qt/clist/get"
587
603
  params = {
588
604
  "pn": "1",
589
605
  "pz": "50000",
@@ -595,10 +611,11 @@ def stock_cy_a_spot_em() -> pd.DataFrame:
595
611
  "wbp2u": "|0|0|0|web",
596
612
  "fid": "f3",
597
613
  "fs": "m:0 t:80",
598
- "fields": "f1,f2,f3,f4,f5,f6,f7,f8,f9,f10,f12,f13,f14,f15,f16,f17,f18,f20,f21,f23,f24,f25,f22,f11,f62,f128,f136,f115,f152",
614
+ "fields": "f1,f2,f3,f4,f5,f6,f7,f8,f9,f10,f12,f13,f14,f15,f16,f17,f18,f20,f21,"
615
+ "f23,f24,f25,f22,f11,f62,f128,f136,f115,f152",
599
616
  "_": "1623833739532",
600
617
  }
601
- r = requests.get(url, params=params)
618
+ r = requests.get(url, timeout=15, params=params)
602
619
  data_json = r.json()
603
620
  if not data_json["data"]["diff"]:
604
621
  return pd.DataFrame()
@@ -685,7 +702,9 @@ def stock_cy_a_spot_em() -> pd.DataFrame:
685
702
  temp_df["涨速"] = pd.to_numeric(temp_df["涨速"], errors="coerce")
686
703
  temp_df["5分钟涨跌"] = pd.to_numeric(temp_df["5分钟涨跌"], errors="coerce")
687
704
  temp_df["60日涨跌幅"] = pd.to_numeric(temp_df["60日涨跌幅"], errors="coerce")
688
- temp_df["年初至今涨跌幅"] = pd.to_numeric(temp_df["年初至今涨跌幅"], errors="coerce")
705
+ temp_df["年初至今涨跌幅"] = pd.to_numeric(
706
+ temp_df["年初至今涨跌幅"], errors="coerce"
707
+ )
689
708
  return temp_df
690
709
 
691
710
 
@@ -696,7 +715,7 @@ def stock_kc_a_spot_em() -> pd.DataFrame:
696
715
  :return: 实时行情
697
716
  :rtype: pandas.DataFrame
698
717
  """
699
- url = "http://7.push2.eastmoney.com/api/qt/clist/get"
718
+ url = "https://7.push2.eastmoney.com/api/qt/clist/get"
700
719
  params = {
701
720
  "pn": "1",
702
721
  "pz": "50000",
@@ -708,10 +727,11 @@ def stock_kc_a_spot_em() -> pd.DataFrame:
708
727
  "wbp2u": "|0|0|0|web",
709
728
  "fid": "f3",
710
729
  "fs": "m:1 t:23",
711
- "fields": "f1,f2,f3,f4,f5,f6,f7,f8,f9,f10,f12,f13,f14,f15,f16,f17,f18,f20,f21,f23,f24,f25,f22,f11,f62,f128,f136,f115,f152",
730
+ "fields": "f1,f2,f3,f4,f5,f6,f7,f8,f9,f10,f12,f13,f14,f15,f16,f17,f18,f20,"
731
+ "f21,f23,f24,f25,f22,f11,f62,f128,f136,f115,f152",
712
732
  "_": "1623833739532",
713
733
  }
714
- r = requests.get(url, params=params)
734
+ r = requests.get(url, timeout=15, params=params)
715
735
  data_json = r.json()
716
736
  if not data_json["data"]["diff"]:
717
737
  return pd.DataFrame()
@@ -798,7 +818,9 @@ def stock_kc_a_spot_em() -> pd.DataFrame:
798
818
  temp_df["涨速"] = pd.to_numeric(temp_df["涨速"], errors="coerce")
799
819
  temp_df["5分钟涨跌"] = pd.to_numeric(temp_df["5分钟涨跌"], errors="coerce")
800
820
  temp_df["60日涨跌幅"] = pd.to_numeric(temp_df["60日涨跌幅"], errors="coerce")
801
- temp_df["年初至今涨跌幅"] = pd.to_numeric(temp_df["年初至今涨跌幅"], errors="coerce")
821
+ temp_df["年初至今涨跌幅"] = pd.to_numeric(
822
+ temp_df["年初至今涨跌幅"], errors="coerce"
823
+ )
802
824
  return temp_df
803
825
 
804
826
 
@@ -809,7 +831,7 @@ def stock_zh_b_spot_em() -> pd.DataFrame:
809
831
  :return: 实时行情
810
832
  :rtype: pandas.DataFrame
811
833
  """
812
- url = "http://28.push2.eastmoney.com/api/qt/clist/get"
834
+ url = "https://28.push2.eastmoney.com/api/qt/clist/get"
813
835
  params = {
814
836
  "pn": "1",
815
837
  "pz": "50000",
@@ -820,10 +842,11 @@ def stock_zh_b_spot_em() -> pd.DataFrame:
820
842
  "invt": "2",
821
843
  "fid": "f3",
822
844
  "fs": "m:0 t:7,m:1 t:3",
823
- "fields": "f1,f2,f3,f4,f5,f6,f7,f8,f9,f10,f12,f13,f14,f15,f16,f17,f18,f20,f21,f23,f24,f25,f22,f11,f62,f128,f136,f115,f152",
845
+ "fields": "f1,f2,f3,f4,f5,f6,f7,f8,f9,f10,f12,f13,f14,f15,f16,f17,f18,f20"
846
+ ",f21,f23,f24,f25,f22,f11,f62,f128,f136,f115,f152",
824
847
  "_": "1623833739532",
825
848
  }
826
- r = requests.get(url, params=params)
849
+ r = requests.get(url, timeout=15, params=params)
827
850
  data_json = r.json()
828
851
  if not data_json["data"]["diff"]:
829
852
  return pd.DataFrame()
@@ -910,7 +933,9 @@ def stock_zh_b_spot_em() -> pd.DataFrame:
910
933
  temp_df["涨速"] = pd.to_numeric(temp_df["涨速"], errors="coerce")
911
934
  temp_df["5分钟涨跌"] = pd.to_numeric(temp_df["5分钟涨跌"], errors="coerce")
912
935
  temp_df["60日涨跌幅"] = pd.to_numeric(temp_df["60日涨跌幅"], errors="coerce")
913
- temp_df["年初至今涨跌幅"] = pd.to_numeric(temp_df["年初至今涨跌幅"], errors="coerce")
936
+ temp_df["年初至今涨跌幅"] = pd.to_numeric(
937
+ temp_df["年初至今涨跌幅"], errors="coerce"
938
+ )
914
939
  return temp_df
915
940
 
916
941
 
@@ -922,7 +947,7 @@ def code_id_map_em() -> dict:
922
947
  :return: 股票和市场代码
923
948
  :rtype: dict
924
949
  """
925
- url = "http://80.push2.eastmoney.com/api/qt/clist/get"
950
+ url = "https://80.push2.eastmoney.com/api/qt/clist/get"
926
951
  params = {
927
952
  "pn": "1",
928
953
  "pz": "50000",
@@ -936,7 +961,7 @@ def code_id_map_em() -> dict:
936
961
  "fields": "f12",
937
962
  "_": "1623833739532",
938
963
  }
939
- r = requests.get(url, params=params)
964
+ r = requests.get(url, timeout=15, params=params)
940
965
  data_json = r.json()
941
966
  if not data_json["data"]["diff"]:
942
967
  return dict()
@@ -957,7 +982,7 @@ def code_id_map_em() -> dict:
957
982
  "fields": "f12",
958
983
  "_": "1623833739532",
959
984
  }
960
- r = requests.get(url, params=params)
985
+ r = requests.get(url, timeout=15, params=params)
961
986
  data_json = r.json()
962
987
  if not data_json["data"]["diff"]:
963
988
  return dict()
@@ -977,7 +1002,7 @@ def code_id_map_em() -> dict:
977
1002
  "fields": "f12",
978
1003
  "_": "1623833739532",
979
1004
  }
980
- r = requests.get(url, params=params)
1005
+ r = requests.get(url, timeout=15, params=params)
981
1006
  data_json = r.json()
982
1007
  if not data_json["data"]["diff"]:
983
1008
  return dict()
@@ -988,12 +1013,12 @@ def code_id_map_em() -> dict:
988
1013
 
989
1014
 
990
1015
  def stock_zh_a_hist(
991
- symbol: str = "000001",
992
- period: str = "daily",
993
- start_date: str = "19700101",
994
- end_date: str = "20500101",
995
- adjust: str = "",
996
- timeout: float = None,
1016
+ symbol: str = "000001",
1017
+ period: str = "daily",
1018
+ start_date: str = "19700101",
1019
+ end_date: str = "20500101",
1020
+ adjust: str = "",
1021
+ timeout: float = None,
997
1022
  ) -> pd.DataFrame:
998
1023
  """
999
1024
  东方财富网-行情首页-沪深京 A 股-每日行情
@@ -1016,7 +1041,7 @@ def stock_zh_a_hist(
1016
1041
  code_id_dict = code_id_map_em()
1017
1042
  adjust_dict = {"qfq": "1", "hfq": "2", "": "0"}
1018
1043
  period_dict = {"daily": "101", "weekly": "102", "monthly": "103"}
1019
- url = "http://push2his.eastmoney.com/api/qt/stock/kline/get"
1044
+ url = "https://push2his.eastmoney.com/api/qt/stock/kline/get"
1020
1045
  params = {
1021
1046
  "fields1": "f1,f2,f3,f4,f5,f6",
1022
1047
  "fields2": "f51,f52,f53,f54,f55,f56,f57,f58,f59,f60,f61,f116",
@@ -1033,6 +1058,7 @@ def stock_zh_a_hist(
1033
1058
  if not (data_json["data"] and data_json["data"]["klines"]):
1034
1059
  return pd.DataFrame()
1035
1060
  temp_df = pd.DataFrame([item.split(",") for item in data_json["data"]["klines"]])
1061
+ temp_df["股票代码"] = symbol
1036
1062
  temp_df.columns = [
1037
1063
  "日期",
1038
1064
  "开盘",
@@ -1045,6 +1071,7 @@ def stock_zh_a_hist(
1045
1071
  "涨跌幅",
1046
1072
  "涨跌额",
1047
1073
  "换手率",
1074
+ "股票代码",
1048
1075
  ]
1049
1076
  temp_df["日期"] = pd.to_datetime(temp_df["日期"], errors="coerce").dt.date
1050
1077
  temp_df["开盘"] = pd.to_numeric(temp_df["开盘"], errors="coerce")
@@ -1057,15 +1084,31 @@ def stock_zh_a_hist(
1057
1084
  temp_df["涨跌幅"] = pd.to_numeric(temp_df["涨跌幅"], errors="coerce")
1058
1085
  temp_df["涨跌额"] = pd.to_numeric(temp_df["涨跌额"], errors="coerce")
1059
1086
  temp_df["换手率"] = pd.to_numeric(temp_df["换手率"], errors="coerce")
1087
+ temp_df = temp_df[
1088
+ [
1089
+ "日期",
1090
+ "股票代码",
1091
+ "开盘",
1092
+ "收盘",
1093
+ "最高",
1094
+ "最低",
1095
+ "成交量",
1096
+ "成交额",
1097
+ "振幅",
1098
+ "涨跌幅",
1099
+ "涨跌额",
1100
+ "换手率",
1101
+ ]
1102
+ ]
1060
1103
  return temp_df
1061
1104
 
1062
1105
 
1063
1106
  def stock_zh_a_hist_min_em(
1064
- symbol: str = "000001",
1065
- start_date: str = "1979-09-01 09:32:00",
1066
- end_date: str = "2222-01-01 09:32:00",
1067
- period: str = "5",
1068
- adjust: str = "",
1107
+ symbol: str = "000001",
1108
+ start_date: str = "1979-09-01 09:32:00",
1109
+ end_date: str = "2222-01-01 09:32:00",
1110
+ period: str = "5",
1111
+ adjust: str = "",
1069
1112
  ) -> pd.DataFrame:
1070
1113
  """
1071
1114
  东方财富网-行情首页-沪深京 A 股-每日分时行情
@@ -1100,7 +1143,7 @@ def stock_zh_a_hist_min_em(
1100
1143
  "secid": f"{code_id_dict[symbol]}.{symbol}",
1101
1144
  "_": "1623766962675",
1102
1145
  }
1103
- r = requests.get(url, params=params)
1146
+ r = requests.get(url, timeout=15, params=params)
1104
1147
  data_json = r.json()
1105
1148
  temp_df = pd.DataFrame(
1106
1149
  [item.split(",") for item in data_json["data"]["trends"]]
@@ -1113,7 +1156,7 @@ def stock_zh_a_hist_min_em(
1113
1156
  "最低",
1114
1157
  "成交量",
1115
1158
  "成交额",
1116
- "最新价",
1159
+ "均价",
1117
1160
  ]
1118
1161
  temp_df.index = pd.to_datetime(temp_df["时间"])
1119
1162
  temp_df = temp_df[start_date:end_date]
@@ -1124,11 +1167,11 @@ def stock_zh_a_hist_min_em(
1124
1167
  temp_df["最低"] = pd.to_numeric(temp_df["最低"], errors="coerce")
1125
1168
  temp_df["成交量"] = pd.to_numeric(temp_df["成交量"], errors="coerce")
1126
1169
  temp_df["成交额"] = pd.to_numeric(temp_df["成交额"], errors="coerce")
1127
- temp_df["最新价"] = pd.to_numeric(temp_df["最新价"], errors="coerce")
1170
+ temp_df["均价"] = pd.to_numeric(temp_df["均价"], errors="coerce")
1128
1171
  temp_df["时间"] = pd.to_datetime(temp_df["时间"]).astype(str)
1129
1172
  return temp_df
1130
1173
  else:
1131
- url = "http://push2his.eastmoney.com/api/qt/stock/kline/get"
1174
+ url = "https://push2his.eastmoney.com/api/qt/stock/kline/get"
1132
1175
  params = {
1133
1176
  "fields1": "f1,f2,f3,f4,f5,f6",
1134
1177
  "fields2": "f51,f52,f53,f54,f55,f56,f57,f58,f59,f60,f61",
@@ -1140,7 +1183,7 @@ def stock_zh_a_hist_min_em(
1140
1183
  "end": "20500000",
1141
1184
  "_": "1630930917857",
1142
1185
  }
1143
- r = requests.get(url, params=params)
1186
+ r = requests.get(url, timeout=15, params=params)
1144
1187
  data_json = r.json()
1145
1188
  temp_df = pd.DataFrame(
1146
1189
  [item.split(",") for item in data_json["data"]["klines"]]
@@ -1191,9 +1234,9 @@ def stock_zh_a_hist_min_em(
1191
1234
 
1192
1235
 
1193
1236
  def stock_zh_a_hist_pre_min_em(
1194
- symbol: str = "000001",
1195
- start_time: str = "09:00:00",
1196
- end_time: str = "15:50:00",
1237
+ symbol: str = "000001",
1238
+ start_time: str = "09:00:00",
1239
+ end_time: str = "15:50:00",
1197
1240
  ) -> pd.DataFrame:
1198
1241
  """
1199
1242
  东方财富网-行情首页-沪深京 A 股-每日分时行情包含盘前数据
@@ -1219,7 +1262,7 @@ def stock_zh_a_hist_pre_min_em(
1219
1262
  "secid": f"{code_id_dict[symbol]}.{symbol}",
1220
1263
  "_": "1623766962675",
1221
1264
  }
1222
- r = requests.get(url, params=params)
1265
+ r = requests.get(url, timeout=15, params=params)
1223
1266
  data_json = r.json()
1224
1267
  temp_df = pd.DataFrame([item.split(",") for item in data_json["data"]["trends"]])
1225
1268
  temp_df.columns = [
@@ -1234,7 +1277,7 @@ def stock_zh_a_hist_pre_min_em(
1234
1277
  ]
1235
1278
  temp_df.index = pd.to_datetime(temp_df["时间"])
1236
1279
  date_format = temp_df.index[0].date().isoformat()
1237
- temp_df = temp_df[date_format + " " + start_time: date_format + " " + end_time]
1280
+ temp_df = temp_df[date_format + " " + start_time : date_format + " " + end_time]
1238
1281
  temp_df.reset_index(drop=True, inplace=True)
1239
1282
  temp_df["开盘"] = pd.to_numeric(temp_df["开盘"], errors="coerce")
1240
1283
  temp_df["收盘"] = pd.to_numeric(temp_df["收盘"], errors="coerce")
@@ -1254,7 +1297,7 @@ def stock_hk_spot_em() -> pd.DataFrame:
1254
1297
  :return: 港股-实时行情
1255
1298
  :rtype: pandas.DataFrame
1256
1299
  """
1257
- url = "http://72.push2.eastmoney.com/api/qt/clist/get"
1300
+ url = "https://72.push2.eastmoney.com/api/qt/clist/get"
1258
1301
  params = {
1259
1302
  "pn": "1",
1260
1303
  "pz": "50000",
@@ -1265,10 +1308,11 @@ def stock_hk_spot_em() -> pd.DataFrame:
1265
1308
  "invt": "2",
1266
1309
  "fid": "f3",
1267
1310
  "fs": "m:128 t:3,m:128 t:4,m:128 t:1,m:128 t:2",
1268
- "fields": "f1,f2,f3,f4,f5,f6,f7,f8,f9,f10,f12,f13,f14,f15,f16,f17,f18,f20,f21,f23,f24,f25,f22,f11,f62,f128,f136,f115,f152",
1311
+ "fields": "f1,f2,f3,f4,f5,f6,f7,f8,f9,f10,f12,f13,f14,f15,f16,f17,f18,f20,"
1312
+ "f21,f23,f24,f25,f22,f11,f62,f128,f136,f115,f152",
1269
1313
  "_": "1624010056945",
1270
1314
  }
1271
- r = requests.get(url, params=params)
1315
+ r = requests.get(url, timeout=15, params=params)
1272
1316
  data_json = r.json()
1273
1317
  temp_df = pd.DataFrame(data_json["data"]["diff"])
1274
1318
  temp_df.columns = [
@@ -1343,7 +1387,7 @@ def stock_hk_main_board_spot_em() -> pd.DataFrame:
1343
1387
  :return: 港股-主板-实时行情
1344
1388
  :rtype: pandas.DataFrame
1345
1389
  """
1346
- url = "http://81.push2.eastmoney.com/api/qt/clist/get"
1390
+ url = "https://81.push2.eastmoney.com/api/qt/clist/get"
1347
1391
  params = {
1348
1392
  "pn": "1",
1349
1393
  "pz": "50000",
@@ -1354,10 +1398,11 @@ def stock_hk_main_board_spot_em() -> pd.DataFrame:
1354
1398
  "invt": "2",
1355
1399
  "fid": "f3",
1356
1400
  "fs": "m:128 t:3",
1357
- "fields": "f1,f2,f3,f4,f5,f6,f7,f8,f9,f10,f12,f13,f14,f15,f16,f17,f18,f20,f21,f23,f24,f25,f22,f11,f62,f128,f136,f115,f152",
1401
+ "fields": "f1,f2,f3,f4,f5,f6,f7,f8,f9,f10,f12,f13,f14,f15,f16,f17,f18,f20,"
1402
+ "f21,f23,f24,f25,f22,f11,f62,f128,f136,f115,f152",
1358
1403
  "_": "1624010056945",
1359
1404
  }
1360
- r = requests.get(url, params=params)
1405
+ r = requests.get(url, timeout=15, params=params)
1361
1406
  data_json = r.json()
1362
1407
  temp_df = pd.DataFrame(data_json["data"]["diff"])
1363
1408
  temp_df.columns = [
@@ -1426,11 +1471,11 @@ def stock_hk_main_board_spot_em() -> pd.DataFrame:
1426
1471
 
1427
1472
 
1428
1473
  def stock_hk_hist(
1429
- symbol: str = "00593",
1430
- period: str = "daily",
1431
- start_date: str = "19700101",
1432
- end_date: str = "22220101",
1433
- adjust: str = "",
1474
+ symbol: str = "00593",
1475
+ period: str = "daily",
1476
+ start_date: str = "19700101",
1477
+ end_date: str = "22220101",
1478
+ adjust: str = "",
1434
1479
  ) -> pd.DataFrame:
1435
1480
  """
1436
1481
  东方财富网-行情-港股-每日行情
@@ -1450,7 +1495,7 @@ def stock_hk_hist(
1450
1495
  """
1451
1496
  adjust_dict = {"qfq": "1", "hfq": "2", "": "0"}
1452
1497
  period_dict = {"daily": "101", "weekly": "102", "monthly": "103"}
1453
- url = "http://33.push2his.eastmoney.com/api/qt/stock/kline/get"
1498
+ url = "https://33.push2his.eastmoney.com/api/qt/stock/kline/get"
1454
1499
  params = {
1455
1500
  "secid": f"116.{symbol}",
1456
1501
  "ut": "fa5fd1943c7b386f172d6893dbfba10b",
@@ -1462,7 +1507,7 @@ def stock_hk_hist(
1462
1507
  "lmt": "1000000",
1463
1508
  "_": "1623766962675",
1464
1509
  }
1465
- r = requests.get(url, params=params)
1510
+ r = requests.get(url, timeout=15, params=params)
1466
1511
  data_json = r.json()
1467
1512
  temp_df = pd.DataFrame([item.split(",") for item in data_json["data"]["klines"]])
1468
1513
  if temp_df.empty:
@@ -1495,20 +1540,20 @@ def stock_hk_hist(
1495
1540
  temp_df["涨跌幅"] = pd.to_numeric(temp_df["涨跌幅"], errors="coerce")
1496
1541
  temp_df["涨跌额"] = pd.to_numeric(temp_df["涨跌额"], errors="coerce")
1497
1542
  temp_df["换手率"] = pd.to_numeric(temp_df["换手率"], errors="coerce")
1498
- temp_df['日期'] = pd.to_datetime(temp_df['日期'], errors="coerce").dt.date
1543
+ temp_df["日期"] = pd.to_datetime(temp_df["日期"], errors="coerce").dt.date
1499
1544
  return temp_df
1500
1545
 
1501
1546
 
1502
1547
  def stock_hk_hist_min_em(
1503
- symbol: str = "01611",
1504
- period: str = "1",
1505
- adjust: str = "",
1506
- start_date: str = "1979-09-01 09:32:00",
1507
- end_date: str = "2222-01-01 09:32:00",
1548
+ symbol: str = "01611",
1549
+ period: str = "1",
1550
+ adjust: str = "",
1551
+ start_date: str = "1979-09-01 09:32:00",
1552
+ end_date: str = "2222-01-01 09:32:00",
1508
1553
  ) -> pd.DataFrame:
1509
1554
  """
1510
1555
  东方财富网-行情-港股-每日分时行情
1511
- http://quote.eastmoney.com/hk/00948.html
1556
+ https://quote.eastmoney.com/hk/00948.html
1512
1557
  :param symbol: 股票代码
1513
1558
  :type symbol: str
1514
1559
  :param period: choice of {'1', '5', '15', '30', '60'}
@@ -1528,7 +1573,7 @@ def stock_hk_hist_min_em(
1528
1573
  "hfq": "2",
1529
1574
  }
1530
1575
  if period == "1":
1531
- url = "http://push2his.eastmoney.com/api/qt/stock/trends2/get"
1576
+ url = "https://push2his.eastmoney.com/api/qt/stock/trends2/get"
1532
1577
  params = {
1533
1578
  "fields1": "f1,f2,f3,f4,f5,f6,f7,f8,f9,f10,f11,f12,f13",
1534
1579
  "fields2": "f51,f52,f53,f54,f55,f56,f57,f58",
@@ -1538,7 +1583,7 @@ def stock_hk_hist_min_em(
1538
1583
  "secid": f"116.{symbol}",
1539
1584
  "_": "1623766962675",
1540
1585
  }
1541
- r = requests.get(url, params=params)
1586
+ r = requests.get(url, timeout=15, params=params)
1542
1587
  data_json = r.json()
1543
1588
  temp_df = pd.DataFrame(
1544
1589
  [item.split(",") for item in data_json["data"]["trends"]]
@@ -1566,7 +1611,7 @@ def stock_hk_hist_min_em(
1566
1611
  temp_df["时间"] = pd.to_datetime(temp_df["时间"]).astype(str)
1567
1612
  return temp_df
1568
1613
  else:
1569
- url = "http://push2his.eastmoney.com/api/qt/stock/kline/get"
1614
+ url = "https://push2his.eastmoney.com/api/qt/stock/kline/get"
1570
1615
  params = {
1571
1616
  "fields1": "f1,f2,f3,f4,f5,f6",
1572
1617
  "fields2": "f51,f52,f53,f54,f55,f56,f57,f58,f59,f60,f61",
@@ -1578,7 +1623,7 @@ def stock_hk_hist_min_em(
1578
1623
  "end": "20500000",
1579
1624
  "_": "1630930917857",
1580
1625
  }
1581
- r = requests.get(url, params=params)
1626
+ r = requests.get(url, timeout=15, params=params)
1582
1627
  data_json = r.json()
1583
1628
  temp_df = pd.DataFrame(
1584
1629
  [item.split(",") for item in data_json["data"]["klines"]]
@@ -1635,7 +1680,7 @@ def stock_us_spot_em() -> pd.DataFrame:
1635
1680
  :return: 美股-实时行情; 延迟 15 min
1636
1681
  :rtype: pandas.DataFrame
1637
1682
  """
1638
- url = "http://72.push2.eastmoney.com/api/qt/clist/get"
1683
+ url = "https://72.push2.eastmoney.com/api/qt/clist/get"
1639
1684
  params = {
1640
1685
  "pn": "1",
1641
1686
  "pz": "20000",
@@ -1646,10 +1691,11 @@ def stock_us_spot_em() -> pd.DataFrame:
1646
1691
  "invt": "2",
1647
1692
  "fid": "f3",
1648
1693
  "fs": "m:105,m:106,m:107",
1649
- "fields": "f1,f2,f3,f4,f5,f6,f7,f8,f9,f10,f12,f13,f14,f15,f16,f17,f18,f20,f21,f23,f24,f25,f26,f22,f33,f11,f62,f128,f136,f115,f152",
1694
+ "fields": "f1,f2,f3,f4,f5,f6,f7,f8,f9,f10,f12,f13,f14,f15,f16,f17,f18,f20,"
1695
+ "f21,f23,f24,f25,f26,f22,f33,f11,f62,f128,f136,f115,f152",
1650
1696
  "_": "1624010056945",
1651
1697
  }
1652
- r = requests.get(url, params=params)
1698
+ r = requests.get(url, timeout=15, params=params)
1653
1699
  data_json = r.json()
1654
1700
  temp_df = pd.DataFrame(data_json["data"]["diff"])
1655
1701
  temp_df.columns = [
@@ -1728,11 +1774,11 @@ def stock_us_spot_em() -> pd.DataFrame:
1728
1774
 
1729
1775
 
1730
1776
  def stock_us_hist(
1731
- symbol: str = "105.MSFT",
1732
- period: str = "daily",
1733
- start_date: str = "19700101",
1734
- end_date: str = "22220101",
1735
- adjust: str = "",
1777
+ symbol: str = "105.MSFT",
1778
+ period: str = "daily",
1779
+ start_date: str = "19700101",
1780
+ end_date: str = "22220101",
1781
+ adjust: str = "",
1736
1782
  ) -> pd.DataFrame:
1737
1783
  """
1738
1784
  东方财富网-行情-美股-每日行情
@@ -1752,7 +1798,7 @@ def stock_us_hist(
1752
1798
  """
1753
1799
  period_dict = {"daily": "101", "weekly": "102", "monthly": "103"}
1754
1800
  adjust_dict = {"qfq": "1", "hfq": "2", "": "0"}
1755
- url = "http://63.push2his.eastmoney.com/api/qt/stock/kline/get"
1801
+ url = "https://63.push2his.eastmoney.com/api/qt/stock/kline/get"
1756
1802
  params = {
1757
1803
  "secid": f"{symbol}",
1758
1804
  "ut": "fa5fd1943c7b386f172d6893dbfba10b",
@@ -1764,7 +1810,7 @@ def stock_us_hist(
1764
1810
  "lmt": "1000000",
1765
1811
  "_": "1623766962675",
1766
1812
  }
1767
- r = requests.get(url, params=params)
1813
+ r = requests.get(url, timeout=15, params=params)
1768
1814
  data_json = r.json()
1769
1815
  if not data_json["data"]["klines"]:
1770
1816
  return pd.DataFrame()
@@ -1782,7 +1828,7 @@ def stock_us_hist(
1782
1828
  "涨跌额",
1783
1829
  "换手率",
1784
1830
  ]
1785
- temp_df.index = pd.to_datetime(temp_df["日期"])
1831
+ temp_df.index = pd.to_datetime(temp_df["日期"], errors="coerce")
1786
1832
  temp_df = temp_df[start_date:end_date]
1787
1833
  temp_df.reset_index(inplace=True, drop=True)
1788
1834
  temp_df["开盘"] = pd.to_numeric(temp_df["开盘"], errors="coerce")
@@ -1795,18 +1841,18 @@ def stock_us_hist(
1795
1841
  temp_df["涨跌幅"] = pd.to_numeric(temp_df["涨跌幅"], errors="coerce")
1796
1842
  temp_df["涨跌额"] = pd.to_numeric(temp_df["涨跌额"], errors="coerce")
1797
1843
  temp_df["换手率"] = pd.to_numeric(temp_df["换手率"], errors="coerce")
1798
- temp_df.sort_values(["日期"], inplace=True)
1844
+ temp_df.sort_values(["日期"], inplace=True, ignore_index=True)
1799
1845
  return temp_df
1800
1846
 
1801
1847
 
1802
1848
  def stock_us_hist_min_em(
1803
- symbol: str = "105.ATER",
1804
- start_date: str = "1979-09-01 09:32:00",
1805
- end_date: str = "2222-01-01 09:32:00",
1849
+ symbol: str = "105.ATER",
1850
+ start_date: str = "1979-09-01 09:32:00",
1851
+ end_date: str = "2222-01-01 09:32:00",
1806
1852
  ) -> pd.DataFrame:
1807
1853
  """
1808
1854
  东方财富网-行情首页-美股-每日分时行情
1809
- http://quote.eastmoney.com/us/ATER.html
1855
+ https://quote.eastmoney.com/us/ATER.html
1810
1856
  :param symbol: 股票代码
1811
1857
  :type symbol: str
1812
1858
  :param start_date: 开始日期
@@ -1816,7 +1862,7 @@ def stock_us_hist_min_em(
1816
1862
  :return: 每日分时行情
1817
1863
  :rtype: pandas.DataFrame
1818
1864
  """
1819
- url = "http://push2his.eastmoney.com/api/qt/stock/trends2/get"
1865
+ url = "https://push2his.eastmoney.com/api/qt/stock/trends2/get"
1820
1866
  params = {
1821
1867
  "fields1": "f1,f2,f3,f4,f5,f6,f7,f8,f9,f10,f11,f12,f13",
1822
1868
  "fields2": "f51,f52,f53,f54,f55,f56,f57,f58",
@@ -1826,7 +1872,7 @@ def stock_us_hist_min_em(
1826
1872
  "secid": f"{symbol.split('.')[0]}.{symbol.split('.')[1]}",
1827
1873
  "_": "1623766962675",
1828
1874
  }
1829
- r = requests.get(url, params=params)
1875
+ r = requests.get(url, params=params, timeout=15)
1830
1876
  data_json = r.json()
1831
1877
  if not data_json["data"]["trends"]:
1832
1878
  return pd.DataFrame()
@@ -1841,7 +1887,7 @@ def stock_us_hist_min_em(
1841
1887
  "成交额",
1842
1888
  "最新价",
1843
1889
  ]
1844
- temp_df.index = pd.to_datetime(temp_df["时间"])
1890
+ temp_df.index = pd.to_datetime(temp_df["时间"], errors="coerce")
1845
1891
  temp_df = temp_df[start_date:end_date]
1846
1892
  temp_df.reset_index(drop=True, inplace=True)
1847
1893
  temp_df["开盘"] = pd.to_numeric(temp_df["开盘"], errors="coerce")
@@ -1851,7 +1897,7 @@ def stock_us_hist_min_em(
1851
1897
  temp_df["成交量"] = pd.to_numeric(temp_df["成交量"], errors="coerce")
1852
1898
  temp_df["成交额"] = pd.to_numeric(temp_df["成交额"], errors="coerce")
1853
1899
  temp_df["最新价"] = pd.to_numeric(temp_df["最新价"], errors="coerce")
1854
- temp_df["时间"] = pd.to_datetime(temp_df["时间"]).astype(str)
1900
+ temp_df["时间"] = pd.to_datetime(temp_df["时间"], errors="coerce").astype(str)
1855
1901
  return temp_df
1856
1902
 
1857
1903
 
@@ -1893,12 +1939,12 @@ if __name__ == "__main__":
1893
1939
  symbol="000001",
1894
1940
  period="daily",
1895
1941
  start_date="20170301",
1896
- end_date="20231030",
1897
- adjust="",
1942
+ end_date="20240528",
1943
+ adjust="hfq",
1898
1944
  )
1899
1945
  print(stock_zh_a_hist_df)
1900
1946
 
1901
- stock_zh_a_hist_min_em_df = stock_zh_a_hist_min_em(symbol="833454", period="1")
1947
+ stock_zh_a_hist_min_em_df = stock_zh_a_hist_min_em(symbol="603777", period="1")
1902
1948
  print(stock_zh_a_hist_min_em_df)
1903
1949
 
1904
1950
  stock_zh_a_hist_pre_min_em_df = stock_zh_a_hist_pre_min_em(symbol="000001")
@@ -1938,7 +1984,7 @@ if __name__ == "__main__":
1938
1984
  symbol="106.TTE",
1939
1985
  period="daily",
1940
1986
  start_date="20200101",
1941
- end_date="20240213",
1987
+ end_date="20240414",
1942
1988
  adjust="qfq",
1943
1989
  )
1944
1990
  print(stock_us_hist_df)
@@ -1955,8 +2001,15 @@ if __name__ == "__main__":
1955
2001
  stock_us_hist_min_em_df = stock_us_hist_min_em(symbol="106.TTE")
1956
2002
  print(stock_us_hist_min_em_df)
1957
2003
 
2004
+ stock_us_hist_min_em_df = stock_us_hist_min_em(symbol="105.ATER")
2005
+ print(stock_us_hist_min_em_df)
2006
+
1958
2007
  stock_zh_a_hist_min_em_df = stock_zh_a_hist_min_em(
1959
- symbol="000001", period="5", adjust="qfq"
2008
+ symbol="000001",
2009
+ start_date="2024-03-20 09:30:00",
2010
+ end_date="2024-03-20 15:00:00",
2011
+ period="5",
2012
+ adjust="hfq",
1960
2013
  )
1961
2014
  print(stock_zh_a_hist_min_em_df)
1962
2015
 
@@ -1964,7 +2017,7 @@ if __name__ == "__main__":
1964
2017
  symbol="833454",
1965
2018
  period="daily",
1966
2019
  start_date="20170301",
1967
- end_date="20211115",
2020
+ end_date="20241115",
1968
2021
  adjust="hfq",
1969
2022
  )
1970
2023
  print(stock_zh_a_hist_df)
@@ -1973,8 +2026,8 @@ if __name__ == "__main__":
1973
2026
  symbol="01611",
1974
2027
  period="1",
1975
2028
  adjust="",
1976
- start_date="2022-10-02 09:30:00",
1977
- end_date="2022-10-29 18:32:00",
2029
+ start_date="2024-04-12 09:30:00",
2030
+ end_date="2024-04-12 18:32:00",
1978
2031
  )
1979
2032
  print(stock_hk_hist_min_em_df)
1980
2033