From b945ecdfbbdf4780f085dba5eb5775ff0d9a7f2d Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Sat, 5 Oct 2019 14:51:46 +0200 Subject: [PATCH] Dates in process heartbeat --- IndicatorBotProcessMainLoop.js | 10 ++++++---- MultiPeriod.js | 4 ++++ MultiPeriodDaily.js | 26 +++++++++++++++----------- SensorBotProcessMainLoop.js | 10 ++++++---- Session.js | 4 ++-- TradingEngineProcessMainLoop.js | 6 ++++-- 6 files changed, 37 insertions(+), 23 deletions(-) diff --git a/IndicatorBotProcessMainLoop.js b/IndicatorBotProcessMainLoop.js index 5d742c75e..dd451faec 100644 --- a/IndicatorBotProcessMainLoop.js +++ b/IndicatorBotProcessMainLoop.js @@ -119,7 +119,8 @@ if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] run -> loop -> Entering function."); } /* Loop Heartbeat sent to the UI */ - processHearBeat() + bot.processHeartBeat = processHeartBeat + processHeartBeat() /* We define here all the modules that the rest of the infraestructure, including the bots themselves can consume. */ @@ -801,7 +802,7 @@ /* We show we reached the end of the loop. */ - processHearBeat() + processHeartBeat() /* Here we check if we must stop the loop gracefully. */ @@ -929,9 +930,10 @@ } } - function processHearBeat() { + function processHeartBeat(processingDate) { let event = { - seconds: (new Date()).getSeconds() + seconds: (new Date()).getSeconds(), + processingDate: processingDate } global.SYSTEM_EVENT_HANDLER.raiseEvent(bot.processKey, 'Heartbeat', event) } diff --git a/MultiPeriod.js b/MultiPeriod.js index d9ccbfac2..42aed721b 100644 --- a/MultiPeriod.js +++ b/MultiPeriod.js @@ -542,6 +542,10 @@ if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> processTimePeriodsDailyFiles -> 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/MultiPeriodDaily.js b/MultiPeriodDaily.js index f7732a42b..0ca72c491 100644 --- a/MultiPeriodDaily.js +++ b/MultiPeriodDaily.js @@ -306,7 +306,7 @@ let n; 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. + bot.multiPeriodProcessDatetime = 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. advanceTime(); @@ -316,21 +316,21 @@ if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> processTimePeriods -> advanceTime -> Entering function."); } - bot.multiPeriodDailyProcessDatetime = new Date(bot.multiPeriodDailyProcessDatetime.valueOf() + ONE_DAY_IN_MILISECONDS); - previousDay = new Date(bot.multiPeriodDailyProcessDatetime.valueOf() - ONE_DAY_IN_MILISECONDS); + bot.multiPeriodProcessDatetime = new Date(bot.multiPeriodProcessDatetime.valueOf() + ONE_DAY_IN_MILISECONDS); + previousDay = new Date(bot.multiPeriodProcessDatetime.valueOf() - ONE_DAY_IN_MILISECONDS); - console.log(new Date().toISOString() + " " + pad(bot.codeName, 20) + " " + pad(bot.process, 30) + " " + "bot.multiPeriodDailyProcessDatetime = " + bot.multiPeriodDailyProcessDatetime.toISOString()); + console.log(new Date().toISOString() + " " + pad(bot.codeName, 20) + " " + pad(bot.process, 30) + " " + "bot.multiPeriodProcessDatetime = " + bot.multiPeriodProcessDatetime.toISOString()); if (global.WRITE_LOGS_TO_FILES === 'true') { logger.newInternalLoop(bot.codeName, bot.process); } - if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> processTimePeriods -> advanceTime -> bot.multiPeriodDailyProcessDatetime = " + bot.multiPeriodDailyProcessDatetime); } + if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> processTimePeriods -> advanceTime -> bot.multiPeriodProcessDatetime = " + bot.multiPeriodProcessDatetime); } if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> processTimePeriods -> advanceTime -> previousDay = " + previousDay); } /* Validation that we are not going past the head of the market. */ - if (bot.multiPeriodDailyProcessDatetime.valueOf() > contextVariables.dateEndOfMarket.valueOf()) { + if (bot.multiPeriodProcessDatetime.valueOf() > contextVariables.dateEndOfMarket.valueOf()) { const logText = "Head of the market found @ " + previousDay.getUTCFullYear() + "/" + (previousDay.getUTCMonth() + 1) + "/" + previousDay.getUTCDate() + "."; if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> processTimePeriods -> advanceTime -> " + logText); } @@ -354,6 +354,10 @@ if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> processTimePeriods -> periodsLoop -> Entering function."); } + /* Telling the world we are alive and doing well */ + let processingDate = bot.multiPeriodProcessDatetime.getUTCFullYear() + '-' + utilities.pad(bot.multiPeriodProcessDatetime.getUTCMonth() + 1, 2) + '-' + utilities.pad(bot.multiPeriodProcessDatetime.getUTCDate(), 2); + bot.processHeartBeat(processingDate) + /* We will iterate through all posible periods. @@ -410,7 +414,7 @@ let previousFile; let currentFile; - if (bot.multiPeriodDailyProcessDatetime.valueOf() > contextVariables.dateBeginOfMarket.valueOf()) { + if (bot.multiPeriodProcessDatetime.valueOf() > contextVariables.dateBeginOfMarket.valueOf()) { getPreviousFile(); } else { previousFile = []; @@ -493,7 +497,7 @@ if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> processTimePeriods -> periodsLoopBody -> dependencyLoopBody -> getCurrentFile -> Entering function."); } - let dateForPath = bot.multiPeriodDailyProcessDatetime.getUTCFullYear() + '/' + utilities.pad(bot.multiPeriodDailyProcessDatetime.getUTCMonth() + 1, 2) + '/' + utilities.pad(bot.multiPeriodDailyProcessDatetime.getUTCDate(), 2); + let dateForPath = bot.multiPeriodProcessDatetime.getUTCFullYear() + '/' + utilities.pad(bot.multiPeriodProcessDatetime.getUTCMonth() + 1, 2) + '/' + utilities.pad(bot.multiPeriodProcessDatetime.getUTCDate(), 2); let filePath if (dependency.dataSet === "Multi-Period-Daily") { filePath = dependency.product + '/' + dependency.dataSet + "/" + outputPeriodLabel + "/" + dateForPath; @@ -600,7 +604,7 @@ dataFiles, timePeriod, outputPeriodLabel, - bot.multiPeriodDailyProcessDatetime, + bot.multiPeriodProcessDatetime, contextVariables.dateBeginOfMarket, contextVariables.dateEndOfMarket, interExecutionMemoryArray[n], @@ -669,7 +673,7 @@ return; } - writeStatusReport(bot.multiPeriodDailyProcessDatetime, advanceTime); + writeStatusReport(bot.multiPeriodProcessDatetime, advanceTime); } catch (err) { logger.write(MODULE_NAME, "[ERROR] start -> processTimePeriods -> controlLoop -> onWritten -> err = "+ err.stack); @@ -704,7 +708,7 @@ let folderName = bot.products[productIndex].codeName; - writeDataRange(contextVariables.dateBeginOfMarket, bot.multiPeriodDailyProcessDatetime, folderName, controlLoop); + writeDataRange(contextVariables.dateBeginOfMarket, bot.multiPeriodProcessDatetime, folderName, controlLoop); } function controlLoop() { diff --git a/SensorBotProcessMainLoop.js b/SensorBotProcessMainLoop.js index b37e8a9ee..3d20a878d 100644 --- a/SensorBotProcessMainLoop.js +++ b/SensorBotProcessMainLoop.js @@ -121,7 +121,8 @@ if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] run -> loop -> Entering function."); } /* Loop Heartbeat sent to the UI */ - processHearBeat() + bot.processHeartBeat = processHeartBeat + processHeartBeat() /* We define here all the modules that the rest of the infraestructure, including the bots themselves can consume. */ @@ -547,7 +548,7 @@ /* We show we reached the end of the loop. */ - processHearBeat() + processHeartBeat() /* Here we check if we must stop the loop gracefully. */ @@ -701,9 +702,10 @@ } } - function processHearBeat() { + function processHeartBeat(processingDate) { let event = { - seconds: (new Date()).getSeconds() + seconds: (new Date()).getSeconds(), + processingDate: processingDate } global.SYSTEM_EVENT_HANDLER.raiseEvent(bot.processKey, 'Heartbeat', event) } diff --git a/Session.js b/Session.js index 62f51a569..07e526339 100644 --- a/Session.js +++ b/Session.js @@ -61,7 +61,7 @@ bot.startMode = "Backtest" bot.resumeExecution = false; bot.hasTheBotJustStarted = true - bot.multiPeriodDailyProcessDatetime = bot.VALUES_TO_USE.timeRange.initialDatetime + bot.multiPeriodProcessDatetime = bot.VALUES_TO_USE.timeRange.initialDatetime } function startLiveTrading(message) { @@ -93,7 +93,7 @@ bot.VALUES_TO_USE.timeRange.initialDatetime = new Date() } bot.resumeExecution = false; - bot.multiPeriodDailyProcessDatetime = bot.VALUES_TO_USE.timeRange.initialDatetime + bot.multiPeriodProcessDatetime = bot.VALUES_TO_USE.timeRange.initialDatetime bot.hasTheBotJustStarted = true } diff --git a/TradingEngineProcessMainLoop.js b/TradingEngineProcessMainLoop.js index d6d7a6b8c..efc4c8143 100644 --- a/TradingEngineProcessMainLoop.js +++ b/TradingEngineProcessMainLoop.js @@ -127,6 +127,7 @@ /* Heartbeats sent to the UI */ bot.sessionHeartBeat = sessionHeartBeat + bot.processHeartBeat = processHeartBeat processHeartBeat() /* We define here all the modules that the rest of the infraestructure, including the bots themselves can consume. */ @@ -1053,9 +1054,10 @@ } } - function processHeartBeat() { + function processHeartBeat(processingDate) { let event = { - seconds: (new Date()).getSeconds() + seconds: (new Date()).getSeconds(), + processingDate: processingDate } global.SYSTEM_EVENT_HANDLER.raiseEvent(bot.processKey, 'Heartbeat', event) }