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 | ... | MOC;MOC 仅支持 real US common stock,
53    /// 不接收 --price/--stop-price,且要求 --idempotency-key 与 daemon
54    /// --enable-moc-order。16–19 协议已声明,但当前 PlaceOrder 不支持并会拒绝。
55    #[arg(long, default_value = "NORMAL")]
56    pub(crate) order_type: String,
57
58    /// 股票代码(不含 market 前缀,如 00700 / AAPL)
59    #[arg(long)]
60    pub(crate) code: String,
61
62    /// 数量
63    #[arg(long)]
64    pub(crate) qty: f64,
65
66    /// 价格(NORMAL 限价单必填,MARKET 可省)
67    #[arg(long)]
68    pub(crate) price: Option<f64>,
69
70    /// Event Contract 金额单金额;仅 `--market PREDICTION` 有效
71    #[arg(long)]
72    pub(crate) amount: Option<f64>,
73
74    /// Event Contract 预测方向:1=Yes,2=No;仅 `--market PREDICTION` 有效
75    #[arg(long = "pred-side")]
76    pub(crate) pred_side: Option<i32>,
77
78    /// 订单有效期限:DAY|GTC|IOC|GTD 或 0|1|2|3
79    #[arg(long = "time-in-force")]
80    pub(crate) time_in_force: Option<String>,
81
82    /// 允许美股盘前/盘后成交(FTAPI fillOutsideRTH)
83    #[arg(long = "fill-outside-rth")]
84    pub(crate) fill_outside_rth: bool,
85
86    /// 美股订单时段:NONE|RTH|ETH|ALL|OVERNIGHT 或 0|1|2|3|4
87    #[arg(long)]
88    pub(crate) session: Option<String>,
89
90    /// GTD 到期日期 YYYY-MM-DD,仅在 --time-in-force GTD 时有效
91    #[arg(long = "expire-time")]
92    pub(crate) expire_time: Option<String>,
93
94    /// JP 子账户类型(TrdHeader.jpAccType / TrdSubAccType)
95    #[arg(long = "jp-acc-type")]
96    pub(crate) jp_acc_type: Option<i32>,
97
98    /// real env 必须显式加此 flag 才能下单
99    #[arg(long)]
100    pub(crate) confirm: bool,
101
102    /// v1.4.39:普通订单可选、MOC 必填的幂等键。**设置后**,同一键在 90s 内重试返 cached 响应不
103    /// 重复下单(对齐 REST `Idempotency-Key` header 语义)。不设置则每次调
104    /// 用都真实下单。例:`--idempotency-key my-order-2026-04-20-a`
105    #[arg(long)]
106    pub(crate) idempotency_key: Option<String>,
107
108    /// **v1.4.53 条件单**:止损/止盈触发价(仅对 STOP / STOP_LIMIT / MIT /
109    /// LIT / TRAILING_STOP / TRAILING_STOP_LIMIT 生效)。对齐 FTAPI `auxPrice`
110    #[arg(long)]
111    pub(crate) stop_price: Option<f64>,
112
113    /// **v1.4.53 条件单**:跟踪类型 1=Ratio(比例)/ 2=Amount(金额)
114    #[arg(long)]
115    pub(crate) trail_type: Option<i32>,
116
117    /// **v1.4.53 条件单**:跟踪金额 / 百分比(TrailType=1 时为百分比)
118    #[arg(long)]
119    pub(crate) trail_value: Option<f64>,
120
121    /// **v1.4.53 条件单**:指定价差(跟踪限价单用)
122    #[arg(long)]
123    pub(crate) trail_spread: Option<f64>,
124}
125
126#[derive(Args)]
127pub struct ModifyOrderArgs {
128    #[arg(short, long)]
129    pub(crate) market: String,
130
131    #[arg(long)]
132    pub(crate) acc_id: Option<u64>,
133
134    /// App 显示卡号:4 位末尾或 16 位完整卡号
135    #[arg(long = "card-num")]
136    pub(crate) card_num: Option<String>,
137
138    /// Unix owner-only (exact mode 0600) account-id file; keeps the raw selector out of argv.
139    #[arg(
140        long = "acc-id-file",
141        value_name = "MODE_0600_FILE",
142        conflicts_with_all = ["acc_id", "card_num"]
143    )]
144    pub(crate) acc_id_file: Option<std::path::PathBuf>,
145
146    #[arg(short, long, default_value = "simulate")]
147    pub(crate) env: String,
148
149    #[arg(long)]
150    pub(crate) order_id: String,
151
152    /// 操作类型: NORMAL(改数量价格)| CANCEL | DISABLE | ENABLE | DELETE
153    #[arg(long)]
154    pub(crate) op: String,
155
156    /// 新数量(op=NORMAL 必填)
157    #[arg(long)]
158    pub(crate) qty: Option<f64>,
159
160    /// 新价格(op=NORMAL 必填)
161    #[arg(long)]
162    pub(crate) price: Option<f64>,
163
164    /// JP 子账户类型(TrdHeader.jpAccType / TrdSubAccType)
165    #[arg(long = "jp-acc-type")]
166    pub(crate) jp_acc_type: Option<i32>,
167
168    #[arg(long)]
169    pub(crate) confirm: bool,
170
171    /// v1.4.39:可选幂等键。同 `place-order --idempotency-key`
172    #[arg(long)]
173    pub(crate) idempotency_key: Option<String>,
174}
175
176#[derive(Args)]
177pub struct CancelOrderArgs {
178    #[arg(short, long)]
179    pub(crate) market: String,
180
181    #[arg(long)]
182    pub(crate) acc_id: Option<u64>,
183
184    /// App 显示卡号:4 位末尾或 16 位完整卡号
185    #[arg(long = "card-num")]
186    pub(crate) card_num: Option<String>,
187
188    /// Unix owner-only (exact mode 0600) account-id file; keeps the raw selector out of argv.
189    #[arg(
190        long = "acc-id-file",
191        value_name = "MODE_0600_FILE",
192        conflicts_with_all = ["acc_id", "card_num"]
193    )]
194    pub(crate) acc_id_file: Option<std::path::PathBuf>,
195
196    #[arg(short, long, default_value = "simulate")]
197    pub(crate) env: String,
198
199    #[arg(long)]
200    pub(crate) order_id: String,
201
202    /// JP 子账户类型(TrdHeader.jpAccType / TrdSubAccType)
203    #[arg(long = "jp-acc-type")]
204    pub(crate) jp_acc_type: Option<i32>,
205
206    /// v1.4.110:可选幂等键。同 `modify-order --idempotency-key`
207    #[arg(long)]
208    pub(crate) idempotency_key: Option<String>,
209
210    #[arg(long)]
211    pub(crate) confirm: bool,
212}
213
214#[derive(Args)]
215pub struct ReconfirmOrderArgs {
216    #[arg(short, long)]
217    pub(crate) market: String,
218
219    #[arg(long)]
220    pub(crate) acc_id: Option<u64>,
221
222    /// App 显示卡号:4 位末尾或 16 位完整卡号
223    #[arg(long = "card-num")]
224    pub(crate) card_num: Option<String>,
225
226    /// Unix owner-only (exact mode 0600) account-id file; keeps the raw selector out of argv.
227    #[arg(
228        long = "acc-id-file",
229        value_name = "MODE_0600_FILE",
230        conflicts_with_all = ["acc_id", "card_num"]
231    )]
232    pub(crate) acc_id_file: Option<std::path::PathBuf>,
233
234    #[arg(short, long, default_value = "simulate")]
235    pub(crate) env: String,
236
237    /// 待二次确认的 FTAPI numeric order_id
238    #[arg(long)]
239    pub(crate) order_id: String,
240
241    /// 二次确认原因(Trd_Common.ReconfirmOrderReason int)
242    #[arg(long)]
243    pub(crate) reason: i32,
244
245    /// JP 子账户类型(TrdHeader.jpAccType / TrdSubAccType)
246    #[arg(long = "jp-acc-type")]
247    pub(crate) jp_acc_type: Option<i32>,
248
249    /// real env 必须显式加此 flag 才能二次确认订单
250    #[arg(long)]
251    pub(crate) confirm: bool,
252}