diff --git a/Projects/Superalgos/TS/Globals/ProcessVariables.js b/Projects/Superalgos/TS/Globals/ProcessVariables.js index 9c456a9ff..569592c3e 100644 --- a/Projects/Superalgos/TS/Globals/ProcessVariables.js +++ b/Projects/Superalgos/TS/Globals/ProcessVariables.js @@ -25,7 +25,8 @@ exports.newSuperalgosGlobalsProcessVariables = function () { SESSION_STATUS This tell us the status of the session at any given time. IS_SESSION_STOPPING This tell us if a session is in the process of being stopped. IS_SESSION_RESUMING This tell us if a session is resuming from the state at the previous execution. - IS_SESSION_FIRST_LOOP This tell us if we are at the execution of the first loop of the bot related to this session. + IS_SESSION_FIRST_LOOP This tell us if we are at the execution of the first loop of the bot related to this session. + SIMULATION_STATE This is the state of a simulaation, as it is loaded from disk. */ return thisObject } \ No newline at end of file diff --git a/TaskServer/LearningSession.js b/TaskServer/LearningSession.js index 5706eb102..ce4154f30 100644 --- a/TaskServer/LearningSession.js +++ b/TaskServer/LearningSession.js @@ -83,8 +83,8 @@ exports.newLearningSession = function (processIndex, bot, parentLogger) { 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) TS.projects.superalgos.globals.processConstants.CONSTANTS_BY_PROCESS_INDEX_MAP.get(processIndex).DEPENDENCY_FILTER = JSON.parse(message.event.dependencyFilter) - TS.projects.superalgos.globals.processConstants.CONSTANTS_BY_PROCESS_INDEX_MAP.get(processIndex).IS_SESSION_RESUMING = false - TS.projects.superalgos.globals.processConstants.CONSTANTS_BY_PROCESS_INDEX_MAP.get(processIndex).IS_SESSION_FIRST_LOOP = true + TS.projects.superalgos.globals.processVariables.VARIABLES_BY_PROCESS_INDEX_MAP.get(processIndex).IS_SESSION_RESUMING = false + TS.projects.superalgos.globals.processVariables.VARIABLES_BY_PROCESS_INDEX_MAP.get(processIndex).IS_SESSION_FIRST_LOOP = true bot.LEARNING_SESSION.stop = stopSession // stop function setUpSessionFolderName() @@ -144,7 +144,7 @@ exports.newLearningSession = function (processIndex, bot, parentLogger) { return } - TS.projects.superalgos.globals.processConstants.CONSTANTS_BY_PROCESS_INDEX_MAP.get(processIndex).IS_SESSION_RESUMING = true + TS.projects.superalgos.globals.processVariables.VARIABLES_BY_PROCESS_INDEX_MAP.get(processIndex).IS_SESSION_RESUMING = true TS.projects.superalgos.globals.processVariables.VARIABLES_BY_PROCESS_INDEX_MAP.get(processIndex).IS_SESSION_STOPPING = false TS.projects.superalgos.globals.processVariables.VARIABLES_BY_PROCESS_INDEX_MAP.get(processIndex).SOCIAL_BOTS_MODULE.sendMessage(bot.LEARNING_SESSION.type + " '" + TS.projects.superalgos.globals.taskConstants.TASK_NODE.bot.processes[processIndex].session.name + "' is resuming.") diff --git a/TaskServer/LowFrequencyTrading/Announcements.js b/TaskServer/LowFrequencyTrading/Announcements.js index 48730852e..f52a6ae4f 100644 --- a/TaskServer/LowFrequencyTrading/Announcements.js +++ b/TaskServer/LowFrequencyTrading/Announcements.js @@ -14,8 +14,8 @@ exports.newAnnouncements = function (processIndex, bot, logger) { return thisObject function initialize() { - tradingSystem = bot.simulationState.tradingSystem - tradingEngine = bot.simulationState.tradingEngine + tradingSystem = TS.projects.superalgos.globals.processVariables.VARIABLES_BY_PROCESS_INDEX_MAP.get(processIndex).SIMULATION_STATE.tradingSystem + tradingEngine = TS.projects.superalgos.globals.processVariables.VARIABLES_BY_PROCESS_INDEX_MAP.get(processIndex).SIMULATION_STATE.tradingEngine } function finalize() { diff --git a/TaskServer/LowFrequencyTrading/ExchangeAPI.js b/TaskServer/LowFrequencyTrading/ExchangeAPI.js index 18af1f71f..a6d8c4fb7 100644 --- a/TaskServer/LowFrequencyTrading/ExchangeAPI.js +++ b/TaskServer/LowFrequencyTrading/ExchangeAPI.js @@ -21,7 +21,7 @@ return thisObject; function initialize() { - tradingSystem = bot.simulationState.tradingSystem + tradingSystem = TS.projects.superalgos.globals.processVariables.VARIABLES_BY_PROCESS_INDEX_MAP.get(processIndex).SIMULATION_STATE.tradingSystem exchangeId = TS.projects.superalgos.globals.taskConstants.TASK_NODE.parentNode.parentNode.parentNode.referenceParent.parentNode.parentNode.name.toLowerCase() diff --git a/TaskServer/LowFrequencyTrading/OrdersCalculations.js b/TaskServer/LowFrequencyTrading/OrdersCalculations.js index c138310b0..aa06cfe7d 100644 --- a/TaskServer/LowFrequencyTrading/OrdersCalculations.js +++ b/TaskServer/LowFrequencyTrading/OrdersCalculations.js @@ -24,8 +24,8 @@ exports.newOrdersCalculations = function (processIndex, bot, logger) { function initialize() { sessionParameters = TS.projects.superalgos.globals.processConstants.CONSTANTS_BY_PROCESS_INDEX_MAP.get(processIndex).SESSION_NODE.tradingParameters - tradingEngine = bot.simulationState.tradingEngine - tradingSystem = bot.simulationState.tradingSystem + tradingEngine = TS.projects.superalgos.globals.processVariables.VARIABLES_BY_PROCESS_INDEX_MAP.get(processIndex).SIMULATION_STATE.tradingEngine + tradingSystem = TS.projects.superalgos.globals.processVariables.VARIABLES_BY_PROCESS_INDEX_MAP.get(processIndex).SIMULATION_STATE.tradingSystem } function finalize() { diff --git a/TaskServer/LowFrequencyTrading/OrdersSimulations.js b/TaskServer/LowFrequencyTrading/OrdersSimulations.js index f66c6b4ad..38b357945 100644 --- a/TaskServer/LowFrequencyTrading/OrdersSimulations.js +++ b/TaskServer/LowFrequencyTrading/OrdersSimulations.js @@ -24,8 +24,8 @@ exports.newOrdersSimulations = function (processIndex, bot, logger) { function initialize() { sessionParameters = TS.projects.superalgos.globals.processConstants.CONSTANTS_BY_PROCESS_INDEX_MAP.get(processIndex).SESSION_NODE.tradingParameters - tradingEngine = bot.simulationState.tradingEngine - tradingSystem = bot.simulationState.tradingSystem + tradingEngine = TS.projects.superalgos.globals.processVariables.VARIABLES_BY_PROCESS_INDEX_MAP.get(processIndex).SIMULATION_STATE.tradingEngine + tradingSystem = TS.projects.superalgos.globals.processVariables.VARIABLES_BY_PROCESS_INDEX_MAP.get(processIndex).SIMULATION_STATE.tradingSystem } function finalize() { diff --git a/TaskServer/LowFrequencyTrading/Snapshots.js b/TaskServer/LowFrequencyTrading/Snapshots.js index 80d528565..a927045ad 100644 --- a/TaskServer/LowFrequencyTrading/Snapshots.js +++ b/TaskServer/LowFrequencyTrading/Snapshots.js @@ -43,8 +43,8 @@ exports.newSnapshots = function (processIndex, bot, logger) { return thisObject function initialize() { - tradingEngine = bot.simulationState.tradingEngine - tradingSystem = bot.simulationState.tradingSystem + tradingEngine = TS.projects.superalgos.globals.processVariables.VARIABLES_BY_PROCESS_INDEX_MAP.get(processIndex).SIMULATION_STATE.tradingEngine + tradingSystem = TS.projects.superalgos.globals.processVariables.VARIABLES_BY_PROCESS_INDEX_MAP.get(processIndex).SIMULATION_STATE.tradingSystem sessionParameters = TS.projects.superalgos.globals.processConstants.CONSTANTS_BY_PROCESS_INDEX_MAP.get(processIndex).SESSION_NODE.tradingParameters } diff --git a/TaskServer/LowFrequencyTrading/TradingEngine.js b/TaskServer/LowFrequencyTrading/TradingEngine.js index 5dcd894f5..042ae700d 100644 --- a/TaskServer/LowFrequencyTrading/TradingEngine.js +++ b/TaskServer/LowFrequencyTrading/TradingEngine.js @@ -24,12 +24,12 @@ exports.newTradingEngine = function (processIndex, bot, logger) { function initialize() { - tradingEngine = bot.simulationState.tradingEngine + tradingEngine = TS.projects.superalgos.globals.processVariables.VARIABLES_BY_PROCESS_INDEX_MAP.get(processIndex).SIMULATION_STATE.tradingEngine sessionParameters = TS.projects.superalgos.globals.processConstants.CONSTANTS_BY_PROCESS_INDEX_MAP.get(processIndex).SESSION_NODE.tradingParameters initializeNodeMap(tradingEngine) - if (TS.projects.superalgos.globals.processConstants.CONSTANTS_BY_PROCESS_INDEX_MAP.get(processIndex).IS_SESSION_FIRST_LOOP === true) { + if (TS.projects.superalgos.globals.processVariables.VARIABLES_BY_PROCESS_INDEX_MAP.get(processIndex).IS_SESSION_FIRST_LOOP === true) { /* Here we will go through all the nodes in the Trading Engine hiriarchy and apply the initial value to the value property when needed diff --git a/TaskServer/LowFrequencyTrading/TradingEpisode.js b/TaskServer/LowFrequencyTrading/TradingEpisode.js index 2a1f71950..15c45f217 100644 --- a/TaskServer/LowFrequencyTrading/TradingEpisode.js +++ b/TaskServer/LowFrequencyTrading/TradingEpisode.js @@ -21,8 +21,8 @@ exports.newTradingEpisode = function (processIndex, bot, logger, tradingEngineMo return thisObject function initialize() { - tradingSystem = bot.simulationState.tradingSystem - tradingEngine = bot.simulationState.tradingEngine + tradingSystem = TS.projects.superalgos.globals.processVariables.VARIABLES_BY_PROCESS_INDEX_MAP.get(processIndex).SIMULATION_STATE.tradingSystem + tradingEngine = TS.projects.superalgos.globals.processVariables.VARIABLES_BY_PROCESS_INDEX_MAP.get(processIndex).SIMULATION_STATE.tradingEngine sessionParameters = TS.projects.superalgos.globals.processConstants.CONSTANTS_BY_PROCESS_INDEX_MAP.get(processIndex).SESSION_NODE.tradingParameters } diff --git a/TaskServer/LowFrequencyTrading/TradingExecution.js b/TaskServer/LowFrequencyTrading/TradingExecution.js index dd596bbb8..9f3e9cc38 100644 --- a/TaskServer/LowFrequencyTrading/TradingExecution.js +++ b/TaskServer/LowFrequencyTrading/TradingExecution.js @@ -22,8 +22,8 @@ exports.newTradingExecution = function (processIndex, bot, logger, tradingEngine return thisObject function initialize() { - tradingSystem = bot.simulationState.tradingSystem - tradingEngine = bot.simulationState.tradingEngine + tradingSystem = TS.projects.superalgos.globals.processVariables.VARIABLES_BY_PROCESS_INDEX_MAP.get(processIndex).SIMULATION_STATE.tradingSystem + tradingEngine = TS.projects.superalgos.globals.processVariables.VARIABLES_BY_PROCESS_INDEX_MAP.get(processIndex).SIMULATION_STATE.tradingEngine sessionParameters = TS.projects.superalgos.globals.processConstants.CONSTANTS_BY_PROCESS_INDEX_MAP.get(processIndex).SESSION_NODE.tradingParameters tradingOrdersModule.initialize() diff --git a/TaskServer/LowFrequencyTrading/TradingOrders.js b/TaskServer/LowFrequencyTrading/TradingOrders.js index db2547596..e6c72e534 100644 --- a/TaskServer/LowFrequencyTrading/TradingOrders.js +++ b/TaskServer/LowFrequencyTrading/TradingOrders.js @@ -25,8 +25,8 @@ exports.newTradingOrders = function (processIndex, bot, logger, tradingEngineMod return thisObject function initialize() { - tradingSystem = bot.simulationState.tradingSystem - tradingEngine = bot.simulationState.tradingEngine + tradingSystem = TS.projects.superalgos.globals.processVariables.VARIABLES_BY_PROCESS_INDEX_MAP.get(processIndex).SIMULATION_STATE.tradingSystem + tradingEngine = TS.projects.superalgos.globals.processVariables.VARIABLES_BY_PROCESS_INDEX_MAP.get(processIndex).SIMULATION_STATE.tradingEngine sessionParameters = TS.projects.superalgos.globals.processConstants.CONSTANTS_BY_PROCESS_INDEX_MAP.get(processIndex).SESSION_NODE.tradingParameters exchangeAPIModule.initialize() diff --git a/TaskServer/LowFrequencyTrading/TradingOutput.js b/TaskServer/LowFrequencyTrading/TradingOutput.js index 20b80b6e4..565baf080 100644 --- a/TaskServer/LowFrequencyTrading/TradingOutput.js +++ b/TaskServer/LowFrequencyTrading/TradingOutput.js @@ -50,10 +50,10 @@ exports.newTradingOutput = function (processIndex, bot, logger, tradingEngineMod we are at the head of the market, because at the head of the market we need to append more data to the same output files that already exists. */ - if (TS.projects.superalgos.globals.processConstants.CONSTANTS_BY_PROCESS_INDEX_MAP.get(processIndex).IS_SESSION_FIRST_LOOP === true && TS.projects.superalgos.globals.processConstants.CONSTANTS_BY_PROCESS_INDEX_MAP.get(processIndex).IS_SESSION_RESUMING === false) { + if (TS.projects.superalgos.globals.processVariables.VARIABLES_BY_PROCESS_INDEX_MAP.get(processIndex).IS_SESSION_FIRST_LOOP === true && TS.projects.superalgos.globals.processVariables.VARIABLES_BY_PROCESS_INDEX_MAP.get(processIndex).IS_SESSION_RESUMING === false) { await initializeOutputs() } else { - if (bot.simulationState.tradingEngine.current.episode.headOfTheMarket.value === true) { + if (TS.projects.superalgos.globals.processVariables.VARIABLES_BY_PROCESS_INDEX_MAP.get(processIndex).SIMULATION_STATE.tradingEngine.current.episode.headOfTheMarket.value === true) { await readFiles() } else { await initializeOutputs() @@ -66,7 +66,7 @@ exports.newTradingOutput = function (processIndex, bot, logger, tradingEngineMod head of the market. Remember that backtests finishes the session once the reach the final datetime. */ - if (TS.projects.superalgos.globals.processConstants.CONSTANTS_BY_PROCESS_INDEX_MAP.get(processIndex).IS_SESSION_FIRST_LOOP === true && TS.projects.superalgos.globals.processConstants.CONSTANTS_BY_PROCESS_INDEX_MAP.get(processIndex).IS_SESSION_RESUMING === false) { + if (TS.projects.superalgos.globals.processVariables.VARIABLES_BY_PROCESS_INDEX_MAP.get(processIndex).IS_SESSION_FIRST_LOOP === true && TS.projects.superalgos.globals.processVariables.VARIABLES_BY_PROCESS_INDEX_MAP.get(processIndex).IS_SESSION_RESUMING === false) { await initializeOutputs() } else { await readFiles() diff --git a/TaskServer/LowFrequencyTrading/TradingPosition.js b/TaskServer/LowFrequencyTrading/TradingPosition.js index 1be7c9f6e..b04765f22 100644 --- a/TaskServer/LowFrequencyTrading/TradingPosition.js +++ b/TaskServer/LowFrequencyTrading/TradingPosition.js @@ -29,8 +29,8 @@ exports.newTradingPosition = function (processIndex, bot, logger, tradingEngineM return thisObject function initialize() { - tradingSystem = bot.simulationState.tradingSystem - tradingEngine = bot.simulationState.tradingEngine + tradingSystem = TS.projects.superalgos.globals.processVariables.VARIABLES_BY_PROCESS_INDEX_MAP.get(processIndex).SIMULATION_STATE.tradingSystem + tradingEngine = TS.projects.superalgos.globals.processVariables.VARIABLES_BY_PROCESS_INDEX_MAP.get(processIndex).SIMULATION_STATE.tradingEngine sessionParameters = TS.projects.superalgos.globals.processConstants.CONSTANTS_BY_PROCESS_INDEX_MAP.get(processIndex).SESSION_NODE.tradingParameters } diff --git a/TaskServer/LowFrequencyTrading/TradingProcess.js b/TaskServer/LowFrequencyTrading/TradingProcess.js index 57efc430c..a7d6bf7bf 100644 --- a/TaskServer/LowFrequencyTrading/TradingProcess.js +++ b/TaskServer/LowFrequencyTrading/TradingProcess.js @@ -83,19 +83,19 @@ if (getContextVariables() !== true) { return } - if (TS.projects.superalgos.globals.processConstants.CONSTANTS_BY_PROCESS_INDEX_MAP.get(processIndex).IS_SESSION_FIRST_LOOP === true && TS.projects.superalgos.globals.processConstants.CONSTANTS_BY_PROCESS_INDEX_MAP.get(processIndex).IS_SESSION_RESUMING === false) { + if (TS.projects.superalgos.globals.processVariables.VARIABLES_BY_PROCESS_INDEX_MAP.get(processIndex).IS_SESSION_FIRST_LOOP === true && TS.projects.superalgos.globals.processVariables.VARIABLES_BY_PROCESS_INDEX_MAP.get(processIndex).IS_SESSION_RESUMING === false) { /* Here is where the Trading Engine and Trading Systems received are moved to the simulation state. */ - 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 + TS.projects.superalgos.globals.processVariables.VARIABLES_BY_PROCESS_INDEX_MAP.get(processIndex).SIMULATION_STATE.tradingEngine = TS.projects.superalgos.globals.processConstants.CONSTANTS_BY_PROCESS_INDEX_MAP.get(processIndex).TRADING_ENGINE_NODE + TS.projects.superalgos.globals.processVariables.VARIABLES_BY_PROCESS_INDEX_MAP.get(processIndex).SIMULATION_STATE.tradingSystem = TS.projects.superalgos.globals.processConstants.CONSTANTS_BY_PROCESS_INDEX_MAP.get(processIndex).TRADING_SYSTEM_NODE } /* We set up the Trading Engine Module. */ tradingEngineModule.initialize() /* Initializing the Trading Process Date */ - if (TS.projects.superalgos.globals.processConstants.CONSTANTS_BY_PROCESS_INDEX_MAP.get(processIndex).IS_SESSION_FIRST_LOOP === true && TS.projects.superalgos.globals.processConstants.CONSTANTS_BY_PROCESS_INDEX_MAP.get(processIndex).IS_SESSION_RESUMING === false) { + if (TS.projects.superalgos.globals.processVariables.VARIABLES_BY_PROCESS_INDEX_MAP.get(processIndex).IS_SESSION_FIRST_LOOP === true && TS.projects.superalgos.globals.processVariables.VARIABLES_BY_PROCESS_INDEX_MAP.get(processIndex).IS_SESSION_RESUMING === false) { /* This funcion is going to be called many times by the Trading Bot Loop. Only during the first execution and when the User is not resuming the execution @@ -103,7 +103,7 @@ This variable tell us which day we are standing at, specially while working with Daily Files. From this Date is that we are going to load the Daily Files. */ - bot.simulationState.tradingEngine.current.episode.processDate.value = TS.projects.superalgos.utilities.dateTimeFunctions.removeTime(TS.projects.superalgos.globals.processConstants.CONSTANTS_BY_PROCESS_INDEX_MAP.get(processIndex).SESSION_NODE.tradingParameters.timeRange.config.initialDatetime).valueOf() + TS.projects.superalgos.globals.processVariables.VARIABLES_BY_PROCESS_INDEX_MAP.get(processIndex).SIMULATION_STATE.tradingEngine.current.episode.processDate.value = TS.projects.superalgos.utilities.dateTimeFunctions.removeTime(TS.projects.superalgos.globals.processConstants.CONSTANTS_BY_PROCESS_INDEX_MAP.get(processIndex).SESSION_NODE.tradingParameters.timeRange.config.initialDatetime).valueOf() } /* @@ -115,7 +115,7 @@ the simulation loop, once we discover that all candles from a certain date have benn processed. Here is the point where we sync one and the other. */ - let tradingProcessDate = TS.projects.superalgos.utilities.dateTimeFunctions.removeTime(bot.simulationState.tradingEngine.current.episode.processDate.value) + let tradingProcessDate = TS.projects.superalgos.utilities.dateTimeFunctions.removeTime(TS.projects.superalgos.globals.processVariables.VARIABLES_BY_PROCESS_INDEX_MAP.get(processIndex).SIMULATION_STATE.tradingEngine.current.episode.processDate.value) await processSingleFiles() if (await processMarketFiles() === false) { @@ -166,7 +166,7 @@ use it to save Output Files and later the Data Ranges. This is the point where the date calculated by the Simulation is applied at the Trading Process Level. */ - tradingProcessDate = TS.projects.superalgos.utilities.dateTimeFunctions.removeTime(bot.simulationState.tradingEngine.current.episode.processDate.value) + tradingProcessDate = TS.projects.superalgos.utilities.dateTimeFunctions.removeTime(TS.projects.superalgos.globals.processVariables.VARIABLES_BY_PROCESS_INDEX_MAP.get(processIndex).SIMULATION_STATE.tradingEngine.current.episode.processDate.value) if (checkStopTaskGracefully() === false) { break } if (checkStopProcessing() === false) { break } @@ -286,11 +286,11 @@ } thisReport = statusReport.file; - bot.simulationState = thisReport.simulationState; - if (bot.simulationState === undefined) { bot.simulationState = {} } // This should happen only when there is no status report + TS.projects.superalgos.globals.processVariables.VARIABLES_BY_PROCESS_INDEX_MAP.get(processIndex).SIMULATION_STATE = thisReport.simulationState; + if (TS.projects.superalgos.globals.processVariables.VARIABLES_BY_PROCESS_INDEX_MAP.get(processIndex).SIMULATION_STATE === undefined) { TS.projects.superalgos.globals.processVariables.VARIABLES_BY_PROCESS_INDEX_MAP.get(processIndex).SIMULATION_STATE = {} } // This should happen only when there is no status report if (thisReport.lastFile !== undefined) { - if (TS.projects.superalgos.globals.processConstants.CONSTANTS_BY_PROCESS_INDEX_MAP.get(processIndex).IS_SESSION_RESUMING !== true) { + if (TS.projects.superalgos.globals.processVariables.VARIABLES_BY_PROCESS_INDEX_MAP.get(processIndex).IS_SESSION_RESUMING !== true) { if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> getContextVariables -> Starting from the begining because bot has just started and resume execution was true."); } startFromBegining(); return true @@ -529,7 +529,7 @@ indicators to be built and continue the processing once this process is called again. */ - if (bot.simulationState.tradingEngine.current.episode.headOfTheMarket.value === true) { + if (TS.projects.superalgos.globals.processVariables.VARIABLES_BY_PROCESS_INDEX_MAP.get(processIndex).SIMULATION_STATE.tradingEngine.current.episode.headOfTheMarket.value === true) { return false } } @@ -619,8 +619,8 @@ From here on, all other loops executions wont be the first execution and also we will consider that it is not resuming a previous execution as well. */ - TS.projects.superalgos.globals.processConstants.CONSTANTS_BY_PROCESS_INDEX_MAP.get(processIndex).IS_SESSION_FIRST_LOOP = false - TS.projects.superalgos.globals.processConstants.CONSTANTS_BY_PROCESS_INDEX_MAP.get(processIndex).IS_SESSION_RESUMING = false + TS.projects.superalgos.globals.processVariables.VARIABLES_BY_PROCESS_INDEX_MAP.get(processIndex).IS_SESSION_FIRST_LOOP = false + TS.projects.superalgos.globals.processVariables.VARIABLES_BY_PROCESS_INDEX_MAP.get(processIndex).IS_SESSION_RESUMING = false } async function writeProcessFiles() { @@ -708,7 +708,7 @@ thisReport.file.lastExecution = bot.currentDaytime thisReport.file.lastFile = tradingProcessDate - thisReport.file.simulationState = bot.simulationState + thisReport.file.simulationState = TS.projects.superalgos.globals.processVariables.VARIABLES_BY_PROCESS_INDEX_MAP.get(processIndex).SIMULATION_STATE thisReport.file.timeFrames = currentTimeFrameLabel await thisReport.asyncSave() } @@ -718,7 +718,7 @@ let thisReport = statusDependencies.statusReports.get(reportKey); thisReport.file.lastExecution = bot.processDatetime - thisReport.file.simulationState = bot.simulationState + thisReport.file.simulationState = TS.projects.superalgos.globals.processVariables.VARIABLES_BY_PROCESS_INDEX_MAP.get(processIndex).SIMULATION_STATE thisReport.file.timeFrames = currentTimeFrameLabel logger.newInternalLoop(tradingProcessDate) diff --git a/TaskServer/LowFrequencyTrading/TradingRecords.js b/TaskServer/LowFrequencyTrading/TradingRecords.js index 096801ad2..6f6f5188b 100644 --- a/TaskServer/LowFrequencyTrading/TradingRecords.js +++ b/TaskServer/LowFrequencyTrading/TradingRecords.js @@ -18,8 +18,8 @@ exports.newTradingRecords = function (processIndex, bot, logger) { return thisObject function initialize(pOutputDatasetsMap) { - tradingEngine = bot.simulationState.tradingEngine - tradingSystem = bot.simulationState.tradingSystem + tradingEngine = TS.projects.superalgos.globals.processVariables.VARIABLES_BY_PROCESS_INDEX_MAP.get(processIndex).SIMULATION_STATE.tradingEngine + tradingSystem = TS.projects.superalgos.globals.processVariables.VARIABLES_BY_PROCESS_INDEX_MAP.get(processIndex).SIMULATION_STATE.tradingSystem sessionParameters = TS.projects.superalgos.globals.processConstants.CONSTANTS_BY_PROCESS_INDEX_MAP.get(processIndex).SESSION_NODE.tradingParameters outputDatasetsMap = pOutputDatasetsMap // These are the files turned into arrays, stored in a Map by Product codeName. } diff --git a/TaskServer/LowFrequencyTrading/TradingSimulation.js b/TaskServer/LowFrequencyTrading/TradingSimulation.js index 71f28e1ef..93cc0fdea 100644 --- a/TaskServer/LowFrequencyTrading/TradingSimulation.js +++ b/TaskServer/LowFrequencyTrading/TradingSimulation.js @@ -26,8 +26,8 @@ exports.newTradingSimulation = function (processIndex, bot, logger, tradingEngin ) { try { - let tradingSystem = bot.simulationState.tradingSystem - let tradingEngine = bot.simulationState.tradingEngine + let tradingSystem = TS.projects.superalgos.globals.processVariables.VARIABLES_BY_PROCESS_INDEX_MAP.get(processIndex).SIMULATION_STATE.tradingSystem + let tradingEngine = TS.projects.superalgos.globals.processVariables.VARIABLES_BY_PROCESS_INDEX_MAP.get(processIndex).SIMULATION_STATE.tradingEngine let sessionParameters = TS.projects.superalgos.globals.processConstants.CONSTANTS_BY_PROCESS_INDEX_MAP.get(processIndex).SESSION_NODE.tradingParameters if (FULL_LOG === true) { logger.write(MODULE_NAME, '[INFO] runSimulation -> initialDatetime = ' + sessionParameters.timeRange.config.initialDatetime) } @@ -57,7 +57,7 @@ exports.newTradingSimulation = function (processIndex, bot, logger, tradingEngin Estimation of the Initial Candle to Process in this Run. */ let initialCandle - if (TS.projects.superalgos.globals.processConstants.CONSTANTS_BY_PROCESS_INDEX_MAP.get(processIndex).IS_SESSION_FIRST_LOOP === true && TS.projects.superalgos.globals.processConstants.CONSTANTS_BY_PROCESS_INDEX_MAP.get(processIndex).IS_SESSION_RESUMING === false) { + if (TS.projects.superalgos.globals.processVariables.VARIABLES_BY_PROCESS_INDEX_MAP.get(processIndex).IS_SESSION_FIRST_LOOP === true && TS.projects.superalgos.globals.processVariables.VARIABLES_BY_PROCESS_INDEX_MAP.get(processIndex).IS_SESSION_RESUMING === false) { /* Estimate Initial Candle based on the timeRage configured for the session. */ let firstEnd = candles[0].end let targetEnd = sessionParameters.timeRange.config.initialDatetime diff --git a/TaskServer/LowFrequencyTrading/TradingStages.js b/TaskServer/LowFrequencyTrading/TradingStages.js index 59b1a056a..c4e094d74 100644 --- a/TaskServer/LowFrequencyTrading/TradingStages.js +++ b/TaskServer/LowFrequencyTrading/TradingStages.js @@ -45,8 +45,8 @@ exports.newTradingStages = function (processIndex, bot, logger, tradingEngineMod return thisObject function initialize() { - tradingSystem = bot.simulationState.tradingSystem - tradingEngine = bot.simulationState.tradingEngine + tradingSystem = TS.projects.superalgos.globals.processVariables.VARIABLES_BY_PROCESS_INDEX_MAP.get(processIndex).SIMULATION_STATE.tradingSystem + tradingEngine = TS.projects.superalgos.globals.processVariables.VARIABLES_BY_PROCESS_INDEX_MAP.get(processIndex).SIMULATION_STATE.tradingEngine sessionParameters = TS.projects.superalgos.globals.processConstants.CONSTANTS_BY_PROCESS_INDEX_MAP.get(processIndex).SESSION_NODE.tradingParameters tradingStrategyModule.initialize() diff --git a/TaskServer/LowFrequencyTrading/TradingStrategy.js b/TaskServer/LowFrequencyTrading/TradingStrategy.js index aacabbc09..471391ecd 100644 --- a/TaskServer/LowFrequencyTrading/TradingStrategy.js +++ b/TaskServer/LowFrequencyTrading/TradingStrategy.js @@ -18,7 +18,7 @@ exports.newTradingStrategy = function (processIndex, bot, logger, tradingEngineM return thisObject function initialize() { - tradingEngine = bot.simulationState.tradingEngine + tradingEngine = TS.projects.superalgos.globals.processVariables.VARIABLES_BY_PROCESS_INDEX_MAP.get(processIndex).SIMULATION_STATE.tradingEngine sessionParameters = TS.projects.superalgos.globals.processConstants.CONSTANTS_BY_PROCESS_INDEX_MAP.get(processIndex).SESSION_NODE.tradingParameters } diff --git a/TaskServer/LowFrequencyTrading/TradingSystem.js b/TaskServer/LowFrequencyTrading/TradingSystem.js index 647a3a098..08ba5112a 100644 --- a/TaskServer/LowFrequencyTrading/TradingSystem.js +++ b/TaskServer/LowFrequencyTrading/TradingSystem.js @@ -26,8 +26,8 @@ exports.newTradingSystem = function (processIndex, bot, logger, tradingEngineMod return thisObject function initialize() { - tradingSystem = bot.simulationState.tradingSystem - tradingEngine = bot.simulationState.tradingEngine + tradingSystem = TS.projects.superalgos.globals.processVariables.VARIABLES_BY_PROCESS_INDEX_MAP.get(processIndex).SIMULATION_STATE.tradingSystem + tradingEngine = TS.projects.superalgos.globals.processVariables.VARIABLES_BY_PROCESS_INDEX_MAP.get(processIndex).SIMULATION_STATE.tradingEngine sessionParameters = TS.projects.superalgos.globals.processConstants.CONSTANTS_BY_PROCESS_INDEX_MAP.get(processIndex).SESSION_NODE.tradingParameters tradingSystem.conditions = new Map() diff --git a/TaskServer/ReinforcementLearning/LearningProcess.js b/TaskServer/ReinforcementLearning/LearningProcess.js index 8acb8f5ab..d0b58de26 100644 --- a/TaskServer/ReinforcementLearning/LearningProcess.js +++ b/TaskServer/ReinforcementLearning/LearningProcess.js @@ -83,19 +83,19 @@ exports.newLearningProcess = function (processIndex, bot, logger, UTILITIES) { getContextVariables() - if (TS.projects.superalgos.globals.processConstants.CONSTANTS_BY_PROCESS_INDEX_MAP.get(processIndex).IS_SESSION_FIRST_LOOP === true && TS.projects.superalgos.globals.processConstants.CONSTANTS_BY_PROCESS_INDEX_MAP.get(processIndex).IS_SESSION_RESUMING === false) { + if (TS.projects.superalgos.globals.processVariables.VARIABLES_BY_PROCESS_INDEX_MAP.get(processIndex).IS_SESSION_FIRST_LOOP === true && TS.projects.superalgos.globals.processVariables.VARIABLES_BY_PROCESS_INDEX_MAP.get(processIndex).IS_SESSION_RESUMING === false) { /* Here is where the Trading Engine and Trading Systems received are moved to the simulation state. */ - 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 + TS.projects.superalgos.globals.processVariables.VARIABLES_BY_PROCESS_INDEX_MAP.get(processIndex).SIMULATION_STATE.tradingEngine = TS.projects.superalgos.globals.processConstants.CONSTANTS_BY_PROCESS_INDEX_MAP.get(processIndex).TRADING_ENGINE_NODE + TS.projects.superalgos.globals.processVariables.VARIABLES_BY_PROCESS_INDEX_MAP.get(processIndex).SIMULATION_STATE.tradingSystem = TS.projects.superalgos.globals.processConstants.CONSTANTS_BY_PROCESS_INDEX_MAP.get(processIndex).TRADING_SYSTEM_NODE } /* We set up the Trading Engine Module. */ markovDecisionProcessModule.initialize() /* Initializing the Trading Process Date */ - if (TS.projects.superalgos.globals.processConstants.CONSTANTS_BY_PROCESS_INDEX_MAP.get(processIndex).IS_SESSION_FIRST_LOOP === true && TS.projects.superalgos.globals.processConstants.CONSTANTS_BY_PROCESS_INDEX_MAP.get(processIndex).IS_SESSION_RESUMING === false) { + if (TS.projects.superalgos.globals.processVariables.VARIABLES_BY_PROCESS_INDEX_MAP.get(processIndex).IS_SESSION_FIRST_LOOP === true && TS.projects.superalgos.globals.processVariables.VARIABLES_BY_PROCESS_INDEX_MAP.get(processIndex).IS_SESSION_RESUMING === false) { /* This funcion is going to be called many times by the Trading Bot Loop. Only during the first execution and when the User is not resuming the execution @@ -103,7 +103,7 @@ exports.newLearningProcess = function (processIndex, bot, logger, UTILITIES) { This variable tell us which day we are standing at, specially while working with Daily Files. From this Date is that we are going to load the Daily Files. */ - bot.simulationState.tradingEngine.current.episode.processDate.value = TS.projects.superalgos.utilities.dateTimeFunctions.removeTime(TS.projects.superalgos.globals.processConstants.CONSTANTS_BY_PROCESS_INDEX_MAP.get(processIndex).SESSION_NODE.tradingParameters.timeRange.config.initialDatetime).valueOf() + TS.projects.superalgos.globals.processVariables.VARIABLES_BY_PROCESS_INDEX_MAP.get(processIndex).SIMULATION_STATE.tradingEngine.current.episode.processDate.value = TS.projects.superalgos.utilities.dateTimeFunctions.removeTime(TS.projects.superalgos.globals.processConstants.CONSTANTS_BY_PROCESS_INDEX_MAP.get(processIndex).SESSION_NODE.tradingParameters.timeRange.config.initialDatetime).valueOf() } /* @@ -115,7 +115,7 @@ exports.newLearningProcess = function (processIndex, bot, logger, UTILITIES) { the simulation loop, once we discover that all candles from a certain date have benn processed. Here is the point where we sync one and the other. */ - let LearningProcessDate = TS.projects.superalgos.utilities.dateTimeFunctions.removeTime(bot.simulationState.tradingEngine.current.episode.processDate.value) + let LearningProcessDate = TS.projects.superalgos.utilities.dateTimeFunctions.removeTime(TS.projects.superalgos.globals.processVariables.VARIABLES_BY_PROCESS_INDEX_MAP.get(processIndex).SIMULATION_STATE.tradingEngine.current.episode.processDate.value) await processSingleFiles() if (await processMarketFiles() === false) { @@ -166,7 +166,7 @@ exports.newLearningProcess = function (processIndex, bot, logger, UTILITIES) { use it to save Output Files and later the Data Ranges. This is the point where the date calculated by the Simulation is applied at the Trading Process Level. */ - LearningProcessDate = TS.projects.superalgos.utilities.dateTimeFunctions.removeTime(bot.simulationState.tradingEngine.current.episode.processDate.value) + LearningProcessDate = TS.projects.superalgos.utilities.dateTimeFunctions.removeTime(TS.projects.superalgos.globals.processVariables.VARIABLES_BY_PROCESS_INDEX_MAP.get(processIndex).SIMULATION_STATE.tradingEngine.current.episode.processDate.value) if (checkStopTaskGracefully() === false) { break } if (checkStopProcessing() === false) { break } @@ -286,11 +286,11 @@ exports.newLearningProcess = function (processIndex, bot, logger, UTILITIES) { } thisReport = statusReport.file; - bot.simulationState = thisReport.simulationState; - if (bot.simulationState === undefined) { bot.simulationState = {} } // This should happen only when there is no status report + TS.projects.superalgos.globals.processVariables.VARIABLES_BY_PROCESS_INDEX_MAP.get(processIndex).SIMULATION_STATE = thisReport.simulationState; + if (TS.projects.superalgos.globals.processVariables.VARIABLES_BY_PROCESS_INDEX_MAP.get(processIndex).SIMULATION_STATE === undefined) { TS.projects.superalgos.globals.processVariables.VARIABLES_BY_PROCESS_INDEX_MAP.get(processIndex).SIMULATION_STATE = {} } // This should happen only when there is no status report if (thisReport.lastFile !== undefined) { - if (TS.projects.superalgos.globals.processConstants.CONSTANTS_BY_PROCESS_INDEX_MAP.get(processIndex).IS_SESSION_RESUMING !== true) { + if (TS.projects.superalgos.globals.processVariables.VARIABLES_BY_PROCESS_INDEX_MAP.get(processIndex).IS_SESSION_RESUMING !== true) { if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> getContextVariables -> Starting from the begining because bot has just started and resume execution was true."); } startFromBegining(); return @@ -529,7 +529,7 @@ exports.newLearningProcess = function (processIndex, bot, logger, UTILITIES) { indicators to be built and continue the processing once this process is called again. */ - if (bot.simulationState.tradingEngine.current.episode.headOfTheMarket.value === true) { + if (TS.projects.superalgos.globals.processVariables.VARIABLES_BY_PROCESS_INDEX_MAP.get(processIndex).SIMULATION_STATE.tradingEngine.current.episode.headOfTheMarket.value === true) { return false } } @@ -619,8 +619,8 @@ exports.newLearningProcess = function (processIndex, bot, logger, UTILITIES) { From here on, all other loops executions wont be the first execution and also we will consider that it is not resuming a previous execution as well. */ - TS.projects.superalgos.globals.processConstants.CONSTANTS_BY_PROCESS_INDEX_MAP.get(processIndex).IS_SESSION_FIRST_LOOP = false - TS.projects.superalgos.globals.processConstants.CONSTANTS_BY_PROCESS_INDEX_MAP.get(processIndex).IS_SESSION_RESUMING = false + TS.projects.superalgos.globals.processVariables.VARIABLES_BY_PROCESS_INDEX_MAP.get(processIndex).IS_SESSION_FIRST_LOOP = false + TS.projects.superalgos.globals.processVariables.VARIABLES_BY_PROCESS_INDEX_MAP.get(processIndex).IS_SESSION_RESUMING = false } async function writeProcessFiles() { @@ -708,7 +708,7 @@ exports.newLearningProcess = function (processIndex, bot, logger, UTILITIES) { thisReport.file.lastExecution = bot.currentDaytime thisReport.file.lastFile = LearningProcessDate - thisReport.file.simulationState = bot.simulationState + thisReport.file.simulationState = TS.projects.superalgos.globals.processVariables.VARIABLES_BY_PROCESS_INDEX_MAP.get(processIndex).SIMULATION_STATE thisReport.file.timeFrames = currentTimeFrameLabel await thisReport.asyncSave() } @@ -718,7 +718,7 @@ exports.newLearningProcess = function (processIndex, bot, logger, UTILITIES) { let thisReport = statusDependencies.statusReports.get(reportKey); thisReport.file.lastExecution = bot.processDatetime - thisReport.file.simulationState = bot.simulationState + thisReport.file.simulationState = TS.projects.superalgos.globals.processVariables.VARIABLES_BY_PROCESS_INDEX_MAP.get(processIndex).SIMULATION_STATE thisReport.file.timeFrames = currentTimeFrameLabel logger.newInternalLoop(LearningProcessDate) diff --git a/TaskServer/ReinforcementLearning/MarkovDecisionProcess.js b/TaskServer/ReinforcementLearning/MarkovDecisionProcess.js index 3366346c1..03b831ab0 100644 --- a/TaskServer/ReinforcementLearning/MarkovDecisionProcess.js +++ b/TaskServer/ReinforcementLearning/MarkovDecisionProcess.js @@ -24,12 +24,12 @@ exports.newMarkovDecisionProcess = function newMarkovDecisionProcess(bot, logger function initialize() { - tradingEngine = bot.simulationState.tradingEngine + tradingEngine = TS.projects.superalgos.globals.processVariables.VARIABLES_BY_PROCESS_INDEX_MAP.get(processIndex).SIMULATION_STATE.tradingEngine sessionParameters = bot.LEARNING_SESSION.learningParameters initializeNodeMap(tradingEngine) - if (TS.projects.superalgos.globals.processConstants.CONSTANTS_BY_PROCESS_INDEX_MAP.get(processIndex).IS_SESSION_FIRST_LOOP === true) { + if (TS.projects.superalgos.globals.processVariables.VARIABLES_BY_PROCESS_INDEX_MAP.get(processIndex).IS_SESSION_FIRST_LOOP === true) { /* Here we will go through all the nodes in the Trading Engine hiriarchy and apply the initial value to the value property when needed diff --git a/TaskServer/TradingSession.js b/TaskServer/TradingSession.js index 0d0c8ce1d..2b9133ff6 100644 --- a/TaskServer/TradingSession.js +++ b/TaskServer/TradingSession.js @@ -87,8 +87,8 @@ TS.projects.superalgos.globals.processConstants.CONSTANTS_BY_PROCESS_INDEX_MAP.get(processIndex).TRADING_ENGINE_NODE = JSON.parse(message.event.tradingEngine) TS.projects.superalgos.globals.processConstants.CONSTANTS_BY_PROCESS_INDEX_MAP.get(processIndex).SESSION_NODE = JSON.parse(message.event.session) TS.projects.superalgos.globals.processConstants.CONSTANTS_BY_PROCESS_INDEX_MAP.get(processIndex).DEPENDENCY_FILTER = JSON.parse(message.event.dependencyFilter) - TS.projects.superalgos.globals.processConstants.CONSTANTS_BY_PROCESS_INDEX_MAP.get(processIndex).IS_SESSION_RESUMING = false - TS.projects.superalgos.globals.processConstants.CONSTANTS_BY_PROCESS_INDEX_MAP.get(processIndex).IS_SESSION_FIRST_LOOP = true + TS.projects.superalgos.globals.processVariables.VARIABLES_BY_PROCESS_INDEX_MAP.get(processIndex).IS_SESSION_RESUMING = false + TS.projects.superalgos.globals.processVariables.VARIABLES_BY_PROCESS_INDEX_MAP.get(processIndex).IS_SESSION_FIRST_LOOP = true setUpSessionFolderName() @@ -147,7 +147,7 @@ return } - TS.projects.superalgos.globals.processConstants.CONSTANTS_BY_PROCESS_INDEX_MAP.get(processIndex).IS_SESSION_RESUMING = true + TS.projects.superalgos.globals.processVariables.VARIABLES_BY_PROCESS_INDEX_MAP.get(processIndex).IS_SESSION_RESUMING = true TS.projects.superalgos.globals.processVariables.VARIABLES_BY_PROCESS_INDEX_MAP.get(processIndex).IS_SESSION_STOPPING = false TS.projects.superalgos.globals.processVariables.VARIABLES_BY_PROCESS_INDEX_MAP.get(processIndex).SOCIAL_BOTS_MODULE.sendMessage(TS.projects.superalgos.globals.processConstants.CONSTANTS_BY_PROCESS_INDEX_MAP.get(processIndex).SESSION_NODE.type + " '" + TS.projects.superalgos.globals.taskConstants.TASK_NODE.bot.processes[processIndex].session.name + "' is resuming.")