Administrator
2023-09-28 36b42e20e14b34c7f7e39640d71aded099b6ca99
l2/cancel_buy_strategy.py
@@ -258,7 +258,8 @@
                            continue
                        # 查询买入位置
                        buy_index = l2_data_source_util.L2DataSourceUtils.get_buy_index_with_cancel_data_v2(data,
                                                                                                            local_today_buyno_map.get(code))
                                                                                                            local_today_buyno_map.get(
                                                                                                                code))
                        if buy_index is not None and transaction_index < buy_index < real_place_order_index:
                            cancel_num += total_data[buy_index]["re"] * int(total_data[buy_index]["val"]["num"])
                            if need_cancel:
@@ -319,7 +320,8 @@
                    elif L2DataUtil.is_limit_up_price_buy_cancel(val):
                        # 查询买入位置
                        buy_index = l2_data_source_util.L2DataSourceUtils.get_buy_index_with_cancel_data_v2(data,
                                                                                                            local_today_buyno_map.get(code))
                                                                                                            local_today_buyno_map.get(
                                                                                                                code))
                        if buy_index is not None and buy_single_index <= buy_index:
                            if place_order_index and place_order_index >= buy_index:
                                cancel_num += total_data[buy_index]["re"] * int(total_data[buy_index]["val"]["num"])
@@ -944,13 +946,17 @@
            watch_indexes_list = list(watch_indexes)
            watch_indexes_list.sort()
            canceled_num = 0
            # 记录撤单索引
            canceled_indexes = []
            for wi in watch_indexes:
                left_count = l2_data_source_util.L2DataSourceUtils.get_limit_up_buy_no_canceled_count_v2(code,
                                                                                                         wi,
                                                                                                         total_data,
                                                                                                         local_today_canceled_buyno_map.get(
                                                                                                             code))
                canceled_num += (total_data[wi]["re"] - left_count) * total_data[wi]["val"]["num"]
                cancel_data = l2_data_source_util.L2DataSourceUtils.get_limit_up_buy_canceled_data_v2(code,
                                                                                                      wi,
                                                                                                      total_data,
                                                                                                      local_today_canceled_buyno_map.get(
                                                                                                          code))
                if cancel_data:
                    canceled_num += total_data[wi]["val"]["num"] * total_data[wi]["re"]
                    canceled_indexes.append(cancel_data["index"])
                # if wi == watch_indexes_list[-1] and left_count == 0:
                #     # 离下单位置最近的一个撤单,必须触发撤单
                #     l2_log.l_cancel_debug(code, f"计算范围:{start_index}-{end_index},临近撤单:{wi}")
@@ -960,11 +966,14 @@
            thresh_hold_rate = LCancelRateManager.get_cancel_rate(code)
            l2_log.l_cancel_debug(code, f"计算范围:{start_index}-{end_index},已撤单比例:{rate}/{thresh_hold_rate}")
            if rate >= thresh_hold_rate:
                return True, total_data[-1]
                canceled_indexes.sort()
                l2_log.l_cancel_debug(code, f"L下撤单,撤单位置:{canceled_indexes[-1]}")
                return True, total_data[canceled_indexes[-1]]
        return False, None
    def __compute_near_by_trade_progress_need_cancel(self, code, buy_exec_index, start_index, end_index, total_data, is_first_code):
    def __compute_near_by_trade_progress_need_cancel(self, code, buy_exec_index, start_index, end_index, total_data,
                                                     is_first_code):
        watch_indexes = self.__get_near_by_trade_progress_indexes_cache(code)
        if not watch_indexes:
            return False, None
@@ -988,17 +997,23 @@
        if need_compute:
            # 计算撤单比例
            canceled_count = 0
            canceled_indexes = []
            for wi in watch_indexes:
                left_count = l2_data_source_util.L2DataSourceUtils.get_limit_up_buy_no_canceled_count_v2(code,
                                                                                                         wi,
                                                                                                         total_data,
                                                                                                         local_today_canceled_buyno_map.get(
                                                                                                             code))
                canceled_count += total_data[wi]["re"] - left_count
                canceled_data = l2_data_source_util.L2DataSourceUtils.get_limit_up_buy_canceled_data_v2(code,
                                                                                                        wi,
                                                                                                        total_data,
                                                                                                        local_today_canceled_buyno_map.get(
                                                                                                            code))
                if canceled_data:
                    canceled_indexes.append(canceled_data["index"])
                    canceled_count += total_data[wi]["re"]
            rate = round(canceled_count / total_count, 3)
            l2_log.l_cancel_debug(code, f"计算范围:{start_index}-{end_index},成交位临近已撤单比例:{rate}")
            if rate >= LCancelRateManager.get_cancel_rate(code):
                return True, total_data[-1]
            thresh_cancel_rate = LCancelRateManager.get_cancel_rate(code)
            l2_log.l_cancel_debug(code, f"计算范围:{start_index}-{end_index},成交位临近已撤单比例:{rate}/{thresh_cancel_rate}")
            if rate >= thresh_cancel_rate:
                canceled_indexes.sort()
                l2_log.l_cancel_debug(code, f"L上撤单,撤单位置:{canceled_indexes[-1]}")
                return True, total_data[canceled_indexes[-1]]
        return False, None