1use std::borrow::Cow;
2
3use serde::Serialize;
4
5use crate::model::{InstType, PositionSide, TradeMode};
6
7#[derive(Debug, Clone, Serialize)]
9pub struct SetLeverageRequest<'a> {
10 lever: Cow<'a, str>,
11 #[serde(rename = "mgnMode")]
12 mgn_mode: TradeMode,
13 #[serde(rename = "instId", skip_serializing_if = "Option::is_none")]
14 inst_id: Option<Cow<'a, str>>,
15 #[serde(skip_serializing_if = "Option::is_none")]
16 ccy: Option<Cow<'a, str>>,
17 #[serde(rename = "posSide", skip_serializing_if = "Option::is_none")]
18 pos_side: Option<PositionSide>,
19}
20
21impl<'a> SetLeverageRequest<'a> {
22 pub fn new(lever: impl Into<Cow<'a, str>>, mgn_mode: TradeMode) -> Self {
24 Self {
25 lever: lever.into(),
26 mgn_mode,
27 inst_id: None,
28 ccy: None,
29 pos_side: None,
30 }
31 }
32
33 pub fn inst_id(mut self, inst_id: impl Into<Cow<'a, str>>) -> Self {
35 self.inst_id = Some(inst_id.into());
36 self
37 }
38
39 pub fn currency(mut self, ccy: impl Into<Cow<'a, str>>) -> Self {
41 self.ccy = Some(ccy.into());
42 self
43 }
44
45 pub fn position_side(mut self, pos_side: PositionSide) -> Self {
47 self.pos_side = Some(pos_side);
48 self
49 }
50}
51
52#[derive(Debug, Clone, Serialize)]
54pub struct LeverageRequest<'a> {
55 #[serde(rename = "mgnMode")]
56 mgn_mode: TradeMode,
57 #[serde(rename = "instId", skip_serializing_if = "Option::is_none")]
58 inst_id: Option<Cow<'a, str>>,
59 #[serde(skip_serializing_if = "Option::is_none")]
60 ccy: Option<Cow<'a, str>>,
61}
62
63impl<'a> LeverageRequest<'a> {
64 pub fn new(mgn_mode: TradeMode) -> Self {
66 Self {
67 mgn_mode,
68 inst_id: None,
69 ccy: None,
70 }
71 }
72
73 pub fn inst_id(mut self, inst_id: impl Into<Cow<'a, str>>) -> Self {
75 self.inst_id = Some(inst_id.into());
76 self
77 }
78
79 pub fn currency(mut self, ccy: impl Into<Cow<'a, str>>) -> Self {
81 self.ccy = Some(ccy.into());
82 self
83 }
84}
85
86#[derive(Debug, Clone, Serialize)]
88pub struct MaxOrderSizeRequest<'a> {
89 #[serde(rename = "instId")]
90 inst_id: Cow<'a, str>,
91 #[serde(rename = "tdMode")]
92 td_mode: TradeMode,
93 #[serde(skip_serializing_if = "Option::is_none")]
94 ccy: Option<Cow<'a, str>>,
95 #[serde(skip_serializing_if = "Option::is_none")]
96 px: Option<Cow<'a, str>>,
97 #[serde(rename = "tradeQuoteCcy", skip_serializing_if = "Option::is_none")]
98 trade_quote_ccy: Option<Cow<'a, str>>,
99}
100
101impl<'a> MaxOrderSizeRequest<'a> {
102 pub fn new(inst_id: impl Into<Cow<'a, str>>, td_mode: TradeMode) -> Self {
104 Self {
105 inst_id: inst_id.into(),
106 td_mode,
107 ccy: None,
108 px: None,
109 trade_quote_ccy: None,
110 }
111 }
112
113 pub fn currency(mut self, ccy: impl Into<Cow<'a, str>>) -> Self {
115 self.ccy = Some(ccy.into());
116 self
117 }
118
119 pub fn price(mut self, px: impl Into<Cow<'a, str>>) -> Self {
121 self.px = Some(px.into());
122 self
123 }
124
125 pub fn trade_quote_currency(mut self, trade_quote_ccy: impl Into<Cow<'a, str>>) -> Self {
127 self.trade_quote_ccy = Some(trade_quote_ccy.into());
128 self
129 }
130}
131
132#[derive(Debug, Clone, Serialize)]
134pub struct MaxAvailableSizeRequest<'a> {
135 #[serde(rename = "instId")]
136 inst_id: Cow<'a, str>,
137 #[serde(rename = "tdMode")]
138 td_mode: TradeMode,
139 #[serde(skip_serializing_if = "Option::is_none")]
140 ccy: Option<Cow<'a, str>>,
141 #[serde(rename = "reduceOnly", skip_serializing_if = "Option::is_none")]
142 reduce_only: Option<bool>,
143 #[serde(rename = "unSpotOffset", skip_serializing_if = "Option::is_none")]
144 un_spot_offset: Option<bool>,
145 #[serde(rename = "quickMgnType", skip_serializing_if = "Option::is_none")]
146 quick_mgn_type: Option<Cow<'a, str>>,
147 #[serde(rename = "tradeQuoteCcy", skip_serializing_if = "Option::is_none")]
148 trade_quote_ccy: Option<Cow<'a, str>>,
149}
150
151impl<'a> MaxAvailableSizeRequest<'a> {
152 pub fn new(inst_id: impl Into<Cow<'a, str>>, td_mode: TradeMode) -> Self {
154 Self {
155 inst_id: inst_id.into(),
156 td_mode,
157 ccy: None,
158 reduce_only: None,
159 un_spot_offset: None,
160 quick_mgn_type: None,
161 trade_quote_ccy: None,
162 }
163 }
164
165 pub fn currency(mut self, ccy: impl Into<Cow<'a, str>>) -> Self {
167 self.ccy = Some(ccy.into());
168 self
169 }
170
171 pub fn reduce_only(mut self, reduce_only: bool) -> Self {
173 self.reduce_only = Some(reduce_only);
174 self
175 }
176
177 pub fn un_spot_offset(mut self, un_spot_offset: bool) -> Self {
179 self.un_spot_offset = Some(un_spot_offset);
180 self
181 }
182
183 pub fn quick_margin_type(mut self, quick_mgn_type: impl Into<Cow<'a, str>>) -> Self {
185 self.quick_mgn_type = Some(quick_mgn_type.into());
186 self
187 }
188
189 pub fn trade_quote_currency(mut self, trade_quote_ccy: impl Into<Cow<'a, str>>) -> Self {
191 self.trade_quote_ccy = Some(trade_quote_ccy.into());
192 self
193 }
194}
195
196#[derive(Debug, Clone, Serialize)]
198pub struct AdjustMarginRequest<'a> {
199 #[serde(rename = "instId")]
200 inst_id: Cow<'a, str>,
201 #[serde(rename = "posSide")]
202 pos_side: PositionSide,
203 #[serde(rename = "type")]
204 action: Cow<'a, str>,
205 amt: Cow<'a, str>,
206 #[serde(rename = "loanTrans", skip_serializing_if = "Option::is_none")]
207 loan_trans: Option<bool>,
208}
209
210impl<'a> AdjustMarginRequest<'a> {
211 pub fn new(
213 inst_id: impl Into<Cow<'a, str>>,
214 pos_side: PositionSide,
215 action: impl Into<Cow<'a, str>>,
216 amt: impl Into<Cow<'a, str>>,
217 ) -> Self {
218 Self {
219 inst_id: inst_id.into(),
220 pos_side,
221 action: action.into(),
222 amt: amt.into(),
223 loan_trans: None,
224 }
225 }
226
227 pub fn loan_transfer(mut self, loan_trans: bool) -> Self {
229 self.loan_trans = Some(loan_trans);
230 self
231 }
232}
233
234#[derive(Debug, Clone, Serialize)]
236pub struct FeeRatesRequest<'a> {
237 #[serde(rename = "instType")]
238 inst_type: InstType,
239 #[serde(rename = "instId", skip_serializing_if = "Option::is_none")]
240 inst_id: Option<Cow<'a, str>>,
241 #[serde(rename = "uly", skip_serializing_if = "Option::is_none")]
242 underlying: Option<Cow<'a, str>>,
243 #[serde(skip_serializing_if = "Option::is_none")]
244 category: Option<Cow<'a, str>>,
245 #[serde(rename = "instFamily", skip_serializing_if = "Option::is_none")]
246 inst_family: Option<Cow<'a, str>>,
247}
248
249impl<'a> FeeRatesRequest<'a> {
250 pub fn new(inst_type: InstType) -> Self {
252 Self {
253 inst_type,
254 inst_id: None,
255 underlying: None,
256 category: None,
257 inst_family: None,
258 }
259 }
260
261 pub fn inst_id(mut self, inst_id: impl Into<Cow<'a, str>>) -> Self {
263 self.inst_id = Some(inst_id.into());
264 self
265 }
266
267 pub fn underlying(mut self, underlying: impl Into<Cow<'a, str>>) -> Self {
269 self.underlying = Some(underlying.into());
270 self
271 }
272
273 pub fn category(mut self, category: impl Into<Cow<'a, str>>) -> Self {
275 self.category = Some(category.into());
276 self
277 }
278
279 pub fn inst_family(mut self, inst_family: impl Into<Cow<'a, str>>) -> Self {
281 self.inst_family = Some(inst_family.into());
282 self
283 }
284}
285
286#[derive(Debug, Clone, Serialize)]
288pub struct AccountInstrumentsRequest<'a> {
289 #[serde(rename = "instType")]
290 inst_type: InstType,
291 #[serde(rename = "seriesId", skip_serializing_if = "Option::is_none")]
292 series_id: Option<Cow<'a, str>>,
293 #[serde(rename = "instFamily", skip_serializing_if = "Option::is_none")]
294 inst_family: Option<Cow<'a, str>>,
295 #[serde(rename = "instId", skip_serializing_if = "Option::is_none")]
296 inst_id: Option<Cow<'a, str>>,
297}
298
299impl<'a> AccountInstrumentsRequest<'a> {
300 pub fn new(inst_type: InstType) -> Self {
302 Self {
303 inst_type,
304 series_id: None,
305 inst_family: None,
306 inst_id: None,
307 }
308 }
309
310 pub fn series_id(mut self, series_id: impl Into<Cow<'a, str>>) -> Self {
312 self.series_id = Some(series_id.into());
313 self
314 }
315
316 pub fn inst_family(mut self, inst_family: impl Into<Cow<'a, str>>) -> Self {
318 self.inst_family = Some(inst_family.into());
319 self
320 }
321
322 pub fn inst_id(mut self, inst_id: impl Into<Cow<'a, str>>) -> Self {
324 self.inst_id = Some(inst_id.into());
325 self
326 }
327}