From 36367e32a8c00cbbacb2cc7f7a09adde3e0cfaa9 Mon Sep 17 00:00:00 2001
From: Administrator <admin@example.com>
Date: 星期一, 11 十一月 2024 18:37:32 +0800
Subject: [PATCH] 扫过的单可继续扫/扫了未成交遵循顺位机制/唯一涨停原因的高位板要计算其身位

---
 l2/l2_data_manager_new.py |  182 +++++++++++++++++++++++++++++++++------------
 1 files changed, 132 insertions(+), 50 deletions(-)

diff --git a/l2/l2_data_manager_new.py b/l2/l2_data_manager_new.py
index 78520f0..2aa1cca 100644
--- a/l2/l2_data_manager_new.py
+++ b/l2/l2_data_manager_new.py
@@ -17,13 +17,15 @@
 from l2.place_order_single_data_manager import L2TradeSingleDataProcessor
 from log_module import async_log_util, log_export
 from third_data import kpl_data_manager, block_info
+from third_data.kpl_data_constant import LimitUpDataConstant
+from trade.buy_money_count_setting import RadicalBuyBlockCodeCountManager
 from utils import global_util, ths_industry_util, tool, buy_condition_util, buy_strategy_util, trade_util
 import l2_data_util
 from db import redis_manager_delegate as redis_manager
 from third_data.code_plate_key_manager import CodePlateKeyBuyManager, KPLCodeJXBlockManager
 from trade import trade_manager, trade_queue_manager, l2_trade_factor, l2_trade_util, \
     trade_result_manager, current_price_process_manager, trade_data_manager, trade_huaxin, trade_record_log_util, \
-    trade_constant
+    trade_constant, buy_open_limit_up_strategy, radical_buy_data_manager
 from l2 import l2_data_manager, l2_log, l2_data_source_util, code_price_manager, \
     transaction_progress, cancel_buy_strategy, place_order_single_data_manager
 from l2.cancel_buy_strategy import DCancelBigNumComputer, \
@@ -432,6 +434,44 @@
                         #     place_order_index = add_datas[-1]["index"]
                         #     cls.set_real_place_order_index(code, place_order_index, order_begin_pos.buy_single_index)
                     else:
+                        # ------------09:30:00涔嬪墠澶勭悊鎺�1鐨勯棶棰�--------------
+                        if int(add_datas[-1]["val"]["time"].replace(":", "")) < 93000:
+                            # 鑾峰彇鏄惁涓嬪崟
+                            buy_info = buy_open_limit_up_strategy.BuyOpenLimitupDataManager().get_place_order_info(code)
+                            # 璁剧疆铏氭嫙涓嬪崟淇℃伅
+                            if buy_info:
+                                try:
+                                    buy_single_index, buy_exec_index, buy_exec_index = add_datas[0]["index"], \
+                                                                                       add_datas[0]["index"], \
+                                                                                       add_datas[0]["index"]
+                                    buy_volume_rate = 0
+                                    sell_info = ("09:15:00", 0)
+                                    threshold_money = 0
+                                    order_begin_pos_info = OrderBeginPosInfo(buy_single_index=buy_single_index,
+                                                                             buy_exec_index=buy_exec_index,
+                                                                             buy_compute_index=buy_exec_index,
+                                                                             num=1, count=1,
+                                                                             max_num_set=set(),
+                                                                             buy_volume_rate=buy_volume_rate,
+                                                                             mode=OrderBeginPosInfo.MODE_RADICAL,
+                                                                             mode_desc=f"鎺�1涓嬪崟",
+                                                                             sell_info=sell_info,
+                                                                             threshold_money=threshold_money)
+                                    cls.__save_order_begin_data(code, order_begin_pos_info)
+                                    # 璁剧疆涓嬪崟淇℃伅
+                                    limit_up_price = gpcode_manager.get_limit_up_price_as_num(code)
+                                    shadow_price = tool.get_shadow_price(limit_up_price)
+                                    huaxin_delegate_postion_manager.place_order(code, limit_up_price, buy_info[0],
+                                                                                buy_exec_index,
+                                                                                add_datas[0], buy_info[2],
+                                                                                shadow_price=shadow_price,
+                                                                                shadow_volume=buy_info[1])
+                                    cls.__place_order_success(code, order_begin_pos_info)
+                                except Exception as e:
+                                    logger_l2_error.exception(e)
+                                finally:
+                                    buy_open_limit_up_strategy.BuyOpenLimitupDataManager().remove_place_order_info(code)
+
                         # 鑾峰彇涓嬪崟浣嶇疆
                         place_order_index, order_info, compute_type = huaxin_delegate_postion_manager.get_l2_place_order_position(
                             code, float(
@@ -739,7 +779,7 @@
 
     @classmethod
     def start_buy(cls, code, last_data, last_data_index, is_first_code):
-        cls.__buy(code, 0, last_data, last_data_index, is_first_code)
+        return cls.__buy(code, 0, last_data, last_data_index, is_first_code)
 
     @classmethod
     def get_active_buy_blocks(cls, code):
@@ -770,6 +810,52 @@
                 if tool.trade_time_sub(tool.get_now_time_str(), "10:00:00") <= 0:
                     return ["鐙嫍"]
         return None
+
+    @classmethod
+    def __place_order_success(cls, code, order_begin_pos):
+        ################涓嬪崟鎴愬姛澶勭悊################
+        trade_result_manager.real_buy_success(code, cls.__TradePointManager)
+        l2_log.debug(code, "澶勭悊涔板叆鎴愬姛1")
+        cancel_buy_strategy.set_real_place_position(code, local_today_datas.get(code)[-1]["index"],
+                                                    order_begin_pos.buy_single_index, is_default=True)
+        l2_log.debug(code, "澶勭悊涔板叆鎴愬姛2")
+        params_desc = cls.__l2PlaceOrderParamsManagerDict[code].get_buy_rank_desc()
+        l2_log.debug(code, params_desc)
+        ############璁板綍涓嬪崟鏃剁殑鏁版嵁############
+        try:
+            jx_blocks, jx_blocks_by = KPLCodeJXBlockManager().get_jx_blocks_cache(
+                code), KPLCodeJXBlockManager().get_jx_blocks_cache(code, by=True)
+            if jx_blocks:
+                jx_blocks = jx_blocks[0]
+            if jx_blocks_by:
+                jx_blocks_by = jx_blocks_by[0]
+
+            info = cls.__trade_log_placr_order_info_dict[code]
+            info.mode = order_begin_pos.mode
+            info.mode_desc = order_begin_pos.mode_desc
+            info.set_buy_index(order_begin_pos.buy_single_index, order_begin_pos.buy_exec_index)
+            info.set_sell_info(order_begin_pos.sell_info)
+            if jx_blocks:
+                info.set_kpl_blocks(list(jx_blocks))
+            elif jx_blocks_by:
+                info.set_kpl_blocks(list(jx_blocks_by))
+            else:
+                info.set_kpl_blocks([])
+            can_buy_result = CodePlateKeyBuyManager.can_buy(code)
+            if can_buy_result:
+                if not can_buy_result[0] and can_buy_result[1]:
+                    info.set_kpl_match_blocks(["鐙嫍"])
+                elif not can_buy_result[0] and not can_buy_result[1]:
+                    info.set_kpl_match_blocks(["闈炵嫭鑻椾笉婊¤冻韬綅"])
+                else:
+                    temps = []
+                    temps.extend([f"{x[0]}" for x in can_buy_result[0]])
+                    if can_buy_result[5]:
+                        temps.append(f"绉瀬涔板叆锛歿can_buy_result[5]}")
+                    info.set_kpl_match_blocks(temps)
+            trade_record_log_util.add_place_order_log(code, info)
+        except Exception as e:
+            async_log_util.error(logger_l2_error, f"鍔犲叆涔板叆璁板綍鏃ュ織鍑洪敊锛歿str(e)}")
 
     @classmethod
     def __buy(cls, code, capture_timestamp, last_data, last_data_index, is_first_code):
@@ -822,51 +908,8 @@
                     trade_manager.start_buy(code, capture_timestamp, last_data,
                                             last_data_index, order_begin_pos.mode, order_begin_pos.buy_exec_index)
                     l2_log.debug(code, "鎵ц涔板叆鎴愬姛")
-                    ################涓嬪崟鎴愬姛澶勭悊################
-                    trade_result_manager.real_buy_success(code, cls.__TradePointManager)
-                    l2_log.debug(code, "澶勭悊涔板叆鎴愬姛1")
-                    cancel_buy_strategy.set_real_place_position(code, local_today_datas.get(code)[-1]["index"],
-                                                                order_begin_pos.buy_single_index, is_default=True)
-                    l2_log.debug(code, "澶勭悊涔板叆鎴愬姛2")
-                    params_desc = cls.__l2PlaceOrderParamsManagerDict[code].get_buy_rank_desc()
-                    l2_log.debug(code, params_desc)
-                    ############璁板綍涓嬪崟鏃剁殑鏁版嵁############
-                    try:
-                        jx_blocks, jx_blocks_by = KPLCodeJXBlockManager().get_jx_blocks_cache(
-                            code), KPLCodeJXBlockManager().get_jx_blocks_cache(code, by=True)
-                        if jx_blocks:
-                            jx_blocks = jx_blocks[0]
-                        if jx_blocks_by:
-                            jx_blocks_by = jx_blocks_by[0]
 
-                        info = cls.__trade_log_placr_order_info_dict[code]
-                        info.mode = order_begin_pos.mode
-                        info.mode_desc = order_begin_pos.mode_desc
-                        info.set_buy_index(order_begin_pos.buy_single_index, order_begin_pos.buy_exec_index)
-                        info.set_sell_info(order_begin_pos.sell_info)
-                        if jx_blocks:
-                            info.set_kpl_blocks(list(jx_blocks))
-                        elif jx_blocks_by:
-                            info.set_kpl_blocks(list(jx_blocks_by))
-                        else:
-                            info.set_kpl_blocks([])
-                        can_buy_result = CodePlateKeyBuyManager.can_buy(code)
-                        if can_buy_result:
-                            if not can_buy_result[0] and can_buy_result[1]:
-                                info.set_kpl_match_blocks(["鐙嫍"])
-                            elif not can_buy_result[0] and not can_buy_result[1]:
-                                info.set_kpl_match_blocks(["闈炵嫭鑻椾笉婊¤冻韬綅"])
-                            else:
-                                temps = []
-                                temps.extend([f"{x[0]}" for x in can_buy_result[0]])
-                                if can_buy_result[5]:
-                                    temps.append(f"绉瀬涔板叆锛歿can_buy_result[5]}")
-                                info.set_kpl_match_blocks(temps)
-                        trade_record_log_util.add_place_order_log(code, info)
-                    except Exception as e:
-                        async_log_util.error(logger_l2_error, f"鍔犲叆涔板叆璁板綍鏃ュ織鍑洪敊锛歿str(e)}")
-
-
+                    cls.__place_order_success(code, order_begin_pos)
 
                 except Exception as e:
                     async_log_util.exception(logger_l2_error, e)
@@ -1503,6 +1546,7 @@
                                         order_begin_pos.threshold_money,
                                         0,
                                         True, False)
+        return ordered
 
     @classmethod
     def __start_compute_buy(cls, code, compute_start_index, compute_end_index, threshold_money, capture_time,
@@ -1560,7 +1604,9 @@
                                                      sell_info=sell_info,
                                                      threshold_money=threshold_money)
             order_begin_pos_info.at_limit_up = cls.__is_at_limit_up_buy(code)
-            cls.__process_with_find_exec_index(code, order_begin_pos_info, compute_end_index)
+            ordered = cls.__process_with_find_exec_index(code, order_begin_pos_info, compute_end_index)
+            if ordered:
+                radical_buy_data_manager.BlockPlaceOrderRecordManager().add_record(code, radical_result[2])
             return
 
         # 鑾峰彇涔板叆淇″彿璁$畻璧峰浣嶇疆
@@ -1968,7 +2014,7 @@
         @param code:
         @param start_index:
         @param end_index:
-        @return: (鏄惁鑾峰彇鍒颁俊鍙�, 淇″彿浣嶇疆, 娑堟伅)
+        @return: (鏄惁鑾峰彇鍒颁俊鍙�, 淇″彿浣嶇疆, 鎵叆鏉垮潡/娑堟伅)
         """
 
         # 婵�杩涗拱淇″彿鐨勬椂闂�
@@ -2020,14 +2066,50 @@
             return False, None, "鏃犲ぇ鍗�"
 
         radical_data = RadicalBuyDealCodesManager.buy_by_l2_delegate_expire_time_dict.get(code)
+        record_codes = radical_buy_data_manager.BlockPlaceOrderRecordManager().get_codes()
+        # 鏄惁鎵叆杩�
+        is_radical_buy = code in record_codes
+
         if not radical_data:
             return False, None, "涓嶆弧瓒虫縺杩涗拱鐨勬潯浠�"
-        if t.time() > radical_data[0]:
+        if t.time() > radical_data[0] and not is_radical_buy:
+            # 娌℃壂鍏ヨ繃鎵嶉渶瑕佸垽鏂椂闂�
             return False, None, "瓒呰繃鐢熸晥鏃堕棿"
         result = __can_order()
         l2_log.debug(code, f"L2鎵叆鍒ゆ柇锛歿result}")
         if result[0]:
-            return True, result[1], f"鎵叆鏉垮潡锛歿radical_data[2]}"
+            # 宸茬粡鎵叆涓嬭繃鍗曠殑灏遍渶瑕佸垽鏂澘涓婃斁閲忕殑璺濈
+            if is_radical_buy:
+                is_limit_up_buy = cls.__is_at_limit_up_buy(code)
+                if is_limit_up_buy:
+                    # 鍒ゆ柇鎴愪氦杩涘害鍒板綋鍓嶆暟鎹殑绗旀暟锛屽鏋滃皯浜�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:
+                        return False, result[1], "鎵叆杩囩殑浠g爜鏉夸笂鏀鹃噺璺濈杩�"
+                    else:
+                        # 鍒ゆ柇璇ユ澘鍧楀墠鎺掓槸鍚﹀凡缁忔湁鎴愪氦
+                        deal_codes = RadicalBuyDealCodesManager().get_deal_codes()
+                        for b in radical_data[2]:
+                            temp_deal_codes = radical_buy_data_manager.get_deal_codes_by_block(b, deal_codes)
+                            if len(temp_deal_codes) > 0:
+                                max_count = RadicalBuyBlockCodeCountManager().get_block_code_count(b)
+                                if len(temp_deal_codes) > max_count:
+                                    return False, result[1], f"鍓嶆帓浠g爜鎴愪氦鏁伴噺瓒冲澶氾細{temp_deal_codes}"
+                                # 鍓嶆帓浠g爜鎵嶄細缁х画涔�
+                                limit_up_timestamp = LimitUpDataConstant.get_first_limit_up_time(code)
+                                if not limit_up_timestamp:
+                                    limit_up_timestamp = t.time()
+                                front_infos = []
+                                for _code in temp_deal_codes:
+                                    temp_limit_up_timestamp = LimitUpDataConstant.get_first_limit_up_time(_code)
+                                    if temp_limit_up_timestamp and limit_up_timestamp > temp_limit_up_timestamp:
+                                        front_infos.append((_code, temp_limit_up_timestamp))
+                                if len(front_infos) >= max_count:
+                                    return False, result[1], f"鍓嶆帓浠g爜宸茬粡鎴愪氦锛歿front_infos}"
+            return True, result[1], radical_data[2]
         return result
 
     @classmethod

--
Gitblit v1.8.0