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, SilenceUsage: true,
RunE: func(cmd *cobra.Command, args []string) error { 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 { if err != nil {
return err return err
} }

View File

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

View File

@ -19,7 +19,8 @@ var subAccountsCmd = &cobra.Command{
SilenceUsage: true, SilenceUsage: true,
RunE: func(cmd *cobra.Command, args []string) error { 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 { if err != nil {
return err return err
} }

View File

@ -56,7 +56,8 @@ func (e *Exchange) PlatformFeeCurrency() string {
} }
func (e *Exchange) QueryAccount(ctx context.Context) (*types.Account, error) { 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 { if err != nil {
return nil, err 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) { 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 { if err != nil {
return nil, err return nil, err
} }

View File

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