From 97cc7f2d7428ea890c0a0ada76e5bffafd2463e4 Mon Sep 17 00:00:00 2001
From: Administrator <admin@example.com>
Date: 星期四, 26 十月 2023 22:56:11 +0800
Subject: [PATCH] L2总卖实现

---
 l2/l2_sell_manager.py |   35 +++++++++++++++++++++++++++++++++--
 1 files changed, 33 insertions(+), 2 deletions(-)

diff --git a/l2/l2_sell_manager.py b/l2/l2_sell_manager.py
index 77a5c11..8e46e46 100644
--- a/l2/l2_sell_manager.py
+++ b/l2/l2_sell_manager.py
@@ -7,6 +7,8 @@
 from db.redis_manager import RedisUtils
 from log_module import async_log_util
 from log_module.log import logger_l2_market_sell
+from utils import tool
+from utils.tool import CodeDataCacheUtil
 
 
 class L2MarketSellManager:
@@ -15,6 +17,7 @@
     __instance = None
     __current_total_sell_data_cache = {}
     __last_total_sell_data_cache = {}
+    __used_refer_sell_data_cache = {}
 
     def __new__(cls, *args, **kwargs):
         if not cls.__instance:
@@ -30,9 +33,31 @@
     def __load_datas(cls):
         __redis = cls.__get_redis()
         try:
-            pass
+            keys = RedisUtils.keys(__redis, "fast_buy_used_sell_data-*")
+            for k in keys:
+                code = k.split("-")[-1]
+                val = RedisUtils.smembers(__redis, k)
+                CodeDataCacheUtil.set_cache(cls.__used_refer_sell_data_cache, code, val)
         finally:
             RedisUtils.realse(__redis)
+
+    def set_sell_time_used(self, code, time_str):
+        if code not in self.__used_refer_sell_data_cache:
+            self.__used_refer_sell_data_cache[code] = set()
+        self.__used_refer_sell_data_cache[code].add(time_str)
+        RedisUtils.sadd_async(self.__db, f"fast_buy_used_sell_data-{code}", time_str)
+        RedisUtils.expire_async(self.__db, f"fast_buy_used_sell_data-{code}", tool.get_expire())
+
+    def is_refer_sell_time_used(self, code, time_str):
+        if code not in self.__used_refer_sell_data_cache:
+            return False
+        return time_str in self.__used_refer_sell_data_cache[code]
+
+    def clear(self):
+        self.__used_refer_sell_data_cache.clear()
+        keys = RedisUtils.keys(self.__get_redis(), "fast_buy_used_sell_data-*")
+        for k in keys:
+            RedisUtils.delete_async(self.__db, k)
 
     # 璁剧疆褰撳墠鐨勬�诲崠
     def set_current_total_sell_data(self, code, time_str, money):
@@ -40,14 +65,20 @@
         async_log_util.info(logger_l2_market_sell, f"{code}: {time_str}-{money}")
         if code in self.__current_total_sell_data_cache:
             self.__last_total_sell_data_cache[code] = self.__current_total_sell_data_cache.get(code)
-        self.__current_total_sell_data_cache[code] = (time_str, money)
+        self.__current_total_sell_data_cache[code] = (time_str, round(money))
 
     # 鑾峰彇鍙傝�冨崠鐨勬暟鎹�
     def get_refer_sell_data(self, code, time_str):
         cuurent = self.__current_total_sell_data_cache.get(code)
+        if cuurent is None:
+            return None
         if int(time_str.replace(":", "")) > int(cuurent[0].replace(":", "")):
             return cuurent
         last = self.__last_total_sell_data_cache.get(code)
         if int(time_str.replace(":", "")) > int(last[0].replace(":", "")):
             return last
         return None
+
+
+if __name__ == "__main__":
+    pass

--
Gitblit v1.8.0