From 772b10632592244de5d1414789c199611dfb7a50 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Mon, 30 Nov 2020 12:06:29 +0100 Subject: [PATCH] Process Constants --- Projects/ProjectsSchema.json | 6 ++++++ .../Superalgos/TS/Globals/ProcessConstants.js | 19 +++++++++++++++++++ TaskServer/LearningSession.js | 4 ++-- .../LowFrequencyTrading/TradingProcess.js | 4 ++-- TaskServer/ProcessInstance.js | 5 +++++ .../ReinforcementLearning/LearningProcess.js | 4 ++-- TaskServer/TradingSession.js | 4 ++-- 7 files changed, 38 insertions(+), 8 deletions(-) create mode 100644 Projects/Superalgos/TS/Globals/ProcessConstants.js diff --git a/Projects/ProjectsSchema.json b/Projects/ProjectsSchema.json index 2b00efbff..b2cbf7811 100644 --- a/Projects/ProjectsSchema.json +++ b/Projects/ProjectsSchema.json @@ -350,6 +350,12 @@ "functionName": "newSuperalgosGlobalsProcessVariables", "fileName": "ProcessVariables.js" }, + { + "name": "Process Constants", + "propertyName": "processConstants", + "functionName": "newSuperalgosGlobalsProcessConstants", + "fileName": "ProcessConstants.js" + }, { "name": "Task Variables", "propertyName": "taskVariables", diff --git a/Projects/Superalgos/TS/Globals/ProcessConstants.js b/Projects/Superalgos/TS/Globals/ProcessConstants.js new file mode 100644 index 000000000..db6a2e7ff --- /dev/null +++ b/Projects/Superalgos/TS/Globals/ProcessConstants.js @@ -0,0 +1,19 @@ +exports.newSuperalgosGlobalsProcessConstants = function () { + + let thisObject = { + CONSTANTS_BY_PROCESS_INDEX_MAP: new Map() + } + + /* + CONSTANTS_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. + + TRADING_SYSTEM_NODE This is a Trading System node structure. + TRADING_ENGINE_NODE This is a Trading Engine node structure. + TRADING_SESSION_NODE This is a Trading Session node structure. + DEPENDENCY_FILTER This is the counter of main loops for a bot process. + */ + return thisObject +} \ No newline at end of file diff --git a/TaskServer/LearningSession.js b/TaskServer/LearningSession.js index 9aa2ffe8d..f736b5f55 100644 --- a/TaskServer/LearningSession.js +++ b/TaskServer/LearningSession.js @@ -79,8 +79,8 @@ exports.newLearningSession = function (processIndex, bot, parentLogger) { } /* We are going to run the Definition comming at the event. */ - bot.TRADING_SYSTEM = JSON.parse(message.event.tradingSystem) - bot.TRADING_ENGINE = JSON.parse(message.event.tradingEngine) + TS.projects.superalgos.globals.processConstants.CONSTANTS_BY_PROCESS_INDEX_MAP.get(processIndex).TRADING_SYSTEM_NODE = JSON.parse(message.event.tradingSystem) + TS.projects.superalgos.globals.processConstants.CONSTANTS_BY_PROCESS_INDEX_MAP.get(processIndex).TRADING_ENGINE_NODE = JSON.parse(message.event.tradingEngine) bot.LEARNING_SESSION = JSON.parse(message.event.session) bot.DEPENDENCY_FILTER = JSON.parse(message.event.dependencyFilter) bot.RESUME = false diff --git a/TaskServer/LowFrequencyTrading/TradingProcess.js b/TaskServer/LowFrequencyTrading/TradingProcess.js index 2adbca27b..430f59234 100644 --- a/TaskServer/LowFrequencyTrading/TradingProcess.js +++ b/TaskServer/LowFrequencyTrading/TradingProcess.js @@ -87,8 +87,8 @@ /* Here is where the Trading Engine and Trading Systems received are moved to the simulation state. */ - bot.simulationState.tradingEngine = bot.TRADING_ENGINE - bot.simulationState.tradingSystem = bot.TRADING_SYSTEM + bot.simulationState.tradingEngine = TS.projects.superalgos.globals.processConstants.CONSTANTS_BY_PROCESS_INDEX_MAP.get(processIndex).TRADING_ENGINE_NODE + bot.simulationState.tradingSystem = TS.projects.superalgos.globals.processConstants.CONSTANTS_BY_PROCESS_INDEX_MAP.get(processIndex).TRADING_SYSTEM_NODE } /* We set up the Trading Engine Module. */ diff --git a/TaskServer/ProcessInstance.js b/TaskServer/ProcessInstance.js index 2dfd614eb..f4ee918c6 100644 --- a/TaskServer/ProcessInstance.js +++ b/TaskServer/ProcessInstance.js @@ -45,6 +45,11 @@ TS.projects.superalgos.globals.taskConstants.TASK_NODE.bot.processes[processIndex].id } TS.projects.superalgos.globals.processVariables.VARIABLES_BY_PROCESS_INDEX_MAP.set(processIndex, VARIABLES_BY_PROCESS_INDEX) + /* + There are also a few constants at the process level. We initialize them here. + */ + let CONSTANTS_BY_PROCESS_INDEX = {} + TS.projects.superalgos.globals.processConstants.CONSTANTS_BY_PROCESS_INDEX_MAP.set(processIndex, CONSTANTS_BY_PROCESS_INDEX) /* File Path Root */ botConfig.filePathRoot = diff --git a/TaskServer/ReinforcementLearning/LearningProcess.js b/TaskServer/ReinforcementLearning/LearningProcess.js index 1144c4506..473b21a7c 100644 --- a/TaskServer/ReinforcementLearning/LearningProcess.js +++ b/TaskServer/ReinforcementLearning/LearningProcess.js @@ -87,8 +87,8 @@ exports.newLearningProcess = function (processIndex, bot, logger, UTILITIES) { /* Here is where the Trading Engine and Trading Systems received are moved to the simulation state. */ - bot.simulationState.tradingEngine = bot.TRADING_ENGINE - bot.simulationState.tradingSystem = bot.TRADING_SYSTEM + bot.simulationState.tradingEngine = TS.projects.superalgos.globals.processConstants.CONSTANTS_BY_PROCESS_INDEX_MAP.get(processIndex).TRADING_ENGINE_NODE + bot.simulationState.tradingSystem = TS.projects.superalgos.globals.processConstants.CONSTANTS_BY_PROCESS_INDEX_MAP.get(processIndex).TRADING_SYSTEM_NODE } /* We set up the Trading Engine Module. */ diff --git a/TaskServer/TradingSession.js b/TaskServer/TradingSession.js index f8d710572..8198f6f8a 100644 --- a/TaskServer/TradingSession.js +++ b/TaskServer/TradingSession.js @@ -80,8 +80,8 @@ } /* We are going to run the Definition comming at the event. */ - bot.TRADING_SYSTEM = JSON.parse(message.event.tradingSystem) - bot.TRADING_ENGINE = JSON.parse(message.event.tradingEngine) + TS.projects.superalgos.globals.processConstants.CONSTANTS_BY_PROCESS_INDEX_MAP.get(processIndex).TRADING_SYSTEM_NODE = JSON.parse(message.event.tradingSystem) + TS.projects.superalgos.globals.processConstants.CONSTANTS_BY_PROCESS_INDEX_MAP.get(processIndex).TRADING_ENGINE_NODE = JSON.parse(message.event.tradingEngine) bot.TRADING_SESSION = JSON.parse(message.event.session) bot.DEPENDENCY_FILTER = JSON.parse(message.event.dependencyFilter) bot.RESUME = false