diff --git a/LowFrequencyTrading/TradingProcess.js b/LowFrequencyTrading/TradingProcess.js index 5a37df7c6..0562fd592 100644 --- a/LowFrequencyTrading/TradingProcess.js +++ b/LowFrequencyTrading/TradingProcess.js @@ -116,7 +116,7 @@ Here is the point where we sync one and the other. */ let tradingProcessDate = global.REMOVE_TIME(bot.simulationState.tradingEngine.current.episode.processDate.value) - + console.log("1 tradingProcessDate ", tradingProcessDate) await processSingleFiles() await processMarketFiles() @@ -147,10 +147,6 @@ /* We are processing Daily Files */ do { global.EMIT_SESSION_STATUS (bot.SESSION_STATUS, bot.sessionKey) - - if (checkStopTaskGracefully() === false) { break } - if (checkStopProcessing() === false) { break } - /* We update the Trading Process Date with the date calculated at the simulation. We will use this date to load indicator and output files. After that we will @@ -158,6 +154,10 @@ the date calculated by the Simulation is applied at the Trading Process Level. */ tradingProcessDate = global.REMOVE_TIME(bot.simulationState.tradingEngine.current.episode.processDate.value) + console.log("2 tradingProcessDate ", tradingProcessDate) + if (checkStopTaskGracefully() === false) { break } + if (checkStopProcessing() === false) { break } + await processDailyFiles() /* With all the indicators data files loaded, we will build the chart object diff --git a/Session.js b/Session.js index 926fbcc09..6a06be524 100644 --- a/Session.js +++ b/Session.js @@ -41,6 +41,7 @@ global.EVENT_SERVER_CLIENT.listenToEvent(bot.sessionKey, 'Session Status', undefined, bot.sessionKey, undefined, onSessionStatus) global.EVENT_SERVER_CLIENT.listenToEvent(bot.sessionKey, 'Run Session', undefined, bot.sessionKey, undefined, onSessionRun) global.EVENT_SERVER_CLIENT.listenToEvent(bot.sessionKey, 'Stop Session', undefined, bot.sessionKey, undefined, onSessionStop) + global.EVENT_SERVER_CLIENT.listenToEvent(bot.sessionKey, 'Resume Session', undefined, bot.sessionKey, undefined, onSessionResume) /* Connect this here so that it is accesible from other places */ bot.sessionError = sessionError @@ -71,7 +72,7 @@ try { /* This happens when the UI is reloaded, the session was running and tries to run it again. */ if (bot.SESSION_STATUS === 'Idle' || bot.SESSION_STATUS === 'Running') { - parentLogger.write(MODULE_NAME, "[WARN] onSessionRun -> Event receive to run the Session while it was already running. ") + parentLogger.write(MODULE_NAME, "[WARN] onSessionRun -> Event received to run the Session while it was already running. ") return } @@ -80,7 +81,7 @@ bot.TRADING_ENGINE = JSON.parse(message.event.tradingEngine) bot.SESSION = JSON.parse(message.event.session) bot.DEPENDENCY_FILTER = JSON.parse(message.event.dependencyFilter) - bot.RESUME = message.event.resume + bot.RESUME = false bot.FIRST_EXECUTION = true bot.SESSION.stop = stopSession // stop function @@ -128,6 +129,28 @@ stopSession('Session Stopped From the User Interface.') } + function onSessionResume(message) { + try { + if (bot.SESSION.stop === undefined) { + parentLogger.write(MODULE_NAME, "[WARN] onSessionResume -> Event received to resume the Session that have never be ran before. ") + return + } + + /* This happens when the UI is reloaded, the session was running and tries to run it again. */ + if (bot.SESSION_STATUS === 'Idle' || bot.SESSION_STATUS === 'Running') { + parentLogger.write(MODULE_NAME, "[WARN] onSessionResume -> Event received to resume the Session while it was already running. ") + return + } + + bot.RESUME = true + bot.STOP_SESSION = false + + socialBotsModule.sendMessage(bot.SESSION.type + " '" + bot.SESSION.name + "' is resuming.") + } catch (err) { + parentLogger.write(MODULE_NAME, "[ERROR] initialize -> onSessionResume -> err = " + err.stack); + } + } + function stopSession(commandOrigin) { socialBotsModule.sendMessage(bot.SESSION.type + " '" + bot.SESSION.name + "' is stopping " + commandOrigin)