Administrator
2023-10-27 ac0551c20c35d84796f7975cf5f4c3c615b56334
撤单记录增加下单起始位置参数
4个文件已修改
65 ■■■■ 已修改文件
l2/cancel_buy_strategy.py 45 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
l2/l2_transaction_data_manager.py 6 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
server.py 11 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
trade/trade_record_log_util.py 3 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
l2/cancel_buy_strategy.py
@@ -420,10 +420,11 @@
            RedisUtils.realse(__redis)
    # 保存成交位置到执行位置的揽括范围数据
    def __save_watch_index_set(self, code, indexes):
    def __save_watch_index_set(self, code, buy_single_index, indexes):
        trade_record_log_util.add_cancel_watch_indexes_log(code,
                                                           trade_record_log_util.CancelWatchIndexesInfo(
                                                               trade_record_log_util.CancelWatchIndexesInfo.CANCEL_TYPE_H,
                                                               buy_single_index,
                                                               list(indexes)))
        CodeDataCacheUtil.set_cache(self.__cancel_watch_indexs_cache, code, indexes)
        key = f"h_cancel_watch_indexs-{code}"
@@ -460,7 +461,7 @@
        # 计算观察索引,倒序计算
    def __compute_watch_index(self, code):
    def __compute_watch_index(self, code, buy_single_index):
        if self.__cancel_watch_indexs_cache.get(code):
            return
        real_place_order_index = self.__SecondCancelBigNumComputer.get_real_place_order_index_cache(code)
@@ -539,7 +540,7 @@
        if watch_indexes or watch_indexes_up:
            watch_indexes |= watch_indexes_up
            self.__save_watch_index_set(code, 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}")
        # 设置真实下单位置
@@ -566,13 +567,13 @@
        return True
    # 设置成交进度
    def set_transaction_index(self, code, index):
    def set_transaction_index(self, code, buy_single_index, index):
        try:
            if index == self.__transaction_progress_index_dict.get(code):
                return
            self.__transaction_progress_index_dict[code] = index
            if self.__need_compute_watch_indexes(code, index):
                self.__compute_watch_index(code)
                self.__compute_watch_index(code, buy_single_index)
        except Exception as e:
            l2_log.h_cancel_debug(code, "设置成交进度位置出错:{}", str(e))
            logger_l2_h_cancel.exception(e)
@@ -631,7 +632,7 @@
                    break
            if need_compute:
                if self.__need_compute_watch_indexes(code, self.__transaction_progress_index_dict.get(code)):
                    self.__compute_watch_index(code)
                    self.__compute_watch_index(code, buy_single_index)
                    watch_index_set = self.__get_watch_index_set_cache(code)
        if not watch_index_set:
            return False, "没有监听索引"
@@ -648,7 +649,6 @@
                                                                                                         total_data,
                                                                                                         local_today_canceled_buyno_map.get(
                                                                                                             code))
                cancel_num += val['num'] * (data['re'] - left_count)
            rate = round(cancel_num / total_num, 4)
            if rate >= constant.H_CANCEL_RATE:
@@ -893,7 +893,7 @@
                self.__cancel_watch_index_cache[code].discard(index)
            RedisUtils.srem_async(self.__db, f"l_cancel_watch_index-{code}", index)
    def __set_watch_indexes(self, code, indexes):
    def __set_watch_indexes(self, code, buy_single_index, indexes):
        self.__cancel_watch_index_cache[code] = indexes
        RedisUtils.delete_async(self.__db, f"l_cancel_watch_index-{code}")
        for index in indexes:
@@ -901,7 +901,7 @@
        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,
                                                                   trade_record_log_util.CancelWatchIndexesInfo.CANCEL_TYPE_L_DOWN,buy_single_index,
                                                                   list(indexes)))
    def __get_watch_indexes(self, code):
@@ -913,11 +913,11 @@
            return cache_result[1]
        return set()
    def __set_near_by_trade_progress_indexes(self, code, indexes):
    def __set_near_by_trade_progress_indexes(self, code, buy_single_index, indexes):
        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,
                                                                   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(),
@@ -955,7 +955,7 @@
                self.del_watch_index(code)
    # 计算观察索引,倒序计算
    def compute_watch_index(self, code, start_index, end_index):
    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值
@@ -1048,31 +1048,31 @@
                        if left_count > 0:
                            watch_indexes.add(i)
                            break
                self.__set_watch_indexes(code, watch_indexes)
                self.__set_watch_indexes(code,buy_single_index, watch_indexes)
                l2_log.l_cancel_debug(code, f"设置监听范围, 数据范围:{re_start_index}-{end_index} 监听范围-{watch_indexes}")
    # 设置真实下单位置
    def set_real_place_order_index(self, code, index, buy_single_index=None):
        self.__real_place_order_index_dict[code] = index
        if buy_single_index:
            self.compute_watch_index(code, buy_single_index, 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, 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, index)
            self.__compute_trade_progress_near_by_indexes(code, buy_single_index, buy_single_index, index)
    # 重新计算L上
    def re_compute_l_up_watch_indexes(self, code):
    def re_compute_l_up_watch_indexes(self, code, buy_single_index):
        if code not in self.__last_trade_progress_dict:
            return
        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, 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))
    # 计算范围内的成交位临近未撤大单
    def __compute_trade_progress_near_by_indexes(self, code, start_index, end_index):
    def __compute_trade_progress_near_by_indexes(self, code, buy_single_index, start_index, end_index):
        if start_index is None or end_index is None:
            return
        total_datas = local_today_datas.get(code)
@@ -1107,17 +1107,17 @@
        # 保存数据
        if changed:
            l2_log.l_cancel_debug(code, f"设置成交位临近撤单监控范围:{watch_indexes} 计算范围:{start_index}-{end_index}")
            self.__set_near_by_trade_progress_indexes(code, 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)
    # 设置成交位置,成交位置变化之后相应的监听数据也会发生变化
    def set_trade_progress(self, code, index, total_datas):
    def set_trade_progress(self, code, buy_single_index, index, total_datas):
        if self.__last_trade_progress_dict.get(code) == index:
            return
        self.__last_trade_progress_dict[code] = index
        # 重新计算成交位置临近大单撤单
        self.__compute_trade_progress_near_by_indexes(code, 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:
@@ -1136,6 +1136,7 @@
    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])
        # 计算监听的总条数
l2/l2_transaction_data_manager.py
@@ -91,18 +91,18 @@
                #     if need_cancel:
                #         L2TradeDataProcessor.cancel_buy(code, f"D撤:{msg}", source="d_cancel")
                LCancelBigNumComputer().set_trade_progress(code, buy_progress_index, total_datas)
                LCancelBigNumComputer().set_trade_progress(code, order_begin_pos.buy_single_index, buy_progress_index, total_datas)
                FastCancelBigNumComputer().set_trade_progress(code, buy_progress_index)
                SecondCancelBigNumComputer().set_transaction_index(
                    code,
                    buy_progress_index)
                if order_begin_pos and order_begin_pos.buy_exec_index and order_begin_pos.buy_exec_index > -1:
                    HourCancelBigNumComputer().set_transaction_index(code, buy_progress_index)
                    HourCancelBigNumComputer().set_transaction_index(code, order_begin_pos.buy_single_index, buy_progress_index)
            else:
                pass
            if order_begin_pos and order_begin_pos.buy_exec_index and order_begin_pos.buy_exec_index > -1:
                # 触发L撤上重新计算
                LCancelBigNumComputer().re_compute_l_up_watch_indexes(code)
                LCancelBigNumComputer().re_compute_l_up_watch_indexes(code, order_begin_pos.buy_single_index)
        except Exception as e:
            hx_logger_l2_transaction.exception(e)
server.py
@@ -407,17 +407,14 @@
                                    buy_one_price_ = decimal.Decimal(round(float(buy_one_price), 2)).quantize(
                                        decimal.Decimal("0.00"))
                                    # 获取执行位时间
                                    buy_single_index, buy_exec_index, compute_index, num, count, max_num_set, volume_rate = l2_data_manager.TradePointManager().get_buy_compute_start_data(
                                        code)
                                    order_begin_pos = l2_data_manager.TradePointManager().get_buy_compute_start_data_cache(code)
                                    if True:
                                        # 只有下单过后才获取交易进度
                                        exec_time = None
                                        try:
                                            if buy_exec_index:
                                            if order_begin_pos.buy_exec_index and order_begin_pos.buy_exec_index > -1:
                                                exec_time = \
                                                    l2.l2_data_util.local_today_datas.get(code)[buy_exec_index]["val"][
                                                        "time"]
                                                    l2.l2_data_util.local_today_datas.get(code)[order_begin_pos.buy_exec_index]["val"]["time"]
                                        except:
                                            pass
                                        buy_progress_index = self.tradeBuyQueue.compute_traded_index(code,
@@ -425,7 +422,7 @@
                                                                                                     buy_queue_result_list,
                                                                                                     exec_time)
                                        if buy_progress_index is not None:
                                            LCancelBigNumComputer().set_trade_progress(code, buy_progress_index,
                                            LCancelBigNumComputer().set_trade_progress(code, order_begin_pos.buy_single_index, buy_progress_index,
                                                                                       l2.l2_data_util.local_today_datas.get(
                                                                                           code))
trade/trade_record_log_util.py
@@ -58,9 +58,10 @@
    CANCEL_TYPE_L_DOWN = "l_cancel_down"
    CANCEL_TYPE_D = "d_cancel"
    def __init__(self, cancel_type, watch_indexes: list):
    def __init__(self, cancel_type, buy_single_index, watch_indexes: list):
        self.cancel_type = cancel_type
        self.watch_indexes = watch_indexes
        self.buy_single_index = buy_single_index
    def to_json_str(self):
        return json.dumps(vars(self))