diff --git a/IndicatorBotProcessMainLoop.js b/IndicatorBotProcessMainLoop.js index 17eceba01..b2593efb9 100644 --- a/IndicatorBotProcessMainLoop.js +++ b/IndicatorBotProcessMainLoop.js @@ -1076,10 +1076,11 @@ } } - function processHeartBeat(processingDate) { + function processHeartBeat(processingDate, percentage) { let event = { seconds: (new Date()).getSeconds(), - processingDate: processingDate + processingDate: processingDate, + percentage: percentage } global.SYSTEM_EVENT_HANDLER.raiseEvent(bot.processKey, 'Heartbeat', event) } diff --git a/MultiPeriodDaily.js b/MultiPeriodDaily.js index c9e9acc25..8666ed61c 100644 --- a/MultiPeriodDaily.js +++ b/MultiPeriodDaily.js @@ -307,6 +307,8 @@ let botNeverRan = true; bot.multiPeriodDailyProcessDatetime = new Date(contextVariables.lastFile.valueOf() - ONE_DAY_IN_MILISECONDS); // Go back one day to start well when we advance time at the begining of the loop. + let fromDate = new Date(bot.multiPeriodDailyProcessDatetime.valueOf()) + let lastDate = new Date() advanceTime(); @@ -334,6 +336,11 @@ } + /* 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)) + checkStopTaskGracefully(); } catch (err) { @@ -371,10 +378,6 @@ if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> processTimeFrames -> periodsLoop -> Entering function."); } - /* Telling the world we are alive and doing well */ - let processingDate = bot.multiPeriodDailyProcessDatetime.getUTCFullYear() + '-' + utilities.pad(bot.multiPeriodDailyProcessDatetime.getUTCMonth() + 1, 2) + '-' + utilities.pad(bot.multiPeriodDailyProcessDatetime.getUTCDate(), 2); - bot.processHeartBeat(processingDate) - /* We will iterate through all posible periods. diff --git a/SensorBotProcessMainLoop.js b/SensorBotProcessMainLoop.js index 669a503b9..b627387b4 100644 --- a/SensorBotProcessMainLoop.js +++ b/SensorBotProcessMainLoop.js @@ -812,10 +812,11 @@ } } - function processHeartBeat(processingDate) { + function processHeartBeat(processingDate, percentage) { let event = { seconds: (new Date()).getSeconds(), - processingDate: processingDate + processingDate: processingDate, + percentage: percentage } global.SYSTEM_EVENT_HANDLER.raiseEvent(bot.processKey, 'Heartbeat', event) } diff --git a/TradingBotProcessMainLoop.js b/TradingBotProcessMainLoop.js index fa1168f52..472d1af46 100644 --- a/TradingBotProcessMainLoop.js +++ b/TradingBotProcessMainLoop.js @@ -1000,10 +1000,11 @@ } } - function processHeartBeat(processingDate) { + function processHeartBeat(processingDate, percentage) { let event = { seconds: (new Date()).getSeconds(), - processingDate: processingDate + processingDate: processingDate, + percentage: percentage } global.SYSTEM_EVENT_HANDLER.raiseEvent(bot.processKey, 'Heartbeat', event) } diff --git a/TradingSimulation.js b/TradingSimulation.js index bb3de5360..358068502 100644 --- a/TradingSimulation.js +++ b/TradingSimulation.js @@ -4,7 +4,7 @@ const LOG_FILE_CONTENT = false; const MODULE_NAME = "Trading Simulation -> " + bot.SESSION.name; - const ONE_DAY_IN_MILISECONDS = 24 * 60 * 60 * 1000; + const GMT_SECONDS = ':00.000 GMT+0000'; let thisObject = { diff --git a/server.js b/server.js index c7523ea32..6f9c02d52 100644 --- a/server.js +++ b/server.js @@ -25,6 +25,8 @@ global.CUSTOM_FAIL_RESPONSE = { message: "Custom Message" }; +const ONE_DAY_IN_MILISECONDS = 24 * 60 * 60 * 1000; + /* Process Events */ process.on('uncaughtException', function (err) { @@ -260,3 +262,11 @@ function startRoot(processIndex) { } } +global.getPercentage = function (fromDate, currentDate, lastDate) { + let fromDays = Math.trunc(fromDate.valueOf() / ONE_DAY_IN_MILISECONDS) + let currentDays = Math.trunc(currentDate.valueOf() / ONE_DAY_IN_MILISECONDS) + let lastDays = Math.trunc(lastDate.valueOf() / ONE_DAY_IN_MILISECONDS) + let percentage = (currentDays - fromDays) * 100 / (lastDays - fromDays) + return percentage.toFixed(2) + " %" +} +