From cbe19ea6066a600cbd0b5110db5d43f8252d14a8 Mon Sep 17 00:00:00 2001
From: Administrator <admin@example.com>
Date: 星期四, 13 六月 2024 11:23:53 +0800
Subject: [PATCH] L撤成交进度相关改进

---
 log_module/log_export.py                 |   34 +++++++++--------
 l2/huaxin/huaxin_target_codes_manager.py |    4 +-
 code_attribute/code_data_util.py         |    4 +
 cancel_strategy/s_l_h_cancel_strategy.py |   42 +++++++++++---------
 4 files changed, 46 insertions(+), 38 deletions(-)

diff --git a/cancel_strategy/s_l_h_cancel_strategy.py b/cancel_strategy/s_l_h_cancel_strategy.py
index c16753a..50e158e 100644
--- a/cancel_strategy/s_l_h_cancel_strategy.py
+++ b/cancel_strategy/s_l_h_cancel_strategy.py
@@ -772,7 +772,7 @@
             return
         # 鑾峰彇鎴愪氦杩涘害浣嶄笌鐪熷疄涓嬪崟浣嶇疆
         real_place_order_index_info = self.__real_place_order_index_dict.get(code)
-        last_trade_progress_index = self.__last_trade_progress_dict.get(code)
+        last_trade_progress_index, is_default = TradeBuyQueue().get_traded_index(code)
         if big_sell_info:
             last_trade_progress_index = big_sell_info[0]
 
@@ -959,29 +959,26 @@
         self.__real_place_order_index_dict[code] = (index, is_default)
         RedisUtils.setex_async(self.__db, f"l_cancel_real_place_order_index-{code}", tool.get_expire(),
                                json.dumps((index, is_default)))
+
+        trade_index, is_default = TradeBuyQueue().get_traded_index(code)
+        if trade_index is None:
+            trade_index = 0
+
         if buy_single_index is not None:
-            if code in self.__last_trade_progress_dict:
-                # L鎾や粠鎴愪氦杩涘害浣嶅紑濮嬭绠�
-                self.compute_watch_index(code, buy_single_index,
-                                         self.__last_trade_progress_dict[code], index)
-            else:
-                self.compute_watch_index(code, buy_single_index, buy_single_index, index)
+            # L鍚庢挙浠庢垚浜よ繘搴︿綅寮�濮嬭绠�
+            self.compute_watch_index(code, buy_single_index, trade_index, index)
+        self.__compute_trade_progress_near_by_indexes(code, buy_single_index, trade_index, index)
 
-        if self.__last_trade_progress_dict.get(code):
-            self.__compute_trade_progress_near_by_indexes(code, buy_single_index,
-                                                          self.__last_trade_progress_dict.get(code) + 1, index)
-        else:
-            self.__compute_trade_progress_near_by_indexes(code, buy_single_index, buy_single_index, index)
-
-    # 閲嶆柊璁$畻L涓�
+    # 閲嶆柊璁$畻L鍓�
     def re_compute_l_up_watch_indexes(self, code, buy_single_index):
-        if code not in self.__last_trade_progress_dict:
+        trade_index, is_default = TradeBuyQueue().get_traded_index(code)
+        if trade_index is None:
             return
         if code not in self.__real_place_order_index_dict:
             return
         if code not in self.__last_l_up_compute_info or time.time() - self.__last_l_up_compute_info[code][0] >= 3:
             self.__compute_trade_progress_near_by_indexes(code, buy_single_index,
-                                                          self.__last_trade_progress_dict.get(code) + 1,
+                                                          trade_index + 1,
                                                           self.__real_place_order_index_dict.get(code)[0])
 
     # 璁$畻鑼冨洿鍐呯殑鎴愪氦浣嶄复杩戞湭鎾ゅぇ鍗�
@@ -1043,7 +1040,10 @@
             if not l_down_cancel_info:
                 return
 
-            trade_progress = self.__last_trade_progress_dict.get(code)
+            trade_progress, is_default = TradeBuyQueue().get_traded_index(code)
+            if trade_progress is None:
+                trade_progress = 0
+
             if trade_progress is None:
                 return
 
@@ -1319,7 +1319,9 @@
             if rate >= thresh_cancel_rate:
                 # 璁$畻鎴愪氦杩涘害浣嶇疆鍒板綋鍓嶄笅鍗曚綅缃殑绾拱棰�
                 real_place_order_index_info = self.__real_place_order_index_dict.get(code)
-                trade_progress_index = self.__last_trade_progress_dict.get(code)
+                trade_progress_index, is_default = TradeBuyQueue().get_traded_index(code)
+                if trade_progress_index is None:
+                    trade_progress_index = 0
                 if real_place_order_index_info and trade_progress_index:
                     total_num = 0
                     thresh_hold_money = l2_trade_factor.L2PlaceOrderParamsManager.get_base_m_val(code)
@@ -1356,7 +1358,9 @@
         watch_indexes_info = self.__get_watch_indexes_cache(code)
         if not watch_indexes_info:
             return True
-        trade_index = self.__last_trade_progress_dict.get(code)
+        trade_index, is_default = TradeBuyQueue().get_traded_index(code)
+        if trade_index is None:
+            trade_index = 0
         if trade_index is None:
             return True
         # 璁$畻宸茬粡鎴愪氦鐨勬瘮渚�
diff --git a/code_attribute/code_data_util.py b/code_attribute/code_data_util.py
index 7abbee5..f21e00e 100644
--- a/code_attribute/code_data_util.py
+++ b/code_attribute/code_data_util.py
@@ -84,7 +84,9 @@
         @return:
         """
         fresults = cls.__mysql.select_one(f"select count(code) from kpl_zylt_volume where update_time >= '{tool.get_now_date_str()}'")
-        return fresults[0]
+        if fresults:
+            return fresults[0]
+        return 0
 
 
 
diff --git a/l2/huaxin/huaxin_target_codes_manager.py b/l2/huaxin/huaxin_target_codes_manager.py
index af9695c..edcd767 100644
--- a/l2/huaxin/huaxin_target_codes_manager.py
+++ b/l2/huaxin/huaxin_target_codes_manager.py
@@ -10,7 +10,7 @@
 from code_attribute.code_data_util import ZYLTGBUtil
 from db import redis_manager_delegate as redis_manager
 from log_module import async_log_util
-from log_module.log import logger_l2_codes_subscript
+from log_module.log import logger_l2_codes_subscript, logger_debug
 from third_data import kpl_data_manager, kpl_api
 from trade import current_price_process_manager
 from utils import tool, global_util, init_data_util
@@ -144,7 +144,7 @@
             tick_datas = first_target_code_data_processor.process_first_codes_datas(flist, request_id)
             current_price_process_manager.accept_prices(tick_datas, request_id)
         except Exception as e:
-            logging.exception(e)
+            logger_debug.exception(e)
 
 
 if __name__ == "__main__":
diff --git a/log_module/log_export.py b/log_module/log_export.py
index 08e7b6d..2696945 100644
--- a/log_module/log_export.py
+++ b/log_module/log_export.py
@@ -123,22 +123,24 @@
     if not date:
         date = datetime.datetime.now().strftime("%Y-%m-%d")
     pos_list = []
-    with open("{}/logs/gp/l2/l2_process.{}.log".format(constant.get_path_prefix(), date), mode='r',
-              encoding="utf-8") as f:
-        while True:
-            line = f.readline()
-            if not line:
-                break
-            if line.find("code:{}".format(code)) < 0:
-                continue
-            time_ = __get_log_time(line)
-            line = line[line.find("澶勭悊鏁版嵁鑼冨洿") + len("澶勭悊鏁版嵁鑼冨洿") + 1:line.find("澶勭悊鏃堕棿")].strip()
-            if len(pos_list) == 0 or pos_list[-1][1] < int(line.split("-")[0]):
-                if int("093000") <= int(time_.replace(":", "")) <= int("150000"):
-                    try:
-                        pos_list.append((int(line.split("-")[0]), int(line.split("-")[1])))
-                    except Exception as e:
-                        logging.exception(e)
+    path_ = "{}/logs/gp/l2/l2_process.{}.log".format(constant.get_path_prefix(), date)
+    if os.path.exists(path_):
+        with open(path_, mode='r',
+                  encoding="utf-8") as f:
+            while True:
+                line = f.readline()
+                if not line:
+                    break
+                if line.find("code:{}".format(code)) < 0:
+                    continue
+                time_ = __get_log_time(line)
+                line = line[line.find("澶勭悊鏁版嵁鑼冨洿") + len("澶勭悊鏁版嵁鑼冨洿") + 1:line.find("澶勭悊鏃堕棿")].strip()
+                if len(pos_list) == 0 or pos_list[-1][1] < int(line.split("-")[0]):
+                    if int("093000") <= int(time_.replace(":", "")) <= int("150000"):
+                        try:
+                            pos_list.append((int(line.split("-")[0]), int(line.split("-")[1])))
+                        except Exception as e:
+                            logging.exception(e)
     return pos_list
 
 

--
Gitblit v1.8.0