mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-10 09:11:55 +00:00
maxapi: add account service tests
This commit is contained in:
parent
f9df65a2f8
commit
68abeb826b
|
@ -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,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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,
|
||||
|
|
54
pkg/exchange/max/maxapi/account_test.go
Normal file
54
pkg/exchange/max/maxapi/account_test.go
Normal 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)
|
||||
}
|
Loading…
Reference in New Issue
Block a user