From ac4f0309f87ce1dc3c6923ed0031be820c47546a Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Mon, 13 Apr 2020 17:44:31 +0200 Subject: [PATCH] Configuration Simplification --- MultiPeriodDaily.js | 154 ++++++++++++++++++++----------------------- MultiPeriodMarket.js | 16 ----- Root.js | 50 ++++++++++---- 3 files changed, 110 insertions(+), 110 deletions(-) diff --git a/MultiPeriodDaily.js b/MultiPeriodDaily.js index 01850e771..75eb7ab7f 100644 --- a/MultiPeriodDaily.js +++ b/MultiPeriodDaily.js @@ -115,95 +115,75 @@ let reportKey; let statusReport; - if (processConfig.framework.startDate.fixedDate !== undefined) { + /* + We look first for the bot who knows the begining of the market in order to get when the market starts. + */ - /* The starting date is fixed, we will start from there. */ - - if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> getContextVariables -> We have got a user defined startDate. -> startDate = " + processConfig.framework.startDate.fixedDate); } - contextVariables.dateBeginOfMarket = new Date(processConfig.framework.startDate.fixedDate); - - } else { - - /* - We look first for the bot who knows the begining of the market in order to get when the market starts. - */ - - statusReport = statusDependencies.reportsByMainUtility.get("Market Starting Point") - - if (statusReport === undefined) { // This means the status report does not exist, that could happen for instance at the begining of a month. - logger.write(MODULE_NAME, "[WARN] start -> getContextVariables -> Market Starting Point -> Status Report does not exist or Market Starting Point not defined. Retrying Later. "); - callBackFunction(global.DEFAULT_RETRY_RESPONSE); - return; - } - - if (statusReport.status === "Status Report is corrupt.") { - logger.write(MODULE_NAME, "[ERROR] start -> getContextVariables -> Can not continue because dependecy Status Report is corrupt. "); - callBackFunction(global.DEFAULT_RETRY_RESPONSE); - return; - } - - thisReport = statusReport.file; - - if (thisReport.beginingOfMarket === undefined) { - logger.write(MODULE_NAME, "[WARN] start -> getContextVariables -> Undefined Last File. -> reportKey = " + reportKey); - logger.write(MODULE_NAME, "[HINT] start -> getContextVariables -> It is too early too run this process since the trade history of the market is not there yet."); - - let customOK = { - result: global.CUSTOM_OK_RESPONSE.result, - message: "Dependency does not exist." - } - logger.write(MODULE_NAME, "[WARN] start -> getContextVariables -> customOK = " + customOK.message); - callBackFunction(customOK); - return; - } - - contextVariables.dateBeginOfMarket = new Date(thisReport.beginingOfMarket.year + "-" + thisReport.beginingOfMarket.month + "-" + thisReport.beginingOfMarket.days + " " + thisReport.beginingOfMarket.hours + ":" + thisReport.beginingOfMarket.minutes + GMT_SECONDS); + statusReport = statusDependencies.reportsByMainUtility.get("Market Starting Point") + if (statusReport === undefined) { // This means the status report does not exist, that could happen for instance at the begining of a month. + logger.write(MODULE_NAME, "[WARN] start -> getContextVariables -> Market Starting Point -> Status Report does not exist or Market Starting Point not defined. Retrying Later. "); + callBackFunction(global.DEFAULT_RETRY_RESPONSE); + return; } - if (processConfig.framework.endDate.fixedDate !== undefined) { - - /* The ending date is fixed, we will end there. */ - if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> getContextVariables -> We have got a user defined endDate. -> endDate = " + processConfig.framework.endDate.fixedDate); } - contextVariables.dateEndOfMarket = new Date(processConfig.framework.endDate.fixedDate); - - } else { - - /* - Here we get the status report from the bot who knows which is the end of the market. - */ - - statusReport = statusDependencies.reportsByMainUtility.get("Market Ending Point") - - if (statusReport === undefined) { // This means the status report does not exist, that could happen for instance at the begining of a month. - logger.write(MODULE_NAME, "[WARN] start -> getContextVariables -> Market Ending Point -> Status Report does not exist or Market Ending Point not defined. Retrying Later. "); - callBackFunction(global.DEFAULT_RETRY_RESPONSE); - return; - } - - if (statusReport.status === "Status Report is corrupt.") { - logger.write(MODULE_NAME, "[ERROR] start -> getContextVariables -> Can not continue because dependecy Status Report is corrupt. "); - callBackFunction(global.DEFAULT_RETRY_RESPONSE); - return; - } - - thisReport = statusReport.file; - - if (thisReport.lastFile === undefined) { - logger.write(MODULE_NAME, "[WARN] start -> getContextVariables -> Undefined Last File. -> reportKey = " + reportKey); - - let customOK = { - result: global.CUSTOM_OK_RESPONSE.result, - message: "Dependency not ready." - } - logger.write(MODULE_NAME, "[WARN] start -> getContextVariables -> customOK = " + customOK.message); - callBackFunction(customOK); - return; - } - - contextVariables.dateEndOfMarket = new Date(thisReport.lastFile.valueOf()); + if (statusReport.status === "Status Report is corrupt.") { + logger.write(MODULE_NAME, "[ERROR] start -> getContextVariables -> Can not continue because dependecy Status Report is corrupt. "); + callBackFunction(global.DEFAULT_RETRY_RESPONSE); + return; } + thisReport = statusReport.file; + + if (thisReport.beginingOfMarket === undefined) { + logger.write(MODULE_NAME, "[WARN] start -> getContextVariables -> Undefined Last File. -> reportKey = " + reportKey); + logger.write(MODULE_NAME, "[HINT] start -> getContextVariables -> It is too early too run this process since the trade history of the market is not there yet."); + + let customOK = { + result: global.CUSTOM_OK_RESPONSE.result, + message: "Dependency does not exist." + } + logger.write(MODULE_NAME, "[WARN] start -> getContextVariables -> customOK = " + customOK.message); + callBackFunction(customOK); + return; + } + + contextVariables.dateBeginOfMarket = new Date(thisReport.beginingOfMarket.year + "-" + thisReport.beginingOfMarket.month + "-" + thisReport.beginingOfMarket.days + " " + thisReport.beginingOfMarket.hours + ":" + thisReport.beginingOfMarket.minutes + GMT_SECONDS); + + /* + Here we get the status report from the bot who knows which is the end of the market. + */ + + statusReport = statusDependencies.reportsByMainUtility.get("Market Ending Point") + + if (statusReport === undefined) { // This means the status report does not exist, that could happen for instance at the begining of a month. + logger.write(MODULE_NAME, "[WARN] start -> getContextVariables -> Market Ending Point -> Status Report does not exist or Market Ending Point not defined. Retrying Later. "); + callBackFunction(global.DEFAULT_RETRY_RESPONSE); + return; + } + + if (statusReport.status === "Status Report is corrupt.") { + logger.write(MODULE_NAME, "[ERROR] start -> getContextVariables -> Can not continue because dependecy Status Report is corrupt. "); + callBackFunction(global.DEFAULT_RETRY_RESPONSE); + return; + } + + thisReport = statusReport.file; + + if (thisReport.lastFile === undefined) { + logger.write(MODULE_NAME, "[WARN] start -> getContextVariables -> Undefined Last File. -> reportKey = " + reportKey); + + let customOK = { + result: global.CUSTOM_OK_RESPONSE.result, + message: "Dependency not ready." + } + logger.write(MODULE_NAME, "[WARN] start -> getContextVariables -> customOK = " + customOK.message); + callBackFunction(customOK); + return; + } + + contextVariables.dateEndOfMarket = new Date(thisReport.lastFile.valueOf()); + /* Finally we get our own Status Report. */ statusReport = statusDependencies.reportsByMainUtility.get("Self Reference") @@ -434,6 +414,14 @@ if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> processTimeFrames -> periodsLoopBody -> dependencyLoopBody -> Entering function."); } let dependency = dataDependencies.nodeArray[dependencyIndex]; + + if (dependency === undefined ) { + + logger.write(MODULE_NAME, "[ERROR] start -> processTimeFrames -> periodsLoopBody -> dependencyLoopBody -> You need to add at least one Data Dependency to the process Multi Period Daily. Aborting process." ); + callBackFunction(global.DEFAULT_FAIL_RESPONSE); + return; + } + let dataset = datasets[dependencyIndex]; let previousFile; diff --git a/MultiPeriodMarket.js b/MultiPeriodMarket.js index 4df897da6..a94bff1e7 100644 --- a/MultiPeriodMarket.js +++ b/MultiPeriodMarket.js @@ -90,22 +90,6 @@ dateEndOfMarket: undefined // Datetime of the last file available to be used as an input of this process. }; - if (processConfig.framework.startDate.fixedDate !== undefined) { - - /* The starting date is fixed, we will start from there. */ - - contextVariables.dateBeginOfMarket = new Date(processConfig.framework.startDate.fixedDate); - - } - - if (processConfig.framework.endDate.fixedDate !== undefined) { - - /* The ending date is fixed, we will end there. */ - - contextVariables.dateEndOfMarket = new Date(processConfig.framework.endDate.fixedDate); - - } - processTimeFrames(); function processTimeFrames() { diff --git a/Root.js b/Root.js index 7ed96f1c7..bd1a498aa 100644 --- a/Root.js +++ b/Root.js @@ -254,20 +254,24 @@ if (processConfig.framework !== undefined) { if (processConfig.framework.name === "Multi-Period-Daily" || processConfig.framework.name === "Multi-Period-Market" || processConfig.framework.name === "Multi-Period") { - processConfig.framework.startDate.resumeExecution = true; - if (processConfig.startMode.noTime !== undefined) { - if (processConfig.startMode.noTime.run === "true") { - if (processConfig.startMode.noTime.beginDatetime !== undefined) { - processConfig.framework.startDate.fixedDate = processConfig.startMode.noTime.beginDatetime; - processConfig.framework.startDate.resumeExecution = true; + if (processConfig.framework.startDate !== undefined) { + processConfig.framework.startDate.resumeExecution = true; + if (processConfig.startMode.noTime !== undefined) { + if (processConfig.startMode.noTime.run === "true") { + if (processConfig.startMode.noTime.beginDatetime !== undefined) { + processConfig.framework.startDate.fixedDate = processConfig.startMode.noTime.beginDatetime; + processConfig.framework.startDate.resumeExecution = true; + } } } } - if (processConfig.startMode.userDefined !== undefined) { - if (processConfig.startMode.userDefined.run === "true") { - if (processConfig.startMode.userDefined.beginDatetime !== undefined) { - processConfig.framework.startDate.fixedDate = processConfig.startMode.userDefined.beginDatetime; - processConfig.framework.startDate.resumeExecution = processConfig.startMode.userDefined.resumeExecution; + if (processConfig.startMode !== undefined) { + if (processConfig.startMode.userDefined !== undefined) { + if (processConfig.startMode.userDefined.run === "true") { + if (processConfig.startMode.userDefined.beginDatetime !== undefined) { + processConfig.framework.startDate.fixedDate = processConfig.startMode.userDefined.beginDatetime; + processConfig.framework.startDate.resumeExecution = processConfig.startMode.userDefined.resumeExecution; + } } } } @@ -276,6 +280,30 @@ try { + if (processConfig.startMode === undefined) { // Default + + botConfig.hasTheBotJustStarted = true; + + switch (botConfig.type) { + case 'Sensor Bot': { + runSensorBot(botConfig, processConfig); + break; + } + case 'Indicator Bot': { + runIndicatorBot(botConfig, processConfig); + break; + } + case 'Trading Bot': { + runTradingBot(botConfig, processConfig); + break; + } + default: { + console.log(logDisplace + "Root : [ERROR] start -> bootingBot -> Unexpected bot type. -> botConfig.type = " + botConfig.type); + } + } + return + } + if (processConfig.startMode.noTime !== undefined) { if (processConfig.startMode.noTime.run === "true") {