rust_okx/api/sub_account/api.rs
1use crate::client::OkxClient;
2use crate::error::Error;
3use crate::transport::Transport;
4
5use super::endpoints::*;
6use super::requests::*;
7use super::responses::*;
8
9/// Accessor for the sub-account management endpoints.
10///
11/// Obtain one via [`OkxClient::sub_account`](crate::OkxClient::sub_account).
12/// All methods require credentials.
13pub struct SubAccount<'a, T> {
14 client: &'a OkxClient<T>,
15}
16
17impl<'a, T: Transport> SubAccount<'a, T> {
18 pub(crate) fn new(client: &'a OkxClient<T>) -> Self {
19 Self { client }
20 }
21
22 /// List sub-accounts of the master account.
23 ///
24 /// `GET /api/v5/users/subaccount/list`. Authenticated.
25 ///
26 /// # Errors
27 ///
28 /// Returns [`RestError::Configuration`](crate::RestError::Configuration) if no credentials are set,
29 /// [`RestError::Okx`](crate::RestError::Okx) on a non-zero OKX code, or transport/decode errors.
30 pub async fn get_subaccount_list(
31 &self,
32 request: &SubAccountListRequest<'_>,
33 ) -> Result<Vec<SubAccountEntry>, Error> {
34 self.client.get(SUBACCOUNT_LIST, request, true).await
35 }
36
37 /// Create a new sub-account.
38 ///
39 /// `POST /api/v5/users/subaccount/create-subaccount`. Authenticated.
40 ///
41 /// # Errors
42 ///
43 /// Returns [`RestError::Configuration`](crate::RestError::Configuration) if no credentials are set,
44 /// [`RestError::Okx`](crate::RestError::Okx) on a non-zero OKX code, or transport/decode errors.
45 pub async fn create_subaccount(
46 &self,
47 request: &CreateSubAccountRequest<'_>,
48 ) -> Result<Vec<SubAccountEntry>, Error> {
49 self.client.post(SUBACCOUNT_CREATE, request, true).await
50 }
51
52 /// Create an API key for a sub-account.
53 ///
54 /// `POST /api/v5/users/subaccount/apikey`. Authenticated.
55 ///
56 /// # Errors
57 ///
58 /// Returns [`RestError::Configuration`](crate::RestError::Configuration) if no credentials are set,
59 /// [`RestError::Okx`](crate::RestError::Okx) on a non-zero OKX code, or transport/decode errors.
60 pub async fn create_subaccount_apikey(
61 &self,
62 request: &CreateSubAccountApiKeyRequest<'_>,
63 ) -> Result<Vec<SubAccountApiKey>, Error> {
64 self.client.post(SUBACCOUNT_APIKEY, request, true).await
65 }
66
67 /// List API keys of a sub-account.
68 ///
69 /// `GET /api/v5/users/subaccount/apikey`. Authenticated.
70 ///
71 /// # Errors
72 ///
73 /// Returns [`RestError::Configuration`](crate::RestError::Configuration) if no credentials are set,
74 /// [`RestError::Okx`](crate::RestError::Okx) on a non-zero OKX code, or transport/decode errors.
75 pub async fn get_subaccount_apikeys(
76 &self,
77 request: &SubAccountApiKeysRequest<'_>,
78 ) -> Result<Vec<SubAccountApiKey>, Error> {
79 self.client.get(SUBACCOUNT_APIKEY, request, true).await
80 }
81
82 /// Modify an API key of a sub-account.
83 ///
84 /// `POST /api/v5/users/subaccount/modify-apikey`. Authenticated.
85 ///
86 /// # Errors
87 ///
88 /// Returns [`RestError::Configuration`](crate::RestError::Configuration) if no credentials are set,
89 /// [`RestError::Okx`](crate::RestError::Okx) on a non-zero OKX code, or transport/decode errors.
90 pub async fn modify_subaccount_apikey(
91 &self,
92 request: &ModifySubAccountApiKeyRequest<'_>,
93 ) -> Result<Vec<SubAccountApiKey>, Error> {
94 self.client
95 .post(SUBACCOUNT_APIKEY_MODIFY, request, true)
96 .await
97 }
98
99 /// Delete an API key of a sub-account.
100 ///
101 /// `POST /api/v5/users/subaccount/delete-apikey`. Authenticated.
102 ///
103 /// # Errors
104 ///
105 /// Returns [`RestError::Configuration`](crate::RestError::Configuration) if no credentials are set,
106 /// [`RestError::Okx`](crate::RestError::Okx) on a non-zero OKX code, or transport/decode errors.
107 pub async fn delete_subaccount_apikey(
108 &self,
109 request: &DeleteSubAccountApiKeyRequest<'_>,
110 ) -> Result<Vec<SubAccountApiKey>, Error> {
111 self.client
112 .post(SUBACCOUNT_APIKEY_DELETE, request, true)
113 .await
114 }
115
116 /// Retrieve trading-account balances of a sub-account.
117 ///
118 /// `GET /api/v5/account/subaccount/balances`. Authenticated.
119 ///
120 /// # Errors
121 ///
122 /// Returns [`RestError::Configuration`](crate::RestError::Configuration) if no credentials are set,
123 /// [`RestError::Okx`](crate::RestError::Okx) on a non-zero OKX code, or transport/decode errors.
124 pub async fn get_subaccount_trading_balances(
125 &self,
126 request: &SubAccountTradingBalancesRequest<'_>,
127 ) -> Result<Vec<SubAccountTradingBalance>, Error> {
128 self.client
129 .get(SUBACCOUNT_TRADING_BALANCES, request, true)
130 .await
131 }
132
133 /// Retrieve funding-account balances of a sub-account.
134 ///
135 /// `GET /api/v5/asset/subaccount/balances`. Authenticated.
136 ///
137 /// # Errors
138 ///
139 /// Returns [`RestError::Configuration`](crate::RestError::Configuration) if no credentials are set,
140 /// [`RestError::Okx`](crate::RestError::Okx) on a non-zero OKX code, or transport/decode errors.
141 pub async fn get_subaccount_funding_balances(
142 &self,
143 request: &SubAccountFundingBalancesRequest<'_>,
144 ) -> Result<Vec<SubAccountFundingBalance>, Error> {
145 self.client
146 .get(SUBACCOUNT_FUNDING_BALANCES, request, true)
147 .await
148 }
149
150 /// Retrieve the maximum withdrawal amount for a sub-account.
151 ///
152 /// `GET /api/v5/account/subaccount/max-withdrawal`. Authenticated.
153 ///
154 /// # Errors
155 ///
156 /// Returns [`RestError::Configuration`](crate::RestError::Configuration) if no credentials are set,
157 /// [`RestError::Okx`](crate::RestError::Okx) on a non-zero OKX code, or transport/decode errors.
158 pub async fn get_subaccount_max_withdrawal(
159 &self,
160 request: &SubAccountMaxWithdrawalRequest<'_>,
161 ) -> Result<Vec<SubAccountMaxWithdrawal>, Error> {
162 self.client
163 .get(SUBACCOUNT_MAX_WITHDRAWAL, request, true)
164 .await
165 }
166
167 /// Retrieve asset bills for sub-accounts of the master account.
168 ///
169 /// `GET /api/v5/asset/subaccount/bills`. Authenticated.
170 ///
171 /// # Errors
172 ///
173 /// Returns [`RestError::Configuration`](crate::RestError::Configuration) if no credentials are set,
174 /// [`RestError::Okx`](crate::RestError::Okx) on a non-zero OKX code, or transport/decode errors.
175 pub async fn get_subaccount_bills(
176 &self,
177 request: &SubAccountBillsRequest<'_>,
178 ) -> Result<Vec<SubAccountBill>, Error> {
179 self.client.get(SUBACCOUNT_BILLS, request, true).await
180 }
181
182 /// Retrieve asset bills for managed sub-accounts.
183 ///
184 /// `GET /api/v5/asset/subaccount/managed-subaccount-bills`. Authenticated.
185 ///
186 /// # Errors
187 ///
188 /// Returns [`RestError::Configuration`](crate::RestError::Configuration) if no credentials are set,
189 /// [`RestError::Okx`](crate::RestError::Okx) on a non-zero OKX code, or transport/decode errors.
190 pub async fn get_subaccount_managed_bills(
191 &self,
192 request: &ManagedSubAccountBillsRequest<'_>,
193 ) -> Result<Vec<ManagedSubAccountBill>, Error> {
194 self.client
195 .get(SUBACCOUNT_MANAGED_BILLS, request, true)
196 .await
197 }
198
199 /// Transfer assets between funding or trading accounts of sub-accounts.
200 ///
201 /// `POST /api/v5/asset/subaccount/transfer`. Authenticated. Use
202 /// [`SubAccountType`] to specify the account type on each side.
203 ///
204 /// # Errors
205 ///
206 /// Returns [`RestError::Configuration`](crate::RestError::Configuration) if no credentials are set,
207 /// [`RestError::Okx`](crate::RestError::Okx) on a non-zero OKX code, or transport/decode errors.
208 pub async fn transfer_between_subaccounts(
209 &self,
210 request: &SubAccountTransferRequest<'_>,
211 ) -> Result<Vec<SubAccountTransferResult>, Error> {
212 self.client.post(SUBACCOUNT_TRANSFER, request, true).await
213 }
214
215 /// Enable or disable transfers out for one or more sub-accounts.
216 ///
217 /// `POST /api/v5/users/subaccount/set-transfer-out`. Authenticated.
218 ///
219 /// # Errors
220 ///
221 /// Returns [`RestError::Configuration`](crate::RestError::Configuration) if no credentials are set,
222 /// [`RestError::Okx`](crate::RestError::Okx) on a non-zero OKX code, or transport/decode errors.
223 pub async fn set_subaccount_transfer_out(
224 &self,
225 request: &SetTransferOutRequest<'_>,
226 ) -> Result<Vec<SetTransferOutResult>, Error> {
227 self.client
228 .post(SUBACCOUNT_SET_TRANSFER_OUT, request, true)
229 .await
230 }
231
232 /// List sub-accounts of an entrusted entity.
233 ///
234 /// `GET /api/v5/users/entrust-subaccount-list`. Authenticated.
235 ///
236 /// # Errors
237 ///
238 /// Returns [`RestError::Configuration`](crate::RestError::Configuration) if no credentials are set,
239 /// [`RestError::Okx`](crate::RestError::Okx) on a non-zero OKX code, or transport/decode errors.
240 pub async fn get_entrust_subaccount_list(&self) -> Result<Vec<EntrustSubAccount>, Error> {
241 self.client.get(ENTRUST_SUBACCOUNT_LIST, &(), true).await
242 }
243}