Skip to main content

rust_okx/api/sub_account/
requests.rs

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