| | |
| | | if 'request_id' not in data_json: |
| | | return |
| | | # 处理数据 |
| | | hx_logger_trade_callback.info(f"response:request_id-{data_json['request_id']}") |
| | | async_log_util.info(hx_logger_trade_callback, f"response:request_id-{data_json['request_id']}") |
| | | # 设置响应内容 |
| | | set_response(data_json["request_id"], data_json['data']) |
| | | |
| | |
| | | type_ = data_json["type"] |
| | | if type_ == "response": |
| | | # 主动触发的响应 |
| | | hx_logger_trade_callback.info( |
| | | async_log_util.info(hx_logger_trade_callback, |
| | | f"response:request_id-{data_json['request_id']}") |
| | | # 设置响应内容 |
| | | threading.Thread(target=lambda: __set_response(data_json), daemon=True).start() |
| | |
| | | data_json = data_json["data"] |
| | | ctype = data_json["type"] |
| | | # 记录交易反馈日志 |
| | | hx_logger_trade_callback.info(data_json) |
| | | async_log_util.info(hx_logger_trade_callback, data_json) |
| | | # 重新请求委托列表与资金 |
| | | huaxin_trade_data_update.add_delegate_list("来自交易管道") |
| | | huaxin_trade_data_update.add_deal_list() |
| | |
| | | if log_enable: |
| | | async_log_util.info(hx_logger_trade_loop, "请求发送成功:request_id-{}", request_id) |
| | | except BrokenPipeError as e: |
| | | hx_logger_trade_loop.info("请求发送异常:request_id-{} error-{}", request_id, str(e)) |
| | | async_log_util.info(hx_logger_trade_loop,"请求发送异常:request_id-{} error-{}", request_id, str(e)) |
| | | raise e |
| | | except Exception as e: |
| | | hx_logger_trade_loop.info("请求发送异常: request_id-{} error-{}", request_id, str(e)) |
| | | async_log_util.info(hx_logger_trade_loop,"请求发送异常: request_id-{} error-{}", request_id, str(e)) |
| | | logging.exception(e) |
| | | raise e |
| | | return request_id |
| | |
| | | # 获取到了响应内容 |
| | | result = __request_response_dict.pop(request_id) |
| | | if log_enable: |
| | | hx_logger_trade_loop.info("请求读取成功: request_id-{}", request_id) |
| | | async_log_util.info(hx_logger_trade_loop, "请求读取成功: request_id-{}", request_id) |
| | | return result |
| | | if time.time() - start_time > timeout: |
| | | if log_enable: |
| | | hx_logger_trade_loop.info("请求读取超时: request_id-{}", request_id) |
| | | async_log_util.info(hx_logger_trade_loop, "请求读取超时: request_id-{}", request_id) |
| | | # 读取内容超时才会释放 |
| | | raise Exception(f"读取内容超时: request_id={request_id}") |
| | | finally: |
| | |
| | | |
| | | def set_response(request_id, response): |
| | | if request_id: |
| | | hx_logger_trade_loop.info(f"请求响应: request_id-{request_id} 内容-{response}") |
| | | async_log_util.info(hx_logger_trade_loop, f"请求响应: request_id-{request_id} 内容-{response}") |
| | | # 主动触发 |
| | | __request_response_dict[request_id] = response |
| | | try: |