diff --git a/Legacy-Code/AAMasters/bots/AABruce-Indicator-Bot/Single-Period-Daily/User.Bot.js b/Legacy-Code/AAMasters/bots/AABruce-Indicator-Bot/Single-Period-Daily/User.Bot.js index d285f0b9e..3c2031fe5 100644 --- a/Legacy-Code/AAMasters/bots/AABruce-Indicator-Bot/Single-Period-Daily/User.Bot.js +++ b/Legacy-Code/AAMasters/bots/AABruce-Indicator-Bot/Single-Period-Daily/User.Bot.js @@ -24,65 +24,19 @@ let utilities = UTILITIES.newCloudUtilities(bot, logger); - let year; - let month; - let statusDependencies; return thisObject; - function initialize(pStatusDependencies, pMonth, pYear, callBackFunction) { + function initialize(pStatusDependencies, callBackFunction) { - try { + statusDependencies = pStatusDependencies; - year = pYear; - month = pMonth; - month = utilities.pad(month, 2); // Adding a left zero when needed. - statusDependencies = pStatusDependencies; + logger.fileName = MODULE_NAME + logger.initialize(); - logger.fileName = MODULE_NAME + "-" + year + "-" + month; - logger.initialize(); + callBackFunction(global.DEFAULT_OK_RESPONSE); - if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] initialize -> Entering function."); } - if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] initialize -> pYear = " + year); } - if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] initialize -> pMonth = " + month); } - - /* The very first validation is about if we are not too far in the future. In those cases we will not proceed and expect this instance to be restarted later. */ - - let processDate = new Date(year + "-" + month + "-1 00:00:00.000 GMT+0000"); - let today = new Date(); - let tomorrow = new Date(today.valueOf() + 1000 * 60 * 60 * 24); - - if (processDate.valueOf() > tomorrow.valueOf()) { // This means that it should start more than a day from current time. - logger.write(MODULE_NAME, "[WARN] initialize -> Too far in the future."); - - let customOK = { - result: global.CUSTOM_OK_RESPONSE.result, - message: "Too far in the future." - } - logger.write(MODULE_NAME, "[WARN] initialize -> customOK = " + customOK.message); - callBackFunction(customOK); - return; - } - - if (processDate.valueOf() > today.valueOf()) { // This means that is should start in less than a day from current time. - logger.write(MODULE_NAME, "[WARN] initialize -> Not needed now, but soon."); - - let customOK = { - result: global.CUSTOM_OK_RESPONSE.result, - message: "Not needed now, but soon." - } - logger.write(MODULE_NAME, "[WARN] initialize -> customOK = " + customOK.message); - callBackFunction(customOK); - return; - } - - callBackFunction(global.DEFAULT_OK_RESPONSE); - - } catch (err) { - logger.write(MODULE_NAME, "[ERROR] initialize -> err = " + err.stack); - callBackFunction(global.DEFAULT_FAIL_RESPONSE); - } } /* @@ -96,26 +50,15 @@ if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> Entering function."); } - let processDate = new Date(year + "-" + month + "-1 00:00:00.000 GMT+0000"); - let lastMinuteOfMonth = new Date(year + "-" + month + "-1 00:00:00.000 GMT+0000"); - - lastMinuteOfMonth.setUTCMonth(lastMinuteOfMonth.getUTCMonth() + 1); // First we go 1 month into the future. - lastMinuteOfMonth.setUTCSeconds(lastMinuteOfMonth.getUTCSeconds() - 30); // Then we go back 30 seconds, or to the last minute of the original month. + let processDate = new Date((new Date()).getUTCFullYear() + "-" + ((new Date()).getUTCMonth() + 1) + "-1 00:00:00.000 GMT+0000"); let thisDatetime = new Date(); - let atHeadOfMarket; // This tell us if we are at the month which includes the head of the market according to current datetime. - if ((parseInt(year) === thisDatetime.getUTCFullYear() && parseInt(month) === thisDatetime.getUTCMonth() + 1)) { - atHeadOfMarket = true; - } else { - atHeadOfMarket = false; - } - let market = bot.market; let lastHoleFixedFile; // Datetime of the last file certified by the Hole Fixing process as without permanent holes. let firstTradeFile; // Datetime of the first trade file in the whole market history. - let lastFileWithoutHoles; // Datetime of the last verified file without holes. + let lastTradeFileSaved; // Datetime of the last verified file without holes. let lastCandleClose; // Value of the last candle close. let lastTradeFile; // Datetime pointing to the last Trade File sucessfuly processed and included in the last file. @@ -131,7 +74,6 @@ let reportKey; /* First Status Report */ - reportKey = "AAMasters" + "-" + "AACharly" + "-" + "Historic-Trades" + "-" + "dataSet.V1"; if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> getContextVariables -> reportKey = " + reportKey); } @@ -156,95 +98,12 @@ return; } - if (thisReport.completeHistory === true) { // We get from the file to know if this markets history is complete or not. - - firstTradeFile = new Date(thisReport.beginingOfMarket.year + "-" + thisReport.beginingOfMarket.month + "-" + thisReport.beginingOfMarket.days + " " + thisReport.beginingOfMarket.hours + ":" + thisReport.beginingOfMarket.minutes + GMT_SECONDS); - - /* Before processing this month we need to check if it is not too far in the past.*/ - - if ( - processDate.getUTCFullYear() < firstTradeFile.getUTCFullYear() - || - (processDate.getUTCFullYear() === firstTradeFile.getUTCFullYear() && processDate.getUTCMonth() < firstTradeFile.getUTCMonth()) - ) { - logger.write(MODULE_NAME, "[WARN] start -> getContextVariables -> The current year / month is before the start of the market history for market."); - let customOK = { - result: global.CUSTOM_OK_RESPONSE.result, - message: "Month before it is needed." - } - logger.write(MODULE_NAME, "[WARN] start -> getContextVariables -> customOK = " + customOK.message); - callBackFunction(customOK); - return; - } - - } else { - logger.write(MODULE_NAME, "[WARN] start -> getContextVariables -> Trade History is not complete."); - - let customOK = { - result: global.CUSTOM_OK_RESPONSE.result, - message: "Dependency not ready." - } - logger.write(MODULE_NAME, "[WARN] start -> getContextVariables -> customOK = " + customOK.message); - callBackFunction(customOK); - return; - } - - /* Next Status Report */ - - reportKey = "AAMasters" + "-" + "AACharly" + "-" + "Historic-Trades" + "-" + "dataSet.V1" - if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> getContextVariables -> reportKey = " + reportKey); } - - if (statusDependencies.statusReports.get(reportKey).status === "Status Report is corrupt.") { - logger.write(MODULE_NAME, "[ERROR] start -> getContextVariables -> Can not continue because dependecy Status Report is corrupt. "); - callBackFunction(global.DEFAULT_RETRY_RESPONSE); - return; - } - - thisReport = statusDependencies.statusReports.get(reportKey).file; - - if (thisReport.lastFileSaved === undefined) { - logger.write(MODULE_NAME, "[WARN] start -> getContextVariables -> Undefined Last File. -> reportKey = " + reportKey); - logger.write(MODULE_NAME, "[HINT] start -> getContextVariables -> It is too early too run this process since the hole fixing process has not started yet for this month."); - - let customOK = { - result: global.CUSTOM_OK_RESPONSE.result, - message: "Dependency does not exist." - } - logger.write(MODULE_NAME, "[WARN] start -> getContextVariables -> customOK = " + customOK.message); - callBackFunction(customOK); - return; - } - - if (thisReport.monthChecked === true) { - - lastFileWithoutHoles = new Date(); // We need this with a valid value. - - } else { - - /* - If the hole report is incomplete, we are only interested if we are at the head of the market. - Otherwise, we are not going to calculate the candles of a month which was not fully checked for holes. - */ - - if (atHeadOfMarket === true) { - - lastFileWithoutHoles = new Date(thisReport.lastFileSaved.year + "-" + thisReport.lastFileSaved.month + "-" + thisReport.lastFileSaved.days + " " + thisReport.lastFileSaved.hours + ":" + thisReport.lastFileSaved.minutes + GMT_SECONDS); - - } else { - - let customOK = { - result: global.CUSTOM_OK_RESPONSE.result, - message: "Dependency not ready." - } - logger.write(MODULE_NAME, "[WARN] start -> getContextVariables -> customOK = " + customOK.message); - callBackFunction(customOK); - return; - } - } + firstTradeFile = new Date(thisReport.beginingOfMarket.year + "-" + thisReport.beginingOfMarket.month + "-" + thisReport.beginingOfMarket.days + " " + thisReport.beginingOfMarket.hours + ":" + thisReport.beginingOfMarket.minutes + GMT_SECONDS); + lastTradeFileSaved = new Date(thisReport.lastFileSaved.year + "-" + thisReport.lastFileSaved.month + "-" + thisReport.lastFileSaved.days + " " + thisReport.lastFileSaved.hours + ":" + thisReport.lastFileSaved.minutes + GMT_SECONDS); /* Final Status Report */ - reportKey = "AAMasters" + "-" + "AABruce" + "-" + "Single-Period-Daily" + "-" + "dataSet.V1" + "-" + year + "-" + month; + reportKey = "AAMasters" + "-" + "AABruce" + "-" + "Single-Period-Daily" + "-" + "dataSet.V1" if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> getContextVariables -> reportKey = " + reportKey); } if (statusDependencies.statusReports.get(reportKey).status === "Status Report is corrupt.") { @@ -264,34 +123,16 @@ return; } - if (thisReport.monthCompleted === true) { - - logger.write(MODULE_NAME, "[WARN] start -> getContextVariables -> The current year / month was already fully processed."); - - let customOK = { - result: global.CUSTOM_OK_RESPONSE.result, - message: "Month fully processed." - } - logger.write(MODULE_NAME, "[WARN] start -> getContextVariables -> customOK = " + customOK.message); - callBackFunction(customOK); - return; + lastHoleFixedFile = new Date(thisReport.lastTradeFile.year + "-" + thisReport.lastTradeFile.month + "-" + thisReport.lastTradeFile.days + " " + "00:00" + GMT_SECONDS); + lastCandleClose = thisReport.candleClose; + if (thisReport.fileComplete === true) { + buildCandlesAndVolumes(); } else { - - lastHoleFixedFile = new Date(thisReport.lastTradeFile.year + "-" + thisReport.lastTradeFile.month + "-" + thisReport.lastTradeFile.days + " " + "00:00" + GMT_SECONDS); - lastCandleClose = thisReport.candleClose; - - if (thisReport.fileComplete === true) { - - buildCandlesAndVolumes(); - - } else { - - lastTradeFile = new Date(thisReport.lastTradeFile.year + "-" + thisReport.lastTradeFile.month + "-" + thisReport.lastTradeFile.days + " " + thisReport.lastTradeFile.hours + ":" + thisReport.lastTradeFile.minutes + GMT_SECONDS); - findPreviousContent(); - } + lastTradeFile = new Date(thisReport.lastTradeFile.year + "-" + thisReport.lastTradeFile.month + "-" + thisReport.lastTradeFile.days + " " + thisReport.lastTradeFile.hours + ":" + thisReport.lastTradeFile.minutes + GMT_SECONDS); + findPreviousContent(); } - + } catch (err) { logger.write(MODULE_NAME, "[ERROR] start -> getContextVariables -> err = " + err.stack); if (err.message === "Cannot read property 'file' of undefined") { @@ -436,7 +277,7 @@ Before going backwards, we need to be sure we are not at the begining of the market. */ - if ((Number(year) === firstTradeFile.getUTCFullYear() && parseInt(month) === firstTradeFile.getUTCMonth() + 1)) { + if ((Number((new Date()).getUTCFullYear()) === firstTradeFile.getUTCFullYear() && parseInt(((new Date()).getUTCMonth() + 1)) === firstTradeFile.getUTCMonth() + 1)) { /* We are at the begining of the market, so we will set everyting to build the first candle. @@ -652,47 +493,9 @@ } } - /* Check if we are outside the currrent Month */ - - if (date.getUTCMonth() + 1 !== parseInt(month)) { - - if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> buildCandlesAndVolumes -> nextFile -> nextDate -> End of the month reached at date = " + date.toUTCString()); } - - lastHoleFixedFile = new Date(lastHoleFixedFile.valueOf() - ONE_DAY_IN_MILISECONDS); - - writeStatusReport(lastHoleFixedFile, lastTradeFile, lastCandleClose, true, true, onStatusReportWritten); - return; - - function onStatusReportWritten(err) { - - try { - if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> buildCandlesAndVolumes -> nextFile -> nextDate -> onStatusReportWritten -> Entering function."); } - - if (err.result !== global.DEFAULT_OK_RESPONSE.result) { - logger.write(MODULE_NAME, "[ERROR] start -> buildCandlesAndVolumes -> nextFile -> nextDate -> onStatusReportWritten -> err = " + err.stack); - callBackFunction(err); - return; - } - - let customOK = { - result: global.CUSTOM_OK_RESPONSE.result, - message: "End of the month reached." - } - logger.write(MODULE_NAME, "[WARN] start -> buildCandlesAndVolumes -> nextFile -> nextDate -> onStatusReportWritten -> customOK = " + customOK.message); - callBackFunction(customOK); - - return; - } catch (err) { - logger.write(MODULE_NAME, "[ERROR] start -> buildCandlesAndVolumes -> nextFile -> nextDate -> onStatusReportWritten -> err = " + err.stack); - callBackFunction(global.DEFAULT_FAIL_RESPONSE); - return; - } - } - } - /* Check if we have past the most recent hole fixed file */ - if (date.valueOf() > lastFileWithoutHoles.valueOf()) { + if (date.valueOf() > lastTradeFileSaved.valueOf()) { writeFiles(lastHoleFixedFile, candles, volumes, false, onFilesWritten); return; @@ -1062,7 +865,7 @@ return; } - let key = bot.dataMine + "-" + bot.codeName + "-" + bot.process + "-" + bot.dataSetVersion + "-" + year + "-" + month; + let key = bot.dataMine + "-" + bot.codeName + "-" + bot.process + "-" + bot.dataSetVersion let statusReport = statusDependencies.statusReports.get(key); statusReport.file = { @@ -1079,7 +882,6 @@ minutes: lastTradeFile.getUTCMinutes() }, candleClose: candleClose, - monthCompleted: isMonthComplete, fileComplete: isFileComplete }; diff --git a/Legacy-Code/AAMasters/bots/AACharly-Sensor-Bot/Historic-Trades/User.Bot.js b/Legacy-Code/AAMasters/bots/AACharly-Sensor-Bot/Historic-Trades/User.Bot.js index a8ba2f333..1557d27cf 100644 --- a/Legacy-Code/AAMasters/bots/AACharly-Sensor-Bot/Historic-Trades/User.Bot.js +++ b/Legacy-Code/AAMasters/bots/AACharly-Sensor-Bot/Historic-Trades/User.Bot.js @@ -30,7 +30,7 @@ exports.newUserBot = function newUserBot(bot, logger, COMMONS, UTILITIES, fileSt return thisObject; - function initialize(pStatusDependencies, pMonth, pYear, callBackFunction) { + function initialize(pStatusDependencies, callBackFunction) { try { logger.fileName = MODULE_NAME; @@ -97,7 +97,7 @@ exports.newUserBot = function newUserBot(bot, logger, COMMONS, UTILITIES, fileSt verbose: false, options: options } - console.log(JSON.stringify(exchangeConstructorParams)) + const exchange = new exchangeClass(exchangeConstructorParams) begin() @@ -199,7 +199,7 @@ exports.newUserBot = function newUserBot(bot, logger, COMMONS, UTILITIES, fileSt let processingDate = new Date(since) processingDate = processingDate.getUTCFullYear() + '-' + utilities.pad(processingDate.getUTCMonth() + 1, 2) + '-' + utilities.pad(processingDate.getUTCDate(), 2); if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> getTrades -> Fetching Trades @ " + processingDate + "-> exchange = " + bot.exchange + " -> symbol = " + symbol + " -> since = " + since + " -> limit = " + limit ) } - console.log("Charly -> " + MODULE_NAME + " -> start -> getTrades -> Fetching Trades from " + bot.exchange + " " + symbol + " @ " + processingDate + " collecting " + allTrades.length + " records trades so far.") + //console.log("Charly -> " + MODULE_NAME + " -> start -> getTrades -> Fetching Trades from " + bot.exchange + " " + symbol + " @ " + processingDate + " collecting " + allTrades.length + " records trades so far.") bot.processHeartBeat("Fetching " + allTrades.length.toFixed(0) + " trades from " + bot.exchange + " " + symbol + " @ " + processingDate) // tell the world we are alive and doing well if (fetchType === "by Id") { @@ -295,7 +295,7 @@ exports.newUserBot = function newUserBot(bot, logger, COMMONS, UTILITIES, fileSt let processingDate = new Date(trade.timestamp) processingDate = processingDate.getUTCFullYear() + '-' + utilities.pad(processingDate.getUTCMonth() + 1, 2) + '-' + utilities.pad(processingDate.getUTCDate(), 2); if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> saveTrades -> Saving Trades @ " + processingDate + " -> i = " + i + " -> total = " + allTrades.length) } - console.log("Charly -> " + MODULE_NAME + " -> start -> saveTrades -> Saving Trades from " + bot.exchange + " " + symbol + " @ " + processingDate) + //console.log("Charly -> " + MODULE_NAME + " -> start -> saveTrades -> Saving Trades from " + bot.exchange + " " + symbol + " @ " + processingDate) bot.processHeartBeat("Saving " + i.toFixed(0) + " trades from " + bot.exchange + " " + symbol + " @ " + processingDate) // tell the world we are alive and doing well } @@ -425,8 +425,7 @@ exports.newUserBot = function newUserBot(bot, logger, COMMONS, UTILITIES, fileSt days: beginingOfMarket.getUTCDate(), hours: beginingOfMarket.getUTCHours(), minutes: beginingOfMarket.getUTCMinutes() - }, - completeHistory: true + } }; if (fetchType === "by Id") { diff --git a/Legacy-Code/AAMasters/bots/AAChris-Indicator-Bot/Multi-Period-Daily/User.Bot.js b/Legacy-Code/AAMasters/bots/AAChris-Indicator-Bot/Multi-Period-Daily/User.Bot.js index 0b652ef60..ddaf95527 100644 --- a/Legacy-Code/AAMasters/bots/AAChris-Indicator-Bot/Multi-Period-Daily/User.Bot.js +++ b/Legacy-Code/AAMasters/bots/AAChris-Indicator-Bot/Multi-Period-Daily/User.Bot.js @@ -26,7 +26,7 @@ return thisObject; - function initialize(pStatusDependencies, pMonth, pYear, callBackFunction) { + function initialize(pStatusDependencies, callBackFunction) { try { diff --git a/Legacy-Code/AAMasters/bots/AAChris-Indicator-Bot/Multi-Period-Market/User.Bot.js b/Legacy-Code/AAMasters/bots/AAChris-Indicator-Bot/Multi-Period-Market/User.Bot.js index c9bf74b81..3f0742040 100644 --- a/Legacy-Code/AAMasters/bots/AAChris-Indicator-Bot/Multi-Period-Market/User.Bot.js +++ b/Legacy-Code/AAMasters/bots/AAChris-Indicator-Bot/Multi-Period-Market/User.Bot.js @@ -20,7 +20,7 @@ return thisObject; - function initialize(pStatusDependencies, pMonth, pYear, callBackFunction) { + function initialize(pStatusDependencies, callBackFunction) { try { diff --git a/Legacy-Code/AAMasters/bots/AAOlivia-Indicator-Bot/Multi-Period-Daily/User.Bot.js b/Legacy-Code/AAMasters/bots/AAOlivia-Indicator-Bot/Multi-Period-Daily/User.Bot.js index 43cffff70..c7fea7ed0 100644 --- a/Legacy-Code/AAMasters/bots/AAOlivia-Indicator-Bot/Multi-Period-Daily/User.Bot.js +++ b/Legacy-Code/AAMasters/bots/AAOlivia-Indicator-Bot/Multi-Period-Daily/User.Bot.js @@ -28,7 +28,7 @@ return thisObject; - function initialize(pStatusDependencies, pMonth, pYear, callBackFunction) { + function initialize(pStatusDependencies, callBackFunction) { try { @@ -121,7 +121,7 @@ Read the candles and volumes from Bruce and produce a file for each day and for /* Second, we get the report from Bruce, to know when the marted ends. */ - reportKey = "AAMasters" + "-" + "AABruce" + "-" + "Single-Period-Daily" + "-" + "dataSet.V1" + "-" + bot.processDatetime.getUTCFullYear() + "-" + utilities.pad(bot.processDatetime.getUTCMonth() + 1,2); + reportKey = "AAMasters" + "-" + "AABruce" + "-" + "Single-Period-Daily" + "-" + "dataSet.V1" if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> getContextVariables -> reportKey = " + reportKey); } statusReport = statusDependencies.statusReports.get(reportKey); diff --git a/Legacy-Code/AAMasters/bots/AAOlivia-Indicator-Bot/Multi-Period-Market/User.Bot.js b/Legacy-Code/AAMasters/bots/AAOlivia-Indicator-Bot/Multi-Period-Market/User.Bot.js index 0a0e1c154..fbeccde07 100644 --- a/Legacy-Code/AAMasters/bots/AAOlivia-Indicator-Bot/Multi-Period-Market/User.Bot.js +++ b/Legacy-Code/AAMasters/bots/AAOlivia-Indicator-Bot/Multi-Period-Market/User.Bot.js @@ -28,7 +28,7 @@ return thisObject; - function initialize(pStatusDependencies, pMonth, pYear, callBackFunction) { + function initialize(pStatusDependencies, callBackFunction) { try { @@ -130,7 +130,7 @@ /* Second, we get the report from Bruce, to know when the marted ends. */ - reportKey = "AAMasters" + "-" + "AABruce" + "-" + "Single-Period-Daily" + "-" + "dataSet.V1" + "-" + bot.processDatetime.getUTCFullYear() + "-" + utilities.pad(bot.processDatetime.getUTCMonth() + 1,2); + reportKey = "AAMasters" + "-" + "AABruce" + "-" + "Single-Period-Daily" + "-" + "dataSet.V1" if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> getContextVariables -> reportKey = " + reportKey); } statusReport = statusDependencies.statusReports.get(reportKey); diff --git a/Legacy-Code/AAMasters/bots/AATom-Indicator-Bot/Multi-Period-Daily/User.Bot.js b/Legacy-Code/AAMasters/bots/AATom-Indicator-Bot/Multi-Period-Daily/User.Bot.js index 010355a9b..dd35fa56c 100644 --- a/Legacy-Code/AAMasters/bots/AATom-Indicator-Bot/Multi-Period-Daily/User.Bot.js +++ b/Legacy-Code/AAMasters/bots/AATom-Indicator-Bot/Multi-Period-Daily/User.Bot.js @@ -29,7 +29,7 @@ return thisObject; - function initialize(pStatusDependencies, pMonth, pYear, callBackFunction) { + function initialize(pStatusDependencies, callBackFunction) { try { diff --git a/Legacy-Code/AAMasters/bots/AATom-Indicator-Bot/Multi-Period-Market/User.Bot.js b/Legacy-Code/AAMasters/bots/AATom-Indicator-Bot/Multi-Period-Market/User.Bot.js index 57c0e199d..bc193bb89 100644 --- a/Legacy-Code/AAMasters/bots/AATom-Indicator-Bot/Multi-Period-Market/User.Bot.js +++ b/Legacy-Code/AAMasters/bots/AATom-Indicator-Bot/Multi-Period-Market/User.Bot.js @@ -26,7 +26,7 @@ return thisObject; - function initialize(pStatusDependencies, pMonth, pYear, callBackFunction) { + function initialize(pStatusDependencies, callBackFunction) { try { diff --git a/TaskManager/server.js b/TaskManager/server.js index fc6584c1b..1d9579878 100644 --- a/TaskManager/server.js +++ b/TaskManager/server.js @@ -32,7 +32,7 @@ function bootLoader() { } function runTask(message) { - console.log('[INFO] Task Manager -> server -> runTask -> Entering function.') + //console.log('[INFO] Task Manager -> server -> runTask -> Entering function.') if (message.event === undefined) { console.log('[WARN] Task Manager -> server -> runTask -> Message Received Without Event -> message = ' + JSON.stringify(message)) @@ -49,8 +49,8 @@ function runTask(message) { return } - console.log('[INFO] Task Manager -> server -> runTask -> Task Name = ' + message.event.taskName) - console.log('[INFO] Task Manager -> server -> runTask -> Task Id = ' + message.event.taskId) + //console.log('[INFO] Task Manager -> server -> runTask -> Task Name = ' + message.event.taskName) + //console.log('[INFO] Task Manager -> server -> runTask -> Task Id = ' + message.event.taskId) let path = process.env.TASK_SERVER_PATH + '/server.js' @@ -77,22 +77,22 @@ function runTask(message) { console.log(`[ERROR] Task Manager -> server -> runTask -> Task Manager exited with error ${err}`) }) task.childProcess.on('close', (code, signal) => { - console.log('[INFO] Task Manager -> server -> runTask -> Task Terminated. -> Task Name = ' + task.name) - console.log('[INFO] Task Manager -> server -> runTask -> Task Terminated. -> Task Id = ' + task.id) + //console.log('[INFO] Task Manager -> server -> runTask -> Task Terminated. -> Task Name = ' + task.name) + //console.log('[INFO] Task Manager -> server -> runTask -> Task Terminated. -> Task Id = ' + task.id) tasks.delete(task.id) }) setTimeout(sendStartingEvent, 3000) function sendStartingEvent() { - console.log('[INFO] Task Manager -> server -> runTask -> Emitting Event -> key = ' + 'Task Server - ' + task.id) + //console.log('[INFO] Task Manager -> server -> runTask -> Emitting Event -> key = ' + 'Task Server - ' + task.id) global.SYSTEM_EVENT_HANDLER.raiseEvent('Task Server - ' + task.id, 'Run Task', message.event) } } function stopTask(message) { - console.log('[INFO] Task Manager -> server -> stopTask -> Entering function.') + //console.log('[INFO] Task Manager -> server -> stopTask -> Entering function.') if (message.event === undefined) { console.log('[WARN] Task Manager -> server -> stopTask -> Message Received Without Event -> message = ' + JSON.stringify(message)) @@ -104,14 +104,14 @@ function stopTask(message) { return } - console.log('[INFO] Task Manager -> server -> stopTask -> Task Name = ' + message.event.taskName) - console.log('[INFO] Task Manager -> server -> stopTask -> Task Id = ' + message.event.taskId) + //console.log('[INFO] Task Manager -> server -> stopTask -> Task Name = ' + message.event.taskName) + //console.log('[INFO] Task Manager -> server -> stopTask -> Task Id = ' + message.event.taskId) let task = tasks.get(message.event.taskId) if (task) { task.childProcess.send('Stop this Task'); - console.log('[INFO] Task Manager -> server -> stopTask -> Child Process instructed to finish.') + //console.log('[INFO] Task Manager -> server -> stopTask -> Child Process instructed to finish.') } else { console.log('[WARN] Task Manager -> server -> stopTask -> Cannot delete Task that does not exist.') } diff --git a/TaskServer/DebugLog.js b/TaskServer/DebugLog.js index ebc3e6d39..ba2c83788 100644 --- a/TaskServer/DebugLog.js +++ b/TaskServer/DebugLog.js @@ -37,10 +37,12 @@ exports.newDebugLog = function newDebugLog() { } } - function newInternalLoop(pBot, pProcess) { + function newInternalLoop(pBot, pProcess, date) { + if (date === undefined) { date = thisObject.bot.processDatetime } - console.log(new Date().toISOString() + " " + strPad(pBot, 20) + " " + strPad(pProcess, 30) + " Entered into Internal Loop # " + strPad(internalLoopCounter + 1, 4) + " bot.processDatetime = " + thisObject.bot.processDatetime.toISOString()); + 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)) persist(); diff --git a/TaskServer/IndicatorBotProcessMainLoop.js b/TaskServer/IndicatorBotProcessMainLoop.js index 0e46ea1e7..aa2cd6ac2 100644 --- a/TaskServer/IndicatorBotProcessMainLoop.js +++ b/TaskServer/IndicatorBotProcessMainLoop.js @@ -85,7 +85,7 @@ } } - function run(pMonth, pYear, callBackFunction) { + function run(callBackFunction) { try { @@ -145,8 +145,8 @@ /* High level log entry */ - console.log(new Date().toISOString() + " " + pad(bot.codeName, 20) + " " + pad(bot.process, 30) + " " + pad(pMonth, 2) + "/" + pad(pYear, 4) - + " Entered into Main Loop # " + pad(Number(bot.loopCounter), 8)); + 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)); /* We will prepare first the infraestructure needed for the bot to run. There are 3 modules we need to sucessfullly initialize first. */ @@ -169,7 +169,7 @@ processExecutionEvents = PROCESS_EXECUTION_EVENTS.newProcessExecutionEvents(bot, logger) - processExecutionEvents.initialize(pMonth, pYear, onInizialized); + processExecutionEvents.initialize(onInizialized); function onInizialized(err) { @@ -317,7 +317,7 @@ statusDependencies = STATUS_DEPENDENCIES.newStatusDependencies(bot, logger, STATUS_REPORT, UTILITIES); - statusDependencies.initialize(pMonth, pYear, onInizialized); + statusDependencies.initialize(onInizialized); function onInizialized(err) { @@ -496,7 +496,7 @@ usertBot = USER_BOT_MODULE.newUserBot(bot, logger, COMMONS_MODULE, UTILITIES, fileStorage); - usertBot.initialize(statusDependencies, pMonth, pYear, onInizialized); + usertBot.initialize(statusDependencies, onInizialized); function onInizialized(err) { @@ -530,18 +530,6 @@ case global.CUSTOM_OK_RESPONSE.result: { switch (err.message) { - case "Too far in the future.": { - logger.write(MODULE_NAME, "[WARN] run -> loop -> initializeUserBot -> onInizialized > Too far in the future. This Loop will enter in coma."); - nextWaitTime = 'Coma'; - loopControl(nextWaitTime); - return; - } - case "Not needed now, but soon.": { - logger.write(MODULE_NAME, "[WARN] run -> loop -> initializeUserBot -> onInizialized > Not needed now, but soon. This Loop will continue with Normal wait time."); - nextWaitTime = 'Normal'; - loopControl(nextWaitTime); - return; - } default: { logger.write(MODULE_NAME, "[ERROR] run -> loop -> initializeUserBot -> onInizialized > Unhandled custom response received. -> err = " + err.message); logger.persist(); @@ -642,36 +630,6 @@ loopControl(nextWaitTime); return; } - case "Month before it is needed.": { - logger.write(MODULE_NAME, "[WARN] run -> loop -> startUserBot -> onFinished -> Month before it is needed. This Loop will be terminated."); - logger.persist(); - clearInterval(fixedTimeLoopIntervalHandle); - clearTimeout(nextLoopTimeoutHandle); - clearTimeout(checkLoopHealthHandle); - bot.enableCheckLoopHealth = false; - callBackFunction(global.DEFAULT_OK_RESPONSE); - return; - } - case "Month fully processed.": { - logger.write(MODULE_NAME, "[WARN] run -> loop -> startUserBot -> onFinished -> Month fully processed. This Loop will be terminated."); - logger.persist(); - clearInterval(fixedTimeLoopIntervalHandle); - clearTimeout(nextLoopTimeoutHandle); - clearTimeout(checkLoopHealthHandle); - bot.enableCheckLoopHealth = false; - callBackFunction(global.DEFAULT_OK_RESPONSE); - return; - } - case "End of the month reached.": { - logger.write(MODULE_NAME, "[WARN] run -> loop -> startUserBot -> onFinished -> End of the month reached. This Loop will be terminated."); - logger.persist(); - clearInterval(fixedTimeLoopIntervalHandle); - clearTimeout(nextLoopTimeoutHandle); - clearTimeout(checkLoopHealthHandle); - bot.enableCheckLoopHealth = false; - callBackFunction(global.DEFAULT_OK_RESPONSE); - return; - } default: { logger.write(MODULE_NAME, "[ERROR] run -> loop -> startUserBot -> onFinished -> Unhandled custom response received. -> err = " + err.message); logger.persist(); @@ -760,18 +718,6 @@ case global.CUSTOM_OK_RESPONSE.result: { switch (err.message) { - case "Too far in the future.": { - logger.write(MODULE_NAME, "[WARN] run -> loop -> intitializeProcessFramework -> onInizialized > Too far in the future. This Loop will enter in coma."); - nextWaitTime = 'Coma'; - loopControl(nextWaitTime); - return; - } - case "Not needed now, but soon.": { - logger.write(MODULE_NAME, "[WARN] run -> loop -> intitializeProcessFramework -> onInizialized > Not needed now, but soon. This Loop will continue with Normal wait time."); - nextWaitTime = 'Normal'; - loopControl(nextWaitTime); - return; - } default: { logger.write(MODULE_NAME, "[ERROR] run -> loop -> intitializeProcessFramework -> onInizialized > Unhandled custom response received. -> err = " + err.message); logger.persist(); @@ -874,36 +820,6 @@ loopControl(nextWaitTime); return; } - case "Month before it is needed.": { - logger.write(MODULE_NAME, "[WARN] run -> loop -> startProcessFramework -> onFinished -> Month before it is needed. This Loop will be terminated."); - logger.persist(); - clearInterval(fixedTimeLoopIntervalHandle); - clearTimeout(nextLoopTimeoutHandle); - clearTimeout(checkLoopHealthHandle); - bot.enableCheckLoopHealth = false; - callBackFunction(global.DEFAULT_OK_RESPONSE); - return; - } - case "Month fully processed.": { - logger.write(MODULE_NAME, "[WARN] run -> loop -> startProcessFramework -> onFinished -> Month fully processed. This Loop will be terminated."); - logger.persist(); - clearInterval(fixedTimeLoopIntervalHandle); - clearTimeout(nextLoopTimeoutHandle); - clearTimeout(checkLoopHealthHandle); - bot.enableCheckLoopHealth = false; - callBackFunction(global.DEFAULT_OK_RESPONSE); - return; - } - case "End of the month reached.": { - logger.write(MODULE_NAME, "[WARN] run -> loop -> startProcessFramework -> onFinished -> End of the month reached. This Loop will be terminated."); - logger.persist(); - clearInterval(fixedTimeLoopIntervalHandle); - clearTimeout(nextLoopTimeoutHandle); - clearTimeout(checkLoopHealthHandle); - bot.enableCheckLoopHealth = false; - callBackFunction(global.DEFAULT_OK_RESPONSE); - return; - } default: { logger.write(MODULE_NAME, "[ERROR] run -> loop -> startProcessFramework -> onFinished -> Unhandled custom response received. -> err = " + err.message); logger.persist(); diff --git a/TaskServer/MultiPeriod.js b/TaskServer/MultiPeriod.js index 62141ce01..94a1cd318 100644 --- a/TaskServer/MultiPeriod.js +++ b/TaskServer/MultiPeriod.js @@ -453,8 +453,6 @@ 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.multiPeriodProcessDatetime = " + bot.multiPeriodProcessDatetime.toISOString()); - if (global.WRITE_LOGS_TO_FILES === 'true') { logger.newInternalLoop(bot.codeName, bot.process); } diff --git a/TaskServer/MultiPeriodDaily.js b/TaskServer/MultiPeriodDaily.js index b50e975c0..1e87a91a5 100644 --- a/TaskServer/MultiPeriodDaily.js +++ b/TaskServer/MultiPeriodDaily.js @@ -306,9 +306,7 @@ bot.multiPeriodDailyProcessDatetime = new Date(bot.multiPeriodDailyProcessDatetime.valueOf() + ONE_DAY_IN_MILISECONDS); previousDay = new Date(bot.multiPeriodDailyProcessDatetime.valueOf() - ONE_DAY_IN_MILISECONDS); - - console.log(new Date().toISOString() + " " + pad(bot.codeName, 20) + " " + pad(bot.process, 30) + " " + "bot.multiPeriodDailyProcessDatetime = " + bot.multiPeriodDailyProcessDatetime.toISOString()); - + if (global.WRITE_LOGS_TO_FILES === 'true') { logger.newInternalLoop(bot.codeName, bot.process); } diff --git a/TaskServer/ProcessExecutionEvents.js b/TaskServer/ProcessExecutionEvents.js index 64f45bda4..ed79e1be7 100644 --- a/TaskServer/ProcessExecutionEvents.js +++ b/TaskServer/ProcessExecutionEvents.js @@ -19,30 +19,21 @@ let processThisDependsOn; // This is the process this process needs to wait for it to finishes in order to start. - let month; - let year; let currentProcessKey - let datetimeForLogs = '' return thisObject; - function initialize(pMonth, pYear, callBackFunction) { + function initialize(callBackFunction) { try { if (global.LOG_CONTROL[MODULE_NAME].logInfo === true) { logger.write(MODULE_NAME, "[INFO] initialize -> Entering function."); } - month = pMonth; - year = pYear; - - if (month && year) { - datetimeForLogs = "Month: " + month + " Year: " + year - } - let name = 'Not Depends on any Process' if (bot.processNode.referenceParent !== undefined) { - currentProcessKey = bot.processNode.referenceParent.name + "-" + bot.processNode.referenceParent.type + "-" + bot.processNode.referenceParent.id + let market = bot.market.baseAsset + '/' + bot.market.quotedAsset + currentProcessKey = bot.processNode.referenceParent.name + "-" + bot.processNode.referenceParent.type + "-" + bot.processNode.referenceParent.id + "-" + bot.exchange + "-" + market if (bot.processNode.referenceParent.executionStartedEvent !== undefined) { if (bot.processNode.referenceParent.executionStartedEvent.referenceParent !== undefined) { @@ -51,9 +42,9 @@ name = processThisDependsOn.name if (processThisDependsOn.code.monthlyInstances === true) { - logger.fileName = MODULE_NAME + "." + name + "." + year + "." + month; + logger.fileName = MODULE_NAME + "." + name; } - if (global.LOG_CONTROL[MODULE_NAME].logInfo === true) { logger.write(MODULE_NAME, "[INFO] initialize -> " + currentProcessKey + datetimeForLogs + " depends on " + name); } + if (global.LOG_CONTROL[MODULE_NAME].logInfo === true) { logger.write(MODULE_NAME, "[INFO] initialize -> " + currentProcessKey + " depends on " + name); } } } } @@ -79,10 +70,9 @@ /* This forces this process to wait until the process that this one depends on, emits its event signaling that the process execution has finished. */ let extraCallerId = '-' + Math.trunc(Math.random() * 10000) + '-' - if (month) { extraCallerId = extraCallerId + '-' + month } - if (year) { extraCallerId = extraCallerId + '-' + year } - let key = processThisDependsOn.name + "-" + processThisDependsOn.type + "-" + processThisDependsOn.id + let market = bot.market.baseAsset + '/' + bot.market.quotedAsset + let key = processThisDependsOn.name + "-" + processThisDependsOn.type + "-" + processThisDependsOn.id + "-" + bot.exchange + "-" + market let callerId = bot.dataMine + "-" + bot.codeName + "-" + bot.process + extraCallerId let subscriptionId @@ -120,7 +110,7 @@ global.SYSTEM_EVENT_HANDLER.createEventHandler(currentProcessKey, 'Process Execution Started') global.SYSTEM_EVENT_HANDLER.raiseEvent(currentProcessKey, 'Process Execution Started', event) - if (global.LOG_CONTROL[MODULE_NAME].logInfo === true) { logger.write(MODULE_NAME, "[INFO] start -> eventsCallBack -> " + currentProcessKey + " Process Execution Started because " + key + datetimeForLogs + " Finished."); } + if (global.LOG_CONTROL[MODULE_NAME].logInfo === true) { logger.write(MODULE_NAME, "[INFO] start -> eventsCallBack -> " + currentProcessKey + " Process Execution Started because " + key + " Finished."); } } callBackFunction(message.event.err); @@ -134,7 +124,7 @@ global.SYSTEM_EVENT_HANDLER.createEventHandler(currentProcessKey, 'Process Execution Started') global.SYSTEM_EVENT_HANDLER.raiseEvent(currentProcessKey, 'Process Execution Started', event) - if (global.LOG_CONTROL[MODULE_NAME].logInfo === true) { logger.write(MODULE_NAME, "[INFO] start -> " + currentProcessKey + " Process Execution Started " + datetimeForLogs); } + if (global.LOG_CONTROL[MODULE_NAME].logInfo === true) { logger.write(MODULE_NAME, "[INFO] start -> " + currentProcessKey + " Process Execution Started " ); } callBackFunction(global.DEFAULT_OK_RESPONSE); } @@ -157,7 +147,8 @@ global.SYSTEM_EVENT_HANDLER.createEventHandler(currentProcessKey, 'Process Execution Finished') global.SYSTEM_EVENT_HANDLER.raiseEvent(currentProcessKey, 'Process Execution Finished', event) - if (global.LOG_CONTROL[MODULE_NAME].logInfo === true) { logger.write(MODULE_NAME, "[INFO] finish -> " + currentProcessKey + " Process Execution Finished " + datetimeForLogs); } + + if (global.LOG_CONTROL[MODULE_NAME].logInfo === true) { logger.write(MODULE_NAME, "[INFO] finish -> " + currentProcessKey + " Process Execution Finished " ); } callBackFunction(global.DEFAULT_OK_RESPONSE); diff --git a/TaskServer/Root.js b/TaskServer/Root.js index 9e9019f79..41e18541b 100644 --- a/TaskServer/Root.js +++ b/TaskServer/Root.js @@ -53,7 +53,6 @@ function initialize(callBackFunction) { try { - console.log(logDisplace + "Root : [INFO] initialize -> Entering function. "); /* Global control of logging. */ @@ -159,7 +158,6 @@ function getBotConfigFromFile() { try { - console.log(logDisplace + "Root : [INFO] start -> getBotConfigFromFile -> Entering function. "); const FILE_STORAGE = require('./FileStorage.js'); let fileStorage = FILE_STORAGE.newFileStorage(); @@ -196,7 +194,6 @@ function bootingBot(processIndex) { try { - if (FULL_LOG === true) { console.log(logDisplace + "Root : [INFO] start -> bootingBot -> Entering function. "); } botConfig.process = global.TASK_NODE.bot.processes[processIndex].referenceParent.code.codeName botConfig.debug = {}; @@ -252,9 +249,6 @@ } } - if (FULL_LOG === true) { console.log(logDisplace + "Root : [INFO] start -> bootingBot -> filePathRoot = " + botConfig.filePathRoot); } - if (FULL_LOG === true) { console.log(logDisplace + "Root : [INFO] start -> bootingBot -> Process found at the bot configuration file. -> process = " + global.TASK_NODE.bot.processes[processIndex].referenceParent.code.codeName); } - let processConfig = global.TASK_NODE.bot.processes[processIndex].referenceParent.code if (processConfig.framework !== undefined) { @@ -281,97 +275,10 @@ try { - /* We test each type of start Mode to get what to run and how. */ - - if (processConfig.startMode.allMonths !== undefined) { - - if (processConfig.startMode.allMonths.run === "true") { - - if (FULL_LOG === true) { console.log(logDisplace + "Root : [INFO] start -> bootingBot -> allMonths start mode detected. "); } - - for (let year = processConfig.startMode.allMonths.maxYear; year >= processConfig.startMode.allMonths.minYear; year--) { - - for (let month = 12; month > 0; month--) { - - let padMonth = pad(month, 2) - - let newInstanceBotConfig = JSON.parse(JSON.stringify(botConfig)); - - newInstanceBotConfig.debug = { - month: pad(month, 2), - year: pad(year, 4) - }; - - let timeDelay = Math.random() * 10 * 1000; // We introduce a short delay so as to not overload the machine. - setTimeout(startProcess, timeDelay); - - function startProcess() { - - if (FULL_LOG === true) { console.log(logDisplace + "Root : [INFO] start -> bootingBot -> startProcess -> Ready to start process."); } - - switch (botConfig.type) { - case 'Sensor Bot': { - runSensorBot(newInstanceBotConfig, processConfig, padMonth, year); - break; - } - case 'Indicator Bot': { - runIndicatorBot(newInstanceBotConfig, processConfig, padMonth, year); - break; - } - default: { - console.log(logDisplace + "Root : [ERROR] start -> bootingBot -> startProcess -> Unexpected bot type. -> botConfig.type = " + botConfig.type); - } - } - } - } - } - } - } - - if (processConfig.startMode.oneMonth !== undefined) { - - if (processConfig.startMode.oneMonth.run === "true") { - - if (FULL_LOG === true) { console.log(logDisplace + "Root : [INFO] start -> bootingBot -> oneMonth start mode detected. "); } - - startProcess(); - - function startProcess() { - - if (FULL_LOG === true) { console.log(logDisplace + "Root : [INFO] start -> bootingBot -> startProcess -> Ready to start process."); } - - let month = pad(processConfig.startMode.oneMonth.month, 2); - let year = processConfig.startMode.oneMonth.year; - - botConfig.debug = { - month: pad(month, 2), - year: pad(year, 4) - }; - - switch (botConfig.type) { - case 'Sensor Bot': { - runSensorBot(botConfig, processConfig, month, year); - break; - } - case 'Indicator Bot': { - runIndicatorBot(botConfig, processConfig, month, year); - break; - } - default: { - console.log(logDisplace + "Root : [ERROR] start -> bootingBot -> startProcess -> Unexpected bot type. -> botConfig.type = " + botConfig.type); - } - } - } - } - } - if (processConfig.startMode.noTime !== undefined) { if (processConfig.startMode.noTime.run === "true") { - let month = pad((new Date()).getUTCMonth() + 1, 2); - let year = (new Date()).getUTCFullYear(); - if (processConfig.startMode.noTime.resumeExecution === true) { botConfig.hasTheBotJustStarted = false; } else { @@ -380,11 +287,11 @@ switch (botConfig.type) { case 'Sensor Bot': { - runSensorBot(botConfig, processConfig, month, year); + runSensorBot(botConfig, processConfig); break; } case 'Indicator Bot': { - runIndicatorBot(botConfig, processConfig, month, year); + runIndicatorBot(botConfig, processConfig); break; } case 'Trading Bot': { @@ -405,12 +312,9 @@ botConfig.runAtFixedInterval = true; botConfig.fixedInterval = processConfig.startMode.fixedInterval.interval; - let month = pad((new Date()).getUTCMonth() + 1, 2); - let year = (new Date()).getUTCFullYear(); - switch (botConfig.type) { case 'Sensor Bot': { - runSensorBot(botConfig, processConfig, month, year); + runSensorBot(botConfig, processConfig); break; } default: { @@ -425,10 +329,6 @@ if (processConfig.startMode.userDefined.run === "true") { botConfig.startMode = "User Defined"; - console.log(logDisplace + "Root : [INFO] start -> bootingBot -> Process found at the bot configuration file. -> Start Mode = " + botConfig.startMode); - - let month = pad((new Date()).getUTCMonth() + 1, 2); - let year = (new Date()).getUTCFullYear(); if (processConfig.startMode.userDefined.resumeExecution === true) { botConfig.hasTheBotJustStarted = false; @@ -453,7 +353,7 @@ } - function runSensorBot(pBotConfig, pProcessConfig, pMonth, pYear) { + function runSensorBot(pBotConfig, pProcessConfig) { try { global.TOTAL_PROCESS_INSTANCES_CREATED++ @@ -465,8 +365,6 @@ logger.bot = pBotConfig; if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> bootingBot -> runSensorBot -> Entering function."); } - if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> bootingBot -> runSensorBot -> pMonth = " + pMonth); } - if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> bootingBot -> runSensorBot -> pYear = " + pYear); } let extractionBotMainLoop = SENSOR_BOT_MAIN_LOOP_MODULE.newSensorBotProcessMainLoop(pBotConfig, logger); extractionBotMainLoop.initialize(pProcessConfig, onInitializeReady); @@ -475,25 +373,19 @@ if (err.result === global.DEFAULT_OK_RESPONSE.result) { - extractionBotMainLoop.run(pMonth, pYear, whenRunFinishes); + extractionBotMainLoop.run(whenRunFinishes); function whenRunFinishes(err) { pBotConfig.loopCounter = 0; - let botId; - if (pYear !== undefined) { - botId = pBotConfig.dataMine + "." + pBotConfig.codeName + "." + pBotConfig.process + "." + pYear + "." + pMonth; - } else { - botId = pBotConfig.dataMine + "." + pBotConfig.codeName + "." + pBotConfig.process; - } + let botId = pBotConfig.dataMine + "." + pBotConfig.codeName + "." + pBotConfig.process; if (err.result === global.DEFAULT_OK_RESPONSE.result) { logger.write(MODULE_NAME, "[INFO] start -> bootingBot -> runSensorBot -> onInitializeReady -> whenStartFinishes -> Bot execution finished sucessfully."); logger.write(MODULE_NAME, "[INFO] start -> bootingBot -> runSensorBot -> onInitializeReady -> whenStartFinishes -> Bot Id = " + botId); - console.log(logDisplace + "Root : [INFO] start -> bootingBot -> runSensorBot -> onInitializeReady -> whenStartFinishes -> botId = " + botId); console.log(logDisplace + "Root : [INFO] start -> bootingBot -> runSensorBot -> onInitializeReady -> whenStartFinishes -> Bot execution finished sucessfully."); logger.persist(); @@ -504,7 +396,6 @@ logger.write(MODULE_NAME, "[ERROR] start -> bootingBot -> runSensorBot -> onInitializeReady -> whenStartFinishes -> Bye."); logger.write(MODULE_NAME, "[ERROR] start -> bootingBot -> runSensorBot -> onInitializeReady -> whenStartFinishes -> Bot Id = " + botId); - console.log(logDisplace + "Root : [ERROR] start -> bootingBot -> runSensorBot -> onInitializeReady -> whenStartFinishes -> botId = " + botId); console.log(logDisplace + "Root : [ERROR] start -> bootingBot -> runSensorBot -> onInitializeReady -> whenStartFinishes -> Bot execution was aborted."); logger.persist(); } @@ -527,7 +418,7 @@ } } - function runIndicatorBot(pBotConfig, pProcessConfig, pMonth, pYear) { + function runIndicatorBot(pBotConfig, pProcessConfig) { try { global.TOTAL_PROCESS_INSTANCES_CREATED++ @@ -539,8 +430,6 @@ logger.bot = pBotConfig; if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> bootingBot -> runIndicatorBot -> Entering function."); } - if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> bootingBot -> runIndicatorBot -> pMonth = " + pMonth); } - if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> bootingBot -> runIndicatorBot -> pYear = " + pYear); } let indicatorBotMainLoop = INDICATOR_BOT_MAIN_LOOP_MODULE.newIndicatorBotProcessMainLoop(pBotConfig, logger); indicatorBotMainLoop.initialize(pProcessConfig, onInitializeReady); @@ -549,25 +438,20 @@ if (err.result === global.DEFAULT_OK_RESPONSE.result) { - indicatorBotMainLoop.run(pMonth, pYear, whenRunFinishes); + indicatorBotMainLoop.run(whenRunFinishes); function whenRunFinishes(err) { pBotConfig.loopCounter = 0; - let botId; - if (pYear !== undefined) { - botId = pBotConfig.dataMine + "." + pBotConfig.codeName + "." + pBotConfig.process + "." + pYear + "." + pMonth; - } else { - botId = pBotConfig.dataMine + "." + pBotConfig.codeName + "." + pBotConfig.process; - } - + let botId = pBotConfig.dataMine + "." + pBotConfig.codeName + "." + pBotConfig.process; + if (err.result === global.DEFAULT_OK_RESPONSE.result) { logger.write(MODULE_NAME, "[INFO] start -> bootingBot -> runIndicatorBot -> onInitializeReady -> whenStartFinishes -> Bot execution finished sucessfully."); logger.write(MODULE_NAME, "[INFO] start -> bootingBot -> runIndicatorBot -> onInitializeReady -> whenStartFinishes -> Bot Id = " + botId); - console.log(logDisplace + "Root : [INFO] start -> bootingBot -> runIndicatorBot -> onInitializeReady -> whenStartFinishes -> botId = " + botId); + console.log(logDisplace + "Root : [INFO] start -> bootingBot -> runIndicatorBot -> onInitializeReady -> whenStartFinishes -> Bot execution finished sucessfully."); logger.persist(); diff --git a/TaskServer/SensorBotProcessMainLoop.js b/TaskServer/SensorBotProcessMainLoop.js index 98053dbb7..b8e2c49fc 100644 --- a/TaskServer/SensorBotProcessMainLoop.js +++ b/TaskServer/SensorBotProcessMainLoop.js @@ -92,7 +92,7 @@ } } - function run(pMonth, pYear, callBackFunction) { + function run(callBackFunction) { try { if (FULL_LOG === true) { parentLogger.write(MODULE_NAME, "[INFO] run -> Entering function."); } @@ -148,10 +148,10 @@ bot.processDatetime = new Date(); // This will be considered the process date and time, so as to have it consistenly all over the execution. - /* High level log entry */ + /* High level log entry */ - console.log(new Date().toISOString() + " " + pad(bot.codeName, 20) + " " + pad(bot.process, 30) + " " + pad(pMonth, 2) + "/" + pad(pYear, 4) - + " Entered into Main Loop # " + pad(Number(bot.loopCounter), 8) + " bot.processDatetime = " + bot.processDatetime.toISOString()); + 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) ) /* We will prepare first the infraestructure needed for the bot to run. There are 4 modules we need to sucessfullly initialize first. */ @@ -173,7 +173,7 @@ processExecutionEvents = PROCESS_EXECUTION_EVENTS.newProcessExecutionEvents(bot, logger) - processExecutionEvents.initialize(pMonth, pYear, onInizialized); + processExecutionEvents.initialize(onInizialized); function onInizialized(err) { @@ -321,7 +321,7 @@ statusDependencies = STATUS_DEPENDENCIES.newStatusDependencies(bot, logger, STATUS_REPORT, UTILITIES); - statusDependencies.initialize(pMonth, pYear, onInizialized); + statusDependencies.initialize(onInizialized); function onInizialized(err) { @@ -396,7 +396,7 @@ usertBot = USER_BOT_MODULE.newUserBot(bot, logger, COMMONS_MODULE, UTILITIES, fileStorage, STATUS_REPORT, exchangeAPI); - usertBot.initialize(statusDependencies, pMonth, pYear, onInizialized); + usertBot.initialize(statusDependencies, onInizialized); function onInizialized(err) { @@ -430,26 +430,6 @@ case global.CUSTOM_OK_RESPONSE.result: { switch (err.message) { - case "Too far in the future.": { - logger.write(MODULE_NAME, "[WARN] run -> loop -> initializeUserBot -> onInizialized > Too far in the future. This Loop will enter in coma."); - nextWaitTime = 'Coma'; - clearInterval(fixedTimeLoopIntervalHandle); - clearTimeout(nextLoopTimeoutHandle); - clearTimeout(checkLoopHealthHandle); - bot.enableCheckLoopHealth = false; - loopControl(nextWaitTime); - return; - } - case "Not needed now, but soon.": { - logger.write(MODULE_NAME, "[WARN] run -> loop -> initializeUserBot -> onInizialized > Not needed now, but soon. This Loop will continue with Normal wait time."); - nextWaitTime = 'Normal'; - clearInterval(fixedTimeLoopIntervalHandle); - clearTimeout(nextLoopTimeoutHandle); - clearTimeout(checkLoopHealthHandle); - bot.enableCheckLoopHealth = false; - loopControl(nextWaitTime); - return; - } default: { logger.write(MODULE_NAME, "[ERROR] run -> loop -> initializeUserBot -> onInizialized > Unhandled custom response received. -> err = " + err.message); logger.persist(); @@ -550,36 +530,6 @@ loopControl(nextWaitTime); return; } - case "Month before it is needed.": { - logger.write(MODULE_NAME, "[WARN] run -> loop -> startUserBot -> onFinished > Month before it is needed. This Loop will be terminated."); - logger.persist(); - clearInterval(fixedTimeLoopIntervalHandle); - clearTimeout(nextLoopTimeoutHandle); - clearTimeout(checkLoopHealthHandle); - bot.enableCheckLoopHealth = false; - callBackFunction(global.DEFAULT_OK_RESPONSE); - return; - } - case "Month fully processed.": { - logger.write(MODULE_NAME, "[WARN] run -> loop -> startUserBot -> onFinished > Month fully processed. This Loop will be terminated."); - logger.persist(); - clearInterval(fixedTimeLoopIntervalHandle); - clearTimeout(nextLoopTimeoutHandle); - clearTimeout(checkLoopHealthHandle); - bot.enableCheckLoopHealth = false; - callBackFunction(global.DEFAULT_OK_RESPONSE); - return; - } - case "End of the month reached.": { - logger.write(MODULE_NAME, "[WARN] run -> loop -> startUserBot -> onFinished > End of the month reached. This Loop will be terminated."); - logger.persist(); - clearInterval(fixedTimeLoopIntervalHandle); - clearTimeout(nextLoopTimeoutHandle); - clearTimeout(checkLoopHealthHandle); - bot.enableCheckLoopHealth = false; - callBackFunction(global.DEFAULT_OK_RESPONSE); - return; - } default: { logger.write(MODULE_NAME, "[ERROR] run -> loop -> startUserBot -> onFinished > Unhandled custom response received. -> err = " + err.message); logger.persist(); diff --git a/TaskServer/StatusDependencies.js b/TaskServer/StatusDependencies.js index 65a888955..176188c16 100644 --- a/TaskServer/StatusDependencies.js +++ b/TaskServer/StatusDependencies.js @@ -16,7 +16,7 @@ return thisObject; - function initialize(pMonth, pYear, callBackFunction) { + function initialize(callBackFunction) { try { @@ -44,27 +44,11 @@ let dependenciesToProcess = [] for (let i = 0; i < thisObject.nodeArray.length; i++) { let statusDependency = { - dependency: thisObject.nodeArray[i], - month: pMonth, - year: pYear + dependency: thisObject.nodeArray[i] } dependenciesToProcess.push(statusDependency) - /* - For the special case that the statusDependency is a Self Reference AND this process is sliced in different - instances for each month, we will add the main self reference status report that is month/year independent. - */ - - if (statusDependency.dependency.code.mainUtility === "Self Reference" && pMonth !== undefined && pYear !== undefined) { - let mainDependency = { - dependency: thisObject.nodeArray[i], - month: undefined, - year: undefined - } - - dependenciesToProcess.push(mainDependency) - } } for (let i = 0; i < dependenciesToProcess.length; i++) { @@ -73,7 +57,7 @@ logger.write(MODULE_NAME, "[INFO] initialize -> onInitilized -> Initializing Status Report # " + (i + 1)); let statusDependency = dependenciesToProcess[i] - statusReportModule.initialize(statusDependency.dependency, statusDependency.month, statusDependency.year, onInitilized); + statusReportModule.initialize(statusDependency.dependency, onInitilized); function onInitilized(err) { @@ -152,13 +136,7 @@ loadCount++; logger.write(MODULE_NAME, "[INFO] initialize -> addReport -> Total Added = " + loadCount); - let key; - - if (statusDependency.dependency.processRunMonthly === true && statusDependency.month !== undefined && statusDependency.year !== undefined) { - key = statusDependency.dependency.dataMine + "-" + statusDependency.dependency.bot + "-" + statusDependency.dependency.process + "-" + statusDependency.dependency.dataSetVersion + "-" + statusDependency.year + "-" + statusDependency.month; - } else { - key = statusDependency.dependency.dataMine + "-" + statusDependency.dependency.bot + "-" + statusDependency.dependency.process + "-" + statusDependency.dependency.dataSetVersion; - } + let key = statusDependency.dependency.dataMine + "-" + statusDependency.dependency.bot + "-" + statusDependency.dependency.process + "-" + statusDependency.dependency.dataSetVersion; thisObject.keys.push(key); thisObject.statusReports.set(key, statusReportModule); diff --git a/TaskServer/StatusReport.js b/TaskServer/StatusReport.js index 89ff5dca7..d6cd7210e 100644 --- a/TaskServer/StatusReport.js +++ b/TaskServer/StatusReport.js @@ -18,8 +18,7 @@ initialize: initialize, load: load, save: save, - status: undefined, - verifyMarketComplete: verifyMarketComplete + status: undefined }; let statusDependencyNode; @@ -33,14 +32,11 @@ const FILE_STORAGE = require('./FileStorage.js'); let fileStorage = FILE_STORAGE.newFileStorage(logger); - let month; - let year; - let timePath = ''; let sessionPath = '' return thisObject; - function initialize(pStatusDependencyNode, pMonth, pYear, callBackFunction) { + function initialize(pStatusDependencyNode, callBackFunction) { try { if (global.LOG_CONTROL[MODULE_NAME].logInfo === true) { logger.write(MODULE_NAME, "[INFO] initialize -> Entering function."); } @@ -48,9 +44,6 @@ statusDependencyNode = pStatusDependencyNode; logger.fileName = MODULE_NAME + "." + statusDependencyNode.type + "." + statusDependencyNode.name + "." + statusDependencyNode.id; - month = pMonth; - year = pYear; - /* Some very basic validations that we have all the information needed. */ if (statusDependencyNode.referenceParent === undefined) { logger.write(MODULE_NAME, "[ERROR] initialize -> Status Dependency without Reference Parent. Status Dependency = " + JSON.stringify(statusDependencyNode)); @@ -128,11 +121,6 @@ if (bot.SESSION !== undefined && statusDependencyNode.bottype === "Trading Bot") { sessionPath = bot.SESSION.folderName + "/" } - - if (statusDependencyNode.processRunMonthly === true && month !== undefined && year !== undefined) { - logger.fileName = MODULE_NAME + "." + statusDependencyNode.bot + "." + statusDependencyNode.process + "." + year + "." + month; - timePath = "/" + year + "/" + month; - } callBackFunction(global.DEFAULT_OK_RESPONSE); @@ -156,9 +144,9 @@ if (ownerId !== botId) { let rootPath = statusDependencyNode.dataMine + "/" + statusDependencyNode.bot + "/" + bot.exchange; - filePath = rootPath + "/Reports/" + sessionPath + statusDependencyNode.process + timePath; + filePath = rootPath + "/Reports/" + sessionPath + statusDependencyNode.process ; } else { - filePath = bot.filePathRoot + "/Reports/" + sessionPath + statusDependencyNode.process + timePath; + filePath = bot.filePathRoot + "/Reports/" + sessionPath + statusDependencyNode.process ; } filePath += '/' + fileName @@ -246,7 +234,7 @@ } let fileName = "Status.Report." + bot.market.baseAsset + '_' + bot.market.quotedAsset + ".json"; - let filePath = bot.filePathRoot + "/Reports/" + sessionPath + statusDependencyNode.process + timePath; + let filePath = bot.filePathRoot + "/Reports/" + sessionPath + statusDependencyNode.process; filePath += '/' + fileName let fileContent = JSON.stringify(thisObject.file); @@ -278,253 +266,4 @@ } } - function verifyMarketComplete(callBackFunction) { - - /* - The mission of this function is to update the main status report on a scheme where there are monthly sub reports. - This report contains the date of the last file sucessfully checked but in a consecutive way. - - For example: if the market starts in March, and March, April and June are checked, then the file will be the last of June even if September is also checked. - - IMPORTANT NOTE: Once executed, this function will leave thisObject in an inconsistant state, so you need to re-initialize it if you wish to use it again. - - */ - - try { - - if (global.LOG_CONTROL[MODULE_NAME].logInfo === true) { logger.write(MODULE_NAME, "[INFO] verifyMarketComplete -> Entering function."); } - - let initialYear; - let initialMonth; - - let finalYear = (new Date()).getUTCFullYear(); - let finalMonth = (new Date()).getUTCMonth() + 1; - - /* Lets load again this main status report as it might have changed since its initialization and first load. */ - - load(onLoad); - - function onLoad(err) { - - try { - - if (global.LOG_CONTROL[MODULE_NAME].logInfo === true) { logger.write(MODULE_NAME, "[INFO] verifyMarketComplete -> onLoad -> Entering function."); } - - if ( - err.result === global.CUSTOM_FAIL_RESPONSE.result && - (err.message === 'Status Report was never created.') - ) { - logger.write(MODULE_NAME, "[INFO] verifyMarketComplete -> onLoad -> err = "+ err.stack); - - /* The first month of the market didnt create the main report yet. Aborting verification. */ - - if (global.LOG_CONTROL[MODULE_NAME].logInfo === true) { logger.write(MODULE_NAME, "[INFO] verifyMarketComplete -> onLoad -> Verification ABORTED since the main status report does not exist."); } - - callBackFunction(global.DEFAULT_OK_RESPONSE); - return; - } - - if (err.result !== global.DEFAULT_OK_RESPONSE.result) { - logger.write(MODULE_NAME, "[ERROR] verifyMarketComplete -> onLoad -> err = "+ err.stack); - callBackFunction(err); - return; - } - - /* Here we get the initial month and year from where our verification process will start. */ - - initialYear = thisObject.file.lastFile.year; - initialMonth = thisObject.file.lastFile.month; - - loopCycle(); - - } catch (err) { - logger.write(MODULE_NAME, "[ERROR] verifyMarketComplete -> onLoad -> err = "+ err.stack); - callBackFunction(global.DEFAULT_FAIL_RESPONSE); - return; - } - } - - function loopCycle() { - - try { - - if (global.LOG_CONTROL[MODULE_NAME].logInfo === true) { logger.write(MODULE_NAME, "[INFO] verifyMarketComplete -> loopCycle -> Entering function."); } - - /* Here we read the status report file of each month / year to verify if it is complete or not. */ - - let paddedInitialMonth = utilities.pad(initialMonth, 2); - - timePath = "/" + initialYear + "/" + paddedInitialMonth; - - load(onLoad); - - function onLoad(err) { - - try { - - if (global.LOG_CONTROL[MODULE_NAME].logInfo === true) { logger.write(MODULE_NAME, "[INFO] verifyMarketComplete -> loopCycle -> onLoad -> Entering function."); } - - if ( - err.result === global.CUSTOM_FAIL_RESPONSE.result && - (err.message === 'Status Report was never created.') - ) { - logger.write(MODULE_NAME, "[INFO] verifyMarketComplete -> loopCycle -> onLoad -> err = "+ err.stack); - - /* The first month of the market didnt create the main report yet. Aborting verification. */ - - if (global.LOG_CONTROL[MODULE_NAME].logInfo === true) { logger.write(MODULE_NAME, "[INFO] verifyMarketComplete -> loopCycle -> onLoad -> Verification ABORTED since the status report for year " + initialYear + " and month " + initialMonth + " did not exist. "); } - - callBackFunction(global.DEFAULT_OK_RESPONSE); - return; - } - - if (err.result !== global.DEFAULT_OK_RESPONSE.result) { - logger.write(MODULE_NAME, "[ERROR] verifyMarketComplete -> loopCycle -> onLoad -> err = "+ err.stack); - callBackFunction(err); - return; - } - - if (thisObject.file.monthChecked === true) { - - readAndWriteNewReport(JSON.stringify(thisObject.file)); - - } else { - - /* If any of the files says that month is not checked then it is enough to know the market continuity is broken. */ - - if (global.LOG_CONTROL[MODULE_NAME].logInfo === true) { logger.write(MODULE_NAME, "[INFO] verifyMarketComplete -> loopCycle -> onLoad -> Verification ABORTED since the status report for year " + initialYear + " and month " + initialMonth + " is not marked as complete."); } - - callBackFunction(global.DEFAULT_OK_RESPONSE); - return; - } - - } catch (err) { - logger.write(MODULE_NAME, "[ERROR] verifyMarketComplete -> loopCycle -> onLoad -> err = "+ err.stack); - callBackFunction(global.DEFAULT_FAIL_RESPONSE); - return; - } - } - } catch (err) { - logger.write(MODULE_NAME, "[ERROR] verifyMarketComplete -> loopCycle -> err = "+ err.stack); - callBackFunction(global.DEFAULT_FAIL_RESPONSE); - return; - } - } - - function readAndWriteNewReport(monthlyStatusReport) { - - try { - - if (global.LOG_CONTROL[MODULE_NAME].logInfo === true) { logger.write(MODULE_NAME, "[INFO] verifyMarketComplete -> readAndWriteNewReport -> Entering function."); } - - /* We will read the current file to preserve its data, and save it again with the new lastFile */ - - monthlyStatusReport = JSON.parse(monthlyStatusReport); - - timePath = ""; - - load(onLoad); - - function onLoad(err) { - - try { - - if (global.LOG_CONTROL[MODULE_NAME].logInfo === true) { logger.write(MODULE_NAME, "[INFO] verifyMarketComplete -> readAndWriteNewReport -> onLoad -> Entering function."); } - - if (err.result !== global.DEFAULT_OK_RESPONSE.result) { - logger.write(MODULE_NAME, "[ERROR] verifyMarketComplete -> readAndWriteNewReport -> onLoad -> err = "+ err.stack); - callBackFunction(err); - return; - } - - if (monthlyStatusReport.lastTrade.id > thisObject.file.lastTrade.id) { - - thisObject.file.lastFile = monthlyStatusReport.lastFile; - thisObject.file.lastTrade = monthlyStatusReport.lastTrade; - thisObject.file.lastTrade.counter = undefined; - - save(onSave); - - function onSave(err) { - - try { - - if (global.LOG_CONTROL[MODULE_NAME].logInfo === true) { logger.write(MODULE_NAME, "[INFO] verifyMarketComplete -> readAndWriteNewReport -> onLoad -> onSave -> Entering function."); } - - if (err.result !== global.DEFAULT_OK_RESPONSE.result) { - logger.write(MODULE_NAME, "[ERROR] verifyMarketComplete -> readAndWriteNewReport -> onLoad -> onSave -> err = "+ err.stack); - callBackFunction(err); - return; - } - - loop(); // Lets see the next month. - - } catch (err) { - logger.write(MODULE_NAME, "[ERROR] verifyMarketComplete -> readAndWriteNewReport -> onLoad -> onSave -> err = "+ err.stack); - callBackFunction(global.DEFAULT_FAIL_RESPONSE); - return; - } - } - - } else { - - if (global.LOG_CONTROL[MODULE_NAME].logInfo === true) { logger.write(MODULE_NAME, "[INFO] verifyMarketComplete -> readAndWriteNewReport -> onLoad -> Main Status Report Not Updated."); } - if (global.LOG_CONTROL[MODULE_NAME].logInfo === true) { logger.write(MODULE_NAME, "[INFO] verifyMarketComplete -> readAndWriteNewReport -> onLoad -> Current Trade Id (" + monthlyStatusReport.lastTrade.id + ") is <= than Id at main status report file. (" + thisObject.file.lastTrade.id + ")"); } - - loop(); // Lets see the next month. - } - - } catch (err) { - logger.write(MODULE_NAME, "[ERROR] verifyMarketComplete -> readAndWriteNewReport -> onLoad -> err = "+ err.stack); - callBackFunction(global.DEFAULT_FAIL_RESPONSE); - return; - } - } - } catch (err) { - logger.write(MODULE_NAME, "[ERROR] verifyMarketComplete -> loopCycle -> err = "+ err.stack); - callBackFunction(global.DEFAULT_FAIL_RESPONSE); - return; - } - } - - function loop() { - - try { - - if (global.LOG_CONTROL[MODULE_NAME].logInfo === true) { logger.write(MODULE_NAME, "[INFO] verifyMarketComplete -> loop -> Entering function."); } - - initialMonth++; - - if (initialMonth > 12) { - - initialMonth = 1; - initialYear++; - - } - - if ((initialYear === finalYear && initialMonth > finalMonth) || (initialYear > finalYear)) { - - /* We arrived to the point where we have checked all the status reports of every month and they are all complete. */ - - if (global.LOG_CONTROL[MODULE_NAME].logInfo === true) { logger.write(MODULE_NAME, "[INFO] verifyMarketComplete -> loop -> Verification Finished. Success."); } - - callBackFunction(global.DEFAULT_OK_RESPONSE); - return; - } - - loopCycle(); - - } catch (err) { - logger.write(MODULE_NAME, "[ERROR] verifyMarketComplete -> loop -> err = "+ err.stack); - callBackFunction(global.DEFAULT_FAIL_RESPONSE); - return; - } - } - } - catch (err) { - logger.write(MODULE_NAME, "[ERROR] verifyMarketComplete -> err = "+ err.stack); - callBackFunction(global.DEFAULT_FAIL_RESPONSE); - return; - } - } }; diff --git a/TaskServer/TradingBotProcessMainLoop.js b/TaskServer/TradingBotProcessMainLoop.js index 7f7124abe..01a0ce2dc 100644 --- a/TaskServer/TradingBotProcessMainLoop.js +++ b/TaskServer/TradingBotProcessMainLoop.js @@ -161,8 +161,8 @@ /* High level log entry */ - console.log(new Date().toISOString() + " " + pad(bot.codeName, 20) + " " + pad(bot.process, 30) + " " + bot.sessionKey - + " Loop # " + pad(Number(bot.loopCounter), 8)); + 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 ) /* Checking if we need to need to emit any event */ @@ -791,18 +791,6 @@ case global.CUSTOM_OK_RESPONSE.result: { switch (err.message) { - case "Too far in the future.": { - logger.write(MODULE_NAME, "[WARN] run -> loop -> intitializeProcessFramework -> onInizialized > Too far in the future. This Loop will enter in coma."); - nextWaitTime = 'Coma'; - loopControl(nextWaitTime); - return; - } - case "Not needed now, but soon.": { - logger.write(MODULE_NAME, "[WARN] run -> loop -> intitializeProcessFramework -> onInizialized > Not needed now, but soon. This Loop will continue with Normal wait time."); - nextWaitTime = 'Normal'; - loopControl(nextWaitTime); - return; - } default: { logger.write(MODULE_NAME, "[ERROR] run -> loop -> intitializeProcessFramework -> onInizialized > Unhandled custom response received. -> err = " + err.message); logger.persist(); @@ -907,36 +895,6 @@ loopControl(nextWaitTime); return; } - case "Month before it is needed.": { - logger.write(MODULE_NAME, "[WARN] run -> loop -> startProcessFramework -> onFinished -> Month before it is needed. This Loop will be terminated."); - logger.persist(); - clearInterval(fixedTimeLoopIntervalHandle); - clearTimeout(nextLoopTimeoutHandle); - clearTimeout(checkLoopHealthHandle); - bot.enableCheckLoopHealth = false; - callBackFunction(global.DEFAULT_OK_RESPONSE); - return; - } - case "Month fully processed.": { - logger.write(MODULE_NAME, "[WARN] run -> loop -> startProcessFramework -> onFinished -> Month fully processed. This Loop will be terminated."); - logger.persist(); - clearInterval(fixedTimeLoopIntervalHandle); - clearTimeout(nextLoopTimeoutHandle); - clearTimeout(checkLoopHealthHandle); - bot.enableCheckLoopHealth = false; - callBackFunction(global.DEFAULT_OK_RESPONSE); - return; - } - case "End of the month reached.": { - logger.write(MODULE_NAME, "[WARN] run -> loop -> startProcessFramework -> onFinished -> End of the month reached. This Loop will be terminated."); - logger.persist(); - clearInterval(fixedTimeLoopIntervalHandle); - clearTimeout(nextLoopTimeoutHandle); - clearTimeout(checkLoopHealthHandle); - bot.enableCheckLoopHealth = false; - callBackFunction(global.DEFAULT_OK_RESPONSE); - return; - } default: { logger.write(MODULE_NAME, "[ERROR] run -> loop -> startProcessFramework -> onFinished -> Unhandled custom response received. -> err = " + err.message); logger.persist(); diff --git a/TaskServer/server.js b/TaskServer/server.js index 49a63094f..700940611 100644 --- a/TaskServer/server.js +++ b/TaskServer/server.js @@ -50,7 +50,7 @@ process.on('exit', function (code) { global.SYSTEM_EVENT_HANDLER.finalize() global.SYSTEM_EVENT_HANDLER = undefined - console.log('[INFO] Task Server -> server -> process.on.exit -> About to exit -> code = ' + code) + //console.log('[INFO] Task Server -> server -> process.on.exit -> About to exit -> code = ' + code) }) /* Here we listen for the message to stop this Task / Process comming from the Task Manager, which is the paret of this node js process. */ @@ -63,7 +63,8 @@ process.on('message', message => { There are some process that might no be able to end grafully, for example the ones schedulle to process information in a future day or month. In order to be sure that the process will be terminated, we schedulle one forced exit in 2 minutes from now. */ - console.log('[INFO] Task Server -> server -> process.on -> Executing order received from Task Manager to Stop this Task. Nodejs process will be exited in less than 1 minute.') + let key = global.TASK_NODE.name + '-' + global.TASK_NODE.type + '-' + global.TASK_NODE.id + console.log('[INFO] Task Server -> server -> process.on -> Stopping Task ' + key + '. Nodejs process will be exited in less than 1 minute.') setTimeout(global.EXIT_NODE_PROCESS, 60000); } }); @@ -81,7 +82,7 @@ global.EXIT_NODE_PROCESS = function exitProcess() { global.SYSTEM_EVENT_HANDLER.raiseEvent(key, 'Stopped') // Meaning Process Stopped } - console.log("[INFO] Task Server -> " + global.TASK_NODE.name + " -> EXIT_NODE_PROCESS -> Task Server will stop in 10 seconds."); + //console.log("[INFO] Task Server -> " + global.TASK_NODE.name + " -> EXIT_NODE_PROCESS -> Task Server will stop in 10 seconds."); setTimeout(process.exit, 10000) // We will give 10 seconds to logs be written on file } @@ -119,7 +120,7 @@ function preLoader() { if (taskId !== undefined) { /* The Task Manager sent the info via a process argument. In this case we listen to an event with the Task Info that should be emitted at the UI */ try { - console.log('[INFO] Task Server -> server -> preLoader -> Listening to starting event -> key = ' + 'Task Server - ' + taskId) + //console.log('[INFO] Task Server -> server -> preLoader -> Listening to starting event -> key = ' + 'Task Server - ' + taskId) global.SYSTEM_EVENT_HANDLER.listenToEvent('Task Server - ' + taskId, 'Run Task', undefined, undefined, undefined, eventReceived) function eventReceived(message) { global.TASK_NODE = message @@ -133,7 +134,7 @@ function preLoader() { } else { /* This process was started not by the Task Manager, but independently (most likely for debugging purposes). In this case we listen to an event with the Task Info that should be emitted at the UI */ try { - console.log('[INFO] Task Server -> server -> preLoader -> Waiting for event to start debugging...') + //console.log('[INFO] Task Server -> server -> preLoader -> Waiting for event to start debugging...') global.SYSTEM_EVENT_HANDLER.listenToEvent('Task Server', 'Debug Task Started', undefined, undefined, undefined, startDebugging) function startDebugging(message) { global.TASK_NODE = message @@ -247,7 +248,7 @@ function bootLoader() { function startRoot(processIndex) { - console.log('[INFO] Task Server -> server -> startRoot -> Entering function. ') + // console.log('[INFO] Task Server -> server -> startRoot -> Entering function. ') const ROOT_MODULE = require('./Root') let root = ROOT_MODULE.newRoot() @@ -255,7 +256,7 @@ function startRoot(processIndex) { root.initialize(onInitialized) function onInitialized() { - console.log('[INFO] Task Server -> server -> startRoot -> onInitialized -> Entering function. ') + //console.log('[INFO] Task Server -> server -> startRoot -> onInitialized -> Entering function. ') root.start(processIndex) } }