From 53755dd13c6c921d3b3a65b1aed54b563f84d152 Mon Sep 17 00:00:00 2001
From: Administrator <admin@example.com>
Date: 星期四, 13 六月 2024 17:34:50 +0800
Subject: [PATCH] L后后半段更新

---
 cancel_strategy/s_l_h_cancel_strategy.py |  143 +++++++++++++++++++++++++++++++++++++----------
 1 files changed, 111 insertions(+), 32 deletions(-)

diff --git a/cancel_strategy/s_l_h_cancel_strategy.py b/cancel_strategy/s_l_h_cancel_strategy.py
index 50e158e..4128085 100644
--- a/cancel_strategy/s_l_h_cancel_strategy.py
+++ b/cancel_strategy/s_l_h_cancel_strategy.py
@@ -672,8 +672,6 @@
                     CodeDataCacheUtil.set_cache(cls.__cancel_l_down_after_place_order_index_cache, code, val)
                 except:
                     pass
-
-
         finally:
             RedisUtils.realse(__redis)
 
@@ -916,42 +914,109 @@
                                 watch_indexes.add(i)
                                 break
                     # 鑾峰彇鐪熷疄涓嬪崟浣嶅悗闈�10绗斿ぇ鍗�
-                    try:
-                        # 鐪熷疄涓嬪崟浣嶇疆鍚庨潰鐨勬暟鎹氨鍙湅澶у崟
-                        MIN_NUM = int(5000 / (float(gpcode_manager.get_limit_up_price(code))))
-                        real_place_order_info = self.__real_place_order_index_dict.get(code)
-                        if real_place_order_info and not real_place_order_info[1]:
-                            # 浠庣湡瀹炰笅鍗曚綅寰�鍚庢壘
-                            after_count = 0
-                            for i in range(real_place_order_info[0] + 1, total_datas[-1]['index'] + 1):
-                                if after_count > 10:
-                                    break
-                                data = total_datas[i]
-                                val = data['val']
-                                # 娑ㄥ仠涔帮紝涓旀湭鎾ゅ崟
-                                if not L2DataUtil.is_limit_up_price_buy(val):
-                                    continue
-                                # 灏忛噾棰濊繃婊�
-                                if val['num'] < MIN_NUM:
-                                    continue
-                                left_count = l2_data_source_util.L2DataSourceUtils.get_limit_up_buy_no_canceled_count_v2(
-                                    code, i,
-                                    total_datas,
-                                    local_today_canceled_buyno_map.get(
-                                        code))
-                                if left_count > 0:
-                                    after_count += 1
-                                    if l2_data_util.is_big_money(val):
-                                        watch_indexes.add(i)
-                                        self.__set_cancel_l_down_after_place_order_index(code, i, after_count - 1)
-                    except Exception as e:
-                        pass
+                    watch_indexes_after = self.__compute_l_down_watch_index_after_real_place_order_index(code)
+                    if watch_indexes_after:
+                        watch_indexes |= watch_indexes_after
                     self.__set_watch_indexes(code, buy_single_index, re_compute, watch_indexes)
                     l2_log.l_cancel_debug(code,
                                           f"璁剧疆鐩戝惉鑼冨洿({msg}){'(閲嶆柊璁$畻)' if re_compute else ''}锛� 鏁版嵁鑼冨洿锛歿re_start_index}-{end_index} 鐩戝惉鑼冨洿-{watch_indexes}")
         except Exception as e:
             l2_log.l_cancel_debug(code, f"璁$畻L鍚庡泭鎷寖鍥村嚭閿欙細{str(e)}")
             async_log_util.exception(logger_l2_l_cancel, e)
+
+    def __need_update_l_down_after(self, code, start_index, end_index):
+        """
+        鏄惁闇�瑕佹洿鏂發鍚庣湡瀹炰笅鍗曚綅缃箣鍚庣殑鍥婃嫭鑼冨洿
+        @param code:
+        @return:
+        """
+        real_place_order_info = self.__real_place_order_index_dict.get(code)
+        if not real_place_order_info or real_place_order_info[1]:
+            return False
+        # 鍒ゆ柇L鍚庢槸鍚﹀寘鍚悗闈㈢殑鏁版嵁
+        watch_indexes_info = self.__get_watch_indexes_cache(code)
+        if not watch_indexes_info:
+            # 娌℃湁鍥婃嫭
+            return False
+        watch_indexes = set([int(i) for i in watch_indexes_info[2]])
+        real_place_order_index = real_place_order_info[0]
+        for index in watch_indexes:
+            if index > real_place_order_index:
+                # L鍚庡悗娈靛凡缁忓泭鎷�
+                return False
+        # 涓嬪崟浣嶇疆涔嬪悗鏁�10绗斿崠鍗�
+        watch_indexes = set()
+        total_datas = local_today_datas.get(code)
+        MIN_NUM = int(5000 / (float(gpcode_manager.get_limit_up_price(code))))
+        MAX_COUNT = 10
+        for i in range(real_place_order_index + 1, end_index):
+            data = total_datas[i]
+            val = data['val']
+            if not L2DataUtil.is_limit_up_price_buy(val):
+                continue
+            if val['num'] < MIN_NUM:
+                continue
+            watch_indexes.add(i)
+            if len(watch_indexes) >= MAX_COUNT:
+                break
+        # 鐪嬮噷闈㈢殑鎾ゅ崟鐜囨槸鍚�
+        if len(watch_indexes) < MAX_COUNT:
+            # 鏁伴噺涓嶅
+            return False
+        # 璁$畻鎾ゅ崟姣斾緥鏄惁瓒冲
+        canceled_buyno_map = local_today_canceled_buyno_map.get(code)
+        cancel_count = 0
+        for index in watch_indexes:
+            # 鏄惁鎾ゅ崟
+            left_count = l2_data_source_util.L2DataSourceUtils.get_limit_up_buy_no_canceled_count_v2(
+                code, index,
+                total_datas,
+                canceled_buyno_map)
+            if left_count <= 0:
+                cancel_count += 1
+        if cancel_count > len(watch_indexes) * 0.5:
+            return True
+        return False
+
+    def __compute_l_down_watch_index_after_real_place_order_index(self, code):
+        """
+        璁$畻L鍚庣湡瀹炰笅鍗曚綅缃箣鍚庣殑鐩戞帶绱㈠紩
+        @return:
+        """
+        watch_indexes = set()
+        total_datas = local_today_datas.get(code)
+        try:
+            # 鐪熷疄涓嬪崟浣嶇疆鍚庨潰鐨勬暟鎹氨鍙湅澶у崟
+            MIN_NUM = int(5000 / (float(gpcode_manager.get_limit_up_price(code))))
+            real_place_order_info = self.__real_place_order_index_dict.get(code)
+            if real_place_order_info and not real_place_order_info[1]:
+                # 浠庣湡瀹炰笅鍗曚綅寰�鍚庢壘
+                after_count = 0
+                for i in range(real_place_order_info[0] + 1, total_datas[-1]['index'] + 1):
+                    if after_count > 10:
+                        break
+                    data = total_datas[i]
+                    val = data['val']
+                    # 娑ㄥ仠涔帮紝涓旀湭鎾ゅ崟
+                    if not L2DataUtil.is_limit_up_price_buy(val):
+                        continue
+                    # 灏忛噾棰濊繃婊�
+                    if val['num'] < MIN_NUM:
+                        continue
+                    left_count = l2_data_source_util.L2DataSourceUtils.get_limit_up_buy_no_canceled_count_v2(
+                        code, i,
+                        total_datas,
+                        local_today_canceled_buyno_map.get(
+                            code))
+                    if left_count > 0:
+                        after_count += 1
+                        if l2_data_util.is_big_money(val):
+                            watch_indexes.add(i)
+                            # 璁板綍绱㈠紩鐨勪綅缃�
+                            self.__set_cancel_l_down_after_place_order_index(code, i, after_count - 1)
+        except Exception as e:
+            pass
+        return watch_indexes
 
     # 璁剧疆鐪熷疄涓嬪崟浣嶇疆
     def set_real_place_order_index(self, code, index, buy_single_index=None, is_default=False):
@@ -1411,6 +1476,20 @@
             except Exception as e:
                 logger_l2_l_cancel.exception(e)
                 raise e
+
+        try:
+            if self.__need_update_l_down_after(code, start_index, end_index):
+                # 鏇存柊鍚庡崐娈�
+                watch_indexes = self.__compute_l_down_watch_index_after_real_place_order_index(code)
+                if watch_indexes:
+                    watch_indexes_info = self.__get_watch_indexes_cache(code)
+                    if watch_indexes_info and watch_indexes_info[2]:
+                        # 娌℃湁鍥婃嫭
+                        watch_indexes|=set(watch_indexes_info[2])
+                        self.__set_watch_indexes(code, watch_indexes_info[0], watch_indexes_info[1], watch_indexes)
+        except Exception as e:
+            l2_log.l_cancel_debug(code,"L鍚庡悗鍗婃璁$畻鍑洪敊锛歿}", str(e))
+
         return can_cancel, cancel_data, extra_msg
 
     def place_order_success(self, code):

--
Gitblit v1.8.0