1use std::borrow::Cow;
2
3use serde::Serialize;
4
5use crate::model::InstType;
6
7#[derive(Debug, Clone, Serialize)]
9pub struct InstrumentsRequest<'a> {
10 #[serde(rename = "instType")]
11 inst_type: InstType,
12 #[serde(rename = "instFamily", skip_serializing_if = "Option::is_none")]
13 inst_family: Option<Cow<'a, str>>,
14}
15
16impl<'a> InstrumentsRequest<'a> {
17 pub fn new(inst_type: InstType) -> Self {
19 Self {
20 inst_type,
21 inst_family: None,
22 }
23 }
24
25 pub fn inst_family(mut self, inst_family: impl Into<Cow<'a, str>>) -> Self {
27 self.inst_family = Some(inst_family.into());
28 self
29 }
30}
31
32#[derive(Debug, Clone, Serialize)]
36pub struct InstIdRequest<'a> {
37 #[serde(rename = "instId")]
38 inst_id: Cow<'a, str>,
39}
40
41impl<'a> InstIdRequest<'a> {
42 pub fn new(inst_id: impl Into<Cow<'a, str>>) -> Self {
44 Self {
45 inst_id: inst_id.into(),
46 }
47 }
48}
49
50#[derive(Debug, Clone, Default, Serialize)]
52pub struct CurrencyRequest<'a> {
53 #[serde(skip_serializing_if = "Option::is_none")]
54 ccy: Option<Cow<'a, str>>,
55}
56
57impl<'a> CurrencyRequest<'a> {
58 pub fn new() -> Self {
60 Self::default()
61 }
62
63 pub fn currency(mut self, ccy: impl Into<Cow<'a, str>>) -> Self {
65 self.ccy = Some(ccy.into());
66 self
67 }
68}
69
70mod edge;
71
72pub use edge::*;
73
74#[derive(Debug, Clone, Serialize)]
76pub struct InstrumentFamilyRequest<'a> {
77 #[serde(rename = "instType")]
78 inst_type: InstType,
79 #[serde(rename = "uly", skip_serializing_if = "Option::is_none")]
80 underlying: Option<Cow<'a, str>>,
81 #[serde(rename = "instId", skip_serializing_if = "Option::is_none")]
82 inst_id: Option<Cow<'a, str>>,
83 #[serde(rename = "instFamily", skip_serializing_if = "Option::is_none")]
84 inst_family: Option<Cow<'a, str>>,
85}
86
87impl<'a> InstrumentFamilyRequest<'a> {
88 pub fn new(inst_type: InstType) -> Self {
90 Self {
91 inst_type,
92 underlying: None,
93 inst_id: None,
94 inst_family: None,
95 }
96 }
97
98 pub fn underlying(mut self, underlying: impl Into<Cow<'a, str>>) -> Self {
100 self.underlying = Some(underlying.into());
101 self
102 }
103
104 pub fn inst_id(mut self, inst_id: impl Into<Cow<'a, str>>) -> Self {
106 self.inst_id = Some(inst_id.into());
107 self
108 }
109
110 pub fn inst_family(mut self, inst_family: impl Into<Cow<'a, str>>) -> Self {
112 self.inst_family = Some(inst_family.into());
113 self
114 }
115}
116
117#[derive(Debug, Clone, Serialize)]
119pub struct FundingRateHistoryRequest<'a> {
120 #[serde(rename = "instId")]
121 inst_id: Cow<'a, str>,
122 #[serde(skip_serializing_if = "Option::is_none")]
123 after: Option<Cow<'a, str>>,
124 #[serde(skip_serializing_if = "Option::is_none")]
125 before: Option<Cow<'a, str>>,
126 #[serde(skip_serializing_if = "Option::is_none")]
127 limit: Option<u32>,
128}
129
130impl<'a> FundingRateHistoryRequest<'a> {
131 pub fn new(inst_id: impl Into<Cow<'a, str>>) -> Self {
133 Self {
134 inst_id: inst_id.into(),
135 after: None,
136 before: None,
137 limit: None,
138 }
139 }
140
141 pub fn after(mut self, after: impl Into<Cow<'a, str>>) -> Self {
143 self.after = Some(after.into());
144 self
145 }
146
147 pub fn before(mut self, before: impl Into<Cow<'a, str>>) -> Self {
149 self.before = Some(before.into());
150 self
151 }
152
153 pub fn limit(mut self, limit: u32) -> Self {
155 self.limit = Some(limit);
156 self
157 }
158}
159
160#[derive(Debug, Clone, Serialize)]
162pub struct DeliveryExerciseHistoryRequest<'a> {
163 #[serde(rename = "instType")]
164 inst_type: InstType,
165 #[serde(rename = "uly", skip_serializing_if = "Option::is_none")]
166 underlying: Option<Cow<'a, str>>,
167 #[serde(rename = "instFamily", skip_serializing_if = "Option::is_none")]
168 inst_family: Option<Cow<'a, str>>,
169 #[serde(skip_serializing_if = "Option::is_none")]
170 after: Option<Cow<'a, str>>,
171 #[serde(skip_serializing_if = "Option::is_none")]
172 before: Option<Cow<'a, str>>,
173 #[serde(skip_serializing_if = "Option::is_none")]
174 limit: Option<u32>,
175}
176
177impl<'a> DeliveryExerciseHistoryRequest<'a> {
178 pub fn new(inst_type: InstType) -> Self {
180 Self {
181 inst_type,
182 underlying: None,
183 inst_family: None,
184 after: None,
185 before: None,
186 limit: None,
187 }
188 }
189
190 pub fn underlying(mut self, underlying: impl Into<Cow<'a, str>>) -> Self {
192 self.underlying = Some(underlying.into());
193 self
194 }
195
196 pub fn inst_family(mut self, inst_family: impl Into<Cow<'a, str>>) -> Self {
198 self.inst_family = Some(inst_family.into());
199 self
200 }
201
202 pub fn after(mut self, after: impl Into<Cow<'a, str>>) -> Self {
204 self.after = Some(after.into());
205 self
206 }
207
208 pub fn before(mut self, before: impl Into<Cow<'a, str>>) -> Self {
210 self.before = Some(before.into());
211 self
212 }
213
214 pub fn limit(mut self, limit: u32) -> Self {
216 self.limit = Some(limit);
217 self
218 }
219}
220
221#[derive(Debug, Clone, Serialize)]
223pub struct PositionTiersRequest<'a> {
224 #[serde(rename = "instType")]
225 inst_type: InstType,
226 #[serde(rename = "tdMode")]
227 td_mode: Cow<'a, str>,
228 #[serde(rename = "uly", skip_serializing_if = "Option::is_none")]
229 underlying: Option<Cow<'a, str>>,
230 #[serde(rename = "instId", skip_serializing_if = "Option::is_none")]
231 inst_id: Option<Cow<'a, str>>,
232 #[serde(skip_serializing_if = "Option::is_none")]
233 ccy: Option<Cow<'a, str>>,
234 #[serde(skip_serializing_if = "Option::is_none")]
235 tier: Option<Cow<'a, str>>,
236 #[serde(rename = "instFamily", skip_serializing_if = "Option::is_none")]
237 inst_family: Option<Cow<'a, str>>,
238}
239
240impl<'a> PositionTiersRequest<'a> {
241 pub fn new(inst_type: InstType, td_mode: impl Into<Cow<'a, str>>) -> Self {
243 Self {
244 inst_type,
245 td_mode: td_mode.into(),
246 underlying: None,
247 inst_id: None,
248 ccy: None,
249 tier: None,
250 inst_family: None,
251 }
252 }
253
254 pub fn underlying(mut self, underlying: impl Into<Cow<'a, str>>) -> Self {
256 self.underlying = Some(underlying.into());
257 self
258 }
259
260 pub fn inst_id(mut self, inst_id: impl Into<Cow<'a, str>>) -> Self {
262 self.inst_id = Some(inst_id.into());
263 self
264 }
265
266 pub fn currency(mut self, ccy: impl Into<Cow<'a, str>>) -> Self {
268 self.ccy = Some(ccy.into());
269 self
270 }
271
272 pub fn tier(mut self, tier: impl Into<Cow<'a, str>>) -> Self {
274 self.tier = Some(tier.into());
275 self
276 }
277
278 pub fn inst_family(mut self, inst_family: impl Into<Cow<'a, str>>) -> Self {
280 self.inst_family = Some(inst_family.into());
281 self
282 }
283}
284
285#[derive(Debug, Clone, Serialize)]
287pub struct InsuranceFundRequest<'a> {
288 #[serde(rename = "instType")]
289 inst_type: InstType,
290 #[serde(rename = "type", skip_serializing_if = "Option::is_none")]
291 fund_type: Option<Cow<'a, str>>,
292 #[serde(rename = "uly", skip_serializing_if = "Option::is_none")]
293 underlying: Option<Cow<'a, str>>,
294 #[serde(skip_serializing_if = "Option::is_none")]
295 ccy: Option<Cow<'a, str>>,
296 #[serde(skip_serializing_if = "Option::is_none")]
297 before: Option<Cow<'a, str>>,
298 #[serde(skip_serializing_if = "Option::is_none")]
299 after: Option<Cow<'a, str>>,
300 #[serde(skip_serializing_if = "Option::is_none")]
301 limit: Option<u32>,
302 #[serde(rename = "instFamily", skip_serializing_if = "Option::is_none")]
303 inst_family: Option<Cow<'a, str>>,
304}
305
306impl<'a> InsuranceFundRequest<'a> {
307 pub fn new(inst_type: InstType) -> Self {
309 Self {
310 inst_type,
311 fund_type: None,
312 underlying: None,
313 ccy: None,
314 before: None,
315 after: None,
316 limit: None,
317 inst_family: None,
318 }
319 }
320
321 pub fn fund_type(mut self, fund_type: impl Into<Cow<'a, str>>) -> Self {
323 self.fund_type = Some(fund_type.into());
324 self
325 }
326
327 pub fn underlying(mut self, underlying: impl Into<Cow<'a, str>>) -> Self {
329 self.underlying = Some(underlying.into());
330 self
331 }
332
333 pub fn currency(mut self, ccy: impl Into<Cow<'a, str>>) -> Self {
335 self.ccy = Some(ccy.into());
336 self
337 }
338
339 pub fn before(mut self, before: impl Into<Cow<'a, str>>) -> Self {
341 self.before = Some(before.into());
342 self
343 }
344
345 pub fn after(mut self, after: impl Into<Cow<'a, str>>) -> Self {
347 self.after = Some(after.into());
348 self
349 }
350
351 pub fn limit(mut self, limit: u32) -> Self {
353 self.limit = Some(limit);
354 self
355 }
356
357 pub fn inst_family(mut self, inst_family: impl Into<Cow<'a, str>>) -> Self {
359 self.inst_family = Some(inst_family.into());
360 self
361 }
362}
363
364#[derive(Debug, Clone, Serialize)]
366pub struct ConvertContractCoinRequest<'a> {
367 #[serde(rename = "type")]
368 conversion_type: Cow<'a, str>,
369 #[serde(rename = "instId")]
370 inst_id: Cow<'a, str>,
371 sz: Cow<'a, str>,
372 #[serde(skip_serializing_if = "Option::is_none")]
373 px: Option<Cow<'a, str>>,
374 #[serde(skip_serializing_if = "Option::is_none")]
375 unit: Option<Cow<'a, str>>,
376}
377
378impl<'a> ConvertContractCoinRequest<'a> {
379 pub fn new(
381 conversion_type: impl Into<Cow<'a, str>>,
382 inst_id: impl Into<Cow<'a, str>>,
383 sz: impl Into<Cow<'a, str>>,
384 ) -> Self {
385 Self {
386 conversion_type: conversion_type.into(),
387 inst_id: inst_id.into(),
388 sz: sz.into(),
389 px: None,
390 unit: None,
391 }
392 }
393
394 pub fn price(mut self, px: impl Into<Cow<'a, str>>) -> Self {
396 self.px = Some(px.into());
397 self
398 }
399
400 pub fn unit(mut self, unit: impl Into<Cow<'a, str>>) -> Self {
402 self.unit = Some(unit.into());
403 self
404 }
405}