Administrator
2023-09-04 858c30ff646ecd8dd4defc8ccec4334e3fedd847
l2/cancel_buy_strategy.py
@@ -1092,7 +1092,7 @@
                        data = total_data[i]
                        val = data['val']
                        total_num += val['num'] * data['re']
                    if total_num >  threshold_num:
                    if total_num > threshold_num:
                        return
        self.__last_trade_progress_dict[code] = index
@@ -1109,14 +1109,16 @@
            # 判断当前订单是否已经撤单
            left_count = l2_data_source_util.L2DataSourceUtils.get_limit_up_buy_no_canceled_count(code, i, total_data,
                                                                                                  local_today_num_operate_map.get(code))
                                                                                                  local_today_num_operate_map.get(
                                                                                                      code))
            if left_count > 0:
                watch_indexes.add(i)
                total_num += val['num'] * data['re']
                if len(watch_indexes) >= constant.L_CANCEL_MIN_WATCH_COUNT and total_num > threshold_num:
                    break
        l2_log.l_cancel_debug(code, f"设置监听范围,成交进度-{index} , 数据范围:{start_index}-{end_index} 监听范围-{watch_indexes} 纯买手数:{total_num}/{threshold_num}")
        l2_log.l_cancel_debug(code,
                              f"设置监听范围,成交进度-{index} , 数据范围:{start_index}-{end_index} 监听范围-{watch_indexes} 纯买手数:{total_num}/{threshold_num}")
        # 数据维护
        add_indexes = watch_indexes - old_watch_indexes
        delete_indexes = old_watch_indexes - watch_indexes
@@ -1124,7 +1126,7 @@
        self.__del_watch_indexes(code, delete_indexes)
    def __compute_need_cancel(self, code, buy_exec_index, start_index, end_index, total_data,
                              local_today_num_operate_map, is_first_code):
                              _local_today_num_operate_map, is_first_code):
        watch_indexes = self.__get_watch_indexes_cache(code)
        if not watch_indexes:
            return False, None
@@ -1141,7 +1143,7 @@
            if L2DataUtil.is_limit_up_price_buy_cancel(val):
                # 查询买入位置
                buy_index = l2_data_source_util.L2DataSourceUtils.get_buy_index_with_cancel_data(code, data,
                                                                                                 local_today_num_operate_map)
                                                                                                 _local_today_num_operate_map)
                if buy_index is not None and buy_index in watch_indexes:
                    need_compute = True
                    break
@@ -1152,7 +1154,7 @@
                left_count = l2_data_source_util.L2DataSourceUtils.get_limit_up_buy_no_canceled_count(code,
                                                                                                      wi,
                                                                                                      total_data,
                                                                                                      local_today_num_operate_map)
                                                                                                      _local_today_num_operate_map)
                canceled_num += (total_data[wi]["re"] - left_count) * int(total_data[wi]["val"]["num"])
            rate = round(canceled_num / total_num, 3)
            l2_log.l_cancel_debug(code, f"计算范围:{start_index}-{end_index},已撤单比例:{rate}")
@@ -1161,7 +1163,7 @@
        return False, None
    def need_cancel(self, code, buy_exec_index, start_index, end_index, total_data, local_today_num_operate_map,
    def need_cancel(self, code, buy_exec_index, start_index, end_index, total_data, _local_today_num_operate_map,
                    is_first_code):
        time_space = tool.trade_time_sub(total_data[start_index]["val"]["time"],
                                         total_data[buy_exec_index]["val"]["time"])
@@ -1169,7 +1171,7 @@
        if time_space <= constant.L_CANCEL_START_TIME or int(tool.get_now_time_str().replace(":", "")) > int("145000"):
            return False, None
        can_cancel, cancel_data = self.__compute_need_cancel(code, buy_exec_index, start_index, end_index, total_data,
                                                             local_today_num_operate_map, is_first_code)
                                                             _local_today_num_operate_map, is_first_code)
        if can_cancel:
            # 判断成交进度位置到当前位置的净买入
            try:
@@ -1199,9 +1201,9 @@
                        if left_count > 0:
                            buy_nums += left_count * data["val"]["num"]
                            if buy_nums > threshold_num:
                                l2_log.l_cancel_debug(code, f"LX阻断L撤撤单:{buy_nums}/{threshold_num}")
                                l2_log.l_cancel_debug(code, f"LX阻断L撤撤单:{buy_nums}/{threshold_num}  成交位置-{transaction_index} 真实下单位置-{place_order_index}")
                                return False, "LX阻断L撤撤单"
                l2_log.l_cancel_debug(code, f"LX尚未阻断L撤撤单:{buy_nums}/{threshold_num}")
                l2_log.l_cancel_debug(code, f"LX尚未阻断L撤撤单:{buy_nums}/{threshold_num} 成交位置-{transaction_index} 真实下单位置-{place_order_index}")
                return can_cancel, cancel_data
            except Exception as e:
                l2_log.l_cancel_debug(code, f"LX撤单计算异常:{str(e)}")