diff --git a/DataDependencies.js b/DataDependencies.js index f5ce0e3d2..a833ad6a3 100644 --- a/DataDependencies.js +++ b/DataDependencies.js @@ -9,9 +9,12 @@ let thisObject = { nodeArray: undefined, dataSetsModulesArray: [], + isItADepenency: isItADepenency, initialize: initialize }; + let filter = new Map() + return thisObject; function initialize(callBackFunction) { @@ -42,10 +45,17 @@ callBackFunction(global.DEFAULT_OK_RESPONSE); return; } + + /* Session based dependency filters */ + if (bot.DEPENDENCY_FILTER !== undefined) { + for (let i = 0; i < bot.DEPENDENCY_FILTER.length; i++) { + let key = bot.DEPENDENCY_FILTER[i] + filter.set(key, true) + } + } + /* - For each dependency declared at the nodeArray, we will initialize a DataSet as part of this initialization process. - */ let alreadyCalledBack = false; let addCount = 0; @@ -92,4 +102,10 @@ callBackFunction(global.DEFAULT_FAIL_RESPONSE); } } + + function isItADepenency(timeFrame, product) { + let key = timeFrame + '-' + product + + return filter.get(key) + } }; diff --git a/MultiPeriod.js b/MultiPeriod.js index ff2c5d19c..bc3d0b196 100644 --- a/MultiPeriod.js +++ b/MultiPeriod.js @@ -71,7 +71,7 @@ if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> Entering function."); } let currentTimeFrame - let currentOutputPeriodName + let currentTimeFrameLabel let market = bot.market; let botNeverRan = true; @@ -246,21 +246,21 @@ getFile(); function getFile() { - try { - if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> processSingleFiles -> dependencyLoopBody -> getFile -> Entering function."); } - let fileName = "Data.json"; - if (datasetModule.node.code.codeName !== "Single-File") { - dependencyControlLoop(); return } - let filePath = datasetModule.node.parentNode.code.codeName + '/' + datasetModule.node.code.codeName; + if (dataDependenciesModule.isItADepenency('atAnyTimeFrame', datasetModule.node.parentNode.code.singularVariableName) !== true) { + dependencyControlLoop(); + return + } + let fileName = "Data.json"; + let filePath = datasetModule.node.parentNode.code.codeName + '/' + datasetModule.node.code.codeName; datasetModule.getTextFile(filePath, fileName, onFileReceived); function onFileReceived(err, text) { @@ -356,9 +356,7 @@ if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> processMarketFiles -> timeFramesLoop -> Entering function."); } /* - We will iterate through all posible timeFrames. - */ n = 0 // loop Variable representing each possible period as defined at the timeFrames array. @@ -386,7 +384,7 @@ if (bot.VALUES_TO_USE.timeFrame === timeFrameLabel) { currentTimeFrame = global.marketFilesPeriods[n][0]; - currentOutputPeriodName = global.marketFilesPeriods[n][1]; + currentTimeFrameLabel = global.marketFilesPeriods[n][1]; } dependencyLoopBody(); @@ -402,21 +400,21 @@ getFile(); function getFile() { - try { - if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> processMarketFiles -> timeFramesLoopBody -> dependencyLoopBody -> getFile -> Entering function."); } - let fileName = "Data.json"; - if (dependency.referenceParent.code.codeName !== "Multi-Period-Market") { - dependencyControlLoop(); return } - let filePath = dependency.referenceParent.parentNode.code.codeName + '/' + dependency.referenceParent.code.codeName + "/" + timeFrameLabel; + if (dataDependenciesModule.isItADepenency(timeFrameLabel, datasetModule.node.parentNode.code.singularVariableName) !== true) { + dependencyControlLoop(); + return + } + let fileName = "Data.json"; + let filePath = dependency.referenceParent.parentNode.code.codeName + '/' + dependency.referenceParent.code.codeName + "/" + timeFrameLabel; datasetModule.getTextFile(filePath, fileName, onFileReceived); function onFileReceived(err, text) { @@ -685,7 +683,7 @@ if (bot.VALUES_TO_USE.timeFrame === timeFrameLabel) { currentTimeFrame = global.dailyFilePeriods[n][0]; - currentOutputPeriodName = global.dailyFilePeriods[n][1]; + currentTimeFrameLabel = global.dailyFilePeriods[n][1]; } let dependencyIndex = 0; @@ -712,13 +710,15 @@ } function getPreviousFile() { - try { - if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> processDailyFiles -> timeFramesLoopBody -> dependencyLoopBody -> getPreviousFile -> Entering function."); } - if (dependency.referenceParent.code.codeName === "Multi-Period-Market") { + if (dependency.referenceParent.code.codeName !== "Multi-Period-Daily") { + dependencyControlLoop(); + return + } + if (dataDependenciesModule.isItADepenency(timeFrameLabel, datasetModule.node.parentNode.code.singularVariableName) !== true) { dependencyControlLoop(); return } @@ -932,7 +932,7 @@ botInstance.start( multiPeriodDataFiles, currentTimeFrame, - currentOutputPeriodName, + currentTimeFrameLabel, bot.multiPeriodProcessDatetime, interExecutionMemoryArray[n], onBotFinished); @@ -954,7 +954,7 @@ writeMarketStatusReport(onMarketStatusReport) } else { - writeDataRanges(currentOutputPeriodName, onWritten); + writeDataRanges(currentTimeFrameLabel, onWritten); } function onWritten(err) { @@ -1035,7 +1035,7 @@ } } - function writeDataRanges(currentOutputPeriodName, callBack) { + function writeDataRanges(currentTimeFrameLabel, callBack) { try { @@ -1046,7 +1046,7 @@ function productLoopBody() { let productCodeName = bot.processNode.referenceParent.processOutput.outputDatasets[outputDatasetIndex].referenceParent.parentNode.code.codeName; - writeDataRange(contextVariables.dateBeginOfMarket, bot.multiPeriodProcessDatetime, productCodeName, currentOutputPeriodName, controlLoop); + writeDataRange(contextVariables.dateBeginOfMarket, bot.multiPeriodProcessDatetime, productCodeName, currentTimeFrameLabel, controlLoop); } function controlLoop() { @@ -1067,7 +1067,7 @@ } - function writeDataRange(pBegin, pEnd, productCodeName, currentOutputPeriodName, callBack) { + function writeDataRange(pBegin, pEnd, productCodeName, currentTimeFrameLabel, callBack) { try { diff --git a/Session.js b/Session.js index 8de5c2c7a..68a12b7f2 100644 --- a/Session.js +++ b/Session.js @@ -54,6 +54,7 @@ /* We are going to run the Definition comming at the event. */ bot.TRADING_SYSTEM = JSON.parse(message.event.tradingSystem) bot.SESSION = JSON.parse(message.event.session) + bot.DEPENDENCY_FILTER = JSON.parse(message.event.dependencyFilter) /* Set the folderName for logging, reports, context and data output */ let code