import os from WindPy import w from kquant_data.xio.csv import read_datetime_dataframe from kquant_data.api import all_instruments from kquant_data.wind.tdays import read_tdays from kquant_data.wind_resume.wsd import resume_download_daily_to_many_files, \ resume_download_financial_report_data_daily_latest from kquant_data.config import __CONFIG_H5_STK_FACTOR_DIR__, __CONFIG_H5_STK_DIR__, __CONFIG_TDAYS_SSE_FILE__ if __name__ == '__main__': w.start() path = os.path.join(__CONFIG_H5_STK_DIR__, '1day', 'Symbol.csv') Symbols = all_instruments(path) wind_codes = list(Symbols['wind_code']) trading_days = read_tdays(__CONFIG_TDAYS_SSE_FILE__) # 读取ipo_date,提前做好准备 path = os.path.join(__CONFIG_H5_STK_FACTOR_DIR__, 'ipo_date.csv') ipo_date = read_datetime_dataframe(path) # 下载最新一天的数据 field = 'total_shares' # 下载最新一天,并且合并历史 resume_download_financial_report_data_daily_latest( w, wind_codes, trading_days, __CONFIG_H5_STK_FACTOR_DIR__, field) resume_download_daily_to_many_files(w, trading_days, ipo_date, __CONFIG_H5_STK_FACTOR_DIR__, field)
df = wind_code_2_InstrumentID(df_csv, 'wind_code') df = df.apply(CZCE_3to4, axis=1) df = df.set_index(['InstrumentID']) return df if __name__ == '__main__': ipo_last_trade = load_ipo_last_trade_trading() ipo_last_trade['ipo_date'] = ipo_last_trade['ipo_date'].apply(lambda x: yyyyMMdd_2_datetime(x)) ipo_last_trade['lasttrade_date'] = ipo_last_trade['lasttrade_date'].apply(lambda x: yyyyMMdd_2_datetime(x)) ipo_last_trade['ipo_date'] = pd.to_datetime(ipo_last_trade['ipo_date']) ipo_last_trade['lasttrade_date'] = pd.to_datetime(ipo_last_trade['lasttrade_date']) root_path = r'D:\DATA_FUT_HDF5\Data_Wind\60' csv_path = os.path.join(root_path, 'first_last.csv') first_last = read_datetime_dataframe(csv_path) if first_last is None: first_last = pd.DataFrame(columns=['first', 'last']) date_table = ipo_last_trade.merge(first_last, how='inner', left_index=True, right_index=True) tic() df = get_first_last_min(root_path, date_table, first_last) toc() # 如何实现 root_path = r'D:\DATA_FUT_HDF5\Data_Wind\86400_Wind' csv_path = os.path.join(root_path, 'first_last.csv') first_last = read_datetime_dataframe(csv_path) if first_last is None: first_last = pd.DataFrame(columns=['first', 'last'])
from kquant_data.config import __CONFIG_H5_FUT_FACTOR_DIR__ from kquant_data.xio.csv import read_datetime_dataframe from kquant_data.wind.tdays import read_tdays from kquant_data.wind_resume.wsd import resume_download_daily_to_many_files, \ resume_download_financial_report_data_daily_latest from kquant_data.config import __CONFIG_TDAYS_SHFE_FILE__ if __name__ == '__main__': w.start() trading_days = read_tdays(__CONFIG_TDAYS_SHFE_FILE__) # 读取合约上市日期,提前做好准备 path = os.path.join(__CONFIG_H5_FUT_FACTOR_DIR__, 'contract_issuedate.csv') contract_issuedate = read_datetime_dataframe(path) wind_codes = list(contract_issuedate.columns) # 下载最新一天的数据 field = 'trade_hiscode' if True: # 下载最新一天,并且合并历史 date_str = (datetime.today() + timedelta(days=0)).strftime('%Y-%m-%d') resume_download_financial_report_data_daily_latest( w, wind_codes, trading_days, __CONFIG_H5_FUT_FACTOR_DIR__, field, date_str) # 使用下一个交易日 new_trading_days = trading_days[date_str:]
# 也可选择全下 # 分钟数据是按天分割,还是放在一个文件中呢? # 下载是从哪下到哪呢? w.start() # 注意,数据中有可能出现0 path_ipo_last_trade = os.path.join(__CONFIG_H5_FUT_SECTOR_DIR__, 'ipo_last_trade_trading.csv') ipo_last_trade = pd.read_csv(path_ipo_last_trade) ipo_last_trade['ipo_date'] = ipo_last_trade['ipo_date'].apply(lambda x: yyyyMMdd_2_datetime(x)) ipo_last_trade['lasttrade_date'] = ipo_last_trade['lasttrade_date'].apply(lambda x: yyyyMMdd_2_datetime(x)) root_path = r'D:\DATA_FUT\60' path_first_last = os.path.join(root_path, 'first_last.csv') first_last = read_datetime_dataframe(path_first_last) date_str = (datetime.today() - timedelta(days=1)).strftime('%Y-%m-%d') # 设置至少30天比较靠谱 start_str = (datetime.today() - timedelta(days=30)).strftime('%Y-%m-%d') trading_days = read_tdays(__CONFIG_TDAYS_SHFE_FILE__) trading_days_slice = trading_days[start_str:date_str] wind_code_set = set() dirpath = os.path.join(__CONFIG_H5_FUT_SECTOR_DIR__, '中金所全部品种') for i in range(len(trading_days_slice)): wind_code_set = download_constituent_min(w, dirpath, trading_days_slice['date'][i], ipo_last_trade, first_last, wind_code_set, trading_days)