From b6b259bb9b1a305f8691506602144d634c28f12d Mon Sep 17 00:00:00 2001 From: Administrator <admin@example.com> Date: 星期四, 05 九月 2024 18:17:35 +0800 Subject: [PATCH] 最近的卖信息优化 --- l2/l2_sell_manager.py | 40 +++++++++++++++++++++++++--------------- 1 files changed, 25 insertions(+), 15 deletions(-) diff --git a/l2/l2_sell_manager.py b/l2/l2_sell_manager.py index d347697..73538a2 100644 --- a/l2/l2_sell_manager.py +++ b/l2/l2_sell_manager.py @@ -15,9 +15,9 @@ __db = 0 __redis_manager = redis_manager.RedisManager(0) __instance = None - __current_total_sell_data_cache = {} - __last_total_sell_data_cache = {} __used_refer_sell_data_cache = {} + # 鎬诲崠淇℃伅鍒楄〃 + __total_sell_data_cache_list_cache = {} def __new__(cls, *args, **kwargs): if not cls.__instance: @@ -58,6 +58,7 @@ def clear(self): self.__used_refer_sell_data_cache.clear() + self.__total_sell_data_cache_list_cache.clear() keys = RedisUtils.keys(self.__get_redis(), "fast_buy_used_sell_data-*") for k in keys: RedisUtils.delete_async(self.__db, k) @@ -74,17 +75,27 @@ """ # 璁板綍鏃ュ織 async_log_util.info(logger_l2_market_sell, f"{code}: {time_str}-{money} {sell_1_info}") - 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, round(money), volume, sell_1_info) + + if code not in self.__total_sell_data_cache_list_cache: + self.__total_sell_data_cache_list_cache[code] = [] + if self.__total_sell_data_cache_list_cache[code] and self.__total_sell_data_cache_list_cache[code][-1][ + 0] == time_str: + return + + self.__total_sell_data_cache_list_cache[code].append((time_str, round(money), volume, sell_1_info)) + # 淇濈暀鏈�澶�10鏉℃暟鎹� + if len(self.__total_sell_data_cache_list_cache[code]) > 10: + self.__total_sell_data_cache_list_cache[code] = self.__total_sell_data_cache_list_cache[code][-10:] def get_current_total_sell_data(self, code): """ - @param code: @return:(鏃堕棿, 鎬讳拱棰�, 鎬婚噺, 鍗�1淇℃伅) """ - return self.__current_total_sell_data_cache.get(code) + total_sell_data_cache_list = self.__total_sell_data_cache_list_cache.get(code) + if not total_sell_data_cache_list: + return None + return total_sell_data_cache_list[-1] # 鑾峰彇鍙傝�冨崠鐨勬暟鎹� def get_refer_sell_data(self, code, time_str): @@ -94,14 +105,13 @@ @param time_str: 褰撳墠鏁版嵁鎴鏃堕棿 @return: (time_str, round(money), volume, sell_1_info) """ - 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 last and int(time_str.replace(":", "")) > int(last[0].replace(":", "")): - return last + total_sell_data_cache_list = self.__total_sell_data_cache_list_cache.get(code) + if total_sell_data_cache_list: + for i in range(len(total_sell_data_cache_list) - 1, -1, -1): + sell_data = total_sell_data_cache_list[i] + if int(time_str.replace(":", "")) > int(sell_data[0].replace(":", "")): + # 鍙栧垰濂芥瘮褰撳墠鏃堕棿鏃╃殑鏁版嵁 + return sell_data return None -- Gitblit v1.8.0