futu_mcp/handlers/reference/
screen.rs1use std::sync::Arc;
4
5use anyhow::{Result, anyhow, bail};
6use futu_net::client::FutuClient;
7use prost::Message;
8use serde_json::Value;
9
10pub async fn stock_screen(client: &Arc<FutuClient>, c2s: Value) -> Result<String> {
11 let c2s = serde_json::from_value::<futu_proto::qot_stock_screen::C2s>(c2s)
12 .map_err(|e| anyhow!("stock_screen c2s json: {e}"))?;
13 let req = futu_proto::qot_stock_screen::Request { c2s };
14 let frame = client
15 .request(futu_core::proto_id::QOT_STOCK_SCREEN, req.encode_to_vec())
16 .await?;
17 let resp = futu_proto::qot_stock_screen::Response::decode(frame.body.as_ref())
18 .map_err(|e| anyhow!("decode stock_screen: {e}"))?;
19 if resp.ret_type != 0 {
20 bail!(
21 "stock_screen ret_type={} msg={:?}",
22 resp.ret_type,
23 resp.ret_msg
24 );
25 }
26 let s2c = resp.s2c.ok_or_else(|| anyhow!("missing s2c"))?;
27 Ok(serde_json::to_string_pretty(&s2c)?)
28}
29
30pub async fn option_screen(client: &Arc<FutuClient>, c2s: Value) -> Result<String> {
31 let c2s = serde_json::from_value::<futu_proto::qot_option_screen::C2s>(c2s)
32 .map_err(|e| anyhow!("option_screen c2s json: {e}"))?;
33 let req = futu_proto::qot_option_screen::Request { c2s };
34 let frame = client
35 .request(futu_core::proto_id::QOT_OPTION_SCREEN, req.encode_to_vec())
36 .await?;
37 let resp = futu_proto::qot_option_screen::Response::decode(frame.body.as_ref())
38 .map_err(|e| anyhow!("decode option_screen: {e}"))?;
39 if resp.ret_type != 0 {
40 bail!(
41 "option_screen ret_type={} msg={:?}",
42 resp.ret_type,
43 resp.ret_msg
44 );
45 }
46 let s2c = resp.s2c.ok_or_else(|| anyhow!("missing s2c"))?;
47 Ok(serde_json::to_string_pretty(&s2c)?)
48}
49
50pub async fn warrant_screen(client: &Arc<FutuClient>, c2s: Value) -> Result<String> {
51 let c2s = serde_json::from_value::<futu_proto::qot_warrant_screen::C2s>(c2s)
52 .map_err(|e| anyhow!("warrant_screen c2s json: {e}"))?;
53 let req = futu_proto::qot_warrant_screen::Request { c2s };
54 let frame = client
55 .request(futu_core::proto_id::QOT_WARRANT_SCREEN, req.encode_to_vec())
56 .await?;
57 let resp = futu_proto::qot_warrant_screen::Response::decode(frame.body.as_ref())
58 .map_err(|e| anyhow!("decode warrant_screen: {e}"))?;
59 if resp.ret_type != 0 {
60 bail!(
61 "warrant_screen ret_type={} msg={:?}",
62 resp.ret_type,
63 resp.ret_msg
64 );
65 }
66 let s2c = resp.s2c.ok_or_else(|| anyhow!("missing s2c"))?;
67 Ok(serde_json::to_string_pretty(&s2c)?)
68}