def save(self): try: with open(self.dataPath, 'wb') as fs: pickle.dump(self.data, fs, pickle.HIGHEST_PROTOCOL) except: logger.info("存储 tushareBasicData 失败") else: logger.info("存储 tushareBasicData 成功")
def readData(self): try: with open(self.dataPath, 'rb') as fs: d = pickle.load(fs) return d except: logger.info("打开 tushareBasicData 错误,新建数据") return self.updateHolderData(self.stockList)
def initBasicData(self): try: with open(self.basicDataPath, 'rb') as fs: _d = pickle.load(fs) return _d except: logger.info("读取查询数据失败,新建查询数据库") return dict()
def loadStockList(self): try: with open(stockListPath,'rb') as fs: stock_list = pickle.load(fs) except: logger.info("读取股票列表失败,新建股票列表") stock_list = list(pro.stock_basic(exchange='', list_status='L', fields='ts_code').ts_code) with open(stockListPath,'wb') as fs: pickle.dump(stock_list, fs, pickle.HIGHEST_PROTOCOL) return stock_list
def initStockList(self): try: with open(stockListPath, 'rb') as fs: _l = pickle.load(fs) return _l except: logger.info("打开股票列表错误,新建股票列表") _l = list( pro.stock_basic(exchange='', list_status='L', fields='ts_code').ts_code) with open(stockListPath, 'wb') as fs: pickle.dump(_l, fs, pickle.HIGHEST_PROTOCOL)
def initData(self, ktype='d'): path_dict = { 'd': dayData_path, 'm': monthData_path, 'w': weekData_path } try: with open(path_dict.get(ktype), 'rb') as fs: _data = pickle.load(fs) logger.info( f"成功读取历史数据文件,证券数量:{len(_data)},更新日期:{ _data['000001.SZ'].index[-1]}" ) return _data except: print("数据库不存在,新建数据库") self.update()
def productQueryData(self, d): stockColumns = ['close', 'pct_chg', 'stat_macd', 'stat_wad'] basicColumns = [ '名称', '细分行业', '地区', '每股收益', '市盈(动)', '每股现金流', '流通股(亿)', '员工人数' ] foundationColumns = ['机构数量', '持股数量', '持股市值', '股本比例'] capitalColumns = ['主力净额', '主力净占比'] bdata = self.s.basicData[basicColumns] sddata = createDayData(self, d, stockColumns) swdata = createWeekData(self, d, stockColumns) smdata = createMonthData(self, d, stockColumns) cdata = self.c.dateDetail(d)[capitalColumns] fdata = self.f.data[foundationDate(d)][1][foundationColumns] data = pd.concat([bdata, sddata, swdata, smdata, fdata, cdata], axis=1) logger.info(f"productQueryData, {d} is ok.") return data
def save(self): try: with open(self.queryDataPath, 'wb') as fs: pickle.dump(self.queryData, fs, pickle.HIGHEST_PROTOCOL) except: logger.info("存储查询数据库失败") else: logger.info("存储查询数据库成功") try: with open(self.basicDataPath, 'wb') as fs: pickle.dump(self.basicData, fs, pickle.HIGHEST_PROTOCOL) except: logger.info("存储查询数据库失败") else: logger.info("存储查询数据库成功")