rust_okx/api/account/requests/
borrowing.rs1use std::borrow::Cow;
2
3use serde::Serialize;
4
5use crate::model::TradeMode;
6
7#[derive(Debug, Clone, Serialize)]
9pub struct MaxLoanRequest<'a> {
10 #[serde(rename = "instId", skip_serializing_if = "Option::is_none")]
11 inst_id: Option<Cow<'a, str>>,
12 #[serde(skip_serializing_if = "Option::is_none")]
13 ccy: Option<Cow<'a, str>>,
14 #[serde(rename = "mgnMode")]
15 mgn_mode: TradeMode,
16 #[serde(rename = "mgnCcy", skip_serializing_if = "Option::is_none")]
17 mgn_ccy: Option<Cow<'a, str>>,
18 #[serde(rename = "tradeQuoteCcy", skip_serializing_if = "Option::is_none")]
19 trade_quote_ccy: Option<Cow<'a, str>>,
20}
21
22impl<'a> MaxLoanRequest<'a> {
23 pub fn new(inst_id: impl Into<Cow<'a, str>>, mgn_mode: TradeMode) -> Self {
29 Self::by_instrument(inst_id, mgn_mode)
30 }
31
32 pub fn by_instrument(inst_id: impl Into<Cow<'a, str>>, mgn_mode: TradeMode) -> Self {
34 Self {
35 mgn_mode,
36 inst_id: Some(inst_id.into()),
37 ccy: None,
38 mgn_ccy: None,
39 trade_quote_ccy: None,
40 }
41 }
42
43 pub fn by_currency(ccy: impl Into<Cow<'a, str>>) -> Self {
45 Self {
46 mgn_mode: TradeMode::Cross,
47 inst_id: None,
48 ccy: Some(ccy.into()),
49 mgn_ccy: None,
50 trade_quote_ccy: None,
51 }
52 }
53
54 pub fn currency(mut self, ccy: impl Into<Cow<'a, str>>) -> Self {
56 self.inst_id = None;
57 self.ccy = Some(ccy.into());
58 self
59 }
60
61 pub fn margin_currency(mut self, mgn_ccy: impl Into<Cow<'a, str>>) -> Self {
63 self.mgn_ccy = Some(mgn_ccy.into());
64 self
65 }
66
67 pub fn trade_quote_currency(mut self, trade_quote_ccy: impl Into<Cow<'a, str>>) -> Self {
69 self.trade_quote_ccy = Some(trade_quote_ccy.into());
70 self
71 }
72}
73
74#[derive(Debug, Clone, Default, Serialize)]
76pub struct InterestAccruedRequest<'a> {
77 #[serde(rename = "instId", skip_serializing_if = "Option::is_none")]
78 inst_id: Option<Cow<'a, str>>,
79 #[serde(skip_serializing_if = "Option::is_none")]
80 ccy: Option<Cow<'a, str>>,
81 #[serde(rename = "mgnMode", skip_serializing_if = "Option::is_none")]
82 mgn_mode: Option<TradeMode>,
83 #[serde(skip_serializing_if = "Option::is_none")]
84 after: Option<Cow<'a, str>>,
85 #[serde(skip_serializing_if = "Option::is_none")]
86 before: Option<Cow<'a, str>>,
87 #[serde(skip_serializing_if = "Option::is_none")]
88 limit: Option<u32>,
89}
90
91impl<'a> InterestAccruedRequest<'a> {
92 pub fn new() -> Self {
94 Self::default()
95 }
96
97 pub fn inst_id(mut self, inst_id: impl Into<Cow<'a, str>>) -> Self {
99 self.inst_id = Some(inst_id.into());
100 self
101 }
102
103 pub fn currency(mut self, ccy: impl Into<Cow<'a, str>>) -> Self {
105 self.ccy = Some(ccy.into());
106 self
107 }
108
109 pub fn margin_mode(mut self, mgn_mode: TradeMode) -> Self {
111 self.mgn_mode = Some(mgn_mode);
112 self
113 }
114
115 pub fn after(mut self, after: impl Into<Cow<'a, str>>) -> Self {
117 self.after = Some(after.into());
118 self
119 }
120
121 pub fn before(mut self, before: impl Into<Cow<'a, str>>) -> Self {
123 self.before = Some(before.into());
124 self
125 }
126
127 pub fn limit(mut self, limit: u32) -> Self {
129 self.limit = Some(limit);
130 self
131 }
132}
133
134#[derive(Debug, Clone, Serialize)]
136pub struct BorrowRepayRequest<'a> {
137 ccy: Cow<'a, str>,
138 side: Cow<'a, str>,
139 amt: Cow<'a, str>,
140 #[serde(rename = "ordId", skip_serializing_if = "Option::is_none")]
141 ord_id: Option<Cow<'a, str>>,
142}
143
144impl<'a> BorrowRepayRequest<'a> {
145 pub fn new(
147 ccy: impl Into<Cow<'a, str>>,
148 side: impl Into<Cow<'a, str>>,
149 amt: impl Into<Cow<'a, str>>,
150 ) -> Self {
151 Self {
152 ccy: ccy.into(),
153 side: side.into(),
154 amt: amt.into(),
155 ord_id: None,
156 }
157 }
158
159 pub fn order_id(mut self, ord_id: impl Into<Cow<'a, str>>) -> Self {
161 self.ord_id = Some(ord_id.into());
162 self
163 }
164}
165
166#[derive(Debug, Clone, Default, Serialize)]
168pub struct BorrowRepayHistoryRequest<'a> {
169 #[serde(skip_serializing_if = "Option::is_none")]
170 ccy: Option<Cow<'a, str>>,
171 #[serde(skip_serializing_if = "Option::is_none")]
172 after: Option<Cow<'a, str>>,
173 #[serde(skip_serializing_if = "Option::is_none")]
174 before: Option<Cow<'a, str>>,
175 #[serde(skip_serializing_if = "Option::is_none")]
176 limit: Option<u32>,
177}
178
179impl<'a> BorrowRepayHistoryRequest<'a> {
180 pub fn new() -> Self {
182 Self::default()
183 }
184
185 pub fn currency(mut self, ccy: impl Into<Cow<'a, str>>) -> Self {
187 self.ccy = Some(ccy.into());
188 self
189 }
190
191 pub fn after(mut self, after: impl Into<Cow<'a, str>>) -> Self {
193 self.after = Some(after.into());
194 self
195 }
196
197 pub fn before(mut self, before: impl Into<Cow<'a, str>>) -> Self {
199 self.before = Some(before.into());
200 self
201 }
202
203 pub fn limit(mut self, limit: u32) -> Self {
205 self.limit = Some(limit);
206 self
207 }
208}
209
210#[derive(Debug, Clone, Default, Serialize)]
212pub struct InterestLimitsRequest<'a> {
213 #[serde(rename = "type", skip_serializing_if = "Option::is_none")]
214 limit_type: Option<Cow<'a, str>>,
215 #[serde(skip_serializing_if = "Option::is_none")]
216 ccy: Option<Cow<'a, str>>,
217}
218
219impl<'a> InterestLimitsRequest<'a> {
220 pub fn new() -> Self {
222 Self::default()
223 }
224
225 pub fn limit_type(mut self, limit_type: impl Into<Cow<'a, str>>) -> Self {
227 self.limit_type = Some(limit_type.into());
228 self
229 }
230
231 pub fn currency(mut self, ccy: impl Into<Cow<'a, str>>) -> Self {
233 self.ccy = Some(ccy.into());
234 self
235 }
236}