From 72ab99fabf2df42a4cc2c711ec2bd96f3902338a Mon Sep 17 00:00:00 2001 From: kuzetsa Date: Thu, 5 Dec 2013 12:12:28 -0500 Subject: [PATCH] actually refresh the portfolio before displaying balance bugfix for gekko having a stale internal state which doesn't match the actual balance in portfolio --- portfolioManager.js | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/portfolioManager.js b/portfolioManager.js index 639fe6508..54acfcf38 100644 --- a/portfolioManager.js +++ b/portfolioManager.js @@ -54,16 +54,24 @@ var Manager = function(conf, checker) { this.emit('ready'); }; - // callback function to refresh portfolio stats - var refreshPortfolio = function() { + // callback function to DISPLAY portfolio stats + var refreshPortfolioBeforeYouCanDisplay = function() { log.info('refreshed', this.exchange.name, 'portfolio:'); _.each(this.portfolio, function(fund) { log.info('\t', fund.name + ':', fund.amount); }); }; - // refresh portfolio stats every 11 minutes - setInterval(_.bind(refreshPortfolio, this), util.minToMs( 11 )); + // callback function to REFRESH portfolio stats + var displayPortfolio = function() { + // lazy way to do it without a major rewrite + async.series([ + this.setPortfolio + ], _.bind(refreshPortfolioBeforeYouCanDisplay, this)); + }; + + // refresh and display portfolio stats every 11 minutes + setInterval(_.bind(displayPortfolio, this), util.minToMs( 11 )); async.series([ this.setPortfolio,