Administrator
7 天以前 6640ec047111cd789bf463d4e3572a197f104763
L后已撤比例修改
1个文件已修改
92 ■■■■■ 已修改文件
cancel_strategy/s_l_h_cancel_strategy.py 92 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
cancel_strategy/s_l_h_cancel_strategy.py
@@ -1519,6 +1519,95 @@
        self.__set_watch_indexes(code, watch_indexes_info[0], watch_indexes_info[1], watch_indexes)
    def __compute_l_down_canceled_rate(self, code, total_data):
        """
        计算L后的已经撤单的比例
        @param code:
        @return: 比例, 已经撤单的索引
        """
        watch_indexes_info = self.__get_watch_indexes_cache(code)
        if not watch_indexes_info:
            return 0, []
        # 这是下单位置之后的索引: key为字符串
        after_place_order_index_dict = self.__get_cancel_l_down_after_place_order_index_dict(code)
        if after_place_order_index_dict is None:
            after_place_order_index_dict = {}
        after_place_order_index_by_dict = self.__l_down_after_by_big_order_weight_dict.get(code)
        if after_place_order_index_by_dict is None:
            after_place_order_index_by_dict = {}
        watch_indexes = set([int(i) for i in watch_indexes_info[2]])
        try:
            # 将备用订单加进去
            watch_indexes_by = self.__l_down_after_by_big_order_dict.get(code)
            if watch_indexes_by:
                # 是否是下单30分钟内
                real_place_order_info = self.__real_place_order_index_dict.get(code)
                if real_place_order_info and tool.trade_time_sub(total_data[-1]["val"]["time"],
                                                                 total_data[real_place_order_info[0]]["val"][
                                                                     "time"]) < 30 * 60:
                    # 下单30分钟内有效
                    watch_indexes |= watch_indexes_by
                else:
                    # 清除备用大单
                    watch_indexes_by.clear()
        except Exception as e:
            l2_log.l_cancel_debug(code, "将L2后后半段备用大单加入计算出错:{}", str(e))
        # 计算监听的总条数
        total_num = 0
        max_num, max_num_count = 0, 0
        thresh_hold_rate, must_buy, cancel_rate_info = LCancelRateManager.get_cancel_rate(code)
        for wi in watch_indexes:
            if str(wi) in after_place_order_index_dict:
                # 如果加红就需要计算分母
                if must_buy:
                    total_num += total_data[wi]["val"]["num"] * (
                            10 - after_place_order_index_dict[str(wi)]) // 10
                continue
            elif str(wi) in after_place_order_index_by_dict:
                if must_buy:
                    total_num += total_data[wi]["val"]["num"] * (
                            10 - after_place_order_index_by_dict[str(wi)]) // 10
                continue
            total_num += total_data[wi]["val"]["num"] * total_data[wi]["re"]
            if total_data[wi]["val"]["num"] > max_num:
                max_num = total_data[wi]["val"]["num"]
                max_num_count = 1
            elif total_data[wi]["val"]["num"] == max_num:
                max_num_count += 1
        # 计算撤单比例
        watch_indexes_list = list(watch_indexes)
        watch_indexes_list.sort()
        canceled_num = 0
        # 记录撤单索引
        canceled_indexes = []
        deal_order_nos = HuaXinBuyOrderManager().get_deal_buy_order_nos(code)
        if deal_order_nos is None:
            deal_order_nos = set()
        trade_index, is_default = TradeBuyQueue().get_traded_index(code)
        if is_default:
            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)
            if cancel_data:
                if str(wi) in after_place_order_index_dict:
                    # 真实下单位置之后的按照权重比例来计算
                    canceled_num += total_data[wi]["val"]["num"] * (
                            10 - after_place_order_index_dict[str(wi)]) // 10
                elif str(wi) in after_place_order_index_by_dict:
                    canceled_num += total_data[wi]["val"]["num"] * (
                            10 - after_place_order_index_by_dict[str(wi)]) // 10
                else:
                    canceled_num += total_data[wi]["val"]["num"]
                canceled_indexes.append(cancel_data["index"])
        rate = round(canceled_num / total_num, 3)
        return rate, canceled_indexes
    def __compute_need_cancel(self, code, buy_exec_index, start_index, end_index, total_data, is_first_code):
        """
        L后撤单;
@@ -1979,7 +2068,8 @@
            fresults.append(100.00)
        else:
            fresults.append(round(total_cancel_num * 100 / (total_nums - total_after_num), 2))
        fresults.append(LCancelRateManager.get_cancel_rate(code)[0]*100)
        canceled_info = self.__compute_l_down_canceled_rate(code, total_datas)
        fresults.append(canceled_info[0] * 100)
        return fresults