diff --git a/exchanges/account/account.go b/exchanges/account/account.go index 043635d9..db5b5116 100644 --- a/exchanges/account/account.go +++ b/exchanges/account/account.go @@ -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. diff --git a/exchanges/binance/binance_wrapper.go b/exchanges/binance/binance_wrapper.go index d54f8924..5aa470c5 100644 --- a/exchanges/binance/binance_wrapper.go +++ b/exchanges/binance/binance_wrapper.go @@ -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