Administrator
2023-11-09 13663fc5a29800ab0036e6f2dcdc79ef726f8035
错误日志定位
2个文件已修改
219 ■■■■ 已修改文件
l2/cancel_buy_strategy.py 213 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
l2/l2_data_manager_new.py 6 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
l2/cancel_buy_strategy.py
@@ -541,7 +541,7 @@
        if watch_indexes or watch_indexes_up:
            watch_indexes |= watch_indexes_up
            self.__save_watch_index_set(code, buy_single_index,  watch_indexes)
            self.__save_watch_index_set(code, buy_single_index, watch_indexes)
            l2_log.h_cancel_debug(code, f"设置监听范围, 数据范围:{real_place_order_index}-{end_index} 监听范围-{watch_indexes}")
        # 设置真实下单位置
@@ -609,7 +609,7 @@
                temp_index = int(temp_count * 9 / 10)
                self.__start_compute_index_dict[code] = not_cancel_indexes[temp_index]
        except Exception as e:
            async_log_util.exception(logger_l2_h_cancel,e)
            async_log_util.exception(logger_l2_h_cancel, e)
            l2_log.h_cancel_debug(code, "设置真实下单位置出错:{}", str(e))
    def need_cancel(self, code, buy_single_index, buy_exec_index, start_index, end_index, total_data,
@@ -807,7 +807,8 @@
                if temp_rate >= 1:
                    if temp_rate > 3:
                        temp_rate = 3
                    deal_rate = round((temp_rate * 3.5 - 2.5) / 100, 4) if is_up else round((temp_rate * 10.5 - 7.5) / 100, 4)
                    deal_rate = round((temp_rate * 3.5 - 2.5) / 100, 4) if is_up else round(
                        (temp_rate * 10.5 - 7.5) / 100, 4)
            base_rate += block_rate
            base_rate += deal_rate
@@ -905,7 +906,8 @@
        if indexes:
            trade_record_log_util.add_cancel_watch_indexes_log(code,
                                                               trade_record_log_util.CancelWatchIndexesInfo(
                                                                   trade_record_log_util.CancelWatchIndexesInfo.CANCEL_TYPE_L_DOWN,buy_single_index,
                                                                   trade_record_log_util.CancelWatchIndexesInfo.CANCEL_TYPE_L_DOWN,
                                                                   buy_single_index,
                                                                   list(indexes)))
    def __get_watch_indexes(self, code):
@@ -921,7 +923,8 @@
        if indexes:
            trade_record_log_util.add_cancel_watch_indexes_log(code,
                                                               trade_record_log_util.CancelWatchIndexesInfo(
                                                                   trade_record_log_util.CancelWatchIndexesInfo.CANCEL_TYPE_L_UP,buy_single_index,
                                                                   trade_record_log_util.CancelWatchIndexesInfo.CANCEL_TYPE_L_UP,
                                                                   buy_single_index,
                                                                   list(indexes)))
        self.__near_by_trade_progress_index_cache[code] = indexes
        RedisUtils.setex_async(self.__db, f"l_cancel_near_by_index-{code}", tool.get_expire(),
@@ -960,108 +963,117 @@
    # 计算观察索引,倒序计算
    def compute_watch_index(self, code, buy_single_index, start_index, end_index):
        total_datas = local_today_datas.get(code)
        if total_datas:
            # 计算的上截至位距离下截至位纯买额要小于2.5倍m值
            # thresh_hold_money = l2_trade_factor.L2PlaceOrderParamsManager.get_base_m_val(code)
            # thresh_hold_money = int(thresh_hold_money * 2.5)
            min_num = int(5000 / (float(gpcode_manager.get_limit_up_price(code))))
            # 统计净涨停买的数量
            not_cancel_indexes = []
            re_start_index = start_index
            MAX_COUNT = 5
            for j in range(start_index, end_index):
                data = total_datas[j]
                val = data['val']
                if not L2DataUtil.is_limit_up_price_buy(val):
                    continue
                if val["num"] < min_num:
                    continue
                left_count = l2_data_source_util.L2DataSourceUtils.get_limit_up_buy_no_canceled_count_v2(code,
                                                                                                         j,
                                                                                                         total_datas,
                                                                                                         local_today_canceled_buyno_map.get(
                                                                                                             code))
                if left_count > 0:
                    not_cancel_indexes.append(j)
            if not_cancel_indexes:
                temp_count = len(not_cancel_indexes)
                # 取后1/3的数据
                if temp_count >= 30:
                    temp_index = int(temp_count * 5 / 6)
                    re_start_index = not_cancel_indexes[temp_index]
                    MAX_COUNT = len(not_cancel_indexes[temp_index:])
                elif temp_count >= 5:
                    re_start_index = not_cancel_indexes[-5]
                else:
                    re_start_index = not_cancel_indexes[0]
            MIN_MONEYS = [300, 200, 100, 50]
            watch_indexes = set()
            for min_money in MIN_MONEYS:
                for i in range(end_index, re_start_index, -1):
                    try:
                        data = total_datas[i]
                        val = data['val']
                        if not L2DataUtil.is_limit_up_price_buy(val):
                            continue
                        # 小金额过滤
                        if float(val['price']) * val['num'] < min_money * 100:
                            continue
                        left_count = l2_data_source_util.L2DataSourceUtils.get_limit_up_buy_no_canceled_count_v2(code,
                                                                                                                 i,
                                                                                                                 total_datas,
                                                                                                                 local_today_canceled_buyno_map.get(
                                                                                                                     code))
                        if left_count > 0:
                            watch_indexes.add(i)
                            if len(watch_indexes) >= MAX_COUNT:
                                break
                    except Exception as e:
                        logger_l2_l_cancel.error(f"{code}: 范围: {start_index}-{end_index}  位置:{i}")
                        logger_l2_l_cancel.exception(e)
                if len(watch_indexes) >= MAX_COUNT:
                    break
            if watch_indexes:
                ##判断监听的数据中是否有大单##
                has_big_num = False
                for i in watch_indexes:
                    # 是否有大单
                    data = total_datas[i]
        try:
            l2_log.l_cancel_debug(code, f"计算L后囊括范围:{start_index}-{end_index}")
            total_datas = local_today_datas.get(code)
            if total_datas:
                # 计算的上截至位距离下截至位纯买额要小于2.5倍m值
                # thresh_hold_money = l2_trade_factor.L2PlaceOrderParamsManager.get_base_m_val(code)
                # thresh_hold_money = int(thresh_hold_money * 2.5)
                min_num = int(5000 / (float(gpcode_manager.get_limit_up_price(code))))
                # 统计净涨停买的数量
                not_cancel_indexes = []
                re_start_index = start_index
                MAX_COUNT = 5
                for j in range(start_index, end_index):
                    data = total_datas[j]
                    val = data['val']
                    if float(val['price']) * val['num'] > 100 * 100:
                        has_big_num = True
                    if not L2DataUtil.is_limit_up_price_buy(val):
                        continue
                    if val["num"] < min_num:
                        continue
                    left_count = l2_data_source_util.L2DataSourceUtils.get_limit_up_buy_no_canceled_count_v2(code,
                                                                                                             j,
                                                                                                             total_datas,
                                                                                                             local_today_canceled_buyno_map.get(
                                                                                                                 code))
                    if left_count > 0:
                        not_cancel_indexes.append(j)
                if not_cancel_indexes:
                    temp_count = len(not_cancel_indexes)
                    # 取后1/3的数据
                    if temp_count >= 30:
                        temp_index = int(temp_count * 5 / 6)
                        re_start_index = not_cancel_indexes[temp_index]
                        MAX_COUNT = len(not_cancel_indexes[temp_index:])
                    elif temp_count >= 5:
                        re_start_index = not_cancel_indexes[-5]
                    else:
                        re_start_index = not_cancel_indexes[0]
                MIN_MONEYS = [300, 200, 100, 50]
                watch_indexes = set()
                for min_money in MIN_MONEYS:
                    for i in range(end_index, re_start_index, -1):
                        try:
                            data = total_datas[i]
                            val = data['val']
                            if not L2DataUtil.is_limit_up_price_buy(val):
                                continue
                            # 小金额过滤
                            if float(val['price']) * val['num'] < min_money * 100:
                                continue
                            left_count = l2_data_source_util.L2DataSourceUtils.get_limit_up_buy_no_canceled_count_v2(
                                code,
                                i,
                                total_datas,
                                local_today_canceled_buyno_map.get(
                                    code))
                            if left_count > 0:
                                watch_indexes.add(i)
                                if len(watch_indexes) >= MAX_COUNT:
                                    break
                        except Exception as e:
                            logger_l2_l_cancel.error(f"{code}: 范围: {start_index}-{end_index}  位置:{i}")
                            logger_l2_l_cancel.exception(e)
                    if len(watch_indexes) >= MAX_COUNT:
                        break
                if not has_big_num:
                    # 无大单,需要找大单
                    for i in range(re_start_index, start_index, -1):
                if watch_indexes:
                    ##判断监听的数据中是否有大单##
                    has_big_num = False
                    for i in watch_indexes:
                        # 是否有大单
                        data = total_datas[i]
                        val = data['val']
                        # 涨停买,且未撤单
                        if not L2DataUtil.is_limit_up_price_buy(val):
                            continue
                        # 小金额过滤
                        if float(val['price']) * val['num'] < 100 * 100:
                            continue
                        left_count = l2_data_source_util.L2DataSourceUtils.get_limit_up_buy_no_canceled_count_v2(code,
                                                                                                                 i,
                                                                                                                 total_datas,
                                                                                                                 local_today_canceled_buyno_map.get(
                                                                                                                     code))
                        if left_count > 0:
                            watch_indexes.add(i)
                        if float(val['price']) * val['num'] > 100 * 100:
                            has_big_num = True
                            break
                self.__set_watch_indexes(code,buy_single_index, watch_indexes)
                l2_log.l_cancel_debug(code, f"设置监听范围, 数据范围:{re_start_index}-{end_index} 监听范围-{watch_indexes}")
                    if not has_big_num:
                        # 无大单,需要找大单
                        for i in range(re_start_index, start_index, -1):
                            data = total_datas[i]
                            val = data['val']
                            # 涨停买,且未撤单
                            if not L2DataUtil.is_limit_up_price_buy(val):
                                continue
                            # 小金额过滤
                            if float(val['price']) * val['num'] < 100 * 100:
                                continue
                            left_count = l2_data_source_util.L2DataSourceUtils.get_limit_up_buy_no_canceled_count_v2(
                                code,
                                i,
                                total_datas,
                                local_today_canceled_buyno_map.get(
                                    code))
                            if left_count > 0:
                                watch_indexes.add(i)
                                break
                    self.__set_watch_indexes(code, buy_single_index, watch_indexes)
                    l2_log.l_cancel_debug(code, f"设置监听范围, 数据范围:{re_start_index}-{end_index} 监听范围-{watch_indexes}")
        except Exception as e:
            l2_log.l_cancel_debug(code, f"计算L后囊括范围出错:{str(e)}")
            async_log_util.exception(logger_l2_l_cancel, e)
    # 设置真实下单位置
    def set_real_place_order_index(self, code, index, buy_single_index=None):
        l2_log.l_cancel_debug(code, f"设置真实下单位-{index},buy_single_index-{buy_single_index}")
        self.__real_place_order_index_dict[code] = index
        if buy_single_index:
            self.compute_watch_index(code, buy_single_index, buy_single_index, index)
        if self.__last_trade_progress_dict.get(code):
            self.__compute_trade_progress_near_by_indexes(code,buy_single_index, self.__last_trade_progress_dict.get(code) + 1, index)
            self.__compute_trade_progress_near_by_indexes(code, buy_single_index,
                                                          self.__last_trade_progress_dict.get(code) + 1, index)
        else:
            self.__compute_trade_progress_near_by_indexes(code, buy_single_index, buy_single_index, index)
@@ -1072,7 +1084,8 @@
        if code not in self.__real_place_order_index_dict:
            return
        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.__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))
    # 计算范围内的成交位临近未撤大单
@@ -1111,7 +1124,7 @@
        # 保存数据
        if changed:
            l2_log.l_cancel_debug(code, f"设置成交位临近撤单监控范围:{watch_indexes} 计算范围:{start_index}-{end_index}")
            self.__set_near_by_trade_progress_indexes(code,buy_single_index, watch_indexes)
            self.__set_near_by_trade_progress_indexes(code, buy_single_index, watch_indexes)
        self.__last_l_up_compute_info[code] = (time.time(), watch_indexes)
    # 设置成交位置,成交位置变化之后相应的监听数据也会发生变化
@@ -1121,7 +1134,8 @@
        self.__last_trade_progress_dict[code] = index
        # 重新计算成交位置临近大单撤单
        self.__compute_trade_progress_near_by_indexes(code, buy_single_index, index + 1, self.__real_place_order_index_dict.get(code))
        self.__compute_trade_progress_near_by_indexes(code, buy_single_index, index + 1,
                                                      self.__real_place_order_index_dict.get(code))
        # 成交进度与L下撤无关
        # try:
@@ -1140,7 +1154,6 @@
    def __compute_need_cancel(self, code, buy_exec_index, start_index, end_index, total_data, is_first_code):
        watch_indexes = self.__get_watch_indexes_cache(code)
        if not watch_indexes:
            return False, None
        watch_indexes = set([int(i) for i in watch_indexes])
        # 计算监听的总条数
@@ -1412,7 +1425,7 @@
            if len(watch_indexes) >= MAX_COUNT:
                break
        # 保存数据
        l2_log.f_cancel_debug(code,f"监听范围:{watch_indexes} 计算起始点:{c_start_index}")
        l2_log.f_cancel_debug(code, f"监听范围:{watch_indexes} 计算起始点:{c_start_index}")
        self.__set_watch_indexes(code, watch_indexes)
    def set_trade_progress(self, code, index):
l2/l2_data_manager_new.py
@@ -295,6 +295,7 @@
                l2_log.debug(code, "触发撤单,撤单位置:{} ,撤单原因:{}", index, "F撤不够2笔触发撤单")
                cls.cancel_buy(code, msg="F撤不够2笔触发撤单")
                return
        l2_log.debug(code, "设置真实下单位:{}",index)
        cancel_buy_strategy.set_real_place_position(code, index, order_begin_pos.buy_single_index)
    # 处理华鑫L2数据
@@ -485,7 +486,8 @@
                    logging.exception(e)
                async_log_util.error(logger_l2_error,
                                     f"H撤出错 参数:buy_single_index-{_buy_single_index} buy_exec_index-{_buy_exec_index} {str(e)}")
                async_log_util.exception(logger_l2_error, e)
                # async_log_util.exception(logger_l2_error, e)
                logger_l2_error.exception(e)
            finally:
                # l2_data_log.l2_time(code, round(t.time() * 1000) - _start_time, "已下单-H撤大单计算")
                pass
@@ -520,7 +522,7 @@
            except Exception as e:
                async_log_util.error(logger_l2_error,
                                     f"L撤出错 参数:buy_single_index-{_buy_single_index} buy_exec_index-{_buy_exec_index} 错误原因:{str(e)}")
                logger_l2_error.exception(e)
                # logger_l2_error.exception(e)
                async_log_util.exception(logger_l2_error, e)
            finally:
                # l2_data_log.l2_time(code, round(t.time() * 1000) - _start_time, "已下单-L撤大单计算")