diff --git a/IndicatorBotProcessMainLoop.js b/IndicatorBotProcessMainLoop.js index feedc0ae7..e22c9979a 100644 --- a/IndicatorBotProcessMainLoop.js +++ b/IndicatorBotProcessMainLoop.js @@ -39,13 +39,7 @@ UI_COMMANDS = pUI_COMMANDS; processConfig = pProcessConfig; - let filePath; - - 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. - } + let filePath = global.DEV_TEAM + "/" + "bots" + "/" + bot.repo + "/" + pProcessConfig.name filePath += "/User.Bot.js" fileStorage.getTextFile(global.DEV_TEAM, filePath, onBotDownloaded); diff --git a/Integrations/Ecosystem.js b/Integrations/Ecosystem.js new file mode 100644 index 000000000..bcb1238cc --- /dev/null +++ b/Integrations/Ecosystem.js @@ -0,0 +1,71 @@ +const axios = require('axios') + +exports.getEcosystem = async function () { + try { + if (!global.ECOSYSTEM) { + const ecosystemResponse = await axios({ + url: process.env.GATEWAY_ENDPOINT_K8S, + method: 'post', + data: { + query: ` + query { + web_GetEcosystem { + id + devTeams { + codeName + displayName + host { + url + storage + container + accessKey + } + bots { + codeName + displayName + type + profilePicture + repo + configFile + products{ + codeName + displayName + description + dataSets{ + codeName + type + validPeriods + filePath + fileName + dataRange{ + filePath + fileName + } + } + exchangeList{ + name + } + } + } + } + } + } + ` + }, + headers: { + authorization: process.env.AUTHORIZATION + } + }) + //TODO Competition hosts not retrieved currently + + if (ecosystemResponse.data.errors) + throw new Error(ecosystemResponse.data.errors[0].message) + + global.ECOSYSTEM = ecosystemResponse.data.data.web_GetEcosystem; + } + return global.ECOSYSTEM + + } catch (error) { + throw new Error('There has been an error getting the Ecosystem: ', error) + } +} diff --git a/Integrations/FileStorage.js b/Integrations/FileStorage.js index 653f53e1c..bdb2930af 100644 --- a/Integrations/FileStorage.js +++ b/Integrations/FileStorage.js @@ -1,4 +1,5 @@ const axios = require('axios') +const Ecosystem = require('./Ecosystem') exports.newFileStorage = function newFileStorage() { const INFO_LOG = true @@ -11,12 +12,14 @@ exports.newFileStorage = function newFileStorage() { return thisObject - function getTextFile(container, filePath, callBackFunction) { + async function getTextFile(container, filePath, callBackFunction) { try { - if (INFO_LOG === true) { console.log('[INFO] getTextFile -> Entering function: '+ container.toLowerCase() + '/' + filePath) } + if (INFO_LOG === true) { console.log('[INFO] getTextFile -> Entering function: ' + container.toLowerCase() + '/' + filePath) } + + let host = await getDevTeamHost(container) axios({ - url: process.env.GATEWAY_ENDPOINT_K8S, + url: host.url + 'graphql', method: 'post', data: { query: ` @@ -28,8 +31,8 @@ exports.newFileStorage = function newFileStorage() { file: { container: container.toLowerCase(), filePath, - storage: process.env.HOST_STORAGE, - accessKey: process.env.HOST_ACCESS_KEY + storage: host.storage, + accessKey: host.accessKey } } } @@ -61,7 +64,7 @@ exports.newFileStorage = function newFileStorage() { async function createTextFile(container, filePath, fileContent, callBackFunction) { try { - if (INFO_LOG === true) { console.log('[INFO] createTextFile -> Entering function: ' + filePath) } + if (INFO_LOG === true) { console.log('[INFO] createTextFile -> Entering function: ' + container.toLowerCase() + '/' + filePath) } let response = await axios({ url: process.env.GATEWAY_ENDPOINT_K8S, @@ -96,4 +99,15 @@ exports.newFileStorage = function newFileStorage() { } } + async function getDevTeamHost(devTeamName) { + let ecosystem = await Ecosystem.getEcosystem() + + for (var i = 0; i < ecosystem.devTeams.length; i++) { + for (key in ecosystem.devTeams[i]) { + if (key ==='codeName' && ecosystem.devTeams[i][key].indexOf(devTeamName)!=-1) { + return ecosystem.devTeams[i].host + } + } + } + } } diff --git a/Integrations/Strategy.js b/Integrations/Strategy.js index a26daefe3..54f9e7ba1 100644 --- a/Integrations/Strategy.js +++ b/Integrations/Strategy.js @@ -2,20 +2,14 @@ const axios = require('axios') exports.getStrategy = async function () { try { - - let strategyOnlyOnce = true - if (process.env.STRATEGY_ONLY_ONCE !== undefined) - strategyOnlyOnce = JSON.parse(process.env.STRATEGY_ONLY_ONCE) - - if (!global.STRATEGY || !strategyOnlyOnce) { - + if (!global.STRATEGY) { let fbSlug = process.env.BOT if (process.env.TEST_FB !== undefined) { fbSlug = process.env.TEST_FB } const strategizerResponse = await axios({ - url: process.env.STRATEGIZER_ENDPOINT || process.env.GATEWAY_ENDPOINT_K8S, + url: process.env.GATEWAY_ENDPOINT_K8S, method: 'post', data: { query: ` @@ -30,7 +24,7 @@ exports.getStrategy = async function () { }, }, headers: { - access_token: process.env.ACCESS_TOKEN_STRATEGY + authorization: process.env.AUTHORIZATION } }) @@ -42,6 +36,6 @@ exports.getStrategy = async function () { return global.STRATEGY } catch (error) { - throw new Error('There has been an error getting the strategy: ', error) + throw new Error('There has been an error getting the strategy: ', JSON.stringify(error)) } } diff --git a/Run.js b/Run.js index fa0580f06..b3e4a4463 100644 --- a/Run.js +++ b/Run.js @@ -2,7 +2,6 @@ global.SHALL_BOT_STOP = false; global.AT_BREAKPOINT = false; // This is used only when running at the browser. -global.RUN_AS_TEAM = false; global.FULL_LOG = process.env.FULL_LOG; /* Default parameters can be changed by the execution configuration */ @@ -38,8 +37,6 @@ function readExecutionConfiguration() { // General Financial Being Configuration global.DEV_TEAM = process.env.DEV_TEAM global.CURRENT_BOT_REPO = process.env.BOT + "-" + process.env.TYPE + "-Bot" - global.RUN_AS_TEAM = (process.env.RUN_AS_TEAM === "true") - global.USER_LOGGED_IN = process.env.USER_LOGGED_IN if (process.env.TYPE === 'Trading') { let live = { @@ -116,13 +113,6 @@ function readExecutionConfiguration() { dataSet: process.env.DATA_SET }; - // var cloneExecutorConfig = require('./package.json'); - // global.CLONE_EXECUTOR = { - // codeName: 'clone-executor', - // codeName: 'clone-executor', - // version: cloneExecutorConfig.version - // } - global.CLONE_EXECUTOR = { codeName: 'AACloud', version: '1.1' diff --git a/SensorBotProcessMainLoop.js b/SensorBotProcessMainLoop.js index 26b49627c..21ceb375f 100644 --- a/SensorBotProcessMainLoop.js +++ b/SensorBotProcessMainLoop.js @@ -37,12 +37,7 @@ UI_COMMANDS = pUI_COMMANDS; processConfig = pProcessConfig; - let filePath; - 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. - } + let filePath = global.DEV_TEAM + "/" + "bots" + "/" + bot.repo + "/" + pProcessConfig.name; filePath += "/User.Bot.js" fileStorage.getTextFile(global.DEV_TEAM, filePath, onBotDownloaded); diff --git a/TradingBotProcessMainLoop.js b/TradingBotProcessMainLoop.js index cf21ee6f4..1b7ba1604 100644 --- a/TradingBotProcessMainLoop.js +++ b/TradingBotProcessMainLoop.js @@ -37,12 +37,7 @@ UI_COMMANDS = pUI_COMMANDS; processConfig = pProcessConfig; - let filePath; - 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. - } + let filePath = global.DEV_TEAM + "/" + "bots" + "/" + bot.repo + "/" + pProcessConfig.name filePath += "/User.Bot.js" fileStorage.getTextFile(global.DEV_TEAM, filePath, onBotDownloaded); diff --git a/docker-compose.yml b/docker-compose.yml index 2d65a2cb5..737672175 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,7 +1,7 @@ version: '3' services: node: - image: superalgos/clone-executor:1.0.25 + image: superalgos/clone-executor:1.0.30 build: context: . dockerfile: ./Dockerfile diff --git a/package-lock.json b/package-lock.json index 2979492fb..8eff8392f 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,13 +1,13 @@ { "name": "@superalgos/clone-executor", - "version": "1.0.12", + "version": "1.0.29", "lockfileVersion": 1, "requires": true, "dependencies": { "@superalgos/exchange-gateway": { - "version": "0.0.4", - "resolved": "https://registry.npmjs.org/@superalgos/exchange-gateway/-/exchange-gateway-0.0.4.tgz", - "integrity": "sha512-ebDiup8Op7zBNSoRv+wbfCgk9e8VOl9RCiYHFUq6p8AJ1Cu+zG2SOEXOT6eFG6ANq0HJASIl6oXi7CfdAekL6A==", + "version": "0.0.6", + "resolved": "https://registry.npmjs.org/@superalgos/exchange-gateway/-/exchange-gateway-0.0.6.tgz", + "integrity": "sha512-dVKvqEfKoRj6G6xhxDsdKlaj5eeSa5jhx9QxtzN6wUHyWbYEK19mOTuL3Kzs16IG2beGeCL+Yhmd6LONHVMsJw==", "requires": { "axios": "0.19.0", "dotenv": "8.0.0", @@ -18,17 +18,6 @@ "retry": "^0.12.0", "superagent": "^5.0.2", "underscore": "^1.9.1" - }, - "dependencies": { - "axios": { - "version": "0.19.0", - "resolved": "https://registry.npmjs.org/axios/-/axios-0.19.0.tgz", - "integrity": "sha512-1uvKqKQta3KBxIz14F2v06AEHZ/dIoeKfbTRkK1E5oqjDnuEerLmYTgJB5AiQZHJcljpg1TuRzdjDR06qNk0DQ==", - "requires": { - "follow-redirects": "1.5.10", - "is-buffer": "^2.0.2" - } - } } }, "@superalgos/mqservice": { @@ -846,9 +835,9 @@ "integrity": "sha1-VSmk1nZUE07cxSZmVoNbD4Ua/O4=" }, "mime": { - "version": "2.4.3", - "resolved": "https://registry.npmjs.org/mime/-/mime-2.4.3.tgz", - "integrity": "sha512-QgrPRJfE+riq5TPZMcHZOtm8c6K/yYrMbKIoRfapfiGLxS8OTeIfRhUGW5LU7MlRa52KOAGCfUNruqLrIBvWZw==" + "version": "2.4.4", + "resolved": "https://registry.npmjs.org/mime/-/mime-2.4.4.tgz", + "integrity": "sha512-LRxmNwziLPT828z+4YkNzloCFC2YM4wrB99k+AV5ZbEyfGNWfG8SO1FUXLmLDBSo89NrJZ4DIWeLjy1CHGhMGA==" }, "mime-db": { "version": "1.40.0", @@ -1098,9 +1087,9 @@ "integrity": "sha512-MtEC1TqN0EU5nephaJ4rAtThHtC86dNN9qCuEhtshvpVBkAW5ZO7BASN9REnF9eoXGcRub+pFuKEpOHE+HbEMw==" }, "psl": { - "version": "1.1.32", - "resolved": "https://registry.npmjs.org/psl/-/psl-1.1.32.tgz", - "integrity": "sha512-MHACAkHpihU/REGGPLj4sEfc/XKW2bheigvHO1dUqjaKigMp1C8+WLQYRGgeKFMsw5PMfegZcaN8IDXK/cD0+g==" + "version": "1.1.33", + "resolved": "https://registry.npmjs.org/psl/-/psl-1.1.33.tgz", + "integrity": "sha512-LTDP2uSrsc7XCb5lO7A8BI1qYxRe/8EqlRvMeEl6rsnYAqDOl8xHR+8lSAIVfrNaSAlTPTNOCgNjWcoUL3AZsw==" }, "pump": { "version": "3.0.0", @@ -1196,9 +1185,9 @@ "integrity": "sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg==" }, "semver": { - "version": "6.1.1", - "resolved": "https://registry.npmjs.org/semver/-/semver-6.1.1.tgz", - "integrity": "sha512-rWYq2e5iYW+fFe/oPPtYJxYgjBm8sC4rmoGdUOgBB7VnwKt6HrL793l2voH1UlsyYZpJ4g0wfjnTEO1s1NP2eQ==" + "version": "6.1.3", + "resolved": "https://registry.npmjs.org/semver/-/semver-6.1.3.tgz", + "integrity": "sha512-aymF+56WJJMyXQHcd4hlK4N75rwj5RQpfW8ePlQnJsTYOBLlLbcIErR/G1s9SkIvKBqOudR3KAx4wEqP+F1hNQ==" }, "set-blocking": { "version": "2.0.0", @@ -1293,20 +1282,21 @@ "integrity": "sha1-PFMZQukIwml8DsNEhYwobHygpgo=" }, "superagent": { - "version": "5.0.5", - "resolved": "https://registry.npmjs.org/superagent/-/superagent-5.0.5.tgz", - "integrity": "sha512-5fnihpNqJfDJHxeIkqlXKFDOW5t4WUFV8Ba1erxdWT0RySqjgAW6Hska0xNYEpAfaoMzubn77GROm/XlkssOoQ==", + "version": "5.1.0", + "resolved": "https://registry.npmjs.org/superagent/-/superagent-5.1.0.tgz", + "integrity": "sha512-7V6JVx5N+eTL1MMqRBX0v0bG04UjrjAvvZJTF/VDH/SH2GjSLqlrcYepFlpTrXpm37aSY6h3GGVWGxXl/98TKA==", "requires": { "component-emitter": "^1.3.0", "cookiejar": "^2.1.2", "debug": "^4.1.1", + "fast-safe-stringify": "^2.0.6", "form-data": "^2.3.3", "formidable": "^1.2.1", "methods": "^1.1.2", - "mime": "^2.4.2", + "mime": "^2.4.4", "qs": "^6.7.0", - "readable-stream": "^3.3.0", - "semver": "^6.0.0" + "readable-stream": "^3.4.0", + "semver": "^6.1.1" }, "dependencies": { "debug": { @@ -1318,9 +1308,9 @@ } }, "ms": { - "version": "2.1.1", - "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.1.tgz", - "integrity": "sha512-tgp+dl5cGk28utYktBsrFqA7HKgrhgPsg6Z/EfhWI4gl1Hwq8B/GmY/0oXZ6nF8hDVesS/FpnYaD/kOWhYQvyg==" + "version": "2.1.2", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz", + "integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==" }, "qs": { "version": "6.7.0", diff --git a/package.json b/package.json index d6db2b47b..39f7c71c0 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@superalgos/clone-executor", - "version": "1.0.25", + "version": "1.0.30", "description": "Module responsible for executing the bots on the cloud.", "author": "Superalgos, ltd.", "license": "Apache-2.0", @@ -13,10 +13,10 @@ "test": "echo \"Error: no test specified\" && exit 1" }, "dependencies": { - "@superalgos/exchange-gateway": "0.0.4", + "@superalgos/exchange-gateway": "0.0.6", "@superalgos/mqservice": "^0.0.14", - "axios": "0.19.0", - "dotenv": "8.0.0", + "axios": "^0.19.0", + "dotenv": "^8.0.0", "winston": "^3.2.1" } }