From 65afea1ba534b51f947cbe7989d7f4d650bbc9e6 Mon Sep 17 00:00:00 2001 From: Administrator <admin@example.com> Date: 星期一, 04 十一月 2024 18:29:00 +0800 Subject: [PATCH] 代码异常保护 --- utils/init_data_util.py | 41 +++++++++++++++++++++++++++++++++-------- 1 files changed, 33 insertions(+), 8 deletions(-) diff --git a/utils/init_data_util.py b/utils/init_data_util.py index 7a4008b..e400369 100644 --- a/utils/init_data_util.py +++ b/utils/init_data_util.py @@ -2,6 +2,7 @@ import decimal from code_attribute import gpcode_manager +from log_module.log import logger_debug from third_data.history_k_data_util import HistoryKDatasUtils from utils import tool @@ -12,6 +13,7 @@ def re_set_price_pres(codes, force=False): + # 閫氳繃鍘嗗彶鏁版嵁缂撳瓨鑾峰彇 result = HistoryKDatasUtils.get_gp_latest_info(codes) for item in result: symbol = item['symbol'] @@ -22,15 +24,17 @@ # 鑾峰彇杩�90澶╃殑鏈�澶ч噺涓庢渶杩戠殑閲� # 鑾峰彇鏈�杩戜竴娆℃定鍋�/娑ㄥ仠涓嬩竴涓氦鏄撴棩鐨勬渶澶у�� -def get_volumns_by_code(code, count=60) -> object: +def get_volumns_by_code(code, count=60): datas = HistoryKDatasUtils.get_history_tick_n(code, count, "open,high,low,close,volume,pre_close,bob,amount") + if not datas: + return None # 璁$畻 datas.sort(key=lambda x: x["bob"], reverse=True) return datas -def parse_max_volume(datas, is_new_or_near_top=False): - result = __parse_max_volume(datas, is_new_or_near_top) +def parse_max_volume(code, datas, is_new_or_near_top=False): + result = __parse_max_volume(code, datas, is_new_or_near_top) refer_index = result[3] # 璁$畻鏈�浣庝环 refer_price = datas[refer_index]["high"] @@ -54,11 +58,32 @@ if datas[refer_index - 1]["volume"] > datas[refer_index]["volume"]: refer_index -= 1 - return datas[refer_index]["volume"], datas[refer_index]["volume"], datas[refer_index]['bob'].strftime("%Y-%m-%d"), refer_index + return datas[refer_index]["volume"], datas[refer_index]["volume"], datas[refer_index]['bob'].strftime( + "%Y-%m-%d"), refer_index + + +def parse_max_volume_in_days(datas, max_day): + """ + 瑙f瀽鏈�杩戝嚑澶╂渶澶х殑閲� + @param datas: + @param max_day: + @return: + """ + # 瑙f瀽鏈�杩戝嚑澶╃殑鏈�澶ч噺 + datas = datas[:max_day] + max_volume_info = None + for d in datas: + if max_volume_info is None: + max_volume_info = (d["volume"], d) + if d["volume"] > max_volume_info[0]: + max_volume_info = (d["volume"], d) + if max_volume_info: + return max_volume_info[0] + return None # 杩斿洖锛�(60澶╂渶澶ч噺,鏄ㄦ棩閲�,閲忓弬鑰冩棩鏈�,鍙傝�冮噺鎹粖浜ゆ槗鏃ユ暟) -def __parse_max_volume(datas, is_new_or_near_top=False): +def __parse_max_volume(code, datas, is_new_or_near_top=False): max_volume = 0 max_volume_date = None max_volume_index = None @@ -70,7 +95,7 @@ if i >= len(datas): break item = datas[i] - limit_up_price = float(gpcode_manager.get_limit_up_price_by_preprice(item["pre_close"])) + limit_up_price = float(gpcode_manager.get_limit_up_price_by_preprice(code, item["pre_close"])) if abs(limit_up_price - item["high"]) < 0.001: latest_limit_up_index = i break @@ -104,9 +129,9 @@ max_volume = volume max_volume_date = item['bob'] # 鏄惁鏈夋定鍋� - limit_up_price = float(gpcode_manager.get_limit_up_price_by_preprice(item["pre_close"])) + limit_up_price = float(gpcode_manager.get_limit_up_price_by_preprice(code, item["pre_close"])) # 涓嶇湅瓒呰繃60澶╃殑娑ㄥ仠 - if abs(limit_up_price - item["high"]) < 0.01 and i <= 59: + if abs(limit_up_price - item["high"]) < 0.001 and i <= 59: # 娑ㄥ仠 next_volume = 0 if i > 0: -- Gitblit v1.8.0