rust_okx/api/trade/requests/
advanced.rs1use std::borrow::Cow;
2
3use serde::Serialize;
4
5#[derive(Debug, Clone, Serialize)]
7pub struct EasyConvertRequest<'a> {
8 #[serde(rename = "fromCcy")]
9 from_ccy: Vec<Cow<'a, str>>,
10 #[serde(rename = "toCcy")]
11 to_ccy: Cow<'a, str>,
12 #[serde(skip_serializing_if = "Option::is_none")]
13 source: Option<Cow<'a, str>>,
14}
15
16impl<'a> EasyConvertRequest<'a> {
17 pub fn new<I, S>(from_ccy: I, to_ccy: impl Into<Cow<'a, str>>) -> Self
19 where
20 I: IntoIterator<Item = S>,
21 S: Into<Cow<'a, str>>,
22 {
23 Self {
24 from_ccy: from_ccy.into_iter().map(Into::into).collect(),
25 to_ccy: to_ccy.into(),
26 source: None,
27 }
28 }
29
30 pub fn source(mut self, value: impl Into<Cow<'a, str>>) -> Self {
32 self.source = Some(value.into());
33 self
34 }
35}
36
37#[derive(Debug, Clone, Default, Serialize)]
39pub struct EasyConvertHistoryRequest<'a> {
40 #[serde(skip_serializing_if = "Option::is_none")]
41 after: Option<Cow<'a, str>>,
42 #[serde(skip_serializing_if = "Option::is_none")]
43 before: Option<Cow<'a, str>>,
44 #[serde(skip_serializing_if = "Option::is_none")]
45 limit: Option<u32>,
46}
47
48impl<'a> EasyConvertHistoryRequest<'a> {
49 pub fn new() -> Self {
51 Self::default()
52 }
53
54 pub fn after(mut self, value: impl Into<Cow<'a, str>>) -> Self {
56 self.after = Some(value.into());
57 self
58 }
59
60 pub fn before(mut self, value: impl Into<Cow<'a, str>>) -> Self {
62 self.before = Some(value.into());
63 self
64 }
65
66 pub fn limit(mut self, value: u32) -> Self {
68 self.limit = Some(value);
69 self
70 }
71}
72
73#[derive(Debug, Clone, Default, Serialize)]
75pub struct OneClickRepayCurrencyListRequest<'a> {
76 #[serde(rename = "debtType", skip_serializing_if = "Option::is_none")]
77 debt_type: Option<Cow<'a, str>>,
78}
79
80impl<'a> OneClickRepayCurrencyListRequest<'a> {
81 pub fn new() -> Self {
83 Self::default()
84 }
85
86 pub fn debt_type(mut self, value: impl Into<Cow<'a, str>>) -> Self {
88 self.debt_type = Some(value.into());
89 self
90 }
91}
92
93#[derive(Debug, Clone, Serialize)]
95#[serde(untagged)]
96enum DebtCurrencySelection<'a> {
97 One(Cow<'a, str>),
98 Many(Vec<Cow<'a, str>>),
99}
100
101#[derive(Debug, Clone, Serialize)]
103pub struct OneClickRepayRequest<'a> {
104 #[serde(rename = "debtCcy")]
105 debt_ccy: DebtCurrencySelection<'a>,
106 #[serde(rename = "repayCcy", skip_serializing_if = "Option::is_none")]
107 repay_ccy: Option<Cow<'a, str>>,
108 #[serde(rename = "repayCcyList", skip_serializing_if = "Option::is_none")]
109 repay_ccy_list: Option<Vec<Cow<'a, str>>>,
110}
111
112impl<'a> OneClickRepayRequest<'a> {
113 pub fn new<I, S>(debt_ccy: I, repay_ccy: impl Into<Cow<'a, str>>) -> Self
115 where
116 I: IntoIterator<Item = S>,
117 S: Into<Cow<'a, str>>,
118 {
119 Self {
120 debt_ccy: DebtCurrencySelection::Many(debt_ccy.into_iter().map(Into::into).collect()),
121 repay_ccy: Some(repay_ccy.into()),
122 repay_ccy_list: None,
123 }
124 }
125
126 pub fn v2<I, S>(debt_ccy: impl Into<Cow<'a, str>>, repay_ccy_list: I) -> Self
128 where
129 I: IntoIterator<Item = S>,
130 S: Into<Cow<'a, str>>,
131 {
132 Self {
133 debt_ccy: DebtCurrencySelection::One(debt_ccy.into()),
134 repay_ccy: None,
135 repay_ccy_list: Some(repay_ccy_list.into_iter().map(Into::into).collect()),
136 }
137 }
138}
139
140#[derive(Debug, Clone, Default, Serialize)]
142pub struct OneClickRepayHistoryRequest<'a> {
143 #[serde(skip_serializing_if = "Option::is_none")]
144 after: Option<Cow<'a, str>>,
145 #[serde(skip_serializing_if = "Option::is_none")]
146 before: Option<Cow<'a, str>>,
147 #[serde(skip_serializing_if = "Option::is_none")]
148 limit: Option<u32>,
149}
150
151impl<'a> OneClickRepayHistoryRequest<'a> {
152 pub fn new() -> Self {
154 Self::default()
155 }
156
157 pub fn after(mut self, value: impl Into<Cow<'a, str>>) -> Self {
159 self.after = Some(value.into());
160 self
161 }
162
163 pub fn before(mut self, value: impl Into<Cow<'a, str>>) -> Self {
165 self.before = Some(value.into());
166 self
167 }
168
169 pub fn limit(mut self, value: u32) -> Self {
171 self.limit = Some(value);
172 self
173 }
174}