Skip to main content

futu_backend/
option_event.rs

1use bytes::Bytes;
2use prost::Message as _;
3
4use futu_command_spec::QotReadOperation;
5use futu_core::error::{FutuError, Result};
6
7use crate::command_runtime::execute_qot_read_with_reserved;
8use crate::conn::BackendConn;
9use crate::proto_internal::option_move_reader::{GetOptionEventListReq, GetOptionEventListRsp};
10
11pub async fn pull_option_events(
12    backend: &BackendConn,
13    request: GetOptionEventListReq,
14    quote_mkt_type: u8,
15) -> Result<GetOptionEventListRsp> {
16    let mut reserved = [0; 10];
17    reserved[0] = quote_mkt_type;
18    let response = execute_qot_read_with_reserved(
19        backend,
20        QotReadOperation::OptionEvent,
21        Bytes::from(request.encode_to_vec()),
22        reserved,
23    )
24    .await?;
25    let decoded =
26        GetOptionEventListRsp::decode(response.body.as_ref()).map_err(FutuError::Proto)?;
27    match decoded.ret_code {
28        Some(0) => Ok(decoded),
29        Some(code) => Err(FutuError::ServerError {
30            ret_type: code,
31            msg: decoded
32                .ret_message
33                .clone()
34                .unwrap_or_else(|| "option event backend rejected request".into()),
35        }),
36        None => Err(FutuError::Codec(
37            "option event response missing ret_code".into(),
38        )),
39    }
40}