From 2f2516749615da866e96d8d24e499b7ecbb63a3e Mon Sep 17 00:00:00 2001
From: Administrator <admin@example.com>
Date: 星期一, 23 六月 2025 12:28:52 +0800
Subject: [PATCH] 默认交易模式变更/真实下单位置计算位置修改

---
 l2/l2_data_manager_new.py |  296 ++++++++++++++++++++++++++++++++++++++++++++++++-----------
 1 files changed, 241 insertions(+), 55 deletions(-)

diff --git a/l2/l2_data_manager_new.py b/l2/l2_data_manager_new.py
index eaba884..63c53cd 100644
--- a/l2/l2_data_manager_new.py
+++ b/l2/l2_data_manager_new.py
@@ -190,7 +190,8 @@
             # 濡傛灉鏄定鍋滀拱鎾や俊鍙烽渶瑕佺湅鏁版嵁浣嶇疆鏄惁姣斿紑濮嬪鐞嗘椂闂存棭
             if L2DataUtil.is_limit_up_price_buy_cancel(data["val"]):
                 # 鑾峰彇涔板叆淇″彿
-                buy_index = l2_data_source_util.L2DataSourceUtils.get_buy_index_with_cancel_data_v2(total_datas[i], buyno_map)
+                buy_index = l2_data_source_util.L2DataSourceUtils.get_buy_index_with_cancel_data_v2(total_datas[i],
+                                                                                                    buyno_map)
                 if buy_index is not None and buy_index < begin_pos:
                     continue
 
@@ -216,6 +217,70 @@
 
         # print("m鍊煎ぇ鍗曡绠楄寖鍥达細{}-{}  鏃堕棿锛歿}".format(max(start_index, processed_index), end_index,
         #                                      round(t.time() * 1000) - start_time))
+
+
+class HumanRadicalBuySingleManager:
+    """
+    浜轰负涔板叆绠$悊
+    """
+    # 浜轰负涓嬪崟鏍囪:{"浠g爜":(淇″彿鏃堕棿, 闂撮殧鏃堕棿,淇″彿鎴嚦鏃堕棿, radical_result)}
+    __human_radical_buy_mark_info = {}
+
+    @classmethod
+    def add_single(cls, code, latest_data, radical_result):
+        """
+        娣诲姞涔板叆淇″彿
+        @param code:
+        @param latest_data:
+        @param radical_result:
+        @return:
+        """
+        start_time_with_ms = L2DataUtil.get_time_with_ms(latest_data["val"])
+        if tool.is_sh_code(code):
+            cls.__human_radical_buy_mark_info[code] = (
+                start_time_with_ms, 400, tool.trade_time_add_millionsecond(start_time_with_ms, 3000), radical_result)
+        else:
+            cls.__human_radical_buy_mark_info[code] = (
+                start_time_with_ms, 30, tool.trade_time_add_millionsecond(start_time_with_ms, 2000), radical_result)
+
+    @classmethod
+    def remove_single(cls, code):
+        """
+        绉婚櫎淇″彿
+        @param code:
+        @return:
+        """
+        if code in cls.__human_radical_buy_mark_info:
+            cls.__human_radical_buy_mark_info.pop(code)
+
+    @classmethod
+    def has_single(cls, code):
+        """
+        鏄惁鏈変俊鍙�
+        @param code:
+        @return:
+        """
+        if code in cls.__human_radical_buy_mark_info:
+            return True
+        return False
+
+    @classmethod
+    def is_valid(cls, code, data):
+        """
+        淇″彿鏄惁鏈夋晥
+        @param code:
+        @return: 鏄惁鏈夋晥锛屾棤鏁堟秷鎭�/鏈夋晥瀵硅薄
+        """
+        if code not in cls.__human_radical_buy_mark_info:
+            return False, "娌℃湁浜轰拱鍏ヤ俊鍙�"
+        single_time_ms, space_time_ms, expire_time_ms, _ = cls.__human_radical_buy_mark_info[code]
+        now_time_ms = L2DataUtil.get_time_with_ms(data["val"])
+        if tool.trade_time_sub_with_ms(now_time_ms,
+                                       expire_time_ms) > 0:
+            cls.__human_radical_buy_mark_info.pop(code)
+            async_log_util.info(logger_l2_not_buy_reasons, f"{code}#澶у崟瓒冲锛屼汉涓轰笅鍗曪細 瓒呰繃淇″彿鐢熸晥鏃堕棿-{now_time_ms}/{expire_time_ms}")
+            return False, "瓒呰繃淇″彿鐢熸晥鏃堕棿"
+        return True, cls.__human_radical_buy_mark_info[code]
 
 
 class L2TradeDataProcessor:
@@ -325,12 +390,14 @@
                 cls.unreal_buy_dict.pop(code)
 
     @classmethod
-    def set_real_place_order_index(cls, code, index, order_begin_pos: OrderBeginPosInfo):
+    def set_real_place_order_index(cls, code, index, order_begin_pos: OrderBeginPosInfo, last_data):
         trade_record_log_util.add_real_place_order_position_log(code, index, order_begin_pos.buy_single_index)
         total_datas = local_today_datas.get(code)
-        use_time = 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"]))
-        trade_record_log_util.add_place_order_use_time(code, f"鎵ц浣嶆椂闂达細{L2DataUtil.get_time_with_ms(total_datas[order_begin_pos.buy_exec_index]['val'])} 鑰楁椂锛歿use_time}")
+        use_time = 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"]))
+        trade_record_log_util.add_place_order_use_time(code,
+                                                       f"鎵ц浣嶆椂闂达細{L2DataUtil.get_time_with_ms(total_datas[order_begin_pos.buy_exec_index]['val'])} 鑰楁椂锛歿use_time}")
         l2_log.debug(code, "璁剧疆鐪熷疄涓嬪崟浣嶏細{}", index)
         cancel_buy_strategy.set_real_place_position(code, index, order_begin_pos.buy_single_index, is_default=False)
         # 鑾峰彇鐪熷疄涓嬪崟浣嶇疆涔嬪悗闇�瑕佸垽鏂璅鎾�
@@ -395,7 +462,7 @@
         finally:
             if datas:
                 l2.l2_data_util.save_l2_data(code, None, datas)
-            origin_datas.clear()
+            # origin_datas.clear()
 
     @classmethod
     def __recompute_real_order_index(cls, code, pre_real_order_index, order_info, compute_type):
@@ -405,13 +472,13 @@
             code, order_info, pre_real_order_index, compute_type)
         if real_order_index and pre_real_order_index != real_order_index:
             try:
-                exec_index = order_info[6]
+                exec_index = order_info[3]
                 order_begin_pos = cls.__get_order_begin_pos(
                     code)
                 async_log_util.info(logger_debug,
                                     f"涓嬪崟浣嶇煫姝o細鐪熷疄涓嬪崟浣�-{real_order_index} 璁㈠崟淇℃伅-{order_info}  涓嬪崟淇℃伅-{order_begin_pos.to_dict()}")
                 if order_begin_pos and order_begin_pos.buy_exec_index == exec_index:
-                    cls.set_real_place_order_index(code, real_order_index, order_begin_pos)
+                    cls.set_real_place_order_index(code, real_order_index, order_begin_pos, order_info[1])
                     async_log_util.info(logger_real_place_order_position,
                                         f"鐪熷疄涓嬪崟浣嶇疆鐭锛歿code}-({real_order_index},1)")
             except Exception as e:
@@ -480,9 +547,19 @@
                                     logger_l2_error.exception(e)
                                 finally:
                                     buy_open_limit_up_strategy.BuyOpenLimitupDataManager().remove_place_order_info(code)
-
-                        # 鑾峰彇涓嬪崟浣嶇疆
-
+                    # 澶勭悊娑ㄥ仠鍗栦笌娑ㄥ仠鍗栨挙
+                    try:
+                        for d in add_datas:
+                            if L2DataUtil.is_limit_up_price_sell(d['val']):
+                                L2TradeSingleDataProcessor.add_l2_delegate_limit_up_sell(code, d)
+                            elif L2DataUtil.is_limit_up_price_sell_cancel(d['val']):
+                                L2TradeSingleDataProcessor.add_l2_delegate_limit_up_sell_cancel(code,
+                                                                                                d['val']['orderNo'])
+                    except Exception as e:
+                        logger_debug.exception(e)
+                    finally:
+                        # 鎵ц鏈�鍚庡啀鑾峰彇鐪熷疄涓嬪崟浣嶇疆锛岄槻姝笅鍗曚綅缃偅鎵规暟鎹湁澶ф壒閲忕殑鎾ゅ崟
+                        # ======鑾峰彇涓嬪崟浣嶇疆
                         if constant.IS_NEW_VERSION_PLACE_ORDER:
                             place_order_index, order_info, compute_type = huaxin_delegate_postion_manager.RealDelegateOrderPositionManager.compute_l2_place_order_position(
                                 code, add_datas)
@@ -494,7 +571,7 @@
                         if place_order_index:
                             order_begin_pos = cls.__get_order_begin_pos(
                                 code)
-                            cls.set_real_place_order_index(code, place_order_index, order_begin_pos)
+                            cls.set_real_place_order_index(code, place_order_index, order_begin_pos, order_info[1])
                             try:
                                 cls.__re_compute_threading_pool.submit(
                                     cls.__recompute_real_order_index, code, place_order_index, order_info,
@@ -502,17 +579,6 @@
                             except:
                                 pass
                             async_log_util.info(logger_l2_process, f"code:{code} 鑾峰彇鍒颁笅鍗曠湡瀹炰綅缃細{place_order_index}")
-
-                    # 澶勭悊娑ㄥ仠鍗栦笌娑ㄥ仠鍗栨挙
-                    try:
-                        for d in add_datas:
-                            if L2DataUtil.is_limit_up_price_sell(d['val']):
-                                L2TradeSingleDataProcessor.add_l2_delegate_limit_up_sell(code, d)
-                            elif L2DataUtil.is_limit_up_price_sell_cancel(d['val']):
-                                L2TradeSingleDataProcessor.add_l2_delegate_limit_up_sell_cancel(code,
-                                                                                                d['val']['orderNo'])
-                    except Exception as e:
-                        logger_debug.exception(e)
                 except:
                     async_log_util.error(logger_l2_error, f"{code} 澶勭悊鐪熷疄涓嬪崟浣嶇疆鍑洪敊")
             # 绗�1鏉℃暟鎹槸鍚︿负09:30:00
@@ -825,11 +891,12 @@
         average_rate = cls.__Buy1PriceManager.get_average_rate(code)
         if average_rate:
             if tool.is_ge_code(code):
-                if average_rate < 0.8:
+                if average_rate < 0.08:
                     return False, True, f"鍧囦环娑ㄥ箙({average_rate})灏忎簬8%", True
             else:
                 if average_rate < 0.04:
                     return False, True, f"鍧囦环娑ㄥ箙({average_rate})灏忎簬4%", True
+
         return True, False, f"", False
 
     @classmethod
@@ -971,12 +1038,21 @@
                                                              local_today_datas.get(code))
                 return False
             else:
-                l2_log.debug(code, "鍙互涓嬪崟锛屽師鍥狅細{}锛� 涓嬪崟妯″紡锛歿}", reason, order_begin_pos.mode)
-                try:
 
+                try:
                     # 鍒ゆ柇鏄惁涓洪灏佷笅鍗�
                     order_begin_pos.first_limit_up_buy = radical_buy_data_manager.is_first_limit_up_buy(code)
 
+                    if not constant.CAN_BUY_FIRST_LIMIT_UP and order_begin_pos.first_limit_up_buy:
+                        reason = "棣栧皝涓嶄笅鍗�"
+                        l2_log.debug(code, "涓嶅彲浠ヤ笅鍗曪紝鍘熷洜锛歿}", reason)
+                        trade_record_log_util.add_cant_place_order_log(code, reason)
+                        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))
+                        return False
+                    l2_log.debug(code, "鍙互涓嬪崟锛屽師鍥狅細{}锛� 涓嬪崟妯″紡锛歿} 鏈�灏忚鍗曞彿锛歿}", reason, order_begin_pos.mode, order_begin_pos.min_order_no)
                     l2_log.debug(code, "寮�濮嬫墽琛屼拱鍏�")
                     trade_manager.start_buy(code, capture_timestamp, last_data,
                                             last_data_index, order_begin_pos.mode, order_begin_pos.buy_exec_index)
@@ -1386,7 +1462,7 @@
                      order_begin_pos.threshold_money,
                      order_begin_pos.num,
                      order_begin_pos.count, order_begin_pos.at_limit_up, total_datas[order_begin_pos.buy_exec_index],
-                     cls.volume_rate_info[code], order_begin_pos.mode)
+                     cls.volume_rate_info[code], order_begin_pos.mode_desc)
         cls.__save_order_begin_data(code, order_begin_pos)
         cls.__LimitUpTimeManager.save_limit_up_time(code, total_datas[order_begin_pos.buy_exec_index]["val"]["time"])
         l2_log.debug(code, "delete_buy_cancel_point")
@@ -1444,10 +1520,36 @@
         _start_time = tool.get_now_timestamp()
         total_datas = local_today_datas[code]
 
-        # ---------璁$畻婵�杩涗拱鍏ョ殑淇″彿---------
-        radical_result = cls.__compute_radical_order_begin_pos(code, compute_start_index, compute_end_index)
+        # 涓嶉渶瑕佹牴鎹汉涓轰笅鍗曟潵涓嬪崟
+        # if not HumanRadicalBuySingleManager.has_single(code):
+        #     # ---------璁$畻婵�杩涗拱鍏ョ殑淇″彿---------
+        #     radical_result = cls.__compute_radical_order_begin_pos(code, compute_start_index, compute_end_index)
+        # else:
+        #     human_radical_result = cls.__compute_human_radical_order_begin_pos(code, compute_start_index,
+        #                                                                        compute_end_index)
+        #     l2_log.debug(code, f"澶у崟瓒冲锛屼汉涓轰笅鍗曡绠楃粨鏋�({compute_start_index}-{compute_end_index}):{human_radical_result}")
+        #     if human_radical_result[0]:
+        #         radical_result = list(human_radical_result[2])
+        #         # 鏀瑰彉鎵ц浣嶇疆
+        #         radical_result[1] = human_radical_result[1]["index"]
+        #     else:
+        #         radical_result = None
 
-        if radical_result[0]:
+        radical_result = cls.__compute_radical_order_begin_pos(code, compute_start_index, compute_end_index)
+        if radical_result and radical_result[0]:
+
+            # if not HumanRadicalBuySingleManager.has_single(code):
+            #     big_order_deal_enough_result = radical_buy_data_manager.is_big_order_deal_enough(code,
+            #                                                                                      code_volumn_manager.CodeVolumeManager().get_volume_rate_refer_in_5days(
+            #                                                                                          code), 0)
+            #     if big_order_deal_enough_result[6] <= 0:
+            #         HumanRadicalBuySingleManager.add_single(code, total_datas[-1], radical_result)
+            #         async_log_util.info(logger_l2_not_buy_reasons, f"{code}#澶у崟瓒冲锛岄渶瑕佹牴鎹汉涓轰笅鍗�({compute_start_index}-{compute_end_index})锛歿radical_result[1]}")
+            #         return
+            # #涓嬪崟鍓嶄竴姝ワ紝绉婚櫎浜轰负涓嬪崟淇″彿
+            # is_human_radical_buy = HumanRadicalBuySingleManager.has_single(code)
+            # HumanRadicalBuySingleManager.remove_single(code)
+
             buy_single_index, buy_exec_index = radical_result[1], radical_result[1]
             buy_volume_rate = cls.volume_rate_info[code][0]
             refer_sell_data = cls.__L2MarketSellManager.get_refer_sell_data(code, total_datas[buy_single_index]["val"][
@@ -1467,7 +1569,9 @@
                                                      mode=OrderBeginPosInfo.MODE_RADICAL,
                                                      mode_desc=f"澶у崟涓嶈冻鎵叆:{radical_result[2]}",
                                                      sell_info=sell_info,
-                                                     threshold_money=threshold_money)
+                                                     threshold_money=threshold_money,
+                                                     min_order_no=radical_result[5]
+                                                     )
             order_begin_pos_info.at_limit_up = cls.__is_at_limit_up_buy(code)
             ordered = cls.__process_with_find_exec_index(code, order_begin_pos_info, compute_end_index,
                                                          block_info=radical_result[3])
@@ -1920,25 +2024,26 @@
         @param code:
         @param start_index:
         @param end_index:
-        @return: (鏄惁鑾峰彇鍒颁俊鍙�, 淇″彿浣嶇疆, 鎵叆鏉垮潡/娑堟伅, 鎵叆鏉垮潡澶у崟娴佸叆淇℃伅, 闇�瑕佺洃鍚殑澶у崟)
+        @return: (鏄惁鑾峰彇鍒颁俊鍙�, 淇″彿浣嶇疆, 鎵叆鏉垮潡/娑堟伅, 鎵叆鏉垮潡澶у崟娴佸叆淇℃伅, 闇�瑕佺洃鍚殑澶у崟, 缁熻涓婃澘澶у崟鎴愪氦鐨勬渶灏忚鍗曞彿)
         """
 
         # 婵�杩涗拱淇″彿鐨勬椂闂�
-
         def __can_order():
             # 鍒ゆ柇鏄惁鏄澘涓婃斁閲�
-            if cls.__is_at_limit_up_buy(code, start_index):
-                return False, None, "鏉夸笂鏀鹃噺", None
+            # if cls.__is_at_limit_up_buy(code, start_index):
+            #     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))
-            min_num = int(bigger_money / limit_up_price / 100)
+            bigger_money_num, current_min_num, total_min_num = int(bigger_money / limit_up_price / 100), int(
+                bigger_money / limit_up_price / 100), int(5000 / limit_up_price)
 
             refer_sell_data = L2MarketSellManager().get_refer_sell_data(code, radical_data[3])
             # 鍙傝�冩�诲崠棰�
             refer_sell_money = 0
             if refer_sell_data:
                 refer_sell_money = refer_sell_data[1]
+            # 鍒ゆ柇杩橀渶澶у崟鐨勯噾棰濓紙max(姣忔涓婃澘澶у崟,绱鎴愪氦澶у崟)锛�
             big_order_deal_enough_result = radical_buy_data_manager.is_big_order_deal_enough(code,
                                                                                              code_volumn_manager.CodeVolumeManager().get_volume_rate_refer_in_5days(
                                                                                                  code),
@@ -1947,7 +2052,8 @@
                                                                                              is_almost_open_limit_up=
                                                                                              radical_data[5])
             # 缂轰箯鐨勫ぇ鍗曢噾棰�
-            lack_money = big_order_deal_enough_result[3]
+            current_lack_money = int(big_order_deal_enough_result[5])
+            total_lack_money = int(big_order_deal_enough_result[6])
             # 濡傛灉鏈夊ぇ鍗曟垚浜ゅ氨涓嶉渶瑕佺湅澶у崟
             if constant.CAN_RADICAL_BUY_NEED_BIG_ORDER_EVERYTIME:
                 # 姣忔涓嬪崟閮介渶瑕佸ぇ鍗�
@@ -1958,10 +2064,14 @@
                     # 60s浠ヤ笂灏变笉涓嬪崟浜�
                     return False, None, "璺濈涓婃缁熻澶у崟鏃堕棿杩囧幓60s", set()
 
-            if lack_money == 0:
-                if not tool.is_sh_code(code):
-                    # 闈炰笂璇佺殑绁ㄧ湅50w
-                    min_num = int(5000 / limit_up_price)
+            if max(current_lack_money, total_lack_money) <= 0:
+                # 宸茬粡涓嶇己灏戝ぇ鍗曚簡
+                # if not tool.is_sh_code(code):
+                # 闈炰笂璇佺殑绁ㄧ湅50w
+                current_min_num = int(5000 / limit_up_price)
+            # 濡傛灉绱澶у崟鎴愪氦瓒冲锛屽彧闇�鐪�50w
+            # if big_order_deal_enough_result[4]:
+            #     min_num = int(5000 / limit_up_price)
             # 闇�瑕佺洃鍚殑澶у崟
             watch_indexes = set()
             # 鎬诲鎵樺ぇ鍗曢噾棰�
@@ -1977,8 +2087,6 @@
                 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,
@@ -1993,23 +2101,40 @@
                         # 鍒ゆ柇鏄惁涓哄ぇ鍗�
                         order_money = dealing_active_order_info[2] + round(val["price"], 2) * val["num"] * 100
                         if order_money >= bigger_money:
-                            lack_money -= order_money
-                            watch_indexes.add(i)
-                            if lack_money < 0:
+                            if val["num"] >= bigger_money_num:
+                                watch_indexes.add(i)
+                            if val["num"] >= current_min_num:
+                                current_lack_money -= order_money
+                            if val["num"] >= total_min_num:
+                                total_lack_money -= order_money
+                            if max(current_lack_money, total_lack_money) < 0:
                                 single_index = i
                                 break
 
                 if int(val["orderNo"]) <= radical_data[1]:
                     # 涓诲姩涔板崟鍚庣殑鏁版嵁涓嶇畻
                     continue
-                watch_indexes.add(i)
-                lack_money -= round(val["price"], 2) * val["num"] * 100
-                if lack_money < 0:
+
+                if val["num"] >= bigger_money_num:
+                    watch_indexes.add(i)
+
+                if val["num"] >= current_min_num:
+                    current_lack_money -= round(val["price"], 2) * val["num"] * 100
+
+                if val["num"] >= total_min_num:
+                    total_lack_money -= round(val["price"], 2) * val["num"] * 100
+
+                if max(current_lack_money, total_lack_money) < 0:
                     single_index = i
                     break
             if single_index is not None:
-                return True, single_index, "鏈夊ぇ鍗�", watch_indexes
-            return False, None, f"澶у崟涓嶈冻锛歿trade_index}-{end_index}  缂哄皯鐨勫ぇ鍗�-{lack_money}", watch_indexes
+                every_time_big_orders = EveryLimitupBigDealOrderManager.list_big_buy_deal_orders(code)
+                if every_time_big_orders:
+                    min_order_no = min(min(every_time_big_orders, key=lambda e: e[0])[0], radical_data[1])
+                else:
+                    min_order_no = radical_data[1]
+                return True, single_index, f"鏈夊ぇ鍗�,澶у崟鎯呭喌锛歿big_order_deal_enough_result[1]}", watch_indexes, min_order_no
+            return False, None, f"澶у崟涓嶈冻锛歿trade_index}-{end_index}  缂哄皯鐨勫ぇ鍗�-{max(current_lack_money, total_lack_money)}  澶у崟鎯呭喌锛歿big_order_deal_enough_result[1]}", watch_indexes, None
 
         radical_data = RadicalBuyDealCodesManager.buy_by_l2_delegate_expire_time_dict.get(code)
         record_codes = radical_buy_data_manager.BlockPlaceOrderRecordManager().get_codes()
@@ -2030,7 +2155,7 @@
                 return False, None, "瓒呰繃鐢熸晥鏃堕棿"
 
         result = __can_order()
-        l2_log.debug(code, f"L2鎵叆鍒ゆ柇锛歿result}")
+        l2_log.debug(code, f"L2鎵叆鍒ゆ柇({start_index}-{end_index})锛歿result}")
         if result[0]:
             # 宸茬粡鎵叆涓嬭繃鍗曚笖鍏佽鏉夸笂鏀鹃噺鎵叆鐨勫氨闇�瑕佸垽鏂澘涓婃斁閲忕殑璺濈
             if is_radical_buy and constant.CAN_RADICAL_BUY_AT_LIMIT_UP:
@@ -2053,10 +2178,67 @@
             # 濡傛灉鏉夸笂鏀鹃噺涓嶅彲涔板叆灏遍渶瑕佸垹闄や俊鍙�
             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[4], result[3]
+            return True, result[1], radical_data[2], radical_data[4], result[3], result[4]
         else:
             async_log_util.info(logger_l2_not_buy_reasons, f"{code}#{result[2]}")
         return result
+
+    @classmethod
+    def __compute_human_radical_order_begin_pos(cls, code, start_index, end_index):
+        """
+        澶勭悊璺熶汉涔�
+        @param code:
+        @param start_index:
+        @param end_index:
+        @return:
+        """
+        total_datas = local_today_datas.get(code)
+        result = HumanRadicalBuySingleManager.is_valid(code, total_datas[start_index])
+        if not result[0]:
+            return False, None, result[1]
+        result = result[1]
+        single_time_ms, space_time_ms, expire_time_ms, radical_result = result[0], result[1], result[2], result[3]
+
+        bigger_num = l2_data_util.get_big_money_val(gpcode_manager.get_limit_up_price_as_num(code),
+                                                    tool.is_ge_code(code)) // (
+                             gpcode_manager.get_limit_up_price_as_num(code) * 100)
+        canceled_buyno_map = local_today_buyno_map.get(code)
+        for i in range(start_index, end_index + 1):
+            data = total_datas[i]
+            val = data["val"]
+            if not L2DataUtil.is_limit_up_price_buy(val):
+                continue
+            if val["num"] < bigger_num:
+                continue
+
+            left_count = l2_data_source_util.L2DataSourceUtils.get_limit_up_buy_no_canceled_count_v2(code, i,
+                                                                                                     total_datas,
+                                                                                                     canceled_buyno_map)
+            if left_count == 0:
+                continue
+
+            # 鍒ゆ柇鏄惁瓒呰繃鐢熸晥鏃堕棿
+            if tool.trade_time_sub_with_ms(L2DataUtil.get_time_with_ms(total_datas[i]["val"]),
+                                           expire_time_ms) > 0:
+                HumanRadicalBuySingleManager.remove_single(code)
+                return False, None, "瓒呰繃淇″彿鐢熸晥鏃堕棿"
+            is_valid = False
+            # 鍒ゆ柇璺濈涓婁釜50w涔板崟鐨勬椂闂存槸鍚﹁秴杩囦簡space_time_ms
+            buy_exec_index = radical_result[1]
+            for ii in range(i - 1, buy_exec_index, -1):
+                data_child = total_datas[ii]
+                val_child = data_child["val"]
+                if not L2DataUtil.is_limit_up_price_buy(val_child):
+                    continue
+                if val_child["num"] * float(val_child["price"]) < 5000:
+                    continue
+                if tool.trade_time_sub_with_ms(L2DataUtil.get_time_with_ms(val),
+                                               L2DataUtil.get_time_with_ms(val_child)) > space_time_ms:
+                    is_valid = True
+                    break
+            if is_valid:
+                return True, data, radical_result
+        return False, None, "娌℃湁鏈夋晥淇″彿"
 
     # 鎬诲崠棰濆弬鑰冩椂闂翠娇鐢ㄨ褰�
     __refer_sell_used_times = {}
@@ -2070,6 +2252,8 @@
         @param end_index:
         @return: 淇″彿淇℃伅锛堜俊鍙蜂綅,鎵ц浣嶏級, 娑堟伅, 鍙拱鍏ョ殑鏉垮潡
         """
+        if True:
+            return None, "姝ゆ潯涓嶇敓鏁�", None
         if not tool.is_sz_code(code):
             return None, "闈炴繁璇佺殑绁�", None
         # 鍒ゆ柇鎶涘帇鏄惁澶т簬5000w
@@ -2230,7 +2414,8 @@
                                 f"{code}鑾峰彇鍒颁拱鍏ユ墽琛岀偣(蹇�熶拱鍏�)锛歿i} 缁熻绾拱鎵嬫暟锛歿buy_nums} 鐩爣绾拱鎵嬫暟锛歿threshold_num} 缁熻绾拱鍗曟暟锛歿buy_count}")
             elif L2DataUtil.is_limit_up_price_buy_cancel(_val):
                 # 鍒ゆ柇涔板叆浣嶇疆鏄惁鍦ㄤ拱鍏ヤ俊鍙蜂箣鍓�
-                buy_index = l2_data_source_util.L2DataSourceUtils.get_buy_index_with_cancel_data_v2(total_datas[i], buy_no_map)
+                buy_index = l2_data_source_util.L2DataSourceUtils.get_buy_index_with_cancel_data_v2(total_datas[i],
+                                                                                                    buy_no_map)
                 if buy_index is not None:
                     # 鎵惧埌涔版挙鏁版嵁鐨勪拱鍏ョ偣
                     if buy_index >= buy_single_index:
@@ -2370,7 +2555,8 @@
                                 f"{code}鑾峰彇鍒颁拱鍏ユ墽琛岀偣(绉瀬涓嬪崟)锛歿i} 缁熻绾拱鎵嬫暟锛歿buy_nums} 鐩爣绾拱鎵嬫暟锛歿threshold_num} 缁熻绾拱鍗曟暟锛歿buy_count}")
             elif L2DataUtil.is_limit_up_price_buy_cancel(_val):
                 # 鍒ゆ柇涔板叆浣嶇疆鏄惁鍦ㄤ拱鍏ヤ俊鍙蜂箣鍓�
-                buy_index = l2_data_source_util.L2DataSourceUtils.get_buy_index_with_cancel_data_v2(total_datas[i], buyno_map)
+                buy_index = l2_data_source_util.L2DataSourceUtils.get_buy_index_with_cancel_data_v2(total_datas[i],
+                                                                                                    buyno_map)
                 if buy_index is not None:
 
                     # 鎵惧埌涔版挙鏁版嵁鐨勪拱鍏ョ偣

--
Gitblit v1.8.0