maxapi: add account service tests

This commit is contained in:
c9s 2022-04-20 13:28:39 +08:00
parent f9df65a2f8
commit 68abeb826b
3 changed files with 71 additions and 9 deletions

View File

@ -621,7 +621,7 @@ func (e *Exchange) QueryAccount(ctx context.Context) (*types.Account, error) {
return nil, err
}
userInfo, err := e.client.AccountService.NewGetMeRequest()
userInfo, err := e.client.AccountService.NewGetMeRequest().Do(ctx)
if err != nil {
return nil, err
}
@ -630,8 +630,8 @@ func (e *Exchange) QueryAccount(ctx context.Context) (*types.Account, error) {
for _, a := range userInfo.Accounts {
balances[toGlobalCurrency(a.Currency)] = types.Balance{
Currency: toGlobalCurrency(a.Currency),
Available: fixedpoint.Must(fixedpoint.NewFromString(a.Balance)),
Locked: fixedpoint.Must(fixedpoint.NewFromString(a.Locked)),
Available: a.Balance,
Locked: a.Locked,
}
}
@ -828,8 +828,8 @@ func (e *Exchange) QueryAccountBalances(ctx context.Context) (types.BalanceMap,
for _, a := range accounts {
balances[toGlobalCurrency(a.Currency)] = types.Balance{
Currency: toGlobalCurrency(a.Currency),
Available: fixedpoint.Must(fixedpoint.NewFromString(a.Balance)),
Locked: fixedpoint.Must(fixedpoint.NewFromString(a.Locked)),
Available: a.Balance,
Locked: a.Locked,
}
}

View File

@ -7,6 +7,8 @@ import (
"context"
"github.com/c9s/requestgen"
"github.com/c9s/bbgo/pkg/fixedpoint"
)
type AccountService struct {
@ -15,10 +17,12 @@ type AccountService struct {
// Account is for max rest api v2, Balance and Type will be conflict with types.PrivateBalanceUpdate
type Account struct {
Currency string `json:"currency"`
Balance string `json:"balance"`
Locked string `json:"locked"`
Type string `json:"type"`
Currency string `json:"currency"`
Balance fixedpoint.Value `json:"balance"`
Locked fixedpoint.Value `json:"locked"`
Type string `json:"type"`
FiatCurrency string `json:"fiat_currency"`
FiatBalance fixedpoint.Value `json:"fiat_balance"`
}
// Balance is for kingfisher
@ -98,6 +102,10 @@ type GetAccountRequest struct {
currency string `param:"currency,slug"`
}
func (s *AccountService) NewGetAccountRequest() *GetAccountRequest {
return &GetAccountRequest{client: s.client}
}
func (s *AccountService) NewGetWithdrawalHistoryRequest() *GetWithdrawHistoryRequest {
return &GetWithdrawHistoryRequest{
client: s.client,

View File

@ -0,0 +1,54 @@
package max
import (
"context"
"testing"
"github.com/stretchr/testify/assert"
)
func TestAccountService_GetAccountsRequest(t *testing.T) {
key, secret, ok := integrationTestConfigured(t, "MAX")
if !ok {
t.SkipNow()
}
ctx := context.Background()
client := NewRestClient(ProductionAPIURL)
client.Auth(key, secret)
req := client.AccountService.NewGetAccountsRequest()
accounts, err := req.Do(ctx)
assert.NoError(t, err)
assert.NotNil(t, accounts)
assert.NotEmpty(t, accounts)
t.Logf("accounts: %+v", accounts)
}
func TestAccountService_GetAccountRequest(t *testing.T) {
key, secret, ok := integrationTestConfigured(t, "MAX")
if !ok {
t.SkipNow()
}
ctx := context.Background()
client := NewRestClient(ProductionAPIURL)
client.Auth(key, secret)
req := client.AccountService.NewGetAccountRequest()
req.Currency("twd")
account, err := req.Do(ctx)
assert.NoError(t, err)
assert.NotNil(t, account)
t.Logf("account: %+v", account)
req2 := client.AccountService.NewGetAccountRequest()
req2.Currency("usdt")
account, err = req.Do(ctx)
assert.NoError(t, err)
assert.NotNil(t, account)
t.Logf("account: %+v", account)
}