Administrator
2025-07-04 118fb223ddd6650e3cc8971b046a2995e3e3109e
加红撤单比例修改/大单足够后加白改为加红
4个文件已修改
75 ■■■■■ 已修改文件
cancel_strategy/s_l_h_cancel_strategy.py 36 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
constant.py 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
trade/buy_radical/radical_buy_data_manager.py 34 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
trade/trade_result_manager.py 3 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
cancel_strategy/s_l_h_cancel_strategy.py
@@ -571,15 +571,21 @@
        try:
            must_buy = cls.__MustBuyCodesManager.is_in_cache(code)
            if buy_mode == OrderBeginPosInfo.MODE_RADICAL:
                try:
                    human_rate = CancelRateHumanSettingManager().get_l_down(code)
                    if human_rate is None:
                        human_rate = 0
                except:
                    human_rate = 0
                if must_buy:
                    # 扫入加红
                    return constant.L_CANCEL_RATE_WITH_MUST_BUY_FOR_REDICAL_BUY, True
                    return max(constant.L_CANCEL_RATE_WITH_MUST_BUY_FOR_REDICAL_BUY, human_rate), True
                else:
                    # 根据成交额的大单成交占比来计算撤单比例
                    big_money_rate = radical_buy_data_manager.TotalDealBigOrderInfoManager.get_big_order_rate(code)
                    if big_money_rate is not None:
                        threshold_rate = min(big_money_rate * 3, 0.8)
                        return threshold_rate, False
                        return max(threshold_rate, human_rate), False
                    else:
                        deal_big_order_info = radical_buy_data_manager.get_total_deal_big_order_info(code,
                                                                                                     gpcode_manager.get_limit_up_price_as_num(
@@ -588,7 +594,7 @@
                        threshold_rate = 0.5 * deal_rate + 0.35
                        threshold_rate = max(threshold_rate, 0.375)
                        threshold_rate = min(threshold_rate, 0.8)
                        return threshold_rate, False
                        return max(threshold_rate, human_rate), False
            if must_buy:
                if is_up:
                    return constant.L_CANCEL_RATE_UP_WITH_MUST_BUY, True
@@ -668,6 +674,27 @@
        total_buy_money = BigOrderDealManager().get_total_buy_money(code)
        total_sell_money = BigOrderDealManager().get_total_sell_money(code)
        cls.set_big_num_deal_info(code, total_buy_money, total_sell_money)
@tool.singleton
class CancelRateHumanSettingManager:
    """
    手动撤单率设置
    """
    def __init__(self):
        # L后撤单
        self.l_down = {}
    def set_l_down(self, code, rate):
        self.l_down[code] = rate
    def get_l_down(self, code):
        return self.l_down.get(code)
    def remove_l_down(self, code):
        if code in self.l_down:
            self.l_down.pop(code)
# 计算成交位置之后的大单(特定笔数)的撤单比例
@@ -1530,7 +1557,8 @@
                trade_index = None
            canceled_buyno_map = local_today_canceled_buyno_map.get(code)
            for wi in watch_indexes:
                cancel_data = L2DataComputeUtil.is_canceled(code, wi, total_data, canceled_buyno_map, trade_index, deal_order_nos)
                cancel_data = L2DataComputeUtil.is_canceled(code, wi, total_data, canceled_buyno_map, trade_index,
                                                            deal_order_nos)
                if cancel_data:
                    if str(wi) in after_place_order_index_dict:
                        # 真实下单位置之后的按照权重比例来计算
constant.py
@@ -138,7 +138,7 @@
L_CANCEL_RATE_WITH_MUST_BUY = 0.9  # 加红L后
L_CANCEL_RATE_WITH_MUST_BUY_FOR_REDICAL_BUY = 0.95  # 扫入加红
L_CANCEL_RATE_WITH_MUST_BUY_FOR_REDICAL_BUY = 0.9  # 扫入加红
L_CANCEL_RATE_WITH_HALF_MUST_BUY_FOR_REDICAL_BUY = 0.85  # 扫入半加红
trade/buy_radical/radical_buy_data_manager.py
@@ -625,7 +625,7 @@
        @param count:
        @return:
        """
        cls.__process_add_white(code)
        cls.__process_add_must(code)
        if gpcode_manager.MustBuyCodesManager().is_in_cache(code):
            return
        total_deal_big_order_result = get_total_deal_big_order_info(code,
@@ -647,10 +647,10 @@
                    return
                gpcode_manager.MustBuyCodesManager().add_code(code)
                trade_record_log_util.add_must_buy(code, "累计成交大单足够")
        cls.__process_add_white(code)
        cls.__process_add_must(code)
    @classmethod
    def __process_add_white(cls, code):
    def __process_add_must(cls, code):
        """
        处理加白
        @param code:
@@ -658,7 +658,7 @@
        """
        if not constant.CAN_AUTO_ADD_WHITE:
            return
        if gpcode_manager.WhiteListCodeManager().is_in_cache(code):
        if gpcode_manager.MustBuyCodesManager().is_in_cache(code):
            return
        human_setting_money = TotalDealBigOrderThresholdMoneyManager().get_money_cache(code)
        if not human_setting_money:
@@ -680,7 +680,7 @@
                    total_buy_data_list = BigOrderDealManager().get_total_buy_data_list(code)
                    min_order_no = order_begin_pos.min_order_no
                    if min_order_no is None:
                        async_log_util.warning(logger_debug, "处理成交大单足够加白: 最小订单号为空")
                        async_log_util.warning(logger_debug, "处理成交大单足够加红: 最小订单号为空")
                        return
                    bigger_money = l2_data_util.get_big_money_val(gpcode_manager.get_limit_up_price_as_num(code),
                                                                  tool.is_ge_code(code))
@@ -690,9 +690,9 @@
                    THRESHOLD_MONEY, is_temp_threshold_money = BeforeSubDealBigOrderManager().get_big_order_threshold_info(
                        code)
                    if deal_money >= 2 * THRESHOLD_MONEY:
                        gpcode_manager.WhiteListCodeManager().add_code(code)
                        trade_record_log_util.add_common_msg(code, "加白",
                                                             f"{code}大单成交足够加白, 本批次成交金额-{deal_money}/{THRESHOLD_MONEY * 2}  累计大单金额:{total_deal_big_order_result[1]}/{total_deal_big_order_result[2]}")
                        gpcode_manager.MustBuyCodesManager().add_code(code)
                        trade_record_log_util.add_common_msg(code, "加红",
                                                             f"{code}大单成交足够加红, 本批次成交金额-{deal_money}/{THRESHOLD_MONEY * 2}  累计大单金额:{total_deal_big_order_result[1]}/{total_deal_big_order_result[2]}")
                    else:
                        async_log_util.info(logger_debug,
                                            f"{code}-成交大单少({deal_money}/{2 * THRESHOLD_MONEY},最小订单号-{order_begin_pos.min_order_no}),不能加白")
@@ -722,20 +722,10 @@
        @param code:
        @return:
        """
        if 1 > 0:
            # 大单足够暂时不做处理
            return
        # 如果加绿了就直接拉白
        if gpcode_manager.GreenListCodeManager().is_in_cache(code):
            if gpcode_manager.WhiteListCodeManager().is_in_cache(code):
                return
            gpcode_manager.WhiteListCodeManager().add_code(code)
            trade_record_log_util.add_white_buy(code, "已加绿且大单足够")
        else:
            if gpcode_manager.MustBuyCodesManager().is_in_cache(code):
                return
            gpcode_manager.MustBuyCodesManager().add_code(code)
            trade_record_log_util.add_must_buy(code, "大单足够")
        # if not gpcode_manager.MustBuyCodesManager().is_in_cache(code):
        #     gpcode_manager.MustBuyCodesManager().add_code(code)
        #     trade_record_log_util.add_must_buy(code, "大单足够")
        pass
class RadicalBuyBlockManager:
trade/trade_result_manager.py
@@ -1,7 +1,7 @@
# 虚拟买成功
import logging
from cancel_strategy.s_l_h_cancel_strategy import HourCancelBigNumComputer
from cancel_strategy.s_l_h_cancel_strategy import HourCancelBigNumComputer, CancelRateHumanSettingManager
from cancel_strategy.s_l_h_cancel_strategy import LCancelBigNumComputer
from cancel_strategy.s_l_h_cancel_strategy import SCancelBigNumComputer
from code_attribute.gpcode_manager import MustBuyCodesManager, GreenListCodeManager, WantBuyCodesManager, \
@@ -142,6 +142,7 @@
    NewGCancelBigNumComputer().cancel_success(code)
    JCancelBigNumComputer().cancel_success(code)
    NBCancelBigNumComputer().cancel_success(code)
    CancelRateHumanSettingManager().remove_l_down(code)
    # 记录最近的撤单时间
    if from_real_cancel:
        __latest_cancel_l2_data_dict[code] = total_datas[-1]