From b9404847333a972b55766924ad3aa41aac5fd4f4 Mon Sep 17 00:00:00 2001
From: Administrator <admin@example.com>
Date: 星期四, 15 八月 2024 18:30:07 +0800
Subject: [PATCH] 下单条件修改

---
 l2/l2_data_manager_new.py |  135 ++++++++++++++++++++------------------------
 1 files changed, 61 insertions(+), 74 deletions(-)

diff --git a/l2/l2_data_manager_new.py b/l2/l2_data_manager_new.py
index 50cd000..5c15e67 100644
--- a/l2/l2_data_manager_new.py
+++ b/l2/l2_data_manager_new.py
@@ -260,6 +260,9 @@
     # 涓嬫涔扮殑鏃堕棿
     __next_buy_time_dict = {}
 
+    # 涓柇鏈壒娆′拱鍏ユ暟鎹鐞�
+    __break_current_batch_data_for_buy_dict = {}
+
     # 鑾峰彇浠g爜璇勫垎
     @classmethod
     def get_code_scores(cls):
@@ -518,6 +521,7 @@
     # 澶勭悊鏈寕鍗�
     @classmethod
     def __process_not_order(cls, code, start_index, end_index, capture_time, is_first_code):
+        cls.__break_current_batch_data_for_buy_dict[code] = False
         __start_time = round(t.time() * 1000)
         # 鑾峰彇闃堝��
         threshold_money, msg = cls.__get_threshmoney(code)
@@ -728,6 +732,8 @@
                 l2_log.debug(code, "涓嶅彲浠ヤ笅鍗曪紝鍘熷洜锛歿}", reason)
                 trade_record_log_util.add_cant_place_order_log(code, reason)
                 if need_clear_data:
+                    # 涓柇涔板叆
+                    cls.__break_current_batch_data_for_buy_dict[code] = True
                     trade_result_manager.real_cancel_success(code, order_begin_pos.buy_single_index,
                                                              order_begin_pos.buy_exec_index,
                                                              local_today_datas.get(code))
@@ -910,59 +916,67 @@
                 if int(limit_up_time.replace(":", "")) < int("093000"):
                     return False, True, f"涓婅瘉寮�涓�09:32涔嬪墠涓嶄笅鍗�"
 
+        # ------------鎸傚崟鏃堕棿绾︽潫----------
         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]):
             return False, True, f"璺濈涓婃鎸傚崟灏忎簬鏃堕棿闄愬埗"
+
+        # ------------鏉垮潡绾︽潫-------------
+        if not cls.__WantBuyCodesManager.is_in_cache(code):
+            # 鎯充拱鍗曟棤鏉垮潡绾︽潫
+            block_buy_result = buy_strategy_util.is_block_can_buy(code, cls.__get_can_buy_block(code))
+            if not block_buy_result[0]:
+                return block_buy_result
+
         if constant.L2_SOURCE_TYPE == constant.L2_SOURCE_TYPE_HUAXIN:
+            # ---------------------鍒ゆ柇鏄惁涓烘澘涓婃斁閲�----------------------
             trade_price = current_price_process_manager.get_trade_price(code)
             if trade_price is None:
                 return False, True, f"灏氭湭鑾峰彇鍒板綋鍓嶆垚浜や环"
             # 鍒ゆ柇鏄惁涓烘澘涓婃斁閲忥細
             # 1.褰撳墠鎴愪氦浠蜂负娑ㄥ仠浠�
-            # 2.鎬诲崠棰濅负0
+            # 2.璺濈鏈�杩戠殑闈炴澘涓婃垚浜ょ殑鏃堕棿澶т簬涓�涓槇鍊�
             if abs(limit_up_price - float(trade_price)) < 0.001:
                 # 鑾峰彇鏈�杩戠殑闈炴定鍋滀环鎴愪氦鏃堕棿
-                not_limit_up_info = current_price_process_manager.get_trade_not_limit_up_info(code)
-                if not not_limit_up_info or tool.trade_time_sub(total_data[-1]['val']['time'],
-                                                                not_limit_up_info[1]) > 10:
-                    # 鑾峰彇鏈�杩�2s鐨勬垚浜�
-                    deal_list = HuaXinSellOrderStatisticManager.get_latest_2s_continue_deal_volumes(code)
-                    total_deal_volume = 0
-                    if deal_list:
-                        total_deal_volume = sum([x[1] for x in deal_list])
-                    total_deal_money = int(total_deal_volume * float(limit_up_price))
-                    # 鑾峰彇涔�1鐨勫皝鍗曢
+                not_limit_up_trade_time_with_ms = current_price_process_manager.get_trade_not_limit_up_time_with_ms(
+                    code)
+                threshold_time_space = buy_condition_util.get_cancel_and_buy_space_time(code)
+                if not not_limit_up_trade_time_with_ms or tool.trade_time_sub_with_ms(
+                        L2DataUtil.get_time_with_ms(total_data[-1]['val']),
+                        not_limit_up_trade_time_with_ms) >= threshold_time_space:
+                    # 鍒ゆ柇鎴愪氦杩涘害鍒板綋鍓嶆暟鎹殑绗旀暟锛屽鏋滃皯浜�10绗斾笖杩樻湁鏈垚浜ょ殑澶у崟锛�>=299锛夊氨鍙互涓嬪崟
+                    trade_index, is_default = cls.__TradeBuyQueue.get_traded_index(code)
+                    if trade_index is None:
+                        trade_index = 0
+                    can_place_order, msg = buy_strategy_util.is_near_by_trade_index(code, trade_index)
+                    if not can_place_order:
+                        try:
+                            # 涓嶈兘涓嬪崟锛屽垽鏂皬缇ゆ挙鏄惁鍙互涓�
+                            if buy_strategy_util.is_has_small_batch_cancel(code, trade_index,
+                                                                           order_begin_pos.buy_single_index):
+                                # 鍒ゆ柇鎾ゅ崟姣斾緥鏄惁瓒冲
+                                if not buy_strategy_util.is_cancel_rate_reieved(code, 0.69, trade_index,
+                                                                                order_begin_pos.buy_single_index):
+                                    return False, True, f"鏉夸笂鏀鹃噺璺濈杩�({not_limit_up_trade_time_with_ms})锛屾湁灏忕兢鎾�, 鏁翠綋鎾ゅ崟姣斾緥涓嶈冻锛坽trade_index}-{order_begin_pos.buy_single_index}锛�"
+                            else:
+                                return False, True, f"鏉夸笂鏀鹃噺璺濈杩�({not_limit_up_trade_time_with_ms})锛屾病鏈夊皬缇ゆ挙锛坽trade_index}-{order_begin_pos.buy_single_index}锛�"
+                        except Exception as e:
+                            l2_log.info(code, logger_l2_error, f"鏉夸笂鏀鹃噺({not_limit_up_trade_time_with_ms})涓嶈冻寮傚父锛歿str(e)}")
+                            return False, True, f"鏉夸笂鏀鹃噺璁$畻寮傚父"
+
+                    # -------鏄惁璺濈鎴愪氦杩涘害浣嶅お杩�--------
                     buy1_money = code_price_manager.Buy1PriceManager().get_latest_buy1_money(code)
                     buy1_price = code_price_manager.Buy1PriceManager().get_buy1_price(code)
                     if buy1_price and abs(limit_up_price - buy1_price) > 0.0001:
                         # 涔�1鏈定鍋�
                         buy1_money = 0
-
                     if not buy1_money:
                         buy1_money = 1
-                    deal_rate = round(total_deal_money / buy1_money, 2)
-                    if deal_rate < 0.5:
-                        # 鍒ゆ柇鎴愪氦杩涘害鍒板綋鍓嶆暟鎹殑绗旀暟锛屽鏋滃皯浜�10绗斾笖杩樻湁鏈垚浜ょ殑澶у崟锛�>=299锛夊氨鍙互涓嬪崟
-                        trade_index, is_default = cls.__TradeBuyQueue.get_traded_index(code)
-                        if trade_index is None:
-                            trade_index = 0
-                        can_place_order, msg = buy_strategy_util.is_near_by_trade_index(code, trade_index)
-                        if not can_place_order:
-                            try:
-                                # 涓嶈兘涓嬪崟锛屽垽鏂皬缇ゆ挙鏄惁鍙互涓�
-                                if buy_strategy_util.is_has_small_batch_cancel(code, trade_index,
-                                                                               order_begin_pos.buy_single_index):
-                                    # 鍒ゆ柇鎾ゅ崟姣斾緥鏄惁瓒冲
-                                    if not buy_strategy_util.is_cancel_rate_reieved(code, 0.69, trade_index,
-                                                                                    order_begin_pos.buy_single_index):
-                                        return False, True, f"鏉夸笂鏀鹃噺涓嶈冻锛屾湁灏忕兢鎾�, 鏁翠綋鎾ゅ崟姣斾緥涓嶈冻锛坽trade_index}-{order_begin_pos.buy_single_index}锛�"
-                                else:
-                                    return False, True, f"鏉夸笂鏀鹃噺涓嶈冻锛屼笖娌℃湁灏忕兢鎾わ紙{trade_index}-{order_begin_pos.buy_single_index}锛�"
-                            except Exception as e:
-                                l2_log.info(code, logger_l2_error, "鏉夸笂鏀鹃噺涓嶈冻寮傚父锛歿}", str(e))
-                                return False, True, f"鏉夸笂鏀鹃噺涓嶈冻"
-            # 涓婅瘉涓嬪崟闇�瑕佹湁鎴愪氦澶у崟锛堝寘鍚富鍔ㄤ拱涓庤鍔ㄤ拱锛夋垨鑰呮寕涔扮殑澶у崟
+                    if buy_strategy_util.is_far_away_from_trade_index(code, trade_index, buy1_money):
+                        return False, True, f"璺濈鎴愪氦杩涘害浣嶅お杩滐細鎴愪氦杩涘害-{trade_index} 涔�1-{buy1_money}"
+
+            # ------------------涓婅瘉涓嬪崟闇�瑕佹湁鎴愪氦澶у崟锛堝寘鍚富鍔ㄤ拱涓庤鍔ㄤ拱锛夋垨鑰呮寕涔扮殑澶у崟-----------------
             if tool.is_sh_code(code):
                 deal_big_order_count = BigOrderDealManager().get_total_buy_count(code)
                 if deal_big_order_count < 1:
@@ -983,7 +997,7 @@
                     if left_count < 1:
                         return False, False, f"娌℃湁宸叉寕鎴栬�呮垚浜ょ殑澶у崟"
             place_order_count = trade_data_manager.PlaceOrderCountManager().get_place_order_count(code)
-            # 绗竴鍜岀浜屾涓嬪崟閮藉繀椤昏鏈夎嚦灏戜竴绗旀湭鎴愪氦鐨勫ぇ鍗�
+            # ------------------绗竴鍜岀浜屾涓嬪崟閮藉繀椤昏鏈夎嚦灏戜竴绗旀湭鎴愪氦鐨勫ぇ鍗�--------------------------
             # 璁$畻澶у崟
             total_datas = local_today_datas.get(code)
             if place_order_count < 2:
@@ -997,47 +1011,16 @@
                 if left_count < 1:
                     return False, False, f"绗瑊place_order_count + 1}涓嬪崟鏃犲緟鎴愪氦鐨勫ぇ鍗�"
 
-            # 鎵ц浣嶉偅涓�鎴虫暟鎹灏忎簬20鏉℃暟鎹�
-            THRESHOLD_BUY_COUNT = 20
-            buy_count = 0
-            min_num = int(5000 / limit_up_price)
+            # -------鍒ゆ柇鏄惁鏄噺鍖栦笅鍗曪紝濡傛灉鏄氨涓嶈窡鍒颁笅鍗�--------
+            # 閲嶈锛氶噺鍖栦笅鍗曚細澧炲姞涓嬪崟娆℃暟锛屾澘鍧椾笅鍗曚腑鏈変笅鍗曟鏁扮殑浣跨敤锛屾墍浠ユ澘鍧楅渶瑕佸湪閲忓寲鍒ゆ柇涔嬪墠
+            # 鍙湁鏉垮潡婊¤冻涓嬪崟涔嬪悗鎵嶈兘鍒ゆ柇鍏跺畠鏉′欢
             range_indexes = cls.__processing_data_indexes.get(code)
-            trade_index, is_default = transaction_progress.TradeBuyQueue().get_traded_index(code)
-            if trade_index is None:
-                trade_index = 0
             if range_indexes:
-                # 鑾峰彇鎴愪氦杩涘害浣�
-                for i in range(range_indexes[0], range_indexes[1] + 1):
-                    val = total_datas[i]["val"]
-                    if not L2DataUtil.is_limit_up_price_buy(val):
-                        continue
-                    if val["num"] < min_num:
-                        continue
-                    buy_count += 1
-                    if buy_count > THRESHOLD_BUY_COUNT:
-                        break
-            if buy_count > THRESHOLD_BUY_COUNT:
-                # 鍒ゆ柇鏄惁涓洪噺鍖�
-                time_as_ms = tool.trade_time_sub_with_ms(
-                    L2DataUtil.get_time_with_ms(total_datas[range_indexes[1]]["val"]),
-                    L2DataUtil.get_time_with_ms(total_datas[range_indexes[0]]["val"]))
-                if time_as_ms <= 10 if tool.is_sz_code(code) else 100:
-                    # 娣辫瘉10ms鍐咃紝涓婅瘉100ms鍐呭氨鍒ゅ畾涓洪噺鍖�
-                    HuaXinSellOrderStatisticManager.clear_latest_deal_volume(code)
-                    cls.__next_buy_time_dict[code] = t.time() + buy_condition_util.get_cancel_and_buy_space_time(
-                        code) / 1000
-                    # 濡傛灉鏄娆′笅鍗曪紝澧炲姞涓�娆′笅鍗曟鏁�
-                    place_order_count = trade_data_manager.PlaceOrderCountManager().get_place_order_count(code)
-                    if place_order_count == 0:
-                        trade_data_manager.PlaceOrderCountManager().place_order(code)
-                    return False, True, f"鎵ц浣嶆壒娆℃暟鎹噺({buy_count})澶т簬{THRESHOLD_BUY_COUNT}  {range_indexes[0]}-{range_indexes[1]}"
-            # 鏆傛椂娉ㄩ噴鎯充拱鍗曞姛鑳�
-        if not cls.__WantBuyCodesManager.is_in_cache(code):
-            # if cls.__TradeTargetCodeModeManager.get_mode_cache() == TradeTargetCodeModeManager.MODE_ONLY_BUY_WANT_CODES:
-            #     return False, True, f"鍙拱鎯充拱鍗曚腑鐨勪唬鐮�"
-            return cls.can_buy_first_new(code, limit_up_price)
-        else:
-            return True, False, "鍦ㄦ兂涔板崟涓�"
+                is_quantization_result = buy_strategy_util.is_quantization(code, range_indexes[0], range_indexes[1])
+                if is_quantization_result[0]:
+                    cls.__next_buy_time_dict[code] = is_quantization_result[1]
+                    return False, True, is_quantization_result[2]
+        return True, False, "婊¤冻涓嬪崟鏉′欢"
 
     # 鑾峰彇鍙互涔扮殑鏉垮潡
     @classmethod
@@ -1348,6 +1331,10 @@
                             is_first_code,
                             new_add=True):
 
+        # 涓柇褰撳墠鎵规涔板叆鏁版嵁澶勭悊
+        if cls.__break_current_batch_data_for_buy_dict.get(code):
+            return
+
         # 鍒ゆ柇涓嬫涔板叆鏃堕棿鏄惁姝g‘
         if code in cls.__next_buy_time_dict and t.time() < cls.__next_buy_time_dict[code]:
             return

--
Gitblit v1.8.0