Skip to main content

gateio_rs/api/spot/
amend_batch_orders.rs

1use crate::http::{Credentials, Method, request::Request};
2use serde::Serialize;
3
4/// Single order amendment parameters
5#[derive(Debug, Clone, Serialize)]
6pub struct OrderAmendment {
7    /// Order ID to amend
8    pub order_id: String,
9    /// Trading pair
10    pub currency_pair: String,
11    /// Account type
12    #[serde(skip_serializing_if = "Option::is_none")]
13    pub account: Option<String>,
14    /// Order amount
15    #[serde(skip_serializing_if = "Option::is_none")]
16    pub amount: Option<String>,
17    /// Order price
18    #[serde(skip_serializing_if = "Option::is_none")]
19    pub price: Option<String>,
20    /// Custom amendment text
21    #[serde(skip_serializing_if = "Option::is_none")]
22    pub amend_text: Option<String>,
23}
24
25impl OrderAmendment {
26    /// Create new order amendment
27    pub fn new(order_id: &str, currency_pair: &str) -> Self {
28        Self {
29            order_id: order_id.to_owned(),
30            currency_pair: currency_pair.to_owned(),
31            account: None,
32            amount: None,
33            price: None,
34            amend_text: None,
35        }
36    }
37
38    /// Set account type
39    pub fn account(mut self, account: &str) -> Self {
40        self.account = Some(account.to_owned());
41        self
42    }
43
44    /// Set order amount
45    pub fn amount(mut self, amount: &str) -> Self {
46        self.amount = Some(amount.to_owned());
47        self
48    }
49
50    /// Set order price
51    pub fn price(mut self, price: &str) -> Self {
52        self.price = Some(price.to_owned());
53        self
54    }
55
56    /// Set amendment text
57    pub fn amend_text(mut self, amend_text: &str) -> Self {
58        self.amend_text = Some(amend_text.to_owned());
59        self
60    }
61}
62
63/// Batch order amendment request
64pub struct AmendBatchOrders {
65    /// Orders to amend
66    pub orders: Vec<OrderAmendment>,
67    /// Request expiration time
68    pub x_gate_exp_time: Option<u128>,
69    /// API credentials
70    pub credentials: Option<Credentials>,
71}
72
73impl AmendBatchOrders {
74    /// Create batch amendment request
75    pub fn new(orders: Vec<OrderAmendment>) -> Self {
76        Self {
77            orders,
78            x_gate_exp_time: None,
79            credentials: None,
80        }
81    }
82
83    /// Set expiration time
84    pub fn x_gate_exp_time(mut self, x_gate_exp_time: u128) -> Self {
85        self.x_gate_exp_time = Some(x_gate_exp_time);
86        self
87    }
88
89    /// Set API credentials
90    pub fn credentials(mut self, creds: Credentials) -> Self {
91        self.credentials = Some(creds);
92        self
93    }
94}
95
96impl From<AmendBatchOrders> for Request {
97    fn from(request: AmendBatchOrders) -> Request {
98        let params = Vec::new();
99        let payload = serde_json::to_string(&request.orders).unwrap();
100
101        Request {
102            method: Method::Post,
103            path: "/api/v4/spot/amend_batch_orders".into(),
104            params,
105            payload,
106            x_gate_exp_time: request.x_gate_exp_time,
107            credentials: request.credentials,
108            sign: true,
109        }
110    }
111}