Administrator
2025-05-26 a846b46f15ad309a62fe400cf78dd7fc888155d7
完善大单够了加白机制
8个文件已修改
198 ■■■■ 已修改文件
api/outside_api_command_callback.py 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
code_attribute/gpcode_manager.py 30 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
l2/l2_data_manager.py 4 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
l2/l2_data_manager_new.py 73 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
servers/huaxin_trade_server.py 12 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
trade/buy_radical/radical_buy_data_manager.py 66 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
trade/buy_radical/radical_buy_strategy.py 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
trade/trade_result_manager.py 5 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
api/outside_api_command_callback.py
@@ -344,14 +344,14 @@
                    fresult = {"code": 0, "data": datas}
            elif code_list_type == outside_api_command_manager.CODE_LIST_WHITE:
                if operate == outside_api_command_manager.OPERRATE_SET:
                    gpcode_manager.WhiteListCodeManager().add_code(code)
                    gpcode_manager.WhiteListCodeManager().add_code(code, is_human=True)
                    name = gpcode_manager.get_code_name(code)
                    if not name:
                        results = HistoryKDatasUtils.get_gp_codes_names([code])
                        if results:
                            gpcode_manager.CodesNameManager.add_first_code_name(code, results[code])
                elif operate == outside_api_command_manager.OPERRATE_DELETE:
                    gpcode_manager.WhiteListCodeManager().remove_code(code)
                    gpcode_manager.WhiteListCodeManager().remove_code(code, is_human=True)
                elif operate == outside_api_command_manager.OPERRATE_GET:
                    codes = gpcode_manager.WhiteListCodeManager().list_codes_cache()
                    datas = []
code_attribute/gpcode_manager.py
@@ -401,6 +401,7 @@
class WhiteListCodeManager:
    __instance = None
    __redis_manager = redis_manager.RedisManager(2)
    __human_remove_codes = set()
    def __new__(cls, *args, **kwargs):
        if not cls.__instance:
@@ -421,14 +422,21 @@
        if data:
            self.__white_codes_cache |= data
    def add_code(self, code):
    def add_code(self, code, is_human=False):
        if not is_human and code in self.__human_remove_codes:
            # 机器加白,且被人为移白了就不能再加白
            return
        self.__white_codes_cache.add(code)
        RedisUtils.sadd(self.__get_redis(), "white_list_codes", code)
        RedisUtils.expire(self.__get_redis(), "white_list_codes", tool.get_expire())
    def remove_code(self, code):
    def remove_code(self, code, is_human=False):
        self.__white_codes_cache.discard(code)
        RedisUtils.srem(self.__get_redis(), "white_list_codes", code)
        if is_human:
            self.human_remove(code)
    def is_in(self, code):
        return RedisUtils.sismember(self.__get_redis(), "white_list_codes", code)
@@ -446,6 +454,24 @@
        self.__white_codes_cache.clear()
        RedisUtils.delete(self.__get_redis(), "white_list_codes")
    def human_remove(self, code):
        """
        人为移白
        @param code:
        @return:
        """
        self.__human_remove_codes.add(code)
    def clear_huamn_info(self, code):
        """
        移除人为干预信息
        @param code:
        @return:
        """
        if code in self.__human_remove_codes:
            self.__human_remove_codes.discard(code)
class BlackListCodeManager:
    __instance = None
l2/l2_data_manager.py
@@ -23,7 +23,7 @@
    # mode: 0-普通交易  1-快速交易
    def __init__(self, buy_single_index=None, buy_exec_index=-1, buy_compute_index=None, num=0, count=0,
                 max_num_set=None, buy_volume_rate=None, sell_info=None, threshold_money=None, mode=0, mode_desc=None,
                 at_limit_up=False, first_limit_up_buy=False):
                 at_limit_up=False, first_limit_up_buy=False, min_order_no = None):
        self.buy_single_index = buy_single_index
        self.buy_exec_index = buy_exec_index
        self.buy_compute_index = buy_compute_index
@@ -42,6 +42,8 @@
        self.at_limit_up = at_limit_up
        # 是否为首封买
        self.first_limit_up_buy = first_limit_up_buy
        # 统计批次大单成交的最小订单号
        self.min_order_no = min_order_no
    def get_max_num_set(self):
        if self.max_num_set:
l2/l2_data_manager_new.py
@@ -1522,32 +1522,35 @@
        _start_time = tool.get_now_timestamp()
        total_datas = local_today_datas[code]
        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 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
        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)
            # 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]
@@ -1566,9 +1569,11 @@
                                                     max_num_set=set(),
                                                     buy_volume_rate=buy_volume_rate,
                                                     mode=OrderBeginPosInfo.MODE_RADICAL,
                                                     mode_desc=f"大单不足扫入:{radical_result[2]} 是否跟人买入-{is_human_radical_buy}",
                                                     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])
@@ -2021,11 +2026,10 @@
        @param code:
        @param start_index:
        @param end_index:
        @return: (是否获取到信号, 信号位置, 扫入板块/消息, 扫入板块大单流入信息, 需要监听的大单)
        @return: (是否获取到信号, 信号位置, 扫入板块/消息, 扫入板块大单流入信息, 需要监听的大单, 统计上板大单成交的最小订单号)
        """
        # 激进买信号的时间
        def __can_order():
            # 判断是否是板上放量
            # if cls.__is_at_limit_up_buy(code, start_index):
@@ -2126,8 +2130,13 @@
                    single_index = i
                    break
            if single_index is not None:
                return True, single_index, f"有大单,大单情况:{big_order_deal_enough_result[1]}", watch_indexes
            return False, None, f"大单不足:{trade_index}-{end_index}  缺少的大单-{max(current_lack_money, total_lack_money)}  大单情况:{big_order_deal_enough_result[1]}", 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()
@@ -2171,7 +2180,7 @@
            # 如果板上放量不可买入就需要删除信号
            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
@@ -2245,6 +2254,8 @@
        @param end_index:
        @return: 信号信息(信号位,执行位), 消息, 可买入的板块
        """
        if True:
            return None, "此条不生效", None
        if not tool.is_sz_code(code):
            return None, "非深证的票", None
        # 判断抛压是否大于5000w
servers/huaxin_trade_server.py
@@ -839,6 +839,12 @@
                            if refer_sell_data:
                                sell_info = (refer_sell_data[0], refer_sell_data[1])
                            threshold_money = 0
                            every_deal_orders = EveryLimitupBigDealOrderManager.list_big_buy_deal_orders(code)
                            if every_deal_orders:
                                min_order_no = min(every_deal_orders, lambda x: x[0])[0]
                            else:
                                min_order_no = transaction_datas[-1][6]
                            order_begin_pos_info = OrderBeginPosInfo(buy_single_index=buy_single_index,
                                                                     buy_exec_index=buy_exec_index,
                                                                     buy_compute_index=buy_exec_index,
@@ -846,9 +852,11 @@
                                                                     max_num_set=set(),
                                                                     buy_volume_rate=buy_volume_rate,
                                                                     mode=OrderBeginPosInfo.MODE_RADICAL,
                                                                     mode_desc=f"扫入买入:{buy_blocks}",
                                                                     mode_desc=f"扫入买入:{buy_blocks}, 大单成交最小订单号:{min_order_no}",
                                                                     sell_info=sell_info,
                                                                     threshold_money=threshold_money)
                                                                     threshold_money=threshold_money,
                                                                     min_order_no= min_order_no
                                                                     )
                            L2TradeDataProcessor.save_order_begin_data(code, order_begin_pos_info)
                            buy_result = L2TradeDataProcessor.start_buy(code, total_datas[-1], total_datas[-1]["index"],
                                                                        True, block_info=buy_blocks_with_money)
trade/buy_radical/radical_buy_data_manager.py
@@ -11,7 +11,7 @@
import constant
import l2_data_util
from code_attribute.code_volumn_manager import CodeVolumeManager
from l2 import l2_data_util as l2_data_util_new, l2_log
from l2 import l2_data_util as l2_data_util_new, l2_log, l2_data_manager
from code_attribute import code_nature_analyse, code_volumn_manager, gpcode_manager
from code_attribute.code_l1_data_manager import L1DataManager
from code_attribute.gpcode_manager import WantBuyCodesManager
@@ -560,6 +560,7 @@
        @param count:
        @return:
        """
        cls.__process_add_white(code)
        if gpcode_manager.MustBuyCodesManager().is_in_cache(code):
            return
        total_deal_big_order_result = get_total_deal_big_order_info(code,
@@ -570,15 +571,54 @@
    @classmethod
    def place_order_success(cls, code):
        # 如果是加想,且成交大单足够就加红
        total_deal_big_order_result = get_total_deal_big_order_info(code,
                                                                    gpcode_manager.get_limit_up_price_as_num(code))
        if WantBuyCodesManager().is_in_cache(code):
            big_order_deal_enough_result = 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:
            if total_deal_big_order_result[0] <= 0:
                # 累计大单足够需要加红
                gpcode_manager.MustBuyCodesManager().add_code(code)
                trade_record_log_util.add_must_buy(code, "累计成交大单足够")
        cls.__process_add_white(code)
    @classmethod
    def __process_add_white(cls, code):
        """
        处理加白
        @param code:
        @return:
        """
        if gpcode_manager.WhiteListCodeManager().is_in_cache(code):
            return
        try:
            total_deal_big_order_result = get_total_deal_big_order_info(code,
                                                                        gpcode_manager.get_limit_up_price_as_num(code))
            if total_deal_big_order_result[0] <= 0 and total_deal_big_order_result[2] >= 1e8:
                # 1个亿以上的且本批次成交的大单金额大于2倍大单金额就加白
                order_begin_pos = TradePointManager().get_buy_compute_start_data_cache(code)
                is_placed_order = l2_data_manager.TradePointManager.is_placed_order(order_begin_pos)
                if not is_placed_order:
                    # 没有下过单
                    return
                if order_begin_pos and order_begin_pos.min_order_no is not None:
                    # 在 min_order_no 之后成交的大单金额
                    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, "处理成交大单足够加白: 最小订单号为空")
                        return
                    bigger_money = l2_data_util.get_big_money_val(gpcode_manager.get_limit_up_price_as_num(code),
                                                                  tool.is_ge_code(code))
                    deal_money = sum(
                        [x[2] for x in total_buy_data_list if x[0] >= min_order_no and x[2] >= bigger_money])
                    # 获取均大单
                    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]}")
        except Exception as e:
            logger_debug.exception(e)
            async_log_util.info(logger_debug, f"处理成交大单足够加白的问题:{str(e)}")
    @classmethod
    def market_info_change(cls, code):
@@ -1854,11 +1894,25 @@
    @classmethod
    def get_big_buy_deal_order_money_info(cls, code):
        """
        获取成交大单的信息
        @param code:
        @return: (总共大单成交金额, 最近成交大单的最后成交时间)
        """
        if cls.__deal_big_order_infos_dict.get(code):
            return sum([x[1] for x in cls.__deal_big_order_infos_dict[code]]), l2_huaxin_util.convert_time(
                cls.__deal_big_order_infos_dict[code][-1][2])
        return None
    @classmethod
    def list_big_buy_deal_orders(cls, code):
        """
        @param code:
        @return:[(订单号,金额, 最后成交时间)]
        """
        return cls.__deal_big_order_infos_dict.get(code, [])
class EveryLimitupBigDelegateOrderManager:
    """
trade/buy_radical/radical_buy_strategy.py
@@ -165,8 +165,8 @@
    left_limit_up_sell_money = selling_num * price
    # 每次上板的大单与金额
    big_order_count = radical_buy_data_manager.EveryLimitupBigDealOrderManager().get_big_buy_deal_order_count(code)
    big_order_money = radical_buy_data_manager.EveryLimitupBigDealOrderManager().get_big_buy_deal_order_money(code)
    big_order_count = radical_buy_data_manager.EveryLimitupBigDealOrderManager.get_big_buy_deal_order_count(code)
    big_order_money = radical_buy_data_manager.EveryLimitupBigDealOrderManager.get_big_buy_deal_order_money(code)
    if big_order_count >= 2:
        average_big_order_money = int(big_order_money / big_order_count)
        # 如果均价涨幅小于7%均大单等于299w
trade/trade_result_manager.py
@@ -4,7 +4,8 @@
from cancel_strategy.s_l_h_cancel_strategy import HourCancelBigNumComputer
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
from code_attribute.gpcode_manager import MustBuyCodesManager, GreenListCodeManager, WantBuyCodesManager, \
    WhiteListCodeManager
from l2 import l2_data_manager, place_order_single_data_manager
from l2.cancel_buy_strategy import FCancelBigNumComputer, \
    NewGCancelBigNumComputer, JCancelBigNumComputer, NBCancelBigNumComputer
@@ -111,6 +112,8 @@
    # 如果是扫入下单,下单之后就加红
    if order_begin_pos.mode == OrderBeginPosInfo.MODE_RADICAL:
        # 移除人为移白
        WhiteListCodeManager().clear_huamn_info(code)
        RadicalBuyDataManager.place_order_success(code)
    # 清除下单信号