From 789b97bc20be530195dcca4d6966a7307b8a44f6 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Mon, 30 Nov 2020 10:38:20 +0100 Subject: [PATCH] Folder Name finished --- .../Superalgos/TS/Globals/ProcessVariables.js | 12 ++++++++++++ TaskServer/DebugLog.js | 2 +- TaskServer/LearningSession.js | 15 +++++---------- .../LowFrequencyTrading/TradingSimulation.js | 2 +- TaskServer/TradingSession.js | 16 +++++----------- 5 files changed, 24 insertions(+), 23 deletions(-) diff --git a/Projects/Superalgos/TS/Globals/ProcessVariables.js b/Projects/Superalgos/TS/Globals/ProcessVariables.js index 080433876..69e06b340 100644 --- a/Projects/Superalgos/TS/Globals/ProcessVariables.js +++ b/Projects/Superalgos/TS/Globals/ProcessVariables.js @@ -10,5 +10,17 @@ exports.newSuperalgosGlobalsProcessVariables = function () { VARIABLES_BY_PROCESS_INDEX_MAP: new Map() } + /* + VARIABLES_BY_PROCESS_INDEX_MAP + + What it is stored here depends very much on what the process is about and what it needs to do. Following + is a list of known properties of this object. + + PROCESS_KEY This is the key used in events related to the Process + SESSION_KEY This is the key used in events related to the Session + SESSION_FOLDER_NAME This is the folder name for Session related data and logs. + MAIN_LOOP_COUNTER This is the counter of main loops for a bot process. + LOGS_TO_DELETE_QUEUE This stores the logs that need to be deleted, for auto mantainance. + */ return thisObject } \ No newline at end of file diff --git a/TaskServer/DebugLog.js b/TaskServer/DebugLog.js index bd96bc809..55a8a6ca2 100644 --- a/TaskServer/DebugLog.js +++ b/TaskServer/DebugLog.js @@ -112,7 +112,7 @@ exports.newDebugLog = function (processIndex) { let filePath = thisObject.bot.filePathRoot + "/Logs/" + TS.projects.superalgos.globals.taskConstants.TASK_NODE.bot.processes[processIndex].referenceParent.config.codeName + "/" - if (thisObject.bot.TRADING_SESSION !== undefined) { + if (TS.projects.superalgos.globals.processVariables.VARIABLES_BY_PROCESS_INDEX_MAP.get(processIndex).SESSION_FOLDER_NAME !== undefined) { filePath = filePath + TS.projects.superalgos.globals.processVariables.VARIABLES_BY_PROCESS_INDEX_MAP.get(processIndex).SESSION_FOLDER_NAME + "/" + executionDatetime; } else { if (thisObject.bot.LEARNING_SESSION !== undefined) { diff --git a/TaskServer/LearningSession.js b/TaskServer/LearningSession.js index a44bdc895..9aa2ffe8d 100644 --- a/TaskServer/LearningSession.js +++ b/TaskServer/LearningSession.js @@ -13,11 +13,6 @@ exports.newLearningSession = function (processIndex, bot, parentLogger) { function initialize(pProcessConfig, callBackFunction) { try { - /* Initialize this info so that everything is logged propeerly */ - bot.LEARNING_SESSION = { - name: TS.projects.superalgos.globals.taskConstants.TASK_NODE.bot.processes[processIndex].session.name, - id: TS.projects.superalgos.globals.taskConstants.TASK_NODE.bot.processes[processIndex].session.id - } /* Check if there is a session */ if (TS.projects.superalgos.globals.taskConstants.TASK_NODE.bot.processes[processIndex].session === undefined) { parentLogger.write(MODULE_NAME, "[ERROR] initialize -> Cannot run without a Session."); @@ -39,7 +34,7 @@ exports.newLearningSession = function (processIndex, bot, parentLogger) { We will also store the session folder name, to be used for debug logging. */ if (TS.projects.superalgos.globals.taskConstants.TASK_NODE.bot.processes[processIndex].session.config.folderName === undefined) { - VARIABLES_BY_PROCESS_INDEX.SESSION_FOLDER_NAME = TS.projects.superalgos.globals.taskConstants.TASK_NODE.bot.processes[processIndex].session.type.replace(' ', '-').replace(' ', '-') + '-' + bot.TRADING_SESSION.id + VARIABLES_BY_PROCESS_INDEX.SESSION_FOLDER_NAME = TS.projects.superalgos.globals.taskConstants.TASK_NODE.bot.processes[processIndex].session.type.replace(' ', '-').replace(' ', '-') + '-' + TS.projects.superalgos.globals.taskConstants.TASK_NODE.bot.processes[processIndex].session.id } else { VARIABLES_BY_PROCESS_INDEX.SESSION_FOLDER_NAME = TS.projects.superalgos.globals.taskConstants.TASK_NODE.bot.processes[processIndex].session.type.replace(' ', '-').replace(' ', '-') + '-' + TS.projects.superalgos.globals.taskConstants.TASK_NODE.bot.processes[processIndex].session.config.folderName } @@ -126,7 +121,7 @@ exports.newLearningSession = function (processIndex, bot, parentLogger) { parentLogger.write(MODULE_NAME, '[IMPORTANT] onSessionRun -> Stopping the Session now. ') } - socialBotsModule.sendMessage(bot.LEARNING_SESSION.type + " '" + bot.LEARNING_SESSION.name + "' is starting.") + socialBotsModule.sendMessage(bot.LEARNING_SESSION.type + " '" + TS.projects.superalgos.globals.taskConstants.TASK_NODE.bot.processes[processIndex].session.name + "' is starting.") } catch (err) { parentLogger.write(MODULE_NAME, "[ERROR] initialize -> onSessionRun -> err = " + err.stack); } @@ -152,7 +147,7 @@ exports.newLearningSession = function (processIndex, bot, parentLogger) { bot.RESUME = true bot.STOP_SESSION = false - socialBotsModule.sendMessage(bot.LEARNING_SESSION.type + " '" + bot.LEARNING_SESSION.name + "' is resuming.") + socialBotsModule.sendMessage(bot.LEARNING_SESSION.type + " '" + TS.projects.superalgos.globals.taskConstants.TASK_NODE.bot.processes[processIndex].session.name + "' is resuming.") } catch (err) { parentLogger.write(MODULE_NAME, "[ERROR] initialize -> onSessionResume -> err = " + err.stack); } @@ -160,7 +155,7 @@ exports.newLearningSession = function (processIndex, bot, parentLogger) { function stopSession(commandOrigin) { - socialBotsModule.sendMessage(bot.LEARNING_SESSION.type + " '" + bot.LEARNING_SESSION.name + "' is stopping " + commandOrigin) + socialBotsModule.sendMessage(bot.LEARNING_SESSION.type + " '" + TS.projects.superalgos.globals.taskConstants.TASK_NODE.bot.processes[processIndex].session.name + "' is stopping " + commandOrigin) socialBotsModule.finalize() bot.STOP_SESSION = true parentLogger.write(MODULE_NAME, '[IMPORTANT] stopSession -> Stopping the Session now. ') @@ -177,7 +172,7 @@ exports.newLearningSession = function (processIndex, bot, parentLogger) { if (bot.LEARNING_SESSION.config !== undefined) { config = bot.LEARNING_SESSION.config if (config.folderName === undefined) { - bot.LEARNING_SESSION.folderName = TS.projects.superalgos.globals.taskConstants.TASK_NODE.bot.processes[processIndex].session.type.replace(' ', '-').replace(' ', '-') + '-' + bot.LEARNING_SESSION.id + bot.LEARNING_SESSION.folderName = TS.projects.superalgos.globals.taskConstants.TASK_NODE.bot.processes[processIndex].session.type.replace(' ', '-').replace(' ', '-') + '-' + TS.projects.superalgos.globals.taskConstants.TASK_NODE.bot.processes[processIndex].session.id } else { bot.LEARNING_SESSION.folderName = TS.projects.superalgos.globals.taskConstants.TASK_NODE.bot.processes[processIndex].session.type.replace(' ', '-').replace(' ', '-') + '-' + TS.projects.superalgos.globals.taskConstants.TASK_NODE.bot.processes[processIndex].session.config.folderName } diff --git a/TaskServer/LowFrequencyTrading/TradingSimulation.js b/TaskServer/LowFrequencyTrading/TradingSimulation.js index d90194265..d8da65347 100644 --- a/TaskServer/LowFrequencyTrading/TradingSimulation.js +++ b/TaskServer/LowFrequencyTrading/TradingSimulation.js @@ -4,7 +4,7 @@ exports.newTradingSimulation = function (processIndex, bot, logger, tradingEngin the execution at each loop cycle of the Trading System Protocol. */ const FULL_LOG = true - const MODULE_NAME = 'Trading Simulation -> ' + bot.TRADING_SESSION.name + const MODULE_NAME = 'Trading Simulation -> ' + TS.projects.superalgos.globals.taskConstants.TASK_NODE.bot.processes[processIndex].session.name let thisObject = { finalize: finalize, diff --git a/TaskServer/TradingSession.js b/TaskServer/TradingSession.js index a55eeffa3..f8d710572 100644 --- a/TaskServer/TradingSession.js +++ b/TaskServer/TradingSession.js @@ -13,18 +13,12 @@ function initialize(pProcessConfig, callBackFunction) { try { - /* Initialize this info so that everything is logged propeerly */ - bot.TRADING_SESSION = { - name: TS.projects.superalgos.globals.taskConstants.TASK_NODE.bot.processes[processIndex].session.name, - id: TS.projects.superalgos.globals.taskConstants.TASK_NODE.bot.processes[processIndex].session.id - } /* Check if there is a session */ if (TS.projects.superalgos.globals.taskConstants.TASK_NODE.bot.processes[processIndex].session === undefined) { parentLogger.write(MODULE_NAME, "[ERROR] initialize -> Cannot run without a Session."); callBackFunction(TS.projects.superalgos.globals.standardResponses.DEFAULT_FAIL_RESPONSE); return; } - /* We will store here the session key, which we will need everytine we need to emit an event related to the session itself. @@ -41,7 +35,7 @@ We will also store the session folder name, to be used for debug logging and session output. */ if (TS.projects.superalgos.globals.taskConstants.TASK_NODE.bot.processes[processIndex].session.config.folderName === undefined) { - VARIABLES_BY_PROCESS_INDEX.SESSION_FOLDER_NAME = TS.projects.superalgos.globals.taskConstants.TASK_NODE.bot.processes[processIndex].session.type.replace(' ', '-').replace(' ', '-') + '-' + bot.TRADING_SESSION.id + VARIABLES_BY_PROCESS_INDEX.SESSION_FOLDER_NAME = TS.projects.superalgos.globals.taskConstants.TASK_NODE.bot.processes[processIndex].session.type.replace(' ', '-').replace(' ', '-') + '-' + TS.projects.superalgos.globals.taskConstants.TASK_NODE.bot.processes[processIndex].session.id } else { VARIABLES_BY_PROCESS_INDEX.SESSION_FOLDER_NAME = TS.projects.superalgos.globals.taskConstants.TASK_NODE.bot.processes[processIndex].session.type.replace(' ', '-').replace(' ', '-') + '-' + TS.projects.superalgos.globals.taskConstants.TASK_NODE.bot.processes[processIndex].session.config.folderName } @@ -128,7 +122,7 @@ parentLogger.write(MODULE_NAME, '[IMPORTANT] onSessionRun -> Stopping the Session now. ') } - socialBotsModule.sendMessage(bot.TRADING_SESSION.type + " '" + bot.TRADING_SESSION.name + "' is starting.") + socialBotsModule.sendMessage(bot.TRADING_SESSION.type + " '" + TS.projects.superalgos.globals.taskConstants.TASK_NODE.bot.processes[processIndex].session.name + "' is starting.") } catch (err) { parentLogger.write(MODULE_NAME, "[ERROR] initialize -> onSessionRun -> err = " + err.stack); } @@ -154,7 +148,7 @@ bot.RESUME = true bot.STOP_SESSION = false - socialBotsModule.sendMessage(bot.TRADING_SESSION.type + " '" + bot.TRADING_SESSION.name + "' is resuming.") + socialBotsModule.sendMessage(bot.TRADING_SESSION.type + " '" + TS.projects.superalgos.globals.taskConstants.TASK_NODE.bot.processes[processIndex].session.name + "' is resuming.") } catch (err) { parentLogger.write(MODULE_NAME, "[ERROR] initialize -> onSessionResume -> err = " + err.stack); } @@ -162,7 +156,7 @@ function stopSession(commandOrigin) { - socialBotsModule.sendMessage(bot.TRADING_SESSION.type + " '" + bot.TRADING_SESSION.name + "' is stopping " + commandOrigin) + socialBotsModule.sendMessage(bot.TRADING_SESSION.type + " '" + TS.projects.superalgos.globals.taskConstants.TASK_NODE.bot.processes[processIndex].session.name + "' is stopping " + commandOrigin) socialBotsModule.finalize() bot.STOP_SESSION = true parentLogger.write(MODULE_NAME, '[IMPORTANT] stopSession -> Stopping the Session now. ') @@ -179,7 +173,7 @@ if (bot.TRADING_SESSION.config !== undefined) { config = bot.TRADING_SESSION.config if (config.folderName === undefined) { - TS.projects.superalgos.globals.processVariables.VARIABLES_BY_PROCESS_INDEX_MAP.get(processIndex).SESSION_FOLDER_NAME = TS.projects.superalgos.globals.taskConstants.TASK_NODE.bot.processes[processIndex].session.type.replace(' ', '-').replace(' ', '-') + '-' + bot.TRADING_SESSION.id + TS.projects.superalgos.globals.processVariables.VARIABLES_BY_PROCESS_INDEX_MAP.get(processIndex).SESSION_FOLDER_NAME = TS.projects.superalgos.globals.taskConstants.TASK_NODE.bot.processes[processIndex].session.type.replace(' ', '-').replace(' ', '-') + '-' + TS.projects.superalgos.globals.taskConstants.TASK_NODE.bot.processes[processIndex].session.id } else { TS.projects.superalgos.globals.processVariables.VARIABLES_BY_PROCESS_INDEX_MAP.get(processIndex).SESSION_FOLDER_NAME = TS.projects.superalgos.globals.taskConstants.TASK_NODE.bot.processes[processIndex].session.type.replace(' ', '-').replace(' ', '-') + '-' + TS.projects.superalgos.globals.taskConstants.TASK_NODE.bot.processes[processIndex].session.config.folderName }