Skip to main content

futucli/cli/dispatch/
trade_read.rs

1use anyhow::Result;
2
3use super::super::commands::{
4    ComboMaxTrdQtysArgs, DealArgs, FundsArgs, OrderArgs, PositionArgs, TradeCheckArgs,
5};
6use crate::cmd;
7use crate::output::OutputFormat;
8
9pub(super) async fn dispatch_funds(
10    gateway: &str,
11    output: OutputFormat,
12    args: FundsArgs,
13) -> Result<()> {
14    let acc_id = cmd::account::resolve_account_locator(
15        gateway,
16        args.acc_id,
17        args.card_num.as_deref(),
18        "funds",
19    )
20    .await?;
21    cmd::account::funds(
22        gateway,
23        &args.env,
24        acc_id,
25        args.market.as_deref(),
26        args.currency.as_deref(),
27        output,
28    )
29    .await
30}
31
32pub(super) async fn dispatch_position(
33    gateway: &str,
34    output: OutputFormat,
35    args: PositionArgs,
36) -> Result<()> {
37    let acc_id = cmd::account::resolve_account_locator(
38        gateway,
39        args.acc_id,
40        args.card_num.as_deref(),
41        "positions",
42    )
43    .await?;
44    cmd::account::positions(
45        gateway,
46        &args.env,
47        acc_id,
48        &args.market,
49        args.currency.as_deref(),
50        args.option_strategy_view,
51        output,
52    )
53    .await
54}
55
56pub(super) async fn dispatch_order(
57    gateway: &str,
58    output: OutputFormat,
59    args: OrderArgs,
60) -> Result<()> {
61    let acc_id = cmd::account::resolve_account_locator(
62        gateway,
63        args.acc_id,
64        args.card_num.as_deref(),
65        "orders",
66    )
67    .await?;
68    cmd::account::orders(gateway, &args.env, acc_id, &args.market, output).await
69}
70
71pub(super) async fn dispatch_deal(
72    gateway: &str,
73    output: OutputFormat,
74    args: DealArgs,
75) -> Result<()> {
76    let acc_id = cmd::account::resolve_account_locator(
77        gateway,
78        args.acc_id,
79        args.card_num.as_deref(),
80        "deals",
81    )
82    .await?;
83    cmd::account::deals(gateway, &args.env, acc_id, &args.market, output).await
84}
85
86pub(super) async fn dispatch_combo_max_trd_qtys(
87    gateway: &str,
88    output: OutputFormat,
89    args: ComboMaxTrdQtysArgs,
90) -> Result<()> {
91    cmd::proto_json::run_combo_max_trd_qtys(gateway, &args.c2s_json, output).await
92}
93
94pub(super) async fn dispatch_trade_check(
95    gateway: &str,
96    output: OutputFormat,
97    args: TradeCheckArgs,
98) -> Result<()> {
99    let acc_id = cmd::account::resolve_account_locator(
100        gateway,
101        args.acc_id,
102        args.card_num.as_deref(),
103        "trade-check",
104    )
105    .await?;
106    cmd::trade_check::run_trade_check(cmd::trade_check::TradeCheckCommand {
107        gateway,
108        market: &args.market,
109        env: &args.env,
110        acc_id,
111        card_num: args.card_num.as_deref(),
112        order_type: &args.order_type,
113        code: &args.code,
114        price: args.price,
115        jp_acc_type: args.jp_acc_type,
116        output,
117    })
118    .await
119}