Administrator
2024-02-05 8c7f84cbd0afde7600b0c67a8032fa19c57d8c41
L撤快速成交触发撤单修改
4个文件已修改
82 ■■■■■ 已修改文件
huaxin_client/l1_client_for_trade.py 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
l2/cancel_buy_strategy.py 59 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
l2/l2_data_manager_new.py 18 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
l2/l2_transaction_data_processor.py 1 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
huaxin_client/l1_client_for_trade.py
@@ -62,8 +62,8 @@
    def subscribe(self, codes: set):
        del_codes = self.__subscribed_codes - codes
        add_codes = codes - self.__subscribed_codes
        if add_codes:
            codes_sh, codes_sz = self.__seperate_codes(add_codes)
        if codes:
            codes_sh, codes_sz = self.__seperate_codes(codes)
            logger_local_huaxin_l1.info(f"新增订阅:{codes_sh}  {codes_sz}")
            if codes_sh:
                ret = self.__api.SubscribeMarketData(codes_sh, xmdapi.TORA_TSTP_EXD_SSE)
l2/cancel_buy_strategy.py
@@ -35,7 +35,8 @@
def set_real_place_position(code, index, buy_single_index=None, is_default = True):
    # DCancelBigNumComputer().set_real_order_index(code, index)
    SecondCancelBigNumComputer().set_real_place_order_index(code, index)
    LCancelBigNumComputer().set_real_place_order_index(code, index, buy_single_index=buy_single_index)
    LCancelBigNumComputer().set_real_place_order_index(code, index, buy_single_index=buy_single_index,
                                                       is_default=is_default)
    HourCancelBigNumComputer().set_real_place_order_index(code, index, buy_single_index)
    GCancelBigNumComputer().set_real_place_order_index(code, index, buy_single_index, is_default)
    FCancelBigNumComputer().set_real_order_index(code, index)
@@ -958,7 +959,7 @@
            for k in keys:
                code = k.split("-")[-1]
                val = RedisUtils.get(__redis, k)
                val = int(val)
                val = json.loads(val)
                CodeDataCacheUtil.set_cache(cls.__real_place_order_index_dict, code, val)
            keys = RedisUtils.keys(__redis, "l_cancel_near_by_index-*")
@@ -1048,11 +1049,12 @@
        if not watch_index_info or watch_index_info[1] > 0:
            return
        # 获取成交进度位与真实下单位置
        real_place_order_index = self.__real_place_order_index_dict.get(code)
        real_place_order_index_info = self.__real_place_order_index_dict.get(code)
        last_trade_progress_index = self.__last_trade_progress_dict.get(code)
        if not real_place_order_index or not last_trade_progress_index:
        if not real_place_order_index_info or not last_trade_progress_index:
            return
        self.compute_watch_index(code, watch_index_info[0], last_trade_progress_index + 1, real_place_order_index,
        self.compute_watch_index(code, watch_index_info[0], last_trade_progress_index + 1,
                                 real_place_order_index_info[0],
                                 re_compute=1)
    # 计算观察索引,倒序计算
@@ -1168,9 +1170,9 @@
            async_log_util.exception(logger_l2_l_cancel, e)
    # 设置真实下单位置
    def set_real_place_order_index(self, code, index, buy_single_index=None):
    def set_real_place_order_index(self, code, index, buy_single_index=None, is_default=False):
        l2_log.l_cancel_debug(code, f"设置真实下单位-{index},buy_single_index-{buy_single_index}")
        self.__real_place_order_index_dict[code] = index
        self.__real_place_order_index_dict[code] = (index, is_default)
        RedisUtils.setex_async(self.__db, f"l_cancel_real_place_order_index-{code}", tool.get_expire(), index)
        if buy_single_index is not None:
            self.compute_watch_index(code, buy_single_index, buy_single_index, index)
@@ -1189,7 +1191,7 @@
        if code not in self.__last_l_up_compute_info or time.time() - self.__last_l_up_compute_info[code][0] >= 3:
            self.__compute_trade_progress_near_by_indexes(code, buy_single_index,
                                                          self.__last_trade_progress_dict.get(code) + 1,
                                                          self.__real_place_order_index_dict.get(code))
                                                          self.__real_place_order_index_dict.get(code)[0])
    # 计算范围内的成交位临近未撤大单
    def __compute_trade_progress_near_by_indexes(self, code, buy_single_index, start_index, end_index):
@@ -1233,7 +1235,6 @@
    # 计算L后还没成交的手数
    def __compute_total_l_down_not_deal_num(self, code):
        # 只有真实获取到下单位置后才开始计算
        try:
            if code in self.__total_l_down_not_deal_num_dict and time.time() - \
@@ -1289,23 +1290,13 @@
            # L后已经不能守护
            HourCancelBigNumComputer().start_compute_watch_indexes(code, buy_single_index)
        # 重新计算成交位置临近大单撤单
        self.__compute_trade_progress_near_by_indexes(code, buy_single_index, index + 1,
                                                      self.__real_place_order_index_dict.get(code))
        real_place_order_index_info = self.__real_place_order_index_dict.get(code)
        real_place_order_index = None
        if real_place_order_index_info:
            real_place_order_index = real_place_order_index_info[0]
        # 成交进度与L下撤无关
        # try:
        #     # 已经有计算的无法触发计算
        #     old_watch_indexes = self.__get_watch_indexes_cache(code)
        #     if old_watch_indexes and self.__last_trade_progress_dict.get(code):
        #         return
        # finally:
        #     self.__last_trade_progress_dict[code] = index
        #
        # if self.__real_place_order_index_dict.get(code):
        #     # 触发计算
        #     self.compute_watch_index(code, self.__last_trade_progress_dict.get(code),
        #                              self.__real_place_order_index_dict.get(code))
        # 重新计算成交位置临近大单撤单
        self.__compute_trade_progress_near_by_indexes(code, buy_single_index, index + 1, real_place_order_index)
    def add_transaction_datas(self, code, transaction_datas):
        if not transaction_datas:
@@ -1347,6 +1338,10 @@
        if orgin_deal_data is None:
            return False, "L后暂时无成交"
        real_place_order_index_info = self.__real_place_order_index_dict.get(code)
        if real_place_order_index_info and real_place_order_index_info[1]:
            return False, "没获取到真实的下单位"
        threshold_rate = constant.L_CANCEL_FAST_DEAL_RATE
        rate = orgin_deal_data[0] / (total_l_down_not_deal_num[0] * 100)
        if rate > threshold_rate:
@@ -1370,11 +1365,11 @@
        if buy_single_index is None:
            return
        # 重新囊括1笔
        real_place_order_index = self.__real_place_order_index_dict.get(code)
        if real_place_order_index and real_place_order_index > index:
        real_place_order_info = self.__real_place_order_index_dict.get(code)
        if real_place_order_info and real_place_order_info[0] > index:
            total_datas = local_today_datas.get(code)
            min_num = int(5000 / (float(gpcode_manager.get_limit_up_price(code))))
            for j in range(index + 1, real_place_order_index):
            for j in range(index + 1, real_place_order_info[0]):
                data = total_datas[j]
                val = data['val']
                if data["index"] in watch_indexes:
@@ -1514,15 +1509,15 @@
            l2_log.l_cancel_debug(code, f"计算范围:{start_index}-{end_index},成交位临近已撤单比例:{rate}/{thresh_cancel_rate}")
            if rate >= thresh_cancel_rate:
                # 计算成交进度位置到当前下单位置的纯买额
                real_place_order_index = self.__real_place_order_index_dict.get(code)
                real_place_order_index_info = self.__real_place_order_index_dict.get(code)
                trade_progress_index = self.__last_trade_progress_dict.get(code)
                if real_place_order_index and trade_progress_index:
                if real_place_order_index_info and trade_progress_index:
                    total_num = 0
                    thresh_hold_money = l2_trade_factor.L2PlaceOrderParamsManager.get_base_m_val(code)
                    thresh_hold_money = thresh_hold_money * 3
                    # 阈值为2倍m值
                    thresh_hold_num = thresh_hold_money // (float(gpcode_manager.get_limit_up_price(code)) * 100)
                    for i in range(trade_progress_index + 1, real_place_order_index):
                    for i in range(trade_progress_index + 1, real_place_order_index_info[0]):
                        data = total_data[i]
                        val = data['val']
                        if not L2DataUtil.is_limit_up_price_buy(val):
@@ -1538,7 +1533,7 @@
                            if total_num > thresh_hold_num:
                                # 成交位到下单位还有足够的单没撤
                                l2_log.l_cancel_debug(code,
                                                      f"L上撤阻断: 成交位-{trade_progress_index} 真实下单位-{real_place_order_index} 阈值-{thresh_hold_money}")
                                                      f"L上撤阻断: 成交位-{trade_progress_index} 真实下单位-{real_place_order_index_info[0]} 阈值-{thresh_hold_money}")
                                return False, None
                canceled_indexes.sort()
l2/l2_data_manager_new.py
@@ -1574,6 +1574,22 @@
                count -= total_datas[i]["re"]
        return count
        # 将已经成交的过滤掉
    @classmethod
    def __filter_not_deal_indexes(cls, code, indexes):
        trade_index, is_default = transaction_progress.TradeBuyQueue().get_traded_index(code)
        if is_default:
            return indexes
        if trade_index is None:
            return indexes
        findexes = set()
        for index in indexes:
            if index < trade_index:
                continue
            findexes.add(index)
        return findexes
    # 统计买入净买量,不计算在买入信号之前的买撤单
    @classmethod
    def __sum_buy_num_for_order_3(cls, code, compute_start_index, compute_end_index, origin_num, origin_count,
@@ -1695,6 +1711,7 @@
                             buy_nums, threshold_num)
            max_buy_num_set_count = 0
            max_buy_num_set = cls.__filter_not_deal_indexes(code, max_buy_num_set)
            for i1 in max_buy_num_set:
                max_buy_num_set_count += total_datas[i1]["re"]
@@ -1833,6 +1850,7 @@
                not_buy_msg = f"【{i}】安全笔数不足,{buy_count}/{5}"
                continue
            max_buy_num_set = cls.__filter_not_deal_indexes(code, max_buy_num_set)
            if place_order_count == 0:
                if len(max_buy_num_set) < 1:
                    not_buy_msg = f"【{i}】首次下单无大单"
l2/l2_transaction_data_processor.py
@@ -62,7 +62,6 @@
                    async_log_util.error(hx_logger_l2_debug, str(e))
                try:
                    # 下单2s后才开始生效
                    if tool.trade_time_sub(total_datas[-1]["val"]["time"],total_datas[order_begin_pos.buy_exec_index]["val"]["time"]) > 2:
                        cresult = LCancelBigNumComputer().add_transaction_datas(code, datas)
                        if cresult[0]:
                            L2TradeDataProcessor.cancel_buy(code, f"L后成交太快撤单:{cresult[1]}")