Bot Config read from the cloud

This commit is contained in:
Luis Fernando Molina committed 2018-05-22 09:36:47 +02:00
1 parent 664d05be29
commit 5b8de349b2
4 files changed
+436 -443

No files matched your search

+16 -72
View File
@@ -27,12 +27,11 @@ exports.newBlobStorage = function newBlobStorage(BOT) {
let readOnlyBlobService;
let writeOnlyBlobService;
let containerName;
let devTeamDataOwner;
let environment = global.STORAGE_CONN_STRING_FOLDER;
return thisObject;
function initialize(pBotDataOwner, callBackFunction, disableLogging) {
function initialize(pDataOwner, callBackFunction, disableLogging) {
try {
@@ -45,89 +44,34 @@ exports.newBlobStorage = function newBlobStorage(BOT) {
logger.initialize();
}
if (pBotDataOwner === undefined) {
containerName = pDataOwner.toLowerCase();
devTeamDataOwner = bot.devTeam;
containerName = 'aamasters';
logger.fileName = MODULE_NAME + '.' + pDataOwner.devTeam + '.' + pDataOwner.bot + '.' + containerName;
logger.fileName = MODULE_NAME + '.' + bot.devTeam + '.' + bot.codeName + '.' + containerName;
} else {
if (pDataOwner.environment !== undefined) { // This is use for data migration from one environment to the other.
devTeamDataOwner = pBotDataOwner.devTeam;
containerName = pBotDataOwner.devTeam.toLowerCase();
environment = pDataOwner.environment;
logger.fileName = MODULE_NAME + '.' + pBotDataOwner.devTeam + '.' + pBotDataOwner.bot + '.' + containerName;
if (pBotDataOwner.environment !== undefined) {
environment = pBotDataOwner.environment;
logger.fileName = MODULE_NAME + '.' + pBotDataOwner.devTeam + '.' + pBotDataOwner.bot + '.' + containerName;
}
logger.fileName = MODULE_NAME + '.' + pDataOwner.devTeam + '.' + pDataOwner.bot + '.' + containerName;
}
if (FULL_LOG === true) { logger.write("[INFO] initialize -> Entering function."); }
if (FULL_LOG === true) { logger.write("[INFO] initialize -> environment = " + environment); }
if (FULL_LOG === true) { logger.write("[INFO] initialize -> containerName = " + containerName); }
if (FULL_LOG === true) { logger.write("[INFO] initialize -> devTeamDataOwner = " + devTeamDataOwner); }
readConnectionStringConfigFile(onConnectionStringReady);
function onConnectionStringReady(err, pConnObj) {
if (err.result !== global.DEFAULT_OK_RESPONSE.result) {
logger.write("[ERROR] initialize -> onConnectionStringReady -> err = " + err.message);
callBackFunction(err);
return;
}
try {
if (pConnObj.readConnectionString !== "") {
readOnlyBlobService = storage.createBlobService(pConnObj.readConnectionString);
}
if (pConnObj.writeConnectionString !== "") {
writeOnlyBlobService = storage.createBlobService(pConnObj.writeConnectionString);
}
if (readOnlyBlobService !== undefined || writeOnlyBlobService !== undefined) {
callBackFunction(global.DEFAULT_OK_RESPONSE);
return;
}
logger.write("[ERROR] initialize -> onConnectionStringReady -> Either a readConnectionString or writeConnectionString must be provided.");
callBackFunction(global.DEFAULT_FAIL_RESPONSE);
return;
} catch (err) {
logger.write("[ERROR] initialize -> onConnectionStringReady -> createFileService -> err = " + err.message);
callBackFunction(err);
return;
}
if (global.STORAGE_PERMISSIONS[environment][containerName].readConnectionString !== undefined) {
readOnlyBlobService = storage.createBlobService(global.STORAGE_PERMISSIONS[environment][containerName].readConnectionString);
}
function readConnectionStringConfigFile(callBack) {
let filePath;
try {
let fs = require('fs');
filePath = '../' + 'Connection-Strings' + '/' + environment + '/' + devTeamDataOwner + '.azure.storage.connstring';
let connObj = JSON.parse(fs.readFileSync(filePath, 'utf8'));
callBack(global.DEFAULT_OK_RESPONSE, connObj);
}
catch (err) {
logger.write("[ERROR] readConnectionStringConfigFile -> err = " + err.message);
logger.write("[HINT] readConnectionStringConfigFile -> You need to have a file at this path -> " + filePath);
logger.write("[HINT] readConnectionStringConfigFile -> The file must have the connection string to the Azure Storage Account. Request the file to an AA Team Member if you dont have it.");
callBackFunction(global.DEFAULT_FAIL_RESPONSE);
}
if (global.STORAGE_PERMISSIONS[environment][containerName].writeConnectionString !== undefined) {
writeOnlyBlobService = storage.createBlobService(global.STORAGE_PERMISSIONS[environment][containerName].writeConnectionString);
}
if (readOnlyBlobService !== undefined || writeOnlyBlobService !== undefined) {
callBackFunction(global.DEFAULT_OK_RESPONSE);
return;
}
}
catch (err) {
logger.write("[ERROR] initialize -> err = " + err.message);
+383 -329
View File
@@ -30,8 +30,8 @@ exports.newRoot = function newRoot() {
}
catch (err) {
console.log("[ERROR] Root -> readConfig -> Error Reading the AACloud Config File.");
console.log("[ERROR] Root -> readConfig -> err.message = " + err.message);
console.log("[ERROR] Root -> start -> Error Reading the AACloud Config File.");
console.log("[ERROR] Root -> start -> err.message = " + err.message);
return;
}
@@ -145,7 +145,9 @@ exports.newRoot = function newRoot() {
if (listItem.enabled !== "true") {
console.log("[INFO] Skipping process " + listItem.process + " for being disabled. ");
console.log("[INFO] Root -> start -> Skipping process for being disabled.");
console.log("[INFO] Root -> start -> listItem.process = " + listItem.process);
continue;
}
@@ -153,425 +155,477 @@ exports.newRoot = function newRoot() {
let botConfig;
try {
getBotConfig();
function getBotConfig() {
try {
console.log("[INFO] Root -> start -> getBotConfig -> Entering function. ");
const BLOB_STORAGE = require(ROOT_DIR + 'BlobStorage');
let cloudStorage = BLOB_STORAGE.newBlobStorage(listItem);
cloudStorage.initialize("AAPlatform", onInizialized, true);
function onInizialized(err) {
if (err.result === global.DEFAULT_OK_RESPONSE.result) {
let filePath = listItem.devTeam + "/" + listItem.repo;
let fileName = "this.bot.config.json";
cloudStorage.getTextFile(filePath, fileName, onFileReceived);
function onFileReceived(err, text) {
if (err.result !== global.DEFAULT_OK_RESPONSE.result) {
console.log("[ERROR] Root -> start -> getBotConfig -> onInizialized -> onFileReceived -> err = " + err.message);
callBack(err);
return;
}
try {
botConfig = JSON.parse(text);
findProcess();
} catch (err) {
}
}
} else {
console.log("[ERROR] Root -> start -> getBotConfig -> onInizialized -> err = " + err.message);
callBackFunction(err);
}
}
}
catch (err) {
console.log("[ERROR] Root -> start -> getBotConfig -> err.message = " + err.message);
return;
}
let botConfigFile = fs.readFileSync(listItem.botPath + '/this.bot.config.json', 'utf8');
botConfig = JSON.parse(botConfigFile);
}
catch (err) {
console.log("[ERROR] Root -> readBotConfig -> err.message = " + err.message);
return;
}
botConfig.process = listItem.process;
botConfig.debug = {};
function findProcess() {
logger = DEBUG_MODULE.newDebugLog();
logger.fileName = MODULE_NAME;
logger.bot = botConfig;
try {
console.log("[INFO] Root -> start -> findProcess -> Entering function. ");
/* Loop Counter */
botConfig.process = listItem.process;
botConfig.debug = {};
botConfig.loopCounter = 0;
logger = DEBUG_MODULE.newDebugLog();
logger.fileName = MODULE_NAME;
logger.bot = botConfig;
if (FULL_LOG === true) { logger.write("[INFO] Root -> Processing item from executionList -> p = " + p); }
if (FULL_LOG === true) { logger.write("[INFO] Root -> listItem.botPath = " + listItem.botPath); }
/* Loop Counter */
/* File Path Root */
botConfig.loopCounter = 0;
botConfig.filePathRoot = botConfig.devTeam + "/" + botConfig.codeName + "." + botConfig.version.major + "." + botConfig.version.minor + "/" + global.PLATFORM_CONFIG.codeName + "." + global.PLATFORM_CONFIG.version.major + "." + global.PLATFORM_CONFIG.version.minor + "/" + global.EXCHANGE_NAME + "/" + botConfig.dataSetVersion;
if (FULL_LOG === true) { logger.write("[INFO] Root -> Processing item from executionList -> p = " + p); }
if (FULL_LOG === true) { logger.write("[INFO] Root -> listItem.botPath = " + listItem.botPath); }
if (FULL_LOG === true) { logger.write("[INFO] Root -> listItem.process = " + listItem.process); }
/* File Path Root */
/* Now we loop throug all the configured processes at each bots configuration until we find the one we are supposed to run at this Node.js process. */
botConfig.filePathRoot = botConfig.devTeam + "/" + botConfig.codeName + "." + botConfig.version.major + "." + botConfig.version.minor + "/" + global.PLATFORM_CONFIG.codeName + "." + global.PLATFORM_CONFIG.version.major + "." + global.PLATFORM_CONFIG.version.minor + "/" + global.EXCHANGE_NAME + "/" + botConfig.dataSetVersion;
let processFound = false;
if (FULL_LOG === true) { logger.write("[INFO] Root -> listItem.process = " + listItem.process); }
for (let i = 0; i < botConfig.processes.length; i++) {
/* Now we loop throug all the configured processes at each bots configuration until we find the one we are supposed to run at this Node.js process. */
if (botConfig.processes[i].name === listItem.process) {
let processFound = false;
processFound = true;
if (FULL_LOG === true) { logger.write("[INFO] Root -> Process found at the bot configuration file. -> listItem.process = " + listItem.process); }
for (let i = 0; i < botConfig.processes.length; i++) {
let processConfig = botConfig.processes[i];
if (botConfig.processes[i].name === listItem.process) {
try {
processFound = true;
if (FULL_LOG === true) { logger.write("[INFO] Root -> Process found at the bot configuration file. -> listItem.process = " + listItem.process); }
/* We tesst each type of start Mode to get what to run and how. */
let processConfig = botConfig.processes[i];
if (processConfig.startMode.allMonths !== undefined) {
try {
if (processConfig.startMode.allMonths.run === "true") {
/* We tesst each type of start Mode to get what to run and how. */
if (FULL_LOG === true) { logger.write("[INFO] Root -> allMonths start mode detected. "); }
if (processConfig.startMode.allMonths !== undefined) {
for (let year = processConfig.startMode.allMonths.maxYear; year >= processConfig.startMode.allMonths.minYear; year--) {
if (processConfig.startMode.allMonths.run === "true") {
for (let month = 12; month > 0; month--) {
if (FULL_LOG === true) { logger.write("[INFO] Root -> start -> findProcess -> allMonths start mode detected. "); }
botConfig.debug = {
month: pad(month, 2),
year: pad(year, 4)
};
for (let year = processConfig.startMode.allMonths.maxYear; year >= processConfig.startMode.allMonths.minYear; year--) {
let padMonth = pad(month, 2)
for (let month = 12; month > 0; month--) {
let newInstanceBotConfig = JSON.parse(JSON.stringify(botConfig));
botConfig.debug = {
month: pad(month, 2),
year: pad(year, 4)
};
let timeDelay = Math.random() * 10 * 1000; // We introduce a short delay so as to not overload the machine.
setTimeout(startProcess, timeDelay);
let padMonth = pad(month, 2)
function startProcess() {
let newInstanceBotConfig = JSON.parse(JSON.stringify(botConfig));
if (FULL_LOG === true) { logger.write("[INFO] Root -> startProcess -> Ready to start process."); }
let timeDelay = Math.random() * 10 * 1000; // We introduce a short delay so as to not overload the machine.
setTimeout(startProcess, timeDelay);
switch (botConfig.type) {
case 'Extraction': {
runExtractionBot(newInstanceBotConfig, processConfig, padMonth, year);
break;
}
case 'Indicator': {
runIndicatorBot(newInstanceBotConfig, processConfig, padMonth, year);
break;
}
default: {
logger.write("[ERROR] Root -> Unexpected bot type. -> botConfig.type = " + botConfig.type);
function startProcess() {
if (FULL_LOG === true) { logger.write("[INFO] Root -> start -> findProcess -> startProcess -> Ready to start process."); }
switch (botConfig.type) {
case 'Extraction': {
runExtractionBot(newInstanceBotConfig, processConfig, padMonth, year);
break;
}
case 'Indicator': {
runIndicatorBot(newInstanceBotConfig, processConfig, padMonth, year);
break;
}
default: {
logger.write("[ERROR] Root -> start -> findProcess -> startProcess -> Unexpected bot type. -> botConfig.type = " + botConfig.type);
}
}
}
}
}
}
}
}
}
if (processConfig.startMode.oneMonth !== undefined) {
if (processConfig.startMode.oneMonth !== undefined) {
if (processConfig.startMode.oneMonth.run === "true") {
if (processConfig.startMode.oneMonth.run === "true") {
if (FULL_LOG === true) { logger.write("[INFO] Root -> oneMonth start mode detected. "); }
if (FULL_LOG === true) { logger.write("[INFO] Root -> start -> findProcess -> oneMonth start mode detected. "); }
startProcess();
startProcess();
function startProcess() {
function startProcess() {
if (FULL_LOG === true) { logger.write("[INFO] Root -> startProcess -> Ready to start process."); }
if (FULL_LOG === true) { logger.write("[INFO] Root -> start -> findProcess -> startProcess -> Ready to start process."); }
let month = pad(processConfig.startMode.oneMonth.month, 2);
let year = processConfig.startMode.oneMonth.year;
let month = pad(processConfig.startMode.oneMonth.month, 2);
let year = processConfig.startMode.oneMonth.year;
botConfig.debug = {
month: pad(month, 2),
year: pad(year, 4)
};
botConfig.debug = {
month: pad(month, 2),
year: pad(year, 4)
};
switch (botConfig.type) {
case 'Extraction': {
runExtractionBot(botConfig, processConfig, month, year);
break;
}
case 'Indicator': {
runIndicatorBot(botConfig, processConfig, month, year);
break;
}
default: {
logger.write("[ERROR] Root -> Unexpected bot type. -> botConfig.type = " + botConfig.type);
switch (botConfig.type) {
case 'Extraction': {
runExtractionBot(botConfig, processConfig, month, year);
break;
}
case 'Indicator': {
runIndicatorBot(botConfig, processConfig, month, year);
break;
}
default: {
logger.write("[ERROR] Root -> start -> findProcess -> startProcess -> Unexpected bot type. -> botConfig.type = " + botConfig.type);
}
}
}
}
}
if (processConfig.startMode.noTime !== undefined) {
if (processConfig.startMode.noTime.run === "true") {
let month = pad((new Date()).getUTCMonth() + 1, 2);
let year = (new Date()).getUTCFullYear();
if (processConfig.startMode.noTime.resumeExecution === "true") {
botConfig.hasTheBotJustStarted = false;
} else {
botConfig.hasTheBotJustStarted = true;
}
switch (botConfig.type) {
case 'Extraction': {
runExtractionBot(botConfig, processConfig, month, year);
break;
}
case 'Indicator': {
runIndicatorBot(botConfig, processConfig, month, year);
break;
}
default: {
logger.write("[ERROR] Root -> start -> findProcess -> Unexpected bot type. -> botConfig.type = " + botConfig.type);
}
}
}
}
if (processConfig.startMode.fixedInterval !== undefined) {
if (processConfig.startMode.fixedInterval.run === "true") {
botConfig.runAtFixedInterval = true;
botConfig.fixedInterval = processConfig.startMode.fixedInterval.interval;
let month = pad((new Date()).getUTCMonth() + 1, 2);
let year = (new Date()).getUTCFullYear();
switch (botConfig.type) {
case 'Extraction': {
runExtractionBot(botConfig, processConfig, month, year);
break;
}
default: {
logger.write("[ERROR] Root -> start -> findProcess -> Unexpected bot type. -> botConfig.type = " + botConfig.type);
}
}
}
}
if (processConfig.startMode.live !== undefined) {
if (processConfig.startMode.live.run === "true") {
botConfig.runMode = "Live";
let month = pad((new Date()).getUTCMonth() + 1, 2);
let year = (new Date()).getUTCFullYear();
if (processConfig.startMode.live.resumeExecution === "true") {
botConfig.hasTheBotJustStarted = false;
} else {
botConfig.hasTheBotJustStarted = true;
}
switch (botConfig.type) {
case 'Trading': {
runTradingBot(botConfig, processConfig);
break;
}
default: {
logger.write("[ERROR] Root -> start -> findProcess -> Unexpected bot type. -> botConfig.type = " + botConfig.type);
}
}
}
}
if (processConfig.startMode.backtest !== undefined) {
if (processConfig.startMode.backtest.run === "true") {
botConfig.runMode = "Backtest";
botConfig.backtest = processConfig.startMode.backtest;
/* We override these waitTimes to the one specified at the backtest configuration. */
processConfig.normalWaitTime = processConfig.startMode.backtest.waitTime;
processConfig.retryWaitTime = processConfig.startMode.backtest.waitTime;
/* Backtest Mode does not support Resume Execution, so this is the only way. */
botConfig.hasTheBotJustStarted = true;
switch (botConfig.type) {
case 'Trading': {
runTradingBot(botConfig, processConfig);
break;
}
default: {
logger.write("[ERROR] Root -> start -> findProcess -> Unexpected bot type. -> botConfig.type = " + botConfig.type);
}
}
}
}
if (processConfig.startMode.competition !== undefined) {
if (processConfig.startMode.competition.run === "true") {
botConfig.runMode = "Competition";
botConfig.competition = processConfig.startMode.competition;
if (processConfig.startMode.competition.resumeExecution === "true") {
botConfig.hasTheBotJustStarted = false;
} else {
botConfig.hasTheBotJustStarted = true;
}
switch (botConfig.type) {
case 'Trading': {
runTradingBot(botConfig, processConfig);
break;
}
default: {
logger.write("[ERROR] Root -> start -> findProcess -> Unexpected bot type. -> botConfig.type = " + botConfig.type);
}
}
}
}
} catch (err) {
logger.write("[ERROR] Root -> start -> findProcess -> Unexpected exception. -> err.message = " + err.message);
}
}
if (processConfig.startMode.noTime !== undefined) {
if (processConfig.startMode.noTime.run === "true") {
let month = pad((new Date()).getUTCMonth() + 1, 2);
let year = (new Date()).getUTCFullYear();
if (processConfig.startMode.noTime.resumeExecution === "true") {
botConfig.hasTheBotJustStarted = false;
} else {
botConfig.hasTheBotJustStarted = true;
}
switch (botConfig.type) {
case 'Extraction': {
runExtractionBot(botConfig, processConfig, month, year);
break;
}
case 'Indicator': {
runIndicatorBot(botConfig, processConfig, month, year);
break;
}
default: {
logger.write("[ERROR] Root -> Unexpected bot type. -> botConfig.type = " + botConfig.type);
}
}
}
}
if (processConfig.startMode.fixedInterval !== undefined) {
if (processConfig.startMode.fixedInterval.run === "true") {
botConfig.runAtFixedInterval = true;
botConfig.fixedInterval = processConfig.startMode.fixedInterval.interval;
let month = pad((new Date()).getUTCMonth() + 1, 2);
let year = (new Date()).getUTCFullYear();
switch (botConfig.type) {
case 'Extraction': {
runExtractionBot(botConfig, processConfig, month, year);
break;
}
default: {
logger.write("[ERROR] Root -> Unexpected bot type. -> botConfig.type = " + botConfig.type);
}
}
}
}
if (processConfig.startMode.live !== undefined) {
if (processConfig.startMode.live.run === "true") {
botConfig.runMode = "Live";
let month = pad((new Date()).getUTCMonth() + 1, 2);
let year = (new Date()).getUTCFullYear();
if (processConfig.startMode.live.resumeExecution === "true") {
botConfig.hasTheBotJustStarted = false;
} else {
botConfig.hasTheBotJustStarted = true;
}
switch (botConfig.type) {
case 'Trading': {
runTradingBot(botConfig, processConfig);
break;
}
default: {
logger.write("[ERROR] Root -> Unexpected bot type. -> botConfig.type = " + botConfig.type);
}
}
}
}
if (processConfig.startMode.backtest !== undefined) {
if (processConfig.startMode.backtest.run === "true") {
botConfig.runMode = "Backtest";
botConfig.backtest = processConfig.startMode.backtest;
/* We override these waitTimes to the one specified at the backtest configuration. */
processConfig.normalWaitTime = processConfig.startMode.backtest.waitTime;
processConfig.retryWaitTime = processConfig.startMode.backtest.waitTime;
/* Backtest Mode does not support Resume Execution, so this is the only way. */
botConfig.hasTheBotJustStarted = true;
switch (botConfig.type) {
case 'Trading': {
runTradingBot(botConfig, processConfig);
break;
}
default: {
logger.write("[ERROR] Root -> Unexpected bot type. -> botConfig.type = " + botConfig.type);
}
}
}
}
if (processConfig.startMode.competition !== undefined) {
if (processConfig.startMode.competition.run === "true") {
botConfig.runMode = "Competition";
botConfig.competition = processConfig.startMode.competition;
if (processConfig.startMode.competition.resumeExecution === "true") {
botConfig.hasTheBotJustStarted = false;
} else {
botConfig.hasTheBotJustStarted = true;
}
switch (botConfig.type) {
case 'Trading': {
runTradingBot(botConfig, processConfig);
break;
}
default: {
logger.write("[ERROR] Root -> Unexpected bot type. -> botConfig.type = " + botConfig.type);
}
}
}
}
} catch (err) {
logger.write("[ERROR] Root -> Unexpected exception. -> err.message = " + err.message);
}
}
}
if (processFound === false) {
if (processFound === false) {
logger.write("[ERROR] Root -> Process listed at the configuration file of AACloud not found at the configuration file of the bot. -> listItem.process = " + listItem.process);
}
logger.write("[ERROR] Root -> Process listed at the configuration file of AACloud not found at the configuration file of the bot. -> listItem.process = " + listItem.process);
}
function runExtractionBot(pBotConfig, pProcessConfig, pMonth, pYear) {
function runExtractionBot(pBotConfig, pProcessConfig, pMonth, pYear) {
try {
if (FULL_LOG === true) { logger.write("[INFO] runExtractionBot -> Entering function."); }
if (FULL_LOG === true) { logger.write("[INFO] runExtractionBot -> pMonth = " + pMonth); }
if (FULL_LOG === true) { logger.write("[INFO] runExtractionBot -> pYear = " + pYear); }
try {
if (FULL_LOG === true) { logger.write("[INFO] Root -> start -> findProcess ->runExtractionBot -> Entering function."); }
if (FULL_LOG === true) { logger.write("[INFO] Root -> start -> findProcess ->runExtractionBot -> pMonth = " + pMonth); }
if (FULL_LOG === true) { logger.write("[INFO] Root -> start -> findProcess ->runExtractionBot -> pYear = " + pYear); }
let extractionBotMainLoop = EXTRACTION_BOT_MAIN_LOOP_MODULE.newExtractionBotMainLoop(pBotConfig);
extractionBotMainLoop.initialize(listItem.botPath, pProcessConfig, onInitializeReady);
let extractionBotMainLoop = EXTRACTION_BOT_MAIN_LOOP_MODULE.newExtractionBotMainLoop(pBotConfig);
extractionBotMainLoop.initialize(listItem.botPath, pProcessConfig, onInitializeReady);
function onInitializeReady(err) {
if (err.result === global.DEFAULT_OK_RESPONSE.result) {
extractionBotMainLoop.run(pMonth, pYear, whenRunFinishes);
function whenRunFinishes(err) {
let botId;
if (pYear !== undefined) {
botId = pBotConfig.devTeam + "." + pBotConfig.codeName + "." + pBotConfig.process + "." + pYear + "." + pMonth;
} else {
botId = pBotConfig.devTeam + "." + pBotConfig.codeName + "." + pBotConfig.process;
}
function onInitializeReady(err) {
if (err.result === global.DEFAULT_OK_RESPONSE.result) {
logger.write("[INFO] runExtractionBot -> onInitializeReady -> whenStartFinishes -> Bot execution finished sucessfully. :-)");
logger.write("[INFO] runExtractionBot -> onInitializeReady -> whenStartFinishes -> Bot Id = " + botId);
console.log(botId + " Bot execution finished sucessfully. :-)");
extractionBotMainLoop.run(pMonth, pYear, whenRunFinishes);
function whenRunFinishes(err) {
let botId;
if (pYear !== undefined) {
botId = pBotConfig.devTeam + "." + pBotConfig.codeName + "." + pBotConfig.process + "." + pYear + "." + pMonth;
} else {
botId = pBotConfig.devTeam + "." + pBotConfig.codeName + "." + pBotConfig.process;
}
if (err.result === global.DEFAULT_OK_RESPONSE.result) {
logger.write("[INFO] Root -> start -> findProcess -> runExtractionBot -> onInitializeReady -> whenStartFinishes -> Bot execution finished sucessfully. :-)");
logger.write("[INFO] Root -> start -> findProcess -> runExtractionBot -> onInitializeReady -> whenStartFinishes -> Bot Id = " + botId);
console.log(botId + " Bot execution finished sucessfully. :-)");
} else {
logger.write("[ERROR] Root -> start -> findProcess -> runExtractionBot -> onInitializeReady -> whenStartFinishes -> err = " + err.message);
logger.write("[ERROR] Root -> start -> findProcess -> runExtractionBot -> onInitializeReady -> whenStartFinishes -> Execution will be stopped. ");
logger.write("[ERROR] Root -> start -> findProcess -> runExtractionBot -> onInitializeReady -> whenStartFinishes -> Bye. :-(");
logger.write("[ERROR] Root -> start -> findProcess -> runExtractionBot -> onInitializeReady -> whenStartFinishes -> Bot Id = " + botId);
console.log(botId + " Bot execution finished with errors. Please check the logs. :-(");
}
}
} else {
logger.write("[ERROR] runExtractionBot -> onInitializeReady -> whenStartFinishes -> err = " + err.message);
logger.write("[ERROR] runExtractionBot -> onInitializeReady -> whenStartFinishes -> Execution will be stopped. ");
logger.write("[ERROR] runExtractionBot -> onInitializeReady -> whenStartFinishes -> Bye. :-(");
logger.write("[ERROR] runExtractionBot -> onInitializeReady -> whenStartFinishes -> Bot Id = " + botId);
console.log(botId + " Bot execution finished with errors. Please check the logs. :-(");
logger.write("[ERROR] runExtractionBot -> onInitializeReady -> err = " + err.message);
logger.write("[ERROR] runExtractionBot -> onInitializeReady -> Bot will not be started. ");
}
}
} else {
logger.write("[ERROR] runExtractionBot -> onInitializeReady -> err = " + err.message);
logger.write("[ERROR] runExtractionBot -> onInitializeReady -> Bot will not be started. ");
}
catch (err) {
logger.write("[ERROR] runExtractionBot -> err = " + err.message);
}
}
}
catch (err) {
logger.write("[ERROR] runExtractionBot -> err = " + err.message);
}
}
function runIndicatorBot(pBotConfig, pProcessConfig, pMonth, pYear) {
function runIndicatorBot(pBotConfig, pProcessConfig, pMonth, pYear) {
try {
if (FULL_LOG === true) { logger.write("[INFO] runIndicatorBot -> Entering function."); }
if (FULL_LOG === true) { logger.write("[INFO] runIndicatorBot -> pMonth = " + pMonth); }
if (FULL_LOG === true) { logger.write("[INFO] runIndicatorBot -> pYear = " + pYear); }
try {
if (FULL_LOG === true) { logger.write("[INFO] Root -> start -> findProcess -> runIndicatorBot -> Entering function."); }
if (FULL_LOG === true) { logger.write("[INFO] Root -> start -> findProcess -> runIndicatorBot -> pMonth = " + pMonth); }
if (FULL_LOG === true) { logger.write("[INFO] Root -> start -> findProcess -> runIndicatorBot -> pYear = " + pYear); }
let indicatorBotMainLoop = INDICATOR_BOT_MAIN_LOOP_MODULE.newIndicatorBotMainLoop(pBotConfig);
indicatorBotMainLoop.initialize(listItem.botPath, pProcessConfig, onInitializeReady);
let indicatorBotMainLoop = INDICATOR_BOT_MAIN_LOOP_MODULE.newIndicatorBotMainLoop(pBotConfig);
indicatorBotMainLoop.initialize(listItem.botPath, pProcessConfig, onInitializeReady);
function onInitializeReady(err) {
if (err.result === global.DEFAULT_OK_RESPONSE.result) {
indicatorBotMainLoop.run(pMonth, pYear, whenRunFinishes);
function whenRunFinishes(err) {
let botId;
if (pYear !== undefined) {
botId = pBotConfig.devTeam + "." + pBotConfig.codeName + "." + pBotConfig.process + "." + pYear + "." + pMonth;
} else {
botId = pBotConfig.devTeam + "." + pBotConfig.codeName + "." + pBotConfig.process;
}
function onInitializeReady(err) {
if (err.result === global.DEFAULT_OK_RESPONSE.result) {
logger.write("[INFO] runIndicatorBot -> onInitializeReady -> whenStartFinishes -> Bot execution finished sucessfully. :-)");
logger.write("[INFO] runIndicatorBot -> onInitializeReady -> whenStartFinishes -> Bot Id = " + botId);
console.log(botId + " Bot execution finished sucessfully. :-)");
indicatorBotMainLoop.run(pMonth, pYear, whenRunFinishes);
function whenRunFinishes(err) {
let botId;
if (pYear !== undefined) {
botId = pBotConfig.devTeam + "." + pBotConfig.codeName + "." + pBotConfig.process + "." + pYear + "." + pMonth;
} else {
botId = pBotConfig.devTeam + "." + pBotConfig.codeName + "." + pBotConfig.process;
}
if (err.result === global.DEFAULT_OK_RESPONSE.result) {
logger.write("[INFO] Root -> start -> findProcess -> runIndicatorBot -> onInitializeReady -> whenStartFinishes -> Bot execution finished sucessfully. :-)");
logger.write("[INFO] Root -> start -> findProcess -> runIndicatorBot -> onInitializeReady -> whenStartFinishes -> Bot Id = " + botId);
console.log(botId + " Bot execution finished sucessfully. :-)");
} else {
logger.write("[ERROR] Root -> start -> findProcess -> runIndicatorBot -> onInitializeReady -> whenStartFinishes -> err = " + err.message);
logger.write("[ERROR] Root -> start -> findProcess -> runIndicatorBot -> onInitializeReady -> whenStartFinishes -> Execution will be stopped. ");
logger.write("[ERROR] Root -> start -> findProcess -> runIndicatorBot -> onInitializeReady -> whenStartFinishes -> Bye. :-(");
logger.write("[ERROR] Root -> start -> findProcess -> runIndicatorBot -> onInitializeReady -> whenStartFinishes -> Bot Id = " + botId);
console.log(botId + " Bot execution finished with errors. Please check the logs. :-(");
}
}
} else {
logger.write("[ERROR] runIndicatorBot -> onInitializeReady -> whenStartFinishes -> err = " + err.message);
logger.write("[ERROR] runIndicatorBot -> onInitializeReady -> whenStartFinishes -> Execution will be stopped. ");
logger.write("[ERROR] runIndicatorBot -> onInitializeReady -> whenStartFinishes -> Bye. :-(");
logger.write("[ERROR] runIndicatorBot -> onInitializeReady -> whenStartFinishes -> Bot Id = " + botId);
console.log(botId + " Bot execution finished with errors. Please check the logs. :-(");
logger.write("[ERROR] Root -> start -> findProcess -> runIndicatorBot -> onInitializeReady -> err = " + err.message);
logger.write("[ERROR] Root -> start -> findProcess -> runIndicatorBot -> onInitializeReady -> Bot will not be started. ");
}
}
} else {
logger.write("[ERROR] runIndicatorBot -> onInitializeReady -> err = " + err.message);
logger.write("[ERROR] runIndicatorBot -> onInitializeReady -> Bot will not be started. ");
}
catch (err) {
logger.write("[ERROR] runIndicatorBot -> err = " + err.message);
}
}
}
catch (err) {
logger.write("[ERROR] runIndicatorBot -> err = " + err.message);
}
}
function runTradingBot(pBotConfig, pProcessConfig) {
function runTradingBot(pBotConfig, pProcessConfig) {
try {
if (FULL_LOG === true) { logger.write("[INFO] runTradingBot -> Entering function."); }
try {
if (FULL_LOG === true) { logger.write("[INFO] Root -> start -> findProcess -> runTradingBot -> Entering function."); }
let tradingBotMainLoop = TRADING_BOT_MAIN_LOOP_MODULE.newTradingBotMainLoop(pBotConfig);
tradingBotMainLoop.initialize(listItem.botPath, pProcessConfig, onInitializeReady);
let tradingBotMainLoop = TRADING_BOT_MAIN_LOOP_MODULE.newTradingBotMainLoop(pBotConfig);
tradingBotMainLoop.initialize(listItem.botPath, pProcessConfig, onInitializeReady);
function onInitializeReady(err) {
if (err.result === global.DEFAULT_OK_RESPONSE.result) {
tradingBotMainLoop.run(whenRunFinishes);
function whenRunFinishes(err) {
let botId;
botId = pBotConfig.devTeam + "." + pBotConfig.codeName + "." + pBotConfig.process;
function onInitializeReady(err) {
if (err.result === global.DEFAULT_OK_RESPONSE.result) {
logger.write("[INFO] runTradingBot -> onInitializeReady -> whenStartFinishes -> Bot execution finished sucessfully. :-)");
logger.write("[INFO] runTradingBot -> onInitializeReady -> whenStartFinishes -> Bot Id = " + botId);
console.log(botId + " Bot execution finished sucessfully. :-)");
tradingBotMainLoop.run(whenRunFinishes);
function whenRunFinishes(err) {
let botId;
botId = pBotConfig.devTeam + "." + pBotConfig.codeName + "." + pBotConfig.process;
if (err.result === global.DEFAULT_OK_RESPONSE.result) {
logger.write("[INFO] Root -> start -> findProcess -> runTradingBot -> onInitializeReady -> whenStartFinishes -> Bot execution finished sucessfully. :-)");
logger.write("[INFO] Root -> start -> findProcess -> runTradingBot -> onInitializeReady -> whenStartFinishes -> Bot Id = " + botId);
console.log(botId + " Bot execution finished sucessfully. :-)");
} else {
logger.write("[ERROR] Root -> start -> findProcess -> runTradingBot -> onInitializeReady -> whenStartFinishes -> err = " + err.message);
logger.write("[ERROR] Root -> start -> findProcess -> runTradingBot -> onInitializeReady -> whenStartFinishes -> Execution will be stopped. ");
logger.write("[ERROR] Root -> start -> findProcess -> runTradingBot -> onInitializeReady -> whenStartFinishes -> Bye. :-(");
logger.write("[ERROR] Root -> start -> findProcess -> runTradingBot -> onInitializeReady -> whenStartFinishes -> Bot Id = " + botId);
console.log(botId + " Bot execution finished with errors. Please check the logs. :-(");
}
}
} else {
logger.write("[ERROR] runTradingBot -> onInitializeReady -> whenStartFinishes -> err = " + err.message);
logger.write("[ERROR] runTradingBot -> onInitializeReady -> whenStartFinishes -> Execution will be stopped. ");
logger.write("[ERROR] runTradingBot -> onInitializeReady -> whenStartFinishes -> Bye. :-(");
logger.write("[ERROR] runTradingBot -> onInitializeReady -> whenStartFinishes -> Bot Id = " + botId);
console.log(botId + " Bot execution finished with errors. Please check the logs. :-(");
logger.write("[ERROR] Root -> start -> findProcess -> runTradingBot -> onInitializeReady -> err = " + err.message);
logger.write("[ERROR] Root -> start -> findProcess -> runTradingBot -> onInitializeReady -> Bot will not be started. ");
}
}
} else {
logger.write("[ERROR] runTradingBot -> onInitializeReady -> err = " + err.message);
logger.write("[ERROR] runTradingBot -> onInitializeReady -> Bot will not be started. ");
}
catch (err) {
logger.write("[ERROR] Root -> start -> findProcess -> runTradingBot -> err = " + err.message);
}
}
}
catch (err) {
logger.write("[ERROR] runTradingBot -> err = " + err.message);
logger.write("[ERROR] Root -> start -> findProcess -> err.message = " + err.message);
return;
}
}
}
+33 -5
View File
@@ -24,9 +24,37 @@ process.on('exit', function (code) {
}
});
const ROOT_DIR = './';
const ROOT_MODULE = require(ROOT_DIR + 'Root');
let root = ROOT_MODULE.newRoot();
global.STORAGE_PERMISSIONS = {};
readConnectionStringConfigFile();
function readConnectionStringConfigFile(environment, devTeamDataOwner) {
let filePath;
try {
let fs = require('fs');
filePath = '../' + 'Connection-Strings' + '/' + 'Storage.Permissions.json';
global.STORAGE_PERMISSIONS = JSON.parse(fs.readFileSync(filePath, 'utf8'));
startRoot();
}
catch (err) {
console.log("[ERROR] readConnectionStringConfigFile -> err = " + err.message);
console.log("[HINT] readConnectionStringConfigFile -> You need to have a file at this path -> " + filePath);
console.log("[HINT] readConnectionStringConfigFile -> The file must have the connection string to the Azure Storage Account. Request the file to an AA Team Member if you dont have it.");
callBackFunction(global.DEFAULT_FAIL_RESPONSE);
}
}
function startRoot() {
const ROOT_DIR = './';
const ROOT_MODULE = require(ROOT_DIR + 'Root');
let root = ROOT_MODULE.newRoot();
root.initialize();
root.start();
}
root.initialize();
root.start();
+4 -37
View File
@@ -8,43 +8,10 @@
"executionList": [
{
"enabled": "true",
"botPath": "../Bots/AAMasters/AAMariam-Trading-Bot",
"process": "Trading-Process"
},
{
"enabled": "false",
"botPath": "../Bots/AAMasters/AAOlivia-Indicator-Bot",
"process": "Multi-Period-Market"
},
{
"enabled": "false",
"botPath": "../Bots/AAMasters/AAOlivia-Indicator-Bot",
"process": "Multi-Period-Daily"
},
{
"enabled": "false",
"botPath": "../Bots/AAMasters/AABruce-Indicator-Bot",
"process": "One-Min-Daily-Candles-Volumes"
},
{
"enabled": "false",
"botPath": "../Bots/AAMasters/AACharly-Extraction-Bot",
"process": "Poloniex-Hole-Fixing"
},
{
"enabled": "false",
"botPath": "../Bots/AAMasters/AACharly-Extraction-Bot",
"process": "Poloniex-Live-Trades"
},
{
"enabled": "false",
"botPath": "../Bots/AAMasters/AAMiguel-Indicator-Bot",
"process": "Trades-Blobs-To-Blobs"
},
{
"enabled": "false",
"botPath": "../Bots/AASpartans/AADumbo-Trading-Bot",
"process": "Trading-Process"
"devTeam": "AAMasters",
"bot": "AAMariam",
"process": "Trading-Process",
"repo": "AAMariam-Trading-Bot"
}
],
"stopGracefully": "false",