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