diff --git a/Projects/Superalgos/Bots-Plotters-Code/Masters/bots/Bollinger-Bands-Indicator-Bot/Multi-Period-Daily/User.Bot.js b/Projects/Superalgos/Bots-Plotters-Code/Masters/bots/Bollinger-Bands-Indicator-Bot/Multi-Period-Daily/User.Bot.js index 3b9e1564d..7b9f87388 100644 --- a/Projects/Superalgos/Bots-Plotters-Code/Masters/bots/Bollinger-Bands-Indicator-Bot/Multi-Period-Daily/User.Bot.js +++ b/Projects/Superalgos/Bots-Plotters-Code/Masters/bots/Bollinger-Bands-Indicator-Bot/Multi-Period-Daily/User.Bot.js @@ -281,10 +281,10 @@ /* Telling the world we are alive and doing well */ let currentDateString = processDate.getUTCFullYear() + '-' + utilities.pad(processDate.getUTCMonth() + 1, 2) + '-' + utilities.pad(processDate.getUTCDate(), 2); let currentDate = new Date(processDate) - let percentage = global.getPercentage(fromDate, currentDate, lastDate) + let percentage = global.GET_PERCENTAGE(fromDate, currentDate, lastDate) bot.processHeartBeat(currentDateString, percentage) - if (global.areEqualDates(currentDate, new Date()) === false) { + if (global.GET_EQUAL_DATES(currentDate, new Date()) === false) { logger.newInternalLoop(bot.codeName, bot.process, currentDate, percentage); } periodsLoop(); diff --git a/Projects/Superalgos/Bots-Plotters-Code/Masters/bots/Bollinger-Bands-Indicator-Bot/Multi-Period-Market/User.Bot.js b/Projects/Superalgos/Bots-Plotters-Code/Masters/bots/Bollinger-Bands-Indicator-Bot/Multi-Period-Market/User.Bot.js index 0de295c7a..2c9cad690 100644 --- a/Projects/Superalgos/Bots-Plotters-Code/Masters/bots/Bollinger-Bands-Indicator-Bot/Multi-Period-Market/User.Bot.js +++ b/Projects/Superalgos/Bots-Plotters-Code/Masters/bots/Bollinger-Bands-Indicator-Bot/Multi-Period-Market/User.Bot.js @@ -471,7 +471,7 @@ thisReport.file.lastExecution = bot.processDatetime; thisReport.save(callBack); - if (global.areEqualDates(bot.processDatetime, new Date()) === false) { + if (global.GET_EQUAL_DATES(bot.processDatetime, new Date()) === false) { logger.newInternalLoop(bot.codeName, bot.process, bot.processDatetime); } @@ -479,7 +479,7 @@ let currentDateString = bot.processDatetime.getUTCFullYear() + '-' + utilities.pad(bot.processDatetime.getUTCMonth() + 1, 2) + '-' + utilities.pad(bot.processDatetime.getUTCDate(), 2); let currentDate = new Date(bot.processDatetime) let lastDate = new Date() - bot.processHeartBeat(currentDateString, global.getPercentage(currentDate, currentDate, lastDate)) + bot.processHeartBeat(currentDateString, global.GET_PERCENTAGE(currentDate, currentDate, lastDate)) } catch (err) { logger.write(MODULE_NAME, "[ERROR] start -> writeStatusReport -> err = " + err.stack); diff --git a/Projects/Superalgos/Bots-Plotters-Code/Masters/bots/Candles-Volumes-Indicator-Bot/Multi-Period-Daily/User.Bot.js b/Projects/Superalgos/Bots-Plotters-Code/Masters/bots/Candles-Volumes-Indicator-Bot/Multi-Period-Daily/User.Bot.js index 8c6f880d2..8b484ff31 100644 --- a/Projects/Superalgos/Bots-Plotters-Code/Masters/bots/Candles-Volumes-Indicator-Bot/Multi-Period-Daily/User.Bot.js +++ b/Projects/Superalgos/Bots-Plotters-Code/Masters/bots/Candles-Volumes-Indicator-Bot/Multi-Period-Daily/User.Bot.js @@ -259,10 +259,10 @@ Read the candles and volumes from Exchange Raw Data and produce a file for each /* Telling the world we are alive and doing well */ let currentDateString = contextVariables.lastCandleFile.getUTCFullYear() + '-' + utilities.pad(contextVariables.lastCandleFile.getUTCMonth() + 1, 2) + '-' + utilities.pad(contextVariables.lastCandleFile.getUTCDate(), 2); let currentDate = new Date(contextVariables.lastCandleFile) - let percentage = global.getPercentage(fromDate, currentDate, lastDate) + let percentage = global.GET_PERCENTAGE(fromDate, currentDate, lastDate) bot.processHeartBeat(currentDateString, percentage) - if (global.areEqualDates(currentDate, new Date()) === false) { + if (global.GET_EQUAL_DATES(currentDate, new Date()) === false) { logger.newInternalLoop(bot.codeName, bot.process, currentDate, percentage); } /* diff --git a/Projects/Superalgos/Bots-Plotters-Code/Masters/bots/Candles-Volumes-Indicator-Bot/Multi-Period-Market/User.Bot.js b/Projects/Superalgos/Bots-Plotters-Code/Masters/bots/Candles-Volumes-Indicator-Bot/Multi-Period-Market/User.Bot.js index 1f017ddc0..5b2621dbe 100644 --- a/Projects/Superalgos/Bots-Plotters-Code/Masters/bots/Candles-Volumes-Indicator-Bot/Multi-Period-Market/User.Bot.js +++ b/Projects/Superalgos/Bots-Plotters-Code/Masters/bots/Candles-Volumes-Indicator-Bot/Multi-Period-Market/User.Bot.js @@ -425,10 +425,10 @@ /* Telling the world we are alive and doing well */ let currentDateString = contextVariables.lastCandleFile.getUTCFullYear() + '-' + utilities.pad(contextVariables.lastCandleFile.getUTCMonth() + 1, 2) + '-' + utilities.pad(contextVariables.lastCandleFile.getUTCDate(), 2); let currentDate = new Date(contextVariables.lastCandleFile) - let percentage = global.getPercentage(fromDate, currentDate, lastDate) + let percentage = global.GET_PERCENTAGE(fromDate, currentDate, lastDate) bot.processHeartBeat(currentDateString, percentage) - if (global.areEqualDates(currentDate, new Date()) === false) { + if (global.GET_EQUAL_DATES(currentDate, new Date()) === false) { logger.newInternalLoop(bot.codeName, bot.process, currentDate, percentage); } diff --git a/Projects/Superalgos/Bots-Plotters-Code/Masters/bots/Exchange-Raw-Data-Sensor-Bot/Historic-OHLCVs/User.Bot.js b/Projects/Superalgos/Bots-Plotters-Code/Masters/bots/Exchange-Raw-Data-Sensor-Bot/Historic-OHLCVs/User.Bot.js index 42d72a9ea..69a78ef46 100644 --- a/Projects/Superalgos/Bots-Plotters-Code/Masters/bots/Exchange-Raw-Data-Sensor-Bot/Historic-OHLCVs/User.Bot.js +++ b/Projects/Superalgos/Bots-Plotters-Code/Masters/bots/Exchange-Raw-Data-Sensor-Bot/Historic-OHLCVs/User.Bot.js @@ -262,9 +262,9 @@ exports.newUserBot = function newUserBot(bot, logger, COMMONS, UTILITIES, FILE_S if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> getOHLCVs -> Fetching OHLCVs @ " + processingDate + "-> exchange = " + bot.exchange + " -> symbol = " + symbol + " -> since = " + since + " -> limit = " + limit) } let heartBeatText = "Fetching " + allOHLCVs.length.toFixed(0) + " OHLCVs from " + bot.exchange + " " + symbol + " @ " + processingDate let currentDate = new Date(since) - let percentage = global.getPercentage(fromDate, currentDate, lastDate) + let percentage = global.GET_PERCENTAGE(fromDate, currentDate, lastDate) bot.processHeartBeat(heartBeatText, percentage) // tell the world we are alive and doing well - if (global.areEqualDates(currentDate, new Date()) === false) { + if (global.GET_EQUAL_DATES(currentDate, new Date()) === false) { if (noNewInternalLoop !== true) { logger.newInternalLoop(bot.codeName, bot.process, currentDate, percentage); } diff --git a/TaskServer/Globals.js b/TaskServer/Globals.js index 0db863956..f16573fae 100644 --- a/TaskServer/Globals.js +++ b/TaskServer/Globals.js @@ -365,7 +365,7 @@ exports.newGlobals = function newGlobals() { global.EXIT_NODE_PROCESS = function exitProcess() { if (global.unexpectedError !== undefined) { - global.taskError(undefined, "An unexpected error caused the Task to stop.") + global.TASK_ERROR(undefined, "An unexpected error caused the Task to stop.") } if (global.SHUTTING_DOWN_PROCESS === true) { return } @@ -408,7 +408,7 @@ exports.newGlobals = function newGlobals() { global.STOP_TASK_GRACEFULLY = false; - global.getPercentage = function (fromDate, currentDate, lastDate) { + global.GET_PERCENTAGE = function (fromDate, currentDate, lastDate) { let fromDays = Math.trunc(fromDate.valueOf() / global.ONE_DAY_IN_MILISECONDS) let currentDays = Math.trunc(currentDate.valueOf() / global.ONE_DAY_IN_MILISECONDS) let lastDays = Math.trunc(lastDate.valueOf() / global.ONE_DAY_IN_MILISECONDS) @@ -419,7 +419,7 @@ exports.newGlobals = function newGlobals() { return percentage } - global.areEqualDates = function (date1, date2) { + global.GET_EQUAL_DATES = function (date1, date2) { let day1Days = Math.trunc(date1.valueOf() / global.ONE_DAY_IN_MILISECONDS) let day2Days = Math.trunc(date2.valueOf() / global.ONE_DAY_IN_MILISECONDS) @@ -429,5 +429,23 @@ exports.newGlobals = function newGlobals() { return false } } + + global.TASK_ERROR = function taskError(node, errorMessage) { + let event + if (node !== undefined) { + event = { + nodeName: node.name, + nodeType: node.type, + nodeId: node.id, + errorMessage: errorMessage + } + } else { + event = { + errorMessage: errorMessage + } + } + + global.EVENT_SERVER_CLIENT_MODULE.raiseEvent(key, 'Error', event) + } } } \ No newline at end of file diff --git a/TaskServer/LowFrequencyTrading/TradingSimulation.js b/TaskServer/LowFrequencyTrading/TradingSimulation.js index 3c262e76a..e3452019c 100644 --- a/TaskServer/LowFrequencyTrading/TradingSimulation.js +++ b/TaskServer/LowFrequencyTrading/TradingSimulation.js @@ -265,7 +265,7 @@ exports.newTradingSimulation = function newTradingSimulation(bot, logger, tradin let currentDateString = heartBeatDate.getUTCFullYear() + '-' + utilities.pad(heartBeatDate.getUTCMonth() + 1, 2) + '-' + utilities.pad(heartBeatDate.getUTCDate(), 2) let currentDate = new Date(heartBeatDate) - let percentage = global.getPercentage(fromDate, currentDate, lastDate) + let percentage = global.GET_PERCENTAGE(fromDate, currentDate, lastDate) /* Theere are a few tasks that we need to do only when the date changes, @@ -279,7 +279,7 @@ exports.newTradingSimulation = function newTradingSimulation(bot, logger, tradin if (FULL_LOG === true) { logger.write(MODULE_NAME, '[INFO] runSimulation -> loop -> Simulation ' + bot.TRADING_SESSIONKey + ' Loop # ' + tradingEngine.current.episode.candle.index.value + ' @ ' + processingDate) } /* Logging to console and disk */ - if (global.areEqualDates(currentDate, new Date()) === false) { + if (global.GET_EQUAL_DATES(currentDate, new Date()) === false) { logger.newInternalLoop(bot.codeName, bot.process, currentDate, percentage) } diff --git a/TaskServer/MultiPeriodDaily.js b/TaskServer/MultiPeriodDaily.js index b1091f548..8a151ceee 100644 --- a/TaskServer/MultiPeriodDaily.js +++ b/TaskServer/MultiPeriodDaily.js @@ -248,10 +248,10 @@ /* 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) - let percentage = global.getPercentage(fromDate, currentDate, lastDate) + let percentage = global.GET_PERCENTAGE(fromDate, currentDate, lastDate) bot.processHeartBeat(currentDateString, percentage) - if (global.areEqualDates(currentDate, new Date()) === false) { + if (global.GET_EQUAL_DATES(currentDate, new Date()) === false) { logger.newInternalLoop(bot.codeName, bot.process, currentDate, percentage) } checkStopTaskGracefully() diff --git a/TaskServer/MultiPeriodMarket.js b/TaskServer/MultiPeriodMarket.js index 76ba55b28..c15592590 100644 --- a/TaskServer/MultiPeriodMarket.js +++ b/TaskServer/MultiPeriodMarket.js @@ -202,7 +202,7 @@ } thisReport.save(callBack) - if (global.areEqualDates(bot.processDatetime, new Date()) === false) { + if (global.GET_EQUAL_DATES(bot.processDatetime, new Date()) === false) { logger.newInternalLoop(bot.codeName, bot.process, bot.processDatetime) } @@ -210,7 +210,7 @@ let currentDateString = bot.processDatetime.getUTCFullYear() + '-' + utilities.pad(bot.processDatetime.getUTCMonth() + 1, 2) + '-' + utilities.pad(bot.processDatetime.getUTCDate(), 2) let currentDate = new Date(bot.processDatetime) let lastDate = new Date() - bot.processHeartBeat(currentDateString, global.getPercentage(currentDate, currentDate, lastDate)) + bot.processHeartBeat(currentDateString, global.GET_PERCENTAGE(currentDate, currentDate, lastDate)) } } catch (err) { diff --git a/TaskServer/server.js b/TaskServer/server.js index 1d22e8cbf..786e33d18 100644 --- a/TaskServer/server.js +++ b/TaskServer/server.js @@ -42,9 +42,13 @@ function preLoader() { console.log('[ERROR] Task Server -> server -> preLoader -> global.TASK_NODE = ' + JSON.stringify(global.TASK_NODE).substring(0, 1000)) } } - 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 */ + 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...') global.EVENT_SERVER_CLIENT_MODULE.listenToEvent('Task Server', 'Debug Task Started', undefined, 'Task Server', undefined, startDebugging) function startDebugging(message) { try { @@ -94,25 +98,6 @@ function bootLoader() { global.EVENT_SERVER_CLIENT_MODULE.raiseEvent(key, 'Heartbeat', event) } - global.taskError = function taskError(node, errorMessage) { - let event - if (node !== undefined) { - event = { - nodeName: node.name, - nodeType: node.type, - nodeId: node.id, - errorMessage: errorMessage - } - } else { - event = { - errorMessage: errorMessage - } - } - - global.EVENT_SERVER_CLIENT_MODULE.raiseEvent(key, 'Error', event) - } - - for (let processIndex = 0; processIndex < global.TASK_NODE.bot.processes.length; processIndex++) { let config = global.TASK_NODE.bot.processes[processIndex].config