akshare 1.13.46__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 +757 -161
- akshare/air/air_hebei.py +79 -53
- akshare/air/air_zhenqi.py +3 -7
- akshare/air/cons.py +1 -0
- akshare/air/crypto.js +1 -1
- akshare/air/outcrypto.js +1 -1
- akshare/air/sunrise_tad.py +32 -17
- 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 +75 -48
- akshare/bond/bond_convert.py +10 -9
- akshare/bond/bond_em.py +37 -17
- akshare/bond/bond_info_cm.py +28 -8
- akshare/bond/bond_issue_cninfo.py +73 -30
- akshare/bond/bond_summary.py +38 -37
- akshare/bond/bond_zh_cov.py +31 -40
- akshare/bond/bond_zh_sina.py +61 -51
- 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/currency/currency_safe.py +7 -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 +163 -117
- akshare/economic/macro_china_hk.py +0 -1
- akshare/economic/macro_china_nbs.py +24 -7
- akshare/economic/macro_euro.py +103 -56
- akshare/economic/macro_finance_ths.py +135 -0
- akshare/economic/macro_germany.py +1 -1
- akshare/economic/macro_info_ws.py +100 -0
- 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 +94 -126
- akshare/energy/energy_oil_em.py +1 -2
- akshare/event/cons.py +1 -0
- akshare/event/migration.py +3 -2
- 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 +15 -48
- 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_amac.py +38 -15
- 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 +76 -27
- akshare/fund/fund_etf_ths.py +95 -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 +78 -66
- akshare/fund/fund_position_lg.py +19 -8
- akshare/fund/fund_rank_em.py +90 -84
- akshare/fund/fund_rating.py +33 -12
- akshare/fund/fund_report_cninfo.py +63 -48
- 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 +141 -46
- akshare/futures/cot.py +89 -88
- akshare/futures/futures_basis.py +99 -33
- akshare/futures/futures_comex_em.py +1 -0
- akshare/futures/futures_comm_ctp.py +13 -2
- akshare/futures/futures_contract_detail.py +59 -9
- akshare/futures/futures_daily_bar.py +75 -62
- 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 +79 -61
- 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 +1 -2
- akshare/futures/futures_to_spot.py +43 -39
- akshare/futures/futures_warehouse_receipt.py +53 -48
- akshare/futures/futures_zh_sina.py +4 -4
- 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 +7 -8
- akshare/futures_derivative/futures_cot_sina.py +28 -19
- akshare/futures_derivative/futures_index_sina.py +25 -13
- akshare/fx/cons.py +12 -7
- akshare/fx/currency_investing.py +19 -285
- 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_cflp.py +29 -26
- akshare/index/index_cni.py +89 -91
- akshare/index/index_cons.py +26 -10
- akshare/index/index_csindex.py +68 -0
- akshare/index/index_cx.py +263 -62
- 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 +38 -38
- akshare/index/index_spot.py +9 -5
- akshare/index/index_stock_hk.py +6 -10
- akshare/index/index_stock_us_sina.py +1 -1
- akshare/index/index_stock_zh.py +193 -101
- akshare/index/index_stock_zh_csindex.py +15 -369
- akshare/index/index_sugar.py +18 -4
- akshare/index/index_sw.py +62 -34
- akshare/index/index_yw.py +53 -75
- akshare/index/index_zh_em.py +15 -82
- akshare/interest_rate/interbank_rate_em.py +14 -10
- akshare/movie/artist_yien.py +32 -5
- akshare/movie/jm.js +0 -1
- akshare/movie/movie_yien.py +92 -18
- akshare/movie/video_yien.py +28 -5
- akshare/news/__init__.py +1 -1
- akshare/news/news_baidu.py +395 -220
- akshare/news/news_cctv.py +38 -38
- akshare/news/news_stock.py +49 -13
- akshare/nlp/nlp_interface.py +7 -8
- akshare/option/cons.py +12 -12
- akshare/option/option_comm_qihuo.py +86 -0
- akshare/option/option_commodity.py +355 -211
- 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 +145 -0
- akshare/option/option_em.py +4 -8
- akshare/option/option_finance.py +60 -12
- akshare/option/option_finance_sina.py +28 -26
- akshare/option/option_lhb_em.py +62 -57
- 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 +18 -16
- akshare/option/option_value_analysis_em.py +62 -55
- akshare/other/__init__.py +1 -1
- akshare/other/other_car_cpca.py +20 -20
- 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 +232 -0
- akshare/spot/spot_price_qh.py +121 -0
- akshare/spot/spot_sge.py +70 -9
- akshare/stock/cons.py +60 -23
- akshare/stock/stock_allotment_cninfo.py +10 -9
- 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_cg_equity_mortgage.py +15 -11
- akshare/stock/stock_cg_guarantee.py +41 -51
- akshare/stock/stock_cg_lawsuit.py +36 -35
- akshare/stock/stock_dividend_cninfo.py +36 -16
- akshare/stock/stock_dzjy_em.py +347 -260
- akshare/stock/stock_fund_em.py +73 -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 +107 -0
- 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 +91 -42
- akshare/stock/stock_hold_control_cninfo.py +100 -15
- akshare/stock/stock_hold_control_em.py +4 -5
- akshare/stock/stock_hold_num_cninfo.py +18 -12
- 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 +25 -20
- akshare/stock/stock_industry_pe_cninfo.py +45 -31
- akshare/stock/stock_industry_sw.py +5 -9
- akshare/stock/stock_info.py +31 -19
- akshare/stock/stock_info_em.py +17 -11
- akshare/stock/stock_intraday_em.py +9 -80
- akshare/stock/stock_intraday_sina.py +2 -2
- akshare/stock/stock_ipo_summary_cninfo.py +25 -10
- akshare/stock/stock_new_cninfo.py +32 -19
- akshare/stock/stock_news_cx.py +39 -0
- akshare/stock/stock_profile_cninfo.py +9 -8
- akshare/stock/stock_profile_em.py +302 -0
- akshare/stock/stock_rank_forecast.py +8 -6
- akshare/stock/stock_repurchase_em.py +7 -2
- akshare/stock/stock_share_changes_cninfo.py +18 -14
- 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 +19 -11
- akshare/stock/stock_us_js.py +3 -2
- akshare/stock/stock_us_pink.py +38 -27
- akshare/stock/stock_us_sina.py +15 -12
- akshare/stock/stock_weibo_nlp.py +18 -20
- akshare/stock/stock_xq.py +36 -9
- akshare/stock/stock_zh_a_sina.py +58 -80
- 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 +32 -55
- akshare/stock/stock_zh_comparison_em.py +250 -0
- akshare/stock/stock_zh_kcb_report.py +11 -9
- 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_below_net_asset_statistics.py +5 -2
- akshare/stock_feature/stock_a_high_low.py +5 -2
- akshare/stock_feature/stock_a_indicator.py +15 -57
- akshare/stock_feature/stock_a_pe_and_pb.py +39 -9
- 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 +144 -252
- akshare/stock_feature/stock_board_industry_ths.py +137 -401
- 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_concept_futu.py +183 -0
- 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 +20 -10
- 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 +33 -15
- akshare/stock_feature/stock_fhps_em.py +62 -26
- akshare/stock_feature/stock_fhps_ths.py +34 -7
- akshare/stock_feature/stock_fund_flow.py +38 -25
- 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 +158 -237
- 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 +8 -81
- akshare/stock_feature/stock_inner_trade_xq.py +38 -31
- akshare/stock_feature/stock_irm_cninfo.py +32 -9
- akshare/stock_feature/stock_jgdy_em.py +43 -40
- akshare/stock_feature/stock_lh_yybpm.py +36 -37
- akshare/stock_feature/stock_lhb_em.py +165 -35
- akshare/stock_feature/stock_lhb_sina.py +93 -46
- akshare/stock_feature/stock_margin_em.py +101 -0
- akshare/stock_feature/{stock_sse_margin.py → stock_margin_sse.py} +21 -17
- akshare/stock_feature/{stock_szse_margin.py → stock_margin_szse.py} +7 -7
- akshare/stock_feature/stock_market_legu.py +4 -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 +152 -8
- akshare/stock_feature/stock_research_report_em.py +55 -20
- akshare/stock_feature/stock_sns_sseinfo.py +15 -12
- akshare/stock_feature/stock_sy_em.py +20 -15
- akshare/stock_feature/stock_technology_ths.py +152 -120
- akshare/stock_feature/stock_tfp_em.py +37 -14
- akshare/stock_feature/stock_three_report_em.py +120 -78
- 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_valuation_baidu.py +3 -2
- 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} +203 -59
- 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 +41 -18
- 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_register_em.py +448 -0
- akshare/stock_fundamental/stock_zygc.py +5 -62
- akshare/tool/trade_date_hist.py +1 -1
- 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/utils/tqdm.py +13 -3
- {akshare-1.13.46.dist-info → akshare-1.17.99.dist-info}/METADATA +56 -86
- akshare-1.17.99.dist-info/RECORD +409 -0
- {akshare-1.13.46.dist-info → akshare-1.17.99.dist-info}/WHEEL +1 -1
- {akshare-1.13.46.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/fortune/fortune_it_juzi.py +0 -123
- 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 -51
- 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/sport/sport_olympic_winter.py +0 -39
- akshare/stock_feature/stock_wencai.py +0 -104
- akshare/stock_fundamental/stock_mda_ym.py +0 -40
- akshare/stock_fundamental/stock_register.py +0 -292
- akshare-1.13.46.dist-info/RECORD +0 -380
- {akshare-1.13.46.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)
|
|
@@ -276,7 +278,7 @@ def get_shfe_rank_table(
|
|
|
276
278
|
"""
|
|
277
279
|
上海期货交易所会员成交及持仓排名表
|
|
278
280
|
https://www.shfe.com.cn/
|
|
279
|
-
https://
|
|
281
|
+
https://tsite.shfe.com.cn/statements/dataview.html?paramid=kx
|
|
280
282
|
注:该交易所只公布每个品种内部的标的排名,没有公布品种的总排名
|
|
281
283
|
数据从 20020107 开始,每交易日 16:30 左右更新数据
|
|
282
284
|
:param date: 交易日
|
|
@@ -300,14 +302,14 @@ def get_shfe_rank_table(
|
|
|
300
302
|
date 日期 string YYYYMMDD
|
|
301
303
|
"""
|
|
302
304
|
date = cons.convert_date(date) if date is not None else datetime.date.today()
|
|
303
|
-
if date < datetime.date(2002, 1, 7):
|
|
304
|
-
print("shfe数据源开始日期为20020107,跳过")
|
|
305
|
+
if date < datetime.date(year=2002, month=1, day=7):
|
|
306
|
+
print("shfe数据源开始日期为 20020107,跳过")
|
|
305
307
|
return {}
|
|
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.
|
|
310
|
-
r = requests_link(url, "utf-8", headers=cons.shfe_headers)
|
|
311
|
+
url = cons.SHFE_VOL_RANK_URL_20250701 % (date.strftime("%Y%m%d"))
|
|
312
|
+
r = requests_link(url, encoding="utf-8", headers=cons.shfe_headers)
|
|
311
313
|
try:
|
|
312
314
|
context = json.loads(r.text)
|
|
313
315
|
except: # noqa: E722
|
|
@@ -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,43 +832,26 @@ 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
|
-
with zipfile.ZipFile(BytesIO(r.content), "r") as z:
|
|
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
|
-
data = pd.read_table(z.open(i), header=None, sep="\t")
|
|
852
|
+
data = pd.read_table(z.open(i), header=None, sep="\t")
|
|
853
|
+
if sum(data.iloc[:, 0].str.find("会员类别") == 0) > 0:
|
|
854
|
+
data = data.iloc[:-6]
|
|
856
855
|
if len(data) < 12: # 处理没有活跃合约的情况
|
|
857
856
|
big_dict[file_name.split("_")[1]] = pd.DataFrame()
|
|
858
857
|
continue
|
|
@@ -869,12 +868,14 @@ def futures_dce_position_rank(
|
|
|
869
868
|
]
|
|
870
869
|
data.reset_index(inplace=True, drop=True)
|
|
871
870
|
start_list = data[data.iloc[:, 0].str.find("名次") == 0].index.tolist()
|
|
872
|
-
end_list = data[
|
|
871
|
+
end_list = data[
|
|
872
|
+
data.iloc[:, 0].str.contains(r"(?:总计|合计)", na=False)
|
|
873
|
+
].index.tolist()
|
|
873
874
|
part_one = data[start_list[0] : end_list[0]].iloc[1:, :]
|
|
874
875
|
part_two = data[start_list[1] : end_list[1]].iloc[1:, :]
|
|
875
876
|
part_three = data[start_list[2] : end_list[2]].iloc[1:, :]
|
|
876
877
|
temp_df = pd.concat(
|
|
877
|
-
[
|
|
878
|
+
objs=[
|
|
878
879
|
part_one.reset_index(drop=True),
|
|
879
880
|
part_two.reset_index(drop=True),
|
|
880
881
|
part_three.reset_index(drop=True),
|
|
@@ -1073,7 +1074,7 @@ def futures_dce_position_rank_other(date: str = "20160104"):
|
|
|
1073
1074
|
"contract": "",
|
|
1074
1075
|
}
|
|
1075
1076
|
r = requests.post(url, data=payload)
|
|
1076
|
-
soup = BeautifulSoup(r.text, "lxml")
|
|
1077
|
+
soup = BeautifulSoup(r.text, features="lxml")
|
|
1077
1078
|
symbol_list = [
|
|
1078
1079
|
item["onclick"].strip("javascript:setVariety(").strip("');")
|
|
1079
1080
|
for item in soup.find_all(attrs={"class": "selBox"})[-3].find_all("input")
|
|
@@ -1091,7 +1092,7 @@ def futures_dce_position_rank_other(date: str = "20160104"):
|
|
|
1091
1092
|
"contract": "",
|
|
1092
1093
|
}
|
|
1093
1094
|
r = requests.post(url, data=payload)
|
|
1094
|
-
soup = BeautifulSoup(r.text, "lxml")
|
|
1095
|
+
soup = BeautifulSoup(r.text, features="lxml")
|
|
1095
1096
|
contract_list = [
|
|
1096
1097
|
item["onclick"].strip("javascript:setContract_id('").strip("');")
|
|
1097
1098
|
for item in soup.find_all(attrs={"name": "contract"})
|
|
@@ -1167,7 +1168,7 @@ def __futures_gfex_vars_list() -> list:
|
|
|
1167
1168
|
return var_list
|
|
1168
1169
|
|
|
1169
1170
|
|
|
1170
|
-
def __futures_gfex_contract_list(symbol: str = "si", date: str = "
|
|
1171
|
+
def __futures_gfex_contract_list(symbol: str = "si", date: str = "20240729") -> list:
|
|
1171
1172
|
"""
|
|
1172
1173
|
广州期货交易所-合约具体名称列表
|
|
1173
1174
|
http://www.gfex.com.cn/gfex/rcjccpm/hqsj_tjsj.shtml
|
|
@@ -1190,6 +1191,8 @@ def __futures_gfex_contract_list(symbol: str = "si", date: str = "20231113") ->
|
|
|
1190
1191
|
r = requests.post(url=url, data=payload, headers=headers)
|
|
1191
1192
|
data_json = r.json()
|
|
1192
1193
|
temp_df = pd.DataFrame(data_json["data"])
|
|
1194
|
+
if temp_df.empty:
|
|
1195
|
+
return []
|
|
1193
1196
|
contract_list = temp_df.iloc[:, 0].tolist()
|
|
1194
1197
|
return contract_list
|
|
1195
1198
|
|
|
@@ -1313,7 +1316,7 @@ def futures_gfex_position_rank(date: str = "20231113", vars_list: list = None):
|
|
|
1313
1316
|
symbol=item.lower(), date=date
|
|
1314
1317
|
)
|
|
1315
1318
|
except: # noqa: E722
|
|
1316
|
-
return
|
|
1319
|
+
return big_dict
|
|
1317
1320
|
for name in futures_contract_list:
|
|
1318
1321
|
try:
|
|
1319
1322
|
temp_df = __futures_gfex_contract_data(
|
|
@@ -1321,60 +1324,58 @@ def futures_gfex_position_rank(date: str = "20231113", vars_list: list = None):
|
|
|
1321
1324
|
)
|
|
1322
1325
|
big_dict[name] = temp_df
|
|
1323
1326
|
except: # noqa: E722
|
|
1324
|
-
return
|
|
1327
|
+
return big_dict
|
|
1325
1328
|
return big_dict
|
|
1326
1329
|
|
|
1327
1330
|
|
|
1328
1331
|
if __name__ == "__main__":
|
|
1329
1332
|
# 郑州商品交易所
|
|
1330
|
-
|
|
1331
|
-
print(
|
|
1333
|
+
get_rank_table_czce_df = get_rank_table_czce(date="20230109")
|
|
1334
|
+
print(get_rank_table_czce_df)
|
|
1332
1335
|
|
|
1333
|
-
|
|
1334
|
-
print(
|
|
1336
|
+
get_rank_table_czce_df = get_rank_table_czce(date="20201026")
|
|
1337
|
+
print(get_rank_table_czce_df)
|
|
1335
1338
|
|
|
1336
1339
|
# 中国金融期货交易所
|
|
1337
|
-
get_cffex_rank_table_df = get_cffex_rank_table(date="
|
|
1340
|
+
get_cffex_rank_table_df = get_cffex_rank_table(date="20250721")
|
|
1338
1341
|
print(get_cffex_rank_table_df)
|
|
1339
1342
|
|
|
1340
1343
|
# 上海期货交易所
|
|
1341
|
-
get_shfe_rank_table_df = get_shfe_rank_table(date="
|
|
1344
|
+
get_shfe_rank_table_df = get_shfe_rank_table(date="20240509")
|
|
1342
1345
|
print(get_shfe_rank_table_df)
|
|
1343
1346
|
|
|
1344
1347
|
# 大连商品交易所-老接口
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
|
|
1348
|
-
|
|
1349
|
-
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
|
-
|
|
1353
|
-
|
|
1354
|
-
|
|
1355
|
-
|
|
1356
|
-
|
|
1357
|
-
|
|
1358
|
-
|
|
1359
|
-
# )
|
|
1360
|
-
# print(get_dce_rank_table_fourth_df)
|
|
1348
|
+
get_dce_rank_table_first_df = get_dce_rank_table(date="20131227")
|
|
1349
|
+
print(get_dce_rank_table_first_df)
|
|
1350
|
+
|
|
1351
|
+
get_dce_rank_table_second_df = get_dce_rank_table(date="20171227")
|
|
1352
|
+
print(get_dce_rank_table_second_df)
|
|
1353
|
+
|
|
1354
|
+
get_dce_rank_table_third_df = get_dce_rank_table(date="20200929")
|
|
1355
|
+
print(get_dce_rank_table_third_df)
|
|
1356
|
+
|
|
1357
|
+
get_dce_rank_table_third_df = get_dce_rank_table(date="20230706")
|
|
1358
|
+
print(get_dce_rank_table_third_df)
|
|
1359
|
+
|
|
1360
|
+
get_dce_rank_table_fourth_df = get_dce_rank_table(date="20210517", vars_list=["V"])
|
|
1361
|
+
print(get_dce_rank_table_fourth_df)
|
|
1361
1362
|
|
|
1362
1363
|
# 大连商品交易所-新接口
|
|
1363
|
-
futures_dce_detail_dict = futures_dce_position_rank(date="
|
|
1364
|
+
futures_dce_detail_dict = futures_dce_position_rank(date="20240517")
|
|
1364
1365
|
print(futures_dce_detail_dict)
|
|
1365
1366
|
|
|
1366
|
-
|
|
1367
|
-
|
|
1368
|
-
|
|
1369
|
-
|
|
1367
|
+
futures_dce_position_rank_other_df = futures_dce_position_rank_other(
|
|
1368
|
+
date="20200727"
|
|
1369
|
+
)
|
|
1370
|
+
print(futures_dce_position_rank_other_df)
|
|
1370
1371
|
|
|
1371
1372
|
# 广州期货交易所
|
|
1372
|
-
futures_gfex_position_rank_df = futures_gfex_position_rank(date="
|
|
1373
|
+
futures_gfex_position_rank_df = futures_gfex_position_rank(date="20250718")
|
|
1373
1374
|
print(futures_gfex_position_rank_df)
|
|
1374
1375
|
|
|
1375
1376
|
# 总接口
|
|
1376
1377
|
get_rank_sum_daily_df = get_rank_sum_daily(
|
|
1377
|
-
start_day="
|
|
1378
|
-
end_day="
|
|
1378
|
+
start_day="20251031",
|
|
1379
|
+
end_day="20251103",
|
|
1379
1380
|
)
|
|
1380
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:
|
|
4
|
+
Date: 2024/12/12 17:00
|
|
5
5
|
Desc: 生意社网站采集大宗商品现货价格及相应基差数据, 数据时间段从 20110104-至今
|
|
6
6
|
备注:现期差 = 现货价格 - 期货价格(这里的期货价格为结算价)
|
|
7
7
|
黄金为 元/克, 白银为 元/千克, 玻璃现货为 元/平方米, 鸡蛋现货为 元/公斤, 鸡蛋期货为 元/500千克, 其余为 元/吨.
|
|
@@ -12,6 +12,7 @@ Desc: 生意社网站采集大宗商品现货价格及相应基差数据, 数据
|
|
|
12
12
|
发现生意社的 bugs:
|
|
13
13
|
1. 2018-09-12 周三 数据缺失是因为生意社源数据在该交易日缺失: https://www.100ppi.com/sf/day-2018-09-12.html
|
|
14
14
|
"""
|
|
15
|
+
|
|
15
16
|
import datetime
|
|
16
17
|
import re
|
|
17
18
|
import time
|
|
@@ -38,7 +39,8 @@ def futures_spot_price_daily(
|
|
|
38
39
|
:param start_day: str 开始日期 format:YYYY-MM-DD 或 YYYYMMDD 或 datetime.date对象; 默认为当天
|
|
39
40
|
:param end_day: str 结束数据 format:YYYY-MM-DD 或 YYYYMMDD 或 datetime.date对象; 默认为当天
|
|
40
41
|
:param vars_list: list 合约品种如 [RB, AL]; 默认参数为所有商品
|
|
41
|
-
:return:
|
|
42
|
+
:return: 基差
|
|
43
|
+
:rtype: pandas.DataFrame
|
|
42
44
|
展期收益率数据:
|
|
43
45
|
var 商品品种 string
|
|
44
46
|
sp 现货价格 float
|
|
@@ -74,7 +76,9 @@ def futures_spot_price_daily(
|
|
|
74
76
|
return temp_df
|
|
75
77
|
|
|
76
78
|
|
|
77
|
-
def futures_spot_price(
|
|
79
|
+
def futures_spot_price(
|
|
80
|
+
date: str = "20240430", vars_list: list = cons.contract_symbols
|
|
81
|
+
) -> pd.DataFrame:
|
|
78
82
|
"""
|
|
79
83
|
指定交易日大宗商品现货价格及相应基差
|
|
80
84
|
https://www.100ppi.com/sf/day-2017-09-12.html
|
|
@@ -96,12 +100,14 @@ def futures_spot_price(date: str = "20230509", vars_list: list = cons.contract_s
|
|
|
96
100
|
"""
|
|
97
101
|
date = cons.convert_date(date) if date is not None else datetime.date.today()
|
|
98
102
|
if date < datetime.date(2011, 1, 4):
|
|
99
|
-
raise Exception(
|
|
103
|
+
raise Exception(
|
|
104
|
+
"数据源开始日期为 20110104, 请将获取数据时间点设置在 20110104 后"
|
|
105
|
+
)
|
|
100
106
|
if date.strftime("%Y%m%d") not in calendar:
|
|
101
107
|
warnings.warn(f"{date.strftime('%Y%m%d')}非交易日")
|
|
102
108
|
return pd.DataFrame()
|
|
103
|
-
u1 = "
|
|
104
|
-
u2 = f'
|
|
109
|
+
u1 = "https://www.100ppi.com/sf/"
|
|
110
|
+
u2 = f'https://www.100ppi.com/sf/day-{date.strftime("%Y-%m-%d")}.html'
|
|
105
111
|
i = 1
|
|
106
112
|
while True:
|
|
107
113
|
for url in [u2, u1]:
|
|
@@ -119,12 +125,16 @@ def futures_spot_price(date: str = "20230509", vars_list: list = cons.contract_s
|
|
|
119
125
|
return temp_df
|
|
120
126
|
else:
|
|
121
127
|
time.sleep(3)
|
|
122
|
-
except:
|
|
123
|
-
print(
|
|
128
|
+
except Exception as e: # noqa: E722
|
|
129
|
+
print(
|
|
130
|
+
f"{date.strftime('%Y-%m-%d')}日生意社数据连接失败[错误信息:{e}],第{str(i)}次尝试,最多5次"
|
|
131
|
+
)
|
|
124
132
|
i += 1
|
|
125
133
|
if i > 5:
|
|
126
134
|
print(
|
|
127
|
-
f"{date.strftime('%Y-%m-%d')}日生意社数据连接失败, 如果当前交易日是 2018-09-12,
|
|
135
|
+
f"{date.strftime('%Y-%m-%d')}日生意社数据连接失败, 如果当前交易日是 2018-09-12, "
|
|
136
|
+
f"由于生意社源数据缺失, 无法访问, 否则为重复访问已超过5次,您的地址被网站墙了,"
|
|
137
|
+
f"请保存好返回数据,稍后从该日期起重试"
|
|
128
138
|
)
|
|
129
139
|
return pd.DataFrame()
|
|
130
140
|
|
|
@@ -160,11 +170,27 @@ def _check_information(df_data, date):
|
|
|
160
170
|
]
|
|
161
171
|
records = pd.DataFrame()
|
|
162
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
|
+
"""
|
|
163
178
|
if string == "PTA":
|
|
164
179
|
news = "PTA"
|
|
165
180
|
else:
|
|
166
181
|
news = "".join(re.findall(r"[\u4e00-\u9fa5]", string))
|
|
167
|
-
|
|
182
|
+
"""
|
|
183
|
+
|
|
184
|
+
if news != "" and news not in [
|
|
185
|
+
"商品",
|
|
186
|
+
"价格",
|
|
187
|
+
"上海期货交易所",
|
|
188
|
+
"郑州商品交易所",
|
|
189
|
+
"大连商品交易所",
|
|
190
|
+
"广州期货交易所",
|
|
191
|
+
# 某些天网站没有数据,比如 20180912,此时返回"暂无数据",但并不是网站被墙了
|
|
192
|
+
"暂无数据",
|
|
193
|
+
]:
|
|
168
194
|
symbol = chinese_to_english(news)
|
|
169
195
|
record = pd.DataFrame(df_data[df_data["symbol"] == string])
|
|
170
196
|
record.loc[:, "symbol"] = symbol
|
|
@@ -177,14 +203,26 @@ def _check_information(df_data, date):
|
|
|
177
203
|
symbol == "FG"
|
|
178
204
|
): # 上表中现货单位为元/平方米, 期货单位为元/吨. 换算公式:元/平方米*80=元/吨(http://www.100ppi.com/sf/959.html)
|
|
179
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
|
|
180
210
|
records = pd.concat([records, record])
|
|
181
211
|
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
"float"
|
|
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
|
+
|
|
222
|
+
records.loc[:, ["near_contract_price", "dominant_contract_price", "spot_price"]] = (
|
|
223
|
+
records.loc[
|
|
224
|
+
:, ["near_contract_price", "dominant_contract_price", "spot_price"]
|
|
225
|
+
].astype("float")
|
|
188
226
|
)
|
|
189
227
|
|
|
190
228
|
records.loc[:, "near_contract"] = records["near_contract"].replace(
|
|
@@ -194,9 +232,11 @@ def _check_information(df_data, date):
|
|
|
194
232
|
r"[^0-9]*(\d*)$", r"\g<1>", regex=True
|
|
195
233
|
)
|
|
196
234
|
|
|
235
|
+
records.loc[:, "near_month"] = records.loc[:, "near_contract"]
|
|
197
236
|
records.loc[:, "near_contract"] = records["symbol"] + records.loc[
|
|
198
237
|
:, "near_contract"
|
|
199
238
|
].astype("int").astype("str")
|
|
239
|
+
records.loc[:, "dominant_month"] = records.loc[:, "dominant_contract"]
|
|
200
240
|
records.loc[:, "dominant_contract"] = records["symbol"] + records.loc[
|
|
201
241
|
:, "dominant_contract"
|
|
202
242
|
].astype("int").astype("str")
|
|
@@ -232,7 +272,8 @@ def _check_information(df_data, date):
|
|
|
232
272
|
records["dom_basis_rate"] = (
|
|
233
273
|
records["dominant_contract_price"] / records["spot_price"] - 1
|
|
234
274
|
)
|
|
235
|
-
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"))
|
|
236
277
|
return records
|
|
237
278
|
|
|
238
279
|
|
|
@@ -240,17 +281,17 @@ def _join_head(content: pd.DataFrame) -> List:
|
|
|
240
281
|
headers = []
|
|
241
282
|
for s1, s2 in zip(content.iloc[0], content.iloc[1]):
|
|
242
283
|
if s1 != s2:
|
|
243
|
-
s = f
|
|
284
|
+
s = f"{s1}{s2}"
|
|
244
285
|
else:
|
|
245
286
|
s = s1
|
|
246
287
|
headers.append(s)
|
|
247
288
|
return headers
|
|
248
289
|
|
|
249
290
|
|
|
250
|
-
def futures_spot_price_previous(date: str = "
|
|
291
|
+
def futures_spot_price_previous(date: str = "20240430") -> pd.DataFrame:
|
|
251
292
|
"""
|
|
252
293
|
具体交易日大宗商品现货价格及相应基差
|
|
253
|
-
|
|
294
|
+
https://www.100ppi.com/sf/day-2017-09-12.html
|
|
254
295
|
:param date: 交易日; 历史日期
|
|
255
296
|
:type date: str
|
|
256
297
|
:return: 现货价格及相应基差
|
|
@@ -258,24 +299,49 @@ def futures_spot_price_previous(date: str = "20220209") -> pd.DataFrame:
|
|
|
258
299
|
"""
|
|
259
300
|
date = cons.convert_date(date) if date is not None else datetime.date.today()
|
|
260
301
|
if date < datetime.date(2011, 1, 4):
|
|
261
|
-
raise Exception(
|
|
302
|
+
raise Exception(
|
|
303
|
+
"数据源开始日期为 20110104, 请将获取数据时间点设置在 20110104 后"
|
|
304
|
+
)
|
|
262
305
|
if date.strftime("%Y%m%d") not in calendar:
|
|
263
306
|
warnings.warn(f"{date.strftime('%Y%m%d')}非交易日")
|
|
264
|
-
return
|
|
265
|
-
url = date.strftime(
|
|
307
|
+
return pd.DataFrame()
|
|
308
|
+
url = date.strftime("https://www.100ppi.com/sf2/day-%Y-%m-%d.html")
|
|
266
309
|
content = pandas_read_html_link(url)
|
|
267
310
|
main = content[1]
|
|
268
311
|
# Header
|
|
269
312
|
header = _join_head(main)
|
|
270
313
|
# Values
|
|
271
|
-
values = main[main[4].str.endswith(
|
|
314
|
+
values = main[main[4].str.endswith("%")]
|
|
272
315
|
values.columns = header
|
|
273
316
|
# Basis
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
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
|
+
|
|
323
|
+
basis.columns = ["主力合约基差", "主力合约基差(%)"]
|
|
324
|
+
# 20241125(jasonudu):因为部分日期,存在多个品种的现货价格,比如20151125的白糖、豆粕、豆油等,如果用商品名来merge,会出现重复列名,所以改用index来merge
|
|
325
|
+
# basis["商品"] = values["商品"].tolist()
|
|
326
|
+
basis.index = values.index
|
|
327
|
+
basis = pd.merge(
|
|
328
|
+
values[["商品", "现货价格", "主力合约代码", "主力合约价格"]],
|
|
329
|
+
basis,
|
|
330
|
+
left_index=True,
|
|
331
|
+
right_index=True,
|
|
332
|
+
)
|
|
333
|
+
basis = pd.merge(
|
|
334
|
+
basis,
|
|
335
|
+
values[
|
|
336
|
+
[
|
|
337
|
+
"180日内主力基差最高",
|
|
338
|
+
"180日内主力基差最低",
|
|
339
|
+
"180日内主力基差平均",
|
|
340
|
+
]
|
|
341
|
+
],
|
|
342
|
+
left_index=True,
|
|
343
|
+
right_index=True,
|
|
344
|
+
)
|
|
279
345
|
basis.columns = [
|
|
280
346
|
"商品",
|
|
281
347
|
"现货价格",
|
|
@@ -287,18 +353,18 @@ def futures_spot_price_previous(date: str = "20220209") -> pd.DataFrame:
|
|
|
287
353
|
"180日内主力基差最低",
|
|
288
354
|
"180日内主力基差平均",
|
|
289
355
|
]
|
|
290
|
-
basis[
|
|
356
|
+
basis["主力合约变动百分比"] = basis["主力合约变动百分比"].str.strip("%")
|
|
291
357
|
return basis
|
|
292
358
|
|
|
293
359
|
|
|
294
360
|
if __name__ == "__main__":
|
|
295
361
|
futures_spot_price_daily_df = futures_spot_price_daily(
|
|
296
|
-
start_day="
|
|
362
|
+
start_day="20250708", end_day="20250709", vars_list=["BZ", "RB"]
|
|
297
363
|
)
|
|
298
364
|
print(futures_spot_price_daily_df)
|
|
299
365
|
|
|
300
|
-
futures_spot_price_df = futures_spot_price(date="
|
|
366
|
+
futures_spot_price_df = futures_spot_price(date="20250620")
|
|
301
367
|
print(futures_spot_price_df)
|
|
302
368
|
|
|
303
|
-
futures_spot_price_previous_df = futures_spot_price_previous(date=
|
|
369
|
+
futures_spot_price_previous_df = futures_spot_price_previous(date="20240430")
|
|
304
370
|
print(futures_spot_price_previous_df)
|