diff --git a/Commons.js b/Commons.js index 7c1ca109a..c7908576e 100644 --- a/Commons.js +++ b/Commons.js @@ -1,4 +1,7 @@ -exports.newCommons = function newCommons(bot, logger, UTILITIES) { +const axios = require('axios') +const auth = require('./utils/auth') + +exports.newCommons = function newCommons(bot, logger, UTILITIES) { const FULL_LOG = true; const LOG_FILE_CONTENT = false; @@ -41,12 +44,14 @@ candles = []; } - function runSimulation( + async function runSimulation( recordsArray, conditionsArray, lastObjectsArray, simulationLogic, timePeriod, + startDate, + endDate, callback) { try { @@ -55,7 +60,7 @@ /* Initial Values */ - let initialDate = new Date("2015-07-01"); + let initialDate = startDate; let initialBalanceA = 1; let minimunBalanceA = 0.5; @@ -106,6 +111,9 @@ let initialBuffer = 3; + simulationLogic.strategies = await getStrategy(); + + /* simulationLogic.strategies = [ { name: "Trend Following", @@ -460,7 +468,7 @@ } } ]; - + */ /* Main Simulation Loop: We go thourgh all the candles at this time period. */ for (let i = 0 + initialBuffer; i < candles.length; i++) { @@ -1242,4 +1250,122 @@ callBackFunction(global.DEFAULT_FAIL_RESPONSE); } } -}; \ No newline at end of file + + async function getStrategy() { + + try { + + const accessToken = await auth.authenticate() + + const strategizerResponse = await axios({ + url: process.env.GATEWAY_ENDPOINT, + method: 'post', + data: { + query: ` + query($fbSlug: String!){ + + strategizer_StrategyByFb(fbSlug: $fbSlug){ + subStrategies{ + name + entryPoint{ + situations{ + name + conditions{ + name + code + } + } + } + exitPoint{ + situations{ + name + conditions{ + name + code + } + } + } + sellPoint{ + situations{ + name + conditions{ + name + code + } + } + } + buyPoint{ + situations{ + name + conditions{ + name + code + } + } + } + stopLoss{ + phases{ + name + code + situations{ + name + conditions{ + name + code + } + } + } + } + buyOrder{ + phases{ + name + code + situations{ + name + conditions{ + name + code + } + } + } + } + sellOrder{ + phases{ + name + code + situations{ + name + conditions{ + name + code + } + } + } + } + } + } + } + + `, + variables: { + fbSlug: bot.codeName + }, + }, + headers: { + authorization: 'Bearer ' + accessToken + } + }) + + if (strategizerResponse.data.errors) + throw new Error(strategizerResponse.data.errors[0].message) + + return strategizerResponse.data.data.strategizer_StrategyByFb.subStrategies; + + } catch (error) { + throw new Error('There has been an error getting the strategy to run on the simulator. Error: ' + error) + } + } +}; + + + diff --git a/Multi-Period-Daily/User.Bot.js b/Multi-Period-Daily/User.Bot.js index 43a221a07..362a2f6eb 100644 --- a/Multi-Period-Daily/User.Bot.js +++ b/Multi-Period-Daily/User.Bot.js @@ -54,7 +54,7 @@ } } - function start(dataFiles, timePeriod, outputPeriodLabel, currentDay, callBackFunction) { + function start(dataFiles, timePeriod, outputPeriodLabel, currentDay, startDate, endDate, callBackFunction) { try { @@ -111,6 +111,8 @@ lastObjectsArray, simulationLogic, timePeriod, + startDate, + endDate, writeRecordsFile) function writeRecordsFile() { diff --git a/Multi-Period-Market/User.Bot.js b/Multi-Period-Market/User.Bot.js index 71a3e83ed..00897693e 100644 --- a/Multi-Period-Market/User.Bot.js +++ b/Multi-Period-Market/User.Bot.js @@ -54,7 +54,7 @@ } } - function start(dataFiles, timePeriod, outputPeriodLabel, callBackFunction) { + function start(dataFiles, timePeriod, outputPeriodLabel, startDate, endDate, callBackFunction) { try { @@ -111,6 +111,8 @@ lastObjectsArray, simulationLogic, timePeriod, + startDate, + endDate, writeRecordsFile) function writeRecordsFile() { diff --git a/this.bot.config.json b/this.bot.config.json index cf3733691..637886720 100644 --- a/this.bot.config.json +++ b/this.bot.config.json @@ -37,6 +37,14 @@ "retryWaitTime": 10000, "sleepWaitTime": 3600000, "comaWaitTime": 86400000, + "framework": { + "name": "Multi-Period-Market", + "startDate": { + "fixedDate": "2018-07-01" + }, + "endDate": { + } + }, "statusDependencies": [ { "devTeam": "AAMasters", @@ -116,8 +124,7 @@ "dataSetVersion": "dataSet.V1", "dataSet": "Multi-Period-Market" } - ], - "framework": "Multi-Period-Market" + ] }, { "name": "Multi-Period-Daily", @@ -145,6 +152,15 @@ "retryWaitTime": 10000, "sleepWaitTime": 3600000, "comaWaitTime": 86400000, + "framework": { + "name": "Multi-Period-Daily", + "startDate": { + "fixedDate": "2018-07-01" + }, + "endDate": { + "takeItFromStatusDependency": 1 + } + }, "statusDependencies": [ { "devTeam": "AAMasters", @@ -177,8 +193,6 @@ "dataSetVersion": "dataSet.V1" } ], - "statusDependenciesIndexBegingOfMarket": 0, - "statusDependenciesIndexEndOfMarket": 1, "dataDependencies": [ { "devTeam": "AAVikings", @@ -246,8 +260,7 @@ "dataSetVersion": "dataSet.V1", "dataSet": "Multi-Period-Market" } - ], - "framework": "Multi-Period-Daily" + ] } ], "products": [ @@ -288,7 +301,7 @@ } }, { - "codeName": "SimulationConditions", + "codeName": "Simulation-Conditions", "displayName": "Simulation Conditions", "description": "Simulation Conditions", "storageAccount": "aajason",