From f58a9f76a5b8d6286ba8532a444a968ea65044fe Mon Sep 17 00:00:00 2001 From: "mati108@gmail.com" <34651529+matbenitez@users.noreply.github.com> Date: Thu, 13 Dec 2018 09:12:25 -0300 Subject: [PATCH] Adding env variables and fixing issues --- Assistant.js | 45 ++++-------------------------------- Root.js | 7 +++++- Run.js | 38 +++++++++++++++++------------- StorageAccessManager.js | 2 +- TradingBotProcessMainLoop.js | 2 +- exchange/ExchangeAPI.js | 5 ++-- package-lock.json | 5 ++++ package.json | 3 ++- 8 files changed, 45 insertions(+), 62 deletions(-) diff --git a/Assistant.js b/Assistant.js index 6f8b9b7f4..301130f36 100644 --- a/Assistant.js +++ b/Assistant.js @@ -918,10 +918,6 @@ try { if (global.LOG_CONTROL[MODULE_NAME].logInfo === true) { logger.write(MODULE_NAME, "[INFO] putPosition -> Entering function."); } - if (global.LOG_CONTROL[MODULE_NAME].logInfo === true) { logger.write(MODULE_NAME, "[INFO] putPosition -> pType = " + pType); } - if (global.LOG_CONTROL[MODULE_NAME].logInfo === true) { logger.write(MODULE_NAME, "[INFO] putPosition -> pRate = " + pRate); } - if (global.LOG_CONTROL[MODULE_NAME].logInfo === true) { logger.write(MODULE_NAME, "[INFO] putPosition -> pAmountA = " + pAmountA); } - if (global.LOG_CONTROL[MODULE_NAME].logInfo === true) { logger.write(MODULE_NAME, "[INFO] putPosition -> pAmountB = " + pAmountB); } /* Removing extra decimals. */ @@ -929,6 +925,11 @@ pAmountA = thisObject.truncDecimals(pAmountA); pAmountB = thisObject.truncDecimals(pAmountB); + if (global.LOG_CONTROL[MODULE_NAME].logInfo === true) { logger.write(MODULE_NAME, "[INFO] putPosition -> pType = " + pType); } + if (global.LOG_CONTROL[MODULE_NAME].logInfo === true) { logger.write(MODULE_NAME, "[INFO] putPosition -> pRate = " + pRate); } + if (global.LOG_CONTROL[MODULE_NAME].logInfo === true) { logger.write(MODULE_NAME, "[INFO] putPosition -> pAmountA = " + pAmountA); } + if (global.LOG_CONTROL[MODULE_NAME].logInfo === true) { logger.write(MODULE_NAME, "[INFO] putPosition -> pAmountB = " + pAmountB); } + /* Validations that the limits are not surpassed. */ if (pType === 'buy') { @@ -947,24 +948,6 @@ callBackFunction(err); return; } - - let aRate = thisObject.truncDecimals(pAmountA / pRate); - - if (aRate !== pAmountB) { - - logger.write(MODULE_NAME, "[ERROR] putPosition -> Input Validations -> pAmountA / pRate !== pAmountB."); - logger.write(MODULE_NAME, "[ERROR] putPosition -> Input Validations -> pAmountA = " + pAmountA); - logger.write(MODULE_NAME, "[ERROR] putPosition -> Input Validations -> pAmountB = " + pAmountB); - logger.write(MODULE_NAME, "[ERROR] putPosition -> Input Validations -> pRate = " + pRate); - - let err = { - result: global.DEFAULT_FAIL_RESPONSE.result, - message: 'pAmountB * pRate !== pAmountA' - }; - - callBackFunction(err); - return; - } } if (pType === 'sell') { @@ -983,24 +966,6 @@ callBackFunction(err); return; } - - let bRate = thisObject.truncDecimals(pAmountB * pRate); - - if (bRate !== pAmountA) { - - logger.write(MODULE_NAME, "[ERROR] putPosition -> Input Validations -> pAmountB * pRate !== pAmountA."); - logger.write(MODULE_NAME, "[ERROR] putPosition -> Input Validations -> pAmountA = " + pAmountA); - logger.write(MODULE_NAME, "[ERROR] putPosition -> Input Validations -> pAmountB = " + pAmountB); - logger.write(MODULE_NAME, "[ERROR] putPosition -> Input Validations -> pRate = " + pRate); - - let err = { - result: global.DEFAULT_FAIL_RESPONSE.result, - message: 'pAmountB * pRate !== pAmountA' - }; - - callBackFunction(err); - return; - } } /* All validations passed, we proceed. */ diff --git a/Root.js b/Root.js index 4c0f321dd..5fcf14cf8 100644 --- a/Root.js +++ b/Root.js @@ -529,8 +529,9 @@ exports.newRoot = function newRoot() { if (processConfig.startMode.live !== undefined) { if (processConfig.startMode.live.run === "true" && global.EXECUTION_CONFIG.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(); @@ -558,6 +559,8 @@ exports.newRoot = function newRoot() { if (processConfig.startMode.backtest.run === "true" && global.EXECUTION_CONFIG.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. */ @@ -586,6 +589,8 @@ exports.newRoot = function newRoot() { if (processConfig.startMode.competition.run === "true" && global.EXECUTION_CONFIG.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" && global.EXECUTION_CONFIG.startMode.competition.resumeExecution === "false") { diff --git a/Run.js b/Run.js index f21106276..18b7b7cca 100644 --- a/Run.js +++ b/Run.js @@ -1,4 +1,4 @@ - +require('dotenv').config() global.CURRENT_ENVIRONMENT = "Develop"; global.CURRENT_EXECUTION_AT = "Cloud"; global.SHALL_BOT_STOP = false; @@ -37,30 +37,36 @@ process.on('exit', function (code) { readExecutionConfiguration(); function readExecutionConfiguration() { - let filePath; try { - let fs = require('fs'); + console.log("[INFO] Run -> readExecutionConfiguration -> Entering function. "); + + global.DEV_TEAM = process.env.DEV_TEAM; + + let executionList = [{ + enabled: "true", + devTeam: process.env.DEV_TEAM, + bot: process.env.BOT, + process: process.env.PROCESS + }] + + // TODO Improve this by changing Root.js + let mode = + '{ "run":"false",' + + '"resumeExecution":' + process.env.RESUME_EXECUTION + + '}' + let startMode = JSON.parse('{ "live": ' + mode +', "backtest": '+mode+', "competition": '+mode+'}') + startMode[process.env.START_MODE].run="true" - let configDirectory = process.argv[2]; - if (configDirectory === undefined) { - console.log("[ERROR] Configuration file not passed as a command line argument."); - return; - } - filePath = configDirectory + '/Execution.Config.json'; - let executionProperties = JSON.parse(fs.readFileSync(filePath, 'utf8')); - global.DEV_TEAM = executionProperties.devTeam; - global.EXCHANGE_NAME = executionProperties.exchangeName; - global.MARKET = executionProperties.market; global.EXECUTION_CONFIG = { - executionList: executionProperties.executionList, - startMode: executionProperties.startMode + executionList: executionList, + startMode: startMode }; readStoragePermissions(); } catch (err) { console.log("[ERROR] readExecutionConfiguration -> err = " + err.message); - console.log("[HINT] You need to have a file at this path -> " + filePath); + console.log("[ERROR] readExecutionConfiguration -> err = " + err.stack); } } diff --git a/StorageAccessManager.js b/StorageAccessManager.js index ae4ad9a67..ed6794ced 100644 --- a/StorageAccessManager.js +++ b/StorageAccessManager.js @@ -57,7 +57,7 @@ let sasToken = blobService.generateSharedAccessSignature(pContainer, blobName, sharedAccessPolicy); return "BlobEndpoint=https://aadevelop.blob.core.windows.net;SharedAccessSignature=" + sasToken + ""; - + //return "BlobEndpoint=https://aaproduction.blob.core.windows.net;SharedAccessSignature=" + sasToken + ""; } } diff --git a/TradingBotProcessMainLoop.js b/TradingBotProcessMainLoop.js index 21b9845bf..877150c6b 100644 --- a/TradingBotProcessMainLoop.js +++ b/TradingBotProcessMainLoop.js @@ -176,7 +176,7 @@ /* We define here all the modules that the rest of the infraestructure, including the bots themselves can consume. */ const UTILITIES = require(ROOT_DIR + 'CloudUtilities'); - const EXCHANGE_API = require(ROOT_DIR + 'Exchange/ExchangeAPI'); + const EXCHANGE_API = require(ROOT_DIR + 'exchange/ExchangeAPI'); const CONTEXT = require(ROOT_DIR + 'Context'); const ASSISTANT = require(ROOT_DIR + 'Assistant'); const STATUS_REPORT = require(ROOT_DIR + 'StatusReport'); diff --git a/exchange/ExchangeAPI.js b/exchange/ExchangeAPI.js index 0d56607fe..0c1559768 100644 --- a/exchange/ExchangeAPI.js +++ b/exchange/ExchangeAPI.js @@ -37,7 +37,7 @@ // TODO integrate with financial beings module to get the exchange let botExchange = 'Poloniex'; let exchange = botExchange.toLowerCase() + 'Client.js'; - let api = require('./Wrappers/' + exchange); + let api = require('./wrappers/' + exchange); request(authOptions, onTokenResponse); @@ -67,7 +67,8 @@ if (global.LOG_CONTROL[MODULE_NAME].logInfo === true) { logger.write(MODULE_NAME, "[INFO] createKeyVaultAPIClient -> Entering function."); } const keyVaultAPI = graphqlClient({ - url: 'https://app-api.advancedalgos.net/graphql', + //url: 'https://platform-api.advancedalgos.net/graphql', + url: 'https://platform-dev-api.advancedalgos.net/graphql', headers: { Authorization: 'Bearer ' + authToken } diff --git a/package-lock.json b/package-lock.json index 8197cfa4b..ef0cf5a63 100644 --- a/package-lock.json +++ b/package-lock.json @@ -245,6 +245,11 @@ "resolved": "https://registry.npmjs.org/delayed-stream/-/delayed-stream-1.0.0.tgz", "integrity": "sha1-3zrhmayt+31ECqrgsp4icrJOxhk=" }, + "dotenv": { + "version": "6.2.0", + "resolved": "https://registry.npmjs.org/dotenv/-/dotenv-6.2.0.tgz", + "integrity": "sha512-HygQCKUBSFl8wKQZBSemMywRWcEDNidvNbjGVyZu3nbZ8qq9ubiPoGLMdRDpfSrpkkm9BXYFkpKxxFX38o/76w==" + }, "ecc-jsbn": { "version": "0.1.2", "resolved": "https://registry.npmjs.org/ecc-jsbn/-/ecc-jsbn-0.1.2.tgz", diff --git a/package.json b/package.json index 564db3a39..a91b814fd 100644 --- a/package.json +++ b/package.json @@ -20,6 +20,7 @@ "request": "^2.88.0", "retry": "^0.12.0", "underscore": "^1.9.1", - "azure-storage": "^2.8.2" + "azure-storage": "^2.8.2", + "dotenv": "^6.0.0" } }