From e23a2fc711caf409359648572828111981ec3681 Mon Sep 17 00:00:00 2001
From: Administrator <admin@example.com>
Date: 星期二, 15 十月 2024 18:13:20 +0800
Subject: [PATCH] 更改买入票的单价上限/板块更新

---
 l2/l2_data_manager_new.py |   87 ++++++++++++++++++++++++-------------------
 1 files changed, 49 insertions(+), 38 deletions(-)

diff --git a/l2/l2_data_manager_new.py b/l2/l2_data_manager_new.py
index e6b4b57..13187da 100644
--- a/l2/l2_data_manager_new.py
+++ b/l2/l2_data_manager_new.py
@@ -340,11 +340,12 @@
         if order_begin_pos.mode != OrderBeginPosInfo.MODE_RADICAL:
             # 闈炴壂鍏ヤ笅鍗曡鍒ゆ柇鎵ц浣嶇疆涓庣湡瀹炰笅鍗曚綅鐨勯棿闅旀椂闂�
             total_datas = local_today_datas.get(code)
-            if tool.trade_time_sub_with_ms(L2DataUtil.get_time_with_ms(total_datas[index]["val"]), L2DataUtil.get_time_with_ms(total_datas[order_begin_pos.buy_exec_index]["val"])) > 2000:
+            if tool.trade_time_sub_with_ms(L2DataUtil.get_time_with_ms(total_datas[index]["val"]),
+                                           L2DataUtil.get_time_with_ms(
+                                               total_datas[order_begin_pos.buy_exec_index]["val"])) > 2000:
                 L2TradeDataProcessor.cancel_buy(code, f"鐪熷疄涓嬪崟浣�({index})涓庢墽琛屼綅({order_begin_pos.buy_exec_index})鐩稿樊2s浠ヤ笂",
                                                 cancel_type=trade_constant.CANCEL_TYPE_F)
                 return
-
 
     # 澶勭悊鍗庨懌L2鏁版嵁
     @classmethod
@@ -724,9 +725,7 @@
 
     @classmethod
     def start_buy(cls, code, last_data, last_data_index, is_first_code):
-        pre_result =  cls.__is_pre_can_buy(code)
-        if pre_result[0]:
-            cls.__buy(code, 0, last_data, last_data_index, is_first_code)
+        cls.__buy(code, 0, last_data, last_data_index, is_first_code)
 
     @classmethod
     def get_active_buy_blocks(cls, code):
@@ -760,6 +759,9 @@
 
     @classmethod
     def __buy(cls, code, capture_timestamp, last_data, last_data_index, is_first_code):
+        pre_result = cls.__is_pre_can_buy(code)
+        if not pre_result[0]:
+            return False
         # 娣诲姞涔板叆閿�
         if code not in cls.__buy_lock_dict:
             cls.__buy_lock_dict[code] = threading.Lock()
@@ -940,7 +942,7 @@
 
         pre_result = cls.__is_pre_can_buy(code)
         if not pre_result[0]:
-            return pre_result[0],pre_result[1], pre_result[2], pre_result[3]
+            return pre_result[0], pre_result[1], pre_result[2], pre_result[3]
 
         now_time_int = int(tool.get_now_time_str().replace(":", ""))
         if 130100 >= now_time_int >= 112900 or now_time_int < 93100:
@@ -1008,7 +1010,8 @@
         # ------------鎸傚崟鏃堕棿绾︽潫----------
         order_begin_pos = cls.__get_order_begin_pos(
             code)
-        if not trade_result_manager.can_place_order_for_cancel_time(code, total_data[order_begin_pos.buy_exec_index]) and not gpcode_manager.GreenListCodeManager().is_in_cache(code):
+        if not trade_result_manager.can_place_order_for_cancel_time(code, total_data[
+            order_begin_pos.buy_exec_index]) and not gpcode_manager.GreenListCodeManager().is_in_cache(code):
             return False, True, f"璺濈涓婃鎸傚崟灏忎簬鏃堕棿闄愬埗", True
 
         # ------------鏉垮潡绾︽潫-------------
@@ -1356,41 +1359,49 @@
 
     @classmethod
     def cancel_buy(cls, code, msg=None, source="l2", cancel_index=None, cancel_type=None):
-        # 鏄惁鏄氦鏄撻槦鍒楄Е鍙�
+
+        finally_can_cancel = True
+        total_datas = local_today_datas.get(code)
         order_begin_pos = cls.__get_order_begin_pos(
             code)
-        # 鎵叆涓嬪崟鍙湁L鎾よ兘鎾ゅ崟
-        if order_begin_pos and order_begin_pos.mode == OrderBeginPosInfo.MODE_RADICAL and cancel_type not in {
-            trade_constant.CANCEL_TYPE_L, trade_constant.CANCEL_TYPE_L_UP, trade_constant.CANCEL_TYPE_L_DOWN}:
-            l2_log.cancel_debug(code, "鎾ゅ崟涓柇锛屽師鍥狅細{}", "鎵叆涓嬪崟涓嶆槸L鎾�")
-            return False
-        # 鍔犵豢鍙湁L鎾ょ敓鏁�
-        if gpcode_manager.GreenListCodeManager().is_in_cache(code):
-            if cancel_type not in { trade_constant.CANCEL_TYPE_L, trade_constant.CANCEL_TYPE_L_UP, trade_constant.CANCEL_TYPE_L_DOWN}:
-                l2_log.cancel_debug(code, "鎾ゅ崟涓柇锛屽師鍥狅細{}", "鍔犵豢涓嶆槸L鎾�")
+        if cancel_type != trade_constant.CANCEL_TYPE_HUMAN:
+            # 鏄惁鏄氦鏄撻槦鍒楄Е鍙�
+            # 鎵叆涓嬪崟鍙湁L鎾よ兘鎾ゅ崟
+            if order_begin_pos and order_begin_pos.mode == OrderBeginPosInfo.MODE_RADICAL and cancel_type not in {
+                trade_constant.CANCEL_TYPE_L, trade_constant.CANCEL_TYPE_L_UP, trade_constant.CANCEL_TYPE_L_DOWN}:
+                l2_log.cancel_debug(code, "鎾ゅ崟涓柇锛屽師鍥狅細{}", "鎵叆涓嬪崟涓嶆槸L鎾�")
                 return False
-        total_datas = local_today_datas.get(code)
-        if not total_datas:
-            return False
-        if source == "trade_queue":
-            # 浜ゆ槗闃熷垪瑙﹀彂鐨勯渶瑕佷笅鍗曞悗5s
-            if order_begin_pos.buy_exec_index is not None and order_begin_pos.buy_exec_index > 0:
-                now_time_str = tool.get_now_time_str()
-                if tool.trade_time_sub(now_time_str, total_datas[order_begin_pos.buy_exec_index]["val"]["time"]) < 5:
+            # 鍔犵豢鍙湁L鎾�/浜烘挙鐢熸晥
+            if gpcode_manager.GreenListCodeManager().is_in_cache(code):
+                if cancel_type not in {trade_constant.CANCEL_TYPE_L, trade_constant.CANCEL_TYPE_L_UP,
+                                       trade_constant.CANCEL_TYPE_L_DOWN}:
+                    l2_log.cancel_debug(code, "鎾ゅ崟涓柇锛屽師鍥狅細{}", "鍔犵豢涓嶆槸L鎾�")
                     return False
 
-        if code in cls.unreal_buy_dict:
-            cls.unreal_buy_dict.pop(code)
-            # 鍙栨秷涔板叆鏍囪瘑
-            trade_result_manager.virtual_cancel_success(code, order_begin_pos.buy_single_index,
-                                                        order_begin_pos.buy_exec_index, total_datas)
-        else:
-            can_cancel, reason = cls.__can_cancel(code)
-            if not can_cancel and cancel_type != trade_constant.CANCEL_TYPE_HUMAN:
-                # 涓嶈兘鍙栨秷涓斾笉鏄汉宸ユ挙鍗�
-                l2_log.cancel_debug(code, "鎾ゅ崟涓柇锛屽師鍥狅細{}", reason)
-                l2_log.debug(code, "鎾ゅ崟涓柇锛屽師鍥狅細{}", reason)
+            if not total_datas:
                 return False
+            if source == "trade_queue":
+                # 浜ゆ槗闃熷垪瑙﹀彂鐨勯渶瑕佷笅鍗曞悗5s
+                if order_begin_pos.buy_exec_index is not None and order_begin_pos.buy_exec_index > 0:
+                    now_time_str = tool.get_now_time_str()
+                    if tool.trade_time_sub(now_time_str,
+                                           total_datas[order_begin_pos.buy_exec_index]["val"]["time"]) < 5:
+                        return False
+
+            if code in cls.unreal_buy_dict:
+                cls.unreal_buy_dict.pop(code)
+                # 鍙栨秷涔板叆鏍囪瘑
+                trade_result_manager.virtual_cancel_success(code, order_begin_pos.buy_single_index,
+                                                            order_begin_pos.buy_exec_index, total_datas)
+            else:
+                can_cancel, reason = cls.__can_cancel(code)
+                if not can_cancel:
+                    # 涓嶈兘鍙栨秷涓斾笉鏄汉宸ユ挙鍗�
+                    l2_log.cancel_debug(code, "鎾ゅ崟涓柇锛屽師鍥狅細{}", reason)
+                    l2_log.debug(code, "鎾ゅ崟涓柇锛屽師鍥狅細{}", reason)
+                    return False
+
+        if finally_can_cancel:
             if cancel_index is None:
                 cancel_index = total_datas[-1]["index"]
             cls.__LatestCancelIndexManager.set_latest_cancel_index(code, cancel_index)
@@ -1404,7 +1415,7 @@
                 trade_result_manager.real_cancel_success(code, order_begin_pos.buy_single_index,
                                                          order_begin_pos.buy_exec_index, total_datas,
                                                          from_real_cancel=True)
-        l2_log.debug(code, "鎵ц鎾ゅ崟缁撴潫锛屽師鍥狅細{}", msg)
+            l2_log.debug(code, "鎵ц鎾ゅ崟缁撴潫锛屽師鍥狅細{}", msg)
         return True
 
     # 铏氭嫙涓嬪崟
@@ -1502,7 +1513,7 @@
                                                      max_num_set=set(),
                                                      buy_volume_rate=buy_volume_rate,
                                                      mode=OrderBeginPosInfo.MODE_RADICAL,
-                                                     mode_desc="婵�杩涗拱鍏�",
+                                                     mode_desc="鎬绘姏鍘嬪皬鎵叆",
                                                      sell_info=sell_info,
                                                      threshold_money=threshold_money)
             order_begin_pos_info.at_limit_up = cls.__is_at_limit_up_buy(code)

--
Gitblit v1.8.0