futu_backend/trade_query/
account_info.rs1use super::*;
2use futu_core::error::FutuError;
3mod command;
4mod funds_cache;
5mod funds_sidecar;
6mod position_cache;
7mod positions;
8mod request;
9mod runtime_plan;
10mod status;
11mod workflow;
12#[cfg(test)]
13use positions::{ComboPositionMeta, PositionAccountContext, cached_position_from_account_pstn};
14use runtime_plan::plan_cmd3020_asset_categories_runtime;
15use workflow::query_cmd3020_account_info_one;
16
17#[derive(Clone, Copy, Debug, PartialEq, Eq)]
21pub enum Cmd3020QuoteLevel {
22 UsBasic,
23 UsUtp,
24}
25
26impl Cmd3020QuoteLevel {
27 #[must_use]
29 pub const fn from_has_us_utp(has_us_utp: bool) -> Self {
30 if has_us_utp {
31 Self::UsUtp
32 } else {
33 Self::UsBasic
34 }
35 }
36
37 pub(super) const fn backend_value(self) -> u32 {
38 match self {
39 Self::UsBasic => 1,
40 Self::UsUtp => 2,
41 }
42 }
43}
44
45pub async fn query_account_info(
64 backend: &BackendConn,
65 acc_id: u64,
66 trd_cache: &TrdCache,
67 requested_currency: Option<i32>,
68 requested_asset_category: Option<i32>,
69 quote_level: Cmd3020QuoteLevel,
70) -> Result<()> {
71 let category_plan =
72 plan_cmd3020_asset_categories_runtime(trd_cache, acc_id, requested_asset_category);
73 for category in category_plan {
74 query_cmd3020_account_info_one(
75 backend,
76 acc_id,
77 trd_cache,
78 requested_currency,
79 category,
80 None,
81 quote_level,
82 TradeQueryOperation::Funds,
83 )
84 .await?;
85 }
86 Ok(())
87}
88
89pub async fn query_account_info_after_trade_push(
96 backend: &BackendConn,
97 acc_id: u64,
98 trd_cache: &TrdCache,
99 push_version: Option<u64>,
100 asset_category: Option<u32>,
101 quote_level: Cmd3020QuoteLevel,
102) -> Result<()> {
103 let requested_asset_category = asset_category.map(i32::try_from).transpose().map_err(|_| {
104 FutuError::Codec("trade notify asset_category exceeds i32 range".to_string())
105 })?;
106 let category_plan =
107 plan_cmd3020_asset_categories_runtime(trd_cache, acc_id, requested_asset_category);
108 for category in category_plan {
109 query_cmd3020_account_info_one(
110 backend,
111 acc_id,
112 trd_cache,
113 None,
114 category,
115 push_version,
116 quote_level,
117 TradeQueryOperation::Funds,
118 )
119 .await?;
120 }
121 Ok(())
122}
123
124#[cfg(test)]
125mod tests;
126
127pub async fn query_position_account_info(
135 backend: &BackendConn,
136 acc_id: u64,
137 trd_cache: &TrdCache,
138 requested_asset_category: Option<i32>,
139 requested_currency: Option<i32>,
140 quote_level: Cmd3020QuoteLevel,
141) -> Result<()> {
142 let category_plan =
143 plan_cmd3020_asset_categories_runtime(trd_cache, acc_id, requested_asset_category);
144 for category in category_plan {
145 query_cmd3020_account_info_one(
146 backend,
147 acc_id,
148 trd_cache,
149 requested_currency,
150 category,
151 None,
152 quote_level,
153 TradeQueryOperation::Positions,
154 )
155 .await?;
156 }
157 Ok(())
158}