From d163fc446359d66afa10e2ab63e860887aa8732c Mon Sep 17 00:00:00 2001 From: Administrator <admin@example.com> Date: 星期二, 19 八月 2025 01:33:11 +0800 Subject: [PATCH] 连续涨停时间记录/新增大单概览接口 --- code_attribute/today_max_price_manager.py | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 45 insertions(+), 0 deletions(-) diff --git a/code_attribute/today_max_price_manager.py b/code_attribute/today_max_price_manager.py index 6627152..b3f3deb 100644 --- a/code_attribute/today_max_price_manager.py +++ b/code_attribute/today_max_price_manager.py @@ -4,6 +4,7 @@ """ import json +from code_attribute import gpcode_manager from db import redis_manager_delegate as redis_manager from db.redis_manager_delegate import RedisUtils from log_module import async_log_util @@ -13,6 +14,11 @@ class MaxPriceInfoManager: __max_price_info_cache = {} + # 鍘嗗彶娑ㄥ仠鏁版嵁锛歿浠g爜锛歔(娑ㄥ仠鏃堕棿, 鐐告澘鏃堕棿)]} + __limit_up_records_cache = {} + # 鏈�杩戠殑娑ㄥ仠鏁版嵁锛歿浠g爜锛氭定鍋滄椂闂磢 + __limit_up_latest_info_cache = {} + __db = 4 _redisManager = redis_manager.RedisManager(4) __instance = None @@ -34,6 +40,16 @@ val = json.loads(val) cls.__max_price_info_cache[code] = val + def __is_limit_up(self, code, price, sell1_info): + limit_up_price = gpcode_manager.get_limit_up_price_as_num(code) + if not limit_up_price: + return False + if sell1_info[1] > 0: + return False + if abs(price - limit_up_price) >= 0.001: + return False + return True + def set_price_info(self, code, price, time, sell1_info): """ 璁剧疆浠锋牸淇℃伅 @@ -51,6 +67,35 @@ RedisUtils.setex_async( self.__db, "max_price_info-{}".format(code), tool.get_expire(), json.dumps(price_info)) async_log_util.info(logger_debug, f"鏈�澶х幇浠�:{code}-{price_info}") + if self.__is_limit_up(code, price, sell1_info): + if code not in self.__limit_up_latest_info_cache: + self.__limit_up_latest_info_cache[code] = time + else: + if code not in self.__limit_up_records_cache: + self.__limit_up_records_cache[code] = [] + if code in self.__limit_up_latest_info_cache: + self.__limit_up_records_cache[code].append((self.__limit_up_latest_info_cache.get(code), time)) + self.__limit_up_latest_info_cache.pop(code) + + def get_max_limit_up_time(self, code): + """ + 鑾峰彇鏈�澶ф定鍋滄寔缁椂闂� + @param code: + @return: + """ + try: + max_space_time = 0 + if code in self.__limit_up_latest_info_cache: + max_space_time = tool.trade_time_sub(tool.get_now_time_str(), self.__limit_up_latest_info_cache[code]) + if code in self.__limit_up_records_cache: + max_item = max(self.__limit_up_records_cache[code], key=lambda x: tool.trade_time_sub(x[1], x[0])) + max_space_time_his = tool.trade_time_sub(max_item[1], max_item[0]) + if max_space_time_his > max_space_time: + max_space_time = max_space_time_his + return max_space_time + except Exception as e: + async_log_util.error(logger_debug, f"鑾峰彇鏈�澶ф定鍋滄椂闂村嚭閿欙細{str(e)}") + return 0 def get_price_info_cache(self, code): return self.__max_price_info_cache.get(code) -- Gitblit v1.8.0