kucoin: refactor account service api

This commit is contained in:
c9s 2022-01-01 02:04:20 +08:00
parent 4e747848f6
commit be408055a6
5 changed files with 18 additions and 17 deletions

View File

@ -27,7 +27,8 @@ var rootCmd = &cobra.Command{
SilenceUsage: true,
RunE: func(cmd *cobra.Command, args []string) error {
accounts, err := client.AccountService.ListAccounts(context.Background())
req := client.AccountService.NewListAccountsRequest()
accounts, err := req.Do(context.Background())
if err != nil {
return err
}

View File

@ -19,7 +19,8 @@ var accountsCmd = &cobra.Command{
RunE: func(cmd *cobra.Command, args []string) error {
if len(args) > 0 {
account, err := client.AccountService.GetAccount(context.Background(), args[0])
req := client.AccountService.NewGetAccountRequest(args[0])
account, err := req.Do(context.Background())
if err != nil {
return err
}
@ -28,7 +29,8 @@ var accountsCmd = &cobra.Command{
return nil
}
accounts, err := client.AccountService.ListAccounts(context.Background())
req := client.AccountService.NewListAccountsRequest()
accounts, err := req.Do(context.Background())
if err != nil {
return err
}

View File

@ -19,7 +19,8 @@ var subAccountsCmd = &cobra.Command{
SilenceUsage: true,
RunE: func(cmd *cobra.Command, args []string) error {
subAccounts, err := client.AccountService.ListSubAccounts(context.Background())
req := client.AccountService.NewListSubAccountsRequest()
subAccounts, err := req.Do(context.Background())
if err != nil {
return err
}

View File

@ -56,7 +56,8 @@ func (e *Exchange) PlatformFeeCurrency() string {
}
func (e *Exchange) QueryAccount(ctx context.Context) (*types.Account, error) {
accounts, err := e.client.AccountService.ListAccounts(ctx)
req := e.client.AccountService.NewListAccountsRequest()
accounts, err := req.Do(ctx)
if err != nil {
return nil, err
}
@ -69,7 +70,8 @@ func (e *Exchange) QueryAccount(ctx context.Context) (*types.Account, error) {
}
func (e *Exchange) QueryAccountBalances(ctx context.Context) (types.BalanceMap, error) {
accounts, err := e.client.AccountService.ListAccounts(ctx)
req := e.client.AccountService.NewListAccountsRequest()
accounts, err := req.Do(ctx)
if err != nil {
return nil, err
}

View File

@ -4,8 +4,6 @@ package kucoinapi
//go:generate -command PostRequest requestgen -method POST -responseType .APIResponse -responseDataField Data
import (
"context"
"github.com/c9s/requestgen"
"github.com/c9s/bbgo/pkg/fixedpoint"
@ -15,19 +13,16 @@ type AccountService struct {
client *RestClient
}
func (s *AccountService) ListSubAccounts(ctx context.Context) ([]SubAccount, error) {
req := &ListSubAccountsRequest{client: s.client}
return req.Do(ctx)
func (s *AccountService) NewListSubAccountsRequest() *ListSubAccountsRequest {
return &ListSubAccountsRequest{client: s.client}
}
func (s *AccountService) ListAccounts(ctx context.Context) ([]Account, error) {
req := &ListAccountsRequest{client: s.client}
return req.Do(ctx)
func (s *AccountService) NewListAccountsRequest() *ListAccountsRequest {
return &ListAccountsRequest{client: s.client}
}
func (s *AccountService) GetAccount(ctx context.Context, accountID string) (*Account, error) {
req := &GetAccountRequest{client: s.client, accountID: accountID}
return req.Do(ctx)
func (s *AccountService) NewGetAccountRequest(accountID string) *GetAccountRequest {
return &GetAccountRequest{client: s.client, accountID: accountID}
}
type SubAccount struct {