akshare 1.16.28__py3-none-any.whl → 1.16.29__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.
akshare/__init__.py CHANGED
@@ -3037,9 +3037,10 @@ amac_manager_cancelled_info # 中国证券投资基金业协会-信息公示-诚
3037
3037
  1.16.26 add: add stock_hsgt_sh_hk_spot_em interface
3038
3038
  1.16.27 fix: fix futures_global_em interface
3039
3039
  1.16.28 fix: fix futures_global_hist_em interface
3040
+ 1.16.29 fix: fix futures_global_hist_em interface
3040
3041
  """
3041
3042
 
3042
- __version__ = "1.16.28"
3043
+ __version__ = "1.16.29"
3043
3044
  __author__ = "AKFamily"
3044
3045
 
3045
3046
  import sys
@@ -3214,7 +3215,7 @@ from akshare.stock_feature.stock_hsgt_min_em import stock_hsgt_fund_min_em
3214
3215
  """
3215
3216
  东方财富网-行情中心-期货市场-国际期货
3216
3217
  """
3217
- from akshare.futures.futures_hf_em import futures_global_em
3218
+ from akshare.futures.futures_hf_em import futures_global_spot_em, futures_global_hist_em
3218
3219
 
3219
3220
  """
3220
3221
  雪球行情数据
@@ -1,12 +1,13 @@
1
1
  #!/usr/bin/env python
2
2
  # -*- coding:utf-8 -*-
3
3
  """
4
- Date: 2024/11/28 22:00
4
+ Date: 2025/3/5 19:00
5
5
  Desc: 东方财富网-行情中心-期货市场-国际期货
6
6
  https://quote.eastmoney.com/center/gridlist.html#futures_global
7
7
  """
8
8
 
9
9
  import math
10
+ from typing import Optional
10
11
 
11
12
  import pandas as pd
12
13
  import requests
@@ -14,7 +15,76 @@ import requests
14
15
  from akshare.utils.tqdm import get_tqdm
15
16
 
16
17
 
17
- def futures_global_em() -> pd.DataFrame:
18
+ def __futures_global_hist_market_code(symbol: str = "HG00Y") -> Optional[int]:
19
+ """
20
+ 东方财富网-行情中心-期货市场-国际期货-品种市场对照表
21
+ https://quote.eastmoney.com/center/gridlist.html#futures_global
22
+ :param symbol: HG00Y, 品种代码;可以通过 ak.futures_global_spot_em() 来获取所有可获取历史行情数据的品种代码
23
+ :type symbol: str
24
+ :return: 品种所属于的市场
25
+ :rtype: str
26
+ """
27
+ # 提取品种代码(去掉年份和月份部分)
28
+ base_symbol = ""
29
+ i = 0
30
+ while i < len(symbol) and not symbol[i].isdigit():
31
+ base_symbol += symbol[i]
32
+ i += 1
33
+ # 如果代码中没有数字(异常情况),则返回整个代码作为基础品种代码
34
+ if not base_symbol and i == len(symbol):
35
+ base_symbol = symbol
36
+ # 金属和贵金属品种 - 101
37
+ if base_symbol in ["HG", "GC", "SI", "QI", "QO", "MGC", "LTH"]:
38
+ return 101
39
+ # 能源品种 - 102
40
+ if base_symbol in ["CL", "NG", "RB", "HO", "PA", "PL", "QM"]:
41
+ return 102
42
+ # 农产品和金融品种 - 103
43
+ if base_symbol in [
44
+ "ZW",
45
+ "ZM",
46
+ "ZS",
47
+ "ZC",
48
+ "XC",
49
+ "XK",
50
+ "XW",
51
+ "YM",
52
+ "TY",
53
+ "US",
54
+ "EH",
55
+ "ZL",
56
+ "ZR",
57
+ "ZO",
58
+ "FV",
59
+ "TU",
60
+ "UL",
61
+ "NQ",
62
+ "ES",
63
+ ]:
64
+ return 103
65
+ # 中国市场特有品种 - 104
66
+ if base_symbol in ["TF", "RT", "CN"]:
67
+ return 104
68
+ # 软商品期货 - 108
69
+ if base_symbol in ["SB", "CT", "SF"]:
70
+ return 108
71
+ # 特殊L开头品种 - 109
72
+ if base_symbol in ["LCPT", "LZNT", "LALT", "LTNT", "LLDT", "LNKT"]:
73
+ return 109
74
+ # MPM开头品种 - 110
75
+ if base_symbol == "MPM":
76
+ return 110
77
+ # 日本市场品种 - 111
78
+ if base_symbol.startswith("J"):
79
+ return 111
80
+ # 单字母代码品种 - 112
81
+ if base_symbol in ["M", "B", "G"]:
82
+ return 112
83
+ # 如果没有匹配到任何规则,返回一个默认值或者错误
84
+ return None
85
+
86
+
87
+ def futures_global_spot_em() -> pd.DataFrame:
18
88
  """
19
89
  东方财富网-行情中心-期货市场-国际期货
20
90
  https://quote.eastmoney.com/center/gridlist.html#futures_global
@@ -101,16 +171,19 @@ def futures_global_em() -> pd.DataFrame:
101
171
  def futures_global_hist_em(symbol: str = "HG00Y") -> pd.DataFrame:
102
172
  """
103
173
  东方财富网-行情中心-期货市场-国际期货-历史行情数据
104
- https://quote.eastmoney.com/center/gridlist.html#futures_global
174
+ https://quote.eastmoney.com/globalfuture/HG25J.html
175
+ :param symbol: 品种代码;可以通过 ak.futures_global_spot_em() 来获取所有可获取历史行情数据的品种代码
176
+ :type symbol: str
105
177
  :return: 历史行情数据
106
178
  :rtype: pandas.DataFrame
107
179
  """
108
180
  url = "https://push2his.eastmoney.com/api/qt/stock/kline/get"
181
+ market_code = __futures_global_hist_market_code(symbol)
109
182
  params = {
110
- "secid": f"101.{symbol}",
183
+ "secid": f"{market_code}.{symbol}",
111
184
  "klt": "101",
112
185
  "fqt": "1",
113
- "lmt": "66",
186
+ "lmt": "6600",
114
187
  "end": "20500000",
115
188
  "iscca": "1",
116
189
  "fields1": "f1,f2,f3,f4,f5,f6,f7,f8",
@@ -123,12 +196,53 @@ def futures_global_hist_em(symbol: str = "HG00Y") -> pd.DataFrame:
123
196
  temp_df = pd.DataFrame([item.split(",") for item in data_json["data"]["klines"]])
124
197
  temp_df["code"] = data_json["data"]["code"]
125
198
  temp_df["name"] = data_json["data"]["name"]
199
+ temp_df.columns = [
200
+ "日期",
201
+ "开盘",
202
+ "最新价",
203
+ "最高",
204
+ "最低",
205
+ "总量",
206
+ "-",
207
+ "-",
208
+ "涨幅",
209
+ "-",
210
+ "-",
211
+ "-",
212
+ "持仓",
213
+ "日增",
214
+ "代码",
215
+ "名称",
216
+ ]
217
+ temp_df = temp_df[
218
+ [
219
+ "日期",
220
+ "代码",
221
+ "名称",
222
+ "开盘",
223
+ "最新价",
224
+ "最高",
225
+ "最低",
226
+ "总量",
227
+ "涨幅",
228
+ "持仓",
229
+ "日增",
230
+ ]
231
+ ]
232
+ temp_df["日期"] = pd.to_datetime(temp_df["日期"], errors="coerce").dt.date
233
+ temp_df["开盘"] = pd.to_numeric(temp_df["开盘"], errors="coerce")
234
+ temp_df["最新价"] = pd.to_numeric(temp_df["最新价"], errors="coerce")
235
+ temp_df["最高"] = pd.to_numeric(temp_df["最高"], errors="coerce")
236
+ temp_df["最低"] = pd.to_numeric(temp_df["最低"], errors="coerce")
237
+ temp_df["总量"] = pd.to_numeric(temp_df["总量"], errors="coerce")
238
+ temp_df["涨幅"] = pd.to_numeric(temp_df["涨幅"], errors="coerce")
239
+ temp_df["日增"] = pd.to_numeric(temp_df["日增"], errors="coerce")
126
240
  return temp_df
127
241
 
128
242
 
129
243
  if __name__ == "__main__":
130
- futures_global_em_df = futures_global_em()
131
- print(futures_global_em_df)
244
+ futures_global_spot_em_df = futures_global_spot_em()
245
+ print(futures_global_spot_em_df)
132
246
 
133
- futures_global_hist_em_df = futures_global_hist_em(symbol="HG25M")
247
+ futures_global_hist_em_df = futures_global_hist_em(symbol="HG00Y")
134
248
  print(futures_global_hist_em_df)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: akshare
3
- Version: 1.16.28
3
+ Version: 1.16.29
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=fqCk5IyCVc85uNjmJj3ZTExFv_FxrGdLP_YRGqCNShQ,189563
1
+ akshare/__init__.py,sha256=0nKkoBzlF340MgMYFgSBYV8fmLvgWMDXYhA6G_cKozY,189642
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
@@ -112,7 +112,7 @@ akshare/futures/futures_comm_qihuo.py,sha256=uQfabZ63qME8sTaxUbIUVQBVi8yTaPPDhD7
112
112
  akshare/futures/futures_contract_detail.py,sha256=auwzNdaoFi5hoJY6rNkO54v5FD2gmEkQu7B90yEDtkc,1175
113
113
  akshare/futures/futures_daily_bar.py,sha256=pultXs8digLfWT0dzyWs0AtFk3Fi2uZDT-zxbg_PcOM,25299
114
114
  akshare/futures/futures_foreign.py,sha256=2cbMA-eug_jriDFwKZWmA_TbPW2GQAjscpZHBrs287E,2131
115
- akshare/futures/futures_hf_em.py,sha256=xcCzyH0sU-il8RTTLLrnLOt3jybylb1FLMXOEuIUXkM,4437
115
+ akshare/futures/futures_hf_em.py,sha256=vEgJav-g_PNO_Jh4Xup27PIt-ARGqVk9TjNXK_3eC-E,7966
116
116
  akshare/futures/futures_hist_em.py,sha256=Q8I20qRjp2ujiJMCCNBvTHXmrIth22p2k6KpvbkC3dk,6472
117
117
  akshare/futures/futures_hq_sina.py,sha256=HZBAve1yxp1fnwgEy_2CqVoniTXRkt8KI3REt0N0TiY,9575
118
118
  akshare/futures/futures_index_ccidx.py,sha256=_kgWioCOpFNn8WUcL5qKHGb3rUHzrbrx2AszprKpBh4,4460
@@ -383,8 +383,8 @@ akshare/utils/token_process.py,sha256=K4rGXjh_tgugbRcyOK2h2x0jP3PT65IIK7nxhUKhOe
383
383
  akshare/utils/tqdm.py,sha256=MuPNwcswkOGjwWQOMWXi9ZvQ_RmW4obCWRj2i7HM7FE,847
384
384
  tests/__init__.py,sha256=gNzhlO0UPjFq6Ieb38kaVIODXv4cTDByrdohAZnDYt4,82
385
385
  tests/test_func.py,sha256=j1MGYbZI2if2j_LY1S4FLsf4qfq4NwVqD5wmRlv5Log,832
386
- akshare-1.16.28.dist-info/LICENSE,sha256=mmSZCPgfHiVw34LXuFArd-SUgQtBJ_QsIlh-kWlDHfs,1073
387
- akshare-1.16.28.dist-info/METADATA,sha256=3tFeYcw8G7HeGaDHnCBIYJirPqcxfhAmBCwLzroXbIE,13847
388
- akshare-1.16.28.dist-info/WHEEL,sha256=jB7zZ3N9hIM9adW7qlTAyycLYW9npaWKLRzaoVcLKcM,91
389
- akshare-1.16.28.dist-info/top_level.txt,sha256=jsf9ZzZPmHaISTVumQPsAw7vv7Yv-PdEVW70SMEelQQ,14
390
- akshare-1.16.28.dist-info/RECORD,,
386
+ akshare-1.16.29.dist-info/LICENSE,sha256=mmSZCPgfHiVw34LXuFArd-SUgQtBJ_QsIlh-kWlDHfs,1073
387
+ akshare-1.16.29.dist-info/METADATA,sha256=RWyZ6eGQqJw6yAxLc7GyPWNLJYW6pjHFfbwRxsfjupE,13847
388
+ akshare-1.16.29.dist-info/WHEEL,sha256=jB7zZ3N9hIM9adW7qlTAyycLYW9npaWKLRzaoVcLKcM,91
389
+ akshare-1.16.29.dist-info/top_level.txt,sha256=jsf9ZzZPmHaISTVumQPsAw7vv7Yv-PdEVW70SMEelQQ,14
390
+ akshare-1.16.29.dist-info/RECORD,,