akshare 1.12.99__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 (236) hide show
  1. akshare/__init__.py +441 -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.72.dist-info}/METADATA +52 -69
  215. akshare-1.15.72.dist-info/RECORD +385 -0
  216. {akshare-1.12.99.dist-info → akshare-1.15.72.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.72.dist-info}/LICENSE +0 -0
  236. {akshare-1.12.99.dist-info → akshare-1.15.72.dist-info}/top_level.txt +0 -0
@@ -1,15 +1,17 @@
1
1
  #!/usr/bin/env python
2
2
  # -*- coding:utf-8 -*-
3
3
  """
4
- Date: 2023/7/14 15:19
4
+ Date: 2024/11/30 18:00
5
5
  Desc: 期货日线行情
6
6
  """
7
+
7
8
  import datetime
8
9
  import json
9
10
  import re
10
11
  import zipfile
11
12
  from io import BytesIO, StringIO
12
13
 
14
+ import numpy as np
13
15
  import pandas as pd
14
16
  import requests
15
17
 
@@ -20,7 +22,7 @@ calendar = cons.get_calendar()
20
22
 
21
23
 
22
24
  def _futures_daily_czce(
23
- date: str = "20100824", dataset: str = "datahistory2010"
25
+ date: str = "20100824", dataset: str = "datahistory2010"
24
26
  ) -> pd.DataFrame:
25
27
  """
26
28
  郑州商品交易所-交易数据-历史行情下载
@@ -42,10 +44,9 @@ def _futures_daily_czce(
42
44
  data_df.dropna(axis=1, inplace=True)
43
45
  for column in data_df.columns:
44
46
  try:
45
-
46
47
  data_df[column] = data_df[column].str.strip("\t")
47
48
  data_df[column] = data_df[column].str.replace(",", "")
48
- except:
49
+ except: # noqa: E722
49
50
  data_df[column] = data_df[column]
50
51
  data_df["昨结算"] = pd.to_numeric(data_df["昨结算"])
51
52
  data_df["今开盘"] = pd.to_numeric(data_df["今开盘"])
@@ -79,8 +80,7 @@ def _futures_daily_czce(
79
80
  "-",
80
81
  ]
81
82
  variety_list = [
82
- re.compile(r"[a-zA-Z_]+").findall(item)[0]
83
- for item in data_df["symbol"]
83
+ re.compile(r"[a-zA-Z_]+").findall(item)[0] for item in data_df["symbol"]
84
84
  ]
85
85
  data_df["variety"] = variety_list
86
86
  data_df = data_df[
@@ -114,17 +114,14 @@ def get_cffex_daily(date: str = "20100416") -> pd.DataFrame:
114
114
  :return: 日频率交易数据
115
115
  :rtype: pandas.DataFrame
116
116
  """
117
- day = (
118
- cons.convert_date(date) if date is not None else datetime.date.today()
119
- )
117
+ day = cons.convert_date(date) if date is not None else datetime.date.today()
120
118
  if day.strftime("%Y%m%d") not in calendar:
121
119
  # warnings.warn("%s非交易日" % day.strftime("%Y%m%d"))
122
- return None
123
- url = (
124
- f"http://www.cffex.com.cn/sj/historysj/{date[:-2]}/zip/{date[:-2]}.zip"
125
- )
120
+ return pd.DataFrame()
121
+ url = f"http://www.cffex.com.cn/sj/historysj/{date[:-2]}/zip/{date[:-2]}.zip"
126
122
  headers = {
127
- "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/108.0.0.0 Safari/537.36",
123
+ "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) "
124
+ "Chrome/108.0.0.0 Safari/537.36",
128
125
  }
129
126
  r = requests.get(url, headers=headers)
130
127
  try:
@@ -132,8 +129,8 @@ def get_cffex_daily(date: str = "20100416") -> pd.DataFrame:
132
129
  with file.open(f"{date}_1.csv") as my_file:
133
130
  data = my_file.read().decode("gb2312")
134
131
  data_df = pd.read_csv(StringIO(data))
135
- except:
136
- return None
132
+ except: # noqa: E722
133
+ return pd.DataFrame()
137
134
  data_df = data_df[data_df["合约代码"] != "小计"]
138
135
  data_df = data_df[data_df["合约代码"] != "合计"]
139
136
  data_df = data_df[~data_df["合约代码"].str.contains("IO")]
@@ -142,9 +139,7 @@ def get_cffex_daily(date: str = "20100416") -> pd.DataFrame:
142
139
  data_df.reset_index(inplace=True, drop=True)
143
140
  data_df["合约代码"] = data_df["合约代码"].str.strip()
144
141
  symbol_list = data_df["合约代码"].to_list()
145
- variety_list = [
146
- re.compile(r"[a-zA-Z_]+").findall(item)[0] for item in symbol_list
147
- ]
142
+ variety_list = [re.compile(r"[a-zA-Z_]+").findall(item)[0] for item in symbol_list]
148
143
  if data_df.shape[1] == 15:
149
144
  data_df.columns = [
150
145
  "symbol",
@@ -211,17 +206,12 @@ def get_gfex_daily(date: str = "20221223") -> pd.DataFrame:
211
206
  :return: 广州期货交易所-日频率-量价数据
212
207
  :rtype: pandas.DataFrame
213
208
  """
214
- day = (
215
- cons.convert_date(date) if date is not None else datetime.date.today()
216
- )
209
+ day = cons.convert_date(date) if date is not None else datetime.date.today()
217
210
  if day.strftime("%Y%m%d") not in calendar:
218
211
  # warnings.warn(f"{day.strftime('%Y%m%d')}非交易日")
219
- return
220
- url = f"http://www.gfex.com.cn/u/interfacesWebTiDayQuotes/loadList"
221
- payload = {
222
- 'trade_date': date,
223
- 'trade_type': '0'
224
- }
212
+ return pd.DataFrame()
213
+ url = "http://www.gfex.com.cn/u/interfacesWebTiDayQuotes/loadList"
214
+ payload = {"trade_date": date, "trade_type": "0"}
225
215
  headers = {
226
216
  "Accept": "application/json, text/javascript, */*; q=0.01",
227
217
  "Accept-Encoding": "gzip, deflate",
@@ -234,77 +224,91 @@ def get_gfex_daily(date: str = "20221223") -> pd.DataFrame:
234
224
  "Pragma": "no-cache",
235
225
  "Proxy-Connection": "keep-alive",
236
226
  "Referer": "http://www.gfex.com.cn/gfex/rihq/hqsj_tjsj.shtml",
237
- "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/108.0.0.0 Safari/537.36",
227
+ "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) "
228
+ "Chrome/108.0.0.0 Safari/537.36",
238
229
  "X-Requested-With": "XMLHttpRequest",
239
- "content-type": "application/x-www-form-urlencoded"
230
+ "content-type": "application/x-www-form-urlencoded",
240
231
  }
241
232
  r = requests.post(url, data=payload, headers=headers)
242
233
  try:
243
234
  data_json = r.json()
244
- except:
245
- return
246
- result_df = pd.DataFrame(data_json['data'])
247
- result_df = result_df[~result_df['variety'].str.contains("小计")]
248
- result_df = result_df[~result_df['variety'].str.contains("总计")]
249
- result_df['symbol'] = result_df['varietyOrder'].str.upper() + result_df['delivMonth']
250
- result_df['date'] = date
251
- result_df['open'] = pd.to_numeric(result_df['open'], errors="coerce")
252
- result_df['high'] = pd.to_numeric(result_df['high'], errors="coerce")
253
- result_df['low'] = pd.to_numeric(result_df['low'], errors="coerce")
254
- result_df['close'] = pd.to_numeric(result_df['close'], errors="coerce")
255
- result_df['volume'] = pd.to_numeric(result_df['volumn'], errors="coerce")
256
- result_df['open_interest'] = pd.to_numeric(result_df['openInterest'], errors="coerce")
257
- result_df['turnover'] = pd.to_numeric(result_df['turnover'], errors="coerce")
258
- result_df['settle'] = pd.to_numeric(result_df['clearPrice'], errors="coerce")
259
- result_df['pre_settle'] = pd.to_numeric(result_df['lastClear'], errors="coerce")
260
- result_df['variety'] = result_df['varietyOrder'].str.upper()
235
+ except: # noqa: E722
236
+ return pd.DataFrame()
237
+ result_df = pd.DataFrame(data_json["data"])
238
+ result_df = result_df[~result_df["variety"].str.contains("小计")]
239
+ result_df = result_df[~result_df["variety"].str.contains("总计")]
240
+ result_df["symbol"] = (
241
+ result_df["varietyOrder"].str.upper() + result_df["delivMonth"]
242
+ )
243
+ result_df["date"] = date
244
+ result_df["open"] = pd.to_numeric(result_df["open"], errors="coerce")
245
+ result_df["high"] = pd.to_numeric(result_df["high"], errors="coerce")
246
+ result_df["low"] = pd.to_numeric(result_df["low"], errors="coerce")
247
+ result_df["close"] = pd.to_numeric(result_df["close"], errors="coerce")
248
+ result_df["volume"] = pd.to_numeric(result_df["volumn"], errors="coerce")
249
+ result_df["open_interest"] = pd.to_numeric(
250
+ result_df["openInterest"], errors="coerce"
251
+ )
252
+ result_df["turnover"] = pd.to_numeric(result_df["turnover"], errors="coerce")
253
+ result_df["settle"] = pd.to_numeric(result_df["clearPrice"], errors="coerce")
254
+ result_df["pre_settle"] = pd.to_numeric(result_df["lastClear"], errors="coerce")
255
+ result_df["variety"] = result_df["varietyOrder"].str.upper()
261
256
  result_df = result_df[
262
- ['symbol', 'date', 'open', 'high', 'low', 'close', 'volume',
263
- 'open_interest', 'turnover', 'settle', 'pre_settle', 'variety']
257
+ [
258
+ "symbol",
259
+ "date",
260
+ "open",
261
+ "high",
262
+ "low",
263
+ "close",
264
+ "volume",
265
+ "open_interest",
266
+ "turnover",
267
+ "settle",
268
+ "pre_settle",
269
+ "variety",
270
+ ]
264
271
  ]
265
272
  return result_df
266
273
 
267
274
 
268
- def get_ine_daily(date: str = "20220208") -> pd.DataFrame:
275
+ def get_ine_daily(date: str = "20241129") -> pd.DataFrame:
269
276
  """
270
277
  上海国际能源交易中心-日频率-量价数据
271
278
  上海国际能源交易中心: 原油期货(上市时间: 20180326); 20号胶期货(上市时间: 20190812)
272
- trade_price: http://www.ine.cn/statements/daily/?paramid=kx
273
- trade_note: http://www.ine.cn/data/datanote.dat
279
+ trade_price: https://www.ine.cn/statements/daily/?paramid=kx
280
+ trade_note: https://www.ine.cn/data/datanote.dat
274
281
  :param date: 日期 format:YYYY-MM-DD 或 YYYYMMDD 或 datetime.date对象,默认为当前交易日
275
282
  :type date: str or datetime.date
276
283
  :return: 上海国际能源交易中心-日频率-量价数据
277
284
  :rtype: pandas.DataFrame or None
278
285
  """
279
- day = (
280
- cons.convert_date(date) if date is not None else datetime.date.today()
281
- )
286
+ day = cons.convert_date(date) if date is not None else datetime.date.today()
282
287
  if day.strftime("%Y%m%d") not in calendar:
283
288
  # warnings.warn(f"{day.strftime('%Y%m%d')}非交易日")
284
- return
285
- url = f"http://www.ine.cn/data/dailydata/kx/kx{day.strftime('%Y%m%d')}.dat"
289
+ return pd.DataFrame()
290
+ url = f"https://www.ine.cn/data/tradedata/future/dailydata/kx{day.strftime('%Y%m%d')}.dat"
286
291
  r = requests.get(url, headers=cons.shfe_headers)
287
292
  result_df = pd.DataFrame()
288
293
  try:
289
294
  data_json = r.json()
290
- except:
291
- return
295
+ except: # noqa: E722
296
+ return pd.DataFrame()
292
297
  temp_df = pd.DataFrame(data_json["o_curinstrument"]).iloc[:-1, :]
293
298
  temp_df = temp_df[temp_df["DELIVERYMONTH"] != "小计"]
294
299
  temp_df = temp_df[~temp_df["PRODUCTNAME"].str.contains("总计")]
295
300
  try:
296
301
  result_df["symbol"] = (
297
- temp_df["PRODUCTGROUPID"].str.upper().str.strip()
298
- + temp_df["DELIVERYMONTH"]
302
+ temp_df["PRODUCTGROUPID"].str.upper().str.strip() + temp_df["DELIVERYMONTH"]
299
303
  )
300
- except:
304
+ except: # noqa: E722
301
305
  result_df["symbol"] = (
302
- temp_df["PRODUCTID"]
303
- .str.upper()
304
- .str.strip()
305
- .str.split("_", expand=True)
306
- .iloc[:, 0]
307
- + temp_df["DELIVERYMONTH"]
306
+ temp_df["PRODUCTID"]
307
+ .str.upper()
308
+ .str.strip()
309
+ .str.split("_", expand=True)
310
+ .iloc[:, 0]
311
+ + temp_df["DELIVERYMONTH"]
308
312
  )
309
313
  result_df["date"] = day.strftime("%Y%m%d")
310
314
  result_df["open"] = temp_df["OPENPRICE"]
@@ -315,15 +319,13 @@ def get_ine_daily(date: str = "20220208") -> pd.DataFrame:
315
319
  result_df["open_interest"] = temp_df["OPENINTEREST"]
316
320
  try:
317
321
  result_df["turnover"] = temp_df["TURNOVER"]
318
- except:
322
+ except: # noqa: E722
319
323
  result_df["turnover"] = 0
320
324
  result_df["settle"] = temp_df["SETTLEMENTPRICE"]
321
325
  result_df["pre_settle"] = temp_df["PRESETTLEMENTPRICE"]
322
326
  try:
323
- result_df["variety"] = (
324
- temp_df["PRODUCTGROUPID"].str.upper().str.strip()
325
- )
326
- except:
327
+ result_df["variety"] = temp_df["PRODUCTGROUPID"].str.upper().str.strip()
328
+ except: # noqa: E722
327
329
  result_df["variety"] = (
328
330
  temp_df["PRODUCTID"]
329
331
  .str.upper()
@@ -343,14 +345,14 @@ def get_czce_daily(date: str = "20050525") -> pd.DataFrame:
343
345
  :param date: 日期 format:YYYY-MM-DD 或 YYYYMMDD 或 datetime.date 对象,默认为当前交易日; 日期需要大于 20100824
344
346
  :type date: str or datetime.date
345
347
  :return: 郑州商品交易所-日频率-量价数据
346
- :rtype: pandas.DataFrame or None
348
+ :rtype: pandas.DataFrame
347
349
  """
348
- day = (
349
- cons.convert_date(date) if date is not None else datetime.date.today()
350
- )
350
+ day = cons.convert_date(date) if date is not None else datetime.date.today()
351
351
  headers = {
352
- "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/108.0.0.0 Safari/537.36"
352
+ "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) "
353
+ "Chrome/108.0.0.0 Safari/537.36"
353
354
  }
355
+ url = ""
354
356
  if day.strftime("%Y%m%d") not in calendar:
355
357
  # warnings.warn(f"{day.strftime('%Y%m%d')}非交易日")
356
358
  return pd.DataFrame()
@@ -365,11 +367,7 @@ def get_czce_daily(date: str = "20050525") -> pd.DataFrame:
365
367
  output_columns = cons.OUTPUT_COLUMNS
366
368
  try:
367
369
  r = requests.get(url, headers=headers)
368
- if (
369
- datetime.date(2015, 11, 12)
370
- <= day
371
- <= datetime.date(2017, 12, 27)
372
- ):
370
+ if datetime.date(2015, 11, 12) <= day <= datetime.date(2017, 12, 27):
373
371
  html = str(r.content, encoding="gbk")
374
372
  else:
375
373
  html = r.text
@@ -380,18 +378,18 @@ def get_czce_daily(date: str = "20050525") -> pd.DataFrame:
380
378
  % (day.strftime("%Y"), day.strftime("%Y%m%d")),
381
379
  reason,
382
380
  )
383
- return
381
+ return pd.DataFrame()
384
382
  if html.find("您的访问出错了") >= 0 or html.find("无期权每日行情交易记录") >= 0:
385
- return
383
+ return pd.DataFrame()
386
384
  html = [
387
385
  i.replace(" ", "").split("|")
388
- for i in html.split("\n")[:-4]
386
+ for i in html.split("\n")[:-3]
389
387
  if i[0][0] != "小"
390
388
  ]
391
389
 
392
390
  if day > datetime.date(2015, 11, 11):
393
391
  if html[1][0] not in ["品种月份", "品种代码", "合约代码"]:
394
- return
392
+ return pd.DataFrame()
395
393
  dict_data = list()
396
394
  day_const = int(day.strftime("%Y%m%d"))
397
395
  for row in html[2:]:
@@ -452,56 +450,10 @@ def get_czce_daily(date: str = "20050525") -> pd.DataFrame:
452
450
  return _futures_daily_czce_df
453
451
 
454
452
 
455
- def get_shfe_v_wap(date: str = "20131017") -> pd.DataFrame:
456
- """
457
- 上期所日成交均价数据
458
- Parameters
459
- ------
460
- date: 日期 format:YYYY-MM-DD 或 YYYYMMDD 或 datetime.date对象 为空时为当天
461
- Return
462
- -------
463
- DataFrame
464
- 郑商所日交易数据(DataFrame):
465
- symbol 合约代码
466
- date 日期
467
- time_range v_wap时段,分09:00-10:15和09:00-15:00两类
468
- v_wap 加权平均成交均价
469
- 或 None(给定日期没有数据)
470
- """
471
- day = (
472
- cons.convert_date(date) if date is not None else datetime.date.today()
473
- )
474
- if day.strftime("%Y%m%d") not in calendar:
475
- # warnings.warn("%s非交易日" % day.strftime("%Y%m%d"))
476
- return None
477
- try:
478
- json_data = json.loads(
479
- requests_link(
480
- cons.SHFE_V_WAP_URL % (day.strftime("%Y%m%d")),
481
- headers=cons.headers,
482
- encoding="utf-8",
483
- ).text
484
- )
485
- except:
486
- return None
487
-
488
- if len(json_data["o_currefprice"]) == 0:
489
- return None
490
- try:
491
- df = pd.DataFrame(json_data["o_currefprice"])
492
- df["INSTRUMENTID"] = df["INSTRUMENTID"].str.strip()
493
- df[":B1"].astype("int16")
494
- return df.rename(columns=cons.SHFE_V_WAP_COLUMNS)[
495
- list(cons.SHFE_V_WAP_COLUMNS.values())
496
- ]
497
- except:
498
- return None
499
-
500
-
501
453
  def get_shfe_daily(date: str = "20220415") -> pd.DataFrame:
502
454
  """
503
455
  上海期货交易所-日频率-量价数据
504
- http://www.shfe.com.cn/statements/dataview.html?paramid=kx
456
+ https://tsite.shfe.com.cn/statements/dataview.html?paramid=kx
505
457
  :param date: 日期 format:YYYY-MM-DD 或 YYYYMMDD 或 datetime.date对象, 默认为当前交易日
506
458
  :type date: str or datetime.date
507
459
  :return: 上海期货交易所-日频率-量价数据
@@ -521,12 +473,10 @@ def get_shfe_daily(date: str = "20220415") -> pd.DataFrame:
521
473
  variety 合约类别
522
474
  或 None(给定交易日没有交易数据)
523
475
  """
524
- day = (
525
- cons.convert_date(date) if date is not None else datetime.date.today()
526
- )
476
+ day = cons.convert_date(date) if date is not None else datetime.date.today()
527
477
  if day.strftime("%Y%m%d") not in calendar:
528
478
  # warnings.warn("%s非交易日" % day.strftime("%Y%m%d"))
529
- return
479
+ return pd.DataFrame()
530
480
  try:
531
481
  json_data = json.loads(
532
482
  requests_link(
@@ -537,22 +487,22 @@ def get_shfe_daily(date: str = "20220415") -> pd.DataFrame:
537
487
  except requests.HTTPError as reason:
538
488
  if reason.response != 404:
539
489
  print(cons.SHFE_DAILY_URL % (day.strftime("%Y%m%d")), reason)
540
- return
490
+ return pd.DataFrame()
541
491
 
542
492
  if len(json_data["o_curinstrument"]) == 0:
543
- return
493
+ return pd.DataFrame()
544
494
 
545
495
  df = pd.DataFrame(
546
496
  [
547
497
  row
548
498
  for row in json_data["o_curinstrument"]
549
499
  if row["DELIVERYMONTH"] not in ["小计", "合计"]
550
- and row["DELIVERYMONTH"] != ""
500
+ and row["DELIVERYMONTH"] != ""
551
501
  ]
552
502
  )
553
503
  try:
554
504
  df["variety"] = df["PRODUCTGROUPID"].str.upper().str.strip()
555
- except KeyError as e:
505
+ except KeyError:
556
506
  df["variety"] = (
557
507
  df["PRODUCTID"]
558
508
  .str.upper()
@@ -562,21 +512,16 @@ def get_shfe_daily(date: str = "20220415") -> pd.DataFrame:
562
512
  )
563
513
  df["symbol"] = df["variety"] + df["DELIVERYMONTH"]
564
514
  df["date"] = day.strftime("%Y%m%d")
565
- v_wap_df = get_shfe_v_wap(day)
566
- if v_wap_df is not None:
567
- df = pd.merge(
568
- df,
569
- v_wap_df[v_wap_df.time_range == "9:00-15:00"],
570
- on=["date", "symbol"],
571
- how="left",
572
- )
573
- df["turnover"] = df.v_wap * df.VOLUME
574
- else:
575
- df["VOLUME"] = df["VOLUME"].apply(lambda x: 0 if x == "" else x)
576
- df["turnover"] = df["VOLUME"] * df["SETTLEMENTPRICE"]
515
+ df["VOLUME"] = df["VOLUME"].apply(lambda x: 0 if x == "" else x)
516
+ try:
517
+ df["turnover"] = df["TURNOVER"].apply(lambda x: 0 if x == "" else x)
518
+ except KeyError:
519
+ df["turnover"] = np.nan
577
520
  df.rename(columns=cons.SHFE_COLUMNS, inplace=True)
578
521
  df = df[~df["symbol"].str.contains("efp")]
579
- return df[cons.OUTPUT_COLUMNS]
522
+ df = df[cons.OUTPUT_COLUMNS]
523
+ df.reset_index(inplace=True)
524
+ return df
580
525
 
581
526
 
582
527
  def get_dce_daily(date: str = "20220308") -> pd.DataFrame:
@@ -588,17 +533,14 @@ def get_dce_daily(date: str = "20220308") -> pd.DataFrame:
588
533
  :return: 具体交易日的个品种行情数据
589
534
  :rtype: pandas.DataFrame
590
535
  """
591
- day = (
592
- cons.convert_date(date) if date is not None else datetime.date.today()
593
- )
536
+ day = cons.convert_date(date) if date is not None else datetime.date.today()
594
537
  if day.strftime("%Y%m%d") not in calendar:
595
538
  # warnings.warn("%s非交易日" % day.strftime("%Y%m%d"))
596
- return None
597
- url = (
598
- "http://www.dce.com.cn/publicweb/quotesdata/exportDayQuotesChData.html"
599
- )
539
+ return pd.DataFrame()
540
+ url = "http://www.dce.com.cn/publicweb/quotesdata/exportDayQuotesChData.html"
600
541
  headers = {
601
- "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9",
542
+ "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,"
543
+ "application/signed-exchange;v=b3;q=0.9",
602
544
  "Accept-Encoding": "gzip, deflate",
603
545
  "Accept-Language": "zh-CN,zh;q=0.9,en;q=0.8",
604
546
  "Cache-Control": "no-cache",
@@ -610,7 +552,8 @@ def get_dce_daily(date: str = "20220308") -> pd.DataFrame:
610
552
  "Pragma": "no-cache",
611
553
  "Referer": "http://www.dce.com.cn/publicweb/quotesdata/dayQuotesCh.html",
612
554
  "Upgrade-Insecure-Requests": "1",
613
- "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.105 Safari/537.36",
555
+ "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) "
556
+ "Chrome/84.0.4147.105 Safari/537.36",
614
557
  }
615
558
  params = {
616
559
  "dayQuotes.variety": "all",
@@ -622,7 +565,6 @@ def get_dce_daily(date: str = "20220308") -> pd.DataFrame:
622
565
  }
623
566
  r = requests.post(url, data=params, headers=headers)
624
567
  data_df = pd.read_excel(BytesIO(r.content), header=1)
625
-
626
568
  data_df = data_df[~data_df["商品名称"].str.contains("小计")]
627
569
  data_df = data_df[~data_df["商品名称"].str.contains("总计")]
628
570
  data_df["variety"] = data_df["商品名称"].map(lambda x: cons.DCE_MAP[x])
@@ -662,12 +604,7 @@ def get_dce_daily(date: str = "20220308") -> pd.DataFrame:
662
604
  "variety",
663
605
  ]
664
606
  ]
665
- # TODO pandas 2.1.0 change
666
- try:
667
- data_df = data_df.map(lambda x: x.replace(",", ""))
668
- except:
669
- data_df = data_df.applymap(lambda x: x.replace(",", ""))
670
-
607
+ data_df = data_df.map(lambda x: x.replace(",", ""))
671
608
  data_df = data_df.astype(
672
609
  {
673
610
  "open": "float",
@@ -686,9 +623,9 @@ def get_dce_daily(date: str = "20220308") -> pd.DataFrame:
686
623
 
687
624
 
688
625
  def get_futures_daily(
689
- start_date: str = "20220208",
690
- end_date: str = "20220208",
691
- market: str = "CFFEX",
626
+ start_date: str = "20220208",
627
+ end_date: str = "20220208",
628
+ market: str = "CFFEX",
692
629
  ) -> pd.DataFrame:
693
630
  """
694
631
  交易所日交易数据
@@ -715,7 +652,7 @@ def get_futures_daily(
715
652
  f = get_gfex_daily
716
653
  else:
717
654
  print("Invalid Market Symbol")
718
- return
655
+ return pd.DataFrame()
719
656
 
720
657
  start_date = (
721
658
  cons.convert_date(start_date)
@@ -725,19 +662,19 @@ def get_futures_daily(
725
662
  end_date = (
726
663
  cons.convert_date(end_date)
727
664
  if end_date is not None
728
- else cons.convert_date(
729
- cons.get_latest_data_date(datetime.datetime.now())
730
- )
665
+ else cons.convert_date(cons.get_latest_data_date(datetime.datetime.now()))
731
666
  )
732
667
 
733
668
  df_list = list()
734
669
  while start_date <= end_date:
735
670
  df = f(date=str(start_date).replace("-", ""))
736
- if df is not None:
671
+ if not df.empty:
737
672
  df_list.append(df)
738
673
  start_date += datetime.timedelta(days=1)
739
674
 
740
- if len(df_list) > 0:
675
+ if len(df_list) == 0:
676
+ return pd.DataFrame()
677
+ elif len(df_list) > 0:
741
678
  temp_df = pd.concat(df_list).reset_index(drop=True)
742
679
  temp_df = temp_df[~temp_df["symbol"].str.contains("efp")]
743
680
  return temp_df
@@ -745,11 +682,11 @@ def get_futures_daily(
745
682
 
746
683
  if __name__ == "__main__":
747
684
  get_futures_daily_df = get_futures_daily(
748
- start_date="20231001", end_date="20240128", market="CZCE"
685
+ start_date="20250102", end_date="20250102", market="DCE"
749
686
  )
750
687
  print(get_futures_daily_df)
751
688
 
752
- get_dce_daily_df = get_dce_daily(date="20230810")
689
+ get_dce_daily_df = get_dce_daily(date="20241118")
753
690
  print(get_dce_daily_df)
754
691
 
755
692
  get_cffex_daily_df = get_cffex_daily(date="20230810")
@@ -758,10 +695,10 @@ if __name__ == "__main__":
758
695
  get_ine_daily_df = get_ine_daily(date="20230818")
759
696
  print(get_ine_daily_df)
760
697
 
761
- get_czce_daily_df = get_czce_daily(date="20230320")
698
+ get_czce_daily_df = get_czce_daily(date="20210513")
762
699
  print(get_czce_daily_df)
763
700
 
764
- get_shfe_daily_df = get_shfe_daily(date="20230621")
701
+ get_shfe_daily_df = get_shfe_daily(date="20210517")
765
702
  print(get_shfe_daily_df)
766
703
 
767
704
  get_gfex_daily_df = get_gfex_daily(date="20221228")