Fixing trading bot execution

This commit is contained in:
Matias committed 2019-07-01 16:35:49 -03:00
1 parent 60f54bf994
commit ca9dbdeb75
10 files changed
+126 -83

No files matched your search

+71
View File
@@ -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)
}
}
+20 -6
View File
@@ -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
}
}
}
}
}
+4 -10
View File
@@ -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))
}
}