From 2350dc0b234b8fb98babb5034b6d4970b629ddfa Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Mon, 27 Jan 2020 21:16:51 +0100 Subject: [PATCH] key instance changed --- Root.js | 17 +++++++++++++++++ SensorBotProcessMainLoop.js | 7 ++++++- Session.js | 32 +------------------------------- 3 files changed, 24 insertions(+), 32 deletions(-) diff --git a/Root.js b/Root.js index 9118749f1..1f6344366 100644 --- a/Root.js +++ b/Root.js @@ -235,6 +235,23 @@ /* Bot Type */ botConfig.type = global.TASK_NODE.bot.processes[processIndex].referenceParent.parentNode.type + /* Setting the Key to use */ + process.env.KEY = undefined + process.env.SECRET = undefined + + if (botConfig.processNode) { + if (botConfig.processNode.marketReference) { + if (botConfig.processNode.marketReference.keyInstance !== undefined) { + if (botConfig.processNode.marketReference.keyInstance.referenceParent !== undefined) { + let key = botConfig.processNode.marketReference.keyInstance.referenceParent + + process.env.KEY = key.code.codeName + process.env.SECRET = key.code.secret + } + } + } + } + if (FULL_LOG === true) { console.log(logDisplace + "Root : [INFO] start -> bootingBot -> filePathRoot = " + botConfig.filePathRoot); } if (FULL_LOG === true) { console.log(logDisplace + "Root : [INFO] start -> bootingBot -> Process found at the bot configuration file. -> process = " + global.TASK_NODE.bot.processes[processIndex].referenceParent.code.codeName); } diff --git a/SensorBotProcessMainLoop.js b/SensorBotProcessMainLoop.js index 45d7ebed2..e63b2c6cf 100644 --- a/SensorBotProcessMainLoop.js +++ b/SensorBotProcessMainLoop.js @@ -59,7 +59,12 @@ if (bot.process === "Hole-Fixing") { //USER_BOT_MODULE.newUserBot = require(process.env.BOTS_PATH + '/aamasters/AAMasters/bots/AACharly-Sensor-Bot/Hole-Fixing/User.Bot').newUserBot } - USER_BOT_MODULE.newUserBot = eval(text); // TODO This needs to be changed function + try { + USER_BOT_MODULE.newUserBot = eval(text); // TODO This needs to be changed function + } catch (err) { + parentLogger.write(MODULE_NAME, "[ERROR] initialize -> onBotDownloaded -> err = " + err.stack); + callBackFunction(global.DEFAULT_FAIL_RESPONSE); + } filePath = bot.dataMine + "/" + "bots" + "/" + bot.repo; filePath += "/Commons.js" diff --git a/Session.js b/Session.js index a22b1dae8..920dcde9f 100644 --- a/Session.js +++ b/Session.js @@ -109,7 +109,7 @@ } function startLiveTrading(message) { - setKeyToUse() + if (process.env.KEY === undefined || process.env.SECRET === undefined) { if (FULL_LOG === true) { parentLogger.write(MODULE_NAME, "[WARN] initialize -> startLiveTrading -> Key name or Secret not provided, not possible to run the process in Live mode."); } console.log("Key 'codeName' or 'secret' not provided. Plese check that and try again.") @@ -128,8 +128,6 @@ function startFordwardTesting(message) { - setKeyToUse() - if (process.env.KEY === undefined || process.env.SECRET === undefined) { if (FULL_LOG === true) { parentLogger.write(MODULE_NAME, "[WARN] initialize -> startLiveTrading -> Key name or Secret not provided, not possible to run the process in Forward Testing mode."); } console.log("Key 'codeName' or 'secret' not provided. Plese check that and try again.") @@ -175,34 +173,6 @@ return true } - function setKeyToUse() { - - /* This is the primary fallback, when there is no key defined at the parameters at the session level. */ - if (bot.TRADING_SYSTEM) { - if (bot.TRADING_SYSTEM.parameters) { - if (bot.TRADING_SYSTEM.parameters.keyInstance !== undefined) { - if (bot.TRADING_SYSTEM.parameters.keyInstance.referenceParent !== undefined) { - let key = bot.TRADING_SYSTEM.parameters.keyInstance.referenceParent - - process.env.KEY = key.code.codeName - process.env.SECRET = key.code.secret - } - } - } - } - - /* Key defined at the parameters at the session level. */ - if (bot.SESSION.parameters) { - if (bot.SESSION.parameters.keyInstance !== undefined) { - if (bot.SESSION.parameters.keyInstance.referenceParent !== undefined) { - let key = bot.SESSION.parameters.keyInstance.referenceParent - process.env.KEY = key.code.codeName - process.env.SECRET = key.code.secret - } - } - } - } - function setValuesToUse(message) { /* Base on the information received we will determined which values ultimatelly are going to be used,