Skip to main content

futucli/cli/commands/
trade_write.rs

1//! Trade-write clap argument structs split from commands.rs.
2
3use clap::Args;
4
5#[derive(Args)]
6pub struct ComboOrderArgs {
7    /// 官方 `Trd_PlaceComboOrder.C2S` JSON;`packetID` 可省略,CLI 会按连接补齐。
8    ///
9    /// 字段名按 generated proto serde 的 snake_case 写法,例如
10    /// `header`、`combo_legs`、`order_type`。CLI 不替用户改写价格、腿方向、
11    /// time_in_force 等交易语义字段。
12    #[arg(long = "c2s-json", value_name = "JSON")]
13    pub(crate) c2s_json: String,
14
15    /// real 交易环境必须显式确认。环境从 C2S.header.trdEnv 读取。
16    #[arg(long)]
17    pub(crate) confirm: bool,
18
19    /// 可选幂等键;设置后 CLI 用稳定 PacketID 派生同一请求。
20    #[arg(long)]
21    pub(crate) idempotency_key: Option<String>,
22}
23
24#[derive(Args)]
25pub struct PlaceOrderArgs {
26    #[arg(short, long)]
27    pub(crate) market: String,
28
29    #[arg(long)]
30    pub(crate) acc_id: Option<u64>,
31
32    /// App 显示卡号:4 位末尾或 16 位完整卡号
33    #[arg(long = "card-num")]
34    pub(crate) card_num: Option<String>,
35
36    /// Unix owner-only (exact mode 0600) account-id file; keeps the raw selector out of argv.
37    #[arg(
38        long = "acc-id-file",
39        value_name = "MODE_0600_FILE",
40        conflicts_with_all = ["acc_id", "card_num"]
41    )]
42    pub(crate) acc_id_file: Option<std::path::PathBuf>,
43
44    /// 交易环境(默认 simulate 防实盘误触)
45    #[arg(short, long, default_value = "simulate")]
46    pub(crate) env: String,
47
48    /// 买卖方向: BUY | SELL | SELL_SHORT | BUY_BACK
49    #[arg(long)]
50    pub(crate) side: String,
51
52    /// 订单类型: NORMAL | MARKET | ABSOLUTE_LIMIT | AUCTION | AUCTION_LIMIT | SPECIAL_LIMIT;
53    /// 16–19 协议已声明,但当前 PlaceOrder 不支持并会拒绝;TWAP/VWAP 算法订单尚未实现
54    #[arg(long, default_value = "NORMAL")]
55    pub(crate) order_type: String,
56
57    /// 股票代码(不含 market 前缀,如 00700 / AAPL)
58    #[arg(long)]
59    pub(crate) code: String,
60
61    /// 数量
62    #[arg(long)]
63    pub(crate) qty: f64,
64
65    /// 价格(NORMAL 限价单必填,MARKET 可省)
66    #[arg(long)]
67    pub(crate) price: Option<f64>,
68
69    /// Event Contract 金额单金额;仅 `--market PREDICTION` 有效
70    #[arg(long)]
71    pub(crate) amount: Option<f64>,
72
73    /// Event Contract 预测方向:1=Yes,2=No;仅 `--market PREDICTION` 有效
74    #[arg(long = "pred-side")]
75    pub(crate) pred_side: Option<i32>,
76
77    /// 订单有效期限:DAY|GTC|IOC|GTD 或 0|1|2|3
78    #[arg(long = "time-in-force")]
79    pub(crate) time_in_force: Option<String>,
80
81    /// 允许美股盘前/盘后成交(FTAPI fillOutsideRTH)
82    #[arg(long = "fill-outside-rth")]
83    pub(crate) fill_outside_rth: bool,
84
85    /// 美股订单时段:NONE|RTH|ETH|ALL|OVERNIGHT 或 0|1|2|3|4
86    #[arg(long)]
87    pub(crate) session: Option<String>,
88
89    /// GTD 到期日期 YYYY-MM-DD,仅在 --time-in-force GTD 时有效
90    #[arg(long = "expire-time")]
91    pub(crate) expire_time: Option<String>,
92
93    /// JP 子账户类型(TrdHeader.jpAccType / TrdSubAccType)
94    #[arg(long = "jp-acc-type")]
95    pub(crate) jp_acc_type: Option<i32>,
96
97    /// real env 必须显式加此 flag 才能下单
98    #[arg(long)]
99    pub(crate) confirm: bool,
100
101    /// v1.4.39:可选幂等键。**设置后**,同一键在 90s 内重试返 cached 响应不
102    /// 重复下单(对齐 REST `Idempotency-Key` header 语义)。不设置则每次调
103    /// 用都真实下单。例:`--idempotency-key my-order-2026-04-20-a`
104    #[arg(long)]
105    pub(crate) idempotency_key: Option<String>,
106
107    /// **v1.4.53 条件单**:止损/止盈触发价(仅对 STOP / STOP_LIMIT / MIT /
108    /// LIT / TRAILING_STOP / TRAILING_STOP_LIMIT 生效)。对齐 FTAPI `auxPrice`
109    #[arg(long)]
110    pub(crate) stop_price: Option<f64>,
111
112    /// **v1.4.53 条件单**:跟踪类型 1=Ratio(比例)/ 2=Amount(金额)
113    #[arg(long)]
114    pub(crate) trail_type: Option<i32>,
115
116    /// **v1.4.53 条件单**:跟踪金额 / 百分比(TrailType=1 时为百分比)
117    #[arg(long)]
118    pub(crate) trail_value: Option<f64>,
119
120    /// **v1.4.53 条件单**:指定价差(跟踪限价单用)
121    #[arg(long)]
122    pub(crate) trail_spread: Option<f64>,
123}
124
125#[derive(Args)]
126pub struct ModifyOrderArgs {
127    #[arg(short, long)]
128    pub(crate) market: String,
129
130    #[arg(long)]
131    pub(crate) acc_id: Option<u64>,
132
133    /// App 显示卡号:4 位末尾或 16 位完整卡号
134    #[arg(long = "card-num")]
135    pub(crate) card_num: Option<String>,
136
137    /// Unix owner-only (exact mode 0600) account-id file; keeps the raw selector out of argv.
138    #[arg(
139        long = "acc-id-file",
140        value_name = "MODE_0600_FILE",
141        conflicts_with_all = ["acc_id", "card_num"]
142    )]
143    pub(crate) acc_id_file: Option<std::path::PathBuf>,
144
145    #[arg(short, long, default_value = "simulate")]
146    pub(crate) env: String,
147
148    #[arg(long)]
149    pub(crate) order_id: String,
150
151    /// 操作类型: NORMAL(改数量价格)| CANCEL | DISABLE | ENABLE | DELETE
152    #[arg(long)]
153    pub(crate) op: String,
154
155    /// 新数量(op=NORMAL 必填)
156    #[arg(long)]
157    pub(crate) qty: Option<f64>,
158
159    /// 新价格(op=NORMAL 必填)
160    #[arg(long)]
161    pub(crate) price: Option<f64>,
162
163    /// JP 子账户类型(TrdHeader.jpAccType / TrdSubAccType)
164    #[arg(long = "jp-acc-type")]
165    pub(crate) jp_acc_type: Option<i32>,
166
167    #[arg(long)]
168    pub(crate) confirm: bool,
169
170    /// v1.4.39:可选幂等键。同 `place-order --idempotency-key`
171    #[arg(long)]
172    pub(crate) idempotency_key: Option<String>,
173}
174
175#[derive(Args)]
176pub struct CancelOrderArgs {
177    #[arg(short, long)]
178    pub(crate) market: String,
179
180    #[arg(long)]
181    pub(crate) acc_id: Option<u64>,
182
183    /// App 显示卡号:4 位末尾或 16 位完整卡号
184    #[arg(long = "card-num")]
185    pub(crate) card_num: Option<String>,
186
187    /// Unix owner-only (exact mode 0600) account-id file; keeps the raw selector out of argv.
188    #[arg(
189        long = "acc-id-file",
190        value_name = "MODE_0600_FILE",
191        conflicts_with_all = ["acc_id", "card_num"]
192    )]
193    pub(crate) acc_id_file: Option<std::path::PathBuf>,
194
195    #[arg(short, long, default_value = "simulate")]
196    pub(crate) env: String,
197
198    #[arg(long)]
199    pub(crate) order_id: String,
200
201    /// JP 子账户类型(TrdHeader.jpAccType / TrdSubAccType)
202    #[arg(long = "jp-acc-type")]
203    pub(crate) jp_acc_type: Option<i32>,
204
205    /// v1.4.110:可选幂等键。同 `modify-order --idempotency-key`
206    #[arg(long)]
207    pub(crate) idempotency_key: Option<String>,
208
209    #[arg(long)]
210    pub(crate) confirm: bool,
211}
212
213#[derive(Args)]
214pub struct ReconfirmOrderArgs {
215    #[arg(short, long)]
216    pub(crate) market: String,
217
218    #[arg(long)]
219    pub(crate) acc_id: Option<u64>,
220
221    /// App 显示卡号:4 位末尾或 16 位完整卡号
222    #[arg(long = "card-num")]
223    pub(crate) card_num: Option<String>,
224
225    /// Unix owner-only (exact mode 0600) account-id file; keeps the raw selector out of argv.
226    #[arg(
227        long = "acc-id-file",
228        value_name = "MODE_0600_FILE",
229        conflicts_with_all = ["acc_id", "card_num"]
230    )]
231    pub(crate) acc_id_file: Option<std::path::PathBuf>,
232
233    #[arg(short, long, default_value = "simulate")]
234    pub(crate) env: String,
235
236    /// 待二次确认的 FTAPI numeric order_id
237    #[arg(long)]
238    pub(crate) order_id: String,
239
240    /// 二次确认原因(Trd_Common.ReconfirmOrderReason int)
241    #[arg(long)]
242    pub(crate) reason: i32,
243
244    /// JP 子账户类型(TrdHeader.jpAccType / TrdSubAccType)
245    #[arg(long = "jp-acc-type")]
246    pub(crate) jp_acc_type: Option<i32>,
247
248    /// real env 必须显式加此 flag 才能二次确认订单
249    #[arg(long)]
250    pub(crate) confirm: bool,
251}