gateio_rs/api/spot/
amend_order.rs1use crate::http::{Credentials, Method, request::Request};
2use serde_json::{Map, Value, json};
3
4pub struct AmendOrder {
6 pub order_id: String,
8 pub currency_pair: String,
10 pub account: Option<String>,
12 pub amount: Option<String>,
14 pub price: Option<String>,
16 pub amend_text: Option<String>,
18 pub action_mode: Option<String>,
20 pub x_gate_exp_time: Option<u128>,
22 pub credentials: Option<Credentials>,
24}
25
26impl AmendOrder {
27 pub fn new(order_id: &str, currency_pair: &str) -> Self {
29 Self {
30 order_id: order_id.to_owned(),
31 currency_pair: currency_pair.to_owned(),
32 account: None,
33 amount: None,
34 price: None,
35 amend_text: None,
36 action_mode: None,
37 x_gate_exp_time: None,
38 credentials: None,
39 }
40 }
41
42 pub fn account(mut self, account: &str) -> Self {
44 self.account = Some(account.into());
45 self
46 }
47
48 pub fn amount(mut self, amount: &str) -> Self {
50 self.amount = Some(amount.into());
51 self
52 }
53
54 pub fn price(mut self, price: &str) -> Self {
56 self.price = Some(price.into());
57 self
58 }
59
60 pub fn amend_text(mut self, amend_text: &str) -> Self {
62 self.amend_text = Some(amend_text.into());
63 self
64 }
65
66 pub fn action_mode(mut self, action_mode: &str) -> Self {
68 self.action_mode = Some(action_mode.into());
69 self
70 }
71
72 pub fn x_gate_exp_time(mut self, x_gate_exp_time: u128) -> Self {
74 self.x_gate_exp_time = Some(x_gate_exp_time.into());
75 self
76 }
77
78 pub fn credentials(mut self, creds: Credentials) -> Self {
80 self.credentials = Some(creds);
81 self
82 }
83}
84
85impl From<AmendOrder> for Request {
86 fn from(request: AmendOrder) -> Request {
87 let params = Vec::new();
88 let mut payload = Map::new();
89
90 payload.insert("currency_pair".to_string(), json!(request.currency_pair));
91
92 if let Some(account) = request.account {
93 payload.insert("account".to_string(), json!(account));
94 }
95
96 if let Some(amount) = request.amount {
97 payload.insert("amount".to_string(), json!(amount));
98 }
99
100 if let Some(price) = request.price {
101 payload.insert("price".to_string(), json!(price));
102 }
103
104 if let Some(amend_text) = request.amend_text {
105 payload.insert("amend_text".to_string(), json!(amend_text));
106 }
107
108 if let Some(action_mode) = request.action_mode {
109 payload.insert("action_mode".to_string(), json!(action_mode));
110 }
111
112 let payload_json = Value::Object(payload);
113
114 Request {
115 method: Method::Patch,
116 path: format!("/api/v4/spot/orders/{}", request.order_id).into(),
117 params,
118 payload: payload_json.to_string(),
119 x_gate_exp_time: request.x_gate_exp_time,
120 credentials: request.credentials,
121 sign: true,
122 }
123 }
124}