Administrator
2024-04-23 545d65a4febc85d628aedf1547d6f9efebce34fd
板上放小量不下单,加红撤单比例调整
3个文件已修改
115 ■■■■ 已修改文件
constant.py 23 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
l2/cancel_buy_strategy.py 55 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
l2/l2_data_manager_new.py 37 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
constant.py
@@ -72,15 +72,13 @@
CACHE_PATH = f"{'D:' if is_windows() else '/home/userzjj'}/trade_cache"
# S撤比例
S_CANCEL_MIN_MONEY = 98
S_CANCEL_SECOND_RATE = 0.59
S_CANCEL_THIRD_RATE = 0.49
# s撤守护时间
S_CANCEL_EXPIRE_TIME = 1
# S撤
F_FAST_RATE = 0.25  # S快砸
F_FAST_RATE_WITH_MUST_BUY = 0.5  # S快砸加红
# H撤比例
H_CANCEL_RATE = 0.80
H_CANCEL_RATE = 0.80  # H撤比例
H_CANCEL_RATE_WITH_MUST_BUY = 0.95  # 加红H撤比例
# L撤无法生效的撤单比例
H_CANCEL_RATE_WITH_LDOWN_CANT_INVALID = 0.69
H_CANCEL_MIN_MONEY = 98
@@ -125,9 +123,15 @@
L_CANCEL_MIN_WATCH_COUNT = 10
# 撤单比例
L_CANCEL_RATE = 0.6
L_CANCEL_RATE = 0.6  # L后
L_CANCEL_RATE_WITH_MUST_BUY = 0.9  # 加红L后
# L上撤单比例
L_CANCEL_RATE_UP = 0.79
L_CANCEL_RATE_UP = 0.79  # L前
L_CANCEL_RATE_UP_WITH_MUST_BUY = 0.95  # 加红L前
# 大金额
L_CANCEL_BIG_MONEY = 100
# 小金额
@@ -175,4 +179,3 @@
# L2数据是否载入完成
L2_DATA_IS_LOADED = False
l2/cancel_buy_strategy.py
@@ -243,7 +243,8 @@
                if val['orderNo'] == watch_info[1]:
                    total_num -= watch_info[2]
        min_index = min(watch_info[0])
        sell_orders = HuaXinSellOrderStatisticManager.get_latest_transaction_datas(code, total_datas[real_place_order_info[0]]['val'][
        sell_orders = HuaXinSellOrderStatisticManager.get_latest_transaction_datas(code, total_datas[
            real_place_order_info[0]]['val'][
            'orderNo'])
        sell_order_num = sum([x[1] for x in sell_orders]) // 100
        rate = round(sell_order_num / total_num, 2)
@@ -361,7 +362,11 @@
            # 防止分母为0
            total_fast_money = 1
        rate = round(total_deal_money / total_fast_money, 2)
        if total_deal_money >= threash_money_w * 10000 and rate >= 0.25:
        threshold_rate = constant.F_FAST_RATE
        if gpcode_manager.MustBuyCodesManager().is_in_cache(code):
            threshold_rate = constant.F_FAST_RATE_WITH_MUST_BUY
        if total_deal_money >= threash_money_w * 10000 and rate >= threshold_rate:
            return True, f"近1s有大卖单({round(total_deal_money / 10000, 1)}万/{threash_money_w}万,成交占比:{total_deal_money}/{total_fast_money})"
        else:
            l2_log.s_cancel_debug(code,
@@ -566,7 +571,8 @@
        total_datas = local_today_datas.get(code)
        # h撤计算必须超过3分钟
        if tool.trade_time_sub(total_datas[-1]["val"]["time"], total_datas[real_place_order_index]["val"]["time"]) < 180:
        if tool.trade_time_sub(total_datas[-1]["val"]["time"],
                               total_datas[real_place_order_index]["val"]["time"]) < 180:
            l2_log.h_cancel_debug(code, "180s内囊括计算H撤")
            return
        # -----------------计算H上-------------------
@@ -598,7 +604,7 @@
        # 获取m值数据
        thresh_hold_money = Buy1PriceManager().get_latest_buy1_money(code)
        # 封单额的1/10
        thresh_hold_money = thresh_hold_money/10
        thresh_hold_money = thresh_hold_money / 10
        thresh_hold_num = thresh_hold_money // (float(limit_up_price) * 100)
        end_index = real_place_order_index + 1
        watch_indexes = set()
@@ -776,14 +782,14 @@
                                                                                                             code))
                cancel_num += val['num'] * (data['re'] - left_count)
            rate = round(cancel_num / total_num, 4)
            must_buy_cancel_rate = constant.H_CANCEL_RATE_WITH_LDOWN_CANT_INVALID if code in self.__l_cancel_triggered_codes else constant.H_CANCEL_RATE
            threshold_rate = constant.H_CANCEL_RATE_WITH_LDOWN_CANT_INVALID if code in self.__l_cancel_triggered_codes else constant.H_CANCEL_RATE
            try:
                temp_rate = gpcode_manager.MustBuyCodesManager().get_cancel_rate_cache(code)
                if temp_rate:
                    must_buy_cancel_rate = temp_rate
                must_buy = gpcode_manager.MustBuyCodesManager().is_in_cache(code)
                if must_buy:
                    threshold_rate = constant.H_CANCEL_RATE_WITH_MUST_BUY
            except Exception as e:
                async_log_util.error(logger_l2_h_cancel, str(e))
            if rate >= must_buy_cancel_rate:
            if rate >= threshold_rate:
                l2_log.h_cancel_debug(code, f"撤单比例:{rate}")
                return True, total_data[-1]
        return False, None
@@ -867,9 +873,12 @@
    @classmethod
    def get_cancel_rate(cls, code, buy_exec_time, is_up=False, is_l_down_recomputed=False):
        try:
            must_buy_cancel_rate = cls.__MustBuyCodesManager.get_cancel_rate_cache(code)
            if must_buy_cancel_rate is not None:
                return must_buy_cancel_rate, True
            must_buy = cls.__MustBuyCodesManager.is_in_cache(code)
            if must_buy:
                if is_up:
                    return constant.L_CANCEL_RATE_UP_WITH_MUST_BUY, True
                else:
                    return constant.L_CANCEL_RATE_WITH_MUST_BUY, True
        except Exception as e:
            async_log_util.error(logger_l2_l_cancel, str(e))
@@ -888,12 +897,7 @@
            deal_rate = 0
            if code in cls.__big_num_deal_rate_dict:
                deal_rate =round( cls.__big_num_deal_rate_dict[code]/100)
            #     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 * 5.25 - 3.75) / 100, 4)
                deal_rate = round(cls.__big_num_deal_rate_dict[code] / 100)
            base_rate += block_rate
            base_rate += deal_rate
@@ -919,17 +923,16 @@
    @classmethod
    def set_big_num_deal_info(cls, code, buy_money, sell_money):
        left_money_w = (buy_money-sell_money)//10000
        left_money_w = (buy_money - sell_money) // 10000
        if left_money_w > 0:
            rate = ((left_money_w+300)//900)*2
            rate = ((left_money_w + 300) // 900) * 2
        else:
            rate = ((left_money_w + 599) // 900) * 2
        if rate <-10:
        if rate < -10:
            rate = -10
        if rate > 10:
            rate = 10
        cls.__big_num_deal_rate_dict[code] = rate
    @classmethod
    def compute_big_num_deal_info(cls, code):
@@ -2046,7 +2049,7 @@
            self.__commpute_watch_indexes(code, index, self.__real_place_order_index_dict.get(code))
    def need_cancel(self, code, buy_exec_index, start_index, end_index):
        if 1>0:
        if 1 > 0:
            return False, None, "G撤被注释掉"
        if code not in self.__real_place_order_index_dict:
@@ -2548,12 +2551,6 @@
            if start_index <= i <= end_index:
                # 如果是减小项
                if val < 0:
                    # 当前量小于最大量的24%则需要取消
                    if exec_time_offset >= constant.S_CANCEL_EXPIRE_TIME:
                        if total_num <= min_volumn_big and max_buy1_volume * 0.24 > total_num:
                            cancel_index = i
                            cancel_msg = "封板额小于最高封板额的24% {}/{}".format(total_num, max_buy1_volume)
                            break
                    # 累计封单金额小于1000万
                    if total_num < min_volumn:
                        # 与执行位相隔>=5s时规则生效
l2/l2_data_manager_new.py
@@ -942,28 +942,21 @@
            trade_price = current_price_process_manager.get_trade_price(code)
            if trade_price is None:
                return False, True, f"尚未获取到当前成交价"
            if False and float(limit_up_price) - float(trade_price) > 0.00001:
                # 计算信号起始位置到当前的手数
                order_begin_pos = cls.__get_order_begin_pos(
                    code)
                num_operate_map = local_today_num_operate_map.get(code)
                total_num = 0
                for i in range(order_begin_pos.buy_single_index, total_data[-1]["index"] + 1):
                    data = total_data[i]
                    val = data["val"]
                    if not L2DataUtil.is_limit_up_price_buy(val):
                        continue
                    left_count = l2_data_source_util.L2DataSourceUtils.get_limit_up_buy_no_canceled_count_v2(code,
                                                                                                             data[
                                                                                                                 "index"],
                                                                                                             total_data,
                                                                                                             local_today_canceled_buyno_map.get(
                                                                                                                 code))
                    total_num += left_count * val["num"]
                m_base_val = l2_trade_factor.L2PlaceOrderParamsManager.get_base_m_val(code)
                thresh_hold_num = m_base_val // (float(gpcode_manager.get_limit_up_price(code)) * 100)
                if total_num < thresh_hold_num * 2:
                    return False, False, f"当前成交价({trade_price})尚未在0档及以内 且 纯买额({total_num})小于2倍M值({thresh_hold_num * 2})"
            # 判断是否为板上放量:
            # 1.当前成交价为涨停价
            # 2.总卖额为0
            if abs(float(limit_up_price) - float(trade_price)) < 0.001:
                sell_data = cls.__L2MarketSellManager.get_current_total_sell_data(code)
                if sell_data and sell_data[1]<=0:
                    # 板上放量,判断是否有放量,放量才会下单
                    # 获取最近1s的主动卖金额
                    min_time =  total_data[order_begin_pos.buy_single_index]['val']['time']
                    min_time = tool.trade_time_add_second(min_time, -1)
                    sell_orders = HuaXinSellOrderStatisticManager.get_latest_transaction_datas(code, min_deal_time=min_time)
                    sell_order_num = sum([x[1] for x in sell_orders])
                    sell_money = int(float(limit_up_price) * sell_order_num)
                    if sell_money < 2990000:
                        return False, False, f"板上放量金额不足,近1s总卖:{sell_money}小于299w"
            # 判断成交进度是否距离我们的位置很近
            trade_index, is_default = cls.__TradeBuyQueue.get_traded_index(code)
            if False and not is_default and trade_index: