mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-05-13 23:16:45 +00:00
account: fix balance issue returning only one balance (#1478)
* fix issue with single-pop response * minor fixes * simplify return
This commit is contained in:
@@ -25,7 +25,6 @@ var (
|
||||
errAssetHoldingsNotFound = errors.New("asset holdings not found")
|
||||
errExchangeAccountsNotFound = errors.New("exchange accounts not found")
|
||||
errNoExchangeSubAccountBalances = errors.New("no exchange sub account balances")
|
||||
errNoBalanceFound = errors.New("no balance found")
|
||||
errBalanceIsNil = errors.New("balance is nil")
|
||||
errNoCredentialBalances = errors.New("no balances associated with credentials")
|
||||
errCredentialsAreNil = errors.New("credentials are nil")
|
||||
@@ -106,7 +105,7 @@ func GetHoldings(exch string, creds *Credentials, assetType asset.Item) (Holding
|
||||
}
|
||||
|
||||
var currencyBalances = make([]Balance, 0, len(subAccountHoldings))
|
||||
accountsHoldings := make([]SubAccount, 0, len(subAccountHoldings))
|
||||
cpy := *creds
|
||||
for mapKey, assetHoldings := range subAccountHoldings {
|
||||
if mapKey.Asset != assetType {
|
||||
continue
|
||||
@@ -121,32 +120,24 @@ func GetHoldings(exch string, creds *Credentials, assetType asset.Item) (Holding
|
||||
Borrowed: assetHoldings.borrowed,
|
||||
})
|
||||
assetHoldings.m.Unlock()
|
||||
|
||||
if len(currencyBalances) == 0 {
|
||||
continue
|
||||
}
|
||||
|
||||
cpy := *creds
|
||||
if cpy.SubAccount == "" {
|
||||
if cpy.SubAccount == "" && mapKey.SubAccount != "" {
|
||||
// TODO: fix this backwards population
|
||||
// the subAccount here may not be associated with the balance across all subAccountHoldings
|
||||
cpy.SubAccount = mapKey.SubAccount
|
||||
}
|
||||
|
||||
accountsHoldings = append(accountsHoldings, SubAccount{
|
||||
Credentials: Protected{creds: cpy},
|
||||
ID: mapKey.SubAccount,
|
||||
AssetType: mapKey.Asset,
|
||||
Currencies: currencyBalances,
|
||||
})
|
||||
break
|
||||
}
|
||||
|
||||
if len(accountsHoldings) == 0 {
|
||||
if len(currencyBalances) == 0 {
|
||||
return Holdings{}, fmt.Errorf("%s %s %w",
|
||||
exch,
|
||||
assetType,
|
||||
errAssetHoldingsNotFound)
|
||||
}
|
||||
return Holdings{Exchange: exch, Accounts: accountsHoldings}, nil
|
||||
return Holdings{Exchange: exch, Accounts: []SubAccount{{
|
||||
Credentials: Protected{creds: cpy},
|
||||
ID: cpy.SubAccount,
|
||||
AssetType: assetType,
|
||||
Currencies: currencyBalances,
|
||||
}}}, nil
|
||||
}
|
||||
|
||||
// GetBalance returns the internal balance for that asset item.
|
||||
|
||||
@@ -646,6 +646,14 @@ func (b *Binance) UpdateAccountInfo(ctx context.Context, assetType asset.Item) (
|
||||
info.Exchange = b.Name
|
||||
switch assetType {
|
||||
case asset.Spot:
|
||||
creds, err := b.GetCredentials(ctx)
|
||||
if err != nil {
|
||||
return info, err
|
||||
}
|
||||
if creds.SubAccount != "" {
|
||||
// TODO: implement sub-account endpoints
|
||||
return info, common.ErrNotYetImplemented
|
||||
}
|
||||
raw, err := b.GetAccount(ctx)
|
||||
if err != nil {
|
||||
return info, err
|
||||
|
||||
Reference in New Issue
Block a user