From 6130b2473a15829e8d138b52d760cfda5285cfca Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Tue, 17 Sep 2019 16:04:04 +0200 Subject: [PATCH] Bug Fixes and Improvements to better respond to UI --- CloneExecutor.sln | 25 ------------------------- MultiPeriod.js | 32 ++++++++++++++++++++++++++------ TradingEngineProcessMainLoop.js | 5 +++++ 3 files changed, 31 insertions(+), 31 deletions(-) delete mode 100644 CloneExecutor.sln diff --git a/CloneExecutor.sln b/CloneExecutor.sln deleted file mode 100644 index a21837e88..000000000 --- a/CloneExecutor.sln +++ /dev/null @@ -1,25 +0,0 @@ - -Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio 15 -VisualStudioVersion = 15.0.27130.2027 -MinimumVisualStudioVersion = 10.0.40219.1 -Project("{9092AA53-FB77-4645-B42D-1CCCA6BD08BD}") = "Project", "Project.njsproj", "{AE0A3FE2-7021-4CC2-9922-A887CA5CDD7C}" -EndProject -Global - GlobalSection(SolutionConfigurationPlatforms) = preSolution - Debug|Any CPU = Debug|Any CPU - Release|Any CPU = Release|Any CPU - EndGlobalSection - GlobalSection(ProjectConfigurationPlatforms) = postSolution - {AE0A3FE2-7021-4CC2-9922-A887CA5CDD7C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {AE0A3FE2-7021-4CC2-9922-A887CA5CDD7C}.Debug|Any CPU.Build.0 = Debug|Any CPU - {AE0A3FE2-7021-4CC2-9922-A887CA5CDD7C}.Release|Any CPU.ActiveCfg = Release|Any CPU - {AE0A3FE2-7021-4CC2-9922-A887CA5CDD7C}.Release|Any CPU.Build.0 = Release|Any CPU - EndGlobalSection - GlobalSection(SolutionProperties) = preSolution - HideSolutionNode = FALSE - EndGlobalSection - GlobalSection(ExtensibilityGlobals) = postSolution - SolutionGuid = {9128DF06-8CA5-497C-8BF7-B924571C5394} - EndGlobalSection -EndGlobal diff --git a/MultiPeriod.js b/MultiPeriod.js index c1faa087f..58700cb52 100644 --- a/MultiPeriod.js +++ b/MultiPeriod.js @@ -115,6 +115,8 @@ /* We look first for the bot who knows the begining of the marke in order to get when the market starts. + IMPORTANT NOTE: When this module is used by Trading Engine Bots it nevers comes through this path since there is allways a ficed start date. + This code would be used by some indicator that is. */ let botWhoKnowsTheBeginingOfTheMarket = statusDependencies.config[processConfig.framework.startDate.takeItFromStatusDependency]; @@ -151,7 +153,7 @@ return; } - contextVariables.dateBeginOfMarket = new Date(thisReport.lastFile.year + "-" + thisReport.lastFile.month + "-" + thisReport.lastFile.days + " " + thisReport.lastFile.hours + ":" + thisReport.lastFile.minutes + GMT_SECONDS); + contextVariables.dateBeginOfMarket = new Date(thisReport.lastFile); } @@ -878,7 +880,8 @@ botNeverRan = false; if (currentTimePeriod > global.dailyFilePeriods[0][0]) { - writeMarketStatusReport(onMarketStatusReport); + writeMarketStatusReport(onMarketStatusReport) + } else { writeDataRanges(onWritten); } @@ -895,7 +898,7 @@ return; } - writeDailyStatusReport(bot.multiPeriodDailyProcessDatetime, advanceTime); + writeDailyStatusReport(bot.multiPeriodDailyProcessDatetime, onDailyStatusReport); } catch (err) { logger.write(MODULE_NAME, "[ERROR] start -> processTimePeriodsDailyFiles -> callTheBot -> onBotFinished -> onWritten -> err = " + err.stack); @@ -903,9 +906,29 @@ } } + + function onDailyStatusReport() { + try { + if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> processTimePeriodsDailyFiles -> callTheBot -> onBotFinished -> onDailyStatusReport -> Entering function."); } + + /* The next run we need the process to continue at the date it finished. */ + processConfig.framework.startDate.resumeExecution = true; + + advanceTime(); + } catch (err) { + logger.write(MODULE_NAME, "[ERROR] start -> processTimePeriodsDailyFiles -> callTheBot -> onBotFinished -> onDailyStatusReport -> err = " + err.stack); + callBackFunction(global.DEFAULT_FAIL_RESPONSE); + } + } + function onMarketStatusReport() { try { if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> processTimePeriodsDailyFiles -> callTheBot -> onBotFinished -> onMarketStatusReport -> Entering function."); } + + if (bot.startMode === "Backtest") { + global.STOP_PROCESSING = true + } + callBackFunction(global.DEFAULT_OK_RESPONSE); } catch (err) { logger.write(MODULE_NAME, "[ERROR] start -> processTimePeriodsDailyFiles -> callTheBot -> onBotFinished -> onMarketStatusReport -> err = " + err.stack); @@ -1023,9 +1046,6 @@ bot.hasTheBotJustStarted = false; - /* Emit event that signals that this process finished */ - global.SYSTEM_EVENT_HANDLER.raiseEvent('Jason-Multi-Period', 'Status Report Updated', { lastProcessedDay: lastFileDate }) - } catch (err) { logger.write(MODULE_NAME, "[ERROR] start -> writeDailyStatusReport -> err = " + err.stack); diff --git a/TradingEngineProcessMainLoop.js b/TradingEngineProcessMainLoop.js index 69fc465e5..e2748d820 100644 --- a/TradingEngineProcessMainLoop.js +++ b/TradingEngineProcessMainLoop.js @@ -183,6 +183,7 @@ let nextWaitTime; /* Loop Heartbeat sent to the UI */ + bot.hearBeat = hearBeat // allow the bot itself to produce a heartbeat hearBeat() /* We define here all the modules that the rest of the infraestructure, including the bots themselves can consume. */ @@ -209,6 +210,9 @@ if (global.STOP_PROCESSING === true) { if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] run -> loop -> We are going to skip this Loop bacause we were requested to stop or never asked to start."); } console.log("[INFO] run -> loop -> We are going to skip this Loop bacause we were requested to stop or never asked to start.") + + global.SYSTEM_EVENT_HANDLER.raiseEvent('Jason-Multi-Period', 'Process Stopped') + nextWaitTime = 'Normal'; loopControl(nextWaitTime); return @@ -1072,6 +1076,7 @@ } global.SYSTEM_EVENT_HANDLER.raiseEvent(key, 'Heartbeat', event) } + } catch (err) { parentLogger.write(MODULE_NAME, "[ERROR] run -> err = "+ err.stack); clearInterval(fixedTimeLoopIntervalHandle);