From 1e4d187222123ad0f0fd53267a4c59b540e3a574 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Sat, 10 Aug 2019 00:15:47 +0200 Subject: [PATCH] timePeriod and beginDate coming at simulationParams --- MultiPeriodDaily.js | 2 +- MultiPeriodMarket.js | 2 +- Run.js | 55 +++++++++++++++++++++++++++++++++----------- 3 files changed, 43 insertions(+), 16 deletions(-) diff --git a/MultiPeriodDaily.js b/MultiPeriodDaily.js index 66a220f4e..003f97ec8 100644 --- a/MultiPeriodDaily.js +++ b/MultiPeriodDaily.js @@ -370,7 +370,7 @@ } } - let timePeriodFilter = process.env.TIME_PERIOD + let timePeriodFilter = global.EXECUTION_CONFIG.timePeriodFileStorage if (timePeriodFilter !== undefined) { if (timePeriodFilter.indexOf(outputPeriodLabel) === -1) { periodsControlLoop(); diff --git a/MultiPeriodMarket.js b/MultiPeriodMarket.js index d5bf944ee..ceab3ff19 100644 --- a/MultiPeriodMarket.js +++ b/MultiPeriodMarket.js @@ -141,7 +141,7 @@ let dependencyIndex = 0; dataFiles = []; - let timePeriodFilter = process.env.TIME_PERIOD + let timePeriodFilter = global.EXECUTION_CONFIG.timePeriodFileStorage if (timePeriodFilter !== undefined) { if (timePeriodFilter.indexOf(outputPeriodLabel) === -1) { periodsControlLoop(); diff --git a/Run.js b/Run.js index dcaa1f688..5760e67a3 100644 --- a/Run.js +++ b/Run.js @@ -69,7 +69,7 @@ function sequenceExecution(currentStep) { processedSteps.set(stepKey, 0); } console.log("Sequence Execution Parameters: " + JSON.stringify(execution)) - readExecutionConfiguration(); + readExecutionConfiguration(execution.type); sequenceStep++; } @@ -97,24 +97,49 @@ function onExecutionFinish (result, finishStepKey) { } -async function readExecutionConfiguration() { +async function readExecutionConfiguration(botType) { try { console.log("[INFO] Run -> readExecutionConfiguration -> Entering function. "); + let timePeriod + let botProcess + /* Try to get the begin and end dates from the Definition */ let definition = await strategy.getStrategy() + + /* Dates are taken initially from .env, but can be overwritten if they are defined by the user */ let initialDatetime = process.env.BEGIN_DATE_TIME let finalDatetime = process.env.END_DATE_TIME - if (definition !== undefined) { - if (definition.tradingSystem !== undefined) { - if (definition.tradingSystem.parameters !== undefined) { - if (definition.tradingSystem.parameters.baseAsset !== undefined) { - if (definition.tradingSystem.parameters.baseAsset.formula !== undefined) { - if (definition.tradingSystem.parameters.baseAsset.formula.code !== undefined) { - let code = JSON.parse(definition.tradingSystem.parameters.baseAsset.formula.code) - initialDatetime = code.initialDatetime - finalDatetime = code.finalDatetime + if (botType === 'Trading-Engine') { + if (definition !== undefined) { + if (definition.simulationParams !== undefined) { + if (definition.simulationParams.beginDatetime !== undefined) { + initialDatetime = new Date(definition.simulationParams.beginDatetime) /* The first override occurs here, with the simulation parameters */ + } + /* Here we only look for one timePeriod, in the future we will be able to process the whole array, but not for now. */ + if (definition.simulationParams.timePeriodDailyArray !== undefined) { + if (definition.simulationParams.timePeriodDailyArray.length > 0) { + timePeriod = definition.simulationParams.timePeriodDailyArray[0] + botProcess = "Multi-Period-Daily" + } + } + if (definition.simulationParams.timePeriodMarketArray !== undefined) { + if (definition.simulationParams.timePeriodMarketArray.length > 0) { + timePeriod = definition.simulationParams.timePeriodMarketArray[0] + botProcess = "Multi-Period-Market" + } + } + } + if (definition.tradingSystem !== undefined) { + if (definition.tradingSystem.parameters !== undefined) { + if (definition.tradingSystem.parameters.baseAsset !== undefined) { + if (definition.tradingSystem.parameters.baseAsset.formula !== undefined) { + if (definition.tradingSystem.parameters.baseAsset.formula.code !== undefined) { + let code = JSON.parse(definition.tradingSystem.parameters.baseAsset.formula.code) + initialDatetime = code.initialDatetime /* The second override occurs here, with the date explicitelly defined by the user */ + finalDatetime = code.finalDatetime + } } } } @@ -189,19 +214,21 @@ async function readExecutionConfiguration() { startMode[process.env.START_MODE].run = "true" + if (botProcess === undefined) { botProcess = process.env.PROCESS } // Only use the .env when nothing comes at Definition.json let cloneToExecute = { enabled: "true", devTeam: process.env.DEV_TEAM, bot: process.env.BOT, - process: process.env.PROCESS, + process: botProcess, repo: global.CURRENT_BOT_REPO } + if (timePeriod === undefined) { timePeriod = process.env.TIME_PERIOD} // Only use the .env when nothing comes at Definition.json global.EXECUTION_CONFIG = { cloneToExecute: cloneToExecute, startMode: startMode, - timePeriod: getTimePeriod(process.env.TIME_PERIOD), - timePeriodFileStorage: process.env.TIME_PERIOD, + timePeriod: getTimePeriod(timePeriod), + timePeriodFileStorage: timePeriod, dataSet: process.env.DATA_SET };