Skip to main content

rust_okx/api/account/requests/
borrowing.rs

1use serde::Serialize;
2
3use crate::model::TradeMode;
4
5/// Query parameters for maximum loan.
6#[derive(Debug, Clone, Serialize)]
7pub struct MaxLoanRequest {
8    #[serde(rename = "instId", skip_serializing_if = "Option::is_none")]
9    inst_id: Option<String>,
10    #[serde(skip_serializing_if = "Option::is_none")]
11    ccy: Option<String>,
12    #[serde(rename = "mgnMode")]
13    mgn_mode: TradeMode,
14    #[serde(rename = "mgnCcy", skip_serializing_if = "Option::is_none")]
15    mgn_ccy: Option<String>,
16    #[serde(rename = "tradeQuoteCcy", skip_serializing_if = "Option::is_none")]
17    trade_quote_ccy: Option<String>,
18}
19
20impl MaxLoanRequest {
21    /// Create an instrument-based maximum-loan query.
22    ///
23    /// `inst_id` may contain one to five comma-separated instrument IDs, as
24    /// documented by OKX. Use [`Self::by_currency`] for Spot-mode manual-borrow
25    /// quota queries.
26    pub fn new(inst_id: impl Into<String>, mgn_mode: TradeMode) -> Self {
27        Self::by_instrument(inst_id, mgn_mode)
28    }
29
30    /// Create an instrument-based maximum-loan query.
31    pub fn by_instrument(inst_id: impl Into<String>, mgn_mode: TradeMode) -> Self {
32        Self {
33            mgn_mode,
34            inst_id: Some(inst_id.into()),
35            ccy: None,
36            mgn_ccy: None,
37            trade_quote_ccy: None,
38        }
39    }
40
41    /// Create a currency-based Spot-mode manual-borrow quota query.
42    pub fn by_currency(ccy: impl Into<String>) -> Self {
43        Self {
44            mgn_mode: TradeMode::Cross,
45            inst_id: None,
46            ccy: Some(ccy.into()),
47            mgn_ccy: None,
48            trade_quote_ccy: None,
49        }
50    }
51
52    /// Replace the selector with a currency-based Spot-mode query.
53    pub fn currency(mut self, ccy: impl Into<String>) -> Self {
54        self.inst_id = None;
55        self.ccy = Some(ccy.into());
56        self
57    }
58
59    /// Set the margin currency.
60    pub fn margin_currency(mut self, mgn_ccy: impl Into<String>) -> Self {
61        self.mgn_ccy = Some(mgn_ccy.into());
62        self
63    }
64
65    /// Set the trade quote currency.
66    pub fn trade_quote_currency(mut self, trade_quote_ccy: impl Into<String>) -> Self {
67        self.trade_quote_ccy = Some(trade_quote_ccy.into());
68        self
69    }
70}
71
72/// Query parameters for interest-accrued records.
73#[derive(Debug, Clone, Default, Serialize)]
74pub struct InterestAccruedRequest {
75    #[serde(rename = "instId", skip_serializing_if = "Option::is_none")]
76    inst_id: Option<String>,
77    #[serde(skip_serializing_if = "Option::is_none")]
78    ccy: Option<String>,
79    #[serde(rename = "mgnMode", skip_serializing_if = "Option::is_none")]
80    mgn_mode: Option<TradeMode>,
81    #[serde(skip_serializing_if = "Option::is_none")]
82    after: Option<String>,
83    #[serde(skip_serializing_if = "Option::is_none")]
84    before: Option<String>,
85    #[serde(skip_serializing_if = "Option::is_none")]
86    limit: Option<u32>,
87}
88
89impl InterestAccruedRequest {
90    /// Create an empty interest-accrued query.
91    pub fn new() -> Self {
92        Self::default()
93    }
94
95    /// Set the instrument ID filter.
96    pub fn inst_id(mut self, inst_id: impl Into<String>) -> Self {
97        self.inst_id = Some(inst_id.into());
98        self
99    }
100
101    /// Set the currency filter.
102    pub fn currency(mut self, ccy: impl Into<String>) -> Self {
103        self.ccy = Some(ccy.into());
104        self
105    }
106
107    /// Set the margin mode filter.
108    pub fn margin_mode(mut self, mgn_mode: TradeMode) -> Self {
109        self.mgn_mode = Some(mgn_mode);
110        self
111    }
112
113    /// Return records after this pagination cursor.
114    pub fn after(mut self, after: impl Into<String>) -> Self {
115        self.after = Some(after.into());
116        self
117    }
118
119    /// Return records before this pagination cursor.
120    pub fn before(mut self, before: impl Into<String>) -> Self {
121        self.before = Some(before.into());
122        self
123    }
124
125    /// Set the maximum number of rows to return.
126    pub fn limit(mut self, limit: u32) -> Self {
127        self.limit = Some(limit);
128        self
129    }
130}
131
132/// Request body for borrow/repay.
133#[derive(Debug, Clone, Serialize)]
134pub struct BorrowRepayRequest {
135    ccy: String,
136    side: String,
137    amt: String,
138    #[serde(rename = "ordId", skip_serializing_if = "Option::is_none")]
139    ord_id: Option<String>,
140}
141
142impl BorrowRepayRequest {
143    /// Create a borrow/repay request.
144    pub fn new(ccy: impl Into<String>, side: impl Into<String>, amt: impl Into<String>) -> Self {
145        Self {
146            ccy: ccy.into(),
147            side: side.into(),
148            amt: amt.into(),
149            ord_id: None,
150        }
151    }
152
153    /// Set the related order ID.
154    pub fn order_id(mut self, ord_id: impl Into<String>) -> Self {
155        self.ord_id = Some(ord_id.into());
156        self
157    }
158}
159
160/// Query parameters for borrow/repay history.
161#[derive(Debug, Clone, Default, Serialize)]
162pub struct BorrowRepayHistoryRequest {
163    #[serde(skip_serializing_if = "Option::is_none")]
164    ccy: Option<String>,
165    #[serde(skip_serializing_if = "Option::is_none")]
166    after: Option<String>,
167    #[serde(skip_serializing_if = "Option::is_none")]
168    before: Option<String>,
169    #[serde(skip_serializing_if = "Option::is_none")]
170    limit: Option<u32>,
171}
172
173impl BorrowRepayHistoryRequest {
174    /// Create an empty borrow/repay-history query.
175    pub fn new() -> Self {
176        Self::default()
177    }
178
179    /// Set the currency filter.
180    pub fn currency(mut self, ccy: impl Into<String>) -> Self {
181        self.ccy = Some(ccy.into());
182        self
183    }
184
185    /// Return records after this pagination cursor.
186    pub fn after(mut self, after: impl Into<String>) -> Self {
187        self.after = Some(after.into());
188        self
189    }
190
191    /// Return records before this pagination cursor.
192    pub fn before(mut self, before: impl Into<String>) -> Self {
193        self.before = Some(before.into());
194        self
195    }
196
197    /// Set the maximum number of rows to return.
198    pub fn limit(mut self, limit: u32) -> Self {
199        self.limit = Some(limit);
200        self
201    }
202}
203
204/// Query parameters for interest limits.
205#[derive(Debug, Clone, Default, Serialize)]
206pub struct InterestLimitsRequest {
207    #[serde(rename = "type", skip_serializing_if = "Option::is_none")]
208    limit_type: Option<String>,
209    #[serde(skip_serializing_if = "Option::is_none")]
210    ccy: Option<String>,
211}
212
213impl InterestLimitsRequest {
214    /// Create an empty interest-limits query.
215    pub fn new() -> Self {
216        Self::default()
217    }
218
219    /// Set the OKX interest-limit type.
220    pub fn limit_type(mut self, limit_type: impl Into<String>) -> Self {
221        self.limit_type = Some(limit_type.into());
222        self
223    }
224
225    /// Set the currency filter.
226    pub fn currency(mut self, ccy: impl Into<String>) -> Self {
227        self.ccy = Some(ccy.into());
228        self
229    }
230}