max: fix QueryAccount for margin

This commit is contained in:
c9s 2022-06-01 19:56:10 +08:00
parent b070952b32
commit 50accc5a2c
No known key found for this signature in database
GPG Key ID: 7385E7E464CB0A54
2 changed files with 23 additions and 24 deletions

View File

@ -551,22 +551,6 @@ func (e *Exchange) QueryAccount(ctx context.Context) (*types.Account, error) {
return nil, err
}
userInfo, err := e.client.AccountService.NewGetMeRequest().Do(ctx)
if err != nil {
return nil, err
}
var balances = make(types.BalanceMap)
for _, a := range userInfo.Accounts {
cur := toGlobalCurrency(a.Currency)
balances[toGlobalCurrency(a.Currency)] = types.Balance{
Currency: cur,
Available: a.Balance,
Locked: a.Locked,
NetAsset: a.Balance.Add(a.Locked),
}
}
vipLevel, err := e.client.AccountService.NewGetVipLevelRequest().Do(ctx)
if err != nil {
return nil, err
@ -583,6 +567,12 @@ func (e *Exchange) QueryAccount(ctx context.Context) (*types.Account, error) {
TakerFeeRate: fixedpoint.NewFromFloat(vipLevel.Current.TakerFee), // 0.15% = 0.0015
}
balances, err := e.QueryAccountBalances(ctx)
if err != nil {
return nil, err
}
a.UpdateBalances(balances)
if e.MarginSettings.IsMargin {
a.AccountType = types.AccountTypeMargin
@ -596,7 +586,6 @@ func (e *Exchange) QueryAccount(ctx context.Context) (*types.Account, error) {
a.TotalAccountValue = adRatio.AssetInUsdt
}
a.UpdateBalances(balances)
return a, nil
}
@ -766,20 +755,26 @@ func (e *Exchange) QueryAccountBalances(ctx context.Context) (types.BalanceMap,
return nil, err
}
accounts, err := e.client.AccountService.NewGetAccountsRequest().Do(ctx)
walletType := maxapi.WalletTypeSpot
if e.MarginSettings.IsMargin {
walletType = maxapi.WalletTypeMargin
}
req := e.v3order.NewGetWalletAccountsRequest(walletType)
accounts, err := req.Do(ctx)
if err != nil {
return nil, err
}
var balances = make(types.BalanceMap)
for _, a := range accounts {
cur := toGlobalCurrency(a.Currency)
for _, b := range accounts {
cur := toGlobalCurrency(b.Currency)
balances[cur] = types.Balance{
Currency: cur,
Available: a.Balance,
Locked: a.Locked,
NetAsset: a.Balance.Add(a.Locked),
Available: b.Balance,
Locked: b.Locked,
NetAsset: b.Balance.Add(b.Locked),
// Borrowed: b.Debt
}
}

View File

@ -23,6 +23,10 @@ type OrderService struct {
Client *maxapi.RestClient
}
func (s *OrderService) NewGetWalletAccountsRequest(walletType WalletType) *GetWalletAccountsRequest {
return &GetWalletAccountsRequest{client: s.Client, walletType: walletType}
}
func (s *OrderService) NewCreateWalletOrderRequest(walletType WalletType) *CreateWalletOrderRequest {
return &CreateWalletOrderRequest{client: s.Client, walletType: walletType}
}