diff --git a/TaskServer/DebugLog.js b/TaskServer/DebugLog.js index 78fea95d5..07901b028 100644 --- a/TaskServer/DebugLog.js +++ b/TaskServer/DebugLog.js @@ -114,9 +114,9 @@ exports.newDebugLog = function (processIndex) { let fileName; if (internalLoopCounter >= 0) { - fileName = "Loop." + pad(thisObject.bot.loopCounter, 8) + "." + pad(internalLoopCounter, 4) + ".json"; + fileName = "Loop." + pad(TS.projects.superalgos.globals.processVariables.VARIABLES_BY_PROCESS_INDEX_MAP.get(processIndex).MAIN_LOOP_COUNTER, 8) + "." + pad(internalLoopCounter, 4) + ".json"; } else { - fileName = "Loop." + pad(thisObject.bot.loopCounter, 8) + ".json"; + fileName = "Loop." + pad(TS.projects.superalgos.globals.processVariables.VARIABLES_BY_PROCESS_INDEX_MAP.get(processIndex).MAIN_LOOP_COUNTER, 8) + ".json"; } writeLog(); diff --git a/TaskServer/IndicatorBot.js b/TaskServer/IndicatorBot.js index c7c62bf54..6816736b9 100644 --- a/TaskServer/IndicatorBot.js +++ b/TaskServer/IndicatorBot.js @@ -111,7 +111,7 @@ logger.bot = bot; logger.initialize(); - bot.loopCounter++; + TS.projects.superalgos.globals.processVariables.VARIABLES_BY_PROCESS_INDEX_MAP.get(processIndex).MAIN_LOOP_COUNTER++; bot.loopStartTime = new Date().valueOf(); /* We tell the UI that we are running. */ @@ -131,7 +131,7 @@ /* High level log entry */ console.log(new Date().toISOString() + " " + pad(TS.projects.superalgos.globals.taskConstants.TASK_NODE.parentNode.parentNode.parentNode.referenceParent.parentNode.parentNode.name, 20) + " " + pad(TS.projects.superalgos.globals.taskConstants.TASK_NODE.parentNode.parentNode.parentNode.referenceParent.baseAsset.referenceParent.config.codeName + '/' + TS.projects.superalgos.globals.taskConstants.TASK_NODE.parentNode.parentNode.parentNode.referenceParent.quotedAsset.referenceParent.config.codeName, 10) + " " + pad(bot.codeName, 30) + " " + pad(TS.projects.superalgos.globals.taskConstants.TASK_NODE.bot.processes[processIndex].referenceParent.config.codeName, 30) - + " Main Loop # " + pad(Number(bot.loopCounter), 8)) + + " Main Loop # " + pad(Number(TS.projects.superalgos.globals.processVariables.VARIABLES_BY_PROCESS_INDEX_MAP.get(processIndex).MAIN_LOOP_COUNTER), 8)) /* We will prepare first the infraestructure needed for the bot to run. There are 3 modules we need to sucessfullly initialize first. */ let processExecutionEvents diff --git a/TaskServer/ProcessInstance.js b/TaskServer/ProcessInstance.js index 02b01a011..168e3576a 100644 --- a/TaskServer/ProcessInstance.js +++ b/TaskServer/ProcessInstance.js @@ -32,7 +32,15 @@ TS.projects.superalgos.globals.taskVariables.LOGGER_MAP.set('Pre-Bot-Main-Loop' + TS.projects.superalgos.globals.taskConstants.TASK_NODE.bot.processes[processIndex].id, logger) logger.bot = botConfig; - TS.projects.superalgos.globals.processVariables.VARIABLES_BY_PROCESS_INDEX_MAP.set(processIndex, {LOGS_TO_DELETE_QUEUE: []}) + /* + There are a few variables with the scope of the process instance. We will store it here so that it can be + accesed from where it is needed. + */ + let VARIABLES_BY_PROCESS_INDEX = { + LOGS_TO_DELETE_QUEUE: [], + MAIN_LOOP_COUNTER: 0 + } + TS.projects.superalgos.globals.processVariables.VARIABLES_BY_PROCESS_INDEX_MAP.set(processIndex, VARIABLES_BY_PROCESS_INDEX) /* Loop Counter */ botConfig.loopCounter = 0; @@ -271,7 +279,7 @@ function whenRunFinishes(err) { - botConfig.loopCounter = 0; + TS.projects.superalgos.globals.processVariables.VARIABLES_BY_PROCESS_INDEX_MAP.get(processIndex).MAIN_LOOP_COUNTER = 0; let botId = TS.projects.superalgos.globals.taskConstants.TASK_NODE.bot.processes[processIndex].referenceParent.parentNode.parentNode.config.codeName + "." + botConfig.codeName + "." + TS.projects.superalgos.globals.taskConstants.TASK_NODE.bot.processes[processIndex].referenceParent.config.codeName; diff --git a/TaskServer/ReinforcementLearning/LearningBot.js b/TaskServer/ReinforcementLearning/LearningBot.js index b8d815014..3c73659b6 100644 --- a/TaskServer/ReinforcementLearning/LearningBot.js +++ b/TaskServer/ReinforcementLearning/LearningBot.js @@ -68,7 +68,7 @@ exports.newLearningBot = function (processIndex, bot, parentLogger) { logger.bot = bot; logger.initialize(); - bot.loopCounter++; + TS.projects.superalgos.globals.processVariables.VARIABLES_BY_PROCESS_INDEX_MAP.get(processIndex).MAIN_LOOP_COUNTER++; bot.loopStartTime = new Date().valueOf(); let nextWaitTime; @@ -90,7 +90,7 @@ exports.newLearningBot = function (processIndex, bot, parentLogger) { /* High level log entry */ console.log(new Date().toISOString() + " " + pad(TS.projects.superalgos.globals.taskConstants.TASK_NODE.parentNode.parentNode.parentNode.referenceParent.parentNode.parentNode.name, 20) + " " + pad(TS.projects.superalgos.globals.taskConstants.TASK_NODE.parentNode.parentNode.parentNode.referenceParent.baseAsset.referenceParent.config.codeName + '/' + TS.projects.superalgos.globals.taskConstants.TASK_NODE.parentNode.parentNode.parentNode.referenceParent.quotedAsset.referenceParent.config.codeName, 10) + " " + pad(bot.codeName, 30) + " " + pad(TS.projects.superalgos.globals.taskConstants.TASK_NODE.bot.processes[processIndex].referenceParent.config.codeName, 30) - + " Main Loop # " + pad(Number(bot.loopCounter), 8) + " " + TS.projects.superalgos.globals.taskConstants.TASK_NODE.bot.processes[processIndex].session.type + " " + TS.projects.superalgos.globals.taskConstants.TASK_NODE.bot.processes[processIndex].session.name) + + " Main Loop # " + pad(Number(TS.projects.superalgos.globals.processVariables.VARIABLES_BY_PROCESS_INDEX_MAP.get(processIndex).MAIN_LOOP_COUNTER), 8) + " " + TS.projects.superalgos.globals.taskConstants.TASK_NODE.bot.processes[processIndex].session.type + " " + TS.projects.superalgos.globals.taskConstants.TASK_NODE.bot.processes[processIndex].session.name) /* Checking if we need to need to emit any event */ if (bot.SESSION_STATUS === 'Idle' && bot.STOP_SESSION === false) { diff --git a/TaskServer/SensorBot.js b/TaskServer/SensorBot.js index 215fd1fb5..de3ce3e23 100644 --- a/TaskServer/SensorBot.js +++ b/TaskServer/SensorBot.js @@ -118,7 +118,7 @@ logger.bot = bot; logger.initialize(); - bot.loopCounter++; + TS.projects.superalgos.globals.processVariables.VARIABLES_BY_PROCESS_INDEX_MAP.get(processIndex).MAIN_LOOP_COUNTER++; bot.loopStartTime = new Date().valueOf(); /* We tell the UI that we are running. */ @@ -136,7 +136,7 @@ /* High level log entry */ console.log(new Date().toISOString() + " " + pad(TS.projects.superalgos.globals.taskConstants.TASK_NODE.parentNode.parentNode.parentNode.referenceParent.parentNode.parentNode.name, 20) + " " + pad(TS.projects.superalgos.globals.taskConstants.TASK_NODE.parentNode.parentNode.parentNode.referenceParent.baseAsset.referenceParent.config.codeName + '/' + TS.projects.superalgos.globals.taskConstants.TASK_NODE.parentNode.parentNode.parentNode.referenceParent.quotedAsset.referenceParent.config.codeName, 10) + " " + pad(bot.codeName, 30) + " " + pad(TS.projects.superalgos.globals.taskConstants.TASK_NODE.bot.processes[processIndex].referenceParent.config.codeName, 30) - + " Main Loop # " + pad(Number(bot.loopCounter), 8)) + + " Main Loop # " + pad(Number(TS.projects.superalgos.globals.processVariables.VARIABLES_BY_PROCESS_INDEX_MAP.get(processIndex).MAIN_LOOP_COUNTER), 8)) /* We will prepare first the infraestructure needed for the bot to run. There are 4 modules we need to sucessfullly initialize first. */ let processExecutionEvents diff --git a/TaskServer/TradingBot.js b/TaskServer/TradingBot.js index a5f375e79..f14cc37d3 100644 --- a/TaskServer/TradingBot.js +++ b/TaskServer/TradingBot.js @@ -68,7 +68,7 @@ logger.bot = bot; logger.initialize(); - bot.loopCounter++; + TS.projects.superalgos.globals.processVariables.VARIABLES_BY_PROCESS_INDEX_MAP.get(processIndex).MAIN_LOOP_COUNTER++; bot.loopStartTime = new Date().valueOf(); let nextWaitTime; @@ -90,7 +90,7 @@ /* High level log entry */ console.log(new Date().toISOString() + " " + pad(TS.projects.superalgos.globals.taskConstants.TASK_NODE.parentNode.parentNode.parentNode.referenceParent.parentNode.parentNode.name, 20) + " " + pad(TS.projects.superalgos.globals.taskConstants.TASK_NODE.parentNode.parentNode.parentNode.referenceParent.baseAsset.referenceParent.config.codeName + '/' + TS.projects.superalgos.globals.taskConstants.TASK_NODE.parentNode.parentNode.parentNode.referenceParent.quotedAsset.referenceParent.config.codeName, 10) + " " + pad(bot.codeName, 30) + " " + pad(TS.projects.superalgos.globals.taskConstants.TASK_NODE.bot.processes[processIndex].referenceParent.config.codeName, 30) - + " Main Loop # " + pad(Number(bot.loopCounter), 8) + " " + TS.projects.superalgos.globals.taskConstants.TASK_NODE.bot.processes[processIndex].session.type + " " + TS.projects.superalgos.globals.taskConstants.TASK_NODE.bot.processes[processIndex].session.name) + + " Main Loop # " + pad(Number(TS.projects.superalgos.globals.processVariables.VARIABLES_BY_PROCESS_INDEX_MAP.get(processIndex).MAIN_LOOP_COUNTER), 8) + " " + TS.projects.superalgos.globals.taskConstants.TASK_NODE.bot.processes[processIndex].session.type + " " + TS.projects.superalgos.globals.taskConstants.TASK_NODE.bot.processes[processIndex].session.name) /* Checking if we need to need to emit any event */ if (bot.TRADING_SESSION_STATUS === 'Idle' && bot.STOP_SESSION === false) {