From fda20e935bea4870544695185ec9427dc66fb168 Mon Sep 17 00:00:00 2001 From: Administrator <admin@example.com> Date: 星期二, 06 八月 2024 16:22:20 +0800 Subject: [PATCH] bug修复/H撤更新/接口修改 --- third_data/history_k_data_manager.py | 47 +++++++++++++++++++++++++++++++++++++++++------ 1 files changed, 41 insertions(+), 6 deletions(-) diff --git a/third_data/history_k_data_manager.py b/third_data/history_k_data_manager.py index 9100426..9b1b203 100644 --- a/third_data/history_k_data_manager.py +++ b/third_data/history_k_data_manager.py @@ -1,11 +1,13 @@ """ 鍘嗗彶K绾跨鐞� """ +import copy import datetime import os import threading import constant +from code_attribute import gpcode_manager from huaxin_client import l1_subscript_codes_manager from log_module.log import logger_debug from third_data import history_k_data_util @@ -45,9 +47,24 @@ return len(codes) +def re_set_price_pres(codes, force=False): + day = tool.get_now_date_str() + # 閫氳繃鍘嗗彶鏁版嵁缂撳瓨鑾峰彇 + not_codes = [] + for code in codes: + pre_close = HistoryKDataManager().get_pre_close(code, day) + if pre_close is not None: + gpcode_manager.CodePrePriceManager.set_price_pre(code, pre_close, force) + else: + not_codes.append(code) + if not_codes: + init_data_util.re_set_price_pres(not_codes, force) + + class HistoryKDataManager: __instance = None __db = 0 + __history_k_day_datas = {} def __new__(cls, *args, **kwargs): if not cls.__instance: @@ -100,15 +117,20 @@ path_str = f"{cache_dir}/{file_name}" if os.path.exists(path_str) and not force: return + if day not in self.__history_k_day_datas: + self.__history_k_day_datas[day] = {} if datas: + self.__history_k_day_datas[day][code] = datas # 灏嗘棩鏈熸牸寮忓寲 + fdatas = [] for d in datas: - for k in d: - if type(d[k]) == datetime.datetime: - d[k] = d[k].strftime("%Y-%m-%d %H:%M:%S") - - with open(path_str, encoding="utf-8", mode='w') as f: - f.write(f"{datas}") + dd = copy.deepcopy(d) + for k in dd: + if type(dd[k]) == datetime.datetime: + dd[k] = dd[k].strftime("%Y-%m-%d %H:%M:%S") + fdatas.append(dd) + with open(path_str, encoding="utf-8", mode='w') as f: + f.write(f"{fdatas}") self.__del_outdate_datas(code) def get_history_bars(self, code, day): @@ -118,6 +140,8 @@ @param day: @return: """ + if day in self.__history_k_day_datas and code in self.__history_k_day_datas[day]: + return self.__history_k_day_datas[day][code] cache_dir = self.__get_cache_dir() file_name = f"{day}_{code}.txt" path_str = f"{cache_dir}/{file_name}" @@ -135,6 +159,17 @@ return datas return None + def get_pre_close(self, code, day): + """ + 鑾峰彇涔嬪墠鐨勬敹鐩樹环 + @param code: + @param day: + @return: + """ + if day in self.__history_k_day_datas and code in self.__history_k_day_datas[day]: + return self.__history_k_day_datas[day][code][0]["close"] + return None + def get_history_bars_codes(self, day): """ 鑾峰彇鏌愪竴澶╃殑鍘嗗彶K绾跨殑浠g爜鏁版嵁 -- Gitblit v1.8.0