gateio_rs/api/spot/cancel_all_price_orders.rs
1use crate::http::{Credentials, Method, request::Request};
2
3/// # Cancel all price-triggered orders
4///
5/// Cancel all running price-triggered orders (auto orders/conditional orders).
6/// This operation will cancel all currently active price-triggered orders for the account.
7///
8/// ## Important Notes:
9/// - This action cannot be undone
10/// - Only cancels orders in "open" status (waiting to trigger)
11/// - Orders that have already triggered and are executing cannot be cancelled
12/// - Completed, failed, expired orders are not affected
13///
14/// [Gate API Documentation](https://www.gate.com/docs/developers/apiv4/#cancel-all-price-triggered-orders)
15pub struct CancelAllPriceOrders {
16 /// Filter by currency pair (market)
17 pub market: Option<String>,
18 /// Trading account type
19 pub account: Option<String>,
20 /// Request expiration time in milliseconds
21 pub x_gate_exp_time: Option<u128>,
22 /// API credentials for authentication
23 pub credentials: Option<Credentials>,
24}
25
26impl CancelAllPriceOrders {
27 /// Create a new cancel all price orders request
28 pub fn new() -> Self {
29 Self {
30 market: None,
31 account: None,
32 x_gate_exp_time: None,
33 credentials: None,
34 }
35 }
36
37 /// Filter by currency pair (market) - if specified, only orders for this market will be cancelled
38 pub fn market(mut self, market: &str) -> Self {
39 self.market = Some(market.into());
40 self
41 }
42
43 /// Filter by account type
44 /// - "normal": Normal spot trading account
45 /// - "margin": Margin trading account
46 /// - "unified": Unified trading account
47 pub fn account(mut self, account: &str) -> Self {
48 self.account = Some(account.into());
49 self
50 }
51
52 /// Specify the expiration time (milliseconds);
53 /// If the GATE receives the request time greater than the expiration time, the request will be rejected
54 pub fn x_gate_exp_time(mut self, x_gate_exp_time: u128) -> Self {
55 self.x_gate_exp_time = Some(x_gate_exp_time);
56 self
57 }
58
59 /// Set API credentials for authentication
60 pub fn credentials(mut self, creds: Credentials) -> Self {
61 self.credentials = Some(creds);
62 self
63 }
64}
65
66impl From<CancelAllPriceOrders> for Request {
67 fn from(request: CancelAllPriceOrders) -> Request {
68 let mut params = Vec::new();
69
70 if let Some(market) = request.market {
71 params.push(("market".into(), market));
72 }
73
74 if let Some(account) = request.account {
75 params.push(("account".into(), account));
76 }
77
78 Request {
79 method: Method::Delete,
80 path: "/api/v4/spot/price_orders".into(),
81 params,
82 payload: "".to_string(),
83 x_gate_exp_time: request.x_gate_exp_time,
84 credentials: request.credentials,
85 sign: true,
86 }
87 }
88}