Administrator
2024-01-19 a00da3062c6c825b585f82275823ac45cdeb6502
L后成交太快撤单
2个文件已修改
102 ■■■■■ 已修改文件
l2/cancel_buy_strategy.py 92 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
l2/l2_transaction_data_manager.py 10 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
l2/cancel_buy_strategy.py
@@ -924,6 +924,11 @@
    __SecondCancelBigNumComputer = SecondCancelBigNumComputer()
    # L后囊括范围未撤单/未成交的总手数
    __total_l_down_not_deal_num_dict = {}
    # L后最近的成交数信息
    __l_down_latest_deal_info_dict = {}
    __last_l_up_compute_info = {}
    __instance = None
@@ -1224,11 +1229,56 @@
            self.__set_near_by_trade_progress_indexes(code, buy_single_index, watch_indexes)
        self.__last_l_up_compute_info[code] = (time.time(), watch_indexes)
    # 计算L后还没成交的手数
    def __compute_total_l_down_not_deal_num(self, code):
        try:
            if code in self.__total_l_down_not_deal_num_dict and time.time() - self.__total_l_down_not_deal_num_dict[code][
                1] < 1:
                # 需要间隔1s更新一次
                return
            l_down_cancel_info = self.__cancel_watch_index_info_cache.get(code)
            if not l_down_cancel_info:
                return
            trade_progress = self.__last_trade_progress_dict.get(code)
            if trade_progress is None:
                return
            l_down_indexes = l_down_cancel_info[2]
            # 统计还未成交的数据
            total_left_num = 0
            total_datas = local_today_datas.get(code)
            for i in l_down_indexes:
                # 已经成交了的不计算
                if i <= trade_progress:
                    continue
                data = total_datas[i]
                val = data['val']
                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:
                    total_left_num += val["num"]
            limit_up_price = float(gpcode_manager.get_limit_up_price(code))
            total_money = limit_up_price * total_left_num
            # 如果200<=金额<=1000w才会生效,否则就设为-1
            if 20000 <= total_money <= 100000:
                pass
            else:
                total_left_num = -1
            self.__total_l_down_not_deal_num_dict[code] = (total_left_num, time.time())
        except Exception as e:
            async_log_util.exception(logger_l2_l_cancel, e)
    # 设置成交位置,成交位置变化之后相应的监听数据也会发生变化
    def set_trade_progress(self, code, buy_single_index, index, total_datas):
        if self.__last_trade_progress_dict.get(code) == index:
            self.__compute_total_l_down_not_deal_num(code)
            return
        self.__last_trade_progress_dict[code] = index
        self.__compute_total_l_down_not_deal_num(code)
        if not self.__is_l_down_can_cancel(code, buy_single_index):
            # L后已经不能守护
@@ -1252,6 +1302,48 @@
        #     self.compute_watch_index(code, self.__last_trade_progress_dict.get(code),
        #                              self.__real_place_order_index_dict.get(code))
    def add_transaction_data(self, transaction_data):
        if not transaction_data:
            return False, "成交数据为空"
        code = transaction_data[0]
        buyno_map = local_today_buyno_map.get(code)
        if not buyno_map:
            return False, "没找到买单字典"
        buy_data = buyno_map.get(str(transaction_data[6]))
        if not buy_data:
            return False, f"没有找到对应买单({transaction_data[6]})"
        total_datas = local_today_datas.get(code)
        if not total_datas:
            return False, "L2数据为空"
        l_down_cancel_info = self.__cancel_watch_index_info_cache.get(code)
        if not l_down_cancel_info:
            return False, "L撤为空"
        l_down_indexes = l_down_cancel_info[2]
        if buy_data["index"] not in l_down_indexes:
            return False, "非L撤监听数据成交"
        # 统计数据
        orgin_deal_data = self.__l_down_latest_deal_info_dict.get(code)
        if not orgin_deal_data:
            orgin_deal_data = [0, None]
        time_str = l2_huaxin_util.convert_time(transaction_data[3])
        if orgin_deal_data[1] != time_str:
            orgin_deal_data[0] = transaction_data[2]
            orgin_deal_data[1] = time_str
        else:
            orgin_deal_data[0] += transaction_data[2]
        self.__l_down_latest_deal_info_dict[code] = orgin_deal_data
        # 计算成交比例
        total_l_down_not_deal_num = self.__total_l_down_not_deal_num_dict.get(code)
        if total_l_down_not_deal_num is None:
            return False, "L后撤数据为空"
        threshold_rate = 0.5
        rate = orgin_deal_data[0] / (total_l_down_not_deal_num[0] * 100)
        if rate > threshold_rate:
            return True, f"达到撤单比例:{rate}/{threshold_rate}"
        else:
            return False, "尚未达到撤单比例"
    # 已经成交的索引
    def add_deal_index(self, code, index, buy_single_index):
        watch_indexes_info = self.__get_watch_indexes_cache(code)
l2/l2_transaction_data_manager.py
@@ -126,6 +126,16 @@
                            break
                except Exception as e:
                    async_log_util.error(hx_logger_l2_debug, str(e))
                try:
                    for d in datas:
                        if LCancelBigNumComputer().add_transaction_data(d)[0]:
                            L2TradeDataProcessor.cancel_buy(code, f"L后成交太快撤单:{d}")
                            order_begin_pos = None
                            break
                except Exception as e:
                    async_log_util.error(hx_logger_l2_debug, str(e))
            # 计算已经成交的大单
            big_money_count = 0
            for d in datas: