diff --git a/.vs/AACloudPlatform/v15/.suo b/.vs/AACloudPlatform/v15/.suo index 01866f77d..aac30a4db 100644 Binary files a/.vs/AACloudPlatform/v15/.suo and b/.vs/AACloudPlatform/v15/.suo differ diff --git a/AAMariam.azure.storage.connstring b/AAMariam.azure.storage.connstring deleted file mode 100644 index 94e460b0e..000000000 --- a/AAMariam.azure.storage.connstring +++ /dev/null @@ -1,7 +0,0 @@ -{ -"useDevelopmentStorage": false, -"connectionString": "DefaultEndpointsProtocol=https;AccountName=aatestnet;AccountKey=rQRuD8KeD0upqcN9532zqZTknKwkYJDpGzkATGptk9lIEovkLchdOGOJVld26cUjpzTA4enxsxpCB33B0pOZRg==;EndpointSuffix=core.windows.net", -"accountName": "", -"accountKey": "", -"sas": "" -} \ No newline at end of file diff --git a/AAOlivia.azure.storage.connstring b/AAOlivia.azure.storage.connstring deleted file mode 100644 index 94e460b0e..000000000 --- a/AAOlivia.azure.storage.connstring +++ /dev/null @@ -1,7 +0,0 @@ -{ -"useDevelopmentStorage": false, -"connectionString": "DefaultEndpointsProtocol=https;AccountName=aatestnet;AccountKey=rQRuD8KeD0upqcN9532zqZTknKwkYJDpGzkATGptk9lIEovkLchdOGOJVld26cUjpzTA4enxsxpCB33B0pOZRg==;EndpointSuffix=core.windows.net", -"accountName": "", -"accountKey": "", -"sas": "" -} \ No newline at end of file diff --git a/AATom.azure.storage.connstring b/AATom.azure.storage.connstring deleted file mode 100644 index 94e460b0e..000000000 --- a/AATom.azure.storage.connstring +++ /dev/null @@ -1,7 +0,0 @@ -{ -"useDevelopmentStorage": false, -"connectionString": "DefaultEndpointsProtocol=https;AccountName=aatestnet;AccountKey=rQRuD8KeD0upqcN9532zqZTknKwkYJDpGzkATGptk9lIEovkLchdOGOJVld26cUjpzTA4enxsxpCB33B0pOZRg==;EndpointSuffix=core.windows.net", -"accountName": "", -"accountKey": "", -"sas": "" -} \ No newline at end of file diff --git a/Assistant.js b/Assistant.js index 00f591499..adab23e4a 100644 --- a/Assistant.js +++ b/Assistant.js @@ -20,6 +20,7 @@ const logger = DEBUG_MODULE.newDebugLog(); logger.fileName = MODULE_NAME; + logger.bot = bot; let exchangePositions = []; // These are the open positions at the exchange at the account the bot is authorized to use. let openPositions = []; // These are the open positions the bot knows it made by itself. diff --git a/Azure File Storage.js b/Azure File Storage.js index 62e538245..88838ed24 100644 --- a/Azure File Storage.js +++ b/Azure File Storage.js @@ -15,7 +15,7 @@ exports.newAzureFileStorage = function newAzureFileStorage(BOT) { const DEBUG_MODULE = require('./Debug Log'); const logger = DEBUG_MODULE.newDebugLog(); - logger.pFileName = MODULE_NAME; + logger.fileName = MODULE_NAME; logger.bot = bot; const shareName = 'data'; @@ -45,28 +45,50 @@ exports.newAzureFileStorage = function newAzureFileStorage(BOT) { dataOwner = pDataOwnerBotCodeName; } - fileService = storage.createFileService(readConfig().connectionString); + readConnectionStringConfigFile(onConnectionStringReady); - callBackFunction(global.DEFAULT_OK_RESPONSE); + function onConnectionStringReady(err, pConnObj) { + + if (err.result !== global.DEFAULT_OK_RESPONSE.result) { + logger.write("[ERROR] initialize -> onConnectionStringReady -> err = " + err.message); + callBackFunction(err); + return; + } + + try { + fileService = storage.createFileService(pConnObj.connectionString); + callBackFunction(global.DEFAULT_OK_RESPONSE); + + } catch (err) { + + logger.write("[ERROR] initialize -> onConnectionStringReady -> createFileService -> err = " + err.message); + callBackFunction(err); + return; + } + } + + function readConnectionStringConfigFile(callBack) { + + let filePath; + + try { + let fs = require('fs'); + filePath = '../' + 'Connection-Strings' + '/' + global.RUNNING_MODE + '/' + dataOwner + '.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); + } + } } catch (err) { logger.write("[ERROR] initialize -> err = " + err.message); - callBackFunction(global.DEFAULT_FAIL_RESPONSE); - } - } - - function readConfig() { - - try { - let fs = require('fs'); - let filePath = '../' + 'Connection-Strings' + '/' + global.RUNNING_MODE + '/' + dataOwner + '.azure.storage.connstring' + '.json'; - return JSON.parse(fs.readFileSync(filePath, 'utf8')); - } - catch (err) { - logger.write("[ERROR] readConfig -> err = " + err.message); - logger.write("[HINT] You need to have a file at this path -> " + filePath); - logger.write("[HINT] 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); + callBack(global.DEFAULT_FAIL_RESPONSE); } } diff --git a/Bruce.azure.storage.connstring b/Bruce.azure.storage.connstring deleted file mode 100644 index 94e460b0e..000000000 --- a/Bruce.azure.storage.connstring +++ /dev/null @@ -1,7 +0,0 @@ -{ -"useDevelopmentStorage": false, -"connectionString": "DefaultEndpointsProtocol=https;AccountName=aatestnet;AccountKey=rQRuD8KeD0upqcN9532zqZTknKwkYJDpGzkATGptk9lIEovkLchdOGOJVld26cUjpzTA4enxsxpCB33B0pOZRg==;EndpointSuffix=core.windows.net", -"accountName": "", -"accountKey": "", -"sas": "" -} \ No newline at end of file diff --git a/Carol.azure.storage.connstring b/Carol.azure.storage.connstring deleted file mode 100644 index 94e460b0e..000000000 --- a/Carol.azure.storage.connstring +++ /dev/null @@ -1,7 +0,0 @@ -{ -"useDevelopmentStorage": false, -"connectionString": "DefaultEndpointsProtocol=https;AccountName=aatestnet;AccountKey=rQRuD8KeD0upqcN9532zqZTknKwkYJDpGzkATGptk9lIEovkLchdOGOJVld26cUjpzTA4enxsxpCB33B0pOZRg==;EndpointSuffix=core.windows.net", -"accountName": "", -"accountKey": "", -"sas": "" -} \ No newline at end of file diff --git a/Charly.azure.storage.connstring b/Charly.azure.storage.connstring deleted file mode 100644 index 94e460b0e..000000000 --- a/Charly.azure.storage.connstring +++ /dev/null @@ -1,7 +0,0 @@ -{ -"useDevelopmentStorage": false, -"connectionString": "DefaultEndpointsProtocol=https;AccountName=aatestnet;AccountKey=rQRuD8KeD0upqcN9532zqZTknKwkYJDpGzkATGptk9lIEovkLchdOGOJVld26cUjpzTA4enxsxpCB33B0pOZRg==;EndpointSuffix=core.windows.net", -"accountName": "", -"accountKey": "", -"sas": "" -} \ No newline at end of file diff --git a/Context.js b/Context.js index 17cb9412f..a861fb5f5 100644 --- a/Context.js +++ b/Context.js @@ -58,6 +58,7 @@ const logger = DEBUG_MODULE.newDebugLog(); logger.fileName = MODULE_NAME; + logger.bot = bot; /* Storage account to be used here. */ diff --git a/Datasource.js b/Datasource.js index e5640df49..4190d36cd 100644 --- a/Datasource.js +++ b/Datasource.js @@ -22,7 +22,7 @@ const logger = DEBUG_MODULE.newDebugLog(); logger.fileName = MODULE_NAME; - + logger.bot = bot; let marketFilesPeriods = '[' + diff --git a/ExchangeAPI.js b/ExchangeAPI.js index 0cf8b0ed0..c2ac09e49 100644 --- a/ExchangeAPI.js +++ b/ExchangeAPI.js @@ -22,6 +22,7 @@ const logger = DEBUG_MODULE.newDebugLog(); logger.fileName = MODULE_NAME; + logger.bot = bot; let poloniexApiClient; diff --git a/Legacy.azure.storage.connstring b/Legacy.azure.storage.connstring deleted file mode 100644 index 9f6ac1b4c..000000000 --- a/Legacy.azure.storage.connstring +++ /dev/null @@ -1,7 +0,0 @@ -{ -"useDevelopmentStorage": false, -"connectionString": "DefaultEndpointsProtocol=https;AccountName=aadata;AccountKey=YOu76OjlJX9T1QTWbj5cvqyYXTdufW1jISNyrtr8RlUK++kVIdm/TnYuyLJzp8kptAEhbQnN4PP3c6SoPLvR+A==;EndpointSuffix=core.windows.net", -"accountName": "", -"accountKey": "", -"sas": "" -} \ No newline at end of file diff --git a/Run.js b/Run.js index f237d2f75..62ec40e08 100644 --- a/Run.js +++ b/Run.js @@ -201,9 +201,9 @@ function runTradingBot(pProcessConfig) { if (err.result === global.DEFAULT_OK_RESPONSE.result) { - tradingBot.start(whenStartFinishes); + tradingBot.run(whenRunFinishes); - function whenStartFinishes(err) { + function whenRunFinishes(err) { if (err.result === global.DEFAULT_OK_RESPONSE.result) { diff --git a/TradingBot.js b/TradingBot.js index dee106d1b..cd85d020c 100644 --- a/TradingBot.js +++ b/TradingBot.js @@ -15,7 +15,7 @@ thisObject = { initialize: initialize, - start: start + run: run }; let processConfig; @@ -38,17 +38,17 @@ } } - function start(callBackFunction) { + function run(callBackFunction) { try { - if (FULL_LOG === true) { logger.write("[INFO] start -> Entering function."); } + if (FULL_LOG === true) { logger.write("[INFO] run -> Entering function."); } loop(); function loop() { try { - if (FULL_LOG === true) { logger.write("[INFO] start -> loop -> Entering function."); } + if (FULL_LOG === true) { logger.write("[INFO] run -> loop -> Entering function."); } /* We define here all the modules that the rest of the infraestructure, including the bots themselves can consume. */ @@ -88,7 +88,7 @@ if (err.result === global.DEFAULT_OK_RESPONSE.result) { initializeDatasource(); } else { - logger.write("[ERROR] start -> loop -> initializeContext -> err = " + err.message); + logger.write("[ERROR] run -> loop -> initializeContext -> err = " + err.message); callBackFunction(err); } } @@ -104,7 +104,7 @@ if (err.result === global.DEFAULT_OK_RESPONSE.result) { initializeExchangeAPI(); } else { - logger.write("[ERROR] start -> loop -> initializeDatasource -> err = " + err.message); + logger.write("[ERROR] run -> loop -> initializeDatasource -> err = " + err.message); callBackFunction(err); } } @@ -120,7 +120,7 @@ if (err.result === global.DEFAULT_OK_RESPONSE.result) { initializeAssistant(); } else { - logger.write("[ERROR] start -> loop -> initializeExchangeAPI -> err = " + err.message); + logger.write("[ERROR] run -> loop -> initializeExchangeAPI -> err = " + err.message); callBackFunction(err); } } @@ -136,7 +136,7 @@ if (err.result === global.DEFAULT_OK_RESPONSE.result) { initializeUserBot(); } else { - logger.write("[ERROR] start -> loop -> initializeAssistant -> err = " + err.message); + logger.write("[ERROR] run -> loop -> initializeAssistant -> err = " + err.message); callBackFunction(err); } } @@ -160,7 +160,7 @@ if (err.result === global.DEFAULT_OK_RESPONSE.result) { startUserBot(); } else { - logger.write("[ERROR] start -> loop -> initializeUserBot -> err = " + err.message); + logger.write("[ERROR] run -> loop -> initializeUserBot -> err = " + err.message); callBackFunction(err); } } @@ -168,7 +168,7 @@ function startUserBot() { - usertBot.start(platform, onFinished); + usertBot.run(platform, onFinished); function onFinished(err) { @@ -186,7 +186,7 @@ } break; case global.DEFAULT_FAIL_RESPONSE.result: { // This is an unexpected exception that we do not know how to handle. - logger.write("[ERROR] start -> loop -> startUserBot -> Operation Failed. Aborting the process."); + logger.write("[ERROR] run -> loop -> startUserBot -> Operation Failed. Aborting the process."); callBackFunction(err); return; } @@ -204,14 +204,14 @@ if (err.result === global.DEFAULT_OK_RESPONSE.result) { loopControl(nextWaitTime); } else { - logger.write("[ERROR] start -> loop -> saveContext -> err = " + err.message); + logger.write("[ERROR] run -> loop -> saveContext -> err = " + err.message); callBackFunction(err); } } } } catch (err) { - logger.write("[ERROR] start -> loop -> err = " + err.message); + logger.write("[ERROR] run -> loop -> err = " + err.message); callBackFunction(err); } } @@ -222,12 +222,12 @@ switch (nextWaitTime) { case 'Normal': { - if (FULL_LOG === true) { logger.write("[INFO] start -> loopControl -> Restarting Loop in " + (processConfig.executionWaitTime / 1000) + " seconds."); } + if (FULL_LOG === true) { logger.write("[INFO] run -> loopControl -> Restarting Loop in " + (processConfig.executionWaitTime / 1000) + " seconds."); } setTimeout(loop, processConfig.executionWaitTime); } break; case 'Retry': { - if (FULL_LOG === true) { logger.write("[INFO] start -> loopControl -> Restarting Loop in " + (processConfig.retryWaitTime / 1000) + " seconds."); } + if (FULL_LOG === true) { logger.write("[INFO] run -> loopControl -> Restarting Loop in " + (processConfig.retryWaitTime / 1000) + " seconds."); } setTimeout(loop, processConfig.retryWaitTime); } break; @@ -236,7 +236,7 @@ } catch (err) { - logger.write("[ERROR] start -> err = " + err.message); + logger.write("[ERROR] run -> err = " + err.message); } } };