Session resume and first loop

This commit is contained in:
Luis Fernando Molina committed 2020-11-30 14:19:19 +01:00
1 parent 53973e5491
commit 583ef49f1d
9 files changed
+31 -29

No files matched your search

@@ -16,14 +16,16 @@ exports.newSuperalgosGlobalsProcessVariables = function () {
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.
SOCIAL_BOTS_MODULE This is the module that controls social bots.
IS_SESSION_STOPPING This tell us if a session is in the process of being stopped.
SESSION_STATUS This tell us the status of the session at any given time.
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.
SOCIAL_BOTS_MODULE This is the module that controls social bots.
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.
*/
return thisObject
}
+3 -3
View File
@@ -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)
bot.RESUME = false
bot.FIRST_EXECUTION = true
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
bot.LEARNING_SESSION.stop = stopSession // stop function
setUpSessionFolderName()
@@ -144,7 +144,7 @@ exports.newLearningSession = function (processIndex, bot, parentLogger) {
return
}
bot.RESUME = true
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_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.")
@@ -29,7 +29,7 @@ exports.newTradingEngine = function (processIndex, bot, logger) {
initializeNodeMap(tradingEngine)
if (bot.FIRST_EXECUTION === true) {
if (TS.projects.superalgos.globals.processConstants.CONSTANTS_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
@@ -50,7 +50,7 @@ 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 (bot.FIRST_EXECUTION === true && bot.RESUME === false) {
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) {
await initializeOutputs()
} else {
if (bot.simulationState.tradingEngine.current.episode.headOfTheMarket.value === true) {
@@ -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 (bot.FIRST_EXECUTION === true && bot.RESUME === false) {
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) {
await initializeOutputs()
} else {
await readFiles()
@@ -83,7 +83,7 @@
if (getContextVariables() !== true) { return }
if (bot.FIRST_EXECUTION === true && bot.RESUME === false) {
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) {
/*
Here is where the Trading Engine and Trading Systems received are moved to the simulation state.
*/
@@ -95,7 +95,7 @@
tradingEngineModule.initialize()
/* Initializing the Trading Process Date */
if (bot.FIRST_EXECUTION === true && bot.RESUME === false) {
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) {
/*
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
@@ -290,7 +290,7 @@
if (bot.simulationState === undefined) { bot.simulationState = {} } // This should happen only when there is no status report
if (thisReport.lastFile !== undefined) {
if (bot.RESUME !== true) {
if (TS.projects.superalgos.globals.processConstants.CONSTANTS_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
@@ -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.
*/
bot.FIRST_EXECUTION = false
bot.RESUME = false
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
}
async function writeProcessFiles() {
@@ -57,7 +57,7 @@ exports.newTradingSimulation = function (processIndex, bot, logger, tradingEngin
Estimation of the Initial Candle to Process in this Run.
*/
let initialCandle
if (bot.FIRST_EXECUTION === true && bot.RESUME === false) {
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) {
/* Estimate Initial Candle based on the timeRage configured for the session. */
let firstEnd = candles[0].end
let targetEnd = sessionParameters.timeRange.config.initialDatetime
@@ -83,7 +83,7 @@ exports.newLearningProcess = function (processIndex, bot, logger, UTILITIES) {
getContextVariables()
if (bot.FIRST_EXECUTION === true && bot.RESUME === false) {
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) {
/*
Here is where the Trading Engine and Trading Systems received are moved to the simulation state.
*/
@@ -95,7 +95,7 @@ exports.newLearningProcess = function (processIndex, bot, logger, UTILITIES) {
markovDecisionProcessModule.initialize()
/* Initializing the Trading Process Date */
if (bot.FIRST_EXECUTION === true && bot.RESUME === false) {
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) {
/*
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
@@ -290,7 +290,7 @@ exports.newLearningProcess = function (processIndex, bot, logger, UTILITIES) {
if (bot.simulationState === undefined) { bot.simulationState = {} } // This should happen only when there is no status report
if (thisReport.lastFile !== undefined) {
if (bot.RESUME !== true) {
if (TS.projects.superalgos.globals.processConstants.CONSTANTS_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
@@ -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.
*/
bot.FIRST_EXECUTION = false
bot.RESUME = false
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
}
async function writeProcessFiles() {
@@ -29,7 +29,7 @@ exports.newMarkovDecisionProcess = function newMarkovDecisionProcess(bot, logger
initializeNodeMap(tradingEngine)
if (bot.FIRST_EXECUTION === true) {
if (TS.projects.superalgos.globals.processConstants.CONSTANTS_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
+3 -3
View File
@@ -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)
bot.RESUME = false
bot.FIRST_EXECUTION = true
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
setUpSessionFolderName()
@@ -147,7 +147,7 @@
return
}
bot.RESUME = true
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_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.")