def update_qfq_for_single_code(code, start, end): max_qfq_date = DB_CLIENT.read_max_date_for(code, DAY_QFQ_REPO) if max_qfq_date is None: calc_qfq_and_update(code, start, end) else: fq_info = SECURITY_DATA_READ_SERVICE.read_fq_info(code, start, end) if fq_info is None: copy_stock_day_directly(code, start, end) else: max_fq_info_date = fq_info.index.levels[0].max() if str(max_fq_info_date)[0:10] < max_qfq_date: copy_stock_day_directly(code, start, end) else: print("Recreate needed for {}, max qfq date={}, max fq info date={}".format(code, max_qfq_date, max_fq_info_date)) re_calc_qfq_and_overwrite(code, start, end)
def do_fetch_and_save_bars(self, code, typ: SeType, start, end, freq: SeFreq): repo_name = typ.repo_name(freq) end_date = date_time_utils.Date().as_str() max_date_in_db = DB_CLIENT.read_max_date_for(code, repo_name) if max_date_in_db is None: start_date = MIN_START_TIME else: start_date = date_time_utils.Date.from_str(max_date_in_db).as_str() try: if start_date != end_date: df = self.fetcher.fetch_bars(typ, code, start, end, freq) if len(df) < 1: self.failed_codes.append(code) else: df = self.remove_columns_for_min_data(df, freq) DB_CLIENT.update_data_append_newer(df, repo_name) except Exception as e: print('Failed to fetch bars for {} {}, reason={}'.format( code, freq, e)) self.failed_codes.append(str(code))