From 202af8692760ce37f46dc9fd28a05d44b125740f Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Fri, 12 Jun 2020 12:16:16 +0200 Subject: [PATCH] Code Mantainance --- DataSet.js | 4 ++-- IndicatorOutput.js | 7 ------- LowFrequencyTrading/TradingProcess.js | 13 ++++--------- MultiPeriodDaily.js | 4 +--- MultiPeriodMarket.js | 2 +- Root.js | 9 +-------- Session.js | 13 ------------- StatusDependencies.js | 12 ++++++------ StatusReport.js | 15 ++++----------- TradingBot.js | 2 -- 10 files changed, 19 insertions(+), 62 deletions(-) diff --git a/DataSet.js b/DataSet.js index 1a6364b7a..bb7f789e3 100644 --- a/DataSet.js +++ b/DataSet.js @@ -204,8 +204,8 @@ exports.newDataSet = function newDataSet(BOT, logger) { if (global.LOG_CONTROL[MODULE_NAME].logInfo === true) { logger.write(MODULE_NAME, "[INFO] createTextFile -> pFolderPath = " + pFolderPath); } if (global.LOG_CONTROL[MODULE_NAME].logInfo === true) { logger.write(MODULE_NAME, "[INFO] createTextFile -> pFileName = " + pFileName); } - let ownerId = thisObject.node.dataMine + "-" + thisObject.node.bot + "-" + thisObject.node.botVersion.major + "-" + thisObject.node.botVersion.minor + "-" + thisObject.node.dataSetVersion; - let botId = bot.dataMine + "-" + bot.codeName + "-" + bot.version.major + "-" + bot.version.minor + "-" + bot.dataSetVersion; + let ownerId = thisObject.node.dataMine + "-" + thisObject.node.bot + let botId = bot.dataMine + "-" + bot.codeName if (ownerId !== botId) { diff --git a/IndicatorOutput.js b/IndicatorOutput.js index 1f1e62182..9a1a9b95b 100644 --- a/IndicatorOutput.js +++ b/IndicatorOutput.js @@ -141,13 +141,6 @@ contextSummary.bot = outputDatasetNode.referenceParent.parentNode.parentNode.config.codeName contextSummary.dataMine = outputDatasetNode.referenceParent.parentNode.parentNode.parentNode.config.codeName - /* This stuff is still hardcoded and unresolved. */ - contextSummary.botVersion = { - "major": 1, - "minor": 0 - } - contextSummary.dataSetVersion = "dataSet.V1" - let fileContent = commons.generateFileContent(outputData, outputDatasetNode.referenceParent.parentNode.record, resultsWithIrregularPeriods, processingDailyFiles, currentDay, callBackFunction) commons.writeFile(contextSummary, fileContent, anotherFileWritten, processingDailyFiles, timeFrameLabel, currentDay, callBackFunction) } diff --git a/LowFrequencyTrading/TradingProcess.js b/LowFrequencyTrading/TradingProcess.js index 712d9d35a..ffe9cb149 100644 --- a/LowFrequencyTrading/TradingProcess.js +++ b/LowFrequencyTrading/TradingProcess.js @@ -155,8 +155,7 @@ if (bot.simulationState === undefined) { bot.simulationState = {} } // This should happen only when there is no status report if (thisReport.lastFile !== undefined) { - if (bot.hasTheBotJustStarted === true && bot.resumeExecution === false) { - + if (bot.RESUME !== true) { if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> getContextVariables -> Starting from the begining because bot has just started and resume execution was true."); } startFromBegining(); return; @@ -628,8 +627,6 @@ } function onDailyStatusReport() { - /* The next run we need the process to continue at the date it finished. */ - processConfig.framework.startDate.resumeExecution = true; advanceTime(); } @@ -711,26 +708,24 @@ } function writeDailyStatusReport(lastFileDate, callBack) { - let reportKey = bot.dataMine + "-" + bot.codeName + "-" + bot.processNode.referenceParent.config.codeName + "-" + "dataSet.V1"; + let reportKey = bot.dataMine + "-" + bot.codeName + "-" + bot.processNode.referenceParent.config.codeName let thisReport = statusDependencies.statusReports.get(reportKey); thisReport.file.lastExecution = bot.currentDaytime; thisReport.file.lastFile = lastFileDate; thisReport.file.simulationState = bot.simulationState; thisReport.save(callBack); - - bot.hasTheBotJustStarted = false; } function writeMarketStatusReport(callBack) { - let reportKey = bot.dataMine + "-" + bot.codeName + "-" + bot.processNode.referenceParent.config.codeName + "-" + "dataSet.V1"; + let reportKey = bot.dataMine + "-" + bot.codeName + "-" + bot.processNode.referenceParent.config.codeName let thisReport = statusDependencies.statusReports.get(reportKey); thisReport.file.lastExecution = bot.processDatetime; thisReport.file.simulationState = bot.simulationState; - thisReport.save(callBack); logger.newInternalLoop(bot.codeName, bot.process, bot.tradingProcessDate); + thisReport.save(callBack); } } catch (err) { diff --git a/MultiPeriodDaily.js b/MultiPeriodDaily.js index da6266000..b26ff1f15 100644 --- a/MultiPeriodDaily.js +++ b/MultiPeriodDaily.js @@ -772,8 +772,7 @@ if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> writeStatusReport -> lastFileDate = " + lastFileDate); } try { - - let reportKey = bot.dataMine + "-" + bot.codeName + "-" + "Multi-Period-Daily" + "-" + "dataSet.V1"; + let reportKey = bot.dataMine + "-" + bot.codeName + "-" + "Multi-Period-Daily" let thisReport = statusDependencies.statusReports.get(reportKey); thisReport.file.lastExecution = bot.currentDaytime; @@ -783,7 +782,6 @@ thisReport.save(callBack); bot.hasTheBotJustStarted = false; - } catch (err) { logger.write(MODULE_NAME, "[ERROR] start -> writeStatusReport -> err = " + err.stack); diff --git a/MultiPeriodMarket.js b/MultiPeriodMarket.js index 0464b5d30..a0b4d41ed 100644 --- a/MultiPeriodMarket.js +++ b/MultiPeriodMarket.js @@ -296,7 +296,7 @@ try { - let reportKey = bot.dataMine + "-" + bot.codeName + "-" + "Multi-Period-Market" + "-" + "dataSet.V1"; + let reportKey = bot.dataMine + "-" + bot.codeName + "-" + "Multi-Period-Market" let thisReport = statusDependencies.statusReports.get(reportKey); thisReport.file.lastExecution = bot.processDatetime; diff --git a/Root.js b/Root.js index 279601849..0070316cf 100644 --- a/Root.js +++ b/Root.js @@ -179,7 +179,7 @@ botConfig.repo = global.TASK_NODE.bot.config.repo; bootingBot(processIndex); } catch (err) { - console.log(logDisplace + "Root : [ERROR] start -> getBotConfigFromFile -> onInizialized -> onFileReceived -> err = " + JSON.stringify(err)); + console.log(logDisplace + "Root : [ERROR] start -> getBotConfigFromFile -> onInizialized -> onFileReceived -> err = " + err.stack); return; } } @@ -213,13 +213,6 @@ botConfig.uiStartDate = global.TASK_NODE.bot.config.startDate botConfig.config = global.TASK_NODE.bot.config - /* This stuff is still hardcoded and unresolved. */ - botConfig.version = { - "major": 1, - "minor": 0 - } - botConfig.dataSetVersion = "dataSet.V1" - /* Loop Counter */ botConfig.loopCounter = 0; diff --git a/Session.js b/Session.js index 0297863f1..64fe9f403 100644 --- a/Session.js +++ b/Session.js @@ -55,7 +55,6 @@ return function runSession(message) { - try { if (bot.SESSION_STATUS === 'Idle' || bot.SESSION_STATUS === 'Running') { return } // This happens when the UI is reloaded, the session was running and tries to run it again. @@ -299,40 +298,31 @@ } function startBackTesting(message) { - bot.resumeExecution = false; // TODO change this for the new way of handling resuming - bot.hasTheBotJustStarted = true // TODO see if this is necesary bot.tradingProcessDate = new Date(bot.SESSION.parameters.timeRange.config.initialDatetime.valueOf()) // Here we initialize the date of the process. return true } function startLiveTrading(message) { - if (process.env.KEY === undefined || process.env.SECRET === undefined) { // TODO Remove this from Process .env if (FULL_LOG === true) { parentLogger.write(MODULE_NAME, "[ERROR] initialize -> startLiveTrading -> Key 'codeName' or 'secret' not provided. Plese check that and try again."); } return false } - bot.resumeExecution = false; bot.tradingProcessDate = new Date(bot.SESSION.parameters.timeRange.config.initialDatetime.valueOf()) - bot.hasTheBotJustStarted = true pProcessConfig.liveWaitTime = sessionParameters.timeFrame.config.value return true } function startFordwardTesting(message) { - if (process.env.KEY === undefined || process.env.SECRET === undefined) { if (FULL_LOG === true) { parentLogger.write(MODULE_NAME, "[WARN] initialize -> startFordwardTesting -> Key name or Secret not provided, not possible to run the process in Forward Testing mode."); } console.log("Key 'codeName' or 'secret' not provided. Plese check that and try again.") return false } - bot.resumeExecution = false; bot.tradingProcessDate = new Date(bot.SESSION.parameters.timeRange.config.initialDatetime.valueOf()) - bot.hasTheBotJustStarted = true /* Reduce the balance */ - let balancePercentage = 1 // This is the default value if (bot.SESSION.config.balancePercentage !== undefined) { @@ -354,9 +344,6 @@ } function startPaperTrading(message) { - - bot.resumeExecution = false; - bot.hasTheBotJustStarted = true bot.tradingProcessDate = new Date(bot.SESSION.parameters.timeRange.config.initialDatetime.valueOf()) pProcessConfig.normalWaitTime = sessionParameters.timeFrame.config.value return true diff --git a/StatusDependencies.js b/StatusDependencies.js index 48b5659a9..21314c4c8 100644 --- a/StatusDependencies.js +++ b/StatusDependencies.js @@ -4,7 +4,7 @@ const LOG_FILE_CONTENT = false; const MODULE_NAME = "Status Dependencies"; - let bot = BOT + let bot = BOT let thisObject = { nodeArray: undefined, @@ -47,7 +47,7 @@ let statusDependency = { dependency: thisObject.nodeArray[i] } - + dependenciesToProcess.push(statusDependency) } @@ -124,7 +124,7 @@ } } catch (err) { - logger.write(MODULE_NAME, "[ERROR] initialize -> onLoad -> err = "+ err.stack); + logger.write(MODULE_NAME, "[ERROR] initialize -> onLoad -> err = " + err.stack); callBackFunction(global.DEFAULT_FAIL_RESPONSE); } } @@ -137,14 +137,14 @@ loadCount++; logger.write(MODULE_NAME, "[INFO] initialize -> addReport -> Total Added = " + loadCount); - let key = statusDependency.dependency.dataMine + "-" + statusDependency.dependency.bot + "-" + statusDependency.dependency.process + "-" + statusDependency.dependency.dataSetVersion; + let key = statusDependency.dependency.dataMine + "-" + statusDependency.dependency.bot + "-" + statusDependency.dependency.process thisObject.keys.push(key); thisObject.statusReports.set(key, statusReportModule); if (statusReportModule.mainUtility !== undefined) { thisObject.reportsByMainUtility.set(statusReportModule.mainUtility, statusReportModule) - } + } if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] initialize -> addReport -> Report added to Map. -> key = " + key); } @@ -161,7 +161,7 @@ } } catch (err) { - logger.write(MODULE_NAME, "[ERROR] initialize -> err = "+ err.stack); + logger.write(MODULE_NAME, "[ERROR] initialize -> err = " + err.stack); callBackFunction(global.DEFAULT_FAIL_RESPONSE); } } diff --git a/StatusReport.js b/StatusReport.js index 72fe4381d..ff40b4e74 100644 --- a/StatusReport.js +++ b/StatusReport.js @@ -102,13 +102,6 @@ } } - /* This stuff is still hardcoded and unresolved. */ - statusDependencyNode.botVersion = { - "major": 1, - "minor": 0 - } - statusDependencyNode.dataSetVersion = "dataSet.V1" - if (bot.SESSION !== undefined && statusDependencyNode.bottype === "Trading Bot") { sessionPath = bot.SESSION.folderName + "/" } @@ -204,8 +197,8 @@ let fileName = "Status.Report.json"; let filePath; - let ownerId = statusDependencyNode.dataMine + "-" + statusDependencyNode.bot + "-" + statusDependencyNode.botVersion.major + "-" + statusDependencyNode.botVersion.minor + "-" + statusDependencyNode.process + "-" + statusDependencyNode.dataSetVersion; - let botId = bot.dataMine + "-" + bot.codeName + "-" + bot.version.major + "-" + bot.version.minor + "-" + bot.process + "-" + bot.dataSetVersion; + let ownerId = statusDependencyNode.dataMine + "-" + statusDependencyNode.bot + "-" + statusDependencyNode.process + let botId = bot.dataMine + "-" + bot.codeName + "-" + bot.process if (ownerId !== botId) { @@ -301,8 +294,8 @@ if (global.LOG_CONTROL[MODULE_NAME].logInfo === true) { logger.write(MODULE_NAME, "[INFO] save -> Entering function."); } - let ownerId = statusDependencyNode.dataMine + "-" + statusDependencyNode.bot + "-" + statusDependencyNode.botVersion.major + "-" + statusDependencyNode.botVersion.minor + "-" + statusDependencyNode.process + "-" + statusDependencyNode.dataSetVersion; - let botId = bot.dataMine + "-" + bot.codeName + "-" + bot.version.major + "-" + bot.version.minor + "-" + bot.process + "-" + bot.dataSetVersion; + let ownerId = statusDependencyNode.dataMine + "-" + statusDependencyNode.bot + "-" + statusDependencyNode.process + let botId = bot.dataMine + "-" + bot.codeName + "-" + bot.process if (ownerId !== botId && statusDependencyNode.process !== "Context") { // Context is a special case where the report is created by the Context.js module itself. diff --git a/TradingBot.js b/TradingBot.js index a99df360a..c62a11434 100644 --- a/TradingBot.js +++ b/TradingBot.js @@ -41,8 +41,6 @@ return } - bot.resumeExecution = processConfig.framework.startDate.resumeExecution // We are inherating this from root, but from here we need it at bot - let filePath = bot.dataMine + "/" + "bots" + "/" + bot.repo + "/" + pProcessConfig.codeName filePath += "/User.Bot.js"