pub struct FutuClient { /* private fields */ }Expand description
FutuOpenD 高层客户端
功能:
- InitConnect 握手
- 自动心跳 KeepAlive
- 请求-响应匹配(serial number)
- 推送消息分发
- 断线重连
Implementations§
Source§impl FutuClient
impl FutuClient
Sourcepub fn new(config: ClientConfig) -> (Self, PushReceiver)
pub fn new(config: ClientConfig) -> (Self, PushReceiver)
创建客户端(未连接状态)
返回 (client, push_rx),其中 push_rx 用于接收服务端推送。
Sourcepub fn with_init_ai_type(self, ai_type: Option<i32>) -> Self
pub fn with_init_ai_type(self, ai_type: Option<i32>) -> Self
Set C++ 10.7 InitConnect.C2S.aiType for the next connection.
None preserves the legacy wire shape. C++ treats an absent value as
0 (non-AI); Some(1) marks a skills/AI caller.
Sourcepub async fn connect(&mut self) -> Result<InitConnectInfo>
pub async fn connect(&mut self) -> Result<InitConnectInfo>
连接到 OpenD 网关并完成 InitConnect 握手
Sourcepub async fn request_with_timeout(
&self,
proto_id: u32,
body: Vec<u8>,
timeout: Duration,
) -> Result<FutuFrame>
pub async fn request_with_timeout( &self, proto_id: u32, body: Vec<u8>, timeout: Duration, ) -> Result<FutuFrame>
发送请求并等待响应(调用方可指定总请求等待上限)。
与 Self::request 共用同一 pending 清理路径:command channel 入队、
send ack、响应等待任一阶段超时时都必须移除 pending[serial],避免
调用方自己在外层 tokio::time::timeout 取消 future 时留下悬挂请求。
Sourcepub fn conn_id(&self) -> Option<u64>
pub fn conn_id(&self) -> Option<u64>
Server-assigned connection id from InitConnect S2C.
FTAPI trade-write packet ids must echo this value in PacketID.connID;
the gateway replay guard compares it against the actual TCP connection.
Sourcepub fn is_closed(&self) -> bool
pub fn is_closed(&self) -> bool
底层连接是否已失效。
connect 成功后 run_event_loop 独占 cmd_rx;gateway 断连(recv EOF /
recv error / send 失败 / 心跳连续失败)时 event loop 退出并 drop cmd_rx,
此后 Self::request 只会返回 [FutuError::NotInitialized]。调用方(如
长驻 MCP 的 client cache)用本方法判断是否需要重建连接;尚未 connect
的 client 同样视为 closed。