Skip to main content

rust_okx/api/sub_account/
requests.rs

1use std::borrow::Cow;
2
3use serde::Serialize;
4
5/// Account type used in sub-account asset transfers.
6#[derive(Debug, Clone, Copy, Serialize)]
7pub enum SubAccountType {
8    /// Funding account (wire value `"6"`).
9    #[serde(rename = "6")]
10    Funding,
11    /// Trading account (wire value `"18"`).
12    #[serde(rename = "18")]
13    Trading,
14}
15
16/// Query parameters for [`SubAccount::get_subaccount_list`](crate::api::sub_account::SubAccount::get_subaccount_list).
17#[derive(Debug, Clone, Default, Serialize)]
18#[serde(rename_all = "camelCase")]
19pub struct SubAccountListRequest<'a> {
20    #[serde(skip_serializing_if = "Option::is_none")]
21    enable: Option<bool>,
22    #[serde(skip_serializing_if = "Option::is_none")]
23    sub_acct: Option<Cow<'a, str>>,
24    #[serde(skip_serializing_if = "Option::is_none")]
25    after: Option<Cow<'a, str>>,
26    #[serde(skip_serializing_if = "Option::is_none")]
27    before: Option<Cow<'a, str>>,
28    #[serde(skip_serializing_if = "Option::is_none")]
29    limit: Option<u32>,
30}
31
32impl<'a> SubAccountListRequest<'a> {
33    /// Start with no filters applied.
34    pub fn new() -> Self {
35        Self::default()
36    }
37
38    /// Filter by enabled/disabled status.
39    pub fn enable(mut self, enable: bool) -> Self {
40        self.enable = Some(enable);
41        self
42    }
43
44    /// Filter to a specific sub-account by name.
45    pub fn sub_acct(mut self, sub_acct: impl Into<Cow<'a, str>>) -> Self {
46        self.sub_acct = Some(sub_acct.into());
47        self
48    }
49
50    /// Return results with UID older than this value.
51    pub fn after(mut self, after: impl Into<Cow<'a, str>>) -> Self {
52        self.after = Some(after.into());
53        self
54    }
55
56    /// Return results with UID newer than this value.
57    pub fn before(mut self, before: impl Into<Cow<'a, str>>) -> Self {
58        self.before = Some(before.into());
59        self
60    }
61
62    /// Maximum number of results (default 100, max 100).
63    pub fn limit(mut self, limit: u32) -> Self {
64        self.limit = Some(limit);
65        self
66    }
67}
68
69/// Query parameters for [`SubAccount::get_subaccount_apikeys`](crate::api::sub_account::SubAccount::get_subaccount_apikeys).
70#[derive(Debug, Clone, Serialize)]
71#[serde(rename_all = "camelCase")]
72pub struct SubAccountApiKeysRequest<'a> {
73    sub_acct: Cow<'a, str>,
74    #[serde(skip_serializing_if = "Option::is_none")]
75    api_key: Option<Cow<'a, str>>,
76}
77
78impl<'a> SubAccountApiKeysRequest<'a> {
79    /// List all API keys for `sub_acct`.
80    pub fn new(sub_acct: impl Into<Cow<'a, str>>) -> Self {
81        Self {
82            sub_acct: sub_acct.into(),
83            api_key: None,
84        }
85    }
86
87    /// Retrieve a specific API key.
88    pub fn api_key(mut self, api_key: impl Into<Cow<'a, str>>) -> Self {
89        self.api_key = Some(api_key.into());
90        self
91    }
92}
93
94/// Query parameters for [`SubAccount::get_subaccount_trading_balances`](crate::api::sub_account::SubAccount::get_subaccount_trading_balances).
95#[derive(Debug, Clone, Serialize)]
96#[serde(rename_all = "camelCase")]
97pub struct SubAccountTradingBalancesRequest<'a> {
98    sub_acct: Cow<'a, str>,
99}
100
101impl<'a> SubAccountTradingBalancesRequest<'a> {
102    /// Query trading-account balances for `sub_acct`.
103    pub fn new(sub_acct: impl Into<Cow<'a, str>>) -> Self {
104        Self {
105            sub_acct: sub_acct.into(),
106        }
107    }
108}
109
110/// Query parameters for [`SubAccount::get_subaccount_funding_balances`](crate::api::sub_account::SubAccount::get_subaccount_funding_balances).
111#[derive(Debug, Clone, Serialize)]
112#[serde(rename_all = "camelCase")]
113pub struct SubAccountFundingBalancesRequest<'a> {
114    sub_acct: Cow<'a, str>,
115    #[serde(skip_serializing_if = "Option::is_none")]
116    ccy: Option<Cow<'a, str>>,
117}
118
119impl<'a> SubAccountFundingBalancesRequest<'a> {
120    /// Query funding-account balances for `sub_acct`.
121    pub fn new(sub_acct: impl Into<Cow<'a, str>>) -> Self {
122        Self {
123            sub_acct: sub_acct.into(),
124            ccy: None,
125        }
126    }
127
128    /// Filter by currency.
129    pub fn ccy(mut self, ccy: impl Into<Cow<'a, str>>) -> Self {
130        self.ccy = Some(ccy.into());
131        self
132    }
133}
134
135/// Query parameters for [`SubAccount::get_subaccount_max_withdrawal`](crate::api::sub_account::SubAccount::get_subaccount_max_withdrawal).
136#[derive(Debug, Clone, Serialize)]
137#[serde(rename_all = "camelCase")]
138pub struct SubAccountMaxWithdrawalRequest<'a> {
139    sub_acct: Cow<'a, str>,
140    #[serde(skip_serializing_if = "Option::is_none")]
141    ccy: Option<Cow<'a, str>>,
142}
143
144impl<'a> SubAccountMaxWithdrawalRequest<'a> {
145    /// Query maximum withdrawal for `sub_acct`.
146    pub fn new(sub_acct: impl Into<Cow<'a, str>>) -> Self {
147        Self {
148            sub_acct: sub_acct.into(),
149            ccy: None,
150        }
151    }
152
153    /// Filter to a specific currency.
154    pub fn ccy(mut self, ccy: impl Into<Cow<'a, str>>) -> Self {
155        self.ccy = Some(ccy.into());
156        self
157    }
158}
159
160/// Request body for [`SubAccount::create_subaccount`](crate::api::sub_account::SubAccount::create_subaccount).
161#[derive(Debug, Clone, Serialize)]
162#[serde(rename_all = "camelCase")]
163pub struct CreateSubAccountRequest<'a> {
164    sub_acct: Cow<'a, str>,
165    #[serde(skip_serializing_if = "Option::is_none")]
166    r#type: Option<Cow<'a, str>>,
167    #[serde(skip_serializing_if = "Option::is_none")]
168    label: Option<Cow<'a, str>>,
169    /// Password is security-sensitive; kept as owned `String`.
170    #[serde(skip_serializing_if = "Option::is_none")]
171    pwd: Option<String>,
172}
173
174impl<'a> CreateSubAccountRequest<'a> {
175    /// Create a sub-account with the given name.
176    pub fn new(sub_acct: impl Into<Cow<'a, str>>) -> Self {
177        Self {
178            sub_acct: sub_acct.into(),
179            r#type: None,
180            label: None,
181            pwd: None,
182        }
183    }
184
185    /// Set the sub-account type.
186    pub fn sub_type(mut self, sub_type: impl Into<Cow<'a, str>>) -> Self {
187        self.r#type = Some(sub_type.into());
188        self
189    }
190
191    /// Set a display label for the sub-account.
192    pub fn label(mut self, label: impl Into<Cow<'a, str>>) -> Self {
193        self.label = Some(label.into());
194        self
195    }
196
197    /// Set the login password.
198    pub fn pwd(mut self, pwd: impl Into<String>) -> Self {
199        self.pwd = Some(pwd.into());
200        self
201    }
202}
203
204/// Request body for [`SubAccount::create_subaccount_apikey`](crate::api::sub_account::SubAccount::create_subaccount_apikey).
205#[derive(Debug, Clone, Serialize)]
206#[serde(rename_all = "camelCase")]
207pub struct CreateSubAccountApiKeyRequest<'a> {
208    sub_acct: Cow<'a, str>,
209    label: Cow<'a, str>,
210    /// Passphrase is security-sensitive; kept as owned `String`.
211    passphrase: String,
212    #[serde(skip_serializing_if = "Option::is_none")]
213    perm: Option<Cow<'a, str>>,
214    #[serde(skip_serializing_if = "Option::is_none")]
215    ip: Option<Cow<'a, str>>,
216}
217
218impl<'a> CreateSubAccountApiKeyRequest<'a> {
219    /// Create an API key for `sub_acct` with a label and passphrase.
220    pub fn new(
221        sub_acct: impl Into<Cow<'a, str>>,
222        label: impl Into<Cow<'a, str>>,
223        passphrase: impl Into<String>,
224    ) -> Self {
225        Self {
226            sub_acct: sub_acct.into(),
227            label: label.into(),
228            passphrase: passphrase.into(),
229            perm: None,
230            ip: None,
231        }
232    }
233
234    /// Set permissions (comma-separated, e.g. `"read_only,trade"`).
235    pub fn perm(mut self, perm: impl Into<Cow<'a, str>>) -> Self {
236        self.perm = Some(perm.into());
237        self
238    }
239
240    /// Restrict to specific IP addresses (comma-separated).
241    pub fn ip(mut self, ip: impl Into<Cow<'a, str>>) -> Self {
242        self.ip = Some(ip.into());
243        self
244    }
245}
246
247/// Request body for [`SubAccount::modify_subaccount_apikey`](crate::api::sub_account::SubAccount::modify_subaccount_apikey).
248#[derive(Debug, Clone, Serialize)]
249#[serde(rename_all = "camelCase")]
250pub struct ModifySubAccountApiKeyRequest<'a> {
251    sub_acct: Cow<'a, str>,
252    api_key: Cow<'a, str>,
253    #[serde(skip_serializing_if = "Option::is_none")]
254    label: Option<Cow<'a, str>>,
255    #[serde(skip_serializing_if = "Option::is_none")]
256    perm: Option<Cow<'a, str>>,
257    #[serde(skip_serializing_if = "Option::is_none")]
258    ip: Option<Cow<'a, str>>,
259}
260
261impl<'a> ModifySubAccountApiKeyRequest<'a> {
262    /// Modify the API key identified by `api_key` on `sub_acct`.
263    pub fn new(sub_acct: impl Into<Cow<'a, str>>, api_key: impl Into<Cow<'a, str>>) -> Self {
264        Self {
265            sub_acct: sub_acct.into(),
266            api_key: api_key.into(),
267            label: None,
268            perm: None,
269            ip: None,
270        }
271    }
272
273    /// Change the label.
274    pub fn label(mut self, label: impl Into<Cow<'a, str>>) -> Self {
275        self.label = Some(label.into());
276        self
277    }
278
279    /// Change permissions (comma-separated).
280    pub fn perm(mut self, perm: impl Into<Cow<'a, str>>) -> Self {
281        self.perm = Some(perm.into());
282        self
283    }
284
285    /// Change allowed IP addresses (comma-separated).
286    pub fn ip(mut self, ip: impl Into<Cow<'a, str>>) -> Self {
287        self.ip = Some(ip.into());
288        self
289    }
290}
291
292/// Request body for [`SubAccount::delete_subaccount_apikey`](crate::api::sub_account::SubAccount::delete_subaccount_apikey).
293#[derive(Debug, Clone, Serialize)]
294#[serde(rename_all = "camelCase")]
295pub struct DeleteSubAccountApiKeyRequest<'a> {
296    sub_acct: Cow<'a, str>,
297    api_key: Cow<'a, str>,
298}
299
300impl<'a> DeleteSubAccountApiKeyRequest<'a> {
301    /// Delete the API key identified by `api_key` from `sub_acct`.
302    pub fn new(sub_acct: impl Into<Cow<'a, str>>, api_key: impl Into<Cow<'a, str>>) -> Self {
303        Self {
304            sub_acct: sub_acct.into(),
305            api_key: api_key.into(),
306        }
307    }
308}
309
310/// Request body for [`SubAccount::transfer_between_subaccounts`](crate::api::sub_account::SubAccount::transfer_between_subaccounts).
311#[derive(Debug, Clone, Serialize)]
312#[serde(rename_all = "camelCase")]
313pub struct SubAccountTransferRequest<'a> {
314    ccy: Cow<'a, str>,
315    amt: Cow<'a, str>,
316    from: SubAccountType,
317    to: SubAccountType,
318    from_sub_account: Cow<'a, str>,
319    to_sub_account: Cow<'a, str>,
320    #[serde(skip_serializing_if = "Option::is_none")]
321    loan_trans: Option<bool>,
322    #[serde(skip_serializing_if = "Option::is_none")]
323    omit_pos_risk: Option<bool>,
324}
325
326impl<'a> SubAccountTransferRequest<'a> {
327    /// Transfer `amt` of `ccy` between sub-accounts.
328    ///
329    /// `from` / `to` select the account type on each side:
330    /// [`SubAccountType::Funding`] or [`SubAccountType::Trading`].
331    pub fn new(
332        ccy: impl Into<Cow<'a, str>>,
333        amt: impl Into<Cow<'a, str>>,
334        from: SubAccountType,
335        to: SubAccountType,
336        from_sub_account: impl Into<Cow<'a, str>>,
337        to_sub_account: impl Into<Cow<'a, str>>,
338    ) -> Self {
339        Self {
340            ccy: ccy.into(),
341            amt: amt.into(),
342            from,
343            to,
344            from_sub_account: from_sub_account.into(),
345            to_sub_account: to_sub_account.into(),
346            loan_trans: None,
347            omit_pos_risk: None,
348        }
349    }
350
351    /// Whether to transfer with borrowing.
352    pub fn loan_trans(mut self, loan_trans: bool) -> Self {
353        self.loan_trans = Some(loan_trans);
354        self
355    }
356
357    /// Whether to ignore position risk when transferring.
358    pub fn omit_pos_risk(mut self, omit_pos_risk: bool) -> Self {
359        self.omit_pos_risk = Some(omit_pos_risk);
360        self
361    }
362}
363
364/// Request body for [`SubAccount::set_subaccount_transfer_out`](crate::api::sub_account::SubAccount::set_subaccount_transfer_out).
365#[derive(Debug, Clone, Serialize)]
366#[serde(rename_all = "camelCase")]
367pub struct SetTransferOutRequest<'a> {
368    sub_acct: Cow<'a, str>,
369    // True is default value.
370    can_trans_out: bool,
371}
372
373impl<'a> SetTransferOutRequest<'a> {
374    /// Enable or disable transfers out for `sub_acct`.
375    pub fn new(sub_acct: impl Into<Cow<'a, str>>) -> Self {
376        Self {
377            sub_acct: sub_acct.into(),
378            can_trans_out: true,
379        }
380    }
381
382    ///Filter by can_trans_out
383    pub fn can_trans_out(mut self, can_trans_out: bool) -> Self {
384        self.can_trans_out = can_trans_out;
385        self
386    }
387}
388
389/// Query parameters for [`SubAccount::get_subaccount_bills`](crate::api::sub_account::SubAccount::get_subaccount_bills).
390#[derive(Debug, Clone, Default, Serialize)]
391#[serde(rename_all = "camelCase")]
392pub struct SubAccountBillsRequest<'a> {
393    #[serde(skip_serializing_if = "Option::is_none")]
394    ccy: Option<Cow<'a, str>>,
395    #[serde(skip_serializing_if = "Option::is_none")]
396    r#type: Option<Cow<'a, str>>,
397    #[serde(skip_serializing_if = "Option::is_none")]
398    sub_acct: Option<Cow<'a, str>>,
399    #[serde(skip_serializing_if = "Option::is_none")]
400    after: Option<Cow<'a, str>>,
401    #[serde(skip_serializing_if = "Option::is_none")]
402    before: Option<Cow<'a, str>>,
403    #[serde(skip_serializing_if = "Option::is_none")]
404    limit: Option<u32>,
405}
406
407impl<'a> SubAccountBillsRequest<'a> {
408    /// Start with no filters applied.
409    pub fn new() -> Self {
410        Self::default()
411    }
412
413    /// Filter by currency.
414    pub fn ccy(mut self, ccy: impl Into<Cow<'a, str>>) -> Self {
415        self.ccy = Some(ccy.into());
416        self
417    }
418
419    /// Filter by bill type.
420    pub fn bill_type(mut self, r#type: impl Into<Cow<'a, str>>) -> Self {
421        self.r#type = Some(r#type.into());
422        self
423    }
424
425    /// Filter by sub-account name.
426    pub fn sub_acct(mut self, sub_acct: impl Into<Cow<'a, str>>) -> Self {
427        self.sub_acct = Some(sub_acct.into());
428        self
429    }
430
431    /// Return results older than this bill ID.
432    pub fn after(mut self, after: impl Into<Cow<'a, str>>) -> Self {
433        self.after = Some(after.into());
434        self
435    }
436
437    /// Return results newer than this bill ID.
438    pub fn before(mut self, before: impl Into<Cow<'a, str>>) -> Self {
439        self.before = Some(before.into());
440        self
441    }
442
443    /// Maximum number of results (default 100, max 100).
444    pub fn limit(mut self, limit: u32) -> Self {
445        self.limit = Some(limit);
446        self
447    }
448}
449
450/// Query parameters for [`SubAccount::get_subaccount_managed_bills`](crate::api::sub_account::SubAccount::get_subaccount_managed_bills).
451#[derive(Debug, Clone, Default, Serialize)]
452#[serde(rename_all = "camelCase")]
453pub struct ManagedSubAccountBillsRequest<'a> {
454    #[serde(skip_serializing_if = "Option::is_none")]
455    ccy: Option<Cow<'a, str>>,
456    #[serde(skip_serializing_if = "Option::is_none")]
457    r#type: Option<Cow<'a, str>>,
458    #[serde(skip_serializing_if = "Option::is_none")]
459    sub_acct: Option<Cow<'a, str>>,
460    #[serde(skip_serializing_if = "Option::is_none")]
461    sub_uid: Option<Cow<'a, str>>,
462    #[serde(skip_serializing_if = "Option::is_none")]
463    after: Option<Cow<'a, str>>,
464    #[serde(skip_serializing_if = "Option::is_none")]
465    before: Option<Cow<'a, str>>,
466    #[serde(skip_serializing_if = "Option::is_none")]
467    limit: Option<u32>,
468}
469
470impl<'a> ManagedSubAccountBillsRequest<'a> {
471    /// Start with no filters applied.
472    pub fn new() -> Self {
473        Self::default()
474    }
475
476    /// Filter by currency.
477    pub fn ccy(mut self, ccy: impl Into<Cow<'a, str>>) -> Self {
478        self.ccy = Some(ccy.into());
479        self
480    }
481
482    /// Filter by bill type.
483    pub fn bill_type(mut self, r#type: impl Into<Cow<'a, str>>) -> Self {
484        self.r#type = Some(r#type.into());
485        self
486    }
487
488    /// Filter by sub-account name.
489    pub fn sub_acct(mut self, sub_acct: impl Into<Cow<'a, str>>) -> Self {
490        self.sub_acct = Some(sub_acct.into());
491        self
492    }
493
494    /// Filter by sub-account UID.
495    pub fn sub_uid(mut self, sub_uid: impl Into<Cow<'a, str>>) -> Self {
496        self.sub_uid = Some(sub_uid.into());
497        self
498    }
499
500    /// Return results older than this bill ID.
501    pub fn after(mut self, after: impl Into<Cow<'a, str>>) -> Self {
502        self.after = Some(after.into());
503        self
504    }
505
506    /// Return results newer than this bill ID.
507    pub fn before(mut self, before: impl Into<Cow<'a, str>>) -> Self {
508        self.before = Some(before.into());
509        self
510    }
511
512    /// Maximum number of results (default 100, max 100).
513    pub fn limit(mut self, limit: u32) -> Self {
514        self.limit = Some(limit);
515        self
516    }
517}
518
519/// Query parameters for [`SubAccount::get_entrust_subaccount_list`](crate::api::sub_account::SubAccount::get_entrust_subaccount_list).
520#[derive(Debug, Clone, Default, Serialize)]
521#[serde(rename_all = "camelCase")]
522pub struct EntrustSubAccountListRequest<'a> {
523    #[serde(skip_serializing_if = "Option::is_none")]
524    sub_acct: Option<Cow<'a, str>>,
525}