diff --git a/DebugLog.js b/DebugLog.js index ba2c83788..7098aea4a 100644 --- a/DebugLog.js +++ b/DebugLog.js @@ -37,18 +37,25 @@ exports.newDebugLog = function newDebugLog() { } } - function newInternalLoop(pBot, pProcess, date) { + function newInternalLoop(pBot, pProcess, date, percentage) { + if (percentage === undefined) { + percentage = "" + } else { + percentage = percentage.toFixed(0) + "%" + } if (date === undefined) { date = thisObject.bot.processDatetime } + date = date.getUTCFullYear() + '-' + strPad(date.getUTCMonth() + 1, 2, "0") + '-' + strPad(date.getUTCDate(), 2, "0"); - console.log(new Date().toISOString() + " " + strPad(pBot, 20) + " " + strPad(pProcess, 30) + " " + strPad(thisObject.bot.exchange, 20) + " " + strPad(thisObject.bot.market.baseAsset + '/' + thisObject.bot.market.quotedAsset, 10) - + " Entered into Internal Loop # " + strPad(internalLoopCounter + 1, 8) + " " + strPad(date.toISOString(), 30)) + console.log(new Date().toISOString() + " " + strPad(thisObject.bot.exchange, 20) + " " + strPad(thisObject.bot.market.baseAsset + '/' + thisObject.bot.market.quotedAsset, 10) + " " + strPad(pBot, 20) + " " + strPad(pProcess, 30) + + " Internal Loop # " + strPad(internalLoopCounter + 1, 8) + " " + strPad(date, 30) + " " + strPad(percentage, 10)) persist(); - function strPad(str, max) { + function strPad(str, max, fill) { + if (fill === undefined) {fill = " "} str = str.toString(); - return str.length < max ? strPad(" " + str, max) : str; + return str.length < max ? strPad(fill + str, max) : str; } } diff --git a/FileStorage.js b/FileStorage.js index 374ab653a..2ec8a47ec 100644 --- a/FileStorage.js +++ b/FileStorage.js @@ -51,7 +51,7 @@ exports.newFileStorage = function newFileStorage(logger) { function onFileRead(err, text) { let retryTimeToUse = FAST_RETRY_TIME_IN_MILISECONDS - if (currentRetryGetTextFile < MAX_RETRY - 3) { + if (currentRetryGetTextFile > MAX_RETRY - 2) { retryTimeToUse = SLOW_RETRY_TIME_IN_MILISECONDS } if (err) { @@ -96,6 +96,7 @@ exports.newFileStorage = function newFileStorage(logger) { } function retry() { + //console.log(new Date(), ' Retry #: ' + currentRetryGetTextFile, fileLocation ) if (currentRetryGetTextFile < MAX_RETRY) { currentRetryGetTextFile++ logger.write(MODULE_NAME, '[WARN] FileStorage -> getTextFile -> retry -> Will try to read the file again -> Retry #: ' + currentRetryGetTextFile) @@ -150,7 +151,7 @@ exports.newFileStorage = function newFileStorage(logger) { function onFileWritenn(err) { let retryTimeToUse = FAST_RETRY_TIME_IN_MILISECONDS - if (currentRetryWriteTextFile < MAX_RETRY - 3) { + if (currentRetryWriteTextFile > MAX_RETRY - 2) { retryTimeToUse = SLOW_RETRY_TIME_IN_MILISECONDS } if (err) { diff --git a/IndicatorBotProcessMainLoop.js b/IndicatorBotProcessMainLoop.js index b2593efb9..1ec9eb324 100644 --- a/IndicatorBotProcessMainLoop.js +++ b/IndicatorBotProcessMainLoop.js @@ -145,8 +145,8 @@ /* High level log entry */ - console.log(new Date().toISOString() + " " + pad(bot.codeName, 20) + " " + pad(bot.process, 30) + " " + pad(bot.exchange, 20) + " " + pad(bot.market.baseAsset + '/' + bot.market.quotedAsset, 10) - + " Entered into Main Loop # " + pad(Number(bot.loopCounter), 8)); + console.log(new Date().toISOString() + " " + pad(bot.exchange, 20) + " " + pad(bot.market.baseAsset + '/' + bot.market.quotedAsset, 10) + " " + pad(bot.codeName, 20) + " " + pad(bot.process, 30) + + " Main Loop # " + pad(Number(bot.loopCounter), 8)) /* We will prepare first the infraestructure needed for the bot to run. There are 3 modules we need to sucessfullly initialize first. */ diff --git a/MultiPeriodDaily.js b/MultiPeriodDaily.js index 7502a677b..516737d4c 100644 --- a/MultiPeriodDaily.js +++ b/MultiPeriodDaily.js @@ -339,7 +339,12 @@ /* Telling the world we are alive and doing well */ let currentDateString = bot.multiPeriodDailyProcessDatetime.getUTCFullYear() + '-' + utilities.pad(bot.multiPeriodDailyProcessDatetime.getUTCMonth() + 1, 2) + '-' + utilities.pad(bot.multiPeriodDailyProcessDatetime.getUTCDate(), 2); let currentDate = new Date(bot.multiPeriodDailyProcessDatetime) - bot.processHeartBeat(currentDateString, global.getPercentage(fromDate, currentDate, lastDate)) + let percentage = global.getPercentage(fromDate, currentDate, lastDate) + bot.processHeartBeat(currentDateString, percentage) + + if (global.areEqualDates(currentDate, new Date()) === false) { + logger.newInternalLoop(bot.codeName, bot.process, currentDate, percentage); + } checkStopTaskGracefully(); @@ -811,9 +816,6 @@ bot.hasTheBotJustStarted = false; - if (global.areEqualDates(bot.multiPeriodDailyProcessDatetime, new Date()) === false) { - logger.newInternalLoop(bot.codeName, bot.process, bot.multiPeriodDailyProcessDatetime); - } } catch (err) { logger.write(MODULE_NAME, "[ERROR] start -> writeStatusReport -> err = "+ err.stack); diff --git a/SensorBotProcessMainLoop.js b/SensorBotProcessMainLoop.js index b627387b4..232131119 100644 --- a/SensorBotProcessMainLoop.js +++ b/SensorBotProcessMainLoop.js @@ -148,8 +148,8 @@ /* High level log entry */ - console.log(new Date().toISOString() + " " + pad(bot.codeName, 20) + " " + pad(bot.process, 30) + " " + pad(bot.exchange, 20) + " " + pad(bot.market.baseAsset + '/' + bot.market.quotedAsset, 10) - + " Entered into Main Loop # " + pad(Number(bot.loopCounter), 8) ) + console.log(new Date().toISOString() + " " + pad(bot.exchange, 20) + " " + pad(bot.market.baseAsset + '/' + bot.market.quotedAsset, 10) + " " + pad(bot.codeName, 20) + " " + pad(bot.process, 30) + + " Main Loop # " + pad(Number(bot.loopCounter), 8) ) /* We will prepare first the infraestructure needed for the bot to run. There are 4 modules we need to sucessfullly initialize first. */ diff --git a/TradingBotProcessMainLoop.js b/TradingBotProcessMainLoop.js index 472d1af46..5d4034129 100644 --- a/TradingBotProcessMainLoop.js +++ b/TradingBotProcessMainLoop.js @@ -157,8 +157,8 @@ /* High level log entry */ - console.log(new Date().toISOString() + " " + pad(bot.codeName, 20) + " " + pad(bot.process, 30) + " " + pad(bot.exchange, 20) + " " + pad(bot.market.baseAsset + '/' + bot.market.quotedAsset, 10) - + " Entered into Main Loop # " + pad(Number(bot.loopCounter), 8) + " " + bot.sessionKey ) + console.log(new Date().toISOString() + " " + pad(bot.exchange, 20) + " " + pad(bot.market.baseAsset + '/' + bot.market.quotedAsset, 10) + " " + pad(bot.codeName, 20) + " " + pad(bot.process, 30) + + " Main Loop # " + pad(Number(bot.loopCounter), 8) + " " + bot.sessionKey) /* Checking if we need to need to emit any event */ diff --git a/server.js b/server.js index b89fdff3d..947341e30 100644 --- a/server.js +++ b/server.js @@ -270,7 +270,7 @@ global.getPercentage = function (fromDate, currentDate, lastDate) { if ((lastDays - fromDays) === 0) { percentage = 100 } - return percentage.toFixed(0) + "%" + return percentage } global.areEqualDates = function (date1, date2) {