def getAllStockHistoryDatas(self): count = 0 length = len(self.__stock_code_map) code_list_cfg = ConfigLoader().get("stocks", "code_list") startDate = ConfigLoader().get("stocks", "history_data_start_date") endDate = ConfigLoader().get("stocks", "history_data_end_date") now = time.time() today = time.strftime("%Y-%m-%d", time.localtime(now)) if endDate == '-1' or endDate >= today: endDate = today if startDate == '-1': sevenDaySecs = 60 * 60 * 24 * 10 startDate = time.strftime("%Y-%m-%d", time.localtime(now - sevenDaySecs)) else: if startDate == '-1': b_time = time.mktime(time.strptime(endDate, "%Y-%m-%d")) e_time = time.mktime(time.strptime(today, "%Y-%m-%d")) diff_day = (e_time - b_time) / 86400 sevenDaySecs = 60 * 60 * 24 * (10 + diff_day) startDate = time.strftime("%Y-%m-%d", time.localtime(now - sevenDaySecs)) print('起始日期: ' + startDate) print('结束日期: ' + endDate) for code, name in self.__stock_code_map.items(): count += 1 if code_list_cfg and code not in code_list_cfg: continue df_SpecStockHistory = ts.get_hist_data(code, start=startDate, end=endDate) if df_SpecStockHistory is None: print("None: ", code) continue StockAnalyst().setCode2Name(code, name) print("第 %d 支股票: [%s],共 %d 支" % (count, StockAnalyst().getNameByCode(code), length)) df_SpecStockHistory = df_SpecStockHistory.reset_index() df_SpecStockHistory = NounsEng2Chn().converseEng2Chn( df_SpecStockHistory, NounsEng2Chn.mDataSpecStockHistory) filename = code + NounsEng2Chn().mStockCode2Chn.get(code) + ".xlsx" df_SpecStockHistory.to_excel("../datas/股票数据/" + filename, sheet_name='历史日K数据', index=False)
def getSpecStockTest(): code = "000001" df_SpecStockHistory = ts.get_hist_data(code, start='2020-01-01') df_SpecStockHistory = NounsEng2Chn().converseEng2Chn( df_SpecStockHistory, NounsEng2Chn.mDataSpecStockHistory) df_SpecStockHistory.to_excel("../datas/" + code + "历史数据.xlsx", sheet_name='股票历史信息')
def getAllStockInfo(self): df_StockInfo = ts.get_stock_basics() df_StockInfo = df_StockInfo.reset_index() df_StockInfo = NounsEng2Chn().converseEng2Chn( df_StockInfo, NounsEng2Chn.mDataCompanyBasicInfo) df_StockInfo.to_excel("../datas/股票数据/当前上市交易的股票列表.xlsx", sheet_name='股票列表', index=False)
def getAllIndexDaily(self): with pd.ExcelWriter(r"../datas/指数数据/指数日K.xlsx") as xlsx: for name, code in self.__index_dict.items(): if code != '000001.sh': # 先做上证指数分析 continue df_SpecIndex = self.__pro.index_daily(ts_code=code, start_date='20200101') df_SpecIndex = df_SpecIndex.reset_index() df_SpecIndex = NounsEng2Chn().converseEng2Chn(df_SpecIndex, NounsEng2Chn.mDataSpecIndexTradingDaily) df_SpecIndex.to_excel(xlsx, sheet_name=name, index=False)
def getAllStockInfoPro(self): field = "ts_code,symbol,name,area,industry,market,list_date,list_status,exchange,fullname,enname,curr_type" df_StockInfo = self.__pro.stock_basic(list_status='L', fields=field) df_StockInfo = df_StockInfo.reset_index() df_StockInfo = NounsEng2Chn().converseEng2Chn( df_StockInfo, NounsEng2Chn.mDataAllStockBasicInfo) NounsEng2Chn().converseStockCode2Chn(df_StockInfo) df_StockInfo.to_excel("../datas/A_当前上市交易的股票列表.xlsx", sheet_name='股票列表', index=False) # __stock_code_list = list(df_StockInfo["code"]) for i in range(0, len(df_StockInfo)): df_line = df_StockInfo.iloc[i] name = df_line["股票名称"] if df_line["市场类型(主板/中小板/创业板/科创板)"] != '科创板' and "ST" not in name: code = df_line["股票代码"] self.__stock_code_map[code] = name self.__stock_ts_code_list.append(df_line["TS代码"])
def getAllStockTradingDayData(): df_AllStock = ts.get_today_all() df_AllStock = NounsEng2Chn().converseEng2Chn( df_AllStock, NounsEng2Chn().mDataTradingDaysMap) df_AllStock.to_excel("../datas/股票数据/股票实时数据.xlsx", sheet_name='股票实时信息')