From b8dd6ca5f8a8da42531e8308e842c70bc5b1a7a4 Mon Sep 17 00:00:00 2001
From: Administrator <admin@example.com>
Date: 星期五, 29 十一月 2024 15:33:01 +0800
Subject: [PATCH] 收盘之后的日志系统添加缓存

---
 log_module/log_export.py |   37 ++++++++++++++++++++++++++++++++-----
 1 files changed, 32 insertions(+), 5 deletions(-)

diff --git a/log_module/log_export.py b/log_module/log_export.py
index 67a02b8..476ffcb 100644
--- a/log_module/log_export.py
+++ b/log_module/log_export.py
@@ -11,6 +11,26 @@
 from log_module.log import logger_l2_process_time
 from utils import tool
 
+__log_cache_data = {}
+
+
+# 鏃ュ織缂撳瓨
+def cache_log(fn):
+    def wrapper(*args, **kwargs):
+        can_cache = tool.get_now_time_as_int() > 150000
+        cache_key = f"{fn.__name__}#{args}#{kwargs}"
+        if can_cache:
+            # 15:00:00涔嬪悗鎵嶈兘缂撳瓨
+
+            if cache_key in __log_cache_data:
+                return __log_cache_data[cache_key]
+        result = fn(*args, **kwargs)
+        if can_cache:
+            __log_cache_data[cache_key] = result
+        return result
+
+    return wrapper
+
 
 class LogUtil:
     @classmethod
@@ -77,6 +97,7 @@
     return tool.time_seconds_format(s - 2 - cha)
 
 
+@cache_log
 def load_l2_from_log(date=None):
     today_data = {}
     if date is None:
@@ -121,6 +142,7 @@
 
 
 # 鑾峰彇L2姣忔鎵归噺澶勭悊鏁版嵁鐨勪綅缃寖鍥�
+@cache_log
 def get_l2_process_position(code, date=None):
     if not date:
         date = datetime.datetime.now().strftime("%Y-%m-%d")
@@ -149,6 +171,7 @@
 
 
 # 鑾峰彇L2姣忔鎵归噺澶勭悊鏁版嵁鐨勪綅缃寖鍥�
+@cache_log
 def get_l2_trade_position(code, date=None):
     if not date:
         date = datetime.datetime.now().strftime("%Y-%m-%d")
@@ -197,6 +220,7 @@
 
 
 # 鑾峰彇L2姣忔鎵归噺澶勭悊鏁版嵁鐨勪綅缃寖鍥�
+@cache_log
 def get_real_place_order_positions(code, date=None):
     if not date:
         date = datetime.datetime.now().strftime("%Y-%m-%d")
@@ -405,10 +429,10 @@
             code = data_json["code"]
             if type != type_:
                 continue
-            fdatas.append((time_str,code, type, data_json["data"]))
+            fdatas.append((time_str, code, type, data_json["data"]))
     return fdatas
 
-
+@cache_log
 def load_cancel_buy_reasons(code, date=tool.get_now_date_str()):
     """
     鑾峰彇鎾ゅ崟鍘熷洜
@@ -429,6 +453,7 @@
 
 
 # 鍔犺浇l2璁㈠崟鎴愪氦鏁版嵁
+@cache_log
 def load_huaxin_deal_record(code, date=tool.get_now_date_str()):
     path = f"{constant.get_path_prefix()}/logs/huaxin/l2/transaction_desc.{date}.log"
     # 鏍煎紡:[(璁㈠崟鍙�,鎵嬫暟,寮�濮嬫垚浜ゆ椂闂�,鎴愪氦缁撴潫鏃堕棿,涓嬪崟鎵嬫暟)]
@@ -474,6 +499,7 @@
     return fdatas
 
 
+@cache_log
 def load_kpl_limit_up_records(current_time_str, date=tool.get_now_date_str()):
     """
     鑾峰彇绂荤粰瀹氭椂闂存渶杩戠殑娑ㄥ仠鏁版嵁
@@ -515,6 +541,7 @@
 
 
 # 鍔犺浇鍗庨懌鎴愪氦鐨勫崠鍗�
+@cache_log
 def load_huaxin_transaction_sell_no(code=None, date=tool.get_now_date_str()):
     path = f"{constant.get_path_prefix()}/logs/huaxin/l2/transaction_sell_order.{date}.log"
     fdatas = {}
@@ -606,7 +633,7 @@
                         pass
     return fdatas
 
-
+@cache_log
 def load_huaxin_active_sell_map(date=tool.get_now_date_str()):
     path = f"{constant.get_path_prefix()}/logs/huaxin/trade/l2_active_sell.{date}.log"
     fdatas = {}
@@ -724,8 +751,8 @@
 
 
 if __name__ == '__main__':
-    fdatas = load_kpl_limit_up_records("10:00:00", "2024-10-21")
-    print(fdatas)
+    load_huaxin_transaction_sell_no(code = '2024-11-10')
+    load_huaxin_transaction_sell_no(code='2024-11-10')
     # print(get_h_cancel_compute_info("603912"))
 
     # logger_l2_h_cancel.info("test")

--
Gitblit v1.8.0