From d2a4dd9c837f8df2a19e58f7fb4c81a91c114b67 Mon Sep 17 00:00:00 2001
From: Administrator <admin@example.com>
Date: 星期五, 15 八月 2025 13:15:32 +0800
Subject: [PATCH] 自动加想接口

---
 code_attribute/gpcode_manager.py |   45 +++++++++++++++++++++++++++------------------
 1 files changed, 27 insertions(+), 18 deletions(-)

diff --git a/code_attribute/gpcode_manager.py b/code_attribute/gpcode_manager.py
index 4dbcfc1..8209c38 100644
--- a/code_attribute/gpcode_manager.py
+++ b/code_attribute/gpcode_manager.py
@@ -8,7 +8,7 @@
 from db import redis_manager_delegate as redis_manager
 from db.mysql_data_delegate import Mysqldb
 from db.redis_manager_delegate import RedisUtils
-from log_module import log_export
+from log_module import log_export, async_log_util
 from log_module.log import logger_pre_close_price, logger_debug
 from trade import trade_record_log_util
 from utils import tool
@@ -285,7 +285,6 @@
         return code in self.__codes_cache
 
 
-
 # 鏆傚仠涓嬪崟浠g爜绠$悊
 # 涓庨粦鍚嶅崟鐨勫尯鍒槸鏆傚仠浜ゆ槗浠g爜鍙槸涓嶄氦鏄擄紝涓嶈兘绉婚櫎L2鐩戞帶浣�
 class PauseBuyCodesManager:
@@ -470,7 +469,6 @@
         """
         if code in self.__human_remove_codes:
             self.__human_remove_codes.discard(code)
-
 
 
 class BlackListCodeManager:
@@ -769,36 +767,42 @@
     return list
 
 
+@tool.singleton
 class CodePrePriceManager:
     __price_pre_cache = {}
     __redisManager = redis_manager.RedisManager(0)
 
+    def __init__(self):
+        fdatas = log_export.load_pre_close_price()
+        for code, v in fdatas.items():
+            self.__price_pre_cache[code] = round(float(v), 2)
+
     # 鑾峰彇鏀剁洏浠�
-    @classmethod
-    def get_price_pre(cls, code):
+    def get_price_pre(self, code):
         fdatas = log_export.load_pre_close_price()
         if code in fdatas:
             return round(float(fdatas.get(code)), 2)
         return None
 
     # 鑾峰彇缂撳瓨
-    @classmethod
-    def get_price_pre_cache(cls, code):
-        if code in cls.__price_pre_cache:
-            return float(cls.__price_pre_cache[code])
-        val = cls.get_price_pre(code)
+    def get_price_pre_cache(self, code):
+        if code in self.__price_pre_cache:
+            return float(self.__price_pre_cache[code])
+        val = self.get_price_pre(code)
         if val:
-            cls.__price_pre_cache[code] = val
+            self.__price_pre_cache[code] = val
         return val
 
     # 璁剧疆鏀剁洏浠�
-    @classmethod
-    def set_price_pre(cls, code, price, force=False):
-        if code in cls.__price_pre_cache and not force:
+    def set_price_pre(self, code, price, force=False):
+        if float(price) > 1000:
+            async_log_util.info(logger_debug, f"鑾峰彇鏄ㄦ棩鏀剁洏浠峰紓甯革細{code}-{price}")
+            return
+        if code in self.__price_pre_cache and not force:
             return
         price = round(float(price), 2)
         logger_pre_close_price.info(f"{code}-{price}")
-        cls.__price_pre_cache[code] = price
+        self.__price_pre_cache[code] = price
 
 
 __limit_up_price_dict = {}
@@ -809,12 +813,17 @@
     # 璇诲彇鍐呭瓨涓殑鍊�
     if code in __limit_up_price_dict:
         return __limit_up_price_dict[code]
-    price = CodePrePriceManager.get_price_pre_cache(code)
+    price = CodePrePriceManager().get_price_pre_cache(code)
     if price is None:
         return None
     limit_up_price = tool.to_price(decimal.Decimal(str(price)) * decimal.Decimal(tool.get_limit_up_rate(code)))
     __limit_up_price_dict[code] = limit_up_price
     return limit_up_price
+
+
+def clear_limit_up_price_cache(code):
+    if code in __limit_up_price_dict:
+        __limit_up_price_dict.pop(code)
 
 
 def get_limit_up_price_as_num(code):
@@ -844,7 +853,7 @@
 
 # 鑾峰彇璺屽仠浠�
 def get_limit_down_price(code):
-    price = CodePrePriceManager.get_price_pre_cache(code)
+    price = CodePrePriceManager().get_price_pre_cache(code)
     if price is None:
         return None
     return tool.to_price(decimal.Decimal(str(price)) * decimal.Decimal(f"{tool.get_limit_down_rate(code)}"))
@@ -971,4 +980,4 @@
         RedisUtils.delete(redis_instance, "first_code_record", auto_free=False)
         RedisUtils.delete(redis_instance, "first_code_limited_up_record", auto_free=False)
     finally:
-        RedisUtils.realse(redis_instance)
\ No newline at end of file
+        RedisUtils.realse(redis_instance)

--
Gitblit v1.8.0