akshare 1.14.49__py3-none-any.whl → 1.17.99__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 +595 -129
- akshare/air/air_hebei.py +77 -54
- akshare/air/air_zhenqi.py +0 -4
- 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/bank/bank_cbirc_2020.py +11 -11
- akshare/bank/cons.py +7 -6
- akshare/bond/bond_buy_back_em.py +228 -0
- akshare/bond/bond_cb_sina.py +1 -0
- akshare/bond/bond_cb_ths.py +17 -9
- akshare/bond/bond_cbond.py +19 -14
- akshare/bond/bond_china.py +38 -39
- akshare/bond/bond_china_money.py +1 -1
- akshare/bond/bond_convert.py +10 -9
- akshare/bond/bond_em.py +37 -17
- akshare/bond/bond_summary.py +38 -37
- akshare/bond/bond_zh_cov.py +31 -40
- akshare/bond/bond_zh_sina.py +4 -0
- akshare/bond/cons.py +14 -11
- akshare/cal/__init__.py +0 -0
- akshare/cal/rv.py +170 -0
- akshare/cost/cost_living.py +7 -5
- akshare/crypto/__init__.py +1 -1
- akshare/crypto/crypto_bitcoin_cme.py +9 -7
- akshare/crypto/crypto_hold.py +4 -2
- akshare/currency/currency.py +1 -0
- akshare/currency/currency_china_bank_sina.py +11 -6
- akshare/data/__init__.py +1 -1
- akshare/data/cninfo.js +1 -1
- akshare/datasets.py +10 -21
- akshare/economic/cons.py +10 -3
- akshare/economic/macro_australia.py +74 -69
- akshare/economic/macro_bank.py +95 -653
- akshare/economic/macro_canada.py +92 -81
- akshare/economic/macro_china.py +97 -105
- akshare/economic/macro_china_hk.py +0 -1
- akshare/economic/macro_euro.py +103 -56
- akshare/economic/macro_finance_ths.py +7 -5
- 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 +7 -9
- akshare/economic/marco_cnbs.py +11 -6
- akshare/energy/energy_carbon.py +0 -1
- akshare/energy/energy_oil_em.py +1 -2
- akshare/event/cons.py +1 -0
- akshare/exceptions.py +43 -0
- akshare/file_fold/calendar.json +245 -2
- akshare/forex/__init__.py +0 -0
- akshare/forex/cons.py +192 -0
- akshare/forex/forex_em.py +149 -0
- akshare/fortune/fortune_500.py +1 -37
- 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_em.py +145 -0
- akshare/fund/fund_aum_em.py +49 -35
- akshare/fund/fund_em.py +251 -220
- akshare/fund/fund_etf_em.py +44 -35
- akshare/fund/fund_etf_sina.py +75 -27
- akshare/fund/fund_etf_ths.py +2 -0
- akshare/fund/fund_fee_em.py +172 -0
- akshare/fund/fund_fhsp_em.py +42 -32
- akshare/fund/fund_init_em.py +8 -5
- akshare/fund/fund_lof_em.py +12 -19
- akshare/fund/fund_manager.py +25 -11
- akshare/fund/fund_overview_em.py +42 -0
- akshare/fund/fund_portfolio_em.py +23 -21
- akshare/fund/fund_position_lg.py +19 -8
- akshare/fund/fund_rank_em.py +2 -5
- akshare/fund/fund_rating.py +33 -12
- akshare/fund/fund_scale_em.py +24 -13
- akshare/fund/fund_scale_sina.py +20 -10
- akshare/fund/fund_xq.py +3 -2
- akshare/futures/cons.py +135 -39
- akshare/futures/cot.py +55 -56
- akshare/futures/futures_basis.py +49 -11
- akshare/futures/futures_comex_em.py +1 -0
- akshare/futures/futures_comm_ctp.py +1 -1
- akshare/futures/futures_contract_detail.py +59 -9
- akshare/futures/futures_daily_bar.py +66 -59
- akshare/futures/futures_foreign.py +14 -8
- akshare/futures/futures_hf_em.py +215 -61
- akshare/futures/futures_hist_em.py +191 -0
- akshare/futures/futures_hq_sina.py +5 -3
- akshare/futures/futures_index_ccidx.py +24 -82
- akshare/futures/futures_inventory_99.py +70 -272
- akshare/futures/futures_inventory_em.py +14 -11
- akshare/futures/futures_news_shmet.py +2 -2
- akshare/futures/futures_roll_yield.py +11 -24
- akshare/futures/futures_rule.py +7 -3
- akshare/futures/futures_rule_em.py +38 -0
- akshare/futures/futures_settlement_price_sgx.py +21 -6
- akshare/futures/futures_stock_js.py +0 -1
- akshare/futures/futures_to_spot.py +5 -6
- akshare/futures/futures_warehouse_receipt.py +48 -47
- akshare/futures/futures_zh_sina.py +3 -3
- akshare/futures/receipt.py +298 -165
- akshare/futures/requests_fun.py +16 -3
- akshare/futures/symbol_var.py +32 -13
- akshare/futures_derivative/cons.py +100 -103
- akshare/futures_derivative/futures_contract_info_cffex.py +55 -39
- akshare/futures_derivative/futures_contract_info_czce.py +2 -0
- akshare/futures_derivative/futures_contract_info_dce.py +43 -17
- akshare/futures_derivative/futures_contract_info_gfex.py +43 -31
- akshare/futures_derivative/futures_contract_info_ine.py +43 -34
- akshare/futures_derivative/futures_contract_info_shfe.py +3 -4
- akshare/futures_derivative/futures_cot_sina.py +8 -6
- akshare/futures_derivative/futures_index_sina.py +25 -13
- akshare/fx/cons.py +12 -7
- akshare/fx/fx_c_swap_cm.py +62 -0
- akshare/fx/fx_quote.py +3 -2
- akshare/fx/fx_quote_baidu.py +2 -1
- akshare/hf/__init__.py +1 -1
- akshare/hf/hf_sp500.py +8 -7
- akshare/index/cons.py +132 -28
- akshare/index/index_cni.py +7 -7
- akshare/index/index_cons.py +2 -2
- akshare/index/index_csindex.py +68 -0
- akshare/index/index_cx.py +20 -20
- akshare/index/index_drewry.py +17 -16
- akshare/index/index_eri.py +1 -0
- akshare/index/index_global_em.py +167 -0
- akshare/index/index_global_sina.py +82 -0
- akshare/index/index_kq_fz.py +17 -14
- akshare/index/index_kq_ss.py +1 -0
- akshare/index/index_option_qvix.py +351 -16
- akshare/index/index_research_sw.py +21 -21
- akshare/index/index_spot.py +9 -5
- akshare/index/index_stock_hk.py +5 -9
- akshare/index/index_stock_zh.py +111 -24
- akshare/index/index_stock_zh_csindex.py +3 -367
- akshare/index/index_sugar.py +18 -4
- akshare/index/index_sw.py +10 -2
- akshare/index/index_yw.py +53 -75
- akshare/index/index_zh_em.py +15 -82
- akshare/interest_rate/interbank_rate_em.py +0 -1
- akshare/movie/jm.js +0 -1
- akshare/news/__init__.py +1 -1
- akshare/news/news_baidu.py +395 -222
- akshare/news/news_stock.py +49 -16
- akshare/option/cons.py +2 -2
- akshare/option/option_commodity.py +341 -220
- akshare/option/option_commodity_sina.py +22 -26
- akshare/option/option_contract_info_ctp.py +63 -0
- akshare/option/option_current_sse.py +61 -0
- akshare/option/option_current_szse.py +84 -0
- akshare/option/option_czce.py +37 -9
- akshare/option/option_daily_stats_sse_szse.py +0 -1
- akshare/option/option_em.py +4 -8
- akshare/option/option_finance.py +60 -12
- akshare/option/option_finance_sina.py +7 -7
- akshare/option/option_lhb_em.py +0 -1
- akshare/option/option_margin.py +62 -0
- akshare/option/option_premium_analysis_em.py +58 -53
- akshare/option/option_risk_analysis_em.py +11 -8
- akshare/option/option_risk_indicator_sse.py +3 -4
- akshare/option/option_value_analysis_em.py +62 -55
- 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/qdii/__init__.py +0 -0
- akshare/qdii/qdii_jsl.py +233 -0
- akshare/qhkc/__init__.py +1 -6
- akshare/qhkc/qhkc_api.py +64 -22
- akshare/qhkc_web/__init__.py +1 -6
- akshare/qhkc_web/qhkc_fund.py +10 -6
- akshare/qhkc_web/qhkc_index.py +28 -14
- akshare/qhkc_web/qhkc_tool.py +62 -59
- akshare/rate/__init__.py +1 -1
- akshare/rate/repo_rate.py +36 -32
- akshare/reits/__init__.py +1 -1
- akshare/reits/reits_basic.py +149 -13
- akshare/request.py +117 -0
- akshare/spot/__init__.py +1 -1
- akshare/spot/spot_hog_soozhu.py +165 -3
- akshare/spot/spot_sge.py +70 -9
- akshare/stock/cons.py +60 -23
- akshare/stock/stock_allotment_cninfo.py +8 -8
- akshare/stock/stock_ask_bid_em.py +3 -78
- akshare/stock/stock_board_concept_em.py +160 -35
- akshare/stock/stock_board_industry_em.py +163 -70
- akshare/stock/stock_dividend_cninfo.py +31 -17
- akshare/stock/stock_dzjy_em.py +347 -260
- akshare/stock/stock_fund_em.py +72 -64
- akshare/stock/stock_fund_hold.py +1 -2
- akshare/stock/stock_gsrl_em.py +1 -0
- akshare/stock/stock_hk_comparison_em.py +175 -0
- akshare/stock/stock_hk_famous.py +4 -5
- akshare/stock/stock_hk_fhpx_ths.py +2 -1
- akshare/stock/stock_hk_hot_rank_em.py +1 -0
- akshare/stock/stock_hk_sina.py +84 -36
- akshare/stock/stock_hold_control_cninfo.py +82 -0
- akshare/stock/stock_hold_control_em.py +0 -2
- akshare/stock/stock_hot_rank_em.py +4 -1
- akshare/stock/stock_hot_search_baidu.py +32 -19
- akshare/stock/stock_hot_up_em.py +4 -1
- akshare/stock/stock_hsgt_em.py +155 -0
- akshare/stock/stock_industry.py +1 -0
- akshare/stock/stock_industry_cninfo.py +1 -2
- akshare/stock/stock_info.py +6 -4
- akshare/stock/stock_info_em.py +17 -11
- akshare/stock/stock_intraday_em.py +4 -78
- akshare/stock/stock_intraday_sina.py +2 -2
- akshare/stock/stock_news_cx.py +39 -0
- akshare/stock/stock_profile_cninfo.py +7 -7
- akshare/stock/stock_profile_em.py +302 -0
- akshare/stock/stock_rank_forecast.py +6 -5
- akshare/stock/stock_repurchase_em.py +7 -2
- akshare/stock/stock_share_changes_cninfo.py +7 -5
- akshare/stock/stock_share_hold.py +24 -20
- akshare/stock/stock_stop.py +6 -6
- akshare/stock/stock_summary.py +153 -417
- akshare/stock/stock_us_famous.py +5 -6
- akshare/stock/stock_us_js.py +3 -2
- akshare/stock/stock_us_pink.py +38 -27
- akshare/stock/stock_us_sina.py +7 -3
- akshare/stock/stock_weibo_nlp.py +18 -20
- akshare/stock/stock_xq.py +24 -22
- akshare/stock/stock_zh_a_sina.py +8 -5
- akshare/stock/stock_zh_a_special.py +240 -243
- akshare/stock/stock_zh_a_tick_tx.py +11 -3
- akshare/stock/stock_zh_ah_tx.py +23 -26
- akshare/stock/stock_zh_b_sina.py +2 -2
- akshare/stock/stock_zh_comparison_em.py +250 -0
- akshare/stock/stock_zh_kcb_sina.py +67 -64
- akshare/stock_a/__init__.py +0 -0
- akshare/stock_a/stock_board_concept_name_em.py +170 -0
- akshare/stock_a/stock_individual_fund_flow_rank.py +258 -0
- akshare/stock_a/stock_zh_a_spot.py +212 -0
- akshare/stock_feature/cons.py +1 -0
- akshare/stock_feature/stock_a_indicator.py +9 -54
- akshare/stock_feature/stock_a_pe_and_pb.py +23 -5
- 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 +36 -30
- akshare/stock_feature/stock_board_concept_ths.py +328 -0
- akshare/stock_feature/stock_board_industry_ths.py +57 -2
- akshare/stock_feature/stock_buffett_index_lg.py +10 -8
- akshare/stock_feature/stock_classify_sina.py +3 -6
- akshare/stock_feature/stock_comment_em.py +81 -144
- akshare/stock_feature/stock_congestion_lg.py +2 -1
- akshare/stock_feature/stock_cyq_em.py +5 -11
- akshare/stock_feature/stock_disclosure_cninfo.py +6 -6
- akshare/stock_feature/stock_dxsyl_em.py +121 -74
- akshare/stock_feature/stock_ebs_lg.py +5 -4
- akshare/stock_feature/stock_esg_sina.py +29 -7
- akshare/stock_feature/stock_fhps_em.py +2 -1
- akshare/stock_feature/stock_fhps_ths.py +15 -7
- akshare/stock_feature/stock_fund_flow.py +30 -22
- akshare/stock_feature/stock_gddh_em.py +19 -11
- akshare/stock_feature/stock_gdfx_em.py +226 -113
- akshare/stock_feature/stock_gdhs.py +75 -50
- akshare/stock_feature/stock_gdzjc_em.py +21 -10
- akshare/stock_feature/stock_gpzy_em.py +78 -46
- akshare/stock_feature/stock_gxl_lg.py +3 -2
- akshare/stock_feature/stock_hist_em.py +137 -234
- akshare/stock_feature/stock_hist_tx.py +13 -10
- akshare/stock_feature/stock_hk_valuation_baidu.py +20 -8
- akshare/stock_feature/stock_hot_xq.py +4 -6
- akshare/stock_feature/stock_hsgt_em.py +269 -97
- akshare/stock_feature/stock_hsgt_exchange_rate.py +115 -87
- akshare/stock_feature/stock_hsgt_min_em.py +13 -16
- akshare/stock_feature/stock_info.py +7 -80
- akshare/stock_feature/stock_inner_trade_xq.py +38 -31
- akshare/stock_feature/stock_jgdy_em.py +43 -40
- akshare/stock_feature/stock_lhb_em.py +119 -3
- 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 +71 -35
- akshare/stock_feature/stock_qsjy_em.py +13 -4
- akshare/stock_feature/stock_report_em.py +151 -7
- akshare/stock_feature/stock_research_report_em.py +55 -20
- akshare/stock_feature/stock_sy_em.py +20 -15
- akshare/stock_feature/stock_technology_ths.py +122 -77
- akshare/stock_feature/stock_tfp_em.py +2 -1
- akshare/stock_feature/stock_three_report_em.py +21 -5
- akshare/stock_feature/stock_ttm_lyr.py +18 -9
- akshare/stock_feature/stock_value_em.py +83 -0
- akshare/stock_feature/stock_yjbb_em.py +58 -32
- akshare/stock_feature/stock_yjyg_cninfo.py +6 -2
- akshare/stock_feature/stock_yjyg_em.py +1 -1
- akshare/stock_feature/stock_yzxdr_em.py +24 -22
- akshare/stock_feature/stock_zdhtmx_em.py +20 -6
- akshare/stock_feature/stock_zh_vote_baidu.py +4 -1
- akshare/stock_feature/stock_ztb_em.py +39 -24
- akshare/stock_fundamental/__init__.py +1 -1
- akshare/stock_fundamental/stock_basic_info_xq.py +119 -0
- akshare/stock_fundamental/{stock_finance_hk.py → stock_finance_hk_em.py} +23 -16
- akshare/stock_fundamental/{stock_finance.py → stock_finance_sina.py} +60 -7
- akshare/stock_fundamental/stock_finance_ths.py +524 -57
- akshare/stock_fundamental/stock_finance_us_em.py +268 -0
- akshare/stock_fundamental/stock_gbjg_em.py +80 -0
- 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_notice.py +12 -3
- akshare/stock_fundamental/stock_profit_forecast_em.py +31 -13
- akshare/stock_fundamental/stock_profit_forecast_hk_etnet.py +64 -41
- akshare/stock_fundamental/stock_profit_forecast_ths.py +86 -35
- akshare/stock_fundamental/stock_recommend.py +20 -4
- akshare/stock_fundamental/stock_zygc.py +5 -62
- akshare/utils/context.py +43 -0
- akshare/utils/demjson.py +2009 -1338
- akshare/utils/func.py +49 -2
- akshare/utils/multi_decrypt.py +53 -0
- akshare/utils/token_process.py +6 -5
- {akshare-1.14.49.dist-info → akshare-1.17.99.dist-info}/METADATA +54 -80
- akshare-1.17.99.dist-info/RECORD +409 -0
- {akshare-1.14.49.dist-info → akshare-1.17.99.dist-info}/WHEEL +1 -1
- {akshare-1.14.49.dist-info → akshare-1.17.99.dist-info/licenses}/LICENSE +1 -1
- tests/test_func.py +3 -5
- akshare/bond/bond_futures.py +0 -50
- akshare/bond/bond_investing.py +0 -139
- akshare/crypto/crypto_hist_investing.py +0 -249
- akshare/fund/fund_announcement.py +0 -56
- akshare/futures/futures_international.py +0 -170
- akshare/futures/futures_news_baidu.py +0 -54
- akshare/futures/inventory_data.py +0 -100
- akshare/futures_derivative/futures_index_price_nh.py +0 -61
- akshare/futures_derivative/futures_index_return_nh.py +0 -47
- akshare/futures_derivative/futures_index_volatility_nh.py +0 -53
- akshare/futures_derivative/futures_other_index_nh.py +0 -145
- akshare/index/index_fear_greed_funddb.py +0 -78
- akshare/index/index_investing.py +0 -232
- akshare/sport/__init__.py +0 -6
- akshare/sport/sport_olympic.py +0 -27
- akshare/stock_feature/stock_wencai.py +0 -104
- akshare/stock_fundamental/stock_mda_ym.py +0 -40
- akshare-1.14.49.dist-info/RECORD +0 -387
- {akshare-1.14.49.dist-info → akshare-1.17.99.dist-info}/top_level.txt +0 -0
akshare/futures/cot.py
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env python
|
|
2
2
|
# -*- coding:utf-8 -*-
|
|
3
3
|
"""
|
|
4
|
-
Date:
|
|
4
|
+
Date: 2025/7/21 15:00
|
|
5
5
|
Desc: 期货-中国-交易所-会员持仓数据接口
|
|
6
6
|
大连商品交易所、上海期货交易所、郑州商品交易所、中国金融期货交易所、广州期货交易所
|
|
7
7
|
采集前 20 会员持仓数据;
|
|
@@ -69,7 +69,8 @@ def get_rank_sum_daily(
|
|
|
69
69
|
:type end_day: str
|
|
70
70
|
:param vars_list: 合约品种如 ['RB'、'AL'] 等列表为空时为所有商品
|
|
71
71
|
:type vars_list: list
|
|
72
|
-
:return:
|
|
72
|
+
:return: 会员持仓排名数据
|
|
73
|
+
:rtype: pandas.DataFrame
|
|
73
74
|
symbol 标的合约 string
|
|
74
75
|
var 商品品种 string
|
|
75
76
|
vol_top5 成交量前5会员成交量总和 int
|
|
@@ -98,7 +99,7 @@ def get_rank_sum_daily(
|
|
|
98
99
|
f"{start_day.strftime('%Y-%m-%d')}日交易所数据连接失败,已超过20次,您的地址被网站墙了,请保存好返回数据,稍后从该日期起重试"
|
|
99
100
|
)
|
|
100
101
|
return records.reset_index(drop=True)
|
|
101
|
-
records = pd.concat([records, data], ignore_index=True)
|
|
102
|
+
records = pd.concat(objs=[records, data], ignore_index=True)
|
|
102
103
|
else:
|
|
103
104
|
warnings.warn(f"{start_day.strftime('%Y%m%d')}非交易日")
|
|
104
105
|
start_day += datetime.timedelta(days=1)
|
|
@@ -116,7 +117,8 @@ def get_rank_sum(date: str = "20210525", vars_list: list = cons.contract_symbols
|
|
|
116
117
|
:type date: date
|
|
117
118
|
:param vars_list: 合约品种如 ['RB', 'AL'] 等列表为空时为所有商品
|
|
118
119
|
:type vars_list: list
|
|
119
|
-
:return:
|
|
120
|
+
:return: 持仓排名数据
|
|
121
|
+
:rtype: pandas.DataFrame
|
|
120
122
|
symbol 标的合约 string
|
|
121
123
|
var 商品品种 string
|
|
122
124
|
vol_top5 成交量前5会员成交量总和 int
|
|
@@ -148,7 +150,7 @@ def get_rank_sum(date: str = "20210525", vars_list: list = cons.contract_symbols
|
|
|
148
150
|
return False
|
|
149
151
|
big_dict.update(data)
|
|
150
152
|
if len(czce_var) > 0:
|
|
151
|
-
data =
|
|
153
|
+
data = get_rank_table_czce(date)
|
|
152
154
|
if data is False:
|
|
153
155
|
return False
|
|
154
156
|
big_dict.update(data)
|
|
@@ -306,7 +308,7 @@ def get_shfe_rank_table(
|
|
|
306
308
|
if date.strftime("%Y%m%d") not in calendar:
|
|
307
309
|
warnings.warn("%s非交易日" % date.strftime("%Y%m%d"))
|
|
308
310
|
return {}
|
|
309
|
-
url = cons.
|
|
311
|
+
url = cons.SHFE_VOL_RANK_URL_20250701 % (date.strftime("%Y%m%d"))
|
|
310
312
|
r = requests_link(url, encoding="utf-8", headers=cons.shfe_headers)
|
|
311
313
|
try:
|
|
312
314
|
context = json.loads(r.text)
|
|
@@ -403,12 +405,15 @@ def _czce_df_read(url, skip_rows, encoding="utf-8", header=0):
|
|
|
403
405
|
return data
|
|
404
406
|
|
|
405
407
|
|
|
406
|
-
def
|
|
408
|
+
def get_rank_table_czce(date: str = "20251103") -> dict:
|
|
407
409
|
"""
|
|
408
410
|
郑州商品交易所前 20 会员持仓排名数据明细
|
|
411
|
+
https://www.czce.com.cn/cn/jysj/ccpm/H077003004index_1.htm
|
|
409
412
|
注:该交易所既公布了品种排名, 也公布了标的排名
|
|
410
413
|
:param date: 日期 format:YYYY-MM-DD 或 YYYYMMDD 或 datetime.date对象 为空时为当天
|
|
411
|
-
:return:
|
|
414
|
+
:return: 持仓排名数据明细
|
|
415
|
+
:rtype: pandas.DataFrame
|
|
416
|
+
返回值格式
|
|
412
417
|
rank 排名 int
|
|
413
418
|
vol_party_name 成交量排序的当前名次会员 string(中文)
|
|
414
419
|
vol 该会员成交量 int
|
|
@@ -435,13 +440,18 @@ def get_czce_rank_table(date: str = "20210428") -> dict:
|
|
|
435
440
|
if date.strftime("%Y%m%d") not in calendar:
|
|
436
441
|
warnings.warn("%s非交易日" % date.strftime("%Y%m%d"))
|
|
437
442
|
return {}
|
|
438
|
-
if date
|
|
443
|
+
if date > datetime.date(year=2025, month=11, day=1):
|
|
444
|
+
url = (
|
|
445
|
+
f"http://www.czce.com.cn/cn/DFSStaticFiles/Future/{date.year}/"
|
|
446
|
+
f"{date.isoformat().replace('-', '')}/FutureDataHolding.xlsx"
|
|
447
|
+
)
|
|
448
|
+
else:
|
|
439
449
|
url = (
|
|
440
450
|
f"http://www.czce.com.cn/cn/DFSStaticFiles/Future/{date.year}/"
|
|
441
451
|
f"{date.isoformat().replace('-', '')}/FutureDataHolding.xls"
|
|
442
452
|
)
|
|
443
|
-
|
|
444
|
-
|
|
453
|
+
r = requests.get(url, headers=headers)
|
|
454
|
+
temp_df = pd.read_excel(BytesIO(r.content))
|
|
445
455
|
|
|
446
456
|
temp_pinzhong_index = [
|
|
447
457
|
item + 1
|
|
@@ -509,7 +519,7 @@ def _get_dce_contract_list(date, var):
|
|
|
509
519
|
:param var: 合约品种
|
|
510
520
|
:return: list 公布了持仓排名的合约列表
|
|
511
521
|
"""
|
|
512
|
-
url = "http://
|
|
522
|
+
url = "http://portal.dce.com.cn/publicweb/quotesdata/memberDealPosiQuotes.html"
|
|
513
523
|
headers = {
|
|
514
524
|
"Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;"
|
|
515
525
|
"q=0.8,application/signed-exchange;v=b3;q=0.9",
|
|
@@ -518,7 +528,7 @@ def _get_dce_contract_list(date, var):
|
|
|
518
528
|
"Cache-Control": "no-cache",
|
|
519
529
|
"Connection": "close",
|
|
520
530
|
"Host": "www.dce.com.cn",
|
|
521
|
-
"Origin": "http://
|
|
531
|
+
"Origin": "http://portal.dce.com.cn",
|
|
522
532
|
"Pragma": "no-cache",
|
|
523
533
|
"Upgrade-Insecure-Requests": "1",
|
|
524
534
|
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) "
|
|
@@ -559,7 +569,10 @@ def get_dce_rank_table(date: str = "20230706", vars_list=cons.contract_symbols)
|
|
|
559
569
|
注: 该交易所只公布标的合约排名
|
|
560
570
|
:param date: 日期 format:YYYY-MM-DD 或 YYYYMMDD 或 datetime.date 对象, 为空时为当天
|
|
561
571
|
:param vars_list: 合约品种如 RB、AL 等列表为空时为所有商品, 数据从 20060104 开始,每交易日 16:30 左右更新数据
|
|
562
|
-
:return:
|
|
572
|
+
:return: 持仓排名
|
|
573
|
+
:rtype: pandas.DataFrame
|
|
574
|
+
|
|
575
|
+
返回值格式
|
|
563
576
|
rank 排名 int
|
|
564
577
|
vol_party_name 成交量排序的当前名次会员 string(中文)
|
|
565
578
|
vol 该会员成交量 int
|
|
@@ -642,7 +655,7 @@ def get_dce_rank_table(date: str = "20230706", vars_list=cons.contract_symbols)
|
|
|
642
655
|
].astype(float)
|
|
643
656
|
big_dict[symbol] = temp_df
|
|
644
657
|
except: # noqa: E722
|
|
645
|
-
temp_url = "http://
|
|
658
|
+
temp_url = "http://portal.dce.com.cn/publicweb/quotesdata/memberDealPosiQuotes.html"
|
|
646
659
|
payload = {
|
|
647
660
|
"memberDealPosiQuotes.variety": var.lower(),
|
|
648
661
|
"memberDealPosiQuotes.trade_type": "0",
|
|
@@ -707,7 +720,9 @@ def get_cffex_rank_table(date: str = "20190805", vars_list=cons.contract_symbols
|
|
|
707
720
|
注:该交易所既公布品种排名,也公布标的排名
|
|
708
721
|
:param date: 日期 format:YYYY-MM-DD 或 YYYYMMDD 或 datetime.date对象 为空时为当天
|
|
709
722
|
:param vars_list: 合约品种如RB、AL等列表 为空时为所有商品, 数据从20100416开始,每交易日16:30左右更新数据
|
|
710
|
-
:return:
|
|
723
|
+
:return: 持仓排名
|
|
724
|
+
:rtype: pandas.DataFrame
|
|
725
|
+
:rfield:
|
|
711
726
|
rank 排名 int
|
|
712
727
|
vol_party_name 成交量排序的当前名次会员 string(中文)
|
|
713
728
|
vol 该会员成交量 int
|
|
@@ -721,6 +736,7 @@ def get_cffex_rank_table(date: str = "20190805", vars_list=cons.contract_symbols
|
|
|
721
736
|
symbol 标的合约 string
|
|
722
737
|
var 品种 string
|
|
723
738
|
date 日期 string YYYYMMDD
|
|
739
|
+
|
|
724
740
|
"""
|
|
725
741
|
vars_list = [i for i in vars_list if i in cons.market_exchange_symbols["cffex"]]
|
|
726
742
|
date = cons.convert_date(date) if date is not None else datetime.date.today()
|
|
@@ -816,40 +832,21 @@ def futures_dce_position_rank(
|
|
|
816
832
|
if date.strftime("%Y%m%d") not in calendar:
|
|
817
833
|
warnings.warn("%s非交易日" % date.strftime("%Y%m%d"))
|
|
818
834
|
return {}
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
"Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;"
|
|
822
|
-
"q=0.8,application/signed-exchange;v=b3;q=0.9",
|
|
823
|
-
"Accept-Encoding": "gzip, deflate",
|
|
824
|
-
"Accept-Language": "zh-CN,zh;q=0.9,en;q=0.8",
|
|
825
|
-
"Cache-Control": "no-cache",
|
|
826
|
-
"Connection": "keep-alive",
|
|
827
|
-
"Content-Length": "160",
|
|
828
|
-
"Content-Type": "application/x-www-form-urlencoded",
|
|
829
|
-
"Host": "www.dce.com.cn",
|
|
830
|
-
"Origin": "http://www.dce.com.cn",
|
|
831
|
-
"Pragma": "no-cache",
|
|
832
|
-
"Referer": "http://www.dce.com.cn/publicweb/quotesdata/memberDealPosiQuotes.html",
|
|
833
|
-
"Upgrade-Insecure-Requests": "1",
|
|
834
|
-
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) "
|
|
835
|
-
"Chrome/81.0.4044.138 Safari/537.36",
|
|
836
|
-
}
|
|
835
|
+
date_str = date.strftime("%Y%m%d")
|
|
836
|
+
url = "http://www.dce.com.cn/dcereport/publicweb/dailystat/memberDealPosi/batchDownload"
|
|
837
837
|
payload = {
|
|
838
|
-
"
|
|
839
|
-
"
|
|
840
|
-
"
|
|
841
|
-
"
|
|
842
|
-
"
|
|
843
|
-
"month": date.month - 1,
|
|
844
|
-
"day": str(date.day).zfill(2),
|
|
845
|
-
"batchExportFlag": "batch",
|
|
838
|
+
"tradeDate": date_str,
|
|
839
|
+
"varietyId": "a",
|
|
840
|
+
"contractId": "a2601",
|
|
841
|
+
"tradeType": "1",
|
|
842
|
+
"lang": "zh",
|
|
846
843
|
}
|
|
847
|
-
r = requests.post(url, payload
|
|
844
|
+
r = requests.post(url, json=payload)
|
|
848
845
|
big_dict = dict()
|
|
849
846
|
with zipfile.ZipFile(BytesIO(r.content), mode="r") as z:
|
|
850
847
|
for i in z.namelist():
|
|
851
|
-
file_name = i
|
|
852
|
-
if not file_name.startswith(
|
|
848
|
+
file_name = i
|
|
849
|
+
if not file_name.startswith(date_str):
|
|
853
850
|
continue
|
|
854
851
|
try:
|
|
855
852
|
data = pd.read_table(z.open(i), header=None, sep="\t")
|
|
@@ -1171,7 +1168,7 @@ def __futures_gfex_vars_list() -> list:
|
|
|
1171
1168
|
return var_list
|
|
1172
1169
|
|
|
1173
1170
|
|
|
1174
|
-
def __futures_gfex_contract_list(symbol: str = "si", date: str = "
|
|
1171
|
+
def __futures_gfex_contract_list(symbol: str = "si", date: str = "20240729") -> list:
|
|
1175
1172
|
"""
|
|
1176
1173
|
广州期货交易所-合约具体名称列表
|
|
1177
1174
|
http://www.gfex.com.cn/gfex/rcjccpm/hqsj_tjsj.shtml
|
|
@@ -1194,6 +1191,8 @@ def __futures_gfex_contract_list(symbol: str = "si", date: str = "20231113") ->
|
|
|
1194
1191
|
r = requests.post(url=url, data=payload, headers=headers)
|
|
1195
1192
|
data_json = r.json()
|
|
1196
1193
|
temp_df = pd.DataFrame(data_json["data"])
|
|
1194
|
+
if temp_df.empty:
|
|
1195
|
+
return []
|
|
1197
1196
|
contract_list = temp_df.iloc[:, 0].tolist()
|
|
1198
1197
|
return contract_list
|
|
1199
1198
|
|
|
@@ -1317,7 +1316,7 @@ def futures_gfex_position_rank(date: str = "20231113", vars_list: list = None):
|
|
|
1317
1316
|
symbol=item.lower(), date=date
|
|
1318
1317
|
)
|
|
1319
1318
|
except: # noqa: E722
|
|
1320
|
-
return
|
|
1319
|
+
return big_dict
|
|
1321
1320
|
for name in futures_contract_list:
|
|
1322
1321
|
try:
|
|
1323
1322
|
temp_df = __futures_gfex_contract_data(
|
|
@@ -1325,20 +1324,20 @@ def futures_gfex_position_rank(date: str = "20231113", vars_list: list = None):
|
|
|
1325
1324
|
)
|
|
1326
1325
|
big_dict[name] = temp_df
|
|
1327
1326
|
except: # noqa: E722
|
|
1328
|
-
return
|
|
1327
|
+
return big_dict
|
|
1329
1328
|
return big_dict
|
|
1330
1329
|
|
|
1331
1330
|
|
|
1332
1331
|
if __name__ == "__main__":
|
|
1333
1332
|
# 郑州商品交易所
|
|
1334
|
-
|
|
1335
|
-
print(
|
|
1333
|
+
get_rank_table_czce_df = get_rank_table_czce(date="20230109")
|
|
1334
|
+
print(get_rank_table_czce_df)
|
|
1336
1335
|
|
|
1337
|
-
|
|
1338
|
-
print(
|
|
1336
|
+
get_rank_table_czce_df = get_rank_table_czce(date="20201026")
|
|
1337
|
+
print(get_rank_table_czce_df)
|
|
1339
1338
|
|
|
1340
1339
|
# 中国金融期货交易所
|
|
1341
|
-
get_cffex_rank_table_df = get_cffex_rank_table(date="
|
|
1340
|
+
get_cffex_rank_table_df = get_cffex_rank_table(date="20250721")
|
|
1342
1341
|
print(get_cffex_rank_table_df)
|
|
1343
1342
|
|
|
1344
1343
|
# 上海期货交易所
|
|
@@ -1371,12 +1370,12 @@ if __name__ == "__main__":
|
|
|
1371
1370
|
print(futures_dce_position_rank_other_df)
|
|
1372
1371
|
|
|
1373
1372
|
# 广州期货交易所
|
|
1374
|
-
futures_gfex_position_rank_df = futures_gfex_position_rank(date="
|
|
1373
|
+
futures_gfex_position_rank_df = futures_gfex_position_rank(date="20250718")
|
|
1375
1374
|
print(futures_gfex_position_rank_df)
|
|
1376
1375
|
|
|
1377
1376
|
# 总接口
|
|
1378
1377
|
get_rank_sum_daily_df = get_rank_sum_daily(
|
|
1379
|
-
start_day="
|
|
1380
|
-
end_day="
|
|
1378
|
+
start_day="20251031",
|
|
1379
|
+
end_day="20251103",
|
|
1381
1380
|
)
|
|
1382
1381
|
print(get_rank_sum_daily_df)
|
akshare/futures/futures_basis.py
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env python
|
|
2
2
|
# -*- coding:utf-8 -*-
|
|
3
3
|
"""
|
|
4
|
-
Date: 2024/
|
|
4
|
+
Date: 2024/12/12 17:00
|
|
5
5
|
Desc: 生意社网站采集大宗商品现货价格及相应基差数据, 数据时间段从 20110104-至今
|
|
6
6
|
备注:现期差 = 现货价格 - 期货价格(这里的期货价格为结算价)
|
|
7
7
|
黄金为 元/克, 白银为 元/千克, 玻璃现货为 元/平方米, 鸡蛋现货为 元/公斤, 鸡蛋期货为 元/500千克, 其余为 元/吨.
|
|
@@ -39,7 +39,8 @@ def futures_spot_price_daily(
|
|
|
39
39
|
:param start_day: str 开始日期 format:YYYY-MM-DD 或 YYYYMMDD 或 datetime.date对象; 默认为当天
|
|
40
40
|
:param end_day: str 结束数据 format:YYYY-MM-DD 或 YYYYMMDD 或 datetime.date对象; 默认为当天
|
|
41
41
|
:param vars_list: list 合约品种如 [RB, AL]; 默认参数为所有商品
|
|
42
|
-
:return:
|
|
42
|
+
:return: 基差
|
|
43
|
+
:rtype: pandas.DataFrame
|
|
43
44
|
展期收益率数据:
|
|
44
45
|
var 商品品种 string
|
|
45
46
|
sp 现货价格 float
|
|
@@ -124,9 +125,9 @@ def futures_spot_price(
|
|
|
124
125
|
return temp_df
|
|
125
126
|
else:
|
|
126
127
|
time.sleep(3)
|
|
127
|
-
except: # noqa: E722
|
|
128
|
+
except Exception as e: # noqa: E722
|
|
128
129
|
print(
|
|
129
|
-
f"{date.strftime('%Y-%m-%d')}
|
|
130
|
+
f"{date.strftime('%Y-%m-%d')}日生意社数据连接失败[错误信息:{e}],第{str(i)}次尝试,最多5次"
|
|
130
131
|
)
|
|
131
132
|
i += 1
|
|
132
133
|
if i > 5:
|
|
@@ -169,10 +170,17 @@ def _check_information(df_data, date):
|
|
|
169
170
|
]
|
|
170
171
|
records = pd.DataFrame()
|
|
171
172
|
for string in df_data["symbol"].tolist():
|
|
173
|
+
news = "".join(re.findall(r"[\u4e00-\u9fa5]", string))
|
|
174
|
+
if news == "":
|
|
175
|
+
news = string.strip()
|
|
176
|
+
|
|
177
|
+
"""
|
|
172
178
|
if string == "PTA":
|
|
173
179
|
news = "PTA"
|
|
174
180
|
else:
|
|
175
181
|
news = "".join(re.findall(r"[\u4e00-\u9fa5]", string))
|
|
182
|
+
"""
|
|
183
|
+
|
|
176
184
|
if news != "" and news not in [
|
|
177
185
|
"商品",
|
|
178
186
|
"价格",
|
|
@@ -180,6 +188,8 @@ def _check_information(df_data, date):
|
|
|
180
188
|
"郑州商品交易所",
|
|
181
189
|
"大连商品交易所",
|
|
182
190
|
"广州期货交易所",
|
|
191
|
+
# 某些天网站没有数据,比如 20180912,此时返回"暂无数据",但并不是网站被墙了
|
|
192
|
+
"暂无数据",
|
|
183
193
|
]:
|
|
184
194
|
symbol = chinese_to_english(news)
|
|
185
195
|
record = pd.DataFrame(df_data[df_data["symbol"] == string])
|
|
@@ -193,8 +203,22 @@ def _check_information(df_data, date):
|
|
|
193
203
|
symbol == "FG"
|
|
194
204
|
): # 上表中现货单位为元/平方米, 期货单位为元/吨. 换算公式:元/平方米*80=元/吨(http://www.100ppi.com/sf/959.html)
|
|
195
205
|
record.loc[:, "spot_price"] = float(record["spot_price"].iloc[0]) * 80
|
|
206
|
+
elif (
|
|
207
|
+
symbol == "LH"
|
|
208
|
+
): # 上表中现货单位为元/公斤, 期货单位为元/吨. 换算公式:元/公斤*1000=元/吨(http://www.100ppi.com/sf/959.html)
|
|
209
|
+
record.loc[:, "spot_price"] = float(record["spot_price"].iloc[0]) * 1000
|
|
196
210
|
records = pd.concat([records, record])
|
|
197
211
|
|
|
212
|
+
# 20241129:如果某日没有数据,直接返回返回空表
|
|
213
|
+
if records.empty:
|
|
214
|
+
records = df_data.iloc[0:0]
|
|
215
|
+
records["near_basis"] = pd.Series(dtype="float")
|
|
216
|
+
records["dom_basis"] = pd.Series(dtype="float")
|
|
217
|
+
records["near_basis_rate"] = pd.Series(dtype="float")
|
|
218
|
+
records["dom_basis_rate"] = pd.Series(dtype="float")
|
|
219
|
+
records["date"] = pd.Series(dtype="object")
|
|
220
|
+
return records
|
|
221
|
+
|
|
198
222
|
records.loc[:, ["near_contract_price", "dominant_contract_price", "spot_price"]] = (
|
|
199
223
|
records.loc[
|
|
200
224
|
:, ["near_contract_price", "dominant_contract_price", "spot_price"]
|
|
@@ -208,9 +232,11 @@ def _check_information(df_data, date):
|
|
|
208
232
|
r"[^0-9]*(\d*)$", r"\g<1>", regex=True
|
|
209
233
|
)
|
|
210
234
|
|
|
235
|
+
records.loc[:, "near_month"] = records.loc[:, "near_contract"]
|
|
211
236
|
records.loc[:, "near_contract"] = records["symbol"] + records.loc[
|
|
212
237
|
:, "near_contract"
|
|
213
238
|
].astype("int").astype("str")
|
|
239
|
+
records.loc[:, "dominant_month"] = records.loc[:, "dominant_contract"]
|
|
214
240
|
records.loc[:, "dominant_contract"] = records["symbol"] + records.loc[
|
|
215
241
|
:, "dominant_contract"
|
|
216
242
|
].astype("int").astype("str")
|
|
@@ -246,7 +272,8 @@ def _check_information(df_data, date):
|
|
|
246
272
|
records["dom_basis_rate"] = (
|
|
247
273
|
records["dominant_contract_price"] / records["spot_price"] - 1
|
|
248
274
|
)
|
|
249
|
-
records.loc[:, "date"] = date.strftime("%Y%m%d")
|
|
275
|
+
# records.loc[:, "date"] = date.strftime("%Y%m%d")
|
|
276
|
+
records.insert(0, "date", date.strftime("%Y%m%d"))
|
|
250
277
|
return records
|
|
251
278
|
|
|
252
279
|
|
|
@@ -287,22 +314,33 @@ def futures_spot_price_previous(date: str = "20240430") -> pd.DataFrame:
|
|
|
287
314
|
values = main[main[4].str.endswith("%")]
|
|
288
315
|
values.columns = header
|
|
289
316
|
# Basis
|
|
290
|
-
|
|
317
|
+
# 对于没有数据的天,xml文件中没有数据,所以content[2:-1]可能为空
|
|
318
|
+
if len(content[2:-1]) > 0:
|
|
319
|
+
basis = pd.concat(content[2:-1])
|
|
320
|
+
else:
|
|
321
|
+
basis = pd.DataFrame(columns=["主力合约基差", "主力合约基差(%)"])
|
|
322
|
+
|
|
291
323
|
basis.columns = ["主力合约基差", "主力合约基差(%)"]
|
|
292
|
-
|
|
324
|
+
# 20241125(jasonudu):因为部分日期,存在多个品种的现货价格,比如20151125的白糖、豆粕、豆油等,如果用商品名来merge,会出现重复列名,所以改用index来merge
|
|
325
|
+
# basis["商品"] = values["商品"].tolist()
|
|
326
|
+
basis.index = values.index
|
|
293
327
|
basis = pd.merge(
|
|
294
|
-
values[["商品", "现货价格", "主力合约代码", "主力合约价格"]],
|
|
328
|
+
values[["商品", "现货价格", "主力合约代码", "主力合约价格"]],
|
|
329
|
+
basis,
|
|
330
|
+
left_index=True,
|
|
331
|
+
right_index=True,
|
|
295
332
|
)
|
|
296
333
|
basis = pd.merge(
|
|
297
334
|
basis,
|
|
298
335
|
values[
|
|
299
336
|
[
|
|
300
|
-
"商品",
|
|
301
337
|
"180日内主力基差最高",
|
|
302
338
|
"180日内主力基差最低",
|
|
303
339
|
"180日内主力基差平均",
|
|
304
340
|
]
|
|
305
341
|
],
|
|
342
|
+
left_index=True,
|
|
343
|
+
right_index=True,
|
|
306
344
|
)
|
|
307
345
|
basis.columns = [
|
|
308
346
|
"商品",
|
|
@@ -321,11 +359,11 @@ def futures_spot_price_previous(date: str = "20240430") -> pd.DataFrame:
|
|
|
321
359
|
|
|
322
360
|
if __name__ == "__main__":
|
|
323
361
|
futures_spot_price_daily_df = futures_spot_price_daily(
|
|
324
|
-
start_day="
|
|
362
|
+
start_day="20250708", end_day="20250709", vars_list=["BZ", "RB"]
|
|
325
363
|
)
|
|
326
364
|
print(futures_spot_price_daily_df)
|
|
327
365
|
|
|
328
|
-
futures_spot_price_df = futures_spot_price(date="
|
|
366
|
+
futures_spot_price_df = futures_spot_price(date="20250620")
|
|
329
367
|
print(futures_spot_price_df)
|
|
330
368
|
|
|
331
369
|
futures_spot_price_previous_df = futures_spot_price_previous(date="20240430")
|
|
@@ -23,7 +23,7 @@ def futures_fees_info() -> pd.DataFrame:
|
|
|
23
23
|
"""
|
|
24
24
|
url = "http://openctp.cn/fees.html"
|
|
25
25
|
r = requests.get(url)
|
|
26
|
-
r.encoding = "
|
|
26
|
+
r.encoding = "utf-8"
|
|
27
27
|
soup = BeautifulSoup(r.text, features="lxml")
|
|
28
28
|
datetime_str = soup.find("p").string.strip("Generated at ").strip(".")
|
|
29
29
|
datetime_raw = datetime.strptime(datetime_str, "%Y-%m-%d %H:%M:%S")
|
|
@@ -1,17 +1,19 @@
|
|
|
1
1
|
#!/usr/bin/env python
|
|
2
2
|
# -*- coding:utf-8 -*-
|
|
3
3
|
"""
|
|
4
|
-
Date:
|
|
4
|
+
Date: 2025/10/30 17:00
|
|
5
5
|
Desc: 查询期货合约当前时刻的详情
|
|
6
6
|
https://finance.sina.com.cn/futures/quotes/V2101.shtml
|
|
7
7
|
"""
|
|
8
|
+
|
|
8
9
|
from io import StringIO
|
|
9
10
|
|
|
10
11
|
import pandas as pd
|
|
11
12
|
import requests
|
|
13
|
+
from bs4 import BeautifulSoup
|
|
12
14
|
|
|
13
15
|
|
|
14
|
-
def futures_contract_detail(symbol: str =
|
|
16
|
+
def futures_contract_detail(symbol: str = "AP2101") -> pd.DataFrame:
|
|
15
17
|
"""
|
|
16
18
|
查询期货合约详情
|
|
17
19
|
https://finance.sina.com.cn/futures/quotes/V2101.shtml
|
|
@@ -22,18 +24,66 @@ def futures_contract_detail(symbol: str = 'AP2101') -> pd.DataFrame:
|
|
|
22
24
|
"""
|
|
23
25
|
url = f"https://finance.sina.com.cn/futures/quotes/{symbol}.shtml"
|
|
24
26
|
r = requests.get(url)
|
|
25
|
-
r.encoding =
|
|
27
|
+
r.encoding = "gb2312"
|
|
26
28
|
temp_df = pd.read_html(StringIO(r.text))[6]
|
|
27
29
|
data_one = temp_df.iloc[:, :2]
|
|
28
|
-
data_one.columns = [
|
|
30
|
+
data_one.columns = ["item", "value"]
|
|
29
31
|
data_two = temp_df.iloc[:, 2:4]
|
|
30
|
-
data_two.columns = [
|
|
32
|
+
data_two.columns = ["item", "value"]
|
|
31
33
|
data_three = temp_df.iloc[:, 4:]
|
|
32
|
-
data_three.columns = [
|
|
33
|
-
temp_df = pd.concat(
|
|
34
|
+
data_three.columns = ["item", "value"]
|
|
35
|
+
temp_df = pd.concat(
|
|
36
|
+
objs=[data_one, data_two, data_three], axis=0, ignore_index=True
|
|
37
|
+
)
|
|
38
|
+
return temp_df
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
def futures_contract_detail_em(symbol: str = "v2602F") -> pd.DataFrame:
|
|
42
|
+
"""
|
|
43
|
+
查询期货合约详情
|
|
44
|
+
https://quote.eastmoney.com/qihuo/v2602F.html
|
|
45
|
+
:param symbol: 合约
|
|
46
|
+
:type symbol: str
|
|
47
|
+
:return: 期货合约详情
|
|
48
|
+
:rtype: pandas.DataFrame
|
|
49
|
+
"""
|
|
50
|
+
url = f"https://quote.eastmoney.com/qihuo/{symbol}.html"
|
|
51
|
+
r = requests.get(url)
|
|
52
|
+
soup = BeautifulSoup(r.text, features="lxml")
|
|
53
|
+
url_text = \
|
|
54
|
+
soup.find(name="div", attrs={"class": "sidertabbox_tsplit"}).find(name="div", attrs={"class": "onet"}).find(
|
|
55
|
+
"a")[
|
|
56
|
+
'href']
|
|
57
|
+
inner_symbol = url_text.split("#")[-1].strip("futures_")
|
|
58
|
+
url = f"https://futsse-static.eastmoney.com/redis?msgid={inner_symbol}_info"
|
|
59
|
+
r = requests.get(url)
|
|
60
|
+
data_json = r.json()
|
|
61
|
+
temp_df = pd.DataFrame.from_dict(data_json, orient="index")
|
|
62
|
+
column_mapping = {
|
|
63
|
+
'vname': '交易品种',
|
|
64
|
+
'vcode': '交易代码',
|
|
65
|
+
'jydw': '交易单位',
|
|
66
|
+
'bjdw': '报价单位',
|
|
67
|
+
'market': '上市交易所',
|
|
68
|
+
'zxbddw': '最小变动价格',
|
|
69
|
+
'zdtbfd': '跌涨停板幅度',
|
|
70
|
+
'hyjgyf': '合约交割月份',
|
|
71
|
+
'jysj': '交易时间',
|
|
72
|
+
'zhjyr': '最后交易日',
|
|
73
|
+
'zhjgr': '最后交割日',
|
|
74
|
+
'jgpj': '交割品级',
|
|
75
|
+
'zcjybzj': '最初交易保证金',
|
|
76
|
+
'jgfs': '交割方式'
|
|
77
|
+
}
|
|
78
|
+
temp_df.rename(index=column_mapping, inplace=True)
|
|
79
|
+
temp_df.reset_index(drop=False, inplace=True)
|
|
80
|
+
temp_df.columns = ['item', 'value']
|
|
34
81
|
return temp_df
|
|
35
82
|
|
|
36
83
|
|
|
37
|
-
if __name__ ==
|
|
38
|
-
futures_contract_detail_df = futures_contract_detail(symbol=
|
|
84
|
+
if __name__ == "__main__":
|
|
85
|
+
futures_contract_detail_df = futures_contract_detail(symbol="V2101")
|
|
39
86
|
print(futures_contract_detail_df)
|
|
87
|
+
|
|
88
|
+
futures_contract_detail_em_df = futures_contract_detail_em(symbol="l2602F")
|
|
89
|
+
print(futures_contract_detail_em_df)
|