From 39ce982afee4df87bca3539e97350cc3e3f1b885 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Wed, 14 Aug 2019 12:14:28 +0200 Subject: [PATCH] Fixing Paula not running --- Commons.js | 5 +++++ Integrations/FileStorage.js | 9 ++++++--- MultiPeriodDaily.js | 13 +++++++++---- Run.js | 9 +++++++-- TradingEngineProcessMainLoop.js | 8 ++++---- 5 files changed, 31 insertions(+), 13 deletions(-) diff --git a/Commons.js b/Commons.js index 9ada6529f..b49271578 100644 --- a/Commons.js +++ b/Commons.js @@ -369,22 +369,27 @@ exports.newCommons = function newCommons(bot, logger, UTILITIES) { /* If any of the needed indicators is missing, then that period is not calculated */ if (candle.begin < initialDate.valueOf()) { + if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] runSimulation -> loop -> Skipping Record before the initialDate."); } controlLoop(); return } if (bollingerBand === undefined) { + if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] runSimulation -> loop -> Skipping Record because Bollinger Band is undefined."); } controlLoop(); return } if (percentageBandwidth === undefined) { + if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] runSimulation -> loop -> Skipping Record because %B is undefined."); } controlLoop(); return } // percentageBandwidth might start after the first few candles. if (bollingerChannel === undefined) { + if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] runSimulation -> loop -> Skipping Record because Bollingeer Channel is undefined."); } controlLoop(); return } if (bollingerSubChannel === undefined) { + if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] runSimulation -> loop -> Skipping Record because Bollingeer Sub Channel is undefined."); } controlLoop(); return } diff --git a/Integrations/FileStorage.js b/Integrations/FileStorage.js index 68014bd70..bc096d472 100644 --- a/Integrations/FileStorage.js +++ b/Integrations/FileStorage.js @@ -6,7 +6,7 @@ const readFileAsync = promisify(fs.readFile) const writeFileAsync = promisify(fs.writeFile) const path = require('path') -exports.newFileStorage = function newFileStorage() { +exports.newFileStorage = function newFileStorage(logger) { const MODULE_NAME = 'FileStorage' const MAX_RETRY = 30 let currentRetryGetTextFile = 0 @@ -37,7 +37,11 @@ exports.newFileStorage = function newFileStorage() { log('[INFO] ' + message) } function log(message) { - console.log("['" + new Date().toISOString() + "', 0,'" + MODULE_NAME + "','" + message + "']") + if (logger) { + logger.write(MODULE_NAME, message); + } else { + console.log("['" + new Date().toISOString() + "', 0,'" + MODULE_NAME + "','" + message + "']") + } } function logError(message) { @@ -46,7 +50,6 @@ exports.newFileStorage = function newFileStorage() { async function getTextFile(container, filePath, callBackFunction) { - try { let host = await getDevTeamHost(container) diff --git a/MultiPeriodDaily.js b/MultiPeriodDaily.js index 77eba7115..3cfb4dad6 100644 --- a/MultiPeriodDaily.js +++ b/MultiPeriodDaily.js @@ -21,7 +21,7 @@ let usertBot; const FILE_STORAGE = require('./Integrations/FileStorage.js'); - let fileStorage = FILE_STORAGE.newFileStorage(); + let fileStorage = FILE_STORAGE.newFileStorage(logger); let processConfig; @@ -103,6 +103,7 @@ /* 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 { @@ -152,7 +153,7 @@ 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 { @@ -222,6 +223,7 @@ if (bot.hasTheBotJustStarted === true && processConfig.framework.startDate.resumeExecution === false) { + 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; } @@ -237,7 +239,7 @@ /* In the case when there is no status report, we assume like the last processed file is the one on the date of Begining of Market. */ - + if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> getContextVariables -> Starting from the begining of the market because own status report not found or lastFile was undefined."); } startFromBegining(); return; } @@ -246,7 +248,6 @@ contextVariables.lastFile = new Date(contextVariables.dateBeginOfMarket.getUTCFullYear() + "-" + (contextVariables.dateBeginOfMarket.getUTCMonth() + 1) + "-" + contextVariables.dateBeginOfMarket.getUTCDate() + " " + "00:00" + GMT_SECONDS); - if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> getContextVariables -> startFromBegining -> thisReport.lastFile === undefined"); } if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> getContextVariables -> startFromBegining -> contextVariables.lastFile = " + contextVariables.lastFile); } /* @@ -365,6 +366,7 @@ if (period === outputPeriodLabel) { validPeriod = true } } if (validPeriod === false) { + if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> processTimePeriods -> periodsLoopBody -> Discarding period for not being listed as a valid period. -> outputPeriodLabel = " + outputPeriodLabel); } periodsControlLoop(); return; } @@ -373,6 +375,7 @@ let timePeriodFilter = global.EXECUTION_CONFIG.timePeriodFileStorage if (timePeriodFilter !== undefined) { if (timePeriodFilter.indexOf(outputPeriodLabel) === -1) { + if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> processTimePeriods -> periodsLoopBody -> Discarding period for being filtered out. -> outputPeriodLabel = " + outputPeriodLabel); } periodsControlLoop(); return; } @@ -499,6 +502,8 @@ if ((err.result === "Fail Because" && err.message === "File does not exist.") || err.code === 'The specified key does not exist.') { logger.write(MODULE_NAME, "[ERROR] start -> processTimePeriods -> periodsLoopBody -> dependencyLoopBody -> getCurrentFile -> onFileReceived -> err = " + err.code); + logger.write(MODULE_NAME, "[ERROR] start -> processTimePeriods -> periodsLoopBody -> dependencyLoopBody -> getCurrentFile -> onFileReceived -> filePath = " + filePath); + logger.write(MODULE_NAME, "[ERROR] start -> processTimePeriods -> periodsLoopBody -> dependencyLoopBody -> getCurrentFile -> onFileReceived -> fileName = " + fileName); callBackFunction(global.DEFAULT_RETRY_RESPONSE); return; } diff --git a/Run.js b/Run.js index fac89b6b5..1ee41d390 100644 --- a/Run.js +++ b/Run.js @@ -34,7 +34,7 @@ let sequenceList = require('./sequence'); let isRunSequence = false; let sequenceStep = 0; let processedSteps = new Map() -notFirstSequence = false +let notFirstSequence = false if (process.env.RUN_SEQUENCE !== undefined) { isRunSequence = JSON.parse(process.env.RUN_SEQUENCE) @@ -53,7 +53,7 @@ function sequenceExecution(currentStep) { execution.devTeam ? process.env.DEV_TEAM = execution.devTeam : undefined; execution.bot ? process.env.BOT = execution.bot : undefined; execution.mode ? process.env.START_MODE = execution.mode : undefined; - execution.resumeExecution = notFirstSequence + execution.resumeExecution = true; execution.type ? process.env.TYPE = execution.type : undefined; execution.process ? process.env.PROCESS = execution.process : undefined; execution.startYear ? process.env.MIN_YEAR = execution.startYear : undefined; @@ -142,6 +142,11 @@ async function readExecutionConfiguration(execution) { if (execution.type === 'Trading-Engine') { + /* The Trading Engine only resumes its execution after the first sequence was completed. */ + if (notFirstSequence === false) { + execution.resumeExecution = false + } + /* We set the START MODE of the Trading Engine */ if (process.env.KEY === undefined || process.env.SECRET === undefined) { process.env.START_MODE = "backtest" // if we dont have keys, we swtich to backtest mode to avoid exchange errors. diff --git a/TradingEngineProcessMainLoop.js b/TradingEngineProcessMainLoop.js index f8b03155b..d43569348 100644 --- a/TradingEngineProcessMainLoop.js +++ b/TradingEngineProcessMainLoop.js @@ -54,8 +54,8 @@ } USER_BOT_MODULE = {} - USER_BOT_MODULE.newUserBot = require(ROOT_DIR + 'User.Bot').newUserBot // Use this for a better debugging experience. You need to bring this js module to this folder in order to work. - //USER_BOT_MODULE.newUserBot = eval(text); // Use this for production + //USER_BOT_MODULE.newUserBot = require(ROOT_DIR + 'User.Bot').newUserBot // Use this for a better debugging experience. You need to bring this js module to this folder in order to work. + USER_BOT_MODULE.newUserBot = eval(text); // Use this for production filePath = global.DEV_TEAM + "/" + "bots" + "/" + bot.repo; filePath += "/Commons.js" @@ -70,8 +70,8 @@ return; } COMMONS_MODULE = {} - COMMONS_MODULE.newCommons = require(ROOT_DIR + 'Commons').newCommons // Use this for a better debugging experience. You need to bring this js module to this folder in order to work. - //COMMONS_MODULE.newCommons = eval(text); // Use this for production + //COMMONS_MODULE.newCommons = require(ROOT_DIR + 'Commons').newCommons // Use this for a better debugging experience. You need to bring this js module to this folder in order to work. + COMMONS_MODULE.newCommons = eval(text); // Use this for production callBackFunction(global.DEFAULT_OK_RESPONSE); }