akshare 1.16.25__py3-none-any.whl → 1.16.28__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 +9 -1
- akshare/futures/cons.py +120 -12
- akshare/futures/futures_foreign.py +14 -8
- akshare/futures/futures_hf_em.py +31 -0
- akshare/futures/futures_hq_sina.py +1 -1
- akshare/futures/futures_inventory_99.py +3 -3
- akshare/futures/futures_inventory_em.py +6 -6
- akshare/futures_derivative/futures_cot_sina.py +3 -1
- akshare/stock/stock_hsgt_em.py +158 -0
- akshare/stock/stock_zh_ah_tx.py +23 -26
- akshare/stock_feature/stock_hist_em.py +3 -3
- akshare/stock_feature/stock_hsgt_em.py +135 -80
- {akshare-1.16.25.dist-info → akshare-1.16.28.dist-info}/METADATA +1 -1
- {akshare-1.16.25.dist-info → akshare-1.16.28.dist-info}/RECORD +17 -16
- {akshare-1.16.25.dist-info → akshare-1.16.28.dist-info}/LICENSE +0 -0
- {akshare-1.16.25.dist-info → akshare-1.16.28.dist-info}/WHEEL +0 -0
- {akshare-1.16.25.dist-info → akshare-1.16.28.dist-info}/top_level.txt +0 -0
akshare/__init__.py
CHANGED
@@ -3034,9 +3034,12 @@ amac_manager_cancelled_info # 中国证券投资基金业协会-信息公示-诚
|
|
3034
3034
|
1.16.23 fix: fix stock_board_industry_cons_em interface
|
3035
3035
|
1.16.24 fix: fix stock_financial_hk_report_em interface
|
3036
3036
|
1.16.25 fix: fix stock_financial_abstract_ths interface
|
3037
|
+
1.16.26 add: add stock_hsgt_sh_hk_spot_em interface
|
3038
|
+
1.16.27 fix: fix futures_global_em interface
|
3039
|
+
1.16.28 fix: fix futures_global_hist_em interface
|
3037
3040
|
"""
|
3038
3041
|
|
3039
|
-
__version__ = "1.16.
|
3042
|
+
__version__ = "1.16.28"
|
3040
3043
|
__author__ = "AKFamily"
|
3041
3044
|
|
3042
3045
|
import sys
|
@@ -3058,6 +3061,11 @@ if sys.version_info < (3, 9):
|
|
3058
3061
|
|
3059
3062
|
del sys
|
3060
3063
|
|
3064
|
+
"""
|
3065
|
+
东方财富网-行情中心-沪深港通
|
3066
|
+
"""
|
3067
|
+
from akshare.stock.stock_hsgt_em import stock_zh_ah_spot_em, stock_hsgt_sh_hk_spot_em
|
3068
|
+
|
3061
3069
|
"""
|
3062
3070
|
东方财富-美股-财务分析-三大报表
|
3063
3071
|
"""
|
akshare/futures/cons.py
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
#!/usr/bin/env python
|
2
2
|
# -*- coding:utf-8 -*-
|
3
3
|
"""
|
4
|
-
Date:
|
4
|
+
Date: 2025/3/5 18:00
|
5
5
|
Desc: 期货配置文件
|
6
6
|
"""
|
7
7
|
|
@@ -11,8 +11,92 @@ import os
|
|
11
11
|
import pickle
|
12
12
|
import re
|
13
13
|
|
14
|
+
|
15
|
+
futures_inventory_em_symbol_dict = {
|
16
|
+
"a": "A", # 豆一
|
17
|
+
"ag": "AG", # 沪银
|
18
|
+
"al": "AL", # 沪铝
|
19
|
+
"ao": "AO", # 氧化铝
|
20
|
+
"AP": "AP", # 苹果
|
21
|
+
"au": "AU", # 沪金
|
22
|
+
"b": "B", # 豆二
|
23
|
+
"bb": None, # 胶合板 (new中没有对应)
|
24
|
+
"bc": None, # 国际铜 (new中没有对应)
|
25
|
+
"br": "BR", # BR橡胶
|
26
|
+
"bu": "BU", # 沥青
|
27
|
+
"c": "C", # 玉米
|
28
|
+
"CF": "CF", # 棉花/郑棉
|
29
|
+
"CJ": "CJ", # 红枣
|
30
|
+
"cs": "CS", # 淀粉/玉米淀粉
|
31
|
+
"cu": "CU", # 沪铜
|
32
|
+
"CY": "CY", # 棉纱
|
33
|
+
"eb": "EB", # 苯乙烯
|
34
|
+
"ec": "ec", # 集运欧线/集运指数(欧线)
|
35
|
+
"eg": "EG", # 乙二醇
|
36
|
+
"fb": None, # 纤维板 (new中没有对应)
|
37
|
+
"FG": "FG", # 玻璃
|
38
|
+
"fu": "FU", # 燃料油/燃油
|
39
|
+
"hc": "HC", # 热卷
|
40
|
+
"i": "I", # 铁矿石
|
41
|
+
"IC": "IC", # 中证500
|
42
|
+
"IF": "IF", # 沪深300
|
43
|
+
"IH": "IH", # 上证50
|
44
|
+
"IM": "IM", # 中证1000
|
45
|
+
"j": "J", # 焦炭
|
46
|
+
"jd": "JD", # 鸡蛋
|
47
|
+
"jm": "JM", # 焦煤
|
48
|
+
"JR": None, # 粳稻 (new中没有对应)
|
49
|
+
"l": "L", # 塑料
|
50
|
+
"lc": "lc", # 碳酸锂
|
51
|
+
"lh": "LH", # 生猪
|
52
|
+
"LR": None, # 晚籼稻 (new中没有对应)
|
53
|
+
"lu": "lu", # LU燃油/低硫燃料油
|
54
|
+
"m": "M", # 豆粕
|
55
|
+
"MA": "MA", # 甲醇
|
56
|
+
"ni": "NI", # 沪镍/镍
|
57
|
+
"nr": "nr", # 20号胶
|
58
|
+
"OI": "OI", # 菜籽油/菜油
|
59
|
+
"p": "P", # 棕榈油/棕榈
|
60
|
+
"pb": "PB", # 沪铅
|
61
|
+
"PF": "PF", # 短纤
|
62
|
+
"pg": "PG", # 液化气/液化石油气
|
63
|
+
"PK": "PK", # 花生
|
64
|
+
"PM": None, # 普麦 (new中没有对应)
|
65
|
+
"pp": "PP", # 聚丙烯
|
66
|
+
"PX": "PX", # 对二甲苯
|
67
|
+
"rb": "RB", # 螺纹钢
|
68
|
+
"RI": None, # 早籼稻 (new中没有对应)
|
69
|
+
"RM": "RM", # 菜籽粕/菜粕
|
70
|
+
"rr": None, # 粳米 (new中没有对应)
|
71
|
+
"RS": "RS", # 油菜籽/菜籽
|
72
|
+
"ru": "RU", # 橡胶
|
73
|
+
"SA": "SA", # 纯碱
|
74
|
+
"sc": None, # 原油 (new中没有对应)
|
75
|
+
"SF": "SF", # 硅铁
|
76
|
+
"SH": "SH", # 烧碱
|
77
|
+
"si": "si", # 工业硅
|
78
|
+
"SM": "SM", # 锰硅
|
79
|
+
"sn": "SN", # 沪锡/锡
|
80
|
+
"sp": "SP", # 纸浆
|
81
|
+
"SR": "SR", # 白糖
|
82
|
+
"ss": "SS", # 不锈钢
|
83
|
+
"T": "T", # 十年国债/10年期国债
|
84
|
+
"TA": "TA", # PTA
|
85
|
+
"TF": "TF", # 五年国债/5年期国债
|
86
|
+
"TL": "TL", # 三十年国债/30年期国债期货
|
87
|
+
"TS": "TS", # 二年国债/2年期国债
|
88
|
+
"UR": "UR", # 尿素
|
89
|
+
"v": "V", # PVC
|
90
|
+
"WH": None, # 强麦 (new中没有对应)
|
91
|
+
"wr": None, # 线材 (new中没有对应)
|
92
|
+
"y": "Y", # 豆油
|
93
|
+
"ZC": None, # 动力煤 (new中没有对应)
|
94
|
+
"zn": "ZN", # 沪锌
|
95
|
+
}
|
96
|
+
|
14
97
|
hq_sina_spot_headers = {
|
15
|
-
"Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,
|
98
|
+
"Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,"
|
99
|
+
"image/apng,*/*;q=0.8,application/signed-exchange;v=b3",
|
16
100
|
"Accept-Encoding": "gzip, deflate",
|
17
101
|
"Accept-Language": "zh-CN,zh;q=0.9,en;q=0.8",
|
18
102
|
"Cache-Control": "no-cache",
|
@@ -21,14 +105,18 @@ hq_sina_spot_headers = {
|
|
21
105
|
"Pragma": "no-cache",
|
22
106
|
"Referer": "https://finance.sina.com.cn/futuremarket/",
|
23
107
|
"Upgrade-Insecure-Requests": "1",
|
24
|
-
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36
|
108
|
+
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 "
|
109
|
+
"(KHTML, like Gecko) Chrome/78.0.3904.97 Safari/537.36",
|
25
110
|
}
|
26
111
|
|
27
112
|
# zh_sina_spot
|
28
113
|
zh_subscribe_exchange_symbol_url = (
|
29
114
|
"http://vip.stock.finance.sina.com.cn/quotes_service/view/js/qihuohangqing.js"
|
30
115
|
)
|
31
|
-
zh_match_main_contract_url =
|
116
|
+
zh_match_main_contract_url = (
|
117
|
+
"http://vip.stock.finance.sina.com.cn/quotes_service/"
|
118
|
+
"api/json_v2.php/Market_Center.getHQFuturesData"
|
119
|
+
)
|
32
120
|
zh_match_main_contract_payload = {
|
33
121
|
"page": "1",
|
34
122
|
"num": "5",
|
@@ -48,7 +136,8 @@ zh_sina_spot_headers = {
|
|
48
136
|
"Referer": "https://finance.sina.com.cn/futuremarket/",
|
49
137
|
"Sec-Fetch-Mode": "no-cors",
|
50
138
|
"Sec-Fetch-Site": "cross-site",
|
51
|
-
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko)
|
139
|
+
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) "
|
140
|
+
"Chrome/78.0.3904.97 Safari/537.36",
|
52
141
|
}
|
53
142
|
|
54
143
|
# 99 期货
|
@@ -58,10 +147,18 @@ inventory_temp_headers = {
|
|
58
147
|
"Accept-Language": "zh-CN,zh;q=0.9,en;q=0.8",
|
59
148
|
"Connection": "keep-alive",
|
60
149
|
"Content-Type": "application/x-www-form-urlencoded",
|
61
|
-
"Cookie": "UM_distinctid=16c378978de5cc-02cfeac5f7869b-c343162-1fa400-16c378978df8d7;
|
150
|
+
"Cookie": "UM_distinctid=16c378978de5cc-02cfeac5f7869b-c343162-1fa400-16c378978df8d7; "
|
151
|
+
"__utmz=181566328.1570520149.3.2.utmcsr=baidu|utmccn=(organic)|utmcmd=organic; "
|
152
|
+
"ASP.NET_SessionId=wj5gxuzl3fvvr25503tquq55; __utmc=181566328; _fxaid=1D9A634AB9F5D026585"
|
153
|
+
"6F7E85E7BC196%1D%2BOOl1inxPE7181fmKs5HCs%2BdLO%2Fq%2FbSvf46UVjo%2BE7w%3D%1DPYphpUa9OlzW"
|
154
|
+
"UzatrOQTXLPOVillbwMhTIJas%2ByfkyVL2Hd5XA1GOSslksqDkMTccXvQ2duLNsc0CHT4789JrYNbakJrpzrxL"
|
155
|
+
"nwtBC5GCTssKHGEpor6EwAZfWJgBUlCs4JYFcGUnh3jIO69A4LsOlRMOGf4c9cd%2FbohSjTx3VA%3D; __utma"
|
156
|
+
"=181566328.1348268634.1564299852.1571066568.1571068391.7; tgw_l7_route=eb1311426274fc07"
|
157
|
+
"631b2135a6431f7d; __utmt=1; __utmb=181566328.7.10.1571068391",
|
62
158
|
"Host": "service.99qh.com",
|
63
159
|
"Referer": "http://service.99qh.com/Storage/Storage.aspx?page=99qh",
|
64
|
-
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36
|
160
|
+
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 "
|
161
|
+
"(KHTML, like Gecko) Chrome/77.0.3865.90 Safari/537.36",
|
65
162
|
}
|
66
163
|
|
67
164
|
# 奇货可查
|
@@ -177,7 +274,8 @@ headers = {
|
|
177
274
|
"Cache-Control": "max-age=0",
|
178
275
|
"Accept": "text/html, */*; q=0.01",
|
179
276
|
"X-Requested-With": "XMLHttpRequest",
|
180
|
-
"User-Agent": "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko)
|
277
|
+
"User-Agent": "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) "
|
278
|
+
"Chrome/56.0.2924.87 Safari/537.36",
|
181
279
|
"DNT": "1",
|
182
280
|
"Referer": "http://www.super-ping.com/?ping=www.google.com&locale=sc",
|
183
281
|
"Accept-Encoding": "gzip, deflate, sdch",
|
@@ -187,7 +285,8 @@ headers = {
|
|
187
285
|
shfe_headers = {"User-Agent": "Mozilla/4.0 (compatible; MSIE 5.5; Windows NT)"}
|
188
286
|
|
189
287
|
dce_headers = {
|
190
|
-
"Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng
|
288
|
+
"Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,"
|
289
|
+
"*/*;q=0.8,application/signed-exchange;v=b3",
|
191
290
|
"Accept-Encoding": "gzip, deflate",
|
192
291
|
"Accept-Language": "zh-CN,zh;q=0.9,en;q=0.8",
|
193
292
|
"Cache-Control": "max-age=0",
|
@@ -198,7 +297,8 @@ dce_headers = {
|
|
198
297
|
"Proxy-Connection": "keep-alive",
|
199
298
|
"Referer": "http://www.dce.com.cn/publicweb/quotesdata/weekQuotesCh.html",
|
200
299
|
"Upgrade-Insecure-Requests": "1",
|
201
|
-
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko)
|
300
|
+
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) "
|
301
|
+
"Chrome/77.0.3865.90 Safari/537.36",
|
202
302
|
}
|
203
303
|
|
204
304
|
SYS_SPOT_PRICE_URL = "http://www.100ppi.com/sf/day-{}.html"
|
@@ -206,8 +306,16 @@ SYS_SPOT_PRICE_LATEST_URL = "http://www.100ppi.com/sf/"
|
|
206
306
|
|
207
307
|
SHFE_VOL_RANK_URL = "https://tsite.shfe.com.cn/data/dailydata/kx/pm%s.dat"
|
208
308
|
CFFEX_VOL_RANK_URL = "http://www.cffex.com.cn/sj/ccpm/%s/%s/%s_1.csv"
|
209
|
-
DCE_VOL_RANK_URL_1 =
|
210
|
-
|
309
|
+
DCE_VOL_RANK_URL_1 = (
|
310
|
+
"http://www.dce.com.cn/publicweb/quotesdata/exportMemberDealPosiQuotesData.html?"
|
311
|
+
"memberDealPosiQuotes.variety=%s&memberDealPosiQuotes.trade_type=0&contract.cont"
|
312
|
+
"ract_id=%s&contract.variety_id=%s&year=%s&month=%s&day=%s&exportFlag=txt"
|
313
|
+
)
|
314
|
+
DCE_VOL_RANK_URL_2 = (
|
315
|
+
"http://www.dce.com.cn/publicweb/quotesdata/memberDealPosiQuotes.html?memberDeal"
|
316
|
+
"PosiQuotes.variety=%s&memberDealPosiQuotes.trade_type=0&contract.contract_id="
|
317
|
+
"all&contract.variety_id=%s&year=%s&month=%s&day=%s"
|
318
|
+
)
|
211
319
|
CZCE_VOL_RANK_URL_1 = "http://www.czce.com.cn/cn/exchange/jyxx/pm/pm%s.html"
|
212
320
|
CZCE_VOL_RANK_URL_2 = "http://www.czce.com.cn/cn/exchange/%s/datatradeholding/%s.htm"
|
213
321
|
CZCE_VOL_RANK_URL_3 = (
|
@@ -1,30 +1,36 @@
|
|
1
1
|
#!/usr/bin/env python
|
2
2
|
# -*- coding:utf-8 -*-
|
3
3
|
"""
|
4
|
-
Date:
|
4
|
+
Date: 2025/3/5 18:00
|
5
5
|
Desc: 外盘期货-历史行情数据-日频率
|
6
6
|
https://finance.sina.com.cn/money/future/hf.html
|
7
7
|
"""
|
8
|
+
|
8
9
|
from datetime import datetime
|
9
10
|
from io import StringIO
|
10
11
|
|
11
12
|
import pandas as pd
|
12
13
|
import requests
|
13
14
|
|
14
|
-
from akshare.futures.futures_hq_sina import
|
15
|
+
from akshare.futures.futures_hq_sina import (
|
16
|
+
futures_foreign_commodity_subscribe_exchange_symbol,
|
17
|
+
)
|
15
18
|
|
16
19
|
|
17
20
|
def futures_foreign_hist(symbol: str = "ZSD") -> pd.DataFrame:
|
18
21
|
"""
|
19
22
|
外盘期货-历史行情数据-日频率
|
20
23
|
https://finance.sina.com.cn/money/future/hf.html
|
21
|
-
:param symbol:
|
24
|
+
:param symbol: 外盘期货代码, 可以通过 ak.futures_foreign_commodity_subscribe_exchange_symbol() 来获取所有品种代码
|
22
25
|
:type symbol: str
|
23
|
-
:return:
|
26
|
+
:return: 历史行情数据-日频率
|
24
27
|
:rtype: pandas.DataFrame
|
25
28
|
"""
|
26
|
-
today = f
|
27
|
-
url =
|
29
|
+
today = f"{datetime.today().year}_{datetime.today().month}_{datetime.today().day}"
|
30
|
+
url = (
|
31
|
+
f"https://stock2.finance.sina.com.cn/futures/api/jsonp.php/var%20_S{today}=/"
|
32
|
+
f"GlobalFuturesService.getGlobalFuturesDailyKLine"
|
33
|
+
)
|
28
34
|
params = {
|
29
35
|
"symbol": symbol,
|
30
36
|
"_": today,
|
@@ -32,7 +38,7 @@ def futures_foreign_hist(symbol: str = "ZSD") -> pd.DataFrame:
|
|
32
38
|
}
|
33
39
|
r = requests.get(url, params=params)
|
34
40
|
data_text = r.text
|
35
|
-
data_df = pd.read_json(StringIO(data_text[data_text.find("[")
|
41
|
+
data_df = pd.read_json(StringIO(data_text[data_text.find("[") : -2]))
|
36
42
|
return data_df
|
37
43
|
|
38
44
|
|
@@ -52,7 +58,7 @@ def futures_foreign_detail(symbol: str = "ZSD") -> pd.DataFrame:
|
|
52
58
|
return data_df
|
53
59
|
|
54
60
|
|
55
|
-
if __name__ ==
|
61
|
+
if __name__ == "__main__":
|
56
62
|
futures_foreign_hist_df = futures_foreign_hist(symbol="ZSD")
|
57
63
|
print(futures_foreign_hist_df)
|
58
64
|
|
akshare/futures/futures_hf_em.py
CHANGED
@@ -98,6 +98,37 @@ def futures_global_em() -> pd.DataFrame:
|
|
98
98
|
return big_df
|
99
99
|
|
100
100
|
|
101
|
+
def futures_global_hist_em(symbol: str = "HG00Y") -> pd.DataFrame:
|
102
|
+
"""
|
103
|
+
东方财富网-行情中心-期货市场-国际期货-历史行情数据
|
104
|
+
https://quote.eastmoney.com/center/gridlist.html#futures_global
|
105
|
+
:return: 历史行情数据
|
106
|
+
:rtype: pandas.DataFrame
|
107
|
+
"""
|
108
|
+
url = "https://push2his.eastmoney.com/api/qt/stock/kline/get"
|
109
|
+
params = {
|
110
|
+
"secid": f"101.{symbol}",
|
111
|
+
"klt": "101",
|
112
|
+
"fqt": "1",
|
113
|
+
"lmt": "66",
|
114
|
+
"end": "20500000",
|
115
|
+
"iscca": "1",
|
116
|
+
"fields1": "f1,f2,f3,f4,f5,f6,f7,f8",
|
117
|
+
"fields2": "f51,f52,f53,f54,f55,f56,f57,f58,f59,f60,f61,f62,f63,f64",
|
118
|
+
"ut": "f057cbcbce2a86e2866ab8877db1d059",
|
119
|
+
"forcect": "1",
|
120
|
+
}
|
121
|
+
r = requests.get(url, params=params)
|
122
|
+
data_json = r.json()
|
123
|
+
temp_df = pd.DataFrame([item.split(",") for item in data_json["data"]["klines"]])
|
124
|
+
temp_df["code"] = data_json["data"]["code"]
|
125
|
+
temp_df["name"] = data_json["data"]["name"]
|
126
|
+
return temp_df
|
127
|
+
|
128
|
+
|
101
129
|
if __name__ == "__main__":
|
102
130
|
futures_global_em_df = futures_global_em()
|
103
131
|
print(futures_global_em_df)
|
132
|
+
|
133
|
+
futures_global_hist_em_df = futures_global_hist_em(symbol="HG25M")
|
134
|
+
print(futures_global_hist_em_df)
|
@@ -1,7 +1,7 @@
|
|
1
1
|
#!/usr/bin/env python
|
2
2
|
# -*- coding:utf-8 -*-
|
3
3
|
"""
|
4
|
-
Date: 2025/
|
4
|
+
Date: 2025/3/5 17:30
|
5
5
|
Desc: 99 期货网-大宗商品库存数据
|
6
6
|
https://www.99qh.com/
|
7
7
|
"""
|
@@ -73,7 +73,7 @@ def futures_inventory_99(symbol: str = "豆一") -> pd.DataFrame:
|
|
73
73
|
"productId": product_id,
|
74
74
|
"type": "1",
|
75
75
|
"pageNo": "1",
|
76
|
-
"pageSize": "
|
76
|
+
"pageSize": "5000",
|
77
77
|
"startDate": "",
|
78
78
|
"endDate": f"{datetime.now().date().isoformat()}",
|
79
79
|
"appCategory": "web",
|
@@ -90,5 +90,5 @@ def futures_inventory_99(symbol: str = "豆一") -> pd.DataFrame:
|
|
90
90
|
|
91
91
|
|
92
92
|
if __name__ == "__main__":
|
93
|
-
futures_inventory_99_df = futures_inventory_99(symbol="
|
93
|
+
futures_inventory_99_df = futures_inventory_99(symbol="a")
|
94
94
|
print(futures_inventory_99_df)
|
@@ -1,16 +1,17 @@
|
|
1
1
|
#!/usr/bin/env python
|
2
2
|
# -*- coding:utf-8 -*-
|
3
3
|
"""
|
4
|
-
Date: 2025/
|
4
|
+
Date: 2025/3/5 17:30
|
5
5
|
Desc: 东方财富网-数据中心-期货库存数据
|
6
6
|
https://data.eastmoney.com/ifdata/kcsj.html
|
7
7
|
"""
|
8
8
|
|
9
9
|
import pandas as pd
|
10
10
|
import requests
|
11
|
+
from akshare.futures.cons import futures_inventory_em_symbol_dict
|
11
12
|
|
12
13
|
|
13
|
-
def futures_inventory_em(symbol: str = "
|
14
|
+
def futures_inventory_em(symbol: str = "a") -> pd.DataFrame:
|
14
15
|
"""
|
15
16
|
东方财富网-数据中心-期货库存数据
|
16
17
|
https://data.eastmoney.com/ifdata/kcsj.html
|
@@ -36,11 +37,10 @@ def futures_inventory_em(symbol: str = "A") -> pd.DataFrame:
|
|
36
37
|
symbol_dict = dict(zip(temp_df["TRADE_TYPE"], temp_df["TRADE_CODE"]))
|
37
38
|
if symbol in symbol_dict.keys():
|
38
39
|
product_id = symbol_dict[symbol]
|
39
|
-
elif symbol in
|
40
|
-
product_id = symbol
|
40
|
+
elif symbol in futures_inventory_em_symbol_dict.keys(): # 如果输入的是代码
|
41
|
+
product_id = futures_inventory_em_symbol_dict[symbol]
|
41
42
|
else:
|
42
43
|
raise ValueError(f"请输入正确的 symbol, 可选项为: {symbol_dict}")
|
43
|
-
url = "https://datacenter-web.eastmoney.com/api/data/v1/get"
|
44
44
|
params = {
|
45
45
|
"reportName": "RPT_FUTU_STOCKDATA",
|
46
46
|
"columns": "SECURITY_CODE,TRADE_DATE,ON_WARRANT_NUM,ADDCHANGE",
|
@@ -67,5 +67,5 @@ def futures_inventory_em(symbol: str = "A") -> pd.DataFrame:
|
|
67
67
|
|
68
68
|
|
69
69
|
if __name__ == "__main__":
|
70
|
-
futures_inventory_em_df = futures_inventory_em(symbol="
|
70
|
+
futures_inventory_em_df = futures_inventory_em(symbol="a")
|
71
71
|
print(futures_inventory_em_df)
|
@@ -1,7 +1,7 @@
|
|
1
1
|
#!/usr/bin/env python
|
2
2
|
# -*- coding:utf-8 -*-
|
3
3
|
"""
|
4
|
-
Date:
|
4
|
+
Date: 2025/3/5 18:00
|
5
5
|
Desc: 新浪财经-期货-成交持仓
|
6
6
|
https://vip.stock.finance.sina.com.cn/q/view/vFutures_Positions_cjcc.php
|
7
7
|
"""
|
@@ -55,6 +55,8 @@ def futures_hold_pos_sina(
|
|
55
55
|
temp_df["比上交易增减"], errors="coerce"
|
56
56
|
)
|
57
57
|
return temp_df
|
58
|
+
else:
|
59
|
+
raise ValueError("请输入正确的 symbol 参数")
|
58
60
|
|
59
61
|
|
60
62
|
if __name__ == "__main__":
|
@@ -0,0 +1,158 @@
|
|
1
|
+
#!/usr/bin/env python
|
2
|
+
# -*- coding:utf-8 -*-
|
3
|
+
"""
|
4
|
+
Date: 2025/3/4 23:00
|
5
|
+
Desc: 东方财富网-行情中心-沪深港通
|
6
|
+
https://quote.eastmoney.com/center/gridlist.html#ah_comparison
|
7
|
+
"""
|
8
|
+
|
9
|
+
import pandas as pd
|
10
|
+
import requests
|
11
|
+
|
12
|
+
|
13
|
+
def stock_zh_ah_spot_em() -> pd.DataFrame:
|
14
|
+
"""
|
15
|
+
东方财富网-行情中心-沪深港通-AH股比价-实时行情
|
16
|
+
https://quote.eastmoney.com/center/gridlist.html#ah_comparison
|
17
|
+
:return: 东方财富网-行情中心-沪深港通-AH股比价-实时行情
|
18
|
+
:rtype: pandas.DataFrame
|
19
|
+
"""
|
20
|
+
url = "https://push2.eastmoney.com/api/qt/clist/get"
|
21
|
+
params = {
|
22
|
+
"np": "2",
|
23
|
+
"fltt": "1",
|
24
|
+
"invt": "2",
|
25
|
+
"fs": "b:DLMK0101",
|
26
|
+
"fields": "f193,f191,f192,f12,f13,f14,f1,f2,f4,f3,f152,f186,f190,f187,f189,f188",
|
27
|
+
"fid": "f3",
|
28
|
+
"pn": "1",
|
29
|
+
"pz": "50000",
|
30
|
+
"po": "1",
|
31
|
+
"dect": "1",
|
32
|
+
"ut": "fa5fd1943c7b386f172d6893dbfba10b",
|
33
|
+
"wbp2u": "|0|0|0|web",
|
34
|
+
"_": "1741100627371",
|
35
|
+
}
|
36
|
+
r = requests.get(url, params=params)
|
37
|
+
data_json = r.json()
|
38
|
+
temp_df = pd.DataFrame(data_json["data"]["diff"]).T
|
39
|
+
temp_df.reset_index(inplace=True)
|
40
|
+
temp_df["index"] = temp_df["index"].astype(int) + 1
|
41
|
+
temp_df.rename(
|
42
|
+
columns={
|
43
|
+
"index": "序号",
|
44
|
+
"f193": "名称",
|
45
|
+
"f12": "H股代码",
|
46
|
+
"f2": "最新价-HKD",
|
47
|
+
"f3": "H股-涨跌幅",
|
48
|
+
"f191": "A股代码",
|
49
|
+
"f186": "最新价-RMB",
|
50
|
+
"f187": "A股-涨跌幅",
|
51
|
+
"f189": "比价",
|
52
|
+
"f188": "溢价",
|
53
|
+
},
|
54
|
+
inplace=True,
|
55
|
+
)
|
56
|
+
temp_df = temp_df[
|
57
|
+
[
|
58
|
+
"序号",
|
59
|
+
"名称",
|
60
|
+
"H股代码",
|
61
|
+
"最新价-HKD",
|
62
|
+
"H股-涨跌幅",
|
63
|
+
"A股代码",
|
64
|
+
"最新价-RMB",
|
65
|
+
"A股-涨跌幅",
|
66
|
+
"比价",
|
67
|
+
"溢价",
|
68
|
+
]
|
69
|
+
]
|
70
|
+
temp_df["最新价-HKD"] = pd.to_numeric(temp_df["最新价-HKD"], errors="coerce") / 1000
|
71
|
+
temp_df["H股-涨跌幅"] = pd.to_numeric(temp_df["H股-涨跌幅"], errors="coerce") / 100
|
72
|
+
temp_df["最新价-RMB"] = pd.to_numeric(temp_df["最新价-RMB"], errors="coerce") / 100
|
73
|
+
temp_df["A股-涨跌幅"] = pd.to_numeric(temp_df["A股-涨跌幅"], errors="coerce") / 100
|
74
|
+
temp_df["比价"] = pd.to_numeric(temp_df["比价"], errors="coerce") / 100
|
75
|
+
temp_df["溢价"] = pd.to_numeric(temp_df["溢价"], errors="coerce") / 100
|
76
|
+
return temp_df
|
77
|
+
|
78
|
+
|
79
|
+
def stock_hsgt_sh_hk_spot_em() -> pd.DataFrame:
|
80
|
+
"""
|
81
|
+
东方财富网-行情中心-沪深港通-港股通(沪>港)-股票
|
82
|
+
https://quote.eastmoney.com/center/gridlist.html#hk_sh_stocks
|
83
|
+
:return: 东方财富网-行情中心-沪深港通-港股通(沪>港)-股票
|
84
|
+
:rtype: pandas.DataFrame
|
85
|
+
"""
|
86
|
+
url = "https://push2.eastmoney.com/api/qt/clist/get"
|
87
|
+
params = {
|
88
|
+
"np": "2",
|
89
|
+
"fltt": "1",
|
90
|
+
"invt": "2",
|
91
|
+
"fs": "b:DLMK0144",
|
92
|
+
"fields": "f12,f13,f14,f19,f1,f2,f4,f3,f152,f17,f18,f15,f16,f5,f6",
|
93
|
+
"fid": "f3",
|
94
|
+
"pn": "1",
|
95
|
+
"pz": "50000",
|
96
|
+
"po": "1",
|
97
|
+
"dect": "1",
|
98
|
+
"ut": "fa5fd1943c7b386f172d6893dbfba10b",
|
99
|
+
"wbp2u": "|0|0|0|web",
|
100
|
+
"_": "1741100627371",
|
101
|
+
}
|
102
|
+
r = requests.get(url, params=params)
|
103
|
+
data_json = r.json()
|
104
|
+
temp_df = pd.DataFrame(data_json["data"]["diff"]).T
|
105
|
+
temp_df.reset_index(inplace=True)
|
106
|
+
temp_df["index"] = temp_df["index"].astype(int) + 1
|
107
|
+
temp_df.rename(
|
108
|
+
columns={
|
109
|
+
"index": "序号",
|
110
|
+
"f12": "代码",
|
111
|
+
"f14": "名称",
|
112
|
+
"f2": "最新价",
|
113
|
+
"f4": "涨跌额",
|
114
|
+
"f3": "涨跌幅",
|
115
|
+
"f17": "今开",
|
116
|
+
"f15": "最高",
|
117
|
+
"f16": "最低",
|
118
|
+
"f18": "昨收",
|
119
|
+
"f5": "成交量",
|
120
|
+
"f6": "成交额",
|
121
|
+
},
|
122
|
+
inplace=True,
|
123
|
+
)
|
124
|
+
|
125
|
+
temp_df = temp_df[
|
126
|
+
[
|
127
|
+
"序号",
|
128
|
+
"代码",
|
129
|
+
"名称",
|
130
|
+
"最新价",
|
131
|
+
"涨跌额",
|
132
|
+
"涨跌幅",
|
133
|
+
"今开",
|
134
|
+
"最高",
|
135
|
+
"最低",
|
136
|
+
"昨收",
|
137
|
+
"成交量",
|
138
|
+
"成交额",
|
139
|
+
]
|
140
|
+
]
|
141
|
+
temp_df["最新价"] = pd.to_numeric(temp_df["最新价"], errors="coerce") / 1000
|
142
|
+
temp_df["涨跌额"] = pd.to_numeric(temp_df["涨跌额"], errors="coerce") / 1000
|
143
|
+
temp_df["涨跌幅"] = pd.to_numeric(temp_df["涨跌幅"], errors="coerce") / 100
|
144
|
+
temp_df["今开"] = pd.to_numeric(temp_df["今开"], errors="coerce") / 1000
|
145
|
+
temp_df["最高"] = pd.to_numeric(temp_df["最高"], errors="coerce") / 1000
|
146
|
+
temp_df["最低"] = pd.to_numeric(temp_df["最低"], errors="coerce") / 1000
|
147
|
+
temp_df["昨收"] = pd.to_numeric(temp_df["昨收"], errors="coerce") / 1000
|
148
|
+
temp_df["成交量"] = pd.to_numeric(temp_df["成交量"], errors="coerce") / 100000000
|
149
|
+
temp_df["成交额"] = pd.to_numeric(temp_df["成交额"], errors="coerce") / 100000000
|
150
|
+
return temp_df
|
151
|
+
|
152
|
+
|
153
|
+
if __name__ == "__main__":
|
154
|
+
stock_zh_ah_spot_em_df = stock_zh_ah_spot_em()
|
155
|
+
print(stock_zh_ah_spot_em_df)
|
156
|
+
|
157
|
+
stock_hsgt_sh_hk_spot_em_df = stock_hsgt_sh_hk_spot_em()
|
158
|
+
print(stock_hsgt_sh_hk_spot_em_df)
|