From 2ebae6f1fb68b5fd57ffe1f18090c0612aa83ee9 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Fri, 16 Aug 2019 17:49:51 +0200 Subject: [PATCH] BUG Fixed initial Date on Backtest --- Commons.js | 118 +++++++++++++++++++++++++++-------------------------- Root.js | 24 ++++++++--- 2 files changed, 79 insertions(+), 63 deletions(-) diff --git a/Commons.js b/Commons.js index 42e713d8a..536197b36 100644 --- a/Commons.js +++ b/Commons.js @@ -1391,42 +1391,44 @@ exports.newCommons = function newCommons(bot, logger, UTILITIES) { tradePositionSize = strategy.positionSize; tradePositionRate = strategy.positionRate; - /* We see if we need to put the actual order at the exchange. */ - - if (interExecutionMemory.executionContext !== undefined) { - switch (interExecutionMemory.executionContext.status) { - case "Without a Position": { // We need to put the order because It was not put yet. - if (strategy.openStage !== undefined) { - if (strategy.openStage.openExecution !== undefined) { - putOpeningOrder() - return + /* Check that we are in LIVE MODE */ + if (process.env.START_MODE === "live") { + /* We see if we need to put the actual order at the exchange. */ + if (interExecutionMemory.executionContext !== undefined) { + switch (interExecutionMemory.executionContext.status) { + case "Without a Position": { // We need to put the order because It was not put yet. + if (strategy.openStage !== undefined) { + if (strategy.openStage.openExecution !== undefined) { + putOpeningOrder() + return + } } + break } - break - } - case "Position Closed": { // Waiting for a confirmation that the position was closed. - if (strategy.openStage !== undefined) { - if (strategy.openStage.openExecution !== undefined) { - putOpeningOrder() - return + case "Position Closed": { // Waiting for a confirmation that the position was closed. + if (strategy.openStage !== undefined) { + if (strategy.openStage.openExecution !== undefined) { + putOpeningOrder() + return + } } + break + } + case "Taking Position": { // Waiting for a confirmation that the position was taken. + if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] runSimulation -> loop -> takePositionNow -> Exiting code block because status is Taking Position."); } + break + } + case "In a Position": { // This should mean that we already put the order at the exchange. + if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] runSimulation -> loop -> takePositionNow -> Exiting code block because status is In a Position."); } + break } - break } - case "Taking Position": { // Waiting for a confirmation that the position was taken. - if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] runSimulation -> loop -> takePositionNow -> Exiting code block because status is Taking Position."); } - break - } - case "In a Position": { // This should mean that we already put the order at the exchange. - if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] runSimulation -> loop -> takePositionNow -> Exiting code block because status is In a Position."); } - break - } - } - } else { // The context does not exist so it means we are not in a position. - if (strategy.openStage !== undefined) { - if (strategy.openStage.openExecution !== undefined) { - putOpeningOrder() - return + } else { // The context does not exist so it means we are not in a position. + if (strategy.openStage !== undefined) { + if (strategy.openStage.openExecution !== undefined) { + putOpeningOrder() + return + } } } } @@ -1613,36 +1615,38 @@ exports.newCommons = function newCommons(bot, logger, UTILITIES) { /* Position size and rate */ let strategy = tradingSystem.strategies[currentStrategyIndex]; - /* We see if we need to put the actual order at the exchange. */ - - if (interExecutionMemory.executionContext !== undefined) { - switch (interExecutionMemory.executionContext.status) { - case "Without a Position": { // No way to close anything at the exchange. - if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] runSimulation -> loop -> Closing a Position -> Exiting code block because status is Without a Position."); } - break - } - case "In a Position": { // This should mean that we already put the order at the exchange. - if (strategy.closeStage !== undefined) { - if (strategy.closeStage.closeExecution !== undefined) { - putClosingOrder() - return - } + /* Check that we are in LIVE MODE */ + if (process.env.START_MODE === "live") { + /* We see if we need to put the actual order at the exchange. */ + if (interExecutionMemory.executionContext !== undefined) { + switch (interExecutionMemory.executionContext.status) { + case "Without a Position": { // No way to close anything at the exchange. + if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] runSimulation -> loop -> Closing a Position -> Exiting code block because status is Without a Position."); } + break } - break - } - case "Closing Position": { // Waiting for a confirmation that the position was taken. - if (strategy.closeStage !== undefined) { - if (strategy.closeStage.closeExecution !== undefined) { - putClosingOrder() - return + case "In a Position": { // This should mean that we already put the order at the exchange. + if (strategy.closeStage !== undefined) { + if (strategy.closeStage.closeExecution !== undefined) { + putClosingOrder() + return + } } + break + } + case "Closing Position": { // Waiting for a confirmation that the position was taken. + if (strategy.closeStage !== undefined) { + if (strategy.closeStage.closeExecution !== undefined) { + putClosingOrder() + return + } + } + break } - break - } - case "Position Closed": { // - if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] runSimulation -> loop -> Closing a Position -> Exiting code block because status is Position Closed."); } - break + case "Position Closed": { // + if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] runSimulation -> loop -> Closing a Position -> Exiting code block because status is Position Closed."); } + break + } } } } diff --git a/Root.js b/Root.js index ff3e8c56f..07a9cc04e 100644 --- a/Root.js +++ b/Root.js @@ -238,15 +238,27 @@ if (processConfig.framework.name === "Multi-Period-Daily" || processConfig.framework.name === "Multi-Period-Market") { processConfig.framework.startDate.resumeExecution = false; if (processConfig.startMode.noTime !== undefined) { - if (processConfig.startMode.noTime.beginDatetime !== undefined) { - processConfig.framework.startDate.fixedDate = processConfig.startMode.noTime.beginDatetime; - processConfig.framework.startDate.resumeExecution = false; + if (processConfig.startMode.noTime.run === "true") { + if (processConfig.startMode.noTime.beginDatetime !== undefined) { + processConfig.framework.startDate.fixedDate = processConfig.startMode.noTime.beginDatetime; + processConfig.framework.startDate.resumeExecution = false; + } } } if (processConfig.startMode.live !== undefined) { - if (processConfig.startMode.live.beginDatetime !== undefined) { - processConfig.framework.startDate.fixedDate = processConfig.startMode.live.beginDatetime; - processConfig.framework.startDate.resumeExecution = false; + if (processConfig.startMode.live.run === "true") { + if (processConfig.startMode.live.beginDatetime !== undefined) { + processConfig.framework.startDate.fixedDate = processConfig.startMode.live.beginDatetime; + processConfig.framework.startDate.resumeExecution = false; + } + } + } + if (processConfig.startMode.backtest !== undefined) { + if (processConfig.startMode.backtest.run === "true") { + if (processConfig.startMode.backtest.beginDatetime !== undefined) { + processConfig.framework.startDate.fixedDate = processConfig.startMode.backtest.beginDatetime; + processConfig.framework.startDate.resumeExecution = false; + } } } }