Skip to main content

futucli/cli/dispatch/
qot.rs

1use anyhow::Result;
2
3use super::super::commands::{
4    BrokerArgs, KlineArgs, OrderbookArgs, PlateListArgs, PlateStocksArgs, QuoteArgs, RtArgs,
5    SnapshotArgs, StaticArgs, SubArgs, TickerArgs,
6};
7use crate::cmd;
8use crate::output::OutputFormat;
9
10pub(super) async fn dispatch_quote(
11    gateway: &str,
12    output: OutputFormat,
13    args: QuoteArgs,
14) -> Result<()> {
15    cmd::quote::run(gateway, &args.symbols, output).await
16}
17
18pub(super) async fn dispatch_snapshot(
19    gateway: &str,
20    output: OutputFormat,
21    args: SnapshotArgs,
22) -> Result<()> {
23    cmd::snapshot::run(gateway, &args.symbols, output).await
24}
25
26pub(super) async fn dispatch_sub(gateway: &str, output: OutputFormat, args: SubArgs) -> Result<()> {
27    cmd::sub::run(gateway, &args.symbols, &args.r#type, output).await
28}
29
30pub(super) async fn dispatch_kline(
31    gateway: &str,
32    output: OutputFormat,
33    args: KlineArgs,
34) -> Result<()> {
35    // v1.4.83 §10: positional 或 --symbol/--code/--stock flag 二选一
36    let symbol = args.symbol_positional.or(args.symbol_arg).ok_or_else(|| {
37        anyhow::anyhow!(
38            "kline: 需要 positional <SYMBOL> 或 --symbol/--code/--stock \
39             (如 `futucli kline US.AAPL` 或 `futucli kline --code US.AAPL`)"
40        )
41    })?;
42    cmd::kline::run_with_format(
43        gateway,
44        &symbol,
45        &args.r#type,
46        args.count,
47        args.begin.as_deref(),
48        args.end.as_deref(),
49        output,
50    )
51    .await
52}
53
54pub(super) async fn dispatch_orderbook(
55    gateway: &str,
56    output: OutputFormat,
57    args: OrderbookArgs,
58) -> Result<()> {
59    let symbol = args.symbol_positional.or(args.symbol_arg).ok_or_else(|| {
60        anyhow::anyhow!("orderbook: 需要 positional <SYMBOL> 或 --symbol/--code/--stock")
61    })?;
62    cmd::orderbook::run(gateway, &symbol, args.depth, output).await
63}
64
65pub(super) async fn dispatch_ticker(
66    gateway: &str,
67    output: OutputFormat,
68    args: TickerArgs,
69) -> Result<()> {
70    let symbol = args.symbol_positional.or(args.symbol_arg).ok_or_else(|| {
71        anyhow::anyhow!("ticker: 需要 positional <SYMBOL> 或 --symbol/--code/--stock")
72    })?;
73    cmd::ticker::run(gateway, &symbol, args.count, output).await
74}
75
76pub(super) async fn dispatch_rt(gateway: &str, output: OutputFormat, args: RtArgs) -> Result<()> {
77    let symbol = args.symbol_positional.or(args.symbol_arg).ok_or_else(|| {
78        anyhow::anyhow!("rt: 需要 positional <SYMBOL> 或 --symbol/--code/--stock")
79    })?;
80    cmd::rt::run(gateway, &symbol, output).await
81}
82
83pub(super) async fn dispatch_static(
84    gateway: &str,
85    output: OutputFormat,
86    args: StaticArgs,
87) -> Result<()> {
88    cmd::static_info::run(gateway, &args.symbols, output).await
89}
90
91pub(super) async fn dispatch_broker(
92    gateway: &str,
93    output: OutputFormat,
94    args: BrokerArgs,
95) -> Result<()> {
96    let symbol = args.symbol_positional.or(args.symbol_arg).ok_or_else(|| {
97        anyhow::anyhow!("broker: 需要 positional <SYMBOL> 或 --symbol/--code/--stock")
98    })?;
99    cmd::broker::run(gateway, &symbol, output).await
100}
101
102pub(super) async fn dispatch_plate_list(
103    gateway: &str,
104    output: OutputFormat,
105    args: PlateListArgs,
106) -> Result<()> {
107    cmd::plate::list(gateway, &args.market, &args.set, output).await
108}
109
110pub(super) async fn dispatch_plate_stocks(
111    gateway: &str,
112    output: OutputFormat,
113    args: PlateStocksArgs,
114) -> Result<()> {
115    let plate = args
116        .plate
117        .or(args.plate_arg)
118        .ok_or_else(|| anyhow::anyhow!("plate-stocks: 需要位置参数 <PLATE> 或 --plate"))?;
119    cmd::plate::stocks(gateway, &plate, output).await
120}