Adding clone support

This commit is contained in:
mati108@gmail.com committed 2019-02-10 17:31:09 -03:00
1 parent 76a0ce15f2
commit 3c0c7f43de
7 files changed
+45 -83

No files matched your search

+2 -39
View File
@@ -1358,45 +1358,8 @@
}
function sendEmail(pTitle, pBody, pTo) {
try {
/**
Email configuration is not available when running the bot on the browser.
*/
if (global.CURRENT_EXECUTION_AT === "Browser") {
logger.write(MODULE_NAME, "[WARN] sendEmail -> Send emails is disabled from the browser.");
return;
}
let emailList = pTo; //TODO Pending to add spam controller
let runIndex = context.statusReport.runs.length - 1;
let transporter = nodemailer.createTransport({
service: global.EMAIL_CONFIG.service,
auth: {
user: global.EMAIL_CONFIG.user,
pass: global.EMAIL_CONFIG.pass
}
});
let mailOptions = {
from: global.EMAIL_CONFIG.from,
bcc: emailList,
subject: bot.startMode + "." + runIndex + ' - ' + pTitle,
text: pBody
};
transporter.sendMail(mailOptions, function (error, info) {
if (error) {
logger.write(MODULE_NAME, "[ERROR] sendEmail -> err = " + error);
} else {
logger.write(MODULE_NAME, "[INFO] sendEmail -> Email sent = " + info.response);
}
});
} catch (err) {
logger.write(MODULE_NAME, "[ERROR] sendEmail -> err = " + err.message);
}
logger.write(MODULE_NAME, "[WARN] sendEmail -> Send emails is currently disabled.");
return;
}
function truncDecimals(pFloatValue, pDecimals) {
+5 -3
View File
@@ -10,7 +10,7 @@ exports.updateExecutionResults = async function (summaryDate, buyAverage, sellAv
try {
const authResponse = await auth.authenticate()
const accessToken = await auth.authenticate()
const operationsResponse = await axios({
url: process.env.GATEWAY_ENDPOINT,
@@ -46,11 +46,13 @@ exports.updateExecutionResults = async function (summaryDate, buyAverage, sellAv
},
},
headers: {
authorization: 'Bearer ' + authResponse.data.access_token
authorization: 'Bearer ' + accessToken
}
})
logger.debug('updateExecutionResults -> Operations Module Response: %s', operationsResponse.data.data.operations_UpdateExecutionSummary)
if (!operationsResponse.data.errors)
logger.debug('updateExecutionResults -> Operations Module Response: %s', operationsResponse.data.data.operations_UpdateExecutionSummary)
else throw new Error(operationsResponse.data.errors[0].message)
} catch (error) {
logger.error('updateExecutionResults -> Error: ' + error.stack)
-2
View File
@@ -85,13 +85,11 @@
</ItemGroup>
<ItemGroup>
<Content Include=".gitignore" />
<Content Include="configs\Email.Config.json" />
<Content Include="exchange\wrappers\binanceProperties.json" />
<Content Include="exchange\wrappers\poloniexProperties.json" />
<Content Include="this.config.json" />
</ItemGroup>
<ItemGroup>
<Folder Include="configs\" />
<Folder Include="Exchange\" />
<Folder Include="Exchange\Wrappers\" />
<Folder Include="Integrations\" />
+8 -4
View File
@@ -841,11 +841,11 @@ exports.newRoot = function newRoot() {
}
let clonName = "Clon" + clonKey;
let clonName = botConfig.codeName + "-" + "Clon" + clonKey + "-" + process.env.CLONE_ID;
botConfig.filePathRoot = botConfig.devTeam + "/" + botConfig.codeName + "-" + clonName + "/" + global.PLATFORM_CONFIG.codeName + "." + global.PLATFORM_CONFIG.version.major + "." + global.PLATFORM_CONFIG.version.minor + "/" + global.EXCHANGE_NAME + "/" + botConfig.dataSetVersion;
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 = "Clon" + clonKey;
botConfig.instance = clonName;
botConfig.instanceIndex = i;
setTimeout(execute, i * Math.random() * 10 * 1000);
@@ -861,7 +861,11 @@ exports.newRoot = function newRoot() {
/* If the bot does not have any genes at all */
let genes = {};
pBotConfig.instance = "Master";
let clonName = botConfig.codeName + "-" + 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;
pBotConfig.instance = clonName;
pBotConfig.instanceIndex = 0;
createBotInstance(genes, 1, pBotConfig);
+2 -21
View File
@@ -47,7 +47,6 @@ function readExecutionConfiguration() {
// Environment Configuration
global.CURRENT_ENVIRONMENT = process.env.PLATFORM_ENVIRONMENT
global.GATEWAY_ENDPOINT = process.env.GATEWAY_ENDPOINT
global.STORAGE_URL = process.env.STORAGE_URL
// General Financial Being Configuration
global.DEV_TEAM = process.env.DEV_TEAM
@@ -182,8 +181,9 @@ function readStoragePermissions() {
global.USER_PROFILE.storagePermissions = permissionsMap;
global.USER_PROFILE.connectionString = "";
process.env.STORAGE_CONNECTION_STRING = "";
readEmailConfiguration();
startRoot();
}
}
@@ -193,25 +193,6 @@ function readStoragePermissions() {
}
}
function readEmailConfiguration() {
let filePath;
try {
console.log( "Run : [INFO] readEmailConfiguration -> Entering function. ");
let fs = require('fs');
filePath = './' + 'configs' + '/' + 'Email.Config.json';
global.EMAIL_CONFIG = JSON.parse(fs.readFileSync(filePath, 'utf8'));
startRoot();
}
catch (err) {
console.log("[ERROR] Run -> readEmailConfiguration -> err = " + err.message);
console.log("[HINT] Run -> You need to have a file at this path -> " + filePath);
}
}
function startRoot() {
console.log( "[INFO] Run -> startRoot -> Entering function. ");
+2 -2
View File
@@ -39,9 +39,9 @@
let exchange = botExchange.toLowerCase() + 'Client.js';
let api = require('./wrappers/' + exchange);
const authResponse = await auth.authenticate()
const accessToken = await auth.authenticate()
let keyVaultAPI = createKeyVaultAPIClient(authResponse.data.access_token)
let keyVaultAPI = createKeyVaultAPIClient(accessToken)
apiClient = api.newAPIClient(keyVaultAPI, logger);
callBackFunction(global.DEFAULT_OK_RESPONSE);
+26 -12
View File
@@ -2,22 +2,36 @@
const appRoot = require('app-root-path')
const { logger } = require(`${appRoot}/utils/logger`)
exports.authenticate = function () {
exports.authenticate = async function () {
try {
logger.debug('authenticate -> Entering Function.')
const authBody = '{"client_id":"' + process.env.AUTH_CLIENT_ID
+ '","client_secret": "' + process.env.AUTH_CLIENT_SECRET
+ '","audience":"' + process.env.AUTH_AUDIENCE
+ '","grant_type":"client_credentials"}'
if (!global.ACCESS_TOKEN) {
logger.debug('authenticate -> Entering Function.')
return axios({
url: process.env.AUTH_URL,
method: 'post',
data: authBody,
headers: { 'content-type': 'application/json' }
})
const authBody = '{"client_id":"' + process.env.AUTH_CLIENT_ID
+ '","client_secret": "' + process.env.AUTH_CLIENT_SECRET
+ '","audience":"' + process.env.AUTH_AUDIENCE
+ '","grant_type":"client_credentials"}'
let authResponse = await axios({
url: process.env.AUTH_URL,
method: 'post',
data: authBody,
headers: { 'content-type': 'application/json' }
})
if (!authResponse.data.errors)
global.ACCESS_TOKEN = authResponse.data.access_token
else throw new Error(operationsResponse.data.errors[0].message)
process.env.AUTH_CLIENT_ID = ""
process.env.AUTH_CLIENT_SECRET = ""
process.env.AUTH_AUDIENCE = ""
process.env.AUTH_URL = ""
}
return global.ACCESS_TOKEN
} catch (error) {
logger.error('authenticate -> Error: ' + error.stack)
throw new Error('There has been an error on the authentication: ' + error)