portfolio: Fix CryptoID balance issue and assertify tests (#1861)

* portfolio: Fix CryptoID balance issue and assertify tests

* portfolio: Expand context usage, enhance tests and a few other minor improvements

* portfolio: Further improvements and enhance common.IsValidCryptoAddress

* config, portfolio: Use v6.DefaultConfig, switch to context.WithCancel
This commit is contained in:
Adrian Gallagher
2025-03-28 12:41:01 +11:00
committed by GitHub
parent 06afde1460
commit cc05f7e6fd
16 changed files with 723 additions and 845 deletions

View File

@@ -41,6 +41,7 @@ func setupPortfolioManager(e *ExchangeManager, portfolioManagerDelay time.Durati
if portfolioManagerDelay <= 0 {
portfolioManagerDelay = PortfolioSleepDelay
}
if cfg == nil {
cfg = &portfolio.Base{Addresses: []portfolio.Address{}}
}
@@ -130,21 +131,14 @@ func (m *portfolioManager) processPortfolio() {
allExchangesHoldings := m.getExchangeAccountInfo(exchanges)
m.seedExchangeAccountInfo(allExchangesHoldings)
data := m.base.GetPortfolioGroupedCoin()
data := m.base.GetPortfolioAddressesGroupedByCoin()
for key, value := range data {
err := m.base.UpdatePortfolio(value, key)
if err != nil {
log.Errorf(log.PortfolioMgr,
"PortfolioWatcher error %s for currency %s\n",
err,
key)
if err := m.base.UpdatePortfolio(context.TODO(), value, key); err != nil {
log.Errorf(log.PortfolioMgr, "Portfolio manager: UpdatePortfolio error: %s for currency %s\n", err, key)
continue
}
log.Debugf(log.PortfolioMgr,
"Portfolio manager: Successfully updated address balance for %s address(es) %s\n",
key,
value)
log.Debugf(log.PortfolioMgr, "Portfolio manager: Successfully updated address balance for %s address(es) %s\n", key, value)
}
atomic.CompareAndSwapInt32(&m.processing, 1, 0)
}
@@ -182,7 +176,7 @@ func (m *portfolioManager) seedExchangeAccountInfo(accounts []account.Holdings)
}
for j := range currencies {
if !m.base.ExchangeAddressExists(accounts[x].Exchange, currencies[j].Currency) {
if !m.base.ExchangeAddressCoinExists(accounts[x].Exchange, currencies[j].Currency) {
if currencies[j].Total <= 0 {
continue
}