Administrator
2024-02-02 df4cee929486a993868a15c13cd67e56b861907b
修改G撤无大单情况/仓位不足主动撤单比例修改
3个文件已修改
51 ■■■■■ 已修改文件
l2/cancel_buy_strategy.py 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
l2/l2_data_manager_new.py 47 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
trade/huaxin/huaxin_trade_server.py 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
l2/cancel_buy_strategy.py
@@ -1810,7 +1810,7 @@
                        # 在成交位置之后
                        need_find_by = False
                        break
            if need_find_by and not is_default:
            if need_find_by and (not is_default or not watch_indexes):
                l2_log.g_cancel_debug(code, f"启动小单备用监听:{start_index}-{real_order_index}")
                temp_list = []
                for i in range(start_index, real_order_index):
l2/l2_data_manager_new.py
@@ -298,7 +298,7 @@
    def set_real_place_order_index(cls, code, index, order_begin_pos: OrderBeginPosInfo):
        trade_record_log_util.add_real_place_order_position_log(code, index, order_begin_pos.buy_single_index)
        l2_log.debug(code, "设置真实下单位:{}", index)
        cancel_buy_strategy.set_real_place_position(code, index, order_begin_pos.buy_single_index,is_default = False)
        cancel_buy_strategy.set_real_place_position(code, index, order_begin_pos.buy_single_index, is_default=False)
    # 处理华鑫L2数据
    @classmethod
@@ -436,7 +436,7 @@
                    cls.__process_order(code, start_index, end_index, capture_timestamp, is_first_code)
                else:
                    # 未挂单,时间相差不大才能挂单
                    #if tool.trade_time_sub(latest_time, "09:32:00") < 0 or l2.l2_data_util.L2DataUtil.is_same_time(now_time_str, latest_time):
                    # if tool.trade_time_sub(latest_time, "09:32:00") < 0 or l2.l2_data_util.L2DataUtil.is_same_time(now_time_str, latest_time):
                    cls.__process_not_order(code, start_index, end_index, capture_timestamp, is_first_code)
            async_log_util.info(logger_l2_process, "code:{} 处理数据范围: {}-{} 处理时间:{} 截图时间戳:{}", code,
@@ -629,7 +629,7 @@
                trade_result_manager.real_buy_success(code, cls.__TradePointManager)
                l2_log.debug(code, "处理买入成功1")
                cancel_buy_strategy.set_real_place_position(code, local_today_datas.get(code)[-1]["index"],
                                                            order_begin_pos.buy_single_index,is_default=True)
                                                            order_begin_pos.buy_single_index, is_default=True)
                l2_log.debug(code, "处理买入成功2")
                params_desc = cls.__l2PlaceOrderParamsManagerDict[code].get_buy_rank_desc()
                l2_log.debug(code, params_desc)
@@ -846,7 +846,7 @@
        if cls.__PauseBuyCodesManager.is_in_cache(code):
            return False, True, f"该代码被暂停交易"
        if int( tool.get_now_time_str().replace(":","")) >= 145700:
        if int(tool.get_now_time_str().replace(":", "")) >= 145700:
            return False, True, f"14:57后不能交易"
        limit_up_price = gpcode_manager.get_limit_up_price(code)
@@ -862,7 +862,7 @@
        # ---------均价约束-------------
        average_rate = cls.__Buy1PriceManager.get_average_rate(code)
        if average_rate and average_rate <= 0.01 and tool.trade_time_sub(tool.get_now_time_str(),"10:30:00") >= 0:
        if average_rate and average_rate <= 0.01 and tool.trade_time_sub(tool.get_now_time_str(), "10:30:00") >= 0:
            return False, True, f"均价涨幅({average_rate})小于1%"
        total_data = local_today_datas.get(code)
@@ -1356,14 +1356,14 @@
        if order_begin_pos.mode == OrderBeginPosInfo.MODE_FAST:
            threshold_money = order_begin_pos.threshold_money
            new_buy_exec_index, buy_nums, buy_count, rebegin_buy_pos, threshold_money_new, not_buy_msg = cls.__sum_buy_num_for_order_fast(
            new_buy_exec_index, buy_nums, buy_count, rebegin_buy_pos, threshold_money_new, max_num_set_new, not_buy_msg = cls.__sum_buy_num_for_order_fast(
                code,
                start_process_index,
                compute_end_index,
                order_begin_pos.num,
                order_begin_pos.count,
                threshold_money,
                order_begin_pos.buy_single_index)
                order_begin_pos.buy_single_index, order_begin_pos.max_num_set)
            threshold_money = threshold_money_new
            order_begin_pos.threshold_money = threshold_money
        else:
@@ -1513,8 +1513,8 @@
            return False, -1, "总卖为空"
        if cls.__L2MarketSellManager.is_refer_sell_time_used(code, refer_sell_data[0]):
            return False, -1, "总卖统计时间已被使用"
        # 是否大于500万
        if refer_sell_data[1] <= 500 * 10000:
        # 是否大于2000万
        if refer_sell_data[1] <= 2000 * 10000:
            return False, -1, "总卖小于指定金额"
        # 统计之前的卖
        threshold_money = refer_sell_data[1]
@@ -1620,8 +1620,8 @@
        max_space_time_ms = cls.__l2PlaceOrderParamsManagerDict[code].get_time_range() * 1000
        # 如果大单含有率大于50%,则时间囊括范围提高到3s
        if max_num_set and origin_count:
            if len(max_num_set)/origin_count > 0.5:
                max_space_time_ms = 3*1000
            if len(max_num_set) / origin_count > 0.5:
                max_space_time_ms = 3 * 1000
        # 最大买量
        max_buy_num = 0
@@ -1733,7 +1733,7 @@
    # 计算快速买入
    @classmethod
    def __sum_buy_num_for_order_fast(cls, code, compute_start_index, compute_end_index, origin_num, origin_count,
                                     threshold_money_origin, buy_single_index):
                                     threshold_money_origin, buy_single_index, max_num_set):
        _start_time = t.time()
        total_datas = local_today_datas[code]
        # is_first_code = gpcode_manager.FirstCodeManager().is_in_first_record_cache(code)
@@ -1757,6 +1757,10 @@
        max_space_time_ms = 3 * 1000
        # 不下单的信息
        not_buy_msg = ""
        max_buy_num_set = set(max_num_set)
        place_order_count = trade_data_manager.PlaceOrderCountManager().get_place_order_count(code)
        if place_order_count is None:
            place_order_count = 0
        for i in range(compute_start_index, compute_end_index + 1):
            data = total_datas[i]
            _val = total_datas[i]["val"]
@@ -1766,12 +1770,12 @@
                cls.__TradePointManager.delete_buy_point(code)
                if i == compute_end_index:
                    # 数据处理完毕
                    return None, buy_nums, buy_count, None, threshold_money, f"【{i}】信号不连续,囊括时间-{max_space_time_ms}ms"
                    return None, buy_nums, buy_count, None, threshold_money, max_buy_num_set, f"【{i}】信号不连续,囊括时间-{max_space_time_ms}ms"
                else:
                    # 计算买入信号,不能同一时间开始计算
                    for ii in range(buy_single_index + 1, compute_end_index + 1):
                        if total_datas[buy_single_index]["val"]["time"] != total_datas[ii]["val"]["time"]:
                            return None, buy_nums, buy_count, ii, threshold_money, f"【{i}】信号不连续,囊括时间-{max_space_time_ms}ms"
                            return None, buy_nums, buy_count, ii, threshold_money, max_buy_num_set, f"【{i}】信号不连续,囊括时间-{max_space_time_ms}ms"
            if L2DataUtil.is_sell(_val):
                threshold_money += _val["num"] * int(float(_val["price"]) * 100)
                threshold_num = round(threshold_money / (limit_up_price * 100))
@@ -1780,6 +1784,8 @@
                threshold_num = round(threshold_money / (limit_up_price * 100))
            # 涨停买
            elif L2DataUtil.is_limit_up_price_buy(_val):
                if l2_data_util.is_big_money(_val):
                    max_buy_num_set.add(i)
                trigger_buy = True
                # 只统计59万以上的金额
                buy_nums += int(_val["num"]) * int(total_datas[i]["re"])
@@ -1793,8 +1799,10 @@
                                                                                                    local_today_buyno_map.get(
                                                                                                        code))
                if buy_index is not None:
                    # 找到买撤数据的买入点
                    if buy_index >= buy_single_index:
                        max_buy_num_set.discard(buy_index)
                        buy_nums -= int(_val["num"]) * int(data["re"])
                        buy_count -= int(data["re"])
                        l2_log.buy_debug(code, "{}数据在买入信号之后 撤买纯买手数:{} 目标手数:{}", i, buy_nums, threshold_num)
@@ -1804,6 +1812,7 @@
                            # 同一秒,当作买入信号之后处理
                            buy_nums -= int(_val["num"]) * int(data["re"])
                            buy_count -= int(data["re"])
                            max_buy_num_set.discard(buy_index)
                            # 大单撤销
                            l2_log.buy_debug(code, "{}数据买入位与预估买入位在同一秒", i)
                else:
@@ -1823,20 +1832,26 @@
            if buy_count < 5:
                not_buy_msg = f"【{i}】安全笔数不足,{buy_count}/{5}"
                continue
            if place_order_count == 0:
                if len(max_buy_num_set) < 1:
                    not_buy_msg = f"【{i}】首次下单无大单"
                    continue
            try:
                info = cls.__trade_log_placr_order_info_dict[code]
                info.set_trade_factor(threshold_money, 0, [])
            except Exception as e:
                async_log_util.error(logger_l2_error, f"记录交易因子出错:{str(e)}")
            return i, buy_nums, buy_count, None, threshold_money, "可以下单"
            return i, buy_nums, buy_count, None, threshold_money, max_buy_num_set, "可以下单"
        l2_log.buy_debug(code, "尚未获取到买入执行点(快速买入),起始计算位置:{} 统计纯买手数:{} 目标纯买手数:{}  统计纯买单数:{}",
                         compute_start_index,
                         buy_nums,
                         threshold_num, buy_count)
        return None, buy_nums, buy_count, None, threshold_money, not_buy_msg
        return None, buy_nums, buy_count, None, threshold_money, max_buy_num_set, not_buy_msg
def test_trade_record():
trade/huaxin/huaxin_trade_server.py
@@ -572,7 +572,7 @@
                if buy1_money > 0:
                    total_left_money = total_left_num * 100 * float(limit_up_price)
                    rate = total_left_money / buy1_money
                    if rate > 0.66:
                    if rate > 0.5:
                        can_cancel_codes.append((code, rate))
            if can_cancel_codes:
                can_cancel_codes.sort(key=lambda x: x[1], reverse=True)