Administrator
2023-08-23 7e8854fb75eb35b0c243c7e61b5a580ea8775ff8
记录L2数据传输耗时日志
4个文件已修改
56 ■■■■ 已修改文件
huaxin_client/l2_data_manager.py 8 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
l2/l2_data_manager_new.py 7 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
log_module/log_analyse.py 38 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
trade/huaxin/trade_server.py 3 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
huaxin_client/l2_data_manager.py
@@ -10,7 +10,7 @@
from huaxin_client.client_network import SendResponseSkManager
# 活动时间
from log_module.log import logger_local_huaxin_l2_error
from log_module.log import logger_local_huaxin_l2_error, logger_local_huaxin_l2_upload
order_detail_upload_active_time_dict = {}
transaction_upload_active_time_dict = {}
@@ -60,7 +60,7 @@
    tmep_order_detail_queue_dict[code].put(
        (data['SecurityID'], data['Price'], data['Volume'], data['Side'], data['OrderType'], data['OrderTime'],
         data['MainSeq'], data['SubSeq'], data['OrderNO'], data['OrderStatus'], int(time.time()*1000)))
         data['MainSeq'], data['SubSeq'], data['OrderNO'], data['OrderStatus'], int(time.time() * 1000)))
# 添加逐笔成交
@@ -166,7 +166,11 @@
                temp = tmep_order_detail_queue_dict[code].get()
                udatas.append(temp)
            if udatas:
                start_time = time.time()
                upload_data(code, "l2_order", udatas)
                use_time = int((time.time() - start_time)*1000)
                if use_time > 20:
                    logger_local_huaxin_l2_upload.info(f"{code}-上传代码耗时:{use_time}ms")
            time.sleep(0.01)
l2/l2_data_manager_new.py
@@ -417,9 +417,10 @@
                    if 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)
            logger_l2_process.info("code:{} 处理数据范围: {}-{} 处理时间:{} 截图时间戳:{}", code, add_datas[0]["index"],
                                   add_datas[-1]["index"], round(t.time() * 1000) - __start_time,
                                   capture_timestamp)
            async_log_util.info(logger_l2_process, "code:{} 处理数据范围: {}-{} 处理时间:{} 截图时间戳:{}", code,
                                add_datas[0]["index"],
                                add_datas[-1]["index"], round(t.time() * 1000) - __start_time,
                                capture_timestamp)
            # __start_time = l2_data_log.l2_time(code, round(t.time() * 1000) - __start_time,
            #                                    "l2数据处理时间")
log_module/log_analyse.py
@@ -2,6 +2,7 @@
日志分析
"""
# 获取不可以下单的原因
import datetime
import os
import constant
@@ -59,5 +60,40 @@
                line = f.readline()
# 分析L2数据传输时间
def analyze_l2_data_transformation(path_):
    with open(path_, 'r') as f:
        while True:
            line = f.readline()
            if not line:
                break
            datas = line.split("|")
            create_time = datas[0].strip()
            data = datas[2].split("-")[1].strip()
            code = data.split("#")[0]
            l2_data = data.split("#")[1]
            l2_data = eval(l2_data)
            max_time_data = None
            min_time_data = None
            for d in l2_data:
                if len(d) > 10:
                    if max_time_data is None:
                        max_time_data = d
                    if min_time_data is None:
                        min_time_data = d
                    if d[10] > max_time_data[10]:
                        max_time_data = d
                    if d[10] < min_time_data[10]:
                        min_time_data = d
            if max_time_data and min_time_data:
                dt = datetime.datetime.strptime(create_time.split(".")[0], "%Y-%m-%d %H:%M:%S")
                create_timestamp = int(dt.timestamp() * 1000) + int(create_time.split(".")[1])
                if create_timestamp - min_time_data[10] > 20:
                    print(create_time, f"数量:{len(l2_data)}", code, create_timestamp - min_time_data[10],
                          create_timestamp - max_time_data[10])
        pass
if __name__ == "__main__":
    print(get_kpl_can_buy_reasons_dict())
    analyze_l2_data_transformation("D:\\logs\\huaxin_l2\\orderdetail.2023-08-23.log")
trade/huaxin/trade_server.py
@@ -179,8 +179,9 @@
                            # L2逐笔委托
                            data = data_json["data"]
                            code = data["code"]
                            timestamp = data.get("time")
                            datas = data["data"]
                            hx_logger_l2_orderdetail.info(f"{code}#{datas}")
                            async_log_util.info(hx_logger_l2_orderdetail,f"{code}#{timestamp}->{int(time.time()*1000)}#{datas}")
                            l2_log.threadIds[code] = random.randint(0, 100000)
                            l2_data_manager_new.L2TradeDataProcessor.process_huaxin(code, datas)
                        finally: