gateio_rs/api/spot/cancel_price_order.rs
1use crate::http::{Credentials, Method, request::Request};
2
3/// # Cancel a price-triggered order
4///
5/// Cancel a specific price-triggered order (auto order/conditional order) by order ID.
6/// Only orders in "open" status (waiting to trigger) can be cancelled.
7///
8/// ## Important Notes:
9/// - Only orders in "open" status can be cancelled
10/// - Orders that have already triggered and are executing cannot be cancelled
11/// - Completed, failed, expired orders cannot be cancelled
12/// - This action cannot be undone
13///
14/// ## Response:
15/// Returns the cancelled order details with updated status
16///
17/// [Gate API Documentation](https://www.gate.com/docs/developers/apiv4/#cancel-a-price-triggered-order)
18pub struct CancelPriceOrder {
19 /// Price-triggered order ID to cancel
20 pub order_id: String,
21 /// Request expiration time in milliseconds
22 pub x_gate_exp_time: Option<u128>,
23 /// API credentials for authentication
24 pub credentials: Option<Credentials>,
25}
26
27impl CancelPriceOrder {
28 /// Create a new cancel price order request
29 pub fn new(order_id: &str) -> Self {
30 Self {
31 order_id: order_id.to_owned(),
32 x_gate_exp_time: None,
33 credentials: None,
34 }
35 }
36
37 /// Specify the expiration time (milliseconds);
38 /// If the GATE receives the request time greater than the expiration time, the request will be rejected
39 pub fn x_gate_exp_time(mut self, x_gate_exp_time: u128) -> Self {
40 self.x_gate_exp_time = Some(x_gate_exp_time);
41 self
42 }
43
44 /// Set API credentials for authentication
45 pub fn credentials(mut self, creds: Credentials) -> Self {
46 self.credentials = Some(creds);
47 self
48 }
49}
50
51impl From<CancelPriceOrder> for Request {
52 fn from(request: CancelPriceOrder) -> Request {
53 let params = Vec::new();
54
55 Request {
56 method: Method::Delete,
57 path: format!("/api/v4/spot/price_orders/{}", request.order_id).into(),
58 params,
59 payload: "".to_string(),
60 x_gate_exp_time: request.x_gate_exp_time,
61 credentials: request.credentials,
62 sign: true,
63 }
64 }
65}