Administrator
2023-08-21 2d27b626b35ec9d62df36daf6405d425557e11ae
trade/huaxin/trade_server.py
@@ -352,17 +352,6 @@
        data = data_json["data"]
        datas = data["data"]
        HuaXinL1TargetCodesManager.set_level_1_codes_datas(datas)
        # lp = LineProfiler()
        # lp.enable()
        # lp_wrap = lp(HuaXinL1TargetCodesManager.set_level_1_codes_datas)
        # lp_wrap(datas)
        # output = io.StringIO()
        # lp.print_stats(stream=output)
        # lp.disable()
        # with open(
        #         f"{constant.get_path_prefix()}/logs/profile/set_level_1_codes_datas_{time.time()}.txt",
        #         'w') as f:
        #     f.write(output.getvalue())
def clear_invalid_client():
@@ -375,8 +364,8 @@
            time.sleep(2)
def __recv_pipe_l1(pipe_trade, pipe_l1):
    if pipe_trade is not None and pipe_l1 is not None:
def __recv_pipe_l1(pipe_l1):
    if pipe_l1 is not None:
        while True:
            try:
                val = pipe_l1.recv()
@@ -387,6 +376,40 @@
                    type_ = val["type"]
                    if type_ == "set_target_codes":
                        TradeServerProcessor.set_target_codes(val)
            except Exception as e:
                logging.exception(e)
# 读取交易那边传递过来的数据
def __recv_pipe_trade(pipe_trade):
    if pipe_trade is not None:
        while True:
            try:
                val = pipe_trade.recv()
                if val:
                    data_json = json.loads(val)
                    print("收到来自交易客户端的数据:", data_json["type"])
                    # 处理数据
                    type_ = data_json["type"]
                    if type_ == "response":
                        # 主动触发的响应
                        hx_logger_trade_callback.info(f"response:request_id-{data_json['request_id']}")
                        # 设置响应内容
                        trade_api.set_response(data_json["request_id"], data_json['data'])
                    elif type_ == "trade_callback":
                        try:
                            # 交易回调
                            data_json = data_json["data"]
                            ctype = data_json["type"]
                            # 记录交易反馈日志
                            hx_logger_trade_callback.info(data_json)
                            # 重新请求委托列表与资金
                            huaxin_trade_data_update.add_delegate_list()
                            huaxin_trade_data_update.add_deal_list()
                            huaxin_trade_data_update.add_money_list()
                            # print("响应结果:", data_json['data'])
                        finally:
                            pass
            except Exception as e:
                logging.exception(e)
@@ -680,7 +703,11 @@
    huaxin_trade_api.set_pipe_trade(pipe_trade)
    # 监听l1那边传过来的代码
    t1 = threading.Thread(target=lambda: __recv_pipe_l1(pipe_trade, pipe_l1), daemon=True)
    t1 = threading.Thread(target=lambda: __recv_pipe_l1(pipe_l1), daemon=True)
    t1.start()
    # 监听交易结果
    t1 = threading.Thread(target=lambda: __recv_pipe_trade(pipe_trade), daemon=True)
    t1.start()
    print("create TradeServer")