From 1a5e1ed6cc73d48e9ecb9ce3d5d72e868a415175 Mon Sep 17 00:00:00 2001 From: Matias Date: Tue, 9 Jul 2019 10:24:57 -0300 Subject: [PATCH] Changing wait time property and removing UI options from backtesting --- TradingBotProcessMainLoop.js | 73 +++++------------------------------- 1 file changed, 9 insertions(+), 64 deletions(-) diff --git a/TradingBotProcessMainLoop.js b/TradingBotProcessMainLoop.js index 1b7ba1604..1c39f67dd 100644 --- a/TradingBotProcessMainLoop.js +++ b/TradingBotProcessMainLoop.js @@ -140,8 +140,8 @@ if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] run -> loop -> Live Mode detected."); } - if(process.env.NORMAL_WAIT_TIME !== undefined) - processConfig.normalWaitTime = process.env.NORMAL_WAIT_TIME + if(process.env.WAIT_TIME !== undefined) + processConfig.normalWaitTime = process.env.WAIT_TIME // This will be considered the process date and time, so as to have it consistenly all over the execution. @@ -168,74 +168,19 @@ if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] run -> loop -> Backtesting Mode detected."); } - if(process.env.NORMAL_WAIT_TIME !== undefined) { - processConfig.normalWaitTime = process.env.NORMAL_WAIT_TIME - } else { - processConfig.normalWaitTime = 1 - } - - let timePeriod; - - if (UI_COMMANDS.timePeriod !== undefined) { - - timePeriod = UI_COMMANDS.timePeriod; - - } else { - - timePeriod = processConfig.timePeriod; - + if(process.env.WAIT_TIME !== undefined) { + processConfig.normalWaitTime = JSON.parse(process.env.WAIT_TIME) } if (bot.hasTheBotJustStarted === true) { - if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] run -> loop -> Setting initial datetime."); } - - if (UI_COMMANDS.beginDatetime !== undefined) { - - bot.processDatetime = new Date(UI_COMMANDS.beginDatetime.valueOf()); //datetime is comming from the UI. - - } else { - - bot.processDatetime = new Date(bot.backtest.beginDatetime); // Set the starting time as the configured beginDatetime. - - } - - /* - We will standarize the backtesting execution time, setting the exact time a fraction after the start of the candle or timePeriod. - */ - - let totalMiliseconds = bot.processDatetime.valueOf(); - totalMiliseconds = Math.trunc(totalMiliseconds / timePeriod) * timePeriod + timePeriod / 6; - - bot.processDatetime = new Date(totalMiliseconds); - + bot.processDatetime = new Date(bot.backtest.beginDatetime); // Set the starting time as the configured beginDatetime. } else { - - bot.processDatetime = new Date(bot.processDatetime.valueOf() + timePeriod); // We advance time here. - - - if (UI_COMMANDS.eventHandler !== undefined) { - - UI_COMMANDS.eventHandler.raiseEvent('Bot Execution Changed Datetime', bot.processDatetime); - - } - - let endDatetime; - - if (UI_COMMANDS.endDatetime !== undefined) { - - endDatetime = new Date(UI_COMMANDS.endDatetime.valueOf()); - - } else { - - endDatetime = new Date(bot.backtest.endDatetime); - - } + bot.processDatetime = new Date(bot.processDatetime.valueOf() + 60000); // We advance time here. + let endDatetime = new Date(bot.backtest.endDatetime); if (bot.processDatetime.valueOf() > endDatetime.valueOf()) { - if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] run -> loop -> End of Backtesting Period reached. Exiting Bot Process Loop."); } - logger.persist(); clearInterval(fixedTimeLoopIntervalHandle); clearTimeout(nextLoopTimeoutHandle); @@ -251,8 +196,8 @@ if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] run -> loop -> Competition Mode detected."); } - if(process.env.NORMAL_WAIT_TIME !== undefined) { - processConfig.normalWaitTime = process.env.NORMAL_WAIT_TIME + if(process.env.WAIT_TIME !== undefined) { + processConfig.normalWaitTime = process.env.WAIT_TIME } let localDate = new Date();