Exchanges: Set AccountInfo ID when available (#882)

* Exchanges: Set AccountInfo ID when avaiable

* Rename CollectAccountBalances to CollectBalances and add checks
This commit is contained in:
khcchiu
2022-02-21 08:24:19 +08:00
committed by GitHub
parent 6127e2ab73
commit 5c8113b048
6 changed files with 99 additions and 26 deletions

View File

@@ -426,28 +426,28 @@ func (b *Bitmex) UpdateAccountInfo(ctx context.Context, assetType asset.Item) (a
return info, err
}
var accountID string
var balances []account.Balance
accountBalances := make(map[string][]account.Balance)
// Need to update to add Margin/Liquidity availability
for i := range userMargins {
accountID = strconv.FormatInt(userMargins[i].Account, 10)
accountID := strconv.FormatInt(userMargins[i].Account, 10)
wallet, err := b.GetWalletInfo(ctx, userMargins[i].Currency)
var wallet WalletInfo
wallet, err = b.GetWalletInfo(ctx, userMargins[i].Currency)
if err != nil {
continue
}
balances = append(balances, account.Balance{
CurrencyName: currency.NewCode(wallet.Currency),
TotalValue: wallet.Amount,
})
accountBalances[accountID] = append(
accountBalances[accountID], account.Balance{
CurrencyName: currency.NewCode(wallet.Currency),
TotalValue: wallet.Amount,
},
)
}
info.Accounts = append(info.Accounts,
account.SubAccount{
ID: accountID,
Currencies: balances,
})
if info.Accounts, err = account.CollectBalances(accountBalances, assetType); err != nil {
return account.Holdings{}, err
}
info.Exchange = b.Name
if err := account.Process(&info); err != nil {