Skip to main content

futu_backend/
trade_keepalive.rs

1//! C++-aligned trade account subscription heartbeat.
2
3use prost::Message;
4
5use futu_command_spec::{BackendChannelKind, HeartbeatOperation, heartbeat_command};
6use futu_core::error::{FutuError, Result};
7
8use crate::{conn::BackendConn, msg_header, proto_internal::order_sys_interface};
9
10/// Queue CMD4700 on the same broker connection as the following real trade
11/// write. The response is intentionally not awaited: C++ sends this as a
12/// subscription refresh immediately before PlaceOrder and proceeds directly
13/// to the order request.
14pub async fn send_real_account_heartbeat(backend: &BackendConn, account_ids: &[u64]) -> Result<()> {
15    let spec = heartbeat_command(HeartbeatOperation::TradeAccountsReal);
16    if spec.runtime.channel != BackendChannelKind::Broker {
17        return Err(FutuError::Codec(
18            "real trade account heartbeat is not broker-bound".to_string(),
19        ));
20    }
21    let request = order_sys_interface::HeartBeatReq {
22        msg_header: Some(msg_header::build_real_trade_account_heartbeat()),
23        account_id_list: account_ids.to_vec(),
24    };
25    backend
26        .send_fire_and_forget(spec.runtime.cmd_id, request.encode_to_vec())
27        .await
28}