akshare 1.16.64__py3-none-any.whl → 1.16.65__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 +2 -1
- akshare/air/cons.py +1 -0
- akshare/air/crypto.js +1 -1
- akshare/air/outcrypto.js +1 -1
- akshare/article/cons.py +1 -0
- akshare/article/epu_index.py +4 -3
- akshare/article/ff_factor.py +19 -8
- akshare/article/fred_md.py +4 -1
- akshare/article/risk_rv.py +3 -8
- akshare/bond/bond_cb_sina.py +1 -0
- akshare/bond/bond_cbond.py +19 -14
- akshare/bond/bond_em.py +34 -15
- akshare/bond/bond_summary.py +38 -37
- akshare/bond/bond_zh_cov.py +0 -6
- akshare/bond/cons.py +14 -11
- akshare/crypto/__init__.py +1 -1
- akshare/crypto/crypto_bitcoin_cme.py +7 -7
- akshare/crypto/crypto_hold.py +4 -1
- akshare/currency/currency.py +1 -0
- akshare/currency/currency_china_bank_sina.py +6 -3
- akshare/data/__init__.py +1 -1
- akshare/data/cninfo.js +1 -1
- akshare/economic/cons.py +10 -3
- akshare/economic/macro_australia.py +0 -7
- akshare/economic/macro_canada.py +92 -81
- akshare/economic/macro_china.py +0 -34
- akshare/economic/macro_china_hk.py +0 -1
- akshare/economic/macro_euro.py +103 -56
- akshare/economic/macro_germany.py +1 -1
- akshare/economic/macro_japan.py +0 -1
- akshare/economic/macro_other.py +1 -6
- akshare/economic/macro_swiss.py +2 -3
- akshare/economic/macro_uk.py +1 -1
- akshare/economic/macro_usa.py +0 -2
- akshare/energy/energy_carbon.py +0 -1
- akshare/energy/energy_oil_em.py +1 -2
- akshare/event/cons.py +1 -0
- akshare/forex/forex_em.py +0 -1
- akshare/fortune/fortune_bloomberg.py +6 -3
- akshare/fortune/fortune_forbes_500.py +3 -6
- akshare/fortune/fortune_hurun.py +2 -1
- akshare/fortune/fortune_xincaifu_500.py +17 -14
- akshare/fund/fund_announcement.py +1 -0
- akshare/fund/fund_aum_em.py +47 -35
- akshare/fund/fund_em.py +0 -7
- akshare/fund/fund_etf_em.py +0 -5
- akshare/fund/fund_fhsp_em.py +27 -20
- akshare/fund/fund_init_em.py +8 -5
- akshare/fund/fund_lof_em.py +0 -5
- akshare/fund/fund_manager.py +18 -7
- akshare/fund/fund_portfolio_em.py +0 -1
- akshare/fund/fund_position_lg.py +19 -8
- akshare/fund/fund_rank_em.py +0 -3
- akshare/fund/fund_rating.py +28 -9
- akshare/fund/fund_scale_em.py +24 -13
- akshare/futures/futures_comex_em.py +1 -0
- akshare/futures/futures_contract_detail.py +11 -8
- akshare/futures/futures_inventory_em.py +0 -2
- akshare/futures/futures_rule.py +5 -1
- akshare/futures/futures_settlement_price_sgx.py +21 -6
- akshare/futures/futures_stock_js.py +0 -1
- akshare/futures/receipt.py +279 -153
- akshare/futures/requests_fun.py +16 -3
- akshare/futures_derivative/cons.py +100 -103
- akshare/futures_derivative/futures_contract_info_cffex.py +53 -39
- akshare/futures_derivative/futures_contract_info_dce.py +16 -9
- akshare/futures_derivative/futures_contract_info_gfex.py +43 -31
- akshare/futures_derivative/futures_index_sina.py +25 -13
- akshare/fx/cons.py +12 -7
- akshare/fx/fx_quote.py +1 -0
- akshare/fx/fx_quote_baidu.py +2 -1
- akshare/hf/__init__.py +1 -1
- akshare/hf/hf_sp500.py +8 -7
- akshare/index/index_eri.py +1 -0
- akshare/index/index_global_em.py +0 -1
- akshare/index/index_kq_fz.py +17 -14
- akshare/index/index_kq_ss.py +1 -0
- akshare/index/index_stock_hk.py +0 -1
- akshare/index/index_stock_zh.py +0 -3
- akshare/index/index_sugar.py +18 -4
- akshare/index/index_zh_em.py +0 -15
- akshare/interest_rate/interbank_rate_em.py +0 -1
- akshare/movie/jm.js +0 -1
- akshare/news/__init__.py +1 -1
- akshare/news/news_stock.py +0 -1
- akshare/option/option_commodity_sina.py +22 -26
- akshare/option/option_daily_stats_sse_szse.py +0 -1
- akshare/option/option_em.py +0 -1
- akshare/option/option_lhb_em.py +0 -1
- akshare/option/option_risk_indicator_sse.py +0 -1
- akshare/other/__init__.py +1 -1
- akshare/pro/__init__.py +0 -1
- akshare/pro/client.py +6 -4
- akshare/pro/cons.py +3 -2
- akshare/pro/data_pro.py +6 -5
- akshare/qhkc/qhkc_api.py +63 -21
- akshare/qhkc_web/qhkc_fund.py +1 -0
- akshare/qhkc_web/qhkc_index.py +1 -0
- akshare/qhkc_web/qhkc_tool.py +55 -54
- akshare/rate/__init__.py +1 -1
- akshare/rate/repo_rate.py +36 -32
- akshare/reits/__init__.py +1 -1
- akshare/reits/reits_basic.py +44 -2
- akshare/sport/__init__.py +1 -1
- akshare/sport/sport_olympic.py +1 -0
- akshare/spot/__init__.py +1 -1
- akshare/stock/cons.py +19 -12
- akshare/stock/stock_board_concept_em.py +0 -6
- akshare/stock/stock_board_industry_em.py +0 -6
- akshare/stock/stock_dzjy_em.py +1 -1
- akshare/stock/stock_fund_em.py +0 -2
- akshare/stock/stock_fund_hold.py +1 -2
- akshare/stock/stock_gsrl_em.py +1 -0
- akshare/stock/stock_hk_famous.py +0 -1
- akshare/stock/stock_hk_fhpx_ths.py +2 -1
- akshare/stock/stock_hk_hot_rank_em.py +1 -0
- akshare/stock/stock_hold_control_em.py +0 -2
- akshare/stock/stock_hot_up_em.py +4 -1
- akshare/stock/stock_hsgt_em.py +0 -2
- akshare/stock/stock_industry.py +1 -0
- akshare/stock/stock_info.py +0 -2
- akshare/stock/stock_info_em.py +0 -1
- akshare/stock/stock_repurchase_em.py +7 -2
- akshare/stock/stock_share_hold.py +0 -1
- akshare/stock/stock_stop.py +0 -1
- akshare/stock/stock_summary.py +0 -2
- akshare/stock/stock_us_famous.py +0 -1
- akshare/stock/stock_us_js.py +3 -2
- akshare/stock/stock_us_pink.py +0 -1
- akshare/stock/stock_weibo_nlp.py +18 -20
- akshare/stock/stock_zh_a_special.py +0 -3
- akshare/stock/stock_zh_a_tick_tx.py +11 -3
- akshare/stock_a/stock_board_concept_name_em.py +0 -1
- akshare/stock_a/stock_zh_a_spot.py +0 -1
- akshare/stock_feature/cons.py +1 -0
- akshare/stock_feature/stock_account_em.py +0 -1
- akshare/stock_feature/stock_all_pb.py +2 -1
- akshare/stock_feature/stock_analyst_em.py +0 -3
- akshare/stock_feature/stock_buffett_index_lg.py +7 -6
- akshare/stock_feature/stock_classify_sina.py +3 -6
- akshare/stock_feature/stock_comment_em.py +0 -2
- akshare/stock_feature/stock_congestion_lg.py +2 -1
- akshare/stock_feature/stock_dxsyl_em.py +116 -71
- akshare/stock_feature/stock_gdzjc_em.py +16 -5
- akshare/stock_feature/stock_gxl_lg.py +3 -2
- akshare/stock_feature/stock_hist_em.py +0 -20
- akshare/stock_feature/stock_hist_tx.py +10 -8
- akshare/stock_feature/stock_hot_xq.py +4 -6
- akshare/stock_feature/stock_hsgt_em.py +0 -2
- akshare/stock_feature/stock_hsgt_exchange_rate.py +0 -2
- akshare/stock_feature/stock_hsgt_min_em.py +13 -16
- akshare/stock_feature/stock_inner_trade_xq.py +0 -1
- akshare/stock_feature/stock_lhb_em.py +0 -1
- akshare/stock_feature/stock_margin_em.py +0 -1
- akshare/stock_feature/stock_margin_sse.py +0 -2
- akshare/stock_feature/stock_pankou_em.py +0 -2
- akshare/stock_feature/stock_qsjy_em.py +13 -4
- akshare/stock_feature/stock_research_report_em.py +0 -1
- akshare/stock_feature/stock_yjyg_cninfo.py +4 -1
- akshare/stock_feature/stock_zh_vote_baidu.py +4 -1
- akshare/stock_feature/stock_ztb_em.py +0 -6
- akshare/stock_fundamental/__init__.py +1 -1
- akshare/stock_fundamental/stock_hold.py +26 -17
- akshare/stock_fundamental/stock_ipo_declare.py +1 -0
- akshare/stock_fundamental/stock_kcb_detail_sse.py +10 -10
- akshare/stock_fundamental/stock_kcb_sse.py +26 -25
- akshare/stock_fundamental/stock_profit_forecast_hk_etnet.py +64 -41
- akshare/stock_fundamental/stock_recommend.py +20 -4
- akshare/utils/demjson.py +2005 -1334
- akshare/utils/token_process.py +6 -5
- {akshare-1.16.64.dist-info → akshare-1.16.65.dist-info}/METADATA +3 -8
- {akshare-1.16.64.dist-info → akshare-1.16.65.dist-info}/RECORD +175 -175
- {akshare-1.16.64.dist-info → akshare-1.16.65.dist-info}/WHEEL +0 -0
- {akshare-1.16.64.dist-info → akshare-1.16.65.dist-info}/licenses/LICENSE +0 -0
- {akshare-1.16.64.dist-info → akshare-1.16.65.dist-info}/top_level.txt +0 -0
akshare/futures/receipt.py
CHANGED
@@ -5,6 +5,7 @@ Date: 2024/1/22 18:00
|
|
5
5
|
Desc: 每日注册仓单数据
|
6
6
|
大连商品交易所, 上海期货交易所, 郑州商品交易所, 广州期货交易所
|
7
7
|
"""
|
8
|
+
|
8
9
|
import datetime
|
9
10
|
import re
|
10
11
|
import warnings
|
@@ -19,10 +20,18 @@ from akshare.futures.requests_fun import requests_link, pandas_read_html_link
|
|
19
20
|
from akshare.futures.symbol_var import chinese_to_english
|
20
21
|
|
21
22
|
calendar = cons.get_calendar()
|
22
|
-
shfe_20100126 = pd.DataFrame(
|
23
|
-
|
24
|
-
|
25
|
-
|
23
|
+
shfe_20100126 = pd.DataFrame(
|
24
|
+
{
|
25
|
+
"var": ["CU", "AL", "ZN", "RU", "FU", "AU", "RB", "WR"],
|
26
|
+
"receipt": [29783, 285396, 187713, 116435, 376200, 12, 145648, 0],
|
27
|
+
}
|
28
|
+
)
|
29
|
+
shfe_20101029 = pd.DataFrame(
|
30
|
+
{
|
31
|
+
"var": ["CU", "AL", "ZN", "RU", "FU", "AU", "RB", "WR"],
|
32
|
+
"receipt": [39214, 359729, 182562, 25990, 313600, 27, 36789, 0],
|
33
|
+
}
|
34
|
+
)
|
26
35
|
|
27
36
|
|
28
37
|
def get_dce_receipt(date: str = None, vars_list: List = cons.contract_symbols):
|
@@ -39,34 +48,41 @@ def get_dce_receipt(date: str = None, vars_list: List = cons.contract_symbols):
|
|
39
48
|
if not isinstance(vars_list, list):
|
40
49
|
return warnings.warn("vars_list: 必须是列表")
|
41
50
|
date = cons.convert_date(date) if date is not None else datetime.date.today()
|
42
|
-
if date.strftime(
|
51
|
+
if date.strftime("%Y%m%d") not in calendar:
|
43
52
|
warnings.warn(f"{date.strftime('%Y%m%d')}非交易日")
|
44
53
|
return None
|
45
54
|
payload = {
|
46
55
|
"weekQuotes.variety": "all",
|
47
56
|
"year": date.year,
|
48
57
|
"month": date.month - 1, # 网站月份描述少 1 个月, 属于网站问题
|
49
|
-
"day": date.day
|
58
|
+
"day": date.day,
|
50
59
|
}
|
51
|
-
data = pandas_read_html_link(
|
60
|
+
data = pandas_read_html_link(
|
61
|
+
cons.DCE_RECEIPT_URL, method="post", data=payload, headers=cons.dce_headers
|
62
|
+
)[0]
|
52
63
|
records = pd.DataFrame()
|
53
|
-
for x in data.to_dict(orient=
|
54
|
-
if isinstance(x[
|
55
|
-
if x[
|
56
|
-
var = x[
|
57
|
-
temp_data = {
|
58
|
-
|
59
|
-
|
64
|
+
for x in data.to_dict(orient="records"):
|
65
|
+
if isinstance(x["品种"], str):
|
66
|
+
if x["品种"][-2:] == "小计":
|
67
|
+
var = x["品种"][:-2]
|
68
|
+
temp_data = {
|
69
|
+
"var": chinese_to_english(var),
|
70
|
+
"receipt": int(x["今日仓单量"]),
|
71
|
+
"receipt_chg": int(x["增减"]),
|
72
|
+
"date": date.strftime("%Y%m%d"),
|
73
|
+
}
|
60
74
|
records = pd.concat([records, pd.DataFrame(temp_data, index=[0])])
|
61
75
|
|
62
76
|
if len(records.index) != 0:
|
63
|
-
records.index = records[
|
77
|
+
records.index = records["var"]
|
64
78
|
vars_in_market = [i for i in vars_list if i in records.index]
|
65
79
|
records = records.loc[vars_in_market, :]
|
66
80
|
return records.reset_index(drop=True)
|
67
81
|
|
68
82
|
|
69
|
-
def get_shfe_receipt_1(
|
83
|
+
def get_shfe_receipt_1(
|
84
|
+
date: str = None, vars_list: List = cons.contract_symbols
|
85
|
+
) -> pd.DataFrame:
|
70
86
|
"""
|
71
87
|
上海期货交易所-注册仓单数据-类型1
|
72
88
|
适用 20081006 至 20140518(包括)、20100126、20101029日期交易所格式混乱,直接回复脚本中 pandas.DataFrame, 20100416、20130821日期交易所数据丢失
|
@@ -78,47 +94,68 @@ def get_shfe_receipt_1(date: str = None, vars_list: List = cons.contract_symbols
|
|
78
94
|
:rtype: pandas.DataFrame
|
79
95
|
"""
|
80
96
|
if not isinstance(vars_list, list):
|
81
|
-
raise warnings.warn(
|
82
|
-
date =
|
97
|
+
raise warnings.warn("symbol_list: 必须是列表")
|
98
|
+
date = (
|
99
|
+
cons.convert_date(date).strftime("%Y%m%d")
|
100
|
+
if date is not None
|
101
|
+
else datetime.date.today()
|
102
|
+
)
|
83
103
|
if date not in calendar:
|
84
104
|
warnings.warn(f"{date.strftime('%Y%m%d')}非交易日")
|
85
105
|
return None
|
86
|
-
if date ==
|
87
|
-
shfe_20100126[
|
106
|
+
if date == "20100126":
|
107
|
+
shfe_20100126["date"] = date
|
88
108
|
return shfe_20100126
|
89
|
-
elif date ==
|
90
|
-
shfe_20101029[
|
109
|
+
elif date == "20101029":
|
110
|
+
shfe_20101029["date"] = date
|
91
111
|
return shfe_20101029
|
92
|
-
elif date in [
|
93
|
-
return warnings.warn(
|
112
|
+
elif date in ["20100416", "20130821"]:
|
113
|
+
return warnings.warn("20100416、20130821交易所数据丢失")
|
94
114
|
else:
|
95
|
-
var_list = [
|
96
|
-
|
115
|
+
var_list = [
|
116
|
+
"天然橡胶",
|
117
|
+
"沥青仓库",
|
118
|
+
"沥青厂库",
|
119
|
+
"热轧卷板",
|
120
|
+
"燃料油",
|
121
|
+
"白银",
|
122
|
+
"线材",
|
123
|
+
"螺纹钢",
|
124
|
+
"铅",
|
125
|
+
"铜",
|
126
|
+
"铝",
|
127
|
+
"锌",
|
128
|
+
"黄金",
|
129
|
+
"锡",
|
130
|
+
"镍",
|
131
|
+
]
|
97
132
|
url = cons.SHFE_RECEIPT_URL_1 % date
|
98
133
|
data = pandas_read_html_link(url)[0]
|
99
134
|
indexes = [x for x in data.index if (data[0].tolist()[x] in var_list)]
|
100
|
-
last_index = [x for x in data.index if
|
135
|
+
last_index = [x for x in data.index if "注" in str(data[0].tolist()[x])][0] - 1
|
101
136
|
records = pd.DataFrame()
|
102
137
|
for i in list(range(len(indexes))):
|
103
138
|
if i != len(indexes) - 1:
|
104
|
-
data_cut = data.loc[indexes[i]:indexes[i + 1] - 1, :]
|
139
|
+
data_cut = data.loc[indexes[i] : indexes[i + 1] - 1, :]
|
105
140
|
else:
|
106
|
-
data_cut = data.loc[indexes[i]:last_index, :]
|
107
|
-
data_cut = data_cut.fillna(method=
|
141
|
+
data_cut = data.loc[indexes[i] : last_index, :]
|
142
|
+
data_cut = data_cut.fillna(method="pad")
|
108
143
|
data_dict = dict()
|
109
|
-
data_dict[
|
110
|
-
data_dict[
|
111
|
-
data_dict[
|
112
|
-
data_dict[
|
144
|
+
data_dict["var"] = chinese_to_english(data_cut[0].tolist()[0])
|
145
|
+
data_dict["receipt"] = int(data_cut[2].tolist()[-1])
|
146
|
+
data_dict["receipt_chg"] = int(data_cut[3].tolist()[-1])
|
147
|
+
data_dict["date"] = date
|
113
148
|
records = pd.concat([records, pd.DataFrame(data_dict, index=[0])])
|
114
149
|
if len(records.index) != 0:
|
115
|
-
records.index = records[
|
150
|
+
records.index = records["var"]
|
116
151
|
vars_in_market = [i for i in vars_list if i in records.index]
|
117
152
|
records = records.loc[vars_in_market, :]
|
118
153
|
return records.reset_index(drop=True)
|
119
154
|
|
120
155
|
|
121
|
-
def get_shfe_receipt_2(
|
156
|
+
def get_shfe_receipt_2(
|
157
|
+
date: str = None, vars_list: List = cons.contract_symbols
|
158
|
+
) -> pd.DataFrame:
|
122
159
|
"""
|
123
160
|
上海商品交易所-注册仓单数据-类型2
|
124
161
|
适用 20140519(包括)-至今
|
@@ -130,39 +167,49 @@ def get_shfe_receipt_2(date: str = None, vars_list: List = cons.contract_symbols
|
|
130
167
|
:rtype: pandas.DataFrame
|
131
168
|
"""
|
132
169
|
if not isinstance(vars_list, list):
|
133
|
-
raise warnings.warn(
|
134
|
-
date =
|
170
|
+
raise warnings.warn("symbol_list: 必须是列表")
|
171
|
+
date = (
|
172
|
+
cons.convert_date(date).strftime("%Y%m%d")
|
173
|
+
if date is not None
|
174
|
+
else datetime.date.today()
|
175
|
+
)
|
135
176
|
if date not in calendar:
|
136
|
-
warnings.warn(
|
177
|
+
warnings.warn("%s 非交易日" % date.strftime("%Y%m%d"))
|
137
178
|
return None
|
138
179
|
url = cons.SHFE_RECEIPT_URL_2 % date
|
139
|
-
r = requests_link(url, encoding=
|
180
|
+
r = requests_link(url, encoding="utf-8", headers=cons.shfe_headers)
|
140
181
|
try:
|
141
182
|
context = r.json()
|
142
|
-
except:
|
183
|
+
except: # noqa: E722
|
143
184
|
return pd.DataFrame()
|
144
|
-
data = pd.DataFrame(context[
|
185
|
+
data = pd.DataFrame(context["o_cursor"])
|
145
186
|
if len(data.columns) < 1:
|
146
187
|
return pd.DataFrame()
|
147
188
|
records = pd.DataFrame()
|
148
|
-
for var in set(data[
|
149
|
-
data_cut = data[data[
|
189
|
+
for var in set(data["VARNAME"].tolist()):
|
190
|
+
data_cut = data[data["VARNAME"] == var]
|
150
191
|
if "BC" in var:
|
151
|
-
data_dict = {
|
152
|
-
|
153
|
-
|
154
|
-
|
192
|
+
data_dict = {
|
193
|
+
"var": "BC",
|
194
|
+
"receipt": int(data_cut["WRTWGHTS"].tolist()[-1]),
|
195
|
+
"receipt_chg": int(data_cut["WRTCHANGE"].tolist()[-1]),
|
196
|
+
"date": date,
|
197
|
+
}
|
155
198
|
else:
|
156
|
-
data_dict = {
|
157
|
-
|
158
|
-
|
159
|
-
|
199
|
+
data_dict = {
|
200
|
+
"var": chinese_to_english(re.sub(r"\W|[a-zA-Z]", "", var)),
|
201
|
+
"receipt": int(data_cut["WRTWGHTS"].tolist()[-1]),
|
202
|
+
"receipt_chg": int(data_cut["WRTCHANGE"].tolist()[-1]),
|
203
|
+
"date": date,
|
204
|
+
}
|
160
205
|
records = pd.concat([records, pd.DataFrame(data_dict, index=[0])])
|
161
|
-
temp_records =
|
162
|
-
|
206
|
+
temp_records = (
|
207
|
+
records.groupby("var")[["receipt", "receipt_chg"]].sum().reset_index()
|
208
|
+
)
|
209
|
+
temp_records["date"] = date
|
163
210
|
records = temp_records
|
164
211
|
if len(records.index) != 0:
|
165
|
-
records.index = records[
|
212
|
+
records.index = records["var"]
|
166
213
|
vars_in_market = [i for i in vars_list if i in records.index]
|
167
214
|
records = records.loc[vars_in_market, :]
|
168
215
|
return records.reset_index(drop=True)
|
@@ -179,40 +226,49 @@ def get_czce_receipt_1(date: str = None, vars_list: List = cons.contract_symbols
|
|
179
226
|
:return: 注册仓单数据
|
180
227
|
:rtype: pandas.DataFrame
|
181
228
|
"""
|
182
|
-
date =
|
229
|
+
date = (
|
230
|
+
cons.convert_date(date).strftime("%Y%m%d")
|
231
|
+
if date is not None
|
232
|
+
else datetime.date.today()
|
233
|
+
)
|
183
234
|
if date not in calendar:
|
184
|
-
warnings.warn(
|
235
|
+
warnings.warn("%s非交易日" % date.strftime("%Y%m%d"))
|
185
236
|
return None
|
186
|
-
if date ==
|
237
|
+
if date == "20090820":
|
187
238
|
return pd.DataFrame()
|
188
239
|
url = cons.CZCE_RECEIPT_URL_1 % date
|
189
|
-
r = requests_link(url, encoding=
|
240
|
+
r = requests_link(url, encoding="utf-8", headers=cons.shfe_headers)
|
190
241
|
context = r.text
|
191
242
|
data = pd.read_html(context)[1]
|
192
243
|
records = pd.DataFrame()
|
193
|
-
indexes = [x for x in data.index if
|
194
|
-
ends = [x for x in data.index if
|
244
|
+
indexes = [x for x in data.index if "品种:" in str(data[0].tolist()[x])]
|
245
|
+
ends = [x for x in data.index if "总计" in str(data[0].tolist()[x])]
|
195
246
|
for i in list(range(len(indexes))):
|
196
247
|
if i != len(indexes) - 1:
|
197
|
-
data_cut = data.loc[indexes[i]:ends[i], :]
|
198
|
-
data_cut = data_cut.fillna(method=
|
248
|
+
data_cut = data.loc[indexes[i] : ends[i], :]
|
249
|
+
data_cut = data_cut.fillna(method="pad")
|
199
250
|
else:
|
200
|
-
data_cut = data.loc[indexes[i]:, :]
|
201
|
-
data_cut = data_cut.fillna(method=
|
202
|
-
if
|
203
|
-
var =
|
251
|
+
data_cut = data.loc[indexes[i] :, :]
|
252
|
+
data_cut = data_cut.fillna(method="pad")
|
253
|
+
if "PTA" in data_cut[0].tolist()[0]:
|
254
|
+
var = "TA"
|
204
255
|
else:
|
205
|
-
var = chinese_to_english(re.sub(r
|
206
|
-
if var ==
|
256
|
+
var = chinese_to_english(re.sub(r"[A-Z]+", "", data_cut[0].tolist()[0][3:]))
|
257
|
+
if var == "CF":
|
207
258
|
receipt = data_cut[6].tolist()[-1]
|
208
259
|
receipt_chg = data_cut[7].tolist()[-1]
|
209
260
|
else:
|
210
261
|
receipt = data_cut[5].tolist()[-1]
|
211
262
|
receipt_chg = data_cut[6].tolist()[-1]
|
212
|
-
data_dict = {
|
263
|
+
data_dict = {
|
264
|
+
"var": var,
|
265
|
+
"receipt": int(receipt),
|
266
|
+
"receipt_chg": int(receipt_chg),
|
267
|
+
"date": date,
|
268
|
+
}
|
213
269
|
records = pd.concat([records, pd.DataFrame(data_dict, index=[0])])
|
214
270
|
if len(records.index) != 0:
|
215
|
-
records.index = records[
|
271
|
+
records.index = records["var"]
|
216
272
|
vars_in_market = [i for i in vars_list if i in records.index]
|
217
273
|
records = records.loc[vars_in_market, :]
|
218
274
|
return records.reset_index(drop=True)
|
@@ -231,41 +287,54 @@ def get_czce_receipt_2(date: str = None, vars_list: List = cons.contract_symbols
|
|
231
287
|
:rtype: pandas.DataFrame
|
232
288
|
"""
|
233
289
|
if not isinstance(vars_list, list):
|
234
|
-
return warnings.warn(
|
235
|
-
date =
|
290
|
+
return warnings.warn("symbol_list: 必须是列表")
|
291
|
+
date = (
|
292
|
+
cons.convert_date(date).strftime("%Y%m%d")
|
293
|
+
if date is not None
|
294
|
+
else datetime.date.today()
|
295
|
+
)
|
236
296
|
if date not in calendar:
|
237
|
-
warnings.warn(
|
297
|
+
warnings.warn("%s非交易日" % date.strftime("%Y%m%d"))
|
238
298
|
return None
|
239
299
|
url = cons.CZCE_RECEIPT_URL_2 % (date[:4], date)
|
240
300
|
r = requests.get(url)
|
241
|
-
r.encoding =
|
301
|
+
r.encoding = "utf-8"
|
242
302
|
data = pd.read_html(r.text)[3:]
|
243
303
|
records = pd.DataFrame()
|
244
304
|
for data_cut in data:
|
245
305
|
if len(data_cut.columns) > 3:
|
246
|
-
last_indexes = [
|
306
|
+
last_indexes = [
|
307
|
+
x for x in data_cut.index if "注:" in str(data_cut[0].tolist()[x])
|
308
|
+
]
|
247
309
|
if len(last_indexes) > 0:
|
248
310
|
last_index = last_indexes[0] - 1
|
249
311
|
data_cut = data_cut.loc[:last_index, :]
|
250
|
-
if
|
251
|
-
var =
|
312
|
+
if "PTA" in data_cut[0].tolist()[0]:
|
313
|
+
var = "TA"
|
252
314
|
else:
|
253
315
|
strings = data_cut[0].tolist()[0]
|
254
|
-
string = strings.split(
|
255
|
-
var = chinese_to_english(re.sub(r
|
316
|
+
string = strings.split(" ")[0][3:]
|
317
|
+
var = chinese_to_english(re.sub(r"[A-Z]+", "", string))
|
256
318
|
data_cut.columns = data_cut.T[1].tolist()
|
257
|
-
receipt = data_cut[
|
258
|
-
receipt_chg = data_cut[
|
259
|
-
data_dict = {
|
319
|
+
receipt = data_cut["仓单数量"].tolist()[-1]
|
320
|
+
receipt_chg = data_cut["当日增减"].tolist()[-1]
|
321
|
+
data_dict = {
|
322
|
+
"var": var,
|
323
|
+
"receipt": int(receipt),
|
324
|
+
"receipt_chg": int(receipt_chg),
|
325
|
+
"date": date,
|
326
|
+
}
|
260
327
|
records = pd.concat([records, pd.DataFrame(data_dict, index=[0])])
|
261
328
|
if len(records.index) != 0:
|
262
|
-
records.index = records[
|
329
|
+
records.index = records["var"]
|
263
330
|
vars_in_market = [i for i in vars_list if i in records.index]
|
264
331
|
records = records.loc[vars_in_market, :]
|
265
332
|
return records.reset_index(drop=True)
|
266
333
|
|
267
334
|
|
268
|
-
def get_czce_receipt_3(
|
335
|
+
def get_czce_receipt_3(
|
336
|
+
date: str = None, vars_list: List = cons.contract_symbols
|
337
|
+
) -> pd.DataFrame:
|
269
338
|
"""
|
270
339
|
郑州商品交易所-注册仓单数据
|
271
340
|
适用 20151008-至今
|
@@ -279,71 +348,104 @@ def get_czce_receipt_3(date: str = None, vars_list: List = cons.contract_symbols
|
|
279
348
|
"""
|
280
349
|
if not isinstance(vars_list, list):
|
281
350
|
return warnings.warn("vars_list: 必须是列表")
|
282
|
-
date =
|
351
|
+
date = (
|
352
|
+
cons.convert_date(date).strftime("%Y%m%d")
|
353
|
+
if date is not None
|
354
|
+
else datetime.date.today()
|
355
|
+
)
|
283
356
|
if date not in calendar:
|
284
|
-
warnings.warn(
|
357
|
+
warnings.warn("%s非交易日" % date.strftime("%Y%m%d"))
|
285
358
|
return None
|
286
359
|
url = f"http://www.czce.com.cn/cn/DFSStaticFiles/Future/{date[:4]}/{date}/FutureDataWhsheet.xls"
|
287
|
-
r = requests_link(url, encoding=
|
360
|
+
r = requests_link(url, encoding="utf-8", headers=cons.shfe_headers)
|
288
361
|
temp_df = pd.read_excel(BytesIO(r.content))
|
289
|
-
temp_df = temp_df[
|
290
|
-
|
362
|
+
temp_df = temp_df[
|
363
|
+
[
|
364
|
+
bool(1 - item)
|
365
|
+
for item in [
|
366
|
+
item if item is not pd.NA else False
|
367
|
+
for item in temp_df.iloc[:, 0].str.contains("非农产品")
|
368
|
+
]
|
369
|
+
]
|
370
|
+
]
|
291
371
|
temp_df.reset_index(inplace=True, drop=True)
|
292
372
|
range_list_one = list(
|
293
|
-
temp_df[
|
373
|
+
temp_df[
|
374
|
+
[
|
375
|
+
item if not pd.isnull(item) else False
|
376
|
+
for item in temp_df.iloc[:, 0].str.contains("品种")
|
377
|
+
]
|
378
|
+
].index
|
379
|
+
)
|
294
380
|
range_list_two = list(
|
295
|
-
temp_df[
|
381
|
+
temp_df[
|
382
|
+
[
|
383
|
+
item if not pd.isnull(item) else False
|
384
|
+
for item in temp_df.iloc[:, 0].str.contains("品种")
|
385
|
+
]
|
386
|
+
].index
|
387
|
+
)[1:]
|
296
388
|
range_list_two.append(None)
|
297
389
|
symbol_list = []
|
298
390
|
receipt_list = []
|
299
391
|
receipt_chg_list = []
|
300
392
|
for page in range(len(range_list_one)):
|
301
|
-
inner_df = temp_df[range_list_one[page]: range_list_two[page]]
|
302
|
-
reg = re.compile(r
|
393
|
+
inner_df = temp_df[range_list_one[page] : range_list_two[page]]
|
394
|
+
reg = re.compile(r"[A-Z]+")
|
303
395
|
try:
|
304
396
|
symbol = reg.findall(inner_df.iloc[0, 0])[0]
|
305
|
-
except:
|
397
|
+
except: # noqa: E722
|
306
398
|
continue
|
307
399
|
symbol_list.append(symbol)
|
308
400
|
inner_df.columns = inner_df.iloc[1, :]
|
309
401
|
inner_df = inner_df.iloc[2:, :]
|
310
|
-
inner_df = inner_df.dropna(axis=1, how=
|
402
|
+
inner_df = inner_df.dropna(axis=1, how="all")
|
311
403
|
if symbol == "PTA":
|
312
404
|
try:
|
313
|
-
receipt_list.append(
|
314
|
-
inner_df[
|
315
|
-
|
405
|
+
receipt_list.append(
|
406
|
+
inner_df["仓单数量(完税)"].iloc[-1]
|
407
|
+
+ int(inner_df["仓单数量(保税)"].iloc[-1])
|
408
|
+
) # 20210316 TA 分为保税和完税
|
409
|
+
except: # noqa: E722
|
316
410
|
receipt_list.append(0)
|
317
411
|
elif symbol == "MA":
|
318
412
|
try:
|
319
413
|
try:
|
320
|
-
receipt_list.append(
|
321
|
-
inner_df[
|
322
|
-
|
323
|
-
|
324
|
-
|
414
|
+
receipt_list.append(
|
415
|
+
inner_df["仓单数量(完税)"].iloc[-2]
|
416
|
+
+ int(inner_df["仓单数量(保税)"].iloc[-2])
|
417
|
+
) # 20210316 MA 分为保税和完税
|
418
|
+
except: # noqa: E722
|
419
|
+
receipt_list.append(
|
420
|
+
inner_df["仓单数量(完税)"].iloc[-2]
|
421
|
+
) # 处理 MA 的特殊格式
|
422
|
+
except: # noqa: E722
|
325
423
|
receipt_list.append(0)
|
326
424
|
else:
|
327
425
|
try:
|
328
|
-
receipt_list.append(inner_df[
|
329
|
-
except:
|
426
|
+
receipt_list.append(inner_df["仓单数量"].iloc[-1])
|
427
|
+
except: # noqa: E722
|
330
428
|
receipt_list.append(0)
|
331
429
|
if symbol == "MA":
|
332
|
-
receipt_chg_list.append(inner_df[
|
430
|
+
receipt_chg_list.append(inner_df["当日增减"].iloc[-2])
|
333
431
|
else:
|
334
|
-
receipt_chg_list.append(inner_df[
|
335
|
-
data_df = pd.DataFrame(
|
336
|
-
|
337
|
-
|
338
|
-
data_df
|
432
|
+
receipt_chg_list.append(inner_df["当日增减"].iloc[-1])
|
433
|
+
data_df = pd.DataFrame(
|
434
|
+
[symbol_list, receipt_list, receipt_chg_list, [date] * len(receipt_chg_list)]
|
435
|
+
).T
|
436
|
+
data_df.columns = ["var", "receipt", "receipt_chg", "date"]
|
437
|
+
temp_list = data_df["var"].tolist()
|
438
|
+
data_df["var"] = [item if item != "PTA" else "TA" for item in temp_list]
|
339
439
|
if len(data_df.index) != 0:
|
340
|
-
data_df.index = data_df[
|
440
|
+
data_df.index = data_df["var"]
|
341
441
|
vars_in_market = [i for i in vars_list if i in data_df.index]
|
342
442
|
records = data_df.loc[vars_in_market, :]
|
343
443
|
return records.reset_index(drop=True)
|
344
444
|
|
345
445
|
|
346
|
-
def get_gfex_receipt(
|
446
|
+
def get_gfex_receipt(
|
447
|
+
date: str = None, vars_list: List = cons.contract_symbols
|
448
|
+
) -> pd.DataFrame:
|
347
449
|
"""
|
348
450
|
广州期货交易所-注册仓单数据
|
349
451
|
http://www.gfex.com.cn/gfex/cdrb/hqsj_tjsj.shtml
|
@@ -357,13 +459,11 @@ def get_gfex_receipt(date: str = None, vars_list: List = cons.contract_symbols)
|
|
357
459
|
if not isinstance(vars_list, list):
|
358
460
|
raise warnings.warn("vars_list: 必须是列表")
|
359
461
|
date = cons.convert_date(date) if date is not None else datetime.date.today()
|
360
|
-
if date.strftime(
|
462
|
+
if date.strftime("%Y%m%d") not in calendar:
|
361
463
|
warnings.warn(f"{date.strftime('%Y%m%d')}非交易日")
|
362
464
|
return pd.DataFrame()
|
363
465
|
url = "http://www.gfex.com.cn/u/interfacesWebTdWbillWeeklyQuotes/loadList"
|
364
|
-
payload = {
|
365
|
-
"gen_date": date.isoformat().replace("-", "")
|
366
|
-
}
|
466
|
+
payload = {"gen_date": date.isoformat().replace("-", "")}
|
367
467
|
headers = {
|
368
468
|
"Accept": "application/json, text/javascript, */*; q=0.01",
|
369
469
|
"Accept-Encoding": "gzip, deflate",
|
@@ -378,35 +478,42 @@ def get_gfex_receipt(date: str = None, vars_list: List = cons.contract_symbols)
|
|
378
478
|
"Referer": "http://www.gfex.com.cn/gfex/rihq/hqsj_tjsj.shtml",
|
379
479
|
"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",
|
380
480
|
"X-Requested-With": "XMLHttpRequest",
|
381
|
-
"content-type": "application/x-www-form-urlencoded"
|
481
|
+
"content-type": "application/x-www-form-urlencoded",
|
382
482
|
}
|
383
483
|
r = requests.post(url, data=payload, headers=headers)
|
384
484
|
data_json = r.json()
|
385
|
-
temp_df = pd.DataFrame(data_json[
|
386
|
-
temp_df = temp_df[temp_df[
|
387
|
-
result_df = temp_df[[
|
485
|
+
temp_df = pd.DataFrame(data_json["data"])
|
486
|
+
temp_df = temp_df[temp_df["variety"].str.contains("小计")]
|
487
|
+
result_df = temp_df[["wbillQty", "diff"]].copy()
|
388
488
|
if result_df.empty:
|
389
489
|
return pd.DataFrame()
|
390
490
|
|
391
|
-
result_df.loc[:,
|
392
|
-
result_df.loc[:,
|
491
|
+
result_df.loc[:, "date"] = date.isoformat().replace("-", "")
|
492
|
+
result_df.loc[:, "var"] = [
|
493
|
+
item.upper() for item in temp_df["varietyOrder"].tolist()
|
494
|
+
]
|
393
495
|
result_df.reset_index(drop=True, inplace=True)
|
394
|
-
result_df.rename(
|
395
|
-
|
396
|
-
|
397
|
-
|
398
|
-
|
399
|
-
|
400
|
-
|
401
|
-
result_df
|
402
|
-
|
403
|
-
|
496
|
+
result_df.rename(
|
497
|
+
columns={
|
498
|
+
"wbillQty": "receipt",
|
499
|
+
"diff": "receipt_chg",
|
500
|
+
},
|
501
|
+
inplace=True,
|
502
|
+
)
|
503
|
+
result_df = result_df[["var", "receipt", "receipt_chg", "date"]]
|
504
|
+
result_df.set_index(["var"], inplace=True)
|
505
|
+
if "LC" not in result_df.index:
|
506
|
+
vars_list.remove("LC")
|
404
507
|
result_df = result_df.loc[vars_list, :]
|
405
508
|
result_df.reset_index(inplace=True)
|
406
509
|
return result_df
|
407
510
|
|
408
511
|
|
409
|
-
def get_receipt(
|
512
|
+
def get_receipt(
|
513
|
+
start_date: str = None,
|
514
|
+
end_date: str = None,
|
515
|
+
vars_list: List = cons.contract_symbols,
|
516
|
+
):
|
410
517
|
"""
|
411
518
|
大宗商品-注册仓单数据
|
412
519
|
:param start_date: 开始日期 format:YYYY-MM-DD 或 YYYYMMDD 或 datetime.date 对象 为空时为当天
|
@@ -419,49 +526,68 @@ def get_receipt(start_date: str = None, end_date: str = None, vars_list: List =
|
|
419
526
|
:rtype: pandas.DataFrame
|
420
527
|
"""
|
421
528
|
if not isinstance(vars_list, list):
|
422
|
-
return warnings.warn(
|
423
|
-
start_date =
|
424
|
-
|
425
|
-
|
529
|
+
return warnings.warn("vars_list: 必须是列表")
|
530
|
+
start_date = (
|
531
|
+
cons.convert_date(start_date)
|
532
|
+
if start_date is not None
|
533
|
+
else datetime.date.today()
|
534
|
+
)
|
535
|
+
end_date = (
|
536
|
+
cons.convert_date(end_date)
|
537
|
+
if end_date is not None
|
538
|
+
else cons.convert_date(cons.get_latest_data_date(datetime.datetime.now()))
|
539
|
+
)
|
426
540
|
records = pd.DataFrame()
|
427
541
|
while start_date <= end_date:
|
428
|
-
if start_date.strftime(
|
542
|
+
if start_date.strftime("%Y%m%d") not in calendar:
|
429
543
|
warnings.warn(f"{start_date.strftime('%Y%m%d')} 非交易日")
|
430
544
|
else:
|
431
545
|
print(start_date)
|
432
546
|
for market, market_vars in cons.market_exchange_symbols.items():
|
433
|
-
if market ==
|
547
|
+
if market == "dce":
|
434
548
|
if start_date >= datetime.date(2009, 4, 7):
|
435
549
|
f = get_dce_receipt
|
436
550
|
else:
|
437
|
-
print(
|
551
|
+
print("20090407 起,大连商品交易所每个交易日更新仓单数据")
|
438
552
|
f = None
|
439
|
-
elif market ==
|
440
|
-
if
|
553
|
+
elif market == "shfe":
|
554
|
+
if (
|
555
|
+
datetime.date(2008, 10, 6)
|
556
|
+
<= start_date
|
557
|
+
<= datetime.date(2014, 5, 16)
|
558
|
+
):
|
441
559
|
f = get_shfe_receipt_1
|
442
560
|
elif start_date > datetime.date(2014, 5, 16):
|
443
561
|
f = get_shfe_receipt_2
|
444
562
|
else:
|
445
563
|
f = None
|
446
|
-
print(
|
564
|
+
print("20081006 起,上海期货交易所每个交易日更新仓单数据")
|
447
565
|
elif market == "gfex":
|
448
566
|
if start_date > datetime.date(2022, 12, 22):
|
449
567
|
f = get_gfex_receipt
|
450
568
|
else:
|
451
569
|
f = None
|
452
|
-
print(
|
453
|
-
elif market ==
|
454
|
-
if
|
570
|
+
print("20081006 起,上海期货交易所每个交易日更新仓单数据")
|
571
|
+
elif market == "czce":
|
572
|
+
if (
|
573
|
+
datetime.date(2008, 3, 3)
|
574
|
+
<= start_date
|
575
|
+
<= datetime.date(2010, 8, 24)
|
576
|
+
):
|
455
577
|
f = get_czce_receipt_1
|
456
|
-
elif
|
578
|
+
elif (
|
579
|
+
datetime.date(2010, 8, 24)
|
580
|
+
< start_date
|
581
|
+
<= datetime.date(2015, 11, 11)
|
582
|
+
):
|
457
583
|
f = get_czce_receipt_2
|
458
584
|
elif start_date > datetime.date(2015, 11, 11):
|
459
585
|
f = get_czce_receipt_3
|
460
586
|
else:
|
461
587
|
f = None
|
462
|
-
print(
|
588
|
+
print("20080303 起,郑州商品交易所每个交易日更新仓单数据")
|
463
589
|
get_vars = [var for var in vars_list if var in market_vars]
|
464
|
-
if market !=
|
590
|
+
if market != "cffex" and get_vars != []:
|
465
591
|
if f is not None:
|
466
592
|
records = pd.concat([records, f(start_date, get_vars)])
|
467
593
|
start_date += datetime.timedelta(days=1)
|
@@ -471,6 +597,6 @@ def get_receipt(start_date: str = None, end_date: str = None, vars_list: List =
|
|
471
597
|
return records
|
472
598
|
|
473
599
|
|
474
|
-
if __name__ ==
|
475
|
-
get_receipt_df = get_receipt(start_date=
|
600
|
+
if __name__ == "__main__":
|
601
|
+
get_receipt_df = get_receipt(start_date="20230601", end_date="20230615")
|
476
602
|
print(get_receipt_df)
|