From e92f9cfeb951cf5c7bbfc31161601f835831bbab Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Mon, 25 Mar 2019 11:26:28 +0100 Subject: [PATCH 1/5] Update README.md --- README.md | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 1604ed841..26c9cd48e 100644 --- a/README.md +++ b/README.md @@ -1,10 +1,12 @@ -# AACloud +# Clone Executor -This repository holds the code of the bits of the AA Platform that run in the cloud. +Whithin the Superalgos project, we have the concept of Financial Beings, which are autonomous agents that have a financial life. These FBs entities have a master (imagine a class in programming) and clones (imagine an instance of a class running). The master is the one who aquires reputation after competitions. Every time we need to do a backtest, live trading or participating in a competition, a clone is extracted from the master and is put to run, either in backtest mode, live trading mode or competition mode. The clone lifespan is contrained by the purpose it was created. For instance, a clone created for a competition will live only during the period of such competition. -## About the AA Project +The software needed to execute these clones is the Clone Executor. -The AA Platform is built and maintained by Advanced Algos, the start up behind the AA Project. +## About the Superalgos Project + +Superalgos is built and maintained by the Superalgos Foundation and its Community. Our mission is to enable the fast-paced evolution of crypto trading bots within the context of trading bots competitions. From 66e4a286dfb6040cc206ef6c989bd3efac952f35 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Mon, 25 Mar 2019 12:17:32 +0100 Subject: [PATCH 2/5] Visual Studio Project Renamed --- AACloud.sln => CloneExecutor.sln | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename AACloud.sln => CloneExecutor.sln (100%) diff --git a/AACloud.sln b/CloneExecutor.sln similarity index 100% rename from AACloud.sln rename to CloneExecutor.sln From 50422852ae3f6736facab672682835b3b5e90463 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Mon, 25 Mar 2019 12:31:13 +0100 Subject: [PATCH 3/5] Cloud refactored to Node --- DebugLog.js | 2 +- Exchange/ExchangeAPI.js | 2 +- ExtractionBotProcessMainLoop.js | 8 ++++---- IndicatorBotProcessMainLoop.js | 8 ++++---- Root.js | 10 +++++----- Run.js | 2 +- TradingBotProcessMainLoop.js | 14 +++++++------- 7 files changed, 23 insertions(+), 23 deletions(-) diff --git a/DebugLog.js b/DebugLog.js index 70adf7be0..50b83f7f8 100644 --- a/DebugLog.js +++ b/DebugLog.js @@ -163,7 +163,7 @@ return; } - if (global.CURRENT_EXECUTION_AT === "Cloud") { + if (global.CURRENT_EXECUTION_AT === "Node") { /* Only ERRORs go to the cloud console. */ diff --git a/Exchange/ExchangeAPI.js b/Exchange/ExchangeAPI.js index 3129473d6..6e8f68098 100644 --- a/Exchange/ExchangeAPI.js +++ b/Exchange/ExchangeAPI.js @@ -38,7 +38,7 @@ let accessToken let keyId let cloneId - if (global.CURRENT_EXECUTION_AT === "Cloud") { + if (global.CURRENT_EXECUTION_AT === "Node") { keyId = process.env.KEY_ID cloneId = process.env.CLONE_ID diff --git a/ExtractionBotProcessMainLoop.js b/ExtractionBotProcessMainLoop.js index 81b4b90a5..b6dbe7ae5 100644 --- a/ExtractionBotProcessMainLoop.js +++ b/ExtractionBotProcessMainLoop.js @@ -49,7 +49,7 @@ let filePath; switch (global.CURRENT_EXECUTION_AT) { // This is what determines if the bot is loaded from the devTeam or an endUser copy. - case "Cloud": { + case "Node": { if (global.RUN_AS_TEAM) { filePath = global.DEV_TEAM + "/" + "bots" + "/" + bot.repo + "/" + pProcessConfig.name; // DevTeams bots only are run at the cloud. } else { @@ -85,7 +85,7 @@ USER_BOT_MODULE = pMODULE; switch (global.CURRENT_EXECUTION_AT) { - case "Cloud": { + case "Node": { filePath = global.DEV_TEAM + "/" + "bots" + "/" + bot.repo; break; } @@ -664,7 +664,7 @@ function checkLoopHealth(pLastLoop) { - if (global.CURRENT_EXECUTION_AT !== "Cloud") { + if (global.CURRENT_EXECUTION_AT !== "Node") { return; } @@ -717,7 +717,7 @@ let filePath; switch (global.CURRENT_EXECUTION_AT) { // This is what determines if the bot is loaded from the devTeam or an endUser copy. - case "Cloud": { + case "Node": { filePath = global.DEV_TEAM + "/" + "AACloud"; // DevTeams bots only are run at the cloud. break; } diff --git a/IndicatorBotProcessMainLoop.js b/IndicatorBotProcessMainLoop.js index 514f6d635..591aa6648 100644 --- a/IndicatorBotProcessMainLoop.js +++ b/IndicatorBotProcessMainLoop.js @@ -51,7 +51,7 @@ let filePath; switch (global.CURRENT_EXECUTION_AT) { // This is what determines if the bot is loaded from the devTeam or an endUser copy. - case "Cloud": { + case "Node": { if (global.RUN_AS_TEAM) { filePath = global.DEV_TEAM + "/" + "bots" + "/" + bot.repo + "/" + pProcessConfig.name; // DevTeams bots only are run at the cloud. } else { @@ -88,7 +88,7 @@ USER_BOT_MODULE = pMODULE; switch (global.CURRENT_EXECUTION_AT) { - case "Cloud": { + case "Node": { filePath = global.DEV_TEAM + "/" + "bots" + "/" + bot.repo; break; } @@ -898,7 +898,7 @@ function checkLoopHealth(pLastLoop) { - if (global.CURRENT_EXECUTION_AT !== "Cloud") { + if (global.CURRENT_EXECUTION_AT !== "Node") { return; } @@ -951,7 +951,7 @@ let filePath; switch (global.CURRENT_EXECUTION_AT) { // This is what determines if the bot is loaded from the devTeam or an endUser copy. - case "Cloud": { + case "Node": { filePath = global.DEV_TEAM + "/" + "AACloud"; // DevTeams bots only are run at the cloud. break; } diff --git a/Root.js b/Root.js index a12f148bb..1cf6532fa 100644 --- a/Root.js +++ b/Root.js @@ -140,7 +140,7 @@ let filePath; switch (global.CURRENT_EXECUTION_AT) { - case "Cloud": { + case "Node": { filePath = global.DEV_TEAM + "/" + "AACloud"; // DevTeams bots only are run at the cloud. break; } @@ -253,7 +253,7 @@ let filePath; switch (global.CURRENT_EXECUTION_AT) { - case "Cloud": { + case "Node": { filePath = global.DEV_TEAM + "/" + "bots" + "/" + listItem.repo; // DevTeams bots only are run at the cloud. console.log(logDisplace + "Root : [INFO] start -> getBotConfig -> Getting Bot Config from the devTeams's Bot. "); @@ -343,7 +343,7 @@ let processConfig = botConfig.processes[i]; switch (global.CURRENT_EXECUTION_AT) { - case "Cloud": { + case "Node": { processConfig.startMode = global.EXECUTION_CONFIG.startMode // Override file storage configuration if(global.EXECUTION_CONFIG.timePeriod){ processConfig.timePeriod = global.EXECUTION_CONFIG.timePeriod @@ -819,7 +819,7 @@ let clonName = botConfig.codeName + "-" + "Clon" + clonKey; clonName += ".1.0"; - if (global.CURRENT_EXECUTION_AT === "Cloud") { + if (global.CURRENT_EXECUTION_AT === "Node") { clonName += "-" + process.env.CLONE_ID; } @@ -843,7 +843,7 @@ let genes = {}; let clonName = botConfig.codeName; - if (global.CURRENT_EXECUTION_AT === "Cloud") { + if (global.CURRENT_EXECUTION_AT === "Node") { clonName += "-" + process.env.CLONE_ID; } diff --git a/Run.js b/Run.js index be015b060..926474a32 100644 --- a/Run.js +++ b/Run.js @@ -1,7 +1,7 @@ require('dotenv').config() global.CURRENT_ENVIRONMENT = "Develop"; -global.CURRENT_EXECUTION_AT = "Cloud"; +global.CURRENT_EXECUTION_AT = "Node"; global.SHALL_BOT_STOP = false; global.AT_BREAKPOINT = false; // This is used only when running at the browser. global.RUN_AS_TEAM = false; diff --git a/TradingBotProcessMainLoop.js b/TradingBotProcessMainLoop.js index 0f5185b48..4aceb006b 100644 --- a/TradingBotProcessMainLoop.js +++ b/TradingBotProcessMainLoop.js @@ -52,7 +52,7 @@ let filePath; switch (global.CURRENT_EXECUTION_AT) { // This is what determines if the bot is loaded from the devTeam or an endUser copy. - case "Cloud": { + case "Node": { if (global.RUN_AS_TEAM) { filePath = global.DEV_TEAM + "/" + "bots" + "/" + bot.repo + "/" + pProcessConfig.name; // DevTeams bots only are run at the cloud. } else { @@ -94,7 +94,7 @@ USER_BOT_MODULE = pMODULE; switch (global.CURRENT_EXECUTION_AT) { - case "Cloud": { + case "Node": { filePath = global.DEV_TEAM + "/" + "bots" + "/" + bot.repo; break; } @@ -284,7 +284,7 @@ } - if (global.CURRENT_EXECUTION_AT === "Cloud") { + if (global.CURRENT_EXECUTION_AT === "Node") { if (bot.processDatetime.valueOf() > endDatetime.valueOf()) { @@ -323,7 +323,7 @@ } - if (global.CURRENT_EXECUTION_AT === "Cloud") { + if (global.CURRENT_EXECUTION_AT === "Node") { let beginDatetime = new Date(bot.competition.beginDatetime); @@ -987,7 +987,7 @@ if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] run -> loop -> updateClonesModule -> Entering function."); } - if (global.CURRENT_EXECUTION_AT === "Cloud") { + if (global.CURRENT_EXECUTION_AT === "Node") { // Update clones module with latest context informations @@ -1079,7 +1079,7 @@ function checkLoopHealth(pLastLoop) { - if (global.CURRENT_EXECUTION_AT !== "Cloud") { + if (global.CURRENT_EXECUTION_AT !== "Node") { return; } @@ -1134,7 +1134,7 @@ let filePath; switch (global.CURRENT_EXECUTION_AT) { // This is what determines if the bot is loaded from the devTeam or an endUser copy. - case "Cloud": { + case "Node": { filePath = global.DEV_TEAM + "/" + "AACloud"; // DevTeams bots only are run at the cloud. break; } From 9a277ddd720cc2ac401bc18460ab162b9c3544a8 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Mon, 25 Mar 2019 14:34:35 +0100 Subject: [PATCH 4/5] Browser Execution type removed --- DebugLog.js | 19 +-------- Exchange/ExchangeAPI.js | 4 +- ExtractionBotProcessMainLoop.js | 73 ++++----------------------------- IndicatorBotProcessMainLoop.js | 70 ++++--------------------------- Root.js | 69 ++++--------------------------- TradingBotProcessMainLoop.js | 55 +++---------------------- 6 files changed, 33 insertions(+), 257 deletions(-) diff --git a/DebugLog.js b/DebugLog.js index 50b83f7f8..8f82f1c19 100644 --- a/DebugLog.js +++ b/DebugLog.js @@ -60,13 +60,6 @@ internalLoopCounter++; - if (global.CURRENT_EXECUTION_AT === "Browser") { - - //console.log("[INFO] DebugLog -> persist -> We do not persist logs while running at the Browser"); - return; - - } - let contentToPersist = accumulatedLog; accumulatedLog = "["; @@ -149,20 +142,12 @@ if (global.CURRENT_EXECUTION_AT === "IDE") { - console.log("AACloud" + spacePad(pModule, 50) + " : " + pMessage); + console.log("CloneExecutor" + spacePad(pModule, 50) + " : " + pMessage); } if (disableLogging === true) { return; } - if (global.CURRENT_EXECUTION_AT === "Browser") { - - /* Only at the browser we send the messages to the console. At the Cloud it does not make sense. */ - - console.log("AACloud" + spacePad(pModule, 50) + " : " + pMessage); - return; - } - if (global.CURRENT_EXECUTION_AT === "Node") { /* Only ERRORs go to the cloud console. */ @@ -170,7 +155,7 @@ if (pMessage.indexOf("[ERROR]") >= 0) { let now = new Date; - console.log("Loop." + pad(thisObject.bot.loopCounter, 8) + " " + now.toUTCString() + " AACloud " + spacePad(pModule, 20) + " : " + pMessage); + console.log("Loop." + pad(thisObject.bot.loopCounter, 8) + " " + now.toUTCString() + " CloneExecutor " + spacePad(pModule, 20) + " : " + pMessage); } } diff --git a/Exchange/ExchangeAPI.js b/Exchange/ExchangeAPI.js index 6e8f68098..1f29542b4 100644 --- a/Exchange/ExchangeAPI.js +++ b/Exchange/ExchangeAPI.js @@ -45,9 +45,7 @@ let auth = require('../utils/auth') let authTokenCloud = await auth.authenticate() accessToken = 'Bearer ' + authTokenCloud - } else if (global.CURRENT_EXECUTION_AT === "Browser") { - accessToken = 'Bearer ' + authToken - } + } let keyVaultAPI = createKeyVaultAPIClient(accessToken, keyId, cloneId) apiClient = api.newAPIClient(keyVaultAPI, logger); diff --git a/ExtractionBotProcessMainLoop.js b/ExtractionBotProcessMainLoop.js index b6dbe7ae5..8d1b4209c 100644 --- a/ExtractionBotProcessMainLoop.js +++ b/ExtractionBotProcessMainLoop.js @@ -47,25 +47,11 @@ if (err.result === global.DEFAULT_OK_RESPONSE.result) { let filePath; - - switch (global.CURRENT_EXECUTION_AT) { // This is what determines if the bot is loaded from the devTeam or an endUser copy. - case "Node": { - if (global.RUN_AS_TEAM) { - filePath = global.DEV_TEAM + "/" + "bots" + "/" + bot.repo + "/" + pProcessConfig.name; // DevTeams bots only are run at the cloud. - } else { - filePath = global.DEV_TEAM + "/" + "members" + "/" + global.USER_LOGGED_IN + "/" + global.CURRENT_BOT_REPO + "/" + pProcessConfig.name; // DevTeam Members bots only are run at the browser. - } - break; - } - case "Browser": { - filePath = global.DEV_TEAM + "/" + "members" + "/" + global.USER_LOGGED_IN + "/" + global.CURRENT_BOT_REPO + "/" + pProcessConfig.name; // DevTeam Members bots only are run at the browser. - break; - } - default: { - parentLogger.write(MODULE_NAME, "[ERROR] initialize -> onInizialized -> CURRENT_EXECUTION_AT must be either 'Cloud' or 'Browser'."); - parentLogger.write(MODULE_NAME, "[ERROR] initialize -> onInizialized -> global.CURRENT_EXECUTION_AT = " + global.CURRENT_EXECUTION_AT); - callBackFunction(global.DEFAULT_FAIL_RESPONSE); - return; } + + if (global.RUN_AS_TEAM) { + filePath = global.DEV_TEAM + "/" + "bots" + "/" + bot.repo + "/" + pProcessConfig.name; // DevTeams bots only are run at the cloud. + } else { + filePath = global.DEV_TEAM + "/" + "members" + "/" + global.USER_LOGGED_IN + "/" + global.CURRENT_BOT_REPO + "/" + pProcessConfig.name; // DevTeam Members bots only are run at the browser. } const CLOUD_REQUIRE = require(ROOT_DIR + 'CloudRequire'); @@ -84,23 +70,8 @@ USER_BOT_MODULE = pMODULE; - switch (global.CURRENT_EXECUTION_AT) { - case "Node": { - filePath = global.DEV_TEAM + "/" + "bots" + "/" + bot.repo; - break; - } - case "Browser": { - filePath = global.DEV_TEAM + "/" + "members" + "/" + global.USER_LOGGED_IN + "/" + global.CURRENT_BOT_REPO; - break; - } - default: { - parentLogger.write(MODULE_NAME, "[ERROR] initialize -> onInizialized -> onBotDownloaded -> CURRENT_EXECUTION_AT must be either 'Cloud' or 'Browser'."); - parentLogger.write(MODULE_NAME, "[ERROR] initialize -> onInizialized -> onBotDownloaded -> global.CURRENT_EXECUTION_AT = " + global.CURRENT_EXECUTION_AT); - callBackFunction(global.DEFAULT_FAIL_RESPONSE); - return; - } - } - + filePath = global.DEV_TEAM + "/" + "bots" + "/" + bot.repo; + cloudRequire.downloadCommons(cloudStorage, filePath, onCommonsDownloaded); function onCommonsDownloaded(err, pMODULE) { @@ -714,34 +685,8 @@ if (err.result === global.DEFAULT_OK_RESPONSE.result) { - let filePath; - - switch (global.CURRENT_EXECUTION_AT) { // This is what determines if the bot is loaded from the devTeam or an endUser copy. - case "Node": { - filePath = global.DEV_TEAM + "/" + "AACloud"; // DevTeams bots only are run at the cloud. - break; - } - case "Browser": { - if (global.SHALL_BOT_STOP === false) { - continueCallBack(); - } else { - stopCallBack(); - } - return; - } - default: { - logger.write(MODULE_NAME, "[ERROR] run -> loop -> shallWeStop -> onInizialized -> CURRENT_EXECUTION_AT must be either 'Cloud' or 'Browser'."); - logger.write(MODULE_NAME, "[ERROR] run -> loop -> shallWeStop -> onInizialized -> global.CURRENT_EXECUTION_AT = " + global.CURRENT_EXECUTION_AT); - logger.persist(); - clearInterval(fixedTimeLoopIntervalHandle); - clearTimeout(nextLoopTimeoutHandle); - clearTimeout(checkLoopHealthHandle); - bot.enableCheckLoopHealth = false; - callBackFunction(global.DEFAULT_FAIL_RESPONSE); - return; - } - } - + let filePath = global.DEV_TEAM + "/" + "AACloud"; // DevTeams bots only are run at the cloud. + let fileName = "this.config.json"; cloudStorage.getTextFile(filePath, fileName, onFileReceived); diff --git a/IndicatorBotProcessMainLoop.js b/IndicatorBotProcessMainLoop.js index 591aa6648..6de54adc5 100644 --- a/IndicatorBotProcessMainLoop.js +++ b/IndicatorBotProcessMainLoop.js @@ -50,25 +50,10 @@ let filePath; - switch (global.CURRENT_EXECUTION_AT) { // This is what determines if the bot is loaded from the devTeam or an endUser copy. - case "Node": { - if (global.RUN_AS_TEAM) { - filePath = global.DEV_TEAM + "/" + "bots" + "/" + bot.repo + "/" + pProcessConfig.name; // DevTeams bots only are run at the cloud. - } else { - filePath = global.DEV_TEAM + "/" + "members" + "/" + global.USER_LOGGED_IN + "/" + global.CURRENT_BOT_REPO + "/" + pProcessConfig.name; // DevTeam Members bots only are run at the browser. - } - break; - } - case "Browser": { - filePath = global.DEV_TEAM + "/" + "members" + "/" + global.USER_LOGGED_IN + "/" + global.CURRENT_BOT_REPO + "/" + pProcessConfig.name; // DevTeam Members bots only are run at the browser. - break; - } - default: { - parentLogger.write(MODULE_NAME, "[ERROR] initialize -> onInizialized -> CURRENT_EXECUTION_AT must be either 'Cloud' or 'Browser'."); - parentLogger.write(MODULE_NAME, "[ERROR] initialize -> onInizialized -> global.CURRENT_EXECUTION_AT = " + global.CURRENT_EXECUTION_AT); - callBackFunction(global.DEFAULT_FAIL_RESPONSE); - return; - } + if (global.RUN_AS_TEAM) { + filePath = global.DEV_TEAM + "/" + "bots" + "/" + bot.repo + "/" + pProcessConfig.name; // DevTeams bots only are run at the cloud. + } else { + filePath = global.DEV_TEAM + "/" + "members" + "/" + global.USER_LOGGED_IN + "/" + global.CURRENT_BOT_REPO + "/" + pProcessConfig.name; // DevTeam Members bots only are run at the browser. } const CLOUD_REQUIRE = require(ROOT_DIR + 'CloudRequire'); @@ -87,22 +72,7 @@ USER_BOT_MODULE = pMODULE; - switch (global.CURRENT_EXECUTION_AT) { - case "Node": { - filePath = global.DEV_TEAM + "/" + "bots" + "/" + bot.repo; - break; - } - case "Browser": { - filePath = global.DEV_TEAM + "/" + "members" + "/" + global.USER_LOGGED_IN + "/" + global.CURRENT_BOT_REPO; - break; - } - default: { - parentLogger.write(MODULE_NAME, "[ERROR] initialize -> onInizialized -> onBotDownloaded -> CURRENT_EXECUTION_AT must be either 'Cloud' or 'Browser'."); - parentLogger.write(MODULE_NAME, "[ERROR] initialize -> onInizialized -> onBotDownloaded -> global.CURRENT_EXECUTION_AT = " + global.CURRENT_EXECUTION_AT); - callBackFunction(global.DEFAULT_FAIL_RESPONSE); - return; - } - } + filePath = global.DEV_TEAM + "/" + "bots" + "/" + bot.repo; cloudRequire.downloadCommons(cloudStorage, filePath, onCommonsDownloaded); @@ -948,34 +918,8 @@ if (err.result === global.DEFAULT_OK_RESPONSE.result) { - let filePath; - - switch (global.CURRENT_EXECUTION_AT) { // This is what determines if the bot is loaded from the devTeam or an endUser copy. - case "Node": { - filePath = global.DEV_TEAM + "/" + "AACloud"; // DevTeams bots only are run at the cloud. - break; - } - case "Browser": { - if (global.SHALL_BOT_STOP === false) { - continueCallBack(); - } else { - stopCallBack(); - } - return; - } - default: { - logger.write(MODULE_NAME, "[ERROR] run -> loop -> shallWeStop -> onInizialized -> CURRENT_EXECUTION_AT must be either 'Cloud' or 'Browser'."); - logger.write(MODULE_NAME, "[ERROR] run -> loop -> shallWeStop -> onInizialized -> global.CURRENT_EXECUTION_AT = " + global.CURRENT_EXECUTION_AT); - logger.persist(); - clearInterval(fixedTimeLoopIntervalHandle); - clearTimeout(nextLoopTimeoutHandle); - clearTimeout(checkLoopHealthHandle); - bot.enableCheckLoopHealth = false; - callBackFunction(global.DEFAULT_FAIL_RESPONSE); - return; - } - } - + let filePath = global.DEV_TEAM + "/" + "AACloud"; // DevTeams bots only are run at the cloud. + let fileName = "this.config.json"; cloudStorage.getTextFile(filePath, fileName, onFileReceived); diff --git a/Root.js b/Root.js index 1cf6532fa..240117a74 100644 --- a/Root.js +++ b/Root.js @@ -74,7 +74,7 @@ let cloudStorage; - let logDisplace = "AACloud" + " "; + let logDisplace = "CloneExecutor" + " "; let UI_COMMANDS; return thisObject; @@ -137,21 +137,7 @@ if (err.result === global.DEFAULT_OK_RESPONSE.result) { - let filePath; - - switch (global.CURRENT_EXECUTION_AT) { - case "Node": { - filePath = global.DEV_TEAM + "/" + "AACloud"; // DevTeams bots only are run at the cloud. - break; - } - case "Browser": { - filePath = global.DEV_TEAM + "/" + "members" + "/" + global.USER_LOGGED_IN + "/" + "AACloud"; // DevTeam Members bots only are run at the browser. - break; - } - default: { - console.log(logDisplace + "Root : [ERROR] start -> getBotConfig -> onInizialized -> CURRENT_EXECUTION_AT must be either 'Cloud' or 'Browser' "); - } - } + let filePath = global.DEV_TEAM + "/" + "CloneExecutor"; // DevTeams bots only are run at the cloud. let fileName = "this.config.json"; @@ -230,7 +216,7 @@ continue; } - /* Now we will read the config of the bot from the path we obtained at the AACloud config. */ + /* Now we will read the config of the bot from the path we obtained at the CloneExecutor config. */ let botConfig; @@ -250,28 +236,7 @@ if (err.result === global.DEFAULT_OK_RESPONSE.result) { - let filePath; - - switch (global.CURRENT_EXECUTION_AT) { - case "Node": { - filePath = global.DEV_TEAM + "/" + "bots" + "/" + listItem.repo; // DevTeams bots only are run at the cloud. - - console.log(logDisplace + "Root : [INFO] start -> getBotConfig -> Getting Bot Config from the devTeams's Bot. "); - console.log(logDisplace + "Root : [INFO] start -> getBotConfig -> filePath = " + filePath); - break; - } - case "Browser": { - filePath = global.DEV_TEAM + "/" + "members" + "/" + global.USER_LOGGED_IN + "/" + global.CURRENT_BOT_REPO; // DevTeam Members bots only are run at the browser. - - console.log(logDisplace + "Root : [INFO] start -> getBotConfig -> Getting Bot Config from the endUser's Bot. "); - console.log(logDisplace + "Root : [INFO] start -> getBotConfig -> global.USER_LOGGED_IN = " + global.USER_LOGGED_IN); - console.log(logDisplace + "Root : [INFO] start -> getBotConfig -> filePath = " + filePath); - break; - } - default: { - console.log(logDisplace + "Root : [ERROR] start -> getBotConfig -> onInizialized -> CURRENT_EXECUTION_AT must be either 'Cloud' or 'Browser' "); - } - } + let filePath = global.DEV_TEAM + "/" + "bots" + "/" + listItem.repo; // DevTeams bots only are run at the cloud. let fileName = "this.bot.config.json"; @@ -342,27 +307,11 @@ let processConfig = botConfig.processes[i]; - switch (global.CURRENT_EXECUTION_AT) { - case "Node": { - processConfig.startMode = global.EXECUTION_CONFIG.startMode // Override file storage configuration - if(global.EXECUTION_CONFIG.timePeriod){ - processConfig.timePeriod = global.EXECUTION_CONFIG.timePeriod - } - break; - } - case "Browser": { - let startMode = { - live: { run: "false" }, - backtest: { run: "false", waitTime: 5000 }, - competition: { run: "false" } - } - let browserStartMode = global.CURRENT_START_MODE.toLowerCase() - startMode[browserStartMode].run = "true" - - processConfig.startMode = startMode - break; - } + processConfig.startMode = global.EXECUTION_CONFIG.startMode // Override file storage configuration + if(global.EXECUTION_CONFIG.timePeriod){ + processConfig.timePeriod = global.EXECUTION_CONFIG.timePeriod } + try { /* We test each type of start Mode to get what to run and how. */ @@ -593,7 +542,7 @@ if (processFound === false) { - console.log(logDisplace + "Root : [ERROR] start -> findProcess -> Process listed at the configuration file of AACloud not found at the configuration file of the bot."); + console.log(logDisplace + "Root : [ERROR] start -> findProcess -> Process listed at the configuration file of CloneExecutor not found at the configuration file of the bot."); console.log(logDisplace + "Root : [ERROR] start -> findProcess -> listItem.process = " + listItem.process); } diff --git a/TradingBotProcessMainLoop.js b/TradingBotProcessMainLoop.js index 4aceb006b..14ad87b49 100644 --- a/TradingBotProcessMainLoop.js +++ b/TradingBotProcessMainLoop.js @@ -61,16 +61,12 @@ break; } - case "Browser": { - filePath = global.DEV_TEAM + "/" + "members" + "/" + global.USER_LOGGED_IN + "/" + global.CURRENT_BOT_REPO + "/" + pProcessConfig.name; // DevTeam Members bots only are run at the browser. - break; - } case "IDE": { filePath = global.DEV_TEAM + "/" + "bots" + "/" + bot.repo + "/" + pProcessConfig.name; // This works like Cloud except of a few things. break; } default: { - parentLogger.write(MODULE_NAME, "[ERROR] initialize -> onInizialized -> CURRENT_EXECUTION_AT must be either 'Cloud' or 'Browser'."); + parentLogger.write(MODULE_NAME, "[ERROR] initialize -> onInizialized -> CURRENT_EXECUTION_AT must be either 'Node' or 'IDE'."); parentLogger.write(MODULE_NAME, "[ERROR] initialize -> onInizialized -> global.CURRENT_EXECUTION_AT = " + global.CURRENT_EXECUTION_AT); callBackFunction(global.DEFAULT_FAIL_RESPONSE); return; @@ -93,23 +89,8 @@ USER_BOT_MODULE = pMODULE; - switch (global.CURRENT_EXECUTION_AT) { - case "Node": { - filePath = global.DEV_TEAM + "/" + "bots" + "/" + bot.repo; - break; - } - case "Browser": { - filePath = global.DEV_TEAM + "/" + "members" + "/" + global.USER_LOGGED_IN + "/" + global.CURRENT_BOT_REPO; - break; - } - default: { - parentLogger.write(MODULE_NAME, "[ERROR] initialize -> onInizialized -> onBotDownloaded -> CURRENT_EXECUTION_AT must be either 'Cloud' or 'Browser'."); - parentLogger.write(MODULE_NAME, "[ERROR] initialize -> onInizialized -> onBotDownloaded -> global.CURRENT_EXECUTION_AT = " + global.CURRENT_EXECUTION_AT); - callBackFunction(global.DEFAULT_FAIL_RESPONSE); - return; - } - } - + filePath = global.DEV_TEAM + "/" + "bots" + "/" + bot.repo; + cloudRequire.downloadCommons(cloudStorage, filePath, onCommonsDownloaded); function onCommonsDownloaded(err, pMODULE) { @@ -1131,34 +1112,8 @@ if (err.result === global.DEFAULT_OK_RESPONSE.result) { - let filePath; - - switch (global.CURRENT_EXECUTION_AT) { // This is what determines if the bot is loaded from the devTeam or an endUser copy. - case "Node": { - filePath = global.DEV_TEAM + "/" + "AACloud"; // DevTeams bots only are run at the cloud. - break; - } - case "Browser": { - if (global.SHALL_BOT_STOP === false) { - continueCallBack(); - } else { - stopCallBack(); - } - return; - } - default: { - logger.write(MODULE_NAME, "[ERROR] run -> loop -> shallWeStop -> onInizialized -> CURRENT_EXECUTION_AT must be either 'Cloud' or 'Browser'."); - logger.write(MODULE_NAME, "[ERROR] run -> loop -> shallWeStop -> onInizialized -> global.CURRENT_EXECUTION_AT = " + global.CURRENT_EXECUTION_AT); - logger.persist(); - clearInterval(fixedTimeLoopIntervalHandle); - clearTimeout(nextLoopTimeoutHandle); - clearTimeout(checkLoopHealthHandle); - bot.enableCheckLoopHealth = false; - callBackFunction(global.DEFAULT_FAIL_RESPONSE); - return; - } - } - + let filePath = global.DEV_TEAM + "/" + "AACloud"; // DevTeams bots only are run at the cloud. + let fileName = "this.config.json"; cloudStorage.getTextFile(filePath, fileName, onFileReceived); From 0353bddef7176af96aa56b5835fc4ef9fd925a6f Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Mon, 25 Mar 2019 16:25:05 +0100 Subject: [PATCH 5/5] Eliminated the Execution List from the config and the code. Only one clone can be executed at the time now. --- Root.js | 1032 ++++++++++++++++++++++------------------------ Run.js | 6 +- this.config.json | 51 --- 3 files changed, 507 insertions(+), 582 deletions(-) diff --git a/Root.js b/Root.js index 240117a74..710a8ee01 100644 --- a/Root.js +++ b/Root.js @@ -137,7 +137,7 @@ if (err.result === global.DEFAULT_OK_RESPONSE.result) { - let filePath = global.DEV_TEAM + "/" + "CloneExecutor"; // DevTeams bots only are run at the cloud. + let filePath = global.DEV_TEAM + "/" + "AACloud"; // DevTeams bots only are run at the cloud. let fileName = "this.config.json"; @@ -192,224 +192,170 @@ /* Loop through all the processes configured to be run by this Node.js Instance. */ - for (let p = 0; p < global.PLATFORM_CONFIG.executionList.length; p++) { + let cloneToExecute = global.EXECUTION_CONFIG.cloneToExecute; - let listItem; + /* Now we will read the config of the bot from the path we obtained at the CloneExecutor config. */ - /* - The local configuration allows to select the configuration to run - locally, without overwriting the server config. - Here we check that the local configuration for the execution - exist, if it doesn't exist we will take the one on the server. - */ - if (global.EXECUTION_CONFIG === undefined) { - listItem = PLATFORM_CONFIG.executionList[p]; - } else { - listItem = global.EXECUTION_CONFIG.executionList[p]; - } + let botConfig; - if (listItem === undefined || listItem.enabled !== "true") { + getBotConfig(); - console.log(logDisplace + "Root : [INFO] start -> Skipping process for being disabled."); - console.log(logDisplace + "Root : [INFO] start -> listItem.process = " + PLATFORM_CONFIG.executionList[p].process); + function getBotConfig() { - continue; - } + try { + console.log(logDisplace + "Root : [INFO] start -> getBotConfig -> Entering function. "); - /* Now we will read the config of the bot from the path we obtained at the CloneExecutor config. */ + const BLOB_STORAGE = require(ROOT_DIR + 'BlobStorage'); + let cloudStorage = BLOB_STORAGE.newBlobStorage(cloneToExecute); - let botConfig; + cloudStorage.initialize("AAPlatform", onInizialized, true); - getBotConfig(); + function onInizialized(err) { - function getBotConfig() { + if (err.result === global.DEFAULT_OK_RESPONSE.result) { - try { - console.log(logDisplace + "Root : [INFO] start -> getBotConfig -> Entering function. "); + let filePath = global.DEV_TEAM + "/" + "bots" + "/" + cloneToExecute.repo; // DevTeams bots only are run at the cloud. - const BLOB_STORAGE = require(ROOT_DIR + 'BlobStorage'); - let cloudStorage = BLOB_STORAGE.newBlobStorage(listItem); + let fileName = "this.bot.config.json"; - cloudStorage.initialize("AAPlatform", onInizialized, true); + cloudStorage.getTextFile(filePath, fileName, onFileReceived); - function onInizialized(err) { + function onFileReceived(err, text) { - if (err.result === global.DEFAULT_OK_RESPONSE.result) { + if (err.result !== global.DEFAULT_OK_RESPONSE.result) { + console.log(logDisplace + "Root : [ERROR] start -> getBotConfig -> onInizialized -> onFileReceived -> err = " + err.message); + console.log(logDisplace + "Root : [ERROR] start -> getBotConfig -> onInizialized -> onFileReceived -> filePath = " + filePath); + console.log(logDisplace + "Root : [ERROR] start -> getBotConfig -> onInizialized -> onFileReceived -> fileName = " + fileName); - let filePath = global.DEV_TEAM + "/" + "bots" + "/" + listItem.repo; // DevTeams bots only are run at the cloud. - - let fileName = "this.bot.config.json"; - - cloudStorage.getTextFile(filePath, fileName, onFileReceived); - - function onFileReceived(err, text) { - - if (err.result !== global.DEFAULT_OK_RESPONSE.result) { - console.log(logDisplace + "Root : [ERROR] start -> getBotConfig -> onInizialized -> onFileReceived -> err = " + err.message); - console.log(logDisplace + "Root : [ERROR] start -> getBotConfig -> onInizialized -> onFileReceived -> filePath = " + filePath); - console.log(logDisplace + "Root : [ERROR] start -> getBotConfig -> onInizialized -> onFileReceived -> fileName = " + fileName); - - return; - } - - try { - botConfig = JSON.parse(text); - botConfig.repo = listItem.repo; - findProcess(); - } catch (err) { - console.log(logDisplace + "Root : [ERROR] start -> getBotConfig -> onInizialized -> onFileReceived -> err = " + err.message); - return; - } + return; } - } else { - console.log(logDisplace + "Root : [ERROR] start -> getBotConfig -> onInizialized -> err = " + err.message); - return; + try { + botConfig = JSON.parse(text); + botConfig.repo = cloneToExecute.repo; + findProcess(); + } catch (err) { + console.log(logDisplace + "Root : [ERROR] start -> getBotConfig -> onInizialized -> onFileReceived -> err = " + err.message); + return; + } } + + } else { + console.log(logDisplace + "Root : [ERROR] start -> getBotConfig -> onInizialized -> err = " + err.message); + return; } } - catch (err) { - console.log(logDisplace + "Root : [ERROR] start -> getBotConfig -> err.message = " + err.message); - return; - } } + catch (err) { + console.log(logDisplace + "Root : [ERROR] start -> getBotConfig -> err.message = " + err.message); + return; + } + } - function findProcess() { + function findProcess() { - try { - if (FULL_LOG === true) { console.log(logDisplace + "Root : [INFO] start -> findProcess -> Entering function. "); } + try { + if (FULL_LOG === true) { console.log(logDisplace + "Root : [INFO] start -> findProcess -> Entering function. "); } - botConfig.process = listItem.process; - botConfig.debug = {}; + botConfig.process = cloneToExecute.process; + botConfig.debug = {}; - /* Loop Counter */ + /* Loop Counter */ - botConfig.loopCounter = 0; + botConfig.loopCounter = 0; - if (FULL_LOG === true) { console.log(logDisplace + "Root : [INFO] start -> findProcess -> Processing item from executionList -> p = " + p); } + /* File Path Root */ - /* File Path Root */ + botConfig.filePathRoot = botConfig.devTeam + "/" + botConfig.codeName + "." + botConfig.version.major + "." + botConfig.version.minor + "/" + global.PLATFORM_CONFIG.codeName + "." + global.PLATFORM_CONFIG.version.major + "." + global.PLATFORM_CONFIG.version.minor + "/" + global.EXCHANGE_NAME + "/" + botConfig.dataSetVersion; - botConfig.filePathRoot = botConfig.devTeam + "/" + botConfig.codeName + "." + botConfig.version.major + "." + botConfig.version.minor + "/" + global.PLATFORM_CONFIG.codeName + "." + global.PLATFORM_CONFIG.version.major + "." + global.PLATFORM_CONFIG.version.minor + "/" + global.EXCHANGE_NAME + "/" + botConfig.dataSetVersion; + if (FULL_LOG === true) { console.log(logDisplace + "Root : [INFO] start -> findProcess -> cloneToExecute.process = " + cloneToExecute.process); } - if (FULL_LOG === true) { console.log(logDisplace + "Root : [INFO] start -> findProcess -> listItem.process = " + listItem.process); } + /* Now we loop throug all the configured processes at each bots configuration until we find the one we are supposed to run at this Node.js process. */ - /* Now we loop throug all the configured processes at each bots configuration until we find the one we are supposed to run at this Node.js process. */ + let processFound = false; - let processFound = false; + for (let i = 0; i < botConfig.processes.length; i++) { - for (let i = 0; i < botConfig.processes.length; i++) { + if (botConfig.processes[i].name === cloneToExecute.process) { - if (botConfig.processes[i].name === listItem.process) { + processFound = true; + if (FULL_LOG === true) { console.log(logDisplace + "Root : [INFO] start -> findProcess -> Process found at the bot configuration file. -> cloneToExecute.process = " + cloneToExecute.process); } - processFound = true; - if (FULL_LOG === true) { console.log(logDisplace + "Root : [INFO] start -> findProcess -> Process found at the bot configuration file. -> listItem.process = " + listItem.process); } + let processConfig = botConfig.processes[i]; - let processConfig = botConfig.processes[i]; - - processConfig.startMode = global.EXECUTION_CONFIG.startMode // Override file storage configuration - if(global.EXECUTION_CONFIG.timePeriod){ - processConfig.timePeriod = global.EXECUTION_CONFIG.timePeriod - } + processConfig.startMode = global.EXECUTION_CONFIG.startMode // Override file storage configuration + if(global.EXECUTION_CONFIG.timePeriod){ + processConfig.timePeriod = global.EXECUTION_CONFIG.timePeriod + } - try { + try { - /* We test each type of start Mode to get what to run and how. */ + /* We test each type of start Mode to get what to run and how. */ - if (processConfig.startMode.allMonths !== undefined) { + if (processConfig.startMode.allMonths !== undefined) { - if (processConfig.startMode.allMonths.run === "true") { + if (processConfig.startMode.allMonths.run === "true") { - if (FULL_LOG === true) { console.log(logDisplace + "Root : [INFO] start -> findProcess -> allMonths start mode detected. "); } + if (FULL_LOG === true) { console.log(logDisplace + "Root : [INFO] start -> findProcess -> allMonths start mode detected. "); } - for (let year = processConfig.startMode.allMonths.maxYear; year >= processConfig.startMode.allMonths.minYear; year--) { + for (let year = processConfig.startMode.allMonths.maxYear; year >= processConfig.startMode.allMonths.minYear; year--) { - for (let month = 12; month > 0; month--) { + for (let month = 12; month > 0; month--) { - let padMonth = pad(month, 2) + let padMonth = pad(month, 2) - let newInstanceBotConfig = JSON.parse(JSON.stringify(botConfig)); + let newInstanceBotConfig = JSON.parse(JSON.stringify(botConfig)); - newInstanceBotConfig.debug = { - month: pad(month, 2), - year: pad(year, 4) - }; + newInstanceBotConfig.debug = { + month: pad(month, 2), + year: pad(year, 4) + }; - let timeDelay = Math.random() * 10 * 1000; // We introduce a short delay so as to not overload the machine. - setTimeout(startProcess, timeDelay); + let timeDelay = Math.random() * 10 * 1000; // We introduce a short delay so as to not overload the machine. + setTimeout(startProcess, timeDelay); - function startProcess() { + function startProcess() { - if (FULL_LOG === true) { console.log(logDisplace + "Root : [INFO] start -> findProcess -> startProcess -> Ready to start process."); } + if (FULL_LOG === true) { console.log(logDisplace + "Root : [INFO] start -> findProcess -> startProcess -> Ready to start process."); } - switch (botConfig.type) { - case 'Extraction': { - runExtractionBot(newInstanceBotConfig, processConfig, padMonth, year); - break; - } - case 'Indicator': { - runIndicatorBot(newInstanceBotConfig, processConfig, padMonth, year); - break; - } - default: { - console.log(logDisplace + "Root : [ERROR] start -> findProcess -> startProcess -> Unexpected bot type. -> botConfig.type = " + botConfig.type); - } + switch (botConfig.type) { + case 'Extraction': { + runExtractionBot(newInstanceBotConfig, processConfig, padMonth, year); + break; + } + case 'Indicator': { + runIndicatorBot(newInstanceBotConfig, processConfig, padMonth, year); + break; + } + default: { + console.log(logDisplace + "Root : [ERROR] start -> findProcess -> startProcess -> Unexpected bot type. -> botConfig.type = " + botConfig.type); } } } } } } + } - if (processConfig.startMode.oneMonth !== undefined) { + if (processConfig.startMode.oneMonth !== undefined) { - if (processConfig.startMode.oneMonth.run === "true") { + if (processConfig.startMode.oneMonth.run === "true") { - if (FULL_LOG === true) { console.log(logDisplace + "Root : [INFO] start -> findProcess -> oneMonth start mode detected. "); } + if (FULL_LOG === true) { console.log(logDisplace + "Root : [INFO] start -> findProcess -> oneMonth start mode detected. "); } - startProcess(); + startProcess(); - function startProcess() { + function startProcess() { - if (FULL_LOG === true) { console.log(logDisplace + "Root : [INFO] start -> findProcess -> startProcess -> Ready to start process."); } + if (FULL_LOG === true) { console.log(logDisplace + "Root : [INFO] start -> findProcess -> startProcess -> Ready to start process."); } - let month = pad(processConfig.startMode.oneMonth.month, 2); - let year = processConfig.startMode.oneMonth.year; + let month = pad(processConfig.startMode.oneMonth.month, 2); + let year = processConfig.startMode.oneMonth.year; - botConfig.debug = { - month: pad(month, 2), - year: pad(year, 4) - }; - - switch (botConfig.type) { - case 'Extraction': { - runExtractionBot(botConfig, processConfig, month, year); - break; - } - case 'Indicator': { - runIndicatorBot(botConfig, processConfig, month, year); - break; - } - default: { - console.log(logDisplace + "Root : [ERROR] start -> findProcess -> startProcess -> Unexpected bot type. -> botConfig.type = " + botConfig.type); - } - } - } - } - } - - if (processConfig.startMode.noTime !== undefined) { - - if (processConfig.startMode.noTime.run === "true") { - - let month = pad((new Date()).getUTCMonth() + 1, 2); - let year = (new Date()).getUTCFullYear(); - - if (processConfig.startMode.noTime.resumeExecution === "true") { - botConfig.hasTheBotJustStarted = false; - } else { - botConfig.hasTheBotJustStarted = true; - } + botConfig.debug = { + month: pad(month, 2), + year: pad(year, 4) + }; switch (botConfig.type) { case 'Extraction': { @@ -421,464 +367,494 @@ break; } default: { - console.log(logDisplace + "Root : [ERROR] start -> findProcess -> Unexpected bot type. -> botConfig.type = " + botConfig.type); + console.log(logDisplace + "Root : [ERROR] start -> findProcess -> startProcess -> Unexpected bot type. -> botConfig.type = " + botConfig.type); } } } } + } - if (processConfig.startMode.fixedInterval !== undefined) { + if (processConfig.startMode.noTime !== undefined) { - if (processConfig.startMode.fixedInterval.run === "true") { + if (processConfig.startMode.noTime.run === "true") { - botConfig.runAtFixedInterval = true; - botConfig.fixedInterval = processConfig.startMode.fixedInterval.interval; - - let month = pad((new Date()).getUTCMonth() + 1, 2); - let year = (new Date()).getUTCFullYear(); - - switch (botConfig.type) { - case 'Extraction': { - runExtractionBot(botConfig, processConfig, month, year); - break; - } - default: { - console.log(logDisplace + "Root : [ERROR] start -> findProcess -> Unexpected bot type. -> botConfig.type = " + botConfig.type); - } - } - } - } - - if (processConfig.startMode.live !== undefined) { - - if (processConfig.startMode.live.run === "true") { - - botConfig.startMode = "Live"; - console.log(logDisplace + "Root : [INFO] start -> findProcess -> Process found at the bot configuration file. -> Start Mode = " + botConfig.startMode); - - let month = pad((new Date()).getUTCMonth() + 1, 2); - let year = (new Date()).getUTCFullYear(); - - if (processConfig.startMode.live.resumeExecution === "true") { - botConfig.hasTheBotJustStarted = false; - } else { - botConfig.hasTheBotJustStarted = true; - } - - switch (botConfig.type) { - case 'Trading': { - runTradingBot(botConfig, processConfig); - break; - } - default: { - console.log(logDisplace + "Root : [ERROR] start -> findProcess -> Unexpected bot type. -> botConfig.type = " + botConfig.type); - } - } - } - } - - if (processConfig.startMode.backtest !== undefined) { - - if (processConfig.startMode.backtest.run === "true") { - - botConfig.startMode = "Backtest"; - console.log(logDisplace + "Root : [INFO] start -> findProcess -> Process found at the bot configuration file. -> Start Mode = " + botConfig.startMode); - - botConfig.backtest = processConfig.startMode.backtest; - - /* We override these waitTimes to the one specified at the backtest configuration. */ - - processConfig.normalWaitTime = processConfig.startMode.backtest.waitTime; - processConfig.retryWaitTime = processConfig.startMode.backtest.waitTime; - - /* Backtest Mode does not support Resume Execution, so this is the only way. */ + let month = pad((new Date()).getUTCMonth() + 1, 2); + let year = (new Date()).getUTCFullYear(); + if (processConfig.startMode.noTime.resumeExecution === "true") { + botConfig.hasTheBotJustStarted = false; + } else { botConfig.hasTheBotJustStarted = true; - - switch (botConfig.type) { - case 'Trading': { - runTradingBot(botConfig, processConfig); - break; - } - default: { - console.log(logDisplace + "Root : [ERROR] start -> findProcess -> Unexpected bot type. -> botConfig.type = " + botConfig.type); - } - } - } - } - - if (processConfig.startMode.competition !== undefined) { - - if (processConfig.startMode.competition.run === "true") { - - botConfig.startMode = "Competition"; - console.log(logDisplace + "Root : [INFO] start -> findProcess -> Process found at the bot configuration file. -> Start Mode = " + botConfig.startMode); - - botConfig.competition = processConfig.startMode.competition; - - if (processConfig.startMode.competition.resumeExecution === "false") { - botConfig.hasTheBotJustStarted = true; - } else { - botConfig.hasTheBotJustStarted = false; - } - - switch (botConfig.type) { - case 'Trading': { - runTradingBot(botConfig, processConfig); - break; - } - default: { - console.log(logDisplace + "Root : [ERROR] start -> findProcess -> Unexpected bot type. -> botConfig.type = " + botConfig.type); - } - } - } - } - - } catch (err) { - console.log(logDisplace + "Root : [ERROR] start -> findProcess -> Unexpected exception. -> err.message = " + err.message); - } - } - } - - if (processFound === false) { - - console.log(logDisplace + "Root : [ERROR] start -> findProcess -> Process listed at the configuration file of CloneExecutor not found at the configuration file of the bot."); - console.log(logDisplace + "Root : [ERROR] start -> findProcess -> listItem.process = " + listItem.process); - - } - - function runExtractionBot(pBotConfig, pProcessConfig, pMonth, pYear) { - - try { - - const DEBUG_MODULE = require(ROOT_DIR + 'DebugLog'); - let logger; - - logger = DEBUG_MODULE.newDebugLog(); - logger.bot = pBotConfig; - - if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> findProcess -> runExtractionBot -> Entering function."); } - if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> findProcess -> runExtractionBot -> pMonth = " + pMonth); } - if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> findProcess -> runExtractionBot -> pYear = " + pYear); } - - let extractionBotMainLoop = EXTRACTION_BOT_MAIN_LOOP_MODULE.newExtractionBotProcessMainLoop(pBotConfig, logger); - extractionBotMainLoop.initialize(UI_COMMANDS, pProcessConfig, onInitializeReady); - - function onInitializeReady(err) { - - if (err.result === global.DEFAULT_OK_RESPONSE.result) { - - extractionBotMainLoop.run(pMonth, pYear, whenRunFinishes); - - function whenRunFinishes(err) { - - pBotConfig.loopCounter = 0; - - let botId; - if (pYear !== undefined) { - botId = pBotConfig.devTeam + "." + pBotConfig.codeName + "." + pBotConfig.process + "." + pYear + "." + pMonth; - } else { - botId = pBotConfig.devTeam + "." + pBotConfig.codeName + "." + pBotConfig.process; - } - - if (err.result === global.DEFAULT_OK_RESPONSE.result) { - - logger.write(MODULE_NAME, "[INFO] start -> findProcess -> runExtractionBot -> onInitializeReady -> whenStartFinishes -> Bot execution finished sucessfully."); - logger.write(MODULE_NAME, "[INFO] start -> findProcess -> runExtractionBot -> onInitializeReady -> whenStartFinishes -> Bot Id = " + botId); - - console.log(logDisplace + "Root : [INFO] start -> findProcess -> runExtractionBot -> onInitializeReady -> whenStartFinishes -> botId = " + botId); - console.log(logDisplace + "Root : [INFO] start -> findProcess -> runExtractionBot -> onInitializeReady -> whenStartFinishes -> Bot execution finished sucessfully."); - - logger.persist(); - - } else { - - logger.write(MODULE_NAME, "[ERROR] start -> findProcess -> runExtractionBot -> onInitializeReady -> whenStartFinishes -> err = " + err.message); - logger.write(MODULE_NAME, "[ERROR] start -> findProcess -> runExtractionBot -> onInitializeReady -> whenStartFinishes -> Execution will be stopped. "); - logger.write(MODULE_NAME, "[ERROR] start -> findProcess -> runExtractionBot -> onInitializeReady -> whenStartFinishes -> Bye."); - logger.write(MODULE_NAME, "[ERROR] start -> findProcess -> runExtractionBot -> onInitializeReady -> whenStartFinishes -> Bot Id = " + botId); - - console.log(logDisplace + "Root : [ERROR] start -> findProcess -> runExtractionBot -> onInitializeReady -> whenStartFinishes -> botId = " + botId); - console.log(logDisplace + "Root : [ERROR] start -> findProcess -> runExtractionBot -> onInitializeReady -> whenStartFinishes -> Bot execution was aborted."); - logger.persist(); - } } - } else { - logger.write(MODULE_NAME, "[ERROR] start -> findProcess -> runExtractionBot -> onInitializeReady -> err = " + err.message); - logger.write(MODULE_NAME, "[ERROR] start -> findProcess -> runExtractionBot -> onInitializeReady -> Bot will not be started. "); - console.log(logDisplace + "Root : [ERROR] start -> findProcess -> runExtractionBot -> onInitializeReady -> err = " + err.message); - - logger.persist(); + switch (botConfig.type) { + case 'Extraction': { + runExtractionBot(botConfig, processConfig, month, year); + break; + } + case 'Indicator': { + runIndicatorBot(botConfig, processConfig, month, year); + break; + } + default: { + console.log(logDisplace + "Root : [ERROR] start -> findProcess -> Unexpected bot type. -> botConfig.type = " + botConfig.type); + } + } } } - } - catch (err) { - console.log(logDisplace + "Root : [ERROR] start -> findProcess -> runExtractionBot -> err = " + err.message); - } - } - function runIndicatorBot(pBotConfig, pProcessConfig, pMonth, pYear) { + if (processConfig.startMode.fixedInterval !== undefined) { - try { - const DEBUG_MODULE = require(ROOT_DIR + 'DebugLog'); - let logger; + if (processConfig.startMode.fixedInterval.run === "true") { - logger = DEBUG_MODULE.newDebugLog(); - logger.bot = pBotConfig; + botConfig.runAtFixedInterval = true; + botConfig.fixedInterval = processConfig.startMode.fixedInterval.interval; - if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> findProcess -> runIndicatorBot -> Entering function."); } - if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> findProcess -> runIndicatorBot -> pMonth = " + pMonth); } - if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> findProcess -> runIndicatorBot -> pYear = " + pYear); } + let month = pad((new Date()).getUTCMonth() + 1, 2); + let year = (new Date()).getUTCFullYear(); - let indicatorBotMainLoop = INDICATOR_BOT_MAIN_LOOP_MODULE.newIndicatorBotProcessMainLoop(pBotConfig, logger); - indicatorBotMainLoop.initialize(UI_COMMANDS, pProcessConfig, onInitializeReady); - - function onInitializeReady(err) { - - if (err.result === global.DEFAULT_OK_RESPONSE.result) { - - indicatorBotMainLoop.run(pMonth, pYear, whenRunFinishes); - - function whenRunFinishes(err) { - - pBotConfig.loopCounter = 0; - - let botId; - if (pYear !== undefined) { - botId = pBotConfig.devTeam + "." + pBotConfig.codeName + "." + pBotConfig.process + "." + pYear + "." + pMonth; - } else { - botId = pBotConfig.devTeam + "." + pBotConfig.codeName + "." + pBotConfig.process; + switch (botConfig.type) { + case 'Extraction': { + runExtractionBot(botConfig, processConfig, month, year); + break; } - - if (err.result === global.DEFAULT_OK_RESPONSE.result) { - - logger.write(MODULE_NAME, "[INFO] start -> findProcess -> runIndicatorBot -> onInitializeReady -> whenStartFinishes -> Bot execution finished sucessfully."); - logger.write(MODULE_NAME, "[INFO] start -> findProcess -> runIndicatorBot -> onInitializeReady -> whenStartFinishes -> Bot Id = " + botId); - - console.log(logDisplace + "Root : [INFO] start -> findProcess -> runIndicatorBot -> onInitializeReady -> whenStartFinishes -> botId = " + botId); - console.log(logDisplace + "Root : [INFO] start -> findProcess -> runIndicatorBot -> onInitializeReady -> whenStartFinishes -> Bot execution finished sucessfully."); - - logger.persist(); - - } else { - - logger.write(MODULE_NAME, "[ERROR] start -> findProcess -> runIndicatorBot -> onInitializeReady -> whenStartFinishes -> err = " + err.message); - logger.write(MODULE_NAME, "[ERROR] start -> findProcess -> runIndicatorBot -> onInitializeReady -> whenStartFinishes -> Execution will be stopped. "); - logger.write(MODULE_NAME, "[ERROR] start -> findProcess -> runIndicatorBot -> onInitializeReady -> whenStartFinishes -> Bye."); - logger.write(MODULE_NAME, "[ERROR] start -> findProcess -> runIndicatorBot -> onInitializeReady -> whenStartFinishes -> Bot Id = " + botId); - console.log(logDisplace + "Root : [ERROR] start -> findProcess -> runIndicatorBot -> onInitializeReady -> whenStartFinishes -> Bot execution finished with errors. Please check the logs."); - logger.persist(); + default: { + console.log(logDisplace + "Root : [ERROR] start -> findProcess -> Unexpected bot type. -> botConfig.type = " + botConfig.type); } } - - } else { - logger.write(MODULE_NAME, "[ERROR] start -> findProcess -> runIndicatorBot -> onInitializeReady -> err = " + err.message); - logger.write(MODULE_NAME, "[ERROR] start -> findProcess -> runIndicatorBot -> onInitializeReady -> Failed to initialize the bot. "); - console.log(logDisplace + "Root : [ERROR] start -> findProcess -> runIndicatorBot -> onInitializeReady -> err = " + err.message); - logger.persist(); - throw new Error("Root -> start -> findProcess -> runIndicatorBot -> onInitializeReady -> Failed to initialize the bot.") } } - } - catch (err) { - console.log(logDisplace + "Root : [ERROR] start -> findProcess -> runIndicatorBot -> err = " + err.message); - } - } + if (processConfig.startMode.live !== undefined) { - function runTradingBot(pBotConfig, pProcessConfig) { + if (processConfig.startMode.live.run === "true") { - try { + botConfig.startMode = "Live"; + console.log(logDisplace + "Root : [INFO] start -> findProcess -> Process found at the bot configuration file. -> Start Mode = " + botConfig.startMode); - if (FULL_LOG === true) { console.log(logDisplace + "[INFO] start -> findProcess -> runTradingBot -> Entering function."); } - - if (pBotConfig.genes !== undefined) { - - /* Here, based on the gene we will create one instance for each combination of genes */ - - let valueMatrix = []; - - for (let i = 0; i < pBotConfig.genes.length; i++) { - - let gene = pBotConfig.genes[i]; - - let possibleValues = []; - - for (let j = gene.lowerLimit; j <= gene.upperLimit; j++) { - - possibleValues.push(j); + let month = pad((new Date()).getUTCMonth() + 1, 2); + let year = (new Date()).getUTCFullYear(); + if (processConfig.startMode.live.resumeExecution === "true") { + botConfig.hasTheBotJustStarted = false; + } else { + botConfig.hasTheBotJustStarted = true; } - valueMatrix.push(possibleValues); - - } - - /* - Now we have all the possible genes values in a multi-dimensional matrix. - We will go thorugh each of the elements of each dimension and get each combination possible with the other dimmensions. - */ - - let combinations = []; - let combination = []; - let dimensionIndex = 0; - - calculateCombinations(dimensionIndex, combination); - - function calculateCombinations(pDimensionIndex, pCombination) { - - let dimension = valueMatrix[pDimensionIndex]; - - for (let j = 0; j < dimension.length; j++) { - - let copy = JSON.parse(JSON.stringify(pCombination)); - - let value = dimension[j]; - copy.push(value); - - if (pDimensionIndex < valueMatrix.length - 1) { - - calculateCombinations(pDimensionIndex + 1, copy); - - } else { - - combinations.push(copy); - + switch (botConfig.type) { + case 'Trading': { + runTradingBot(botConfig, processConfig); + break; + } + default: { + console.log(logDisplace + "Root : [ERROR] start -> findProcess -> Unexpected bot type. -> botConfig.type = " + botConfig.type); } } } + } - /* At this point we have an array with all the possible combinations, we just need to create an instance for each one and set the genes according to that. */ + if (processConfig.startMode.backtest !== undefined) { - for (let i = 0; i < combinations.length; i++) { + if (processConfig.startMode.backtest.run === "true") { - let botConfig = JSON.parse(JSON.stringify(pBotConfig)); - let combination = combinations[i]; - let genes = {}; - let clonKey = ""; + botConfig.startMode = "Backtest"; + console.log(logDisplace + "Root : [INFO] start -> findProcess -> Process found at the bot configuration file. -> Start Mode = " + botConfig.startMode); - for (let j = 0; j < botConfig.genes.length; j++) { + botConfig.backtest = processConfig.startMode.backtest; - genes[botConfig.genes[j].name] = combination[j]; - clonKey = clonKey + "." + combination[j]; + /* We override these waitTimes to the one specified at the backtest configuration. */ - } + processConfig.normalWaitTime = processConfig.startMode.backtest.waitTime; + processConfig.retryWaitTime = processConfig.startMode.backtest.waitTime; - let clonName = botConfig.codeName + "-" + "Clon" + clonKey; - clonName += ".1.0"; + /* Backtest Mode does not support Resume Execution, so this is the only way. */ - if (global.CURRENT_EXECUTION_AT === "Node") { - clonName += "-" + process.env.CLONE_ID; - } - - botConfig.filePathRoot = botConfig.devTeam + "/" + clonName + "/" + global.PLATFORM_CONFIG.codeName + "." + global.PLATFORM_CONFIG.version.major + "." + global.PLATFORM_CONFIG.version.minor + "/" + global.EXCHANGE_NAME + "/" + botConfig.dataSetVersion; - - botConfig.instance = clonName; - botConfig.instanceIndex = i; - - setTimeout(execute, i * Math.random() * 10 * 1000); - - function execute() { - - createBotInstance(genes, combinations.length, botConfig); + botConfig.hasTheBotJustStarted = true; + switch (botConfig.type) { + case 'Trading': { + runTradingBot(botConfig, processConfig); + break; + } + default: { + console.log(logDisplace + "Root : [ERROR] start -> findProcess -> Unexpected bot type. -> botConfig.type = " + botConfig.type); + } } } + } + + if (processConfig.startMode.competition !== undefined) { + + if (processConfig.startMode.competition.run === "true") { + + botConfig.startMode = "Competition"; + console.log(logDisplace + "Root : [INFO] start -> findProcess -> Process found at the bot configuration file. -> Start Mode = " + botConfig.startMode); + + botConfig.competition = processConfig.startMode.competition; + + if (processConfig.startMode.competition.resumeExecution === "false") { + botConfig.hasTheBotJustStarted = true; + } else { + botConfig.hasTheBotJustStarted = false; + } + + switch (botConfig.type) { + case 'Trading': { + runTradingBot(botConfig, processConfig); + break; + } + default: { + console.log(logDisplace + "Root : [ERROR] start -> findProcess -> Unexpected bot type. -> botConfig.type = " + botConfig.type); + } + } + } + } + + } catch (err) { + console.log(logDisplace + "Root : [ERROR] start -> findProcess -> Unexpected exception. -> err.message = " + err.message); + } + } + } + + if (processFound === false) { + + console.log(logDisplace + "Root : [ERROR] start -> findProcess -> Process listed at the configuration file of CloneExecutor not found at the configuration file of the bot."); + console.log(logDisplace + "Root : [ERROR] start -> findProcess -> cloneToExecute.process = " + cloneToExecute.process); + + } + + function runExtractionBot(pBotConfig, pProcessConfig, pMonth, pYear) { + + try { + + const DEBUG_MODULE = require(ROOT_DIR + 'DebugLog'); + let logger; + + logger = DEBUG_MODULE.newDebugLog(); + logger.bot = pBotConfig; + + if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> findProcess -> runExtractionBot -> Entering function."); } + if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> findProcess -> runExtractionBot -> pMonth = " + pMonth); } + if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> findProcess -> runExtractionBot -> pYear = " + pYear); } + + let extractionBotMainLoop = EXTRACTION_BOT_MAIN_LOOP_MODULE.newExtractionBotProcessMainLoop(pBotConfig, logger); + extractionBotMainLoop.initialize(UI_COMMANDS, pProcessConfig, onInitializeReady); + + function onInitializeReady(err) { + + if (err.result === global.DEFAULT_OK_RESPONSE.result) { + + extractionBotMainLoop.run(pMonth, pYear, whenRunFinishes); + + function whenRunFinishes(err) { + + pBotConfig.loopCounter = 0; + + let botId; + if (pYear !== undefined) { + botId = pBotConfig.devTeam + "." + pBotConfig.codeName + "." + pBotConfig.process + "." + pYear + "." + pMonth; + } else { + botId = pBotConfig.devTeam + "." + pBotConfig.codeName + "." + pBotConfig.process; + } + + if (err.result === global.DEFAULT_OK_RESPONSE.result) { + + logger.write(MODULE_NAME, "[INFO] start -> findProcess -> runExtractionBot -> onInitializeReady -> whenStartFinishes -> Bot execution finished sucessfully."); + logger.write(MODULE_NAME, "[INFO] start -> findProcess -> runExtractionBot -> onInitializeReady -> whenStartFinishes -> Bot Id = " + botId); + + console.log(logDisplace + "Root : [INFO] start -> findProcess -> runExtractionBot -> onInitializeReady -> whenStartFinishes -> botId = " + botId); + console.log(logDisplace + "Root : [INFO] start -> findProcess -> runExtractionBot -> onInitializeReady -> whenStartFinishes -> Bot execution finished sucessfully."); + + logger.persist(); + + } else { + + logger.write(MODULE_NAME, "[ERROR] start -> findProcess -> runExtractionBot -> onInitializeReady -> whenStartFinishes -> err = " + err.message); + logger.write(MODULE_NAME, "[ERROR] start -> findProcess -> runExtractionBot -> onInitializeReady -> whenStartFinishes -> Execution will be stopped. "); + logger.write(MODULE_NAME, "[ERROR] start -> findProcess -> runExtractionBot -> onInitializeReady -> whenStartFinishes -> Bye."); + logger.write(MODULE_NAME, "[ERROR] start -> findProcess -> runExtractionBot -> onInitializeReady -> whenStartFinishes -> Bot Id = " + botId); + + console.log(logDisplace + "Root : [ERROR] start -> findProcess -> runExtractionBot -> onInitializeReady -> whenStartFinishes -> botId = " + botId); + console.log(logDisplace + "Root : [ERROR] start -> findProcess -> runExtractionBot -> onInitializeReady -> whenStartFinishes -> Bot execution was aborted."); + logger.persist(); + } + } + } else { + logger.write(MODULE_NAME, "[ERROR] start -> findProcess -> runExtractionBot -> onInitializeReady -> err = " + err.message); + logger.write(MODULE_NAME, "[ERROR] start -> findProcess -> runExtractionBot -> onInitializeReady -> Bot will not be started. "); + console.log(logDisplace + "Root : [ERROR] start -> findProcess -> runExtractionBot -> onInitializeReady -> err = " + err.message); - /* If the bot does not have any genes at all */ + logger.persist(); + } + } + } + catch (err) { + console.log(logDisplace + "Root : [ERROR] start -> findProcess -> runExtractionBot -> err = " + err.message); + } + } + function runIndicatorBot(pBotConfig, pProcessConfig, pMonth, pYear) { + + try { + const DEBUG_MODULE = require(ROOT_DIR + 'DebugLog'); + let logger; + + logger = DEBUG_MODULE.newDebugLog(); + logger.bot = pBotConfig; + + if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> findProcess -> runIndicatorBot -> Entering function."); } + if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> findProcess -> runIndicatorBot -> pMonth = " + pMonth); } + if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> findProcess -> runIndicatorBot -> pYear = " + pYear); } + + let indicatorBotMainLoop = INDICATOR_BOT_MAIN_LOOP_MODULE.newIndicatorBotProcessMainLoop(pBotConfig, logger); + indicatorBotMainLoop.initialize(UI_COMMANDS, pProcessConfig, onInitializeReady); + + function onInitializeReady(err) { + + if (err.result === global.DEFAULT_OK_RESPONSE.result) { + + indicatorBotMainLoop.run(pMonth, pYear, whenRunFinishes); + + function whenRunFinishes(err) { + + pBotConfig.loopCounter = 0; + + let botId; + if (pYear !== undefined) { + botId = pBotConfig.devTeam + "." + pBotConfig.codeName + "." + pBotConfig.process + "." + pYear + "." + pMonth; + } else { + botId = pBotConfig.devTeam + "." + pBotConfig.codeName + "." + pBotConfig.process; + } + + if (err.result === global.DEFAULT_OK_RESPONSE.result) { + + logger.write(MODULE_NAME, "[INFO] start -> findProcess -> runIndicatorBot -> onInitializeReady -> whenStartFinishes -> Bot execution finished sucessfully."); + logger.write(MODULE_NAME, "[INFO] start -> findProcess -> runIndicatorBot -> onInitializeReady -> whenStartFinishes -> Bot Id = " + botId); + + console.log(logDisplace + "Root : [INFO] start -> findProcess -> runIndicatorBot -> onInitializeReady -> whenStartFinishes -> botId = " + botId); + console.log(logDisplace + "Root : [INFO] start -> findProcess -> runIndicatorBot -> onInitializeReady -> whenStartFinishes -> Bot execution finished sucessfully."); + + logger.persist(); + + } else { + + logger.write(MODULE_NAME, "[ERROR] start -> findProcess -> runIndicatorBot -> onInitializeReady -> whenStartFinishes -> err = " + err.message); + logger.write(MODULE_NAME, "[ERROR] start -> findProcess -> runIndicatorBot -> onInitializeReady -> whenStartFinishes -> Execution will be stopped. "); + logger.write(MODULE_NAME, "[ERROR] start -> findProcess -> runIndicatorBot -> onInitializeReady -> whenStartFinishes -> Bye."); + logger.write(MODULE_NAME, "[ERROR] start -> findProcess -> runIndicatorBot -> onInitializeReady -> whenStartFinishes -> Bot Id = " + botId); + console.log(logDisplace + "Root : [ERROR] start -> findProcess -> runIndicatorBot -> onInitializeReady -> whenStartFinishes -> Bot execution finished with errors. Please check the logs."); + logger.persist(); + } + } + + } else { + logger.write(MODULE_NAME, "[ERROR] start -> findProcess -> runIndicatorBot -> onInitializeReady -> err = " + err.message); + logger.write(MODULE_NAME, "[ERROR] start -> findProcess -> runIndicatorBot -> onInitializeReady -> Failed to initialize the bot. "); + console.log(logDisplace + "Root : [ERROR] start -> findProcess -> runIndicatorBot -> onInitializeReady -> err = " + err.message); + logger.persist(); + throw new Error("Root -> start -> findProcess -> runIndicatorBot -> onInitializeReady -> Failed to initialize the bot.") + } + } + } + catch (err) { + console.log(logDisplace + "Root : [ERROR] start -> findProcess -> runIndicatorBot -> err = " + err.message); + + } + } + + function runTradingBot(pBotConfig, pProcessConfig) { + + try { + + if (FULL_LOG === true) { console.log(logDisplace + "[INFO] start -> findProcess -> runTradingBot -> Entering function."); } + + if (pBotConfig.genes !== undefined) { + + /* Here, based on the gene we will create one instance for each combination of genes */ + + let valueMatrix = []; + + for (let i = 0; i < pBotConfig.genes.length; i++) { + + let gene = pBotConfig.genes[i]; + + let possibleValues = []; + + for (let j = gene.lowerLimit; j <= gene.upperLimit; j++) { + + possibleValues.push(j); + + } + + valueMatrix.push(possibleValues); + + } + + /* + Now we have all the possible genes values in a multi-dimensional matrix. + We will go thorugh each of the elements of each dimension and get each combination possible with the other dimmensions. + */ + + let combinations = []; + let combination = []; + let dimensionIndex = 0; + + calculateCombinations(dimensionIndex, combination); + + function calculateCombinations(pDimensionIndex, pCombination) { + + let dimension = valueMatrix[pDimensionIndex]; + + for (let j = 0; j < dimension.length; j++) { + + let copy = JSON.parse(JSON.stringify(pCombination)); + + let value = dimension[j]; + copy.push(value); + + if (pDimensionIndex < valueMatrix.length - 1) { + + calculateCombinations(pDimensionIndex + 1, copy); + + } else { + + combinations.push(copy); + + } + } + } + + /* At this point we have an array with all the possible combinations, we just need to create an instance for each one and set the genes according to that. */ + + for (let i = 0; i < combinations.length; i++) { + + let botConfig = JSON.parse(JSON.stringify(pBotConfig)); + let combination = combinations[i]; let genes = {}; - let clonName = botConfig.codeName; + let clonKey = ""; + + for (let j = 0; j < botConfig.genes.length; j++) { + + genes[botConfig.genes[j].name] = combination[j]; + clonKey = clonKey + "." + combination[j]; + + } + + let clonName = botConfig.codeName + "-" + "Clon" + clonKey; + clonName += ".1.0"; if (global.CURRENT_EXECUTION_AT === "Node") { clonName += "-" + process.env.CLONE_ID; } - clonName += ".1.0"; - botConfig.filePathRoot = botConfig.devTeam + "/" + clonName + "/" + global.PLATFORM_CONFIG.codeName + "." + global.PLATFORM_CONFIG.version.major + "." + global.PLATFORM_CONFIG.version.minor + "/" + global.EXCHANGE_NAME + "/" + botConfig.dataSetVersion; - pBotConfig.instance = clonName; - pBotConfig.instanceIndex = 0; + botConfig.instance = clonName; + botConfig.instanceIndex = i; - createBotInstance(genes, 1, pBotConfig); + setTimeout(execute, i * Math.random() * 10 * 1000); + function execute() { + + createBotInstance(genes, combinations.length, botConfig); + + } + } + } else { + + /* If the bot does not have any genes at all */ + + let genes = {}; + let clonName = botConfig.codeName; + + if (global.CURRENT_EXECUTION_AT === "Node") { + clonName += "-" + process.env.CLONE_ID; } + clonName += ".1.0"; - function createBotInstance(pGenes, pTotalInstances, pBotConfig) { + botConfig.filePathRoot = botConfig.devTeam + "/" + clonName + "/" + global.PLATFORM_CONFIG.codeName + "." + global.PLATFORM_CONFIG.version.major + "." + global.PLATFORM_CONFIG.version.minor + "/" + global.EXCHANGE_NAME + "/" + botConfig.dataSetVersion; - const DEBUG_MODULE = require(ROOT_DIR + 'DebugLog'); - let logger; + pBotConfig.instance = clonName; + pBotConfig.instanceIndex = 0; - logger = DEBUG_MODULE.newDebugLog(); - logger.bot = pBotConfig; - pBotConfig.timePeriodFileStorage = global.EXECUTION_CONFIG.timePeriodFileStorage - pBotConfig.dataSet = global.EXECUTION_CONFIG.dataSet + createBotInstance(genes, 1, pBotConfig); - if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> findProcess -> runTradingBot -> createBotInstance -> Entering function."); } + } - let tradingBotMainLoop = TRADING_BOT_MAIN_LOOP_MODULE.newTradingBotProcessMainLoop(pBotConfig, logger); - tradingBotMainLoop.initialize(UI_COMMANDS, pProcessConfig, onInitializeReady); - function onInitializeReady(err) { + function createBotInstance(pGenes, pTotalInstances, pBotConfig) { - if (err.result === global.DEFAULT_OK_RESPONSE.result) { + const DEBUG_MODULE = require(ROOT_DIR + 'DebugLog'); + let logger; - tradingBotMainLoop.run(pGenes, pTotalInstances, whenRunFinishes); + logger = DEBUG_MODULE.newDebugLog(); + logger.bot = pBotConfig; + pBotConfig.timePeriodFileStorage = global.EXECUTION_CONFIG.timePeriodFileStorage + pBotConfig.dataSet = global.EXECUTION_CONFIG.dataSet - function whenRunFinishes(err) { + if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> findProcess -> runTradingBot -> createBotInstance -> Entering function."); } - pBotConfig.loopCounter = 0; + let tradingBotMainLoop = TRADING_BOT_MAIN_LOOP_MODULE.newTradingBotProcessMainLoop(pBotConfig, logger); + tradingBotMainLoop.initialize(UI_COMMANDS, pProcessConfig, onInitializeReady); - let botId; + function onInitializeReady(err) { - botId = pBotConfig.devTeam + "." + pBotConfig.codeName + "." + pBotConfig.instance + "." + pBotConfig.process; + if (err.result === global.DEFAULT_OK_RESPONSE.result) { - if (err.result === global.DEFAULT_OK_RESPONSE.result) { + tradingBotMainLoop.run(pGenes, pTotalInstances, whenRunFinishes); - logger.write(MODULE_NAME, "[INFO] start -> findProcess -> runTradingBot -> createBotInstance -> onInitializeReady -> whenStartFinishes -> Bot execution finished sucessfully."); - logger.write(MODULE_NAME, "[INFO] start -> findProcess -> runTradingBot -> createBotInstance -> onInitializeReady -> whenStartFinishes -> Bot Id = " + botId); + function whenRunFinishes(err) { - console.log(logDisplace + "Root : [INFO] start -> findProcess -> runTradingBot -> createBotInstance -> onInitializeReady -> whenStartFinishes -> botId = " + botId); - console.log(logDisplace + "Root : [INFO] start -> findProcess -> runTradingBot -> createBotInstance -> onInitializeReady -> whenStartFinishes -> Bot execution finished sucessfully."); - logger.persist(); + pBotConfig.loopCounter = 0; - } else { + let botId; - logger.write(MODULE_NAME, "[ERROR] start -> findProcess -> runTradingBot -> createBotInstance -> onInitializeReady -> whenStartFinishes -> err = " + err.message); - logger.write(MODULE_NAME, "[ERROR] start -> findProcess -> runTradingBot -> createBotInstance -> onInitializeReady -> whenStartFinishes -> Execution will be stopped. "); - logger.write(MODULE_NAME, "[ERROR] start -> findProcess -> runTradingBot -> createBotInstance -> onInitializeReady -> whenStartFinishes -> Bye."); - logger.write(MODULE_NAME, "[ERROR] start -> findProcess -> runTradingBot -> createBotInstance -> onInitializeReady -> whenStartFinishes -> Bot Id = " + botId); - console.log(logDisplace + "Root : [ERROR] start -> findProcess -> runTradingBot -> createBotInstance -> onInitializeReady -> whenStartFinishes -> Bot execution finished with errors. Please check the logs."); - logger.persist(); - } + botId = pBotConfig.devTeam + "." + pBotConfig.codeName + "." + pBotConfig.instance + "." + pBotConfig.process; + + if (err.result === global.DEFAULT_OK_RESPONSE.result) { + + logger.write(MODULE_NAME, "[INFO] start -> findProcess -> runTradingBot -> createBotInstance -> onInitializeReady -> whenStartFinishes -> Bot execution finished sucessfully."); + logger.write(MODULE_NAME, "[INFO] start -> findProcess -> runTradingBot -> createBotInstance -> onInitializeReady -> whenStartFinishes -> Bot Id = " + botId); + + console.log(logDisplace + "Root : [INFO] start -> findProcess -> runTradingBot -> createBotInstance -> onInitializeReady -> whenStartFinishes -> botId = " + botId); + console.log(logDisplace + "Root : [INFO] start -> findProcess -> runTradingBot -> createBotInstance -> onInitializeReady -> whenStartFinishes -> Bot execution finished sucessfully."); + logger.persist(); + + } else { + + logger.write(MODULE_NAME, "[ERROR] start -> findProcess -> runTradingBot -> createBotInstance -> onInitializeReady -> whenStartFinishes -> err = " + err.message); + logger.write(MODULE_NAME, "[ERROR] start -> findProcess -> runTradingBot -> createBotInstance -> onInitializeReady -> whenStartFinishes -> Execution will be stopped. "); + logger.write(MODULE_NAME, "[ERROR] start -> findProcess -> runTradingBot -> createBotInstance -> onInitializeReady -> whenStartFinishes -> Bye."); + logger.write(MODULE_NAME, "[ERROR] start -> findProcess -> runTradingBot -> createBotInstance -> onInitializeReady -> whenStartFinishes -> Bot Id = " + botId); + console.log(logDisplace + "Root : [ERROR] start -> findProcess -> runTradingBot -> createBotInstance -> onInitializeReady -> whenStartFinishes -> Bot execution finished with errors. Please check the logs."); + logger.persist(); } - - } else { - logger.write(MODULE_NAME, "[ERROR] start -> findProcess -> runTradingBot -> createBotInstance -> onInitializeReady -> err = " + err.message); - logger.write(MODULE_NAME, "[ERROR] start -> findProcess -> runTradingBot -> createBotInstance -> onInitializeReady -> Bot will not be started. "); - console.log(logDisplace + "Root : [ERROR] start -> findProcess -> runTradingBot -> createBotInstance -> onInitializeReady -> err = " + err.message); - - logger.persist(); } + + } else { + logger.write(MODULE_NAME, "[ERROR] start -> findProcess -> runTradingBot -> createBotInstance -> onInitializeReady -> err = " + err.message); + logger.write(MODULE_NAME, "[ERROR] start -> findProcess -> runTradingBot -> createBotInstance -> onInitializeReady -> Bot will not be started. "); + console.log(logDisplace + "Root : [ERROR] start -> findProcess -> runTradingBot -> createBotInstance -> onInitializeReady -> err = " + err.message); + + logger.persist(); } } } - catch (err) { - console.log(logDisplace + "Root : [ERROR] start -> findProcess -> runTradingBot -> err = " + err.message); - } } + catch (err) { + console.log(logDisplace + "Root : [ERROR] start -> findProcess -> runTradingBot -> err = " + err.message); + } + } - } - catch (err) { - console.log(logDisplace + "Root : [ERROR] start -> findProcess -> err.message = " + err.message); - return; - } + } + catch (err) { + console.log(logDisplace + "Root : [ERROR] start -> findProcess -> err.message = " + err.message); + return; } } + } } diff --git a/Run.js b/Run.js index 926474a32..980e7dd72 100644 --- a/Run.js +++ b/Run.js @@ -112,16 +112,16 @@ function readExecutionConfiguration() { startMode[process.env.START_MODE].run = "true" - let executionList = [{ + let cloneToExecute = { enabled: "true", devTeam: process.env.DEV_TEAM, bot: process.env.BOT, process: process.env.PROCESS, repo: global.CURRENT_BOT_REPO - }] + } global.EXECUTION_CONFIG = { - executionList: executionList, + cloneToExecute: cloneToExecute, startMode: startMode, timePeriod: getTimePeriod(process.env.TIME_PERIOD), timePeriodFileStorage: process.env.TIME_PERIOD, diff --git a/this.config.json b/this.config.json index 9f33a2962..46ab69018 100644 --- a/this.config.json +++ b/this.config.json @@ -5,57 +5,6 @@ "minor": 1, "patch": 0 }, - "executionList": [ - { - "enabled": "false", - "devTeam": "AAMasters", - "bot": "AAMariam", - "process": "Trading-Process", - "repo": "AAMariam-Trading-Bot" - }, - { - "enabled": "false", - "devTeam": "AAMasters", - "bot": "AACharly", - "process": "Poloniex-Live-Trades", - "repo": "AACharly-Extraction-Bot" - }, - { - "enabled": "false", - "devTeam": "AAMasters", - "bot": "AACharly", - "process": "Poloniex-Hole-Fixing", - "repo": "AACharly-Extraction-Bot" - }, - { - "enabled": "false", - "devTeam": "AAMasters", - "bot": "AABruce", - "process": "One-Min-Daily-Candles-Volumes", - "repo": "AABruce-Indicator-Bot" - }, - { - "enabled": "false", - "devTeam": "AAMasters", - "bot": "AAOlivia", - "process": "Multi-Period-Daily", - "repo": "AAOlivia-Indicator-Bot" - }, - { - "enabled": "false", - "devTeam": "AAMasters", - "bot": "AAOlivia", - "process": "Multi-Period-Market", - "repo": "AAOlivia-Indicator-Bot" - }, - { - "enabled": "true", - "devTeam": "AAMasters", - "bot": "AAChris", - "process": "Multi-Period-Market", - "repo": "AAOlivia-Indicator-Bot" - } - ], "stopGracefully": false, "marketRateProvider": { "devTeam": "AAMasters",