mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-05-13 23:16:45 +00:00
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:
@@ -409,7 +409,7 @@ func (bot *Engine) Start() error {
|
||||
|
||||
if bot.Settings.EnablePortfolioManager {
|
||||
if bot.portfolioManager == nil {
|
||||
if p, err := setupPortfolioManager(bot.ExchangeManager, bot.Settings.PortfolioManagerDelay, &bot.Config.Portfolio); err != nil {
|
||||
if p, err := setupPortfolioManager(bot.ExchangeManager, bot.Settings.PortfolioManagerDelay, bot.Config.Portfolio); err != nil {
|
||||
gctlog.Errorf(gctlog.Global, "portfolio manager unable to setup: %s", err)
|
||||
} else {
|
||||
bot.portfolioManager = p
|
||||
@@ -586,7 +586,7 @@ func (bot *Engine) Stop() {
|
||||
gctlog.Debugln(gctlog.Global, "Engine shutting down..")
|
||||
|
||||
if len(bot.portfolioManager.GetAddresses()) != 0 {
|
||||
bot.Config.Portfolio = *bot.portfolioManager.GetPortfolio()
|
||||
bot.Config.Portfolio = bot.portfolioManager.GetPortfolio()
|
||||
}
|
||||
|
||||
if bot.gctScriptManager.IsRunning() {
|
||||
|
||||
@@ -166,7 +166,7 @@ func (bot *Engine) SetSubsystem(subSystemName string, enable bool) error {
|
||||
case PortfolioManagerName:
|
||||
if enable {
|
||||
if bot.portfolioManager == nil {
|
||||
bot.portfolioManager, err = setupPortfolioManager(bot.ExchangeManager, bot.Settings.PortfolioManagerDelay, &bot.Config.Portfolio)
|
||||
bot.portfolioManager, err = setupPortfolioManager(bot.ExchangeManager, bot.Settings.PortfolioManagerDelay, bot.Config.Portfolio)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user