2021-12-10 13:43:40 +00:00
|
|
|
package kucoinapi
|
|
|
|
|
2021-12-10 16:25:55 +00:00
|
|
|
import "github.com/c9s/bbgo/pkg/fixedpoint"
|
2021-12-10 13:43:40 +00:00
|
|
|
|
|
|
|
type AccountService struct {
|
|
|
|
client *RestClient
|
|
|
|
}
|
|
|
|
|
|
|
|
type SubAccount struct {
|
|
|
|
UserID string `json:"userId"`
|
2021-12-21 16:30:16 +00:00
|
|
|
Name string `json:"subName"`
|
|
|
|
Type string `json:"type"`
|
2021-12-10 13:43:40 +00:00
|
|
|
Remark string `json:"remarks"`
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *AccountService) QuerySubAccounts() ([]SubAccount, error) {
|
2021-12-22 15:52:44 +00:00
|
|
|
req, err := s.client.NewAuthenticatedRequest("GET", "/api/v1/sub/user", nil, nil)
|
2021-12-10 13:43:40 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2021-12-22 15:52:44 +00:00
|
|
|
response, err := s.client.SendRequest(req)
|
2021-12-10 13:43:40 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
var apiResponse struct {
|
|
|
|
Code string `json:"code"`
|
|
|
|
Message string `json:"msg"`
|
|
|
|
Data []SubAccount `json:"data"`
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := response.DecodeJSON(&apiResponse); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2021-12-10 16:25:55 +00:00
|
|
|
return apiResponse.Data, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
type Account struct {
|
2021-12-21 16:30:16 +00:00
|
|
|
ID string `json:"id"`
|
|
|
|
Currency string `json:"currency"`
|
|
|
|
Type AccountType `json:"type"`
|
|
|
|
Balance fixedpoint.Value `json:"balance"`
|
2021-12-10 16:25:55 +00:00
|
|
|
Available fixedpoint.Value `json:"available"`
|
2021-12-21 16:30:16 +00:00
|
|
|
Holds fixedpoint.Value `json:"holds"`
|
2021-12-10 16:25:55 +00:00
|
|
|
}
|
|
|
|
|
2021-12-10 16:34:49 +00:00
|
|
|
func (s *AccountService) ListAccounts() ([]Account, error) {
|
2021-12-22 15:52:44 +00:00
|
|
|
req, err := s.client.NewAuthenticatedRequest("GET", "/api/v1/accounts", nil, nil)
|
2021-12-10 16:25:55 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2021-12-22 15:52:44 +00:00
|
|
|
response, err := s.client.SendRequest(req)
|
2021-12-10 16:25:55 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
var apiResponse struct {
|
2021-12-21 16:30:16 +00:00
|
|
|
Code string `json:"code"`
|
|
|
|
Message string `json:"msg"`
|
2021-12-10 16:25:55 +00:00
|
|
|
Data []Account `json:"data"`
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := response.DecodeJSON(&apiResponse); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2021-12-10 16:34:49 +00:00
|
|
|
return apiResponse.Data, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *AccountService) GetAccount(accountID string) (*Account, error) {
|
2021-12-22 15:52:44 +00:00
|
|
|
req, err := s.client.NewAuthenticatedRequest("GET", "/api/v1/accounts/"+accountID, nil, nil)
|
2021-12-10 16:34:49 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2021-12-22 15:52:44 +00:00
|
|
|
response, err := s.client.SendRequest(req)
|
2021-12-10 16:34:49 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
var apiResponse struct {
|
2021-12-21 16:30:16 +00:00
|
|
|
Code string `json:"code"`
|
|
|
|
Message string `json:"msg"`
|
2021-12-10 16:34:49 +00:00
|
|
|
Data *Account `json:"data"`
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := response.DecodeJSON(&apiResponse); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2021-12-10 13:43:40 +00:00
|
|
|
return apiResponse.Data, nil
|
2021-12-21 16:30:16 +00:00
|
|
|
}
|