Administrator
2023-08-21 307c5a4b792c3aac04a1699ecc265d373ec1d6d7
信息上传优化
3个文件已修改
63 ■■■■■ 已修改文件
huaxin_api/trade_client.py 1 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
trade/huaxin/huaxin_trade_api.py 25 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
trade/huaxin/trade_server.py 37 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
huaxin_api/trade_client.py
@@ -911,6 +911,7 @@
def send_response(data, type, _client_id, _request_id):
    logger_local_huaxin_trade_debug.debug(f"回调返回内容:{data}")
    strategy_pipe.send(data)
trade/huaxin/huaxin_trade_api.py
@@ -32,8 +32,29 @@
                if val:
                    print("收到来自交易服务器的数据:", val)
                    data_json = json.loads(val)
                    t1 = threading.Thread(target=lambda: __set_response(data_json), daemon=True)
                    t1.start()
                    print("收到来自交易客户端的数据:", data_json["type"])
                    # 处理数据
                    type_ = data_json["type"]
                    if type_ == "response":
                        # 主动触发的响应
                        hx_logger_trade_callback.info(
                            f"response:request_id-{data_json['request_id']}")
                        # 设置响应内容
                        threading.Thread(target=lambda: __set_response(data_json), daemon=True).start()
                    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:
                pass
trade/huaxin/trade_server.py
@@ -380,40 +380,6 @@
                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)
class OutsideApiCommandCallback(outside_api_command_manager.ActionCallback):
    @classmethod
    def __send_response(cls, data_bytes):
@@ -706,9 +672,6 @@
    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")
    t1 = threading.Thread(target=lambda: clear_invalid_client(), daemon=True)