From dbfea9c7db1f27de8d0511a2a576ecf4669d588d Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Sat, 25 Jul 2020 20:04:59 +0200 Subject: [PATCH] Time Frames Filter --- MultiPeriodDaily.js | 44 +++++++++++++++++++++++++++++++-- MultiPeriodMarket.js | 58 +++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 99 insertions(+), 3 deletions(-) diff --git a/MultiPeriodDaily.js b/MultiPeriodDaily.js index 2d5e9741d..24d605d62 100644 --- a/MultiPeriodDaily.js +++ b/MultiPeriodDaily.js @@ -276,9 +276,19 @@ } function timeFramesLoopBody() { + const timeFrame = global.dailyFilePeriods[n][0] const timeFrameLabel = global.dailyFilePeriods[n][1] + /* Check Time Frames Filter */ + if (bot.dailyTimeFrames !== undefined) { + if (bot.dailyTimeFrames.includes(timeFrameLabel) === false) { + /* We are not going to process this Time Frame */ + timeFramesControlLoop() + return + } + } + if (processConfig.framework.validPeriods !== undefined) { let validPeriod = false; for (let i = 0; i < processConfig.framework.validPeriods.length; i++) { @@ -417,8 +427,6 @@ } function generateOutput() { - const timeFrame = global.dailyFilePeriods[n][0] - const timeFrameLabel = global.dailyFilePeriods[n][1] indicatorOutputModule.start( dataFiles, @@ -502,6 +510,38 @@ } global.EVENT_SERVER_CLIENT.raiseEvent(key, 'Data Range Updated', event) + writeTimeFramesFile(productCodeName, callBack) + } + } + + function writeTimeFramesFile(productCodeName, callBack) { + + let timeFramesArray = [] + for (let n = 0; n < global.dailyFilePeriods.length; n++) { + let timeFrameLabel = global.dailyFilePeriods[n][1] + + /* Check Time Frames Filter */ + if (bot.marketTimeFrames !== undefined) { + if (bot.dailyTimeFrames.includes(timeFrameLabel) === true) { + timeFramesArray.push(timeFrameLabel) + } + } else { + timeFramesArray.push(timeFrameLabel) + } + } + + let fileContent = JSON.stringify(timeFramesArray) + let fileName = '/Time.Frames.json'; + let filePath = bot.filePathRoot + "/Output/" + productCodeName + "/" + bot.process + fileName; + + fileStorage.createTextFile(filePath, fileContent + '\n', onFileCreated) + + function onFileCreated(err) { + if (err.result !== global.DEFAULT_OK_RESPONSE.result) { + logger.write(MODULE_NAME, "[ERROR] start -> writeTimeFramesFiles -> onFileCreated -> err = " + err.stack) + callBack(err) + return + } callBack(global.DEFAULT_OK_RESPONSE) } } diff --git a/MultiPeriodMarket.js b/MultiPeriodMarket.js index 3e29f55f7..02a35a702 100644 --- a/MultiPeriodMarket.js +++ b/MultiPeriodMarket.js @@ -7,6 +7,7 @@ }; let utilities = UTILITIES.newCloudUtilities(logger) + let fileStorage = FILE_STORAGE.newFileStorage(logger) let statusDependencies; let dataDependenciesModule; @@ -31,6 +32,7 @@ } function finalize() { + fileStorage = undefined dataFiles = undefined statusDependencies = undefined dataDependenciesModule = undefined @@ -130,11 +132,65 @@ if (n < global.marketFilesPeriods.length) { timeFramesLoopBody() } else { - writeStatusReport(callBackFunction) + writeTimeFramesFiles(onTimeFrameFilesWritten) + function onTimeFrameFilesWritten() { + writeStatusReport(callBackFunction) + } } } } + function writeTimeFramesFiles(callBack) { + let outputDatasetIndex = -1; + controlLoop() + + function productLoopBody() { + let productCodeName = bot.processNode.referenceParent.processOutput.outputDatasets[outputDatasetIndex].referenceParent.parentNode.config.codeName; + writeTimeFramesFile(productCodeName, controlLoop) + } + + function controlLoop() { + outputDatasetIndex++ + if (outputDatasetIndex < bot.processNode.referenceParent.processOutput.outputDatasets.length) { + productLoopBody() + } else { + callBack() + } + } + } + + function writeTimeFramesFile(productCodeName, callBack) { + + let timeFramesArray = [] + for (let n = 0; n < global.marketFilesPeriods.length; n++) { + let timeFrameLabel = global.marketFilesPeriods[n][1] + + /* Check Time Frames Filter */ + if (bot.marketTimeFrames !== undefined) { + if (bot.marketTimeFrames.includes(timeFrameLabel) === true) { + timeFramesArray.push(timeFrameLabel) + } + } else { + timeFramesArray.push(timeFrameLabel) + } + } + + let fileContent = JSON.stringify(timeFramesArray) + let fileName = '/Time.Frames.json'; + let filePath = bot.filePathRoot + "/Output/" + productCodeName + "/" + bot.process + fileName; + + fileStorage.createTextFile(filePath, fileContent + '\n', onFileCreated) + + function onFileCreated(err) { + if (err.result !== global.DEFAULT_OK_RESPONSE.result) { + logger.write(MODULE_NAME, "[ERROR] start -> writeTimeFramesFile -> onFileCreated -> err = " + err.stack) + callBack(err) + return + } + callBack() + } + } + function writeStatusReport(callBack) { let reportKey = bot.dataMine + "-" + bot.codeName + "-" + "Multi-Period-Market" let thisReport = statusDependencies.statusReports.get(reportKey)