Skip to main content

rust_okx/api/funding/
requests.rs

1use serde::Serialize;
2
3/// Request for [`get_currencies`](crate::api::funding::Funding::get_currencies),
4/// [`get_balances`](crate::api::funding::Funding::get_balances),
5/// [`get_non_tradable_assets`](crate::api::funding::Funding::get_non_tradable_assets), and
6/// [`get_asset_valuation`](crate::api::funding::Funding::get_asset_valuation).
7#[derive(Debug, Clone, Default, Serialize)]
8pub struct CurrencyRequest<'a> {
9    /// Currency filter, e.g. `Some("BTC")`. `None` returns all currencies.
10    #[serde(skip_serializing_if = "Option::is_none")]
11    pub ccy: Option<&'a str>,
12}
13
14/// Request for [`get_deposit_address`](crate::api::funding::Funding::get_deposit_address).
15#[derive(Debug, Clone, Serialize)]
16pub struct DepositAddressRequest<'a> {
17    /// Currency, e.g. `"USDT"`.
18    pub ccy: &'a str,
19}
20
21/// Request for [`transfer_state`](crate::api::funding::Funding::transfer_state).
22#[derive(Debug, Clone, Serialize)]
23pub struct TransferStateRequest<'a> {
24    /// Transfer ID.
25    #[serde(rename = "transId")]
26    pub trans_id: &'a str,
27    /// Transfer type (optional).
28    #[serde(rename = "type", skip_serializing_if = "Option::is_none")]
29    pub transfer_type: Option<&'a str>,
30}
31
32/// Request for [`cancel_withdrawal`](crate::api::funding::Funding::cancel_withdrawal).
33#[derive(Debug, Clone, Serialize)]
34pub struct CancelWithdrawalRequest<'a> {
35    /// Withdrawal ID.
36    #[serde(rename = "wdId")]
37    pub wd_id: &'a str,
38}
39
40/// Request body for [`Funding::funds_transfer`].
41#[derive(Debug, Clone, Serialize)]
42#[serde(rename_all = "camelCase")]
43pub struct FundsTransferRequest {
44    ccy: String,
45    amt: String,
46    #[serde(rename = "from")]
47    from_account: String,
48    to: String,
49    #[serde(rename = "type", skip_serializing_if = "Option::is_none")]
50    transfer_type: Option<String>,
51    #[serde(rename = "subAcct", skip_serializing_if = "Option::is_none")]
52    sub_account: Option<String>,
53    #[serde(rename = "instId", skip_serializing_if = "Option::is_none")]
54    inst_id: Option<String>,
55    #[serde(rename = "toInstId", skip_serializing_if = "Option::is_none")]
56    to_inst_id: Option<String>,
57    #[serde(rename = "loanTrans", skip_serializing_if = "Option::is_none")]
58    loan_transfer: Option<String>,
59}
60
61impl FundsTransferRequest {
62    /// Create a funds-transfer request.
63    pub fn new(
64        ccy: impl Into<String>,
65        amt: impl Into<String>,
66        from_account: impl Into<String>,
67        to: impl Into<String>,
68    ) -> Self {
69        Self {
70            ccy: ccy.into(),
71            amt: amt.into(),
72            from_account: from_account.into(),
73            to: to.into(),
74            transfer_type: None,
75            sub_account: None,
76            inst_id: None,
77            to_inst_id: None,
78            loan_transfer: None,
79        }
80    }
81
82    /// Set transfer type, e.g. `0` for transfer within account.
83    pub fn transfer_type(mut self, transfer_type: impl Into<String>) -> Self {
84        self.transfer_type = Some(transfer_type.into());
85        self
86    }
87
88    /// Set sub-account name.
89    pub fn sub_account(mut self, sub_account: impl Into<String>) -> Self {
90        self.sub_account = Some(sub_account.into());
91        self
92    }
93
94    /// Set source instrument ID.
95    pub fn inst_id(mut self, inst_id: impl Into<String>) -> Self {
96        self.inst_id = Some(inst_id.into());
97        self
98    }
99
100    /// Set destination instrument ID.
101    pub fn to_inst_id(mut self, to_inst_id: impl Into<String>) -> Self {
102        self.to_inst_id = Some(to_inst_id.into());
103        self
104    }
105
106    /// Set whether this is a loan transfer.
107    pub fn loan_transfer(mut self, loan_transfer: impl Into<String>) -> Self {
108        self.loan_transfer = Some(loan_transfer.into());
109        self
110    }
111}
112
113/// Request body for [`Funding::withdrawal`].
114#[derive(Debug, Clone, Serialize)]
115#[serde(rename_all = "camelCase")]
116pub struct WithdrawalRequest {
117    ccy: String,
118    amt: String,
119    dest: String,
120    #[serde(rename = "toAddr")]
121    to_addr: String,
122    #[serde(skip_serializing_if = "Option::is_none")]
123    chain: Option<String>,
124    #[serde(rename = "areaCode", skip_serializing_if = "Option::is_none")]
125    area_code: Option<String>,
126    #[serde(rename = "clientId", skip_serializing_if = "Option::is_none")]
127    client_id: Option<String>,
128    #[serde(rename = "toAddrType", skip_serializing_if = "Option::is_none")]
129    to_addr_type: Option<String>,
130}
131
132impl WithdrawalRequest {
133    /// Create a withdrawal request.
134    pub fn new(
135        ccy: impl Into<String>,
136        amt: impl Into<String>,
137        dest: impl Into<String>,
138        to_addr: impl Into<String>,
139    ) -> Self {
140        Self {
141            ccy: ccy.into(),
142            amt: amt.into(),
143            dest: dest.into(),
144            to_addr: to_addr.into(),
145            chain: None,
146            area_code: None,
147            client_id: None,
148            to_addr_type: None,
149        }
150    }
151
152    /// Set withdrawal chain.
153    pub fn chain(mut self, chain: impl Into<String>) -> Self {
154        self.chain = Some(chain.into());
155        self
156    }
157
158    /// Set phone area code for internal withdrawals.
159    pub fn area_code(mut self, area_code: impl Into<String>) -> Self {
160        self.area_code = Some(area_code.into());
161        self
162    }
163
164    /// Set client withdrawal ID.
165    pub fn client_id(mut self, client_id: impl Into<String>) -> Self {
166        self.client_id = Some(client_id.into());
167        self
168    }
169
170    /// Set address type.
171    pub fn to_addr_type(mut self, to_addr_type: impl Into<String>) -> Self {
172        self.to_addr_type = Some(to_addr_type.into());
173        self
174    }
175}
176
177/// Query parameters for [`Funding::get_deposit_history`].
178#[derive(Debug, Clone, Default, Serialize)]
179#[serde(rename_all = "camelCase")]
180pub struct DepositHistoryRequest {
181    #[serde(skip_serializing_if = "Option::is_none")]
182    ccy: Option<String>,
183    #[serde(rename = "type", skip_serializing_if = "Option::is_none")]
184    deposit_type: Option<String>,
185    #[serde(skip_serializing_if = "Option::is_none")]
186    state: Option<String>,
187    #[serde(skip_serializing_if = "Option::is_none")]
188    after: Option<String>,
189    #[serde(skip_serializing_if = "Option::is_none")]
190    before: Option<String>,
191    #[serde(skip_serializing_if = "Option::is_none")]
192    limit: Option<u32>,
193    #[serde(rename = "txId", skip_serializing_if = "Option::is_none")]
194    tx_id: Option<String>,
195    #[serde(rename = "depId", skip_serializing_if = "Option::is_none")]
196    dep_id: Option<String>,
197    #[serde(rename = "fromWdId", skip_serializing_if = "Option::is_none")]
198    from_wd_id: Option<String>,
199}
200
201impl DepositHistoryRequest {
202    /// Create an empty deposit-history query.
203    pub fn new() -> Self {
204        Self::default()
205    }
206
207    /// Filter by currency.
208    pub fn currency(mut self, ccy: impl Into<String>) -> Self {
209        self.ccy = Some(ccy.into());
210        self
211    }
212
213    /// Filter by deposit type.
214    pub fn deposit_type(mut self, deposit_type: impl Into<String>) -> Self {
215        self.deposit_type = Some(deposit_type.into());
216        self
217    }
218
219    /// Filter by state.
220    pub fn state(mut self, state: impl Into<String>) -> Self {
221        self.state = Some(state.into());
222        self
223    }
224
225    /// Page after the given ID.
226    pub fn after(mut self, after: impl Into<String>) -> Self {
227        self.after = Some(after.into());
228        self
229    }
230
231    /// Page before the given ID.
232    pub fn before(mut self, before: impl Into<String>) -> Self {
233        self.before = Some(before.into());
234        self
235    }
236
237    /// Set result limit.
238    pub fn limit(mut self, limit: u32) -> Self {
239        self.limit = Some(limit);
240        self
241    }
242
243    /// Filter by transaction ID.
244    pub fn tx_id(mut self, tx_id: impl Into<String>) -> Self {
245        self.tx_id = Some(tx_id.into());
246        self
247    }
248
249    /// Filter by deposit ID.
250    pub fn dep_id(mut self, dep_id: impl Into<String>) -> Self {
251        self.dep_id = Some(dep_id.into());
252        self
253    }
254
255    /// Filter by source withdrawal ID.
256    pub fn from_wd_id(mut self, from_wd_id: impl Into<String>) -> Self {
257        self.from_wd_id = Some(from_wd_id.into());
258        self
259    }
260}
261
262/// Query parameters for [`Funding::get_withdrawal_history`].
263#[derive(Debug, Clone, Default, Serialize)]
264#[serde(rename_all = "camelCase")]
265pub struct WithdrawalHistoryRequest {
266    #[serde(skip_serializing_if = "Option::is_none")]
267    ccy: Option<String>,
268    #[serde(rename = "wdId", skip_serializing_if = "Option::is_none")]
269    wd_id: Option<String>,
270    #[serde(rename = "clientId", skip_serializing_if = "Option::is_none")]
271    client_id: Option<String>,
272    #[serde(rename = "txId", skip_serializing_if = "Option::is_none")]
273    tx_id: Option<String>,
274    #[serde(rename = "type", skip_serializing_if = "Option::is_none")]
275    withdrawal_type: Option<String>,
276    #[serde(skip_serializing_if = "Option::is_none")]
277    state: Option<String>,
278    #[serde(skip_serializing_if = "Option::is_none")]
279    after: Option<String>,
280    #[serde(skip_serializing_if = "Option::is_none")]
281    before: Option<String>,
282    #[serde(skip_serializing_if = "Option::is_none")]
283    limit: Option<u32>,
284    #[serde(rename = "toAddrType", skip_serializing_if = "Option::is_none")]
285    to_addr_type: Option<String>,
286}
287
288impl WithdrawalHistoryRequest {
289    /// Create an empty withdrawal-history query.
290    pub fn new() -> Self {
291        Self::default()
292    }
293
294    /// Filter by currency.
295    pub fn currency(mut self, ccy: impl Into<String>) -> Self {
296        self.ccy = Some(ccy.into());
297        self
298    }
299
300    /// Filter by withdrawal ID.
301    pub fn withdrawal_id(mut self, wd_id: impl Into<String>) -> Self {
302        self.wd_id = Some(wd_id.into());
303        self
304    }
305
306    /// Filter by client ID.
307    pub fn client_id(mut self, client_id: impl Into<String>) -> Self {
308        self.client_id = Some(client_id.into());
309        self
310    }
311
312    /// Filter by transaction ID.
313    pub fn tx_id(mut self, tx_id: impl Into<String>) -> Self {
314        self.tx_id = Some(tx_id.into());
315        self
316    }
317
318    /// Filter by withdrawal type.
319    pub fn withdrawal_type(mut self, withdrawal_type: impl Into<String>) -> Self {
320        self.withdrawal_type = Some(withdrawal_type.into());
321        self
322    }
323
324    /// Filter by state.
325    pub fn state(mut self, state: impl Into<String>) -> Self {
326        self.state = Some(state.into());
327        self
328    }
329
330    /// Page after the given ID.
331    pub fn after(mut self, after: impl Into<String>) -> Self {
332        self.after = Some(after.into());
333        self
334    }
335
336    /// Page before the given ID.
337    pub fn before(mut self, before: impl Into<String>) -> Self {
338        self.before = Some(before.into());
339        self
340    }
341
342    /// Set result limit.
343    pub fn limit(mut self, limit: u32) -> Self {
344        self.limit = Some(limit);
345        self
346    }
347
348    /// Filter by destination address type.
349    pub fn to_addr_type(mut self, to_addr_type: impl Into<String>) -> Self {
350        self.to_addr_type = Some(to_addr_type.into());
351        self
352    }
353}
354
355/// Query parameters for [`Funding::get_bills`].
356#[derive(Debug, Clone, Default, Serialize)]
357pub struct FundingBillsRequest {
358    #[serde(skip_serializing_if = "Option::is_none")]
359    ccy: Option<String>,
360    #[serde(rename = "type", skip_serializing_if = "Option::is_none")]
361    bill_type: Option<String>,
362    #[serde(skip_serializing_if = "Option::is_none")]
363    after: Option<String>,
364    #[serde(skip_serializing_if = "Option::is_none")]
365    before: Option<String>,
366    #[serde(skip_serializing_if = "Option::is_none")]
367    limit: Option<u32>,
368}
369
370impl FundingBillsRequest {
371    /// Create an empty funding-bills query.
372    pub fn new() -> Self {
373        Self::default()
374    }
375
376    /// Filter by currency.
377    pub fn currency(mut self, ccy: impl Into<String>) -> Self {
378        self.ccy = Some(ccy.into());
379        self
380    }
381
382    /// Filter by bill type.
383    pub fn bill_type(mut self, bill_type: impl Into<String>) -> Self {
384        self.bill_type = Some(bill_type.into());
385        self
386    }
387
388    /// Page after the given bill ID.
389    pub fn after(mut self, after: impl Into<String>) -> Self {
390        self.after = Some(after.into());
391        self
392    }
393
394    /// Page before the given bill ID.
395    pub fn before(mut self, before: impl Into<String>) -> Self {
396        self.before = Some(before.into());
397        self
398    }
399
400    /// Set result limit.
401    pub fn limit(mut self, limit: u32) -> Self {
402        self.limit = Some(limit);
403        self
404    }
405}
406
407/// Query parameters for [`Funding::get_deposit_lightning`].
408#[derive(Debug, Clone, Serialize)]
409pub struct DepositLightningRequest {
410    ccy: String,
411    amt: String,
412    #[serde(skip_serializing_if = "Option::is_none")]
413    to: Option<String>,
414}
415
416impl DepositLightningRequest {
417    /// Create a Lightning deposit request.
418    pub fn new(ccy: impl Into<String>, amt: impl Into<String>) -> Self {
419        Self {
420            ccy: ccy.into(),
421            amt: amt.into(),
422            to: None,
423        }
424    }
425
426    /// Set recipient.
427    pub fn to(mut self, to: impl Into<String>) -> Self {
428        self.to = Some(to.into());
429        self
430    }
431}
432
433/// Request body for [`Funding::withdrawal_lightning`].
434#[derive(Debug, Clone, Serialize)]
435pub struct WithdrawalLightningRequest {
436    ccy: String,
437    invoice: String,
438    #[serde(skip_serializing_if = "Option::is_none")]
439    memo: Option<String>,
440}
441
442impl WithdrawalLightningRequest {
443    /// Create a Lightning withdrawal request.
444    pub fn new(ccy: impl Into<String>, invoice: impl Into<String>) -> Self {
445        Self {
446            ccy: ccy.into(),
447            invoice: invoice.into(),
448            memo: None,
449        }
450    }
451
452    /// Set withdrawal memo.
453    pub fn memo(mut self, memo: impl Into<String>) -> Self {
454        self.memo = Some(memo.into());
455        self
456    }
457}
458
459/// Query parameters for [`Funding::get_deposit_withdraw_status`].
460#[derive(Debug, Clone, Default, Serialize)]
461#[serde(rename_all = "camelCase")]
462pub struct DepositWithdrawStatusRequest {
463    #[serde(rename = "wdId", skip_serializing_if = "Option::is_none")]
464    wd_id: Option<String>,
465    #[serde(rename = "txId", skip_serializing_if = "Option::is_none")]
466    tx_id: Option<String>,
467    #[serde(skip_serializing_if = "Option::is_none")]
468    ccy: Option<String>,
469    #[serde(skip_serializing_if = "Option::is_none")]
470    to: Option<String>,
471    #[serde(skip_serializing_if = "Option::is_none")]
472    chain: Option<String>,
473}
474
475impl DepositWithdrawStatusRequest {
476    /// Create an empty deposit/withdrawal-status query.
477    pub fn new() -> Self {
478        Self::default()
479    }
480
481    /// Filter by withdrawal ID.
482    pub fn withdrawal_id(mut self, wd_id: impl Into<String>) -> Self {
483        self.wd_id = Some(wd_id.into());
484        self
485    }
486
487    /// Filter by transaction ID.
488    pub fn tx_id(mut self, tx_id: impl Into<String>) -> Self {
489        self.tx_id = Some(tx_id.into());
490        self
491    }
492
493    /// Filter by currency.
494    pub fn currency(mut self, ccy: impl Into<String>) -> Self {
495        self.ccy = Some(ccy.into());
496        self
497    }
498
499    /// Filter by destination address.
500    pub fn to(mut self, to: impl Into<String>) -> Self {
501        self.to = Some(to.into());
502        self
503    }
504
505    /// Filter by chain.
506    pub fn chain(mut self, chain: impl Into<String>) -> Self {
507        self.chain = Some(chain.into());
508        self
509    }
510}