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,11 +1,12 @@
1
1
  #!/usr/bin/env python
2
2
  # -*- coding:utf-8 -*-
3
3
  """
4
- Date: 2023/11/14 20:20
4
+ Date: 2024/4/4 18:20
5
5
  Desc: 东方财富网-数据中心-特色数据-千股千评
6
6
  https://data.eastmoney.com/stockcomment/
7
7
  """
8
- from datetime import datetime
8
+
9
+ import time
9
10
 
10
11
  import pandas as pd
11
12
  import requests
@@ -27,7 +28,8 @@ def stock_comment_em() -> pd.DataFrame:
27
28
  "pageSize": "500",
28
29
  "pageNumber": "1",
29
30
  "reportName": "RPT_DMSK_TS_STOCKNEW",
30
- "quoteColumns": "f2~01~SECURITY_CODE~CLOSE_PRICE,f8~01~SECURITY_CODE~TURNOVERRATE,f3~01~SECURITY_CODE~CHANGE_RATE,f9~01~SECURITY_CODE~PE_DYNAMIC",
31
+ "quoteColumns": "f2~01~SECURITY_CODE~CLOSE_PRICE,f8~01~SECURITY_CODE~TURNOVERRATE,"
32
+ "f3~01~SECURITY_CODE~CHANGE_RATE,f9~01~SECURITY_CODE~PE_DYNAMIC",
31
33
  "columns": "ALL",
32
34
  "filter": "",
33
35
  "token": "894050c76af8597a853f5b408b759f5d",
@@ -42,7 +44,7 @@ def stock_comment_em() -> pd.DataFrame:
42
44
  r = requests.get(url, params=params)
43
45
  data_json = r.json()
44
46
  temp_df = pd.DataFrame(data_json["result"]["data"])
45
- big_df = pd.concat([big_df, temp_df], ignore_index=True)
47
+ big_df = pd.concat(objs=[big_df, temp_df], ignore_index=True)
46
48
 
47
49
  big_df.reset_index(inplace=True)
48
50
  big_df["index"] = big_df.index + 1
@@ -108,7 +110,7 @@ def stock_comment_em() -> pd.DataFrame:
108
110
  big_df["上升"] = pd.to_numeric(big_df["上升"], errors="coerce")
109
111
  big_df["目前排名"] = pd.to_numeric(big_df["目前排名"], errors="coerce")
110
112
  big_df["关注指数"] = pd.to_numeric(big_df["关注指数"], errors="coerce")
111
- big_df["交易日"] = pd.to_datetime(big_df["交易日"]).dt.date
113
+ big_df["交易日"] = pd.to_datetime(big_df["交易日"], errors="coerce").dt.date
112
114
  return big_df
113
115
 
114
116
 
@@ -121,7 +123,7 @@ def stock_comment_detail_zlkp_jgcyd_em(symbol: str = "600000") -> pd.DataFrame:
121
123
  :return: 主力控盘-机构参与度
122
124
  :rtype: pandas.DataFrame
123
125
  """
124
- url = f"https://datacenter-web.eastmoney.com/api/data/v1/get"
126
+ url = "https://datacenter-web.eastmoney.com/api/data/v1/get"
125
127
  params = {
126
128
  "reportName": "RPT_DMSK_TS_STOCKEVALUATE",
127
129
  "filter": f'(SECURITY_CODE="{symbol}")',
@@ -136,11 +138,11 @@ def stock_comment_detail_zlkp_jgcyd_em(symbol: str = "600000") -> pd.DataFrame:
136
138
  data_json = r.json()
137
139
  temp_df = pd.DataFrame(data_json["result"]["data"])
138
140
  temp_df = temp_df[["TRADE_DATE", "ORG_PARTICIPATE"]]
139
- temp_df.columns = ["date", "value"]
140
- temp_df["date"] = pd.to_datetime(temp_df["date"], errors="coerce").dt.date
141
- temp_df.sort_values(["date"], inplace=True)
141
+ temp_df.columns = ["交易日", "机构参与度"]
142
+ temp_df["交易日"] = pd.to_datetime(temp_df["交易日"], errors="coerce").dt.date
143
+ temp_df.sort_values(["交易日"], inplace=True)
142
144
  temp_df.reset_index(inplace=True, drop=True)
143
- temp_df["value"] = pd.to_numeric(temp_df["value"], errors="coerce") * 100
145
+ temp_df["机构参与度"] = pd.to_numeric(temp_df["机构参与度"], errors="coerce") * 100
144
146
  return temp_df
145
147
 
146
148
 
@@ -153,23 +155,31 @@ def stock_comment_detail_zhpj_lspf_em(symbol: str = "600000") -> pd.DataFrame:
153
155
  :return: 综合评价-历史评分
154
156
  :rtype: pandas.DataFrame
155
157
  """
156
- url = f"https://data.eastmoney.com/stockcomment/api/{symbol}.json"
157
- r = requests.get(url)
158
+ url = "https://datacenter-web.eastmoney.com/api/data/v1/get"
159
+ params = {
160
+ "filter": f'(SECURITY_CODE="{symbol}")',
161
+ "columns": "ALL",
162
+ "source": "WEB",
163
+ "client": "WEB",
164
+ "reportName": "RPT_STOCK_HISTORYMARK",
165
+ "sortColumns": "DIAGNOSE_DATE",
166
+ "sortTypes": "1",
167
+ }
168
+ r = requests.get(url=url, params=params)
158
169
  data_json = r.json()
159
- temp_df = pd.DataFrame(
160
- [
161
- data_json["ApiResults"]["zhpj"]["HistoryScore"]["XData"],
162
- data_json["ApiResults"]["zhpj"]["HistoryScore"]["Ydata"]["Score"],
163
- data_json["ApiResults"]["zhpj"]["HistoryScore"]["Ydata"]["Price"],
164
- ]
165
- ).T
166
- temp_df.columns = ["日期", "评分", "股价"]
167
- temp_df["日期"] = str(datetime.now().year) + "-" + temp_df["日期"]
168
- temp_df["日期"] = pd.to_datetime(temp_df["日期"], errors="coerce").dt.date
169
- temp_df.sort_values(["日期"], inplace=True)
170
+ temp_df = pd.DataFrame(data_json["result"]["data"])
171
+ temp_df.rename(
172
+ columns={
173
+ "TOTAL_SCORE": "评分",
174
+ "DIAGNOSE_DATE": "交易日",
175
+ },
176
+ inplace=True,
177
+ )
178
+ temp_df = temp_df[["交易日", "评分"]]
179
+ temp_df["交易日"] = pd.to_datetime(temp_df["交易日"], errors="coerce").dt.date
180
+ temp_df.sort_values(by=["交易日"], inplace=True)
170
181
  temp_df.reset_index(inplace=True, drop=True)
171
182
  temp_df["评分"] = pd.to_numeric(temp_df["评分"], errors="coerce")
172
- temp_df["股价"] = pd.to_numeric(temp_df["股价"], errors="coerce")
173
183
  return temp_df
174
184
 
175
185
 
@@ -182,28 +192,37 @@ def stock_comment_detail_scrd_focus_em(symbol: str = "600000") -> pd.DataFrame:
182
192
  :return: 市场热度-用户关注指数
183
193
  :rtype: pandas.DataFrame
184
194
  """
185
- url = f"https://data.eastmoney.com/stockcomment/api/{symbol}.json"
186
- r = requests.get(url)
195
+ url = "https://datacenter-web.eastmoney.com/api/data/v1/get"
196
+ params = {
197
+ "filter": f'(SECURITY_CODE="{symbol}")',
198
+ "columns": "ALL",
199
+ "source": "WEB",
200
+ "client": "WEB",
201
+ "reportName": "RPT_STOCK_MARKETFOCUS",
202
+ "sortColumns": "TRADE_DATE",
203
+ "sortTypes": "-1",
204
+ "pageSize": "30",
205
+ }
206
+ r = requests.get(url=url, params=params)
187
207
  data_json = r.json()
188
- temp_df = pd.DataFrame(
189
- [
190
- data_json["ApiResults"]["scrd"]["focus"][1]["XData"],
191
- data_json["ApiResults"]["scrd"]["focus"][1]["Ydata"]["StockFocus"],
192
- data_json["ApiResults"]["scrd"]["focus"][1]["Ydata"]["ClosePrice"],
193
- ]
194
- ).T
195
- temp_df.columns = ["日期", "用户关注指数", "收盘价"]
196
- temp_df["日期"] = str(datetime.now().year) + "-" + temp_df["日期"]
197
- temp_df["日期"] = pd.to_datetime(temp_df["日期"], errors="coerce").dt.date
198
- temp_df.sort_values(["日期"], inplace=True)
208
+ temp_df = pd.DataFrame(data_json["result"]["data"])
209
+ temp_df.rename(
210
+ columns={
211
+ "MARKET_FOCUS": "用户关注指数",
212
+ "TRADE_DATE": "交易日",
213
+ },
214
+ inplace=True,
215
+ )
216
+ temp_df = temp_df[["交易日", "用户关注指数"]]
217
+ temp_df["交易日"] = pd.to_datetime(temp_df["交易日"], errors="coerce").dt.date
218
+ temp_df.sort_values(by=["交易日"], inplace=True)
199
219
  temp_df.reset_index(inplace=True, drop=True)
200
220
  temp_df["用户关注指数"] = pd.to_numeric(temp_df["用户关注指数"], errors="coerce")
201
- temp_df["收盘价"] = pd.to_numeric(temp_df["收盘价"], errors="coerce")
202
221
  return temp_df
203
222
 
204
223
 
205
224
  def stock_comment_detail_scrd_desire_em(
206
- symbol: str = "600000",
225
+ symbol: str = "600000",
207
226
  ) -> pd.DataFrame:
208
227
  """
209
228
  东方财富网-数据中心-特色数据-千股千评-市场热度-市场参与意愿
@@ -214,8 +233,18 @@ def stock_comment_detail_scrd_desire_em(
214
233
  :rtype: pandas.DataFrame
215
234
  """
216
235
  url = f"https://data.eastmoney.com/stockcomment/api/{symbol}.json"
217
- r = requests.get(url)
218
- data_json = r.json()
236
+ try_count = 10
237
+ data_json = None
238
+ while try_count:
239
+ try:
240
+ r = requests.get(url)
241
+ data_json = r.json()
242
+ break
243
+ except requests.exceptions.JSONDecodeError:
244
+ try_count -= 1
245
+ time.sleep(1)
246
+ continue
247
+
219
248
  date_str = (
220
249
  data_json["ApiResults"]["scrd"]["desire"][0][0]["UpdateTime"]
221
250
  .split(" ")[0]
@@ -225,21 +254,15 @@ def stock_comment_detail_scrd_desire_em(
225
254
  temp_df = pd.DataFrame(
226
255
  [
227
256
  data_json["ApiResults"]["scrd"]["desire"][1]["XData"],
228
- data_json["ApiResults"]["scrd"]["desire"][1]["Ydata"][
229
- "MajorPeopleNumChg"
230
- ],
231
- data_json["ApiResults"]["scrd"]["desire"][1]["Ydata"][
232
- "PeopleNumChange"
233
- ],
234
- data_json["ApiResults"]["scrd"]["desire"][1]["Ydata"][
235
- "RetailPeopleNumChg"
236
- ],
257
+ data_json["ApiResults"]["scrd"]["desire"][1]["Ydata"]["MajorPeopleNumChg"],
258
+ data_json["ApiResults"]["scrd"]["desire"][1]["Ydata"]["PeopleNumChange"],
259
+ data_json["ApiResults"]["scrd"]["desire"][1]["Ydata"]["RetailPeopleNumChg"],
237
260
  ]
238
261
  ).T
239
262
  temp_df.columns = ["日期时间", "大户", "全部", "散户"]
240
263
  temp_df["日期时间"] = date_str + " " + temp_df["日期时间"]
241
264
  temp_df["日期时间"] = pd.to_datetime(temp_df["日期时间"], errors="coerce")
242
- temp_df.sort_values(["日期时间"], inplace=True)
265
+ temp_df.sort_values(by=["日期时间"], inplace=True)
243
266
  temp_df.reset_index(inplace=True, drop=True)
244
267
  temp_df["大户"] = pd.to_numeric(temp_df["大户"], errors="coerce")
245
268
  temp_df["全部"] = pd.to_numeric(temp_df["全部"], errors="coerce")
@@ -248,7 +271,7 @@ def stock_comment_detail_scrd_desire_em(
248
271
 
249
272
 
250
273
  def stock_comment_detail_scrd_desire_daily_em(
251
- symbol: str = "600000",
274
+ symbol: str = "600000",
252
275
  ) -> pd.DataFrame:
253
276
  """
254
277
  东方财富网-数据中心-特色数据-千股千评-市场热度-日度市场参与意愿
@@ -258,34 +281,37 @@ def stock_comment_detail_scrd_desire_daily_em(
258
281
  :return: 市场热度-日度市场参与意愿
259
282
  :rtype: pandas.DataFrame
260
283
  """
261
- url = f"https://data.eastmoney.com/stockcomment/api/{symbol}.json"
262
- r = requests.get(url)
284
+ url = "https://datacenter-web.eastmoney.com/api/data/v1/get"
285
+ params = {
286
+ "filter": f'(SECURITY_CODE="{symbol}")',
287
+ "columns": "ALL",
288
+ "source": "WEB",
289
+ "client": "WEB",
290
+ "reportName": "RPT_STOCK_PARTICIPATION",
291
+ "sortColumns": "TRADE_DATE",
292
+ "sortTypes": "-1",
293
+ "pageSize": "30",
294
+ "_": "1727189719991",
295
+ }
296
+ r = requests.get(url=url, params=params)
263
297
  data_json = r.json()
264
- date_str = (
265
- data_json["ApiResults"]["scrd"]["desire"][0][0]["UpdateTime"]
266
- .split(" ")[0]
267
- .replace("/", "-")
298
+ temp_df = pd.DataFrame(data_json["result"]["data"])
299
+ temp_df.rename(
300
+ columns={
301
+ "PARTICIPATION_WISH_5DAYSCHANGE": "5日平均参与意愿变化",
302
+ "PARTICIPATION_WISH_CHANGE": "当日意愿上升",
303
+ "TRADE_DATE": "交易日",
304
+ },
305
+ inplace=True,
268
306
  )
269
-
270
- temp_df = pd.DataFrame(
271
- [
272
- data_json["ApiResults"]["scrd"]["desire"][2]["XData"],
273
- data_json["ApiResults"]["scrd"]["desire"][2]["Ydata"][
274
- "PeopleNumChg"
275
- ],
276
- data_json["ApiResults"]["scrd"]["desire"][2]["Ydata"][
277
- "TotalPeopleNumChange"
278
- ],
279
- ]
280
- ).T
281
- temp_df.columns = ["日期", "当日意愿下降", "五日累计意愿"]
282
- temp_df["日期"] = date_str[:4] + "-" + temp_df["日期"]
283
- temp_df["日期"] = pd.to_datetime(temp_df["日期"], errors="coerce").dt.date
284
-
285
- temp_df.sort_values(["日期"], inplace=True)
307
+ temp_df = temp_df[["交易日", "当日意愿上升", "5日平均参与意愿变化"]]
308
+ temp_df["交易日"] = pd.to_datetime(temp_df["交易日"], errors="coerce").dt.date
309
+ temp_df.sort_values(by=["交易日"], inplace=True)
286
310
  temp_df.reset_index(inplace=True, drop=True)
287
- temp_df["当日意愿下降"] = pd.to_numeric(temp_df["当日意愿下降"], errors="coerce")
288
- temp_df["五日累计意愿"] = pd.to_numeric(temp_df["五日累计意愿"], errors="coerce")
311
+ temp_df["当日意愿上升"] = pd.to_numeric(temp_df["当日意愿上升"], errors="coerce")
312
+ temp_df["5日平均参与意愿变化"] = pd.to_numeric(
313
+ temp_df["5日平均参与意愿变化"], errors="coerce"
314
+ )
289
315
  return temp_df
290
316
 
291
317
 
@@ -299,8 +325,17 @@ def stock_comment_detail_scrd_cost_em(symbol: str = "600000") -> pd.DataFrame:
299
325
  :rtype: pandas.DataFrame
300
326
  """
301
327
  url = f"https://data.eastmoney.com/stockcomment/api/{symbol}.json"
302
- r = requests.get(url)
303
- data_json = r.json()
328
+ try_count = 10
329
+ data_json = None
330
+ while try_count:
331
+ try:
332
+ r = requests.get(url)
333
+ data_json = r.json()
334
+ break
335
+ except requests.exceptions.JSONDecodeError:
336
+ try_count -= 1
337
+ time.sleep(1)
338
+ continue
304
339
  date_str = (
305
340
  data_json["ApiResults"]["scrd"]["cost"][0][0]["UpdateDate"]
306
341
  .split(" ")[0]
@@ -311,15 +346,13 @@ def stock_comment_detail_scrd_cost_em(symbol: str = "600000") -> pd.DataFrame:
311
346
  [
312
347
  data_json["ApiResults"]["scrd"]["cost"][1]["XData"],
313
348
  data_json["ApiResults"]["scrd"]["cost"][1]["Ydata"]["AvgBuyPrice"],
314
- data_json["ApiResults"]["scrd"]["cost"][1]["Ydata"][
315
- "FiveDayAvgBuyPrice"
316
- ],
349
+ data_json["ApiResults"]["scrd"]["cost"][1]["Ydata"]["FiveDayAvgBuyPrice"],
317
350
  ]
318
351
  ).T
319
352
  temp_df.columns = ["日期", "市场成本", "5日市场成本"]
320
353
  temp_df["日期"] = date_str[:4] + "-" + temp_df["日期"]
321
354
  temp_df["日期"] = pd.to_datetime(temp_df["日期"], errors="coerce").dt.date
322
- temp_df.sort_values(["日期"], inplace=True)
355
+ temp_df.sort_values(by=["日期"], inplace=True)
323
356
  temp_df.reset_index(inplace=True, drop=True)
324
357
  temp_df["市场成本"] = pd.to_numeric(temp_df["市场成本"], errors="coerce")
325
358
  temp_df["5日市场成本"] = pd.to_numeric(temp_df["5日市场成本"], errors="coerce")
@@ -345,8 +378,8 @@ if __name__ == "__main__":
345
378
  )
346
379
  print(stock_comment_detail_scrd_focus_em_df)
347
380
 
348
- stock_comment_detail_scrd_desire_em_df = (
349
- stock_comment_detail_scrd_desire_em(symbol="600000")
381
+ stock_comment_detail_scrd_desire_em_df = stock_comment_detail_scrd_desire_em(
382
+ symbol="600000"
350
383
  )
351
384
  print(stock_comment_detail_scrd_desire_em_df)
352
385
 
@@ -0,0 +1,183 @@
1
+ #!/usr/bin/env python
2
+ # -*- coding:utf-8 -*-
3
+ """
4
+ Date: 2024/7/16 22:00
5
+ Desc: 富途牛牛-主题投资-概念板块-成分股
6
+ https://www.futunn.com/quote/sparks-us
7
+ """
8
+
9
+ import json
10
+
11
+ import pandas as pd
12
+ import requests
13
+ from bs4 import BeautifulSoup
14
+
15
+
16
+ def _stock_concept_cons_futu(symbol: str = "巴菲特持仓") -> pd.DataFrame:
17
+ """
18
+ 富途牛牛-主题投资-概念板块-成分股
19
+ https://www.futunn.com/quote/sparks-us
20
+ :param symbol: 板块名称; choice of {"巴菲特持仓", "佩洛西持仓"}
21
+ :type symbol: str
22
+ :return: 概念板块
23
+ :rtype: pandas.DataFrame
24
+ """
25
+ symbol_map = {
26
+ "巴菲特持仓": "BK2999",
27
+ "佩洛西持仓": "BK20883",
28
+ }
29
+ url = f"https://www.futunn.com/stock/{symbol_map[symbol]}"
30
+ # 定义查询参数
31
+ params = {"global_content": json.dumps({"promote_id": 13766, "sub_promote_id": 24})}
32
+ headers = {
33
+ "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 "
34
+ "(KHTML, like Gecko) Chrome/126.0.0.0 Safari/537.36",
35
+ }
36
+ r = requests.get(url, params=params, headers=headers)
37
+ soup = BeautifulSoup(r.text, features="lxml")
38
+ temp_code_name = [
39
+ item.find_all("div", attrs={"class": "fix-left"})
40
+ for item in soup.find(name="div", attrs={"class": "content-main"}).find_all("a")
41
+ ]
42
+ temp_value_list = [
43
+ item.find_all("div", attrs={"class": "middle"})
44
+ for item in soup.find(name="div", attrs={"class": "content-main"}).find_all("a")
45
+ ]
46
+ code_name_list = [item[0].find_all("span") for item in temp_code_name]
47
+
48
+ quant_list = [item[0].find_all("span") for item in temp_value_list]
49
+ temp_df = pd.DataFrame(
50
+ [
51
+ [item[0]["title"] for item in code_name_list],
52
+ [item[1]["title"] for item in code_name_list],
53
+ [item[0]["title"] for item in quant_list],
54
+ [item[1]["title"] for item in quant_list],
55
+ [item[2]["title"] for item in quant_list],
56
+ [item[3]["title"] for item in quant_list],
57
+ [item[4]["title"] for item in quant_list],
58
+ [item[5]["title"] for item in quant_list],
59
+ [item[6]["title"] for item in quant_list],
60
+ [item[7]["title"] for item in quant_list],
61
+ [item[8]["title"] for item in quant_list],
62
+ [item[9]["title"] for item in quant_list],
63
+ [item[10]["title"] for item in quant_list],
64
+ [item[11]["title"] for item in quant_list],
65
+ [item[12]["title"] for item in quant_list],
66
+ [item[13]["title"] for item in quant_list],
67
+ [item[14]["title"] for item in quant_list],
68
+ ]
69
+ ).T
70
+ temp_df.columns = [
71
+ "代码",
72
+ "股票名称",
73
+ "最新价",
74
+ "涨跌额",
75
+ "涨跌幅",
76
+ "成交量",
77
+ "成交额",
78
+ "-",
79
+ "-",
80
+ "-",
81
+ "-",
82
+ "-",
83
+ "-",
84
+ "-",
85
+ "-",
86
+ "-",
87
+ "-",
88
+ ]
89
+ temp_df = temp_df[
90
+ [
91
+ "代码",
92
+ "股票名称",
93
+ "最新价",
94
+ "涨跌额",
95
+ "涨跌幅",
96
+ "成交量",
97
+ "成交额",
98
+ ]
99
+ ]
100
+ return temp_df
101
+
102
+
103
+ def stock_concept_cons_futu(symbol: str = "特朗普概念股") -> pd.DataFrame:
104
+ """
105
+ 富途牛牛-主题投资-概念板块-成分股
106
+ https://www.futunn.com/quote/sparks-us
107
+ :param symbol: 板块名称; choice of {"巴菲特持仓", "佩洛西持仓", "特朗普概念股"}
108
+ :type symbol: str
109
+ :return: 概念板块
110
+ :rtype: pandas.DataFrame
111
+ """
112
+ if symbol == "特朗普概念股":
113
+ url = "https://www.futunn.com/quote-api/quote-v2/get-plate-stock"
114
+ params = {
115
+ "marketType": "2",
116
+ "plateId": "10102960",
117
+ "page": "0",
118
+ "pageSize": "30",
119
+ }
120
+ headers = {
121
+ "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 "
122
+ "(KHTML, like Gecko) Chrome/126.0.0.0 Safari/537.36",
123
+ "Quote-Token": "7f74cd2a5e",
124
+ }
125
+ r = requests.get(url, params=params, headers=headers)
126
+ data_json = r.json()
127
+ total_page = data_json["data"]["pagination"]["pageCount"]
128
+ big_df = pd.DataFrame()
129
+ for page in range(0, total_page):
130
+ params.update(
131
+ {
132
+ "page": page,
133
+ }
134
+ )
135
+ if page == 1:
136
+ headers.update({"Quote-Token": "a3043d6fed"})
137
+ r = requests.get(url, params=params, headers=headers)
138
+ data_json = r.json()
139
+ temp_df = pd.DataFrame(data_json["data"]["list"])
140
+ big_df = pd.concat(objs=[big_df, temp_df], ignore_index=True)
141
+
142
+ big_df.rename(
143
+ columns={
144
+ "stockCode": "代码",
145
+ "name": "股票名称",
146
+ "price": "最新价",
147
+ "change": "涨跌额",
148
+ "changeRatio": "涨跌幅",
149
+ "tradeVolumn": "成交量",
150
+ "tradeTrunover": "成交额",
151
+ },
152
+ inplace=True,
153
+ )
154
+ big_df = big_df[
155
+ [
156
+ "代码",
157
+ "股票名称",
158
+ "最新价",
159
+ "涨跌额",
160
+ "涨跌幅",
161
+ "成交量",
162
+ "成交额",
163
+ ]
164
+ ]
165
+ big_df["最新价"] = pd.to_numeric(big_df["最新价"], errors="coerce")
166
+ big_df["涨跌额"] = pd.to_numeric(big_df["涨跌额"], errors="coerce")
167
+ return big_df
168
+ else:
169
+ temp_df = _stock_concept_cons_futu(symbol)
170
+ temp_df["最新价"] = pd.to_numeric(temp_df["最新价"], errors="coerce")
171
+ temp_df["涨跌额"] = pd.to_numeric(temp_df["涨跌额"], errors="coerce")
172
+ return temp_df
173
+
174
+
175
+ if __name__ == "__main__":
176
+ stock_concept_cons_futu_df = stock_concept_cons_futu(symbol="特朗普概念股")
177
+ print(stock_concept_cons_futu_df)
178
+
179
+ stock_concept_cons_futu_df = stock_concept_cons_futu(symbol="巴菲特持仓")
180
+ print(stock_concept_cons_futu_df)
181
+
182
+ stock_concept_cons_futu_df = stock_concept_cons_futu(symbol="佩洛西持仓")
183
+ print(stock_concept_cons_futu_df)