forked from Kucoin/kucoin-go-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaccount.go
436 lines (386 loc) · 15 KB
/
account.go
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
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
package kucoin
import (
"encoding/json"
"fmt"
"net/http"
)
// An AccountModel represents an account.
type AccountModel struct {
Id string `json:"id"`
Currency string `json:"currency"`
Type string `json:"type"`
Balance string `json:"balance"`
Available string `json:"available"`
Holds string `json:"holds"`
}
// An AccountsModel is the set of *AccountModel.
type AccountsModel []*AccountModel
// Accounts returns a list of accounts.
// See the Deposits section for documentation on how to deposit funds to begin trading.
func (as *ApiService) Accounts(currency, typo string) (*ApiResponse, error) {
p := map[string]string{}
if currency != "" {
p["currency"] = currency
}
if typo != "" {
p["type"] = typo
}
req := NewRequest(http.MethodGet, "/api/v1/accounts", p)
return as.Call(req)
}
// Account returns an account when you know the accountId.
func (as *ApiService) Account(accountId string) (*ApiResponse, error) {
req := NewRequest(http.MethodGet, "/api/v1/accounts/"+accountId, nil)
return as.Call(req)
}
// A SubAccountUserModel represents a sub-account user.
type SubAccountUserModel struct {
UserId string `json:"userId"`
SubName string `json:"subName"`
Remarks string `json:"remarks"`
Type int `json:"type"`
Access string `json:"access"`
Uid int64 `json:"uid"`
}
// A SubAccountUserModelV2 represents a sub-account user.
type SubAccountUserModelV2 struct {
UserId string `json:"userId"`
Uid int64 `json:"uid"`
SubName string `json:"subName"`
Status int `json:"status"`
Type int `json:"type"`
Access string `json:"access"`
CreatedAt json.Number `json:"createdAt"`
Remarks string `json:"remarks"`
}
// A SubAccountUsersModel is the set of *SubAccountUserModel.
type SubAccountUsersModel []*SubAccountUserModel
// A SubAccountUsersModelV2 is the set of *SubAccountUserModelV2.
type SubAccountUsersModelV2 []*SubAccountUserModelV2
// SubAccountUsers returns a list of sub-account user.
func (as *ApiService) SubAccountUsers() (*ApiResponse, error) {
req := NewRequest(http.MethodGet, "/api/v1/sub/user", nil)
return as.Call(req)
}
// A SubAccountsModel is the set of *SubAccountModel.
type SubAccountsModel []*SubAccountModel
// SubAccounts returns the aggregated balance of all sub-accounts of the current user.
func (as *ApiService) SubAccounts() (*ApiResponse, error) {
req := NewRequest(http.MethodGet, "/api/v1/sub-accounts", nil)
return as.Call(req)
}
// AccountsTransferableModel RESPONSES of AccountsTransferable
type AccountsTransferableModel struct {
Currency string `json:"currency"`
Balance string `json:"balance"`
Available string `json:"available"`
Holds string `json:"holds"`
Transferable string `json:"transferable"`
}
// AccountsTransferable returns the transferable balance of a specified account.
func (as *ApiService) AccountsTransferable(currency, typo string) (*ApiResponse, error) {
req := NewRequest(http.MethodGet, "/api/v1/accounts/transferable", map[string]string{"currency": currency, "type": typo})
return as.Call(req)
}
// A SubAccountModel represents the balance of a sub-account user.
type SubAccountModel struct {
SubUserId string `json:"subUserId"`
SubName string `json:"subName"`
MainAccounts []struct {
Currency string `json:"currency"`
Balance string `json:"balance"`
Available string `json:"available"`
Holds string `json:"holds"`
BaseCurrency string `json:"baseCurrency"`
BaseCurrencyPrice string `json:"baseCurrencyPrice"`
BaseAmount string `json:"baseAmount"`
} `json:"mainAccounts"`
TradeAccounts []struct {
Currency string `json:"currency"`
Balance string `json:"balance"`
Available string `json:"available"`
Holds string `json:"holds"`
BaseCurrency string `json:"baseCurrency"`
BaseCurrencyPrice string `json:"baseCurrencyPrice"`
BaseAmount string `json:"baseAmount"`
} `json:"tradeAccounts"`
MarginAccounts []struct {
Currency string `json:"currency"`
Balance string `json:"balance"`
Available string `json:"available"`
Holds string `json:"holds"`
BaseCurrency string `json:"baseCurrency"`
BaseCurrencyPrice string `json:"baseCurrencyPrice"`
BaseAmount string `json:"baseAmount"`
} `json:"marginAccounts"`
}
// SubAccount returns the detail of a sub-account.
func (as *ApiService) SubAccount(subUserId string) (*ApiResponse, error) {
req := NewRequest(http.MethodGet, "/api/v1/sub-accounts/"+subUserId, nil)
return as.Call(req)
}
// CreateAccountModel represents The account id returned from creating an account
type CreateAccountModel struct {
Id string `json:"id"`
}
// CreateAccount creates an account according to type(main|trade) and currency
// Parameter #1 typo is type of account.
// Deprecated
func (as *ApiService) CreateAccount(typo, currency string) (*ApiResponse, error) {
req := NewRequest(http.MethodPost, "/api/v1/accounts", map[string]string{"currency": currency, "type": typo})
return as.Call(req)
}
// An AccountLedgerModel represents account activity either increases or decreases your account balance.
type AccountLedgerModel struct {
ID string `json:"id"`
Currency string `json:"currency"`
Amount string `json:"amount"`
Fee string `json:"fee"`
Balance string `json:"balance"`
AccountType string `json:"accountType"`
BizType string `json:"bizType"`
Direction string `json:"direction"`
CreatedAt int64 `json:"createdAt"`
Context json.RawMessage `json:"context"`
}
// An AccountLedgersModel the set of *AccountLedgerModel.
type AccountLedgersModel []*AccountLedgerModel
// AccountLedgers returns a list of ledgers.
// Deprecated: This interface was discontinued on Nov 05, 2020. Please use AccountLedgersV2.
// Account activity either increases or decreases your account balance.
// Items are paginated and sorted latest first.
// Deprecated
func (as *ApiService) AccountLedgers(accountId string, startAt, endAt int64, options map[string]string, pagination *PaginationParam) (*ApiResponse, error) {
p := map[string]string{}
if startAt > 0 {
p["startAt"] = IntToString(startAt)
}
if endAt > 0 {
p["endAt"] = IntToString(endAt)
}
for k, v := range options {
p[k] = v
}
pagination.ReadParam(p)
req := NewRequest(http.MethodGet, fmt.Sprintf("/api/v1/accounts/%s/ledgers", accountId), p)
return as.Call(req)
}
// AccountLedgersV2 returns a list of ledgers.
// Recommended for use on Nov 05, 2020.
// Account activity either increases or decreases your account balance.
// Items are paginated and sorted latest first.
func (as *ApiService) AccountLedgersV2(params map[string]string, pagination *PaginationParam) (*ApiResponse, error) {
pagination.ReadParam(params)
req := NewRequest(http.MethodGet, "/api/v1/accounts/ledgers", params)
return as.Call(req)
}
// An AccountHoldModel represents the holds on an account for any active orders or pending withdraw requests.
// As an order is filled, the hold amount is updated.
// If an order is canceled, any remaining hold is removed.
// For a withdraw, once it is completed, the hold is removed.
type AccountHoldModel struct {
Currency string `json:"currency"`
HoldAmount string `json:"holdAmount"`
BizType string `json:"bizType"`
OrderId string `json:"orderId"`
CreatedAt int64 `json:"createdAt"`
UpdatedAt int64 `json:"updatedAt"`
}
// An AccountHoldsModel is the set of *AccountHoldModel.
type AccountHoldsModel []*AccountHoldModel
// AccountHolds returns a list of currency hold.
// Holds are placed on an account for any active orders or pending withdraw requests.
// As an order is filled, the hold amount is updated.
// If an order is canceled, any remaining hold is removed.
// For a withdraw, once it is completed, the hold is removed.
func (as *ApiService) AccountHolds(accountId string, pagination *PaginationParam) (*ApiResponse, error) {
p := map[string]string{}
pagination.ReadParam(p)
req := NewRequest(http.MethodGet, fmt.Sprintf("/api/v1/accounts/%s/holds", accountId), p)
return as.Call(req)
}
// An InnerTransferResultModel represents the result of a inner-transfer operation.
type InnerTransferResultModel struct {
OrderId string `json:"orderId"`
}
// InnerTransferV2 makes a currency transfer internally.
// Recommended for use on June 5, 2019.
// The inner transfer interface is used for transferring assets between the accounts of a user and is free of charges.
// For example, a user could transfer assets from their main account to their trading account on the platform.
func (as *ApiService) InnerTransferV2(clientOid, currency, from, to, amount string) (*ApiResponse, error) {
p := map[string]string{
"clientOid": clientOid,
"currency": currency,
"from": from,
"to": to,
"amount": amount,
}
req := NewRequest(http.MethodPost, "/api/v2/accounts/inner-transfer", p)
return as.Call(req)
}
// A SubTransferResultModel represents the result of a sub-transfer operation.
type SubTransferResultModel InnerTransferResultModel
// SubTransfer transfers between master account and sub-account.
// Deprecated: This interface was discontinued on Oct 28, 2020. Please use SubTransferV2.
func (as *ApiService) SubTransfer(params map[string]string) (*ApiResponse, error) {
req := NewRequest(http.MethodPost, "/api/v1/accounts/sub-transfer", params)
return as.Call(req)
}
// SubTransferV2 transfers between master account and sub-account.
// Recommended for use on Oct 28, 2020.
func (as *ApiService) SubTransferV2(params map[string]string) (*ApiResponse, error) {
req := NewRequest(http.MethodPost, "/api/v2/accounts/sub-transfer", params)
return as.Call(req)
}
// BaseFeeModel RESPONSES of BaseFee endpoint
type BaseFeeModel struct {
TakerFeeRate string `json:"takerFeeRate"`
MakerFeeRate string `json:"makerFeeRate"`
}
// BaseFee returns the basic fee rate of users.
func (as *ApiService) BaseFee(currencyType string) (*ApiResponse, error) {
p := map[string]string{
"currencyType": currencyType,
}
req := NewRequest(http.MethodGet, "/api/v1/base-fee", p)
return as.Call(req)
}
type TradeFeesResultModel []struct {
Symbol string `json:"symbol"`
TakerFeeRate string `json:"takerFeeRate"`
MakerFeeRate string `json:"makerFeeRate"`
}
// ActualFee returns the actual fee rate of the trading pair.
// You can inquire about fee rates of 10 trading pairs each time at most.
func (as *ApiService) ActualFee(symbols string) (*ApiResponse, error) {
p := map[string]string{
"symbols": symbols,
}
req := NewRequest(http.MethodGet, "/api/v1/trade-fees", p)
return as.Call(req)
}
// SubAccountUsersV2 returns a list of sub-account user by page.
func (as *ApiService) SubAccountUsersV2(pagination *PaginationParam) (*ApiResponse, error) {
p := map[string]string{}
pagination.ReadParam(p)
req := NewRequest(http.MethodGet, "/api/v2/sub/user", p)
return as.Call(req)
}
// UserSummaryInfoV2 returns summary information of user.
func (as *ApiService) UserSummaryInfoV2() (*ApiResponse, error) {
p := map[string]string{}
req := NewRequest(http.MethodGet, "/api/v2/user-info", p)
return as.Call(req)
}
// An UserSummaryInfoModelV2 represents an account.
type UserSummaryInfoModelV2 struct {
Level int `json:"level"`
SubQuantity int `json:"subQuantity"`
MaxDefaultSubQuantity int `json:"maxDefaultSubQuantity"`
MaxSubQuantity int `json:"maxSubQuantity"`
SpotSubQuantity int `json:"spotSubQuantity"`
MarginSubQuantity int `json:"marginSubQuantity"`
FuturesSubQuantity int `json:"futuresSubQuantity"`
MaxSpotSubQuantity int `json:"maxSpotSubQuantity"`
MaxMarginSubQuantity int `json:"maxMarginSubQuantity"`
MaxFuturesSubQuantity int `json:"maxFuturesSubQuantity"`
}
// CreateSubAccountV2 Create sub account v2.
func (as *ApiService) CreateSubAccountV2(password, remarks, subName, access string) (*ApiResponse, error) {
p := map[string]string{
"password": password,
"remarks": remarks,
"subName": subName,
"access": access,
}
req := NewRequest(http.MethodPost, "/api/v2/sub/user/created", p)
return as.Call(req)
}
// CreateSubAccountV2Res returns Create Sub account response
type CreateSubAccountV2Res struct {
Uid int64 `json:"uid"`
SubName string `json:"subName"`
Remarks string `json:"remarks"`
Access string `json:"access"`
}
// SubApiKey returns sub api key of spot.
func (as *ApiService) SubApiKey(subName, apiKey string) (*ApiResponse, error) {
p := map[string]string{
"apiKey": apiKey,
"subName": subName,
}
req := NewRequest(http.MethodGet, "/api/v1/sub/api-key", p)
return as.Call(req)
}
type SubApiKeyRes []*SubApiKeyModel
type SubApiKeyModel struct {
SubName string `json:"subName"`
Remark string `json:"remark"`
ApiKey string `json:"apiKey"`
Permission string `json:"permission"`
IpWhitelist string `json:"ipWhitelist"`
CreatedAt json.Number `json:"createdAt"`
}
// CreateSubApiKey create sub api key of spot.
func (as *ApiService) CreateSubApiKey(subName, passphrase, remark, permission, ipWhitelist, expire string) (*ApiResponse, error) {
p := map[string]string{
"passphrase": passphrase,
"subName": subName,
"remark": remark,
"permission": permission,
"ipWhitelist": ipWhitelist,
"expire": expire,
}
req := NewRequest(http.MethodPost, "/api/v1/sub/api-key", p)
return as.Call(req)
}
type CreateSubApiKeyRes struct {
ApiKey string `json:"apiKey"`
CreatedAt json.Number `json:"createdAt"`
IpWhitelist string `json:"ipWhitelist"`
Permission string `json:"permission"`
Remark string `json:"remark"`
SubName string `json:"subName"`
ApiSecret string `json:"apiSecret"`
Passphrase string `json:"passphrase"`
}
// UpdateSubApiKey update sub api key of spot.
func (as *ApiService) UpdateSubApiKey(subName, passphrase, apiKey, permission, ipWhitelist, expire string) (*ApiResponse, error) {
p := map[string]string{
"passphrase": passphrase,
"subName": subName,
"apiKey": apiKey,
"permission": permission,
"ipWhitelist": ipWhitelist,
"expire": expire,
}
req := NewRequest(http.MethodPost, "/api/v1/sub/api-key/update", p)
return as.Call(req)
}
type UpdateSubApiKeyRes struct {
ApiKey string `json:"apiKey"`
IpWhitelist string `json:"ipWhitelist"`
Permission string `json:"permission"`
SubName string `json:"subName"`
}
// DeleteSubApiKey delete sub api key of spot.
func (as *ApiService) DeleteSubApiKey(subName, passphrase, apiKey string) (*ApiResponse, error) {
p := map[string]string{
"passphrase": passphrase,
"subName": subName,
"apiKey": apiKey,
}
req := NewRequest(http.MethodDelete, "/api/v1/sub/api-key", p)
return as.Call(req)
}
type DeleteSubApiKeyRes struct {
ApiKey string `json:"apiKey"`
SubName string `json:"subName"`
}
// SubAccountsV2 returns subAccounts of user with page info.
func (as *ApiService) SubAccountsV2(pagination *PaginationParam) (*ApiResponse, error) {
p := map[string]string{}
pagination.ReadParam(p)
req := NewRequest(http.MethodGet, "/api/v2/sub-accounts", p)
return as.Call(req)
}