Administrator
2024-01-15 837e7fb5c1f3c1494cf397dadb19b46c2cec0e83
添加G撤日志/真实下单位计算修改/设置L2特殊量监听日志添加
4个文件已修改
114 ■■■■■ 已修改文件
huaxin_client/l2_client.py 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
l2/cancel_buy_strategy.py 3 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
l2/huaxin/huaxin_delegate_postion_manager.py 101 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
l2/l2_log.py 6 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
huaxin_client/l2_client.py
@@ -550,9 +550,13 @@
                    code = data["data"]["code"]
                    spi.set_code_special_watch_volume(code, volume)
                elif _type == "l2_cmd":
                    __start_time = time.time()
                    # 线程池
                    __l2_cmd_thread_pool.submit(
                        lambda: l2CommandManager.process_command(command_manager.CLIENT_TYPE_CMD_L2, None, data))
                    use_time = time.time() - __start_time
                    if use_time > 0.005:
                        huaxin_l2_log.info(logger_local_huaxin_l2_subscript, f"l2_cmd耗时:{use_time}s")
        except Exception as e:
            logging.exception(e)
l2/cancel_buy_strategy.py
@@ -1683,6 +1683,7 @@
                final_watch_indexes = origin_watch_index | watch_indexes
                self.__watch_indexes_dict[code] = final_watch_indexes
        else:
            l2_log.g_cancel_debug(code,f"没有大单监听,开始计算小单:{start_index}-{real_order_index}")
            # 没有300万以上的大单了,计算备用
            # 只有备用单成交了或者没有备用单,才会再次寻找备用单
            need_find_by = False
@@ -1697,6 +1698,7 @@
                        need_find_by = False
                        break
            if need_find_by:
                l2_log.g_cancel_debug(code, f"启动小单备用监听:{start_index}-{real_order_index}")
                temp_list = []
                for i in range(start_index, real_order_index):
                    data = total_datas[i]
@@ -1710,6 +1712,7 @@
                        break
                temp_list.sort(key=lambda x: x[0], reverse=True)
                if temp_list:
                    l2_log.g_cancel_debug(code, f"小单备用监听位置:{temp_list[0][1]['index']}")
                    watch_indexes.add(temp_list[0][1]["index"])
                    self.__watch_indexes_by_dict[code] = origin_watch_index_by | watch_indexes
l2/huaxin/huaxin_delegate_postion_manager.py
@@ -33,7 +33,24 @@
    return info
RELIABILITY_TYPE_REAL = 1  # 真实下单位
RELIABILITY_TYPE_VIRTUAL = 2  # 影子单下单位
RELIABILITY_TYPE_ESTIMATE = 3  # 估算下单位
# 计算预估下单位
def __compute_estimate_order_position(code, exec_buy_index):
    total_datas = l2_data_util.local_today_datas.get(code)
    exec_data = total_datas[exec_buy_index]
    THRESH_MS = 20 if code.find('00') == 0 else 100
    for i in range(exec_buy_index, total_datas[-1]["index"]):
        if L2DataUtil.time_sub_as_ms(total_datas[i]['val'], exec_data["val"]) >= THRESH_MS:
            return i
    return None
# L2数据列表
# 范围(位置信息,可信的类型)
def get_l2_place_order_position(code, limit_up_price, datas):
    order_info = get_order_info(code)
    if not order_info:
@@ -42,6 +59,7 @@
    price = order_info[0]
    volume = order_info[1]
    exec_data = order_info[2]
    order_time = order_info[3]  # 下单时间
    order_ref = order_info[4]
    shadow_price = order_info[5]
    shadow_place_order_index = None
@@ -61,33 +79,21 @@
            continue
        shadow_place_order_index = d["index"]
        break
    if shadow_place_order_index is None:
        return None
    total_datas = l2_data_util.local_today_datas.get(code)
    # 找到不是同一ms的结束
    temp_start_index = shadow_place_order_index
    for i in range(shadow_place_order_index - 1, -1, -1):
        val = total_datas[i]["val"]
        if val["tms"] != total_datas[shadow_place_order_index]["val"]["tms"]:
            break
        temp_start_index = i
    start_index = max(min(temp_start_index, min(datas[0]["index"], shadow_place_order_index - 15)), 0)
    end_index = min(shadow_place_order_index + 10, datas[-1]["index"])
    real_place_index = None
    # 从中间向两头遍历
    for i in range(shadow_place_order_index - 1, start_index - 1, -1):
        d = total_datas[i]
        if d["val"]["num"] != volume // 100:
            continue
        if abs(float(price) - float(d["val"]["price"])) >= 0.01:
            continue
        # 必须是买入
        if not L2DataUtil.is_limit_up_price_buy(d["val"]):
            continue
        real_place_index = i
        break
    if not real_place_index:
        for i in range(shadow_place_order_index + 1, end_index):
    real_place_index_info = None
    if shadow_place_order_index:
        total_datas = l2_data_util.local_today_datas.get(code)
        # 找到不是同一ms的结束
        temp_start_index = shadow_place_order_index
        for i in range(shadow_place_order_index - 1, -1, -1):
            val = total_datas[i]["val"]
            if val["tms"] != total_datas[shadow_place_order_index]["val"]["tms"]:
                break
            temp_start_index = i
        start_index = max(min(temp_start_index, min(datas[0]["index"], shadow_place_order_index - 15)), 0)
        end_index = min(shadow_place_order_index + 10, datas[-1]["index"])
        real_place_index = None
        # 从中间向两头遍历
        for i in range(shadow_place_order_index - 1, start_index - 1, -1):
            d = total_datas[i]
            if d["val"]["num"] != volume // 100:
                continue
@@ -98,15 +104,38 @@
                continue
            real_place_index = i
            break
    if not real_place_index:
        real_place_index = shadow_place_order_index
    # 获取到了下单位置
    async_log_util.info(hx_logger_trade_debug, f"真实下单位置:{code}-{real_place_index}")
    async_log_util.info(logger_real_place_order_position, f"真实下单位置:{code}-{real_place_index}")
    if code in _place_order_info_dict:
        _place_order_info_dict.pop(code)
    __place_order_position[code] = real_place_index
    return real_place_index
        if not real_place_index:
            for i in range(shadow_place_order_index + 1, end_index):
                d = total_datas[i]
                if d["val"]["num"] != volume // 100:
                    continue
                if abs(float(price) - float(d["val"]["price"])) >= 0.01:
                    continue
                # 必须是买入
                if not L2DataUtil.is_limit_up_price_buy(d["val"]):
                    continue
                real_place_index = i
                break
        if not real_place_index:
            real_place_index_info = shadow_place_order_index, RELIABILITY_TYPE_VIRTUAL
        else:
            real_place_index_info = real_place_index, RELIABILITY_TYPE_REAL
    elif time.time() - order_time >= 1:
        # 下单超过1s
        estimate_index = __compute_estimate_order_position(code, exec_data["index"])
        if estimate_index:
            real_place_index_info = estimate_index, RELIABILITY_TYPE_ESTIMATE
    if real_place_index_info:
        # 获取到了下单位置
        async_log_util.info(hx_logger_trade_debug, f"真实下单位置:{code}-{real_place_index_info}")
        async_log_util.info(logger_real_place_order_position, f"真实下单位置:{code}-{real_place_index_info}")
        if code in _place_order_info_dict:
            _place_order_info_dict.pop(code)
        __place_order_position[code] = real_place_index_info[0]
        return real_place_index_info[0]
    else:
        return None
# 获取真实下单位置
l2/l2_log.py
@@ -1,6 +1,7 @@
from log_module import async_log_util
from log_module.log import logger_l2_trade_cancel, logger_l2_trade_buy, logger_trade_record, logger_l2_trade, \
    logger_l2_s_cancel, logger_l2_h_cancel, logger_l2_l_cancel, logger_l2_error, logger_l2_d_cancel, logger_l2_f_cancel
    logger_l2_s_cancel, logger_l2_h_cancel, logger_l2_l_cancel, logger_l2_error, logger_l2_d_cancel, logger_l2_f_cancel, \
    logger_l2_g_cancel
threadIds = {}
@@ -47,6 +48,9 @@
def f_cancel_debug(code, content, *args):
    __add_async_log(logger_l2_f_cancel, code, content, *args)
def g_cancel_debug(code, content, *args):
    __add_async_log(logger_l2_g_cancel, code, content, *args)
# 交易记录
def trade_record(code, type, content, *args):
    if len(args) > 0: