1use futu_core::error::{FutuError, Result};
2use futu_core::proto_id;
3use futu_net::client::FutuClient;
4
5use crate::types::Security;
6
7pub async fn get_security_snapshot(
12 client: &FutuClient,
13 securities: &[Security],
14) -> Result<futu_proto::qot_get_security_snapshot::S2c> {
15 let req = futu_proto::qot_get_security_snapshot::Request {
16 c2s: futu_proto::qot_get_security_snapshot::C2s {
17 security_list: securities.iter().map(|s| s.to_proto()).collect(),
18 header: None,
19 },
20 };
21
22 let body = prost::Message::encode_to_vec(&req);
23 let resp_frame = client
24 .request(proto_id::QOT_GET_SECURITY_SNAPSHOT, body)
25 .await?;
26
27 let resp: futu_proto::qot_get_security_snapshot::Response =
28 prost::Message::decode(resp_frame.body.as_ref()).map_err(FutuError::Proto)?;
29
30 if resp.ret_type != 0 {
31 return Err(FutuError::ServerError {
32 ret_type: resp.ret_type,
33 msg: resp.ret_msg.unwrap_or_default(),
34 });
35 }
36
37 resp.s2c.ok_or(FutuError::Codec(
38 "missing s2c in GetSecuritySnapshot".into(),
39 ))
40}