From 746d76e4320913a5b1dcf41b6234fa58b3726de7 Mon Sep 17 00:00:00 2001
From: Administrator <admin@example.com>
Date: 星期五, 22 十一月 2024 18:41:48 +0800
Subject: [PATCH] 扫入增加大单撤

---
 l2/l2_data_manager_new.py |   97 +++++++++++++++++++++++++++++++++---------------
 1 files changed, 67 insertions(+), 30 deletions(-)

diff --git a/l2/l2_data_manager_new.py b/l2/l2_data_manager_new.py
index 26841ee..897ed08 100644
--- a/l2/l2_data_manager_new.py
+++ b/l2/l2_data_manager_new.py
@@ -30,7 +30,7 @@
     transaction_progress, cancel_buy_strategy, place_order_single_data_manager
 from l2.cancel_buy_strategy import DCancelBigNumComputer, \
     LatestCancelIndexManager, \
-    NewGCancelBigNumComputer, JCancelBigNumComputer, L2DataComputeUtil
+    NewGCancelBigNumComputer, JCancelBigNumComputer, L2DataComputeUtil, RDCancelBigNumComputer
 from l2.l2_data_manager import L2DataException, OrderBeginPosInfo
 from l2.l2_data_util import local_today_datas, L2DataUtil, local_today_num_operate_map, local_today_buyno_map, \
     local_latest_datas, local_today_canceled_buyno_map, local_today_sellno_map
@@ -703,6 +703,18 @@
                                      f"J鎾ゅ嚭閿� 鍙傛暟锛歜uy_single_index-{_buy_single_index} buy_exec_index-{_buy_exec_index} 閿欒鍘熷洜锛歿str(e)}")
             return None, ""
 
+        # RD鎾�
+        def rd_cancel(_buy_single_index, _buy_exec_index):
+            try:
+                b_need_cancel, b_cancel_data, extra_msg = RDCancelBigNumComputer().need_cancel(code, start_index,
+                                                                                               end_index)
+                if b_need_cancel and b_cancel_data:
+                    return b_cancel_data, f"RD鎾�({extra_msg})", trade_constant.CANCEL_TYPE_RD
+            except Exception as e:
+                async_log_util.error(logger_l2_error,
+                                     f"RD鎾ゅ嚭閿� 鍙傛暟锛歜uy_single_index-{_buy_single_index} buy_exec_index-{_buy_exec_index} 閿欒鍘熷洜锛歿str(e)}")
+            return None, "", trade_constant.CANCEL_TYPE_RD
+
         if start_index < 0:
             start_index = 0
 
@@ -717,24 +729,35 @@
         if order_begin_pos.buy_volume_rate is None:
             order_begin_pos.buy_volume_rate = 0.2
         cancel_data, cancel_msg, cancel_type = None, "", None
-        if not cancel_data:
-            cancel_data, cancel_msg = g_cancel(order_begin_pos.buy_single_index, order_begin_pos.buy_exec_index)
-            cancel_type = trade_constant.CANCEL_TYPE_G
-        # 渚濇澶勭悊
-        if not cancel_data:
-            cancel_data, cancel_msg, cancel_type = l_cancel(order_begin_pos.buy_single_index,
-                                                            order_begin_pos.buy_exec_index)
-        # B鎾�
-        if not cancel_data:
-            cancel_data, cancel_msg = b_cancel(order_begin_pos.buy_single_index, order_begin_pos.buy_exec_index)
-            cancel_type = trade_constant.CANCEL_TYPE_G
-        if not cancel_data:
-            cancel_data, cancel_msg = h_cancel(order_begin_pos.buy_single_index, order_begin_pos.buy_exec_index)
-            cancel_type = trade_constant.CANCEL_TYPE_H
-        # J鎾�
-        if not cancel_data:
-            cancel_data, cancel_msg = j_cancel(order_begin_pos.buy_single_index, order_begin_pos.buy_exec_index)
-            cancel_type = trade_constant.CANCEL_TYPE_J
+        if order_begin_pos.mode == OrderBeginPosInfo.MODE_RADICAL:
+
+            if not cancel_data:
+                cancel_data, cancel_msg, cancel_type = rd_cancel(order_begin_pos.buy_single_index,
+                                                                 order_begin_pos.buy_exec_index)
+
+            # 鎵叆涓嬪崟鍙湁L鎾�
+            if not cancel_data:
+                cancel_data, cancel_msg, cancel_type = l_cancel(order_begin_pos.buy_single_index,
+                                                                order_begin_pos.buy_exec_index)
+        else:
+            if not cancel_data:
+                cancel_data, cancel_msg = g_cancel(order_begin_pos.buy_single_index, order_begin_pos.buy_exec_index)
+                cancel_type = trade_constant.CANCEL_TYPE_G
+            # 渚濇澶勭悊
+            if not cancel_data:
+                cancel_data, cancel_msg, cancel_type = l_cancel(order_begin_pos.buy_single_index,
+                                                                order_begin_pos.buy_exec_index)
+            # B鎾�
+            if not cancel_data:
+                cancel_data, cancel_msg = b_cancel(order_begin_pos.buy_single_index, order_begin_pos.buy_exec_index)
+                cancel_type = trade_constant.CANCEL_TYPE_G
+            if not cancel_data:
+                cancel_data, cancel_msg = h_cancel(order_begin_pos.buy_single_index, order_begin_pos.buy_exec_index)
+                cancel_type = trade_constant.CANCEL_TYPE_H
+            # J鎾�
+            if not cancel_data:
+                cancel_data, cancel_msg = j_cancel(order_begin_pos.buy_single_index, order_begin_pos.buy_exec_index)
+                cancel_type = trade_constant.CANCEL_TYPE_J
 
         if cancel_data and not DCancelBigNumComputer().has_auto_cancel_rules(code):
             l2_log.debug(code, "瑙﹀彂鎾ゅ崟锛屾挙鍗曚綅缃細{} 锛屾挙鍗曞師鍥狅細{}", cancel_data["index"], cancel_msg)
@@ -830,6 +853,8 @@
         l2_log.debug(code, "澶勭悊涔板叆鎴愬姛2")
         params_desc = cls.__l2PlaceOrderParamsManagerDict[code].get_buy_rank_desc()
         l2_log.debug(code, params_desc)
+        #################娓呴櫎鏈涓嬪崟鐨勫ぇ鍗曟暟鎹�###############
+        EveryLimitupBigDealOrderManager.clear(code)
         ############璁板綍涓嬪崟鏃剁殑鏁版嵁############
         try:
             jx_blocks, jx_blocks_by = KPLCodeJXBlockManager().get_jx_blocks_cache(
@@ -891,7 +916,7 @@
                 can, need_clear_data, reason, is_valid_exec_index = True, False, "鎵叆涓嬪崟", True
             else:
                 return False
-                #can, need_clear_data, reason, is_valid_exec_index = cls.__can_buy_first(code)
+                # can, need_clear_data, reason, is_valid_exec_index = cls.__can_buy_first(code)
 
             # 鍒犻櫎铏氭嫙涓嬪崟
             if code in cls.unreal_buy_dict:
@@ -1466,7 +1491,7 @@
             # 鏄惁鏄氦鏄撻槦鍒楄Е鍙�
             # 鎵叆涓嬪崟鍙湁L鎾よ兘鎾ゅ崟
             if order_begin_pos and order_begin_pos.mode == OrderBeginPosInfo.MODE_RADICAL and cancel_type not in {
-                trade_constant.CANCEL_TYPE_L_DOWN, trade_constant.CANCEL_TYPE_L}:
+                trade_constant.CANCEL_TYPE_L_DOWN, trade_constant.CANCEL_TYPE_L, trade_constant.CANCEL_TYPE_RD}:
                 l2_log.cancel_debug(code, "鎾ゅ崟涓柇锛屽師鍥狅細{}", "鎵叆涓嬪崟涓嶆槸L鎾�")
                 return False
             # 鍔犵豢鍙湁L鎾�/浜烘挙鐢熸晥
@@ -1620,9 +1645,12 @@
                                                          block_info=radical_result[3])
             if ordered:
                 radical_buy_data_manager.BlockPlaceOrderRecordManager().add_record(code, radical_result[2])
+                # 鐩戝惉澶у崟
+                RDCancelBigNumComputer().set_watch_indexes(code, radical_result[4])
             return
 
-        if RadicalBuyDealCodesManager.radical_buy_blocks_dict.get(code):
+        if RadicalBuyDealCodesManager().get_code_blocks(code):
+            # 宸茬粡鎵叆涓嬭繃鍗�
             return
 
         if not constant.CAN_COMMON_BUY:
@@ -2034,7 +2062,7 @@
         @param code:
         @param start_index:
         @param end_index:
-        @return: (鏄惁鑾峰彇鍒颁俊鍙�, 淇″彿浣嶇疆, 鎵叆鏉垮潡/娑堟伅, 鎵叆鏉垮潡澶у崟娴佸叆淇℃伅)
+        @return: (鏄惁鑾峰彇鍒颁俊鍙�, 淇″彿浣嶇疆, 鎵叆鏉垮潡/娑堟伅, 鎵叆鏉垮潡澶у崟娴佸叆淇℃伅, 闇�瑕佺洃鍚殑澶у崟)
         """
 
         # 婵�杩涗拱淇″彿鐨勬椂闂�
@@ -2042,7 +2070,7 @@
         def __can_order():
             # 鍒ゆ柇鏄惁鏄澘涓婃斁閲�
             if cls.__is_at_limit_up_buy(code, start_index):
-                return False, None, "鏉夸笂鏀鹃噺"
+                return False, None, "鏉夸笂鏀鹃噺", None
             total_datas = local_today_datas[code]
             limit_up_price = gpcode_manager.get_limit_up_price_as_num(code)
             bigger_money = l2_data_util.get_big_money_val(limit_up_price, tool.is_ge_code(code))
@@ -2051,7 +2079,14 @@
 
             if constant.CAN_RADICAL_BUY_NEED_BIG_ORDER_EVERYTIME:
                 # 姣忔涓嬪崟閮介渶瑕佸ぇ鍗�
-                total_deal_money = EveryLimitupBigDealOrderManager.get_big_buy_deal_order_money(code)
+                current_big_order_deal_money_info = EveryLimitupBigDealOrderManager.get_big_buy_deal_order_money_info(
+                    code)
+                if current_big_order_deal_money_info:
+                    total_deal_money = current_big_order_deal_money_info[0]
+                if current_big_order_deal_money_info and tool.trade_time_sub(tool.get_now_time_str(),
+                                                                             current_big_order_deal_money_info[1]) > 60:
+                    # 60s浠ヤ笂鐨勫ぇ鍗曚笉鐪�
+                    total_deal_money = 0
             else:
                 # 鍙渶瑕佹�绘垚浜ょ殑澶у崟
                 total_deal_money = BigOrderDealManager().get_total_buy_money(code)
@@ -2067,7 +2102,8 @@
                 THRESHOLD_MONEY = 2990000
             if total_deal_money >= THRESHOLD_MONEY:
                 min_num = int(5000 / limit_up_price)
-
+            # 闇�瑕佺洃鍚殑澶у崟
+            watch_indexes = set()
             # 鎬诲鎵樺ぇ鍗曢噾棰�
             total_delegating_big_money = 0
             single_index = None
@@ -2086,6 +2122,7 @@
                         order_money = dealing_active_order_info[2] + round(val["price"], 2) * val["num"] * 100
                         if order_money >= bigger_money:
                             total_delegating_big_money += order_money
+                            watch_indexes.add(i)
                             if total_delegating_big_money + total_deal_money >= THRESHOLD_MONEY:
                                 single_index = i
                                 break
@@ -2093,14 +2130,14 @@
                 if int(val["orderNo"]) <= radical_data[1]:
                     # 涓诲姩涔板崟鍚庣殑鏁版嵁涓嶇畻
                     continue
-
+                watch_indexes.add(i)
                 total_delegating_big_money += round(val["price"], 2) * val["num"] * 100
                 if total_delegating_big_money + total_deal_money >= THRESHOLD_MONEY:
                     single_index = i
                     break
             if single_index is not None:
-                return True, single_index, "鏈夊ぇ鍗�"
-            return False, None, "鏃犲ぇ鍗�"
+                return True, single_index, "鏈夊ぇ鍗�", watch_indexes
+            return False, None, "鏃犲ぇ鍗�", watch_indexes
 
         radical_data = RadicalBuyDealCodesManager.buy_by_l2_delegate_expire_time_dict.get(code)
         record_codes = radical_buy_data_manager.BlockPlaceOrderRecordManager().get_codes()
@@ -2144,7 +2181,7 @@
             # 濡傛灉鏉夸笂鏀鹃噺涓嶅彲涔板叆灏遍渶瑕佸垹闄や俊鍙�
             if not constant.CAN_RADICAL_BUY_AT_LIMIT_UP and code in RadicalBuyDealCodesManager.buy_by_l2_delegate_expire_time_dict:
                 RadicalBuyDealCodesManager.buy_by_l2_delegate_expire_time_dict.pop(code)
-            return True, result[1], radical_data[2], radical_data[3]
+            return True, result[1], radical_data[2], radical_data[3], result[3]
         return result
 
     @classmethod

--
Gitblit v1.8.0