gateio_rs/api/spot/cancel_order.rs
1use crate::http::{Credentials, Method, request::Request};
2
3/// # Cancel a spot order
4///
5/// Cancel a specific spot order by order ID or custom text field.
6///
7/// ## Order ID
8/// The order ID returned when the order was successfully created or the custom ID
9/// specified by the user's creation (i.e. the text field).
10/// Operations based on custom IDs can only be checked in pending orders.
11/// Only order ID can be used after the order is finished (transaction/cancel)
12///
13/// ## Action Mode
14/// Processing Mode - When placing an order, different fields are returned based on the action_mode
15/// - ACK: Asynchronous mode, returns only key order fields
16/// - RESULT: No clearing information
17/// - FULL: Full mode (default)
18///
19/// [Gate API Documentation](https://www.gate.com/docs/developers/apiv4/#cancel-a-single-order)
20pub struct CancelOrder {
21 /// Order ID or custom text field
22 pub order_id: String,
23 /// Currency pair for the order
24 pub currency_pair: String,
25 /// Trading account type
26 pub account: Option<String>,
27 /// Processing mode for the response
28 pub action_mode: Option<String>,
29 /// Request expiration time in milliseconds
30 pub x_gate_exp_time: Option<u128>,
31 /// API credentials for authentication
32 pub credentials: Option<Credentials>,
33}
34
35impl CancelOrder {
36 /// Create a new cancel order request
37 pub fn new(order_id: &str, currency_pair: &str) -> Self {
38 Self {
39 order_id: order_id.to_owned(),
40 currency_pair: currency_pair.to_owned(),
41 account: None,
42 action_mode: None,
43 x_gate_exp_time: None,
44 credentials: None,
45 }
46 }
47
48 /// Set the trading account type
49 pub fn account(mut self, account: &str) -> Self {
50 self.account = Some(account.into());
51 self
52 }
53
54 /// Set the processing mode for the response
55 pub fn action_mode(mut self, action_mode: &str) -> Self {
56 self.action_mode = Some(action_mode.into());
57 self
58 }
59
60 /// Specify the expiration time (milliseconds);<br/>
61 /// If the GATE receives the request time greater than the expiration time, the request will be rejected
62 pub fn x_gate_exp_time(mut self, x_gate_exp_time: u128) -> Self {
63 self.x_gate_exp_time = Some(x_gate_exp_time.into());
64 self
65 }
66
67 /// Set API credentials for authentication
68 pub fn credentials(mut self, creds: Credentials) -> Self {
69 self.credentials = Some(creds);
70 self
71 }
72}
73
74impl From<CancelOrder> for Request {
75 fn from(request: CancelOrder) -> Request {
76 let mut params = vec![("currency_pair".to_owned(), request.currency_pair)];
77
78 if let Some(account) = request.account {
79 params.push(("account".into(), account.to_string()));
80 }
81
82 if let Some(action_mode) = request.action_mode {
83 params.push(("action_mode".into(), action_mode.to_string()));
84 }
85
86 Request {
87 method: Method::Delete,
88 path: format!("/api/v4/spot/orders/{}", request.order_id).into(),
89 params,
90 payload: "".to_string(),
91 x_gate_exp_time: request.x_gate_exp_time,
92 credentials: request.credentials,
93 sign: true,
94 }
95 }
96}