From 8821049f3faee04e03f5535c6259d07bfb8b6433 Mon Sep 17 00:00:00 2001
From: Administrator <admin@example.com>
Date: 星期四, 24 七月 2025 18:11:11 +0800
Subject: [PATCH] 订阅规则修改/增加新的外部接口/删除不必要的debug日志

---
 api/outside_api_command_callback.py |  167 ++++++++++++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 164 insertions(+), 3 deletions(-)

diff --git a/api/outside_api_command_callback.py b/api/outside_api_command_callback.py
index 2947365..60bdf01 100644
--- a/api/outside_api_command_callback.py
+++ b/api/outside_api_command_callback.py
@@ -1034,6 +1034,167 @@
 
                 result = {"code": 0, "data": {"account_available_money": account_available_money, "delegates": fdatas}}
                 self.send_response(result, client_id, request_id)
+            elif ctype == "get_delegated_buy_code_infos_v2":
+                account_available_money = trade_data_manager.AccountMoneyManager().get_available_money_cache()
+                # 鑾峰彇濮旀墭涓殑浠g爜
+                current_delegates = huaxin_trade_record_manager.DelegateRecordManager().list_current_delegates()
+                fdatas = []
+                if current_delegates:
+                    codes_set = set()
+                    for c in current_delegates:
+                        _start_time = time.time()
+                        try:
+                            if int(c["direction"]) != huaxin_util.TORA_TSTP_D_Buy:
+                                continue
+                            code = c["securityID"]
+                            if code in codes_set:
+                                continue
+                            orderSysID = c.get("orderSysID")
+                            codes_set.add(code)
+                            code_name = gpcode_manager.get_code_name(code)
+                            # 鑾峰彇涓嬪崟浣嶇疆淇℃伅
+                            order_begin_pos = TradePointManager().get_buy_compute_start_data_cache(code)
+                            if order_begin_pos is None or order_begin_pos.buy_single_index is None:
+                                order_begin_pos = OrderBeginPosInfo(buy_single_index=0, buy_exec_index=0)
+                            l2_data_util.load_l2_data(code)
+                            total_datas = l2_data_util.local_today_datas.get(code)
+                            if not total_datas:
+                                continue
+                            trade_index, is_default = transaction_progress.TradeBuyQueue().get_traded_index(code)
+                            if trade_index is None:
+                                trade_index = 0
+                            # 涓嬪崟浣嶇疆
+                            place_order_index = SCancelBigNumComputer().get_real_place_order_index_cache(code)
+                            if place_order_index is None:
+                                place_order_index = 0
+
+                            # 鑾峰彇鍓╀笅鐨勭瑪鏁�
+                            total_left_count = 0
+                            total_left_num = 0
+                            for i in range(trade_index + 1, place_order_index):
+                                data = total_datas[i]
+                                val = data["val"]
+                                if not L2DataUtil.is_limit_up_price_buy(val):
+                                    continue
+                                if val["num"] * float(val["price"]) < 5000:
+                                    continue
+                                left_count = l2_data_source_util.L2DataSourceUtils.get_limit_up_buy_no_canceled_count_v2(
+                                    code,
+                                    i,
+                                    total_datas,
+                                    l2_data_util.local_today_canceled_buyno_map.get(
+                                        code))
+                                if left_count > 0:
+                                    total_left_count += left_count
+                                    total_left_num += val["num"] * left_count
+                            # 鑾峰彇姝e湪鎴愪氦
+                            dealing_info = HuaXinBuyOrderManager.get_dealing_order_info(code)
+                            if dealing_info:
+                                if str(total_datas[trade_index]["val"]["orderNo"]) == str(dealing_info[0]):
+                                    total_left_num += (total_datas[trade_index]["val"]["num"] - dealing_info[1] // 100)
+                            limit_up_price = gpcode_manager.get_limit_up_price_as_num(code)
+                            buy1_money = Buy1PriceManager().get_latest_buy1_money(code)
+                            if buy1_money is None:
+                                buy1_money = 1
+                            real_place_order_after_count = 0
+                            real_place_order_after_num = 0
+                            is_ge_code = tool.is_ge_code(code)
+                            # 缁熻鐪熷疄涓嬪崟浣嶇疆鍚庨潰鏈挙鐨勯噾棰�
+                            for i in range(place_order_index, total_datas[-1]["index"]):
+                                val = total_datas[i]["val"]
+                                if not L2DataUtil.is_limit_up_price_buy(val):
+                                    continue
+                                # 鏄笉鏄ぇ鍗�
+                                if not l2_data_util_old.is_big_money(val, is_ge_code):
+                                    continue
+
+                                canceled_data = l2_data_source_util.L2DataSourceUtils.get_limit_up_buy_canceled_data_v2(
+                                    code,
+                                    i,
+                                    total_datas,
+                                    l2_data_util.local_today_canceled_buyno_map.get(
+                                        code))
+                                if not canceled_data:
+                                    real_place_order_after_count += 1
+                                    real_place_order_after_num += val["num"]
+
+                            # 鏄惁闇�瑕佹敞鎰�
+                            need_pay_attention = (total_left_count <= 10 or total_left_num * float(
+                                limit_up_price) * 100 < 1500 * 10000) and (
+                                                         real_place_order_after_count <= 10 or real_place_order_after_num * limit_up_price * 100 < 1500 * 10000)
+                            # L鎾ゆ瘮渚�
+                            l_down_cancel_rate, must_buy, cancel_rate_info = LCancelRateManager.get_cancel_rate(code,
+                                                                                                                buy_mode=OrderBeginPosInfo.MODE_RADICAL)
+
+                            fdata = {"id": orderSysID, "code_info": (code, code_name),
+                                     "buy1_money": output_util.money_desc(buy1_money),
+                                     "left_count": total_left_count,
+                                     "left_money": output_util.money_desc(total_left_num * float(limit_up_price) * 100),
+                                     "pay_attention": need_pay_attention,
+                                     "trade_progress_percent": round(
+                                         total_left_num * float(limit_up_price) * 100 * 100 / buy1_money, 2),  # 鎴愪氦杩涘害姣斾緥
+                                     "limit_up_price": limit_up_price,
+                                     "block": '',
+                                     "trade_queue": [],
+                                     "l_down_cancel_rate": l_down_cancel_rate,
+                                     "l_down_cancel_rate_info": cancel_rate_info,
+                                     }
+                            limit_up_data = kpl_data_manager.KPLLimitUpDataRecordManager.record_code_dict.get(code)
+                            # 鑾峰彇褰撳墠鏉垮潡
+                            try:
+                                limit_up_sequences = CodeLimitUpSequenceManager.get_current_limit_up_sequence(code)
+                                if limit_up_sequences:
+                                    buy_blocks = RadicalBuyDealCodesManager().get_code_blocks(code)
+                                    blocks_info = []
+                                    for limit_up_sequence in limit_up_sequences:
+                                        # 鑾峰彇浠g爜涓嬪崟鐨勬澘鍧�
+                                        if buy_blocks and limit_up_sequence[0] not in buy_blocks:
+                                            continue
+                                        blocks_info.append(
+                                            f"{limit_up_sequence[0]}-{limit_up_sequence[1]}({limit_up_sequence[2]}&{limit_up_sequence[2] - limit_up_sequence[3]})")
+                                    if buy_blocks:
+                                        fdata['block'] = "/".join(blocks_info)
+                            except:
+                                pass
+                            # 鑾峰彇娑ㄥ仠鏃堕棿
+                            if limit_up_data:
+                                fdata['limit_up_time'] = tool.to_time_str(limit_up_data[2])
+
+                                # 鑾峰彇濮旀墭闃熷垪
+                            try:
+                                real_place_order_index = SCancelBigNumComputer().get_real_place_order_index_cache(code)
+                                if real_place_order_index is not None:
+                                    trade_queue = l2_output_util.get_trade_queue_at_near_place_order(code,
+                                                                                                     real_place_order_index,
+                                                                                                     9)
+                                    fdata['trade_queue'] = trade_queue
+                                # 鑷敱娴侀�氳偂鏈�
+                                zyltgb = global_util.zyltgb_map.get(code)
+                                if zyltgb is not None:
+                                    fdata['zyltgb'] = output_util.money_desc(zyltgb)
+                            except:
+                                pass
+                            # L鍚庡泭鎷揩鐓�
+                            try:
+                                __start_time = time.time()
+                                current_info = LCancelBigNumComputer().statistic_l_down_watch_indexes_info(code)
+                                fdata['l_down_watch_indexes_info'] = {}
+                                if current_info:
+                                    fdata['l_down_watch_indexes_info']['current'] = current_info
+                                use_time = time.time() - __start_time
+                                if use_time > 0.05:
+                                    async_log_util.info(logger_debug, f"缁熻瀹炴挙鐢ㄦ椂锛歿code} - {use_time}")
+                            except Exception as e:
+                                logger_debug.exception(e)
+                            fdatas.append(fdata)
+                        except Exception as e:
+                            logger_debug.exception(e)
+                        finally:
+                            use_time = time.time() - _start_time
+                            if use_time > 0.1:
+                                async_log_util.info(logger_debug, f"濮旀墭淇℃伅缁熻鑰楁椂锛歿c['securityID']}-{use_time}")
+                result = {"code": 0, "data": {"account_available_money": account_available_money, "delegates": fdatas}}
+                self.send_response(result, client_id, request_id)
             elif ctype == "set_real_place_order_index":
                 # 璁剧疆鐪熷疄涓嬪崟浣嶇疆
                 code = data["code"]
@@ -1398,10 +1559,10 @@
                 old_rate = LCancelRateManager().get_cancel_rate(0)[0]
                 CancelRateHumanSettingManager().set_l_down(code, rate)
                 # L鍚庨噸鏂板泭鎷�
-                if rate < old_rate:
+                # if rate < old_rate:
                     # 鏀瑰皬鎵嶈兘閲嶆柊鍥婃嫭
-                    trade_record_log_util.add_common_msg(code, "L鍚庨噸鏂板泭鎷�", msg=f"淇敼鎾ゅ崟姣斾緥: {old_rate}->{rate}")
-                    LCancelBigNumComputer().re_compute_l_down_watch_indexes(code, is_force=True)
+                trade_record_log_util.add_common_msg(code, "L鍚庨噸鏂板泭鎷�", msg=f"淇敼鎾ゅ崟姣斾緥: {old_rate}->{rate}")
+                LCancelBigNumComputer().re_compute_l_down_watch_indexes(code, is_force=True)
 
                 self.send_response({"code": 0, "data": {}},
                                    client_id,

--
Gitblit v1.8.0