Skip to main content

futucli/cli/dispatch/
trade_read.rs

1use anyhow::Result;
2
3use super::super::commands::{
4    ComboMaxTrdQtysArgs, DealArgs, FundsArgs, OrderArgs, PositionArgs, ProtoJsonArgs,
5    TradeCheckArgs,
6};
7use crate::cmd;
8use crate::output::OutputFormat;
9
10pub(super) async fn dispatch_funds(
11    gateway: &str,
12    output: OutputFormat,
13    args: FundsArgs,
14) -> Result<()> {
15    let acc_id = cmd::account::resolve_account_locator(
16        gateway,
17        args.acc_id,
18        args.acc_id_file.as_deref(),
19        args.card_num.as_deref(),
20        "funds",
21    )
22    .await?;
23    cmd::account::funds(
24        gateway,
25        &args.env,
26        acc_id,
27        args.market.as_deref(),
28        args.currency.as_deref(),
29        output,
30    )
31    .await
32}
33
34pub(super) async fn dispatch_position(
35    gateway: &str,
36    output: OutputFormat,
37    args: PositionArgs,
38) -> Result<()> {
39    let acc_id = cmd::account::resolve_account_locator(
40        gateway,
41        args.acc_id,
42        args.acc_id_file.as_deref(),
43        args.card_num.as_deref(),
44        "positions",
45    )
46    .await?;
47    cmd::account::positions(
48        gateway,
49        &args.env,
50        acc_id,
51        &args.market,
52        args.currency.as_deref(),
53        args.option_strategy_view,
54        output,
55    )
56    .await
57}
58
59pub(super) async fn dispatch_order(
60    gateway: &str,
61    output: OutputFormat,
62    args: OrderArgs,
63) -> Result<()> {
64    let acc_id = cmd::account::resolve_account_locator(
65        gateway,
66        args.acc_id,
67        args.acc_id_file.as_deref(),
68        args.card_num.as_deref(),
69        "orders",
70    )
71    .await?;
72    cmd::account::orders(gateway, &args.env, acc_id, &args.market, output).await
73}
74
75pub(super) async fn dispatch_deal(
76    gateway: &str,
77    output: OutputFormat,
78    args: DealArgs,
79) -> Result<()> {
80    let acc_id = cmd::account::resolve_account_locator(
81        gateway,
82        args.acc_id,
83        args.acc_id_file.as_deref(),
84        args.card_num.as_deref(),
85        "deals",
86    )
87    .await?;
88    cmd::account::deals(gateway, &args.env, acc_id, &args.market, output).await
89}
90
91pub(super) async fn dispatch_combo_max_trd_qtys(
92    gateway: &str,
93    output: OutputFormat,
94    args: ComboMaxTrdQtysArgs,
95) -> Result<()> {
96    cmd::proto_json::run_combo_max_trd_qtys(gateway, &args.c2s_json, output).await
97}
98
99pub(super) async fn dispatch_preview_order_impact(
100    gateway: &str,
101    output: OutputFormat,
102    args: ProtoJsonArgs,
103) -> Result<()> {
104    cmd::proto_json::run_preview_order_impact(gateway, &args.c2s_json, output).await
105}
106
107pub(super) async fn dispatch_asset_trend(
108    gateway: &str,
109    output: OutputFormat,
110    args: ProtoJsonArgs,
111) -> Result<()> {
112    cmd::proto_json::run_asset_trend(gateway, &args.c2s_json, output).await
113}
114
115pub(super) async fn dispatch_yield_trend(
116    gateway: &str,
117    output: OutputFormat,
118    args: ProtoJsonArgs,
119) -> Result<()> {
120    cmd::proto_json::run_yield_trend(gateway, &args.c2s_json, output).await
121}
122
123pub(super) async fn dispatch_return_calendar(
124    gateway: &str,
125    output: OutputFormat,
126    args: ProtoJsonArgs,
127) -> Result<()> {
128    cmd::proto_json::run_return_calendar(gateway, &args.c2s_json, output).await
129}
130
131pub(super) async fn dispatch_order_relations(
132    gateway: &str,
133    output: OutputFormat,
134    args: ProtoJsonArgs,
135) -> Result<()> {
136    cmd::proto_json::run_order_relations(gateway, &args.c2s_json, output).await
137}
138
139pub(super) async fn dispatch_position_corporate_actions(
140    gateway: &str,
141    output: OutputFormat,
142    args: ProtoJsonArgs,
143) -> Result<()> {
144    cmd::proto_json::run_position_corporate_actions(gateway, &args.c2s_json, output).await
145}
146
147pub(super) async fn dispatch_trade_check(
148    gateway: &str,
149    output: OutputFormat,
150    args: TradeCheckArgs,
151) -> Result<()> {
152    let acc_id = cmd::account::resolve_account_locator(
153        gateway,
154        args.acc_id,
155        args.acc_id_file.as_deref(),
156        args.card_num.as_deref(),
157        "trade-check",
158    )
159    .await?;
160    cmd::trade_check::run_trade_check(cmd::trade_check::TradeCheckCommand {
161        gateway,
162        market: &args.market,
163        env: &args.env,
164        acc_id,
165        card_num: args.card_num.as_deref(),
166        order_type: &args.order_type,
167        code: &args.code,
168        price: args.price,
169        jp_acc_type: args.jp_acc_type,
170        output,
171    })
172    .await
173}