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