From 57a7a0dbc43b21256f877bb50f6dd4a35addf313 Mon Sep 17 00:00:00 2001
From: Administrator <admin@example.com>
Date: 星期五, 07 六月 2024 15:46:15 +0800
Subject: [PATCH] 运行日志添加

---
 code_attribute/gpcode_manager.py |   92 ++++++++++++++++++++++++++++++++++++++++-----
 1 files changed, 81 insertions(+), 11 deletions(-)

diff --git a/code_attribute/gpcode_manager.py b/code_attribute/gpcode_manager.py
index 87e08a3..568096e 100644
--- a/code_attribute/gpcode_manager.py
+++ b/code_attribute/gpcode_manager.py
@@ -7,6 +7,8 @@
 import constant
 from db import redis_manager_delegate as redis_manager
 from db.redis_manager_delegate import RedisUtils
+from log_module import log_export
+from log_module.log import logger_pre_close_price
 from utils import tool
 import decimal
 
@@ -292,6 +294,67 @@
 
     def list_code_cache(self):
         return self.__pause_buy_codes_cache
+
+
+# 蹇呬拱鍗�/绾㈠悕鍗�
+class MustBuyCodesManager:
+    __instance = None
+    __db = 0
+    redisManager = redis_manager.RedisManager(0)
+    __redis_key = "must_buy_rate-"
+    __must_buy_code_cancel_rate_cache = {}
+
+    def __new__(cls, *args, **kwargs):
+        if not cls.__instance:
+            cls.__instance = super(MustBuyCodesManager, cls).__new__(cls, *args, **kwargs)
+            keys = RedisUtils.keys(cls.__get_redis(), cls.__redis_key + "*")
+            for k in keys:
+                code = k.split("-")[-1]
+                val = RedisUtils.get(cls.__get_redis(), k)
+                cls.__must_buy_code_cancel_rate_cache[code] = round(float(val), 2)
+        return cls.__instance
+
+    @classmethod
+    def __get_redis(cls):
+        return cls.redisManager.getRedis()
+
+    def clear(self):
+        self.__must_buy_code_cancel_rate_cache.clear()
+        keys = RedisUtils.keys(self.__get_redis(), self.__redis_key + "*")
+        for k in keys:
+            RedisUtils.delete(self.__get_redis(), k)
+
+    def add_code(self, code, rate=0.9):
+        self.__must_buy_code_cancel_rate_cache[code] = round(rate, 2)
+        RedisUtils.setex_async(self.__db, self.__redis_key + str(code), tool.get_expire(), str(round(rate, 2)))
+
+    def remove_code(self, code):
+        if code in self.__must_buy_code_cancel_rate_cache:
+            self.__must_buy_code_cancel_rate_cache.pop(code)
+        RedisUtils.delete_async(self.__db, self.__redis_key + str(code))
+
+    def is_in(self, code):
+        return RedisUtils.get(self.__get_redis(), self.__redis_key + str(code))
+
+    def is_in_cache(self, code):
+        return code in self.__must_buy_code_cancel_rate_cache
+
+    def list_code(self):
+        codes = set()
+        keys = RedisUtils.keys(self.__get_redis(), self.__redis_key + "*")
+        if keys:
+            for k in keys:
+                code = k.split("-")[-1]
+                codes.add(code)
+        return codes
+
+    def list_code_cache(self):
+        return self.__must_buy_code_cancel_rate_cache.keys()
+
+    def get_cancel_rate_cache(self, code):
+        if code not in self.__must_buy_code_cancel_rate_cache:
+            return None
+        return self.__must_buy_code_cancel_rate_cache[code]
 
 
 class WhiteListCodeManager:
@@ -635,9 +698,9 @@
         data = get_gp_list()
     list = []
     for d in data:
-        if d[0:2] == '00':
+        if tool.is_sz_code(d):
             list.append("SZSE.{}".format(d))
-        elif d[0:2] == '60':
+        elif tool.is_sh_code(d):
             list.append("SHSE.{}".format(d))
     return list
 
@@ -649,9 +712,9 @@
     # 鑾峰彇鏀剁洏浠�
     @classmethod
     def get_price_pre(cls, code):
-        result = RedisUtils.get(cls.__redisManager.getRedis(), "price-pre-{}".format(code))
-        if result is not None:
-            return float(result)
+        fdatas = log_export.load_pre_close_price()
+        if code in fdatas:
+            return round(float(fdatas.get(code)), 2)
         return None
 
     # 鑾峰彇缂撳瓨
@@ -670,8 +733,9 @@
         codes = get_gp_list()
         if code not in codes and not FirstCodeManager().is_in_first_record_cache(code) and not force:
             return
-        RedisUtils.setex(cls.__redisManager.getRedis(), "price-pre-{}".format(code), tool.get_expire(), str(price))
-        cls.__price_pre_cache[code] = float(price)
+        price = round(float(price), 2)
+        logger_pre_close_price.info(f"{code}-{price}")
+        cls.__price_pre_cache[code] = price
 
 
 __limit_up_price_dict = {}
@@ -685,7 +749,7 @@
     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("1.1"))
+    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
 
@@ -696,10 +760,16 @@
     return None
 
 
-def get_limit_up_price_by_preprice(price):
+def get_limit_up_price_by_preprice(code, price):
     if price is None:
         return None
-    return tool.to_price(decimal.Decimal(str(price)) * decimal.Decimal("1.1"))
+    return tool.to_price(decimal.Decimal(str(price)) * decimal.Decimal(f"{tool.get_limit_up_rate(code)}"))
+
+
+def get_limit_down_price_by_preprice(code, price):
+    if price is None:
+        return None
+    return tool.to_price(decimal.Decimal(str(price)) * decimal.Decimal(f"{tool.get_limit_down_rate(code)}"))
 
 
 # 鑾峰彇璺屽仠浠�
@@ -707,7 +777,7 @@
     price = CodePrePriceManager.get_price_pre_cache(code)
     if price is None:
         return None
-    return tool.to_price(decimal.Decimal(str(price)) * decimal.Decimal("0.9"))
+    return tool.to_price(decimal.Decimal(str(price)) * decimal.Decimal(f"{tool.get_limit_down_rate(code)}"))
 
 
 # 鑾峰彇鐜颁环

--
Gitblit v1.8.0