Administrator
2023-07-25 ae1afb4dd4ee19ec4795a60ad70ab3a48b20f2e6
bug修复
2个文件已修改
21 ■■■■ 已修改文件
log_module/log.py 6 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
trade/huaxin/huaxin_trade_api.py 15 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
log_module/log.py
@@ -193,6 +193,11 @@
        logger.add(self.get_hx_path("trade", "debug"),
                   filter=lambda record: record["extra"].get("name") == "hx_trade_debug",
                   rotation="00:00", compression="zip", enqueue=True)
        logger.add(self.get_hx_path("trade", "trade_loop"),
                   filter=lambda record: record["extra"].get("name") == "hx_trade_loop",
                   rotation="00:00", compression="zip", enqueue=True)
    def get_path(self, dir_name, log_name):
        path_str = "{}/logs/gp/{}/{}".format(constant.get_path_prefix(), dir_name, log_name) + ".{time:YYYY-MM-DD}.log"
@@ -275,6 +280,7 @@
hx_logger_contact_debug = __mylogger.get_logger("hx_contact_debug")
hx_logger_trade_callback = __mylogger.get_logger("hx_trade_callback")
hx_logger_trade_debug = __mylogger.get_logger("hx_trade_debug")
hx_logger_trade_loop = __mylogger.get_logger("hx_trade_loop")
class LogUtil:
trade/huaxin/huaxin_trade_api.py
@@ -7,7 +7,7 @@
import threading
import time
from log_module.log import hx_logger_trade_debug
from log_module.log import hx_logger_trade_debug, hx_logger_trade_loop
from utils import socket_util
@@ -160,19 +160,23 @@
        raise Exception("无可用的交易client")
    request_id = __get_request_id(_type)
    try:
        hx_logger_trade_loop.info("请求发送开始:client_id-{} request_id-{}", client[0], request_id)
        root_data = {"type": "cmd",
                     "data": data,
                     "request_id": request_id}
        root_data = socket_util.encryp_client_params_sign(root_data)
        print("请求前对象", root_data)
        # print("请求前对象", root_data)
        # 添加请求头
        client[1].sendall(socket_util.load_header(json.dumps(root_data).encode(encoding='utf-8')))
        result = client[1].recv(1024)
        print("请求发送成功", result.decode(encoding='utf-8'))
        # print("请求发送成功", result.decode(encoding='utf-8'))
        hx_logger_trade_loop.info("请求发送成功:client_id-{} request_id-{}", client[0], request_id)
    except BrokenPipeError as e:
        hx_logger_trade_loop.info("请求发送异常:client_id-{} request_id-{} error-{}", client[0], request_id, str(e))
        ClientSocketManager.del_client(client[0])
        raise e
    except Exception as e:
        hx_logger_trade_loop.info("请求发送异常:client_id-{} request_id-{} error-{}", client[0], request_id, str(e))
        logging.exception(e)
        raise e
    return request_id, client
@@ -183,12 +187,14 @@
        start_time = time.time()
        try:
            while True:
                time.sleep(0.01)
                time.sleep(0.005)
                if request_id in __request_response_dict:
                    # 获取到了响应内容
                    result = __request_response_dict.pop(request_id)
                    hx_logger_trade_loop.info("请求读取成功:client_id-{} request_id-{}", client[0], request_id)
                    return result
                if time.time() - start_time > timeout:
                    hx_logger_trade_loop.info("请求读取超时:client_id-{} request_id-{}", client[0], request_id)
                    # 读取内容超时才会释放
                    ClientSocketManager.release_client(client[0])
                    raise Exception(f"读取内容超时: request_id={request_id}")
@@ -200,6 +206,7 @@
def set_response(client_id, request_id, response):
    if client_id and request_id:
        hx_logger_trade_loop.info("请求响应:client_id-{} request_id-{}", client_id, request_id)
        # 主动触发
        __request_response_dict[request_id] = response
        ClientSocketManager.release_client(client_id)