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

akshare/__init__.py CHANGED
@@ -2984,9 +2984,10 @@ amac_manager_cancelled_info # 中国证券投资基金业协会-信息公示-诚
2984
2984
  1.15.72 fix: fix stock_us_spot interface
2985
2985
  1.15.73 fix: fix stock_dzjy_hygtj interface
2986
2986
  1.15.74 fix: fix macro_australia_retail_rate_monthly interface
2987
+ 1.15.75 feat: add futures_hist_em interface
2987
2988
  """
2988
2989
 
2989
- __version__ = "1.15.74"
2990
+ __version__ = "1.15.75"
2990
2991
  __author__ = "AKFamily"
2991
2992
 
2992
2993
  import sys
@@ -3008,6 +3009,11 @@ if sys.version_info < (3, 9):
3008
3009
 
3009
3010
  del sys
3010
3011
 
3012
+ """
3013
+ 期货行情-内盘-历史行情数据-东财
3014
+ """
3015
+ from akshare.futures.futures_hist_em import futures_hist_table_em, futures_hist_em
3016
+
3011
3017
  """
3012
3018
  巨潮资讯-数据中心-专题统计-股东股本-股本变动
3013
3019
  """
@@ -0,0 +1,189 @@
1
+ #!/usr/bin/env python
2
+ # -*- coding:utf-8 -*-
3
+ """
4
+ Date: 2024/1/17 19:30
5
+ Desc: 东方财富网-期货行情
6
+ https://qhweb.eastmoney.com/quote
7
+ """
8
+
9
+ import re
10
+ from functools import lru_cache
11
+
12
+ import pandas as pd
13
+ import requests
14
+
15
+
16
+ def __futures_hist_separate_char_and_numbers_em(symbol: str = "焦煤2506") -> tuple:
17
+ """
18
+ 东方财富网-期货行情-交易所品种对照表原始数据
19
+ https://quote.eastmoney.com/qihuo/al2505.html
20
+ :param symbol: 股票代码
21
+ :type symbol: str
22
+ :return: 交易所品种对照表原始数据
23
+ :rtype: pandas.DataFrame
24
+ """
25
+ char = re.findall(pattern="[\u4e00-\u9fa5a-zA-Z]+", string=symbol)
26
+ numbers = re.findall(pattern=r"\d+", string=symbol)
27
+ return char[0], numbers[0]
28
+
29
+
30
+ @lru_cache()
31
+ def __fetch_exchange_symbol_raw_em() -> list:
32
+ """
33
+ 东方财富网-期货行情-交易所品种对照表原始数据
34
+ https://quote.eastmoney.com/qihuo/al2505.html
35
+ :return: 交易所品种对照表原始数据
36
+ :rtype: pandas.DataFrame
37
+ """
38
+ url = "https://futsse-static.eastmoney.com/redis"
39
+ params = {"msgid": "gnweb"}
40
+ r = requests.get(url, params=params)
41
+ data_json = r.json()
42
+ all_exchange_symbol_list = []
43
+ for item in data_json:
44
+ params = {"msgid": str(item["mktid"])}
45
+ r = requests.get(url, params=params)
46
+ inner_data_json = r.json()
47
+ for num in range(1, len(inner_data_json) + 1):
48
+ params = {"msgid": str(item["mktid"]) + f"_{num}"}
49
+ r = requests.get(url, params=params)
50
+ inner_data_json = r.json()
51
+ all_exchange_symbol_list.extend(inner_data_json)
52
+ return all_exchange_symbol_list
53
+
54
+
55
+ @lru_cache()
56
+ def __get_exchange_symbol_map() -> tuple[dict, dict, dict, dict]:
57
+ """
58
+ 东方财富网-期货行情-交易所品种映射
59
+ https://quote.eastmoney.com/qihuo/al2505.html
60
+ :return: 交易所品种映射
61
+ :rtype: pandas.DataFrame
62
+ """
63
+ all_exchange_symbol_list = __fetch_exchange_symbol_raw_em()
64
+ c_contract_mkt = {}
65
+ c_contract_to_e_contract = {}
66
+ e_symbol_mkt = {}
67
+ c_symbol_mkt = {}
68
+ for item in all_exchange_symbol_list:
69
+ c_contract_mkt[item["name"]] = item["mktid"]
70
+ c_contract_to_e_contract[item["name"]] = item["code"]
71
+ e_symbol_mkt[item["vcode"]] = item["mktid"]
72
+ c_symbol_mkt[item["vname"]] = item["mktid"]
73
+ return c_contract_mkt, c_contract_to_e_contract, e_symbol_mkt, c_symbol_mkt
74
+
75
+
76
+ def futures_hist_table_em() -> pd.DataFrame:
77
+ """
78
+ 东方财富网-期货行情-交易所品种对照表
79
+ https://quote.eastmoney.com/qihuo/al2505.html
80
+ :return: 交易所品种对照表
81
+ :rtype: pandas.DataFrame
82
+ """
83
+ all_exchange_symbol_list = __fetch_exchange_symbol_raw_em()
84
+ temp_df = pd.DataFrame(all_exchange_symbol_list)
85
+ temp_df = temp_df[["mktname", "name", "code"]]
86
+ temp_df.columns = ["市场简称", "合约中文代码", "合约代码"]
87
+ return temp_df
88
+
89
+
90
+ def futures_hist_em(
91
+ symbol: str = "热卷主连",
92
+ period: str = "daily",
93
+ start_date: str = "19900101",
94
+ end_date: str = "20500101",
95
+ ) -> pd.DataFrame:
96
+ """
97
+ 东方财富网-期货行情-行情数据
98
+ https://qhweb.eastmoney.com/quote
99
+ :param symbol: 期货代码
100
+ :type symbol: str
101
+ :param period: choice of {'daily', 'weekly', 'monthly'}
102
+ :type period: str
103
+ :param start_date: 开始日期
104
+ :type start_date: str
105
+ :param end_date: 结束日期
106
+ :type end_date: str
107
+ :return: 行情数据
108
+ :rtype: pandas.DataFrame
109
+ """
110
+ url = "https://push2his.eastmoney.com/api/qt/stock/kline/get"
111
+ period_dict = {"daily": "101", "weekly": "102", "monthly": "103"}
112
+ c_contract_mkt, c_contract_to_e_contract, e_symbol_mkt, c_symbol_mkt = (
113
+ __get_exchange_symbol_map()
114
+ )
115
+ try:
116
+ sec_id = f"{c_contract_mkt[symbol]}.{c_contract_to_e_contract[symbol]}"
117
+ except KeyError:
118
+ symbol_char, numbers = __futures_hist_separate_char_and_numbers_em(symbol)
119
+ if re.match(pattern="^[\u4e00-\u9fa5]+$", string=symbol_char):
120
+ sec_id = str(c_symbol_mkt[symbol_char]) + "." + symbol
121
+ else:
122
+ sec_id = str(e_symbol_mkt[symbol_char]) + "." + symbol
123
+ params = {
124
+ "secid": sec_id,
125
+ "klt": period_dict[period],
126
+ "fqt": "1",
127
+ "lmt": "10000",
128
+ "end": "20500000",
129
+ "iscca": "1",
130
+ "fields1": "f1,f2,f3,f4,f5,f6,f7,f8",
131
+ "fields2": "f51,f52,f53,f54,f55,f56,f57,f58,f59,f60,f61,f62,f63,f64",
132
+ "ut": "7eea3edcaed734bea9cbfc24409ed989",
133
+ "forcect": "1",
134
+ }
135
+ r = requests.get(url, timeout=15, params=params)
136
+ data_json = r.json()
137
+ temp_df = pd.DataFrame([item.split(",") for item in data_json["data"]["klines"]])
138
+ temp_df.columns = [
139
+ "时间",
140
+ "开盘",
141
+ "收盘",
142
+ "最高",
143
+ "最低",
144
+ "成交量",
145
+ "成交额",
146
+ "-",
147
+ "涨跌幅",
148
+ "涨跌",
149
+ "_",
150
+ "_",
151
+ "持仓量",
152
+ "_",
153
+ ]
154
+ temp_df = temp_df[
155
+ [
156
+ "时间",
157
+ "开盘",
158
+ "最高",
159
+ "最低",
160
+ "收盘",
161
+ "涨跌",
162
+ "涨跌幅",
163
+ "成交量",
164
+ "成交额",
165
+ "持仓量",
166
+ ]
167
+ ]
168
+ temp_df.index = pd.to_datetime(temp_df["时间"])
169
+ temp_df = temp_df[start_date:end_date]
170
+ temp_df.reset_index(drop=True, inplace=True)
171
+ temp_df["开盘"] = pd.to_numeric(temp_df["开盘"], errors="coerce")
172
+ temp_df["收盘"] = pd.to_numeric(temp_df["收盘"], errors="coerce")
173
+ temp_df["最高"] = pd.to_numeric(temp_df["最高"], errors="coerce")
174
+ temp_df["最低"] = pd.to_numeric(temp_df["最低"], errors="coerce")
175
+ temp_df["成交量"] = pd.to_numeric(temp_df["成交量"], errors="coerce")
176
+ temp_df["成交额"] = pd.to_numeric(temp_df["成交额"], errors="coerce")
177
+ temp_df["涨跌"] = pd.to_numeric(temp_df["涨跌"], errors="coerce")
178
+ temp_df["涨跌幅"] = pd.to_numeric(temp_df["涨跌幅"], errors="coerce")
179
+ temp_df["持仓量"] = pd.to_numeric(temp_df["持仓量"], errors="coerce")
180
+ temp_df["时间"] = pd.to_datetime(temp_df["时间"], errors="coerce").dt.date
181
+ return temp_df
182
+
183
+
184
+ if __name__ == "__main__":
185
+ futures_hist_table_em_df = futures_hist_table_em()
186
+ print(futures_hist_table_em_df)
187
+
188
+ futures_hist_em_df = futures_hist_em(symbol="热卷主连", period="daily")
189
+ print(futures_hist_em_df)
@@ -0,0 +1,38 @@
1
+ #!/usr/bin/env python
2
+ # -*- coding:utf-8 -*-
3
+ """
4
+ Date: 2024/1/17 19:30
5
+ Desc: 东方财富网-期货行情-品种及交易规则
6
+ https://portal.eastmoneyfutures.com/pages/service/jyts.html#jyrl
7
+ """
8
+
9
+ import pandas as pd
10
+ import requests
11
+ from akshare.utils.cons import headers
12
+
13
+
14
+ def futures_rule_em() -> pd.DataFrame:
15
+ """
16
+ 东方财富网-期货行情-品种及交易规则
17
+ https://portal.eastmoneyfutures.com/pages/service/jyts.html#jyrl
18
+ :return: 品种及交易规则
19
+ :rtype: pandas.DataFrame
20
+ """
21
+ url = "https://eastmoneyfutures.com/api/ComManage/GetPZJYInfo"
22
+ r = requests.get(url, headers=headers)
23
+ data_json = r.json()
24
+ temp_df = pd.DataFrame(data_json["Data"])
25
+ return temp_df
26
+
27
+
28
+ def futures_trading_hours_em():
29
+ """
30
+ 东方财富网-期货交易时间
31
+ https://qhweb.eastmoney.com/tradinghours
32
+ """
33
+ pass
34
+
35
+
36
+ if __name__ == "__main__":
37
+ futures_rule_em_df = futures_rule_em()
38
+ print(futures_rule_em_df)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: akshare
3
- Version: 1.15.74
3
+ Version: 1.15.75
4
4
  Summary: AKShare is an elegant and simple financial data interface library for Python, built for human beings!
5
5
  Home-page: https://github.com/akfamily/akshare
6
6
  Author: AKFamily
@@ -1,4 +1,4 @@
1
- akshare/__init__.py,sha256=F9xOijKtCdpH32MYlpYbZ1y_KgHe8ORkuoFb8OGXnas,186185
1
+ akshare/__init__.py,sha256=yuHgcgTP8iCMPnvdcJ2ARcDzFXrs3Sz5_e3XhiCe55g,186367
2
2
  akshare/datasets.py,sha256=rKuRNZrqi6IMsZ9nyvO3Rx02js0tH3zMLjz8HQNAoPQ,963
3
3
  akshare/exceptions.py,sha256=WEJjIhSmJ_xXNW6grwV4nufE_cfmmyuhmueVGiN1VAg,878
4
4
  akshare/request.py,sha256=HtFFf9MhfEibR-ETWe-1Tts6ELU4VKSqA-ghaXjegQM,4252
@@ -113,6 +113,7 @@ akshare/futures/futures_contract_detail.py,sha256=auwzNdaoFi5hoJY6rNkO54v5FD2gmE
113
113
  akshare/futures/futures_daily_bar.py,sha256=pultXs8digLfWT0dzyWs0AtFk3Fi2uZDT-zxbg_PcOM,25299
114
114
  akshare/futures/futures_foreign.py,sha256=oSIoAg5oy-CIlPWHkQffcvZGu02Y2GWOrt-6aPA53Xg,2059
115
115
  akshare/futures/futures_hf_em.py,sha256=jne-wUYr2QTUkDq3qAxYKE0Hm90L3H8qUDu3JavKiUg,3338
116
+ akshare/futures/futures_hist_em.py,sha256=23poFID_GE2mWf9NnkJBE3N7FgxNYiqrbTKO0VciS_A,6441
116
117
  akshare/futures/futures_hq_sina.py,sha256=eK1gEan4DPvpYmln8-tNnzh_J_733s95DBr--NqNYVA,9576
117
118
  akshare/futures/futures_index_ccidx.py,sha256=Ni5GICleqcHrmLatOE_Bs4i1DS3bn0lEm_RyrjlucB0,4581
118
119
  akshare/futures/futures_inventory_99.py,sha256=xdX8GSCEcRWYnbw0XS22rcblXOvlzUvfUltv7oyRh3Y,2990
@@ -120,6 +121,7 @@ akshare/futures/futures_inventory_em.py,sha256=C5nt4F51WB-oc8o3GrMvEGo0SO2mIq_H1
120
121
  akshare/futures/futures_news_shmet.py,sha256=1epZ3MwDc-T2n1ie4SSDfvUaBiMpSL0Q_xb2VoZ_llU,2465
121
122
  akshare/futures/futures_roll_yield.py,sha256=RiwN0yYwzYy8zGhmTopBwJ37aUQ7Llwh3eQRzn0apaE,6135
122
123
  akshare/futures/futures_rule.py,sha256=38fJnUTohGqbwE65ZR1id7Oy-0DS-ODrGYsmx2jtGZ8,1571
124
+ akshare/futures/futures_rule_em.py,sha256=qcXfYZibRJLN2pb3ybNIkNonUOjDMvSirG5xKkRoWqk,963
123
125
  akshare/futures/futures_settlement_price_sgx.py,sha256=R0PZOEkdYDf7H242iHYz70rxdvsMWoAL60bmGlj-0GY,2428
124
126
  akshare/futures/futures_spot_stock_em.py,sha256=43CPkAouDu691M6aCMdO1SGKglTak2aba2Np7ftkAdg,3523
125
127
  akshare/futures/futures_stock_js.py,sha256=BV_1Hm9osxWQmNSt24DQ52hAMrfMqP6eud657Y-D6x4,1665
@@ -378,8 +380,8 @@ akshare/utils/token_process.py,sha256=K4rGXjh_tgugbRcyOK2h2x0jP3PT65IIK7nxhUKhOe
378
380
  akshare/utils/tqdm.py,sha256=MuPNwcswkOGjwWQOMWXi9ZvQ_RmW4obCWRj2i7HM7FE,847
379
381
  tests/__init__.py,sha256=gNzhlO0UPjFq6Ieb38kaVIODXv4cTDByrdohAZnDYt4,82
380
382
  tests/test_func.py,sha256=j1MGYbZI2if2j_LY1S4FLsf4qfq4NwVqD5wmRlv5Log,832
381
- akshare-1.15.74.dist-info/LICENSE,sha256=mmSZCPgfHiVw34LXuFArd-SUgQtBJ_QsIlh-kWlDHfs,1073
382
- akshare-1.15.74.dist-info/METADATA,sha256=RsZENaH6zjGF_SgHh2X8mLRBfPjR6Q16Gv63Z73ta_M,13679
383
- akshare-1.15.74.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
384
- akshare-1.15.74.dist-info/top_level.txt,sha256=jsf9ZzZPmHaISTVumQPsAw7vv7Yv-PdEVW70SMEelQQ,14
385
- akshare-1.15.74.dist-info/RECORD,,
383
+ akshare-1.15.75.dist-info/LICENSE,sha256=mmSZCPgfHiVw34LXuFArd-SUgQtBJ_QsIlh-kWlDHfs,1073
384
+ akshare-1.15.75.dist-info/METADATA,sha256=zK_9oFxDTT7z4jd6ousw8rvxaKk-IGObQ1i8XeNAwfE,13679
385
+ akshare-1.15.75.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
386
+ akshare-1.15.75.dist-info/top_level.txt,sha256=jsf9ZzZPmHaISTVumQPsAw7vv7Yv-PdEVW70SMEelQQ,14
387
+ akshare-1.15.75.dist-info/RECORD,,