diff --git a/.vs/AACloud/v15/.suo b/.vs/AACloud/v15/.suo index 147d6c648..0f0ea9c30 100644 Binary files a/.vs/AACloud/v15/.suo and b/.vs/AACloud/v15/.suo differ diff --git a/Blob Storage.js b/Blob Storage.js index 32b22b57d..0b6b30c18 100644 --- a/Blob Storage.js +++ b/Blob Storage.js @@ -2,7 +2,7 @@ exports.newBlobStorage = function newBlobStorage(BOT) { const FULL_LOG = true; - const LOG_FILE_CONTENT = false; + const LOG_FILE_CONTENT = true; let bot = BOT; const ROOT_DIR = './'; diff --git a/Extraction Bot Process Main Loop.js b/Extraction Bot Process Main Loop.js index 0be707e46..64b9ce369 100644 --- a/Extraction Bot Process Main Loop.js +++ b/Extraction Bot Process Main Loop.js @@ -94,157 +94,205 @@ function initializeStatusDependencies() { - if (FULL_LOG === true) { logger.write("[INFO] run -> loop -> initializeStatusDependencies -> Entering function."); } + try { - statusDependencies = STATUS_DEPENDENCIES.newStatusDependencies(bot, DEBUG_MODULE, STATUS_REPORT, BLOB_STORAGE, UTILITIES); + if (FULL_LOG === true) { logger.write("[INFO] run -> loop -> initializeStatusDependencies -> Entering function."); } - statusDependencies.initialize(processConfig.statusDependencies, pMonth, pYear, onInizialized); + statusDependencies = STATUS_DEPENDENCIES.newStatusDependencies(bot, DEBUG_MODULE, STATUS_REPORT, BLOB_STORAGE, UTILITIES); - function onInizialized(err) { + statusDependencies.initialize(processConfig.statusDependencies, pMonth, pYear, onInizialized); - switch (err.result) { - case global.DEFAULT_OK_RESPONSE.result: { - logger.write("[INFO] run -> loop -> initializeStatusDependencies -> onInizialized > Execution finished well. :-)"); - initializeUserBot(); - return; - } - case global.DEFAULT_RETRY_RESPONSE.result: { // Something bad happened, but if we retry in a while it might go through the next time. - logger.write("[ERROR] run -> loop -> initializeStatusDependencies -> onInizialized > Retry Later. Requesting Execution Retry."); - nextWaitTime = 'Retry'; - loopControl(nextWaitTime); - return; - } - case global.DEFAULT_FAIL_RESPONSE.result: { // This is an unexpected exception that we do not know how to handle. - logger.write("[ERROR] run -> loop -> initializeStatusDependencies -> onInizialized > Operation Failed. Aborting the process."); + function onInizialized(err) { + + try { + + if (FULL_LOG === true) { logger.write("[INFO] run -> loop -> initializeStatusDependencies -> onInizialized -> Entering function."); } + + switch (err.result) { + case global.DEFAULT_OK_RESPONSE.result: { + logger.write("[INFO] run -> loop -> initializeStatusDependencies -> onInizialized -> Execution finished well. :-)"); + initializeUserBot(); + return; + } + case global.DEFAULT_RETRY_RESPONSE.result: { // Something bad happened, but if we retry in a while it might go through the next time. + logger.write("[ERROR] run -> loop -> initializeStatusDependencies -> onInizialized -> Retry Later. Requesting Execution Retry."); + nextWaitTime = 'Retry'; + loopControl(nextWaitTime); + return; + } + case global.DEFAULT_FAIL_RESPONSE.result: { // This is an unexpected exception that we do not know how to handle. + logger.write("[ERROR] run -> loop -> initializeStatusDependencies -> onInizialized -> Operation Failed. Aborting the process."); + callBackFunction(err); + return; + } + default: { + logger.write("[ERROR] run -> loop -> initializeStatusDependencies -> onInizialized -> Unhandled err.result received. -> err.result = " + err.result); + logger.write("[ERROR] run -> loop -> initializeStatusDependencies -> onInizialized -> Unhandled err.result received. -> err.message = " + err.message); + + callBackFunction(global.DEFAULT_FAIL_RESPONSE); + return; + } + } + + } catch (err) { + logger.write("[ERROR] run -> loop -> initializeStatusDependencies -> onInizialized -> err = " + err.message); callBackFunction(err); - return; - } - default: { - logger.write("[ERROR] run -> loop -> initializeStatusDependencies -> onInizialized > Unhandled err.result received. -> err.result = " + err.result); - logger.write("[ERROR] run -> loop -> initializeStatusDependencies -> onInizialized > Unhandled err.result received. -> err.message = " + err.message); - - callBackFunction(global.DEFAULT_FAIL_RESPONSE); - return; } } + + } catch (err) { + logger.write("[ERROR] run -> loop -> initializeStatusDependencies -> err = " + err.message); + callBackFunction(err); } } function initializeUserBot() { - if (FULL_LOG === true) { logger.write("[INFO] run -> loop -> initializeUserBot -> Entering function."); } + try { - usertBot = USER_BOT_MODULE.newUserBot(bot, COMMONS_MODULE, UTILITIES, DEBUG_MODULE, BLOB_STORAGE, STATUS_REPORT, POLONIEX_CLIENT_MODULE); + if (FULL_LOG === true) { logger.write("[INFO] run -> loop -> initializeUserBot -> Entering function."); } - usertBot.initialize(statusDependencies, pMonth, pYear, onInizialized); + usertBot = USER_BOT_MODULE.newUserBot(bot, COMMONS_MODULE, UTILITIES, DEBUG_MODULE, BLOB_STORAGE, STATUS_REPORT, POLONIEX_CLIENT_MODULE); - function onInizialized(err) { + usertBot.initialize(statusDependencies, pMonth, pYear, onInizialized); - switch (err.result) { - case global.DEFAULT_OK_RESPONSE.result: { - logger.write("[INFO] run -> loop -> initializeUserBot -> onInizialized > Execution finished well. :-)"); - startUserBot(); - return; - } - case global.DEFAULT_RETRY_RESPONSE.result: { // Something bad happened, but if we retry in a while it might go through the next time. - logger.write("[ERROR] run -> loop -> initializeUserBot -> onInizialized > Retry Later. Requesting Execution Retry."); - nextWaitTime = 'Retry'; - loopControl(nextWaitTime); - return; - } - case global.DEFAULT_FAIL_RESPONSE.result: { // This is an unexpected exception that we do not know how to handle. - logger.write("[ERROR] run -> loop -> initializeUserBot -> onInizialized > Operation Failed. Aborting the process."); + function onInizialized(err) { + + try { + + if (FULL_LOG === true) { logger.write("[INFO] run -> loop -> initializeUserBot -> onInizialized -> Entering function."); } + + switch (err.result) { + case global.DEFAULT_OK_RESPONSE.result: { + logger.write("[INFO] run -> loop -> initializeUserBot -> onInizialized > Execution finished well. :-)"); + startUserBot(); + return; + } + case global.DEFAULT_RETRY_RESPONSE.result: { // Something bad happened, but if we retry in a while it might go through the next time. + logger.write("[ERROR] run -> loop -> initializeUserBot -> onInizialized > Retry Later. Requesting Execution Retry."); + nextWaitTime = 'Retry'; + loopControl(nextWaitTime); + return; + } + case global.DEFAULT_FAIL_RESPONSE.result: { // This is an unexpected exception that we do not know how to handle. + logger.write("[ERROR] run -> loop -> initializeUserBot -> onInizialized > Operation Failed. Aborting the process."); + callBackFunction(err); + return; + } + default: { + logger.write("[ERROR] run -> loop -> initializeUserBot -> onInizialized > Unhandled err.result received. -> err.result = " + err.result); + logger.write("[ERROR] run -> loop -> initializeUserBot -> onInizialized > Unhandled err.result received. -> err.message = " + err.message); + + callBackFunction(global.DEFAULT_FAIL_RESPONSE); + return; + } + } + + } catch (err) { + logger.write("[ERROR] run -> loop -> initializeUserBot -> onInizialized -> err = " + err.message); callBackFunction(err); - return; - } - default: { - logger.write("[ERROR] run -> loop -> initializeUserBot -> onInizialized > Unhandled err.result received. -> err.result = " + err.result); - logger.write("[ERROR] run -> loop -> initializeUserBot -> onInizialized > Unhandled err.result received. -> err.message = " + err.message); - - callBackFunction(global.DEFAULT_FAIL_RESPONSE); - return; } } + + } catch (err) { + logger.write("[ERROR] run -> loop -> initializeUserBot -> err = " + err.message); + callBackFunction(err); } } function startUserBot() { - if (FULL_LOG === true) { logger.write("[INFO] run -> loop -> startUserBot -> Entering function."); } + try { - usertBot.start(onFinished); + if (FULL_LOG === true) { logger.write("[INFO] run -> loop -> startUserBot -> Entering function."); } - function onFinished(err) { + usertBot.start(onFinished); - switch (err.result) { - case global.DEFAULT_OK_RESPONSE.result: { - logger.write("[INFO] run -> loop -> startUserBot -> onFinished > Execution finished well. :-)"); - nextWaitTime = 'Normal'; - loopControl(nextWaitTime); - return; - } - case global.DEFAULT_RETRY_RESPONSE.result: { // Something bad happened, but if we retry in a while it might go through the next time. - logger.write("[ERROR] run -> loop -> startUserBot -> onFinished > Retry Later. Requesting Execution Retry."); - nextWaitTime = 'Retry'; - loopControl(nextWaitTime); - return; - } - case global.DEFAULT_FAIL_RESPONSE.result: { // This is an unexpected exception that we do not know how to handle. - logger.write("[ERROR] run -> loop -> startUserBot -> onFinished > Operation Failed. Aborting the process."); - callBackFunction(err); - return; - } - case global.CUSTOM_OK_RESPONSE.result: { + function onFinished(err) { - switch (err.message) { - case "Dependency does not exist.": { - logger.write("[WARN] run -> loop -> startUserBot -> onFinished > Dependency does not exist. This Loop will go to sleep."); - nextWaitTime = 'Sleep'; + try { + + if (FULL_LOG === true) { logger.write("[INFO] run -> loop -> startUserBot -> onFinished -> Entering function."); } + + switch (err.result) { + case global.DEFAULT_OK_RESPONSE.result: { + logger.write("[INFO] run -> loop -> startUserBot -> onFinished > Execution finished well. :-)"); + nextWaitTime = 'Normal'; loopControl(nextWaitTime); return; } - case "Dependency not ready.": { - logger.write("[WARN] run -> loop -> startUserBot -> onFinished > Dependency not ready. This Loop will go to sleep."); - nextWaitTime = 'Sleep'; + case global.DEFAULT_RETRY_RESPONSE.result: { // Something bad happened, but if we retry in a while it might go through the next time. + logger.write("[ERROR] run -> loop -> startUserBot -> onFinished > Retry Later. Requesting Execution Retry."); + nextWaitTime = 'Retry'; loopControl(nextWaitTime); return; } - case "Month before it is needed.": { - logger.write("[WARN] run -> loop -> startUserBot -> onFinished > Month before it is needed. This Loop will be terminated."); - callBackFunction(global.DEFAULT_OK_RESPONSE); - return; - } - case "Month fully processed.": { - logger.write("[WARN] run -> loop -> startUserBot -> onFinished > Month fully processed. This Loop will be terminated."); - callBackFunction(global.DEFAULT_OK_RESPONSE); - return; - } - case "End of the month reached.": { - logger.write("[WARN] run -> loop -> startUserBot -> onFinished > End of the month reached. This Loop will be terminated."); - callBackFunction(global.DEFAULT_OK_RESPONSE); - return; - } - case "Too far in the future.": { - logger.write("[WARN] run -> loop -> startUserBot -> onFinished > Too far in the future. This Loop will enter in coma."); - nextWaitTime = 'Coma'; - loopControl(nextWaitTime); - return; - } - default: { - logger.write("[ERROR] run -> loop -> startUserBot -> onFinished > Unhandled custom response received. -> err.message = " + err.message); + case global.DEFAULT_FAIL_RESPONSE.result: { // This is an unexpected exception that we do not know how to handle. + logger.write("[ERROR] run -> loop -> startUserBot -> onFinished > Operation Failed. Aborting the process."); callBackFunction(err); return; } - } - } - default: { - logger.write("[ERROR] run -> loop -> startUserBot -> onFinished > Unhandled err.result received. -> err.result = " + err.result); - logger.write("[ERROR] run -> loop -> startUserBot -> onFinished > Unhandled err.result received. -> err.message = " + err.message); + case global.CUSTOM_OK_RESPONSE.result: { - callBackFunction(global.DEFAULT_FAIL_RESPONSE); - return; + switch (err.message) { + case "Dependency does not exist.": { + logger.write("[WARN] run -> loop -> startUserBot -> onFinished > Dependency does not exist. This Loop will go to sleep."); + nextWaitTime = 'Sleep'; + loopControl(nextWaitTime); + return; + } + case "Dependency not ready.": { + logger.write("[WARN] run -> loop -> startUserBot -> onFinished > Dependency not ready. This Loop will go to sleep."); + nextWaitTime = 'Sleep'; + loopControl(nextWaitTime); + return; + } + case "Month before it is needed.": { + logger.write("[WARN] run -> loop -> startUserBot -> onFinished > Month before it is needed. This Loop will be terminated."); + callBackFunction(global.DEFAULT_OK_RESPONSE); + return; + } + case "Month fully processed.": { + logger.write("[WARN] run -> loop -> startUserBot -> onFinished > Month fully processed. This Loop will be terminated."); + callBackFunction(global.DEFAULT_OK_RESPONSE); + return; + } + case "End of the month reached.": { + logger.write("[WARN] run -> loop -> startUserBot -> onFinished > End of the month reached. This Loop will be terminated."); + callBackFunction(global.DEFAULT_OK_RESPONSE); + return; + } + case "Too far in the future.": { + logger.write("[WARN] run -> loop -> startUserBot -> onFinished > Too far in the future. This Loop will enter in coma."); + nextWaitTime = 'Coma'; + loopControl(nextWaitTime); + return; + } + default: { + logger.write("[ERROR] run -> loop -> startUserBot -> onFinished > Unhandled custom response received. -> err.message = " + err.message); + callBackFunction(err); + return; + } + } + } + default: { + logger.write("[ERROR] run -> loop -> startUserBot -> onFinished > Unhandled err.result received. -> err.result = " + err.result); + logger.write("[ERROR] run -> loop -> startUserBot -> onFinished > Unhandled err.result received. -> err.message = " + err.message); + + callBackFunction(global.DEFAULT_FAIL_RESPONSE); + return; + } + } + + } catch (err) { + logger.write("[ERROR] run -> loop -> startUserBot -> onFinished -> err = " + err.message); + callBackFunction(err); } } + + } catch (err) { + logger.write("[ERROR] run -> loop -> startUserBot -> err = " + err.message); + callBackFunction(err); } } diff --git a/Indicator Bot Process Main Loop.js b/Indicator Bot Process Main Loop.js index 28fc84534..d787ecc72 100644 --- a/Indicator Bot Process Main Loop.js +++ b/Indicator Bot Process Main Loop.js @@ -84,157 +84,205 @@ function initializeStatusDependencies() { - if (FULL_LOG === true) { logger.write("[INFO] run -> loop -> initializeStatusDependencies -> Entering function."); } + try { - statusDependencies = STATUS_DEPENDENCIES.newStatusDependencies(bot, DEBUG_MODULE, STATUS_REPORT, BLOB_STORAGE, UTILITIES); + if (FULL_LOG === true) { logger.write("[INFO] run -> loop -> initializeStatusDependencies -> Entering function."); } - statusDependencies.initialize(processConfig.statusDependencies, pMonth, pYear, onInizialized); + statusDependencies = STATUS_DEPENDENCIES.newStatusDependencies(bot, DEBUG_MODULE, STATUS_REPORT, BLOB_STORAGE, UTILITIES); - function onInizialized(err) { + statusDependencies.initialize(processConfig.statusDependencies, pMonth, pYear, onInizialized); - switch (err.result) { - case global.DEFAULT_OK_RESPONSE.result: { - logger.write("[INFO] run -> loop -> initializeStatusDependencies -> onInizialized > Execution finished well. :-)"); - initializeUserBot(); - return; - } - case global.DEFAULT_RETRY_RESPONSE.result: { // Something bad happened, but if we retry in a while it might go through the next time. - logger.write("[ERROR] run -> loop -> initializeStatusDependencies -> onInizialized > Retry Later. Requesting Execution Retry."); - nextWaitTime = 'Retry'; - loopControl(nextWaitTime); - return; - } - case global.DEFAULT_FAIL_RESPONSE.result: { // This is an unexpected exception that we do not know how to handle. - logger.write("[ERROR] run -> loop -> initializeStatusDependencies -> onInizialized > Operation Failed. Aborting the process."); + function onInizialized(err) { + + try { + + if (FULL_LOG === true) { logger.write("[INFO] run -> loop -> initializeStatusDependencies -> onInizialized -> Entering function."); } + + switch (err.result) { + case global.DEFAULT_OK_RESPONSE.result: { + logger.write("[INFO] run -> loop -> initializeStatusDependencies -> onInizialized -> Execution finished well. :-)"); + initializeUserBot(); + return; + } + case global.DEFAULT_RETRY_RESPONSE.result: { // Something bad happened, but if we retry in a while it might go through the next time. + logger.write("[ERROR] run -> loop -> initializeStatusDependencies -> onInizialized -> Retry Later. Requesting Execution Retry."); + nextWaitTime = 'Retry'; + loopControl(nextWaitTime); + return; + } + case global.DEFAULT_FAIL_RESPONSE.result: { // This is an unexpected exception that we do not know how to handle. + logger.write("[ERROR] run -> loop -> initializeStatusDependencies -> onInizialized -> Operation Failed. Aborting the process."); + callBackFunction(err); + return; + } + default: { + logger.write("[ERROR] run -> loop -> initializeStatusDependencies -> onInizialized -> Unhandled err.result received. -> err.result = " + err.result); + logger.write("[ERROR] run -> loop -> initializeStatusDependencies -> onInizialized -> Unhandled err.result received. -> err.message = " + err.message); + + callBackFunction(global.DEFAULT_FAIL_RESPONSE); + return; + } + } + + } catch (err) { + logger.write("[ERROR] run -> loop -> initializeStatusDependencies -> onInizialized -> err = " + err.message); callBackFunction(err); - return; - } - default: { - logger.write("[ERROR] run -> loop -> initializeStatusDependencies -> onInizialized > Unhandled err.result received. -> err.result = " + err.result); - logger.write("[ERROR] run -> loop -> initializeStatusDependencies -> onInizialized > Unhandled err.result received. -> err.message = " + err.message); - - callBackFunction(global.DEFAULT_FAIL_RESPONSE); - return; } } + + } catch (err) { + logger.write("[ERROR] run -> loop -> initializeStatusDependencies -> err = " + err.message); + callBackFunction(err); } } function initializeUserBot() { - if (FULL_LOG === true) { logger.write("[INFO] run -> loop -> initializeUserBot -> Entering function."); } + try { - usertBot = USER_BOT_MODULE.newUserBot(bot, COMMONS_MODULE, UTILITIES, DEBUG_MODULE, BLOB_STORAGE, FILE_STORAGE); + if (FULL_LOG === true) { logger.write("[INFO] run -> loop -> initializeUserBot -> Entering function."); } - usertBot.initialize(statusDependencies, pMonth, pYear, onInizialized); + usertBot = USER_BOT_MODULE.newUserBot(bot, COMMONS_MODULE, UTILITIES, DEBUG_MODULE, BLOB_STORAGE, FILE_STORAGE); - function onInizialized(err) { + usertBot.initialize(statusDependencies, pMonth, pYear, onInizialized); - switch (err.result) { - case global.DEFAULT_OK_RESPONSE.result: { - logger.write("[INFO] run -> loop -> initializeUserBot -> onInizialized > Execution finished well. :-)"); - startUserBot(); - return; - } - case global.DEFAULT_RETRY_RESPONSE.result: { // Something bad happened, but if we retry in a while it might go through the next time. - logger.write("[ERROR] run -> loop -> initializeUserBot -> onInizialized > Retry Later. Requesting Execution Retry."); - nextWaitTime = 'Retry'; - loopControl(nextWaitTime); - return; - } - case global.DEFAULT_FAIL_RESPONSE.result: { // This is an unexpected exception that we do not know how to handle. - logger.write("[ERROR] run -> loop -> initializeUserBot -> onInizialized > Operation Failed. Aborting the process."); + function onInizialized(err) { + + try { + + if (FULL_LOG === true) { logger.write("[INFO] run -> loop -> initializeUserBot -> onInizialized -> Entering function."); } + + switch (err.result) { + case global.DEFAULT_OK_RESPONSE.result: { + logger.write("[INFO] run -> loop -> initializeUserBot -> onInizialized -> Execution finished well. :-)"); + startUserBot(); + return; + } + case global.DEFAULT_RETRY_RESPONSE.result: { // Something bad happened, but if we retry in a while it might go through the next time. + logger.write("[ERROR] run -> loop -> initializeUserBot -> onInizialized -> Retry Later. Requesting Execution Retry."); + nextWaitTime = 'Retry'; + loopControl(nextWaitTime); + return; + } + case global.DEFAULT_FAIL_RESPONSE.result: { // This is an unexpected exception that we do not know how to handle. + logger.write("[ERROR] run -> loop -> initializeUserBot -> onInizialized -> Operation Failed. Aborting the process."); + callBackFunction(err); + return; + } + default: { + logger.write("[ERROR] run -> loop -> initializeUserBot -> onInizialized -> Unhandled err.result received. -> err.result = " + err.result); + logger.write("[ERROR] run -> loop -> initializeUserBot -> onInizialized -> Unhandled err.result received. -> err.message = " + err.message); + + callBackFunction(global.DEFAULT_FAIL_RESPONSE); + return; + } + } + + } catch (err) { + logger.write("[ERROR] run -> loop -> initializeUserBot -> onInizialized -> err = " + err.message); callBackFunction(err); - return; - } - default: { - logger.write("[ERROR] run -> loop -> initializeUserBot -> onInizialized > Unhandled err.result received. -> err.result = " + err.result); - logger.write("[ERROR] run -> loop -> initializeUserBot -> onInizialized > Unhandled err.result received. -> err.message = " + err.message); - - callBackFunction(global.DEFAULT_FAIL_RESPONSE); - return; } } + + } catch (err) { + logger.write("[ERROR] run -> loop -> initializeUserBot -> err = " + err.message); + callBackFunction(err); } } function startUserBot() { - if (FULL_LOG === true) { logger.write("[INFO] run -> loop -> startUserBot -> Entering function."); } + try { - usertBot.start(onFinished); + if (FULL_LOG === true) { logger.write("[INFO] run -> loop -> startUserBot -> Entering function."); } - function onFinished(err) { + usertBot.start(onFinished); - switch (err.result) { - case global.DEFAULT_OK_RESPONSE.result: { - logger.write("[INFO] run -> loop -> startUserBot -> onFinished > Execution finished well. :-)"); - nextWaitTime = 'Normal'; - loopControl(nextWaitTime); - return; - } - case global.DEFAULT_RETRY_RESPONSE.result: { // Something bad happened, but if we retry in a while it might go through the next time. - logger.write("[ERROR] run -> loop -> startUserBot -> onFinished > Retry Later. Requesting Execution Retry."); - nextWaitTime = 'Retry'; - loopControl(nextWaitTime); - return; - } - case global.DEFAULT_FAIL_RESPONSE.result: { // This is an unexpected exception that we do not know how to handle. - logger.write("[ERROR] run -> loop -> startUserBot -> onFinished > Operation Failed. Aborting the process."); - callBackFunction(err); - return; - } - case global.CUSTOM_OK_RESPONSE.result: { + function onFinished(err) { - switch (err.message) { - case "Dependency does not exist.": { - logger.write("[WARN] run -> loop -> startUserBot -> onFinished > Dependency does not exist. This Loop will go to sleep."); - nextWaitTime = 'Sleep'; + try { + + if (FULL_LOG === true) { logger.write("[INFO] run -> loop -> startUserBot -> onFinished -> Entering function."); } + + switch (err.result) { + case global.DEFAULT_OK_RESPONSE.result: { + logger.write("[INFO] run -> loop -> startUserBot -> onFinished -> Execution finished well. :-)"); + nextWaitTime = 'Normal'; loopControl(nextWaitTime); return; } - case "Dependency not ready.": { - logger.write("[WARN] run -> loop -> startUserBot -> onFinished > Dependency not ready. This Loop will go to sleep."); - nextWaitTime = 'Sleep'; + case global.DEFAULT_RETRY_RESPONSE.result: { // Something bad happened, but if we retry in a while it might go through the next time. + logger.write("[ERROR] run -> loop -> startUserBot -> onFinished -> Retry Later. Requesting Execution Retry."); + nextWaitTime = 'Retry'; loopControl(nextWaitTime); return; } - case "Month before it is needed.": { - logger.write("[WARN] run -> loop -> startUserBot -> onFinished > Month before it is needed. This Loop will be terminated."); - callBackFunction(global.DEFAULT_OK_RESPONSE); - return; - } - case "Month fully processed.": { - logger.write("[WARN] run -> loop -> startUserBot -> onFinished > Month fully processed. This Loop will be terminated."); - callBackFunction(global.DEFAULT_OK_RESPONSE); - return; - } - case "End of the month reached.": { - logger.write("[WARN] run -> loop -> startUserBot -> onFinished > End of the month reached. This Loop will be terminated."); - callBackFunction(global.DEFAULT_OK_RESPONSE); - return; - } - case "Too far in the future.": { - logger.write("[WARN] run -> loop -> startUserBot -> onFinished > Too far in the future. This Loop will enter in coma."); - nextWaitTime = 'Coma'; - loopControl(nextWaitTime); - return; - } - default: { - logger.write("[ERROR] run -> loop -> startUserBot -> onFinished > Unhandled custom response received. -> err.message = " + err.message); + case global.DEFAULT_FAIL_RESPONSE.result: { // This is an unexpected exception that we do not know how to handle. + logger.write("[ERROR] run -> loop -> startUserBot -> onFinished -> Operation Failed. Aborting the process."); callBackFunction(err); return; } - } - } - default: { - logger.write("[ERROR] run -> loop -> startUserBot -> onFinished > Unhandled err.result received. -> err.result = " + err.result); - logger.write("[ERROR] run -> loop -> startUserBot -> onFinished > Unhandled err.result received. -> err.message = " + err.message); + case global.CUSTOM_OK_RESPONSE.result: { - callBackFunction(global.DEFAULT_FAIL_RESPONSE); - return; + switch (err.message) { + case "Dependency does not exist.": { + logger.write("[WARN] run -> loop -> startUserBot -> onFinished -> Dependency does not exist. This Loop will go to sleep."); + nextWaitTime = 'Sleep'; + loopControl(nextWaitTime); + return; + } + case "Dependency not ready.": { + logger.write("[WARN] run -> loop -> startUserBot -> onFinished -> Dependency not ready. This Loop will go to sleep."); + nextWaitTime = 'Sleep'; + loopControl(nextWaitTime); + return; + } + case "Month before it is needed.": { + logger.write("[WARN] run -> loop -> startUserBot -> onFinished -> Month before it is needed. This Loop will be terminated."); + callBackFunction(global.DEFAULT_OK_RESPONSE); + return; + } + case "Month fully processed.": { + logger.write("[WARN] run -> loop -> startUserBot -> onFinished -> Month fully processed. This Loop will be terminated."); + callBackFunction(global.DEFAULT_OK_RESPONSE); + return; + } + case "End of the month reached.": { + logger.write("[WARN] run -> loop -> startUserBot -> onFinished -> End of the month reached. This Loop will be terminated."); + callBackFunction(global.DEFAULT_OK_RESPONSE); + return; + } + case "Too far in the future.": { + logger.write("[WARN] run -> loop -> startUserBot -> onFinished -> Too far in the future. This Loop will enter in coma."); + nextWaitTime = 'Coma'; + loopControl(nextWaitTime); + return; + } + default: { + logger.write("[ERROR] run -> loop -> startUserBot -> onFinished -> Unhandled custom response received. -> err.message = " + err.message); + callBackFunction(err); + return; + } + } + } + default: { + logger.write("[ERROR] run -> loop -> startUserBot -> onFinished -> Unhandled err.result received. -> err.result = " + err.result); + logger.write("[ERROR] run -> loop -> startUserBot -> onFinished -> Unhandled err.result received. -> err.message = " + err.message); + + callBackFunction(global.DEFAULT_FAIL_RESPONSE); + return; + } + } + + } catch (err) { + logger.write("[ERROR] run -> loop -> startUserBot -> onFinished -> err = " + err.message); + callBackFunction(err); } } + + } catch (err) { + logger.write("[ERROR] run -> loop -> startUserBot -> err = " + err.message); + callBackFunction(err); } } diff --git a/Trading Bot Process Main Loop.js b/Trading Bot Process Main Loop.js index 0d886fe90..7a1d46026 100644 --- a/Trading Bot Process Main Loop.js +++ b/Trading Bot Process Main Loop.js @@ -186,299 +186,427 @@ function initializeStatusDependencies() { - if (FULL_LOG === true) { logger.write("[INFO] run -> loop -> initializeStatusDependencies -> Entering function."); } + try { - statusDependencies = STATUS_DEPENDENCIES.newStatusDependencies(bot, DEBUG_MODULE, STATUS_REPORT, BLOB_STORAGE, UTILITIES); + if (FULL_LOG === true) { logger.write("[INFO] run -> loop -> initializeStatusDependencies -> Entering function."); } - statusDependencies.initialize(processConfig.statusDependencies, undefined, undefined, onInizialized); + statusDependencies = STATUS_DEPENDENCIES.newStatusDependencies(bot, DEBUG_MODULE, STATUS_REPORT, BLOB_STORAGE, UTILITIES); - function onInizialized(err) { + statusDependencies.initialize(processConfig.statusDependencies, undefined, undefined, onInizialized); - switch (err.result) { - case global.DEFAULT_OK_RESPONSE.result: { - logger.write("[INFO] run -> loop -> initializeStatusDependencies -> onInizialized > Execution finished well. :-)"); - initializeDataDependencies(); - return; - } - case global.DEFAULT_RETRY_RESPONSE.result: { // Something bad happened, but if we retry in a while it might go through the next time. - logger.write("[ERROR] run -> loop -> initializeStatusDependencies -> onInizialized > Retry Later. Requesting Execution Retry."); - nextWaitTime = 'Retry'; - loopControl(nextWaitTime); - return; - } - case global.DEFAULT_FAIL_RESPONSE.result: { // This is an unexpected exception that we do not know how to handle. - logger.write("[ERROR] run -> loop -> initializeStatusDependencies -> onInizialized > Operation Failed. Aborting the process."); + function onInizialized(err) { + + try { + + if (FULL_LOG === true) { logger.write("[INFO] run -> loop -> initializeStatusDependencies -> onInizialized -> Entering function."); } + + switch (err.result) { + case global.DEFAULT_OK_RESPONSE.result: { + logger.write("[INFO] run -> loop -> initializeStatusDependencies -> onInizialized -> Execution finished well. :-)"); + initializeDataDependencies(); + return; + } + case global.DEFAULT_RETRY_RESPONSE.result: { // Something bad happened, but if we retry in a while it might go through the next time. + logger.write("[ERROR] run -> loop -> initializeStatusDependencies -> onInizialized -> Retry Later. Requesting Execution Retry."); + nextWaitTime = 'Retry'; + loopControl(nextWaitTime); + return; + } + case global.DEFAULT_FAIL_RESPONSE.result: { // This is an unexpected exception that we do not know how to handle. + logger.write("[ERROR] run -> loop -> initializeStatusDependencies -> onInizialized -> Operation Failed. Aborting the process."); + callBackFunction(err); + return; + } + default: { + logger.write("[ERROR] run -> loop -> initializeStatusDependencies -> onInizialized -> Unhandled err.result received. -> err.result = " + err.result); + logger.write("[ERROR] run -> loop -> initializeStatusDependencies -> onInizialized -> Unhandled err.result received. -> err.message = " + err.message); + + callBackFunction(global.DEFAULT_FAIL_RESPONSE); + return; + } + } + + } catch (err) { + logger.write("[ERROR] run -> loop -> initializeStatusDependencies -> onInizialized -> err = " + err.message); callBackFunction(err); - return; - } - default: { - logger.write("[ERROR] run -> loop -> initializeStatusDependencies -> onInizialized > Unhandled err.result received. -> err.result = " + err.result); - logger.write("[ERROR] run -> loop -> initializeStatusDependencies -> onInizialized > Unhandled err.result received. -> err.message = " + err.message); - - callBackFunction(global.DEFAULT_FAIL_RESPONSE); - return; } } + + } catch (err) { + logger.write("[ERROR] run -> loop -> initializeStatusDependencies -> err = " + err.message); + callBackFunction(err); } } function initializeDataDependencies() { - if (FULL_LOG === true) { logger.write("[INFO] run -> loop -> initializeDataDependencies -> Entering function."); } + try { - dataDependencies = DATA_DEPENDENCIES.newDataDependencies(bot, DEBUG_MODULE, DATA_SET, BLOB_STORAGE, UTILITIES); + if (FULL_LOG === true) { logger.write("[INFO] run -> loop -> initializeDataDependencies -> Entering function."); } - dataDependencies.initialize(processConfig.dataDependencies, onInizialized); + dataDependencies = DATA_DEPENDENCIES.newDataDependencies(bot, DEBUG_MODULE, DATA_SET, BLOB_STORAGE, UTILITIES); - function onInizialized(err) { + dataDependencies.initialize(processConfig.dataDependencies, onInizialized); - switch (err.result) { - case global.DEFAULT_OK_RESPONSE.result: { - logger.write("[INFO] run -> loop -> initializeDataDependencies -> onInizialized > Execution finished well. :-)"); - initializeContext(); - return; - } - case global.DEFAULT_RETRY_RESPONSE.result: { // Something bad happened, but if we retry in a while it might go through the next time. - logger.write("[ERROR] run -> loop -> initializeDataDependencies -> onInizialized > Retry Later. Requesting Execution Retry."); - nextWaitTime = 'Retry'; - loopControl(nextWaitTime); - return; - } - case global.DEFAULT_FAIL_RESPONSE.result: { // This is an unexpected exception that we do not know how to handle. - logger.write("[ERROR] run -> loop -> initializeDataDependencies -> onInizialized > Operation Failed. Aborting the process."); + function onInizialized(err) { + + try { + + if (FULL_LOG === true) { logger.write("[INFO] run -> loop -> initializeDataDependencies -> onInizialized -> Entering function."); } + + switch (err.result) { + case global.DEFAULT_OK_RESPONSE.result: { + logger.write("[INFO] run -> loop -> initializeDataDependencies -> onInizialized -> Execution finished well. :-)"); + initializeContext(); + return; + } + case global.DEFAULT_RETRY_RESPONSE.result: { // Something bad happened, but if we retry in a while it might go through the next time. + logger.write("[ERROR] run -> loop -> initializeDataDependencies -> onInizialized -> Retry Later. Requesting Execution Retry."); + nextWaitTime = 'Retry'; + loopControl(nextWaitTime); + return; + } + case global.DEFAULT_FAIL_RESPONSE.result: { // This is an unexpected exception that we do not know how to handle. + logger.write("[ERROR] run -> loop -> initializeDataDependencies -> onInizialized -> Operation Failed. Aborting the process."); + callBackFunction(err); + return; + } + default: { + logger.write("[ERROR] run -> loop -> initializeDataDependencies -> onInizialized -> Unhandled err.result received. -> err.result = " + err.result); + logger.write("[ERROR] run -> loop -> initializeDataDependencies -> onInizialized -> Unhandled err.result received. -> err.message = " + err.message); + + callBackFunction(global.DEFAULT_FAIL_RESPONSE); + return; + } + } + + } catch (err) { + logger.write("[ERROR] run -> loop -> initializeDataDependencies -> onInizialized -> err = " + err.message); callBackFunction(err); - return; - } - default: { - logger.write("[ERROR] run -> loop -> initializeDataDependencies -> onInizialized > Unhandled err.result received. -> err.result = " + err.result); - logger.write("[ERROR] run -> loop -> initializeDataDependencies -> onInizialized > Unhandled err.result received. -> err.message = " + err.message); - - callBackFunction(global.DEFAULT_FAIL_RESPONSE); - return; } } + + } catch (err) { + logger.write("[ERROR] run -> loop -> initializeDataDependencies -> err = " + err.message); + callBackFunction(err); } } function initializeContext() { - if (FULL_LOG === true) { logger.write("[INFO] run -> loop -> initializeContext -> Entering function."); } + try { - context = CONTEXT.newContext(bot, DEBUG_MODULE, BLOB_STORAGE, UTILITIES, STATUS_REPORT); - context.initialize(statusDependencies, onInizialized); + if (FULL_LOG === true) { logger.write("[INFO] run -> loop -> initializeContext -> Entering function."); } - function onInizialized(err) { + context = CONTEXT.newContext(bot, DEBUG_MODULE, BLOB_STORAGE, UTILITIES, STATUS_REPORT); + context.initialize(statusDependencies, onInizialized); - switch (err.result) { - case global.DEFAULT_OK_RESPONSE.result: { - logger.write("[INFO] run -> loop -> initializeContext -> onInizialized > Execution finished well. :-)"); - initializeExchangeAPI(); - return; - } - case global.DEFAULT_RETRY_RESPONSE.result: { // Something bad happened, but if we retry in a while it might go through the next time. - logger.write("[ERROR] run -> loop -> initializeContext -> onInizialized > Retry Later. Requesting Execution Retry."); - nextWaitTime = 'Retry'; - loopControl(nextWaitTime); - return; - } - case global.DEFAULT_FAIL_RESPONSE.result: { // This is an unexpected exception that we do not know how to handle. - logger.write("[ERROR] run -> loop -> initializeContext -> onInizialized > Operation Failed. Aborting the process."); + function onInizialized(err) { + + try { + + if (FULL_LOG === true) { logger.write("[INFO] run -> loop -> initializeContext -> onInizialized -> Entering function."); } + + switch (err.result) { + case global.DEFAULT_OK_RESPONSE.result: { + logger.write("[INFO] run -> loop -> initializeContext -> onInizialized -> Execution finished well. :-)"); + initializeExchangeAPI(); + return; + } + case global.DEFAULT_RETRY_RESPONSE.result: { // Something bad happened, but if we retry in a while it might go through the next time. + logger.write("[ERROR] run -> loop -> initializeContext -> onInizialized -> Retry Later. Requesting Execution Retry."); + nextWaitTime = 'Retry'; + loopControl(nextWaitTime); + return; + } + case global.DEFAULT_FAIL_RESPONSE.result: { // This is an unexpected exception that we do not know how to handle. + logger.write("[ERROR] run -> loop -> initializeContext -> onInizialized -> Operation Failed. Aborting the process."); + callBackFunction(err); + return; + } + default: { + logger.write("[ERROR] run -> loop -> initializeContext -> onInizialized -> Unhandled err.result received. -> err.result = " + err.result); + logger.write("[ERROR] run -> loop -> initializeContext -> onInizialized -> Unhandled err.result received. -> err.message = " + err.message); + + callBackFunction(global.DEFAULT_FAIL_RESPONSE); + return; + } + } + + } catch (err) { + logger.write("[ERROR] run -> loop -> initializeContext -> onInizialized -> err = " + err.message); callBackFunction(err); - return; - } - default: { - logger.write("[ERROR] run -> loop -> initializeContext -> onInizialized > Unhandled err.result received. -> err.result = " + err.result); - logger.write("[ERROR] run -> loop -> initializeContext -> onInizialized > Unhandled err.result received. -> err.message = " + err.message); - - callBackFunction(global.DEFAULT_FAIL_RESPONSE); - return; } } + + } catch (err) { + logger.write("[ERROR] run -> loop -> initializeContext -> err = " + err.message); + callBackFunction(err); } } function initializeExchangeAPI() { - if (FULL_LOG === true) { logger.write("[INFO] run -> loop -> initializeExchangeAPI -> Entering function."); } + try { - exchangeAPI = EXCHANGE_API.newExchangeAPI(bot, DEBUG_MODULE, POLONIEX_CLIENT_MODULE); + if (FULL_LOG === true) { logger.write("[INFO] run -> loop -> initializeExchangeAPI -> Entering function."); } - exchangeAPI.initialize(onInizialized); + exchangeAPI = EXCHANGE_API.newExchangeAPI(bot, DEBUG_MODULE, POLONIEX_CLIENT_MODULE); - function onInizialized(err) { + exchangeAPI.initialize(onInizialized); - switch (err.result) { - case global.DEFAULT_OK_RESPONSE.result: { - logger.write("[INFO] run -> loop -> initializeExchangeAPI -> onInizialized > Execution finished well. :-)"); - initializeAssistant(); - return; - } - case global.DEFAULT_RETRY_RESPONSE.result: { // Something bad happened, but if we retry in a while it might go through the next time. - logger.write("[ERROR] run -> loop -> initializeExchangeAPI -> onInizialized > Retry Later. Requesting Execution Retry."); - nextWaitTime = 'Retry'; - loopControl(nextWaitTime); - return; - } - case global.DEFAULT_FAIL_RESPONSE.result: { // This is an unexpected exception that we do not know how to handle. - logger.write("[ERROR] run -> loop -> initializeExchangeAPI -> onInizialized > Operation Failed. Aborting the process."); + function onInizialized(err) { + + try { + + if (FULL_LOG === true) { logger.write("[INFO] run -> loop -> initializeContext -> onInizialized -> onInizialized -> Entering function."); } + + switch (err.result) { + case global.DEFAULT_OK_RESPONSE.result: { + logger.write("[INFO] run -> loop -> initializeExchangeAPI -> onInizialized -> Execution finished well. :-)"); + initializeAssistant(); + return; + } + case global.DEFAULT_RETRY_RESPONSE.result: { // Something bad happened, but if we retry in a while it might go through the next time. + logger.write("[ERROR] run -> loop -> initializeExchangeAPI -> onInizialized -> Retry Later. Requesting Execution Retry."); + nextWaitTime = 'Retry'; + loopControl(nextWaitTime); + return; + } + case global.DEFAULT_FAIL_RESPONSE.result: { // This is an unexpected exception that we do not know how to handle. + logger.write("[ERROR] run -> loop -> initializeExchangeAPI -> onInizialized -> Operation Failed. Aborting the process."); + callBackFunction(err); + return; + } + default: { + logger.write("[ERROR] run -> loop -> initializeExchangeAPI -> onInizialized -> Unhandled err.result received. -> err.result = " + err.result); + logger.write("[ERROR] run -> loop -> initializeExchangeAPI -> onInizialized -> Unhandled err.result received. -> err.message = " + err.message); + + callBackFunction(global.DEFAULT_FAIL_RESPONSE); + return; + } + } + + } catch (err) { + logger.write("[ERROR] run -> loop -> initializeContext -> onInizialized -> onInizialized -> err = " + err.message); callBackFunction(err); - return; - } - default: { - logger.write("[ERROR] run -> loop -> initializeExchangeAPI -> onInizialized > Unhandled err.result received. -> err.result = " + err.result); - logger.write("[ERROR] run -> loop -> initializeExchangeAPI -> onInizialized > Unhandled err.result received. -> err.message = " + err.message); - - callBackFunction(global.DEFAULT_FAIL_RESPONSE); - return; } } + + } catch (err) { + logger.write("[ERROR] run -> loop -> initializeExchangeAPI -> err = " + err.message); + callBackFunction(err); } } function initializeAssistant() { - if (FULL_LOG === true) { logger.write("[INFO] run -> loop -> initializeAssistant -> Entering function."); } + try { - assistant = ASSISTANT.newAssistant(bot, DEBUG_MODULE, UTILITIES); - assistant.initialize(context, exchangeAPI, dataDependencies, onInizialized); + if (FULL_LOG === true) { logger.write("[INFO] run -> loop -> initializeAssistant -> Entering function."); } - function onInizialized(err) { + assistant = ASSISTANT.newAssistant(bot, DEBUG_MODULE, UTILITIES); + assistant.initialize(context, exchangeAPI, dataDependencies, onInizialized); - switch (err.result) { - case global.DEFAULT_OK_RESPONSE.result: { - logger.write("[INFO] run -> loop -> initializeAssistant -> onInizialized > Execution finished well. :-)"); - initializeUserBot(); - return; - } - case global.DEFAULT_RETRY_RESPONSE.result: { // Something bad happened, but if we retry in a while it might go through the next time. - logger.write("[ERROR] run -> loop -> initializeAssistant -> onInizialized > Retry Later. Requesting Execution Retry."); - nextWaitTime = 'Retry'; - loopControl(nextWaitTime); - return; - } - case global.DEFAULT_FAIL_RESPONSE.result: { // This is an unexpected exception that we do not know how to handle. - logger.write("[ERROR] run -> loop -> initializeAssistant -> onInizialized > Operation Failed. Aborting the process."); + function onInizialized(err) { + + try { + + if (FULL_LOG === true) { logger.write("[INFO] run -> loop -> initializeAssistant -> onInizialized -> Entering function."); } + + switch (err.result) { + case global.DEFAULT_OK_RESPONSE.result: { + logger.write("[INFO] run -> loop -> initializeAssistant -> onInizialized -> Execution finished well. :-)"); + initializeUserBot(); + return; + } + case global.DEFAULT_RETRY_RESPONSE.result: { // Something bad happened, but if we retry in a while it might go through the next time. + logger.write("[ERROR] run -> loop -> initializeAssistant -> onInizialized -> Retry Later. Requesting Execution Retry."); + nextWaitTime = 'Retry'; + loopControl(nextWaitTime); + return; + } + case global.DEFAULT_FAIL_RESPONSE.result: { // This is an unexpected exception that we do not know how to handle. + logger.write("[ERROR] run -> loop -> initializeAssistant -> onInizialized -> Operation Failed. Aborting the process."); + callBackFunction(err); + return; + } + default: { + logger.write("[ERROR] run -> loop -> initializeAssistant -> onInizialized -> Unhandled err.result received. -> err.result = " + err.result); + logger.write("[ERROR] run -> loop -> initializeAssistant -> onInizialized -> Unhandled err.result received. -> err.message = " + err.message); + + callBackFunction(global.DEFAULT_FAIL_RESPONSE); + return; + } + } + + } catch (err) { + logger.write("[ERROR] run -> loop -> initializeAssistant -> onInizialized -> err = " + err.message); callBackFunction(err); - return; - } - default: { - logger.write("[ERROR] run -> loop -> initializeAssistant -> onInizialized > Unhandled err.result received. -> err.result = " + err.result); - logger.write("[ERROR] run -> loop -> initializeAssistant -> onInizialized > Unhandled err.result received. -> err.message = " + err.message); - - callBackFunction(global.DEFAULT_FAIL_RESPONSE); - return; } } + + } catch (err) { + logger.write("[ERROR] run -> loop -> initializeAssistant -> err = " + err.message); + callBackFunction(err); } } function initializeUserBot() { - if (FULL_LOG === true) { logger.write("[INFO] run -> loop -> initializeUserBot -> Entering function."); } + try { - usertBot = USER_BOT_MODULE.newUserBot(bot, DEBUG_MODULE, COMMONS_MODULE); + if (FULL_LOG === true) { logger.write("[INFO] run -> loop -> initializeUserBot -> Entering function."); } - usertBot.initialize(assistant, onInizialized); + usertBot = USER_BOT_MODULE.newUserBot(bot, DEBUG_MODULE, COMMONS_MODULE); - function onInizialized(err) { + usertBot.initialize(assistant, onInizialized); - switch (err.result) { - case global.DEFAULT_OK_RESPONSE.result: { - logger.write("[INFO] run -> loop -> initializeUserBot -> onInizialized > Execution finished well. :-)"); - startUserBot(); - return; - } - case global.DEFAULT_RETRY_RESPONSE.result: { // Something bad happened, but if we retry in a while it might go through the next time. - logger.write("[ERROR] run -> loop -> initializeUserBot -> onInizialized > Retry Later. Requesting Execution Retry."); - nextWaitTime = 'Retry'; - loopControl(nextWaitTime); - return; - } - case global.DEFAULT_FAIL_RESPONSE.result: { // This is an unexpected exception that we do not know how to handle. - logger.write("[ERROR] run -> loop -> initializeUserBot -> onInizialized > Operation Failed. Aborting the process."); + function onInizialized(err) { + + try { + + if (FULL_LOG === true) { logger.write("[INFO] run -> loop -> initializeUserBot -> onInizialized -> Entering function."); } + + switch (err.result) { + case global.DEFAULT_OK_RESPONSE.result: { + logger.write("[INFO] run -> loop -> initializeUserBot -> onInizialized -> Execution finished well. :-)"); + startUserBot(); + return; + } + case global.DEFAULT_RETRY_RESPONSE.result: { // Something bad happened, but if we retry in a while it might go through the next time. + logger.write("[ERROR] run -> loop -> initializeUserBot -> onInizialized -> Retry Later. Requesting Execution Retry."); + nextWaitTime = 'Retry'; + loopControl(nextWaitTime); + return; + } + case global.DEFAULT_FAIL_RESPONSE.result: { // This is an unexpected exception that we do not know how to handle. + logger.write("[ERROR] run -> loop -> initializeUserBot -> onInizialized -> Operation Failed. Aborting the process."); + callBackFunction(err); + return; + } + default: { + logger.write("[ERROR] run -> loop -> initializeUserBot -> onInizialized -> Unhandled err.result received. -> err.result = " + err.result); + logger.write("[ERROR] run -> loop -> initializeUserBot -> onInizialized -> Unhandled err.result received. -> err.message = " + err.message); + + callBackFunction(global.DEFAULT_FAIL_RESPONSE); + return; + } + } + + } catch (err) { + logger.write("[ERROR] run -> loop -> initializeUserBot -> onInizialized -> err = " + err.message); callBackFunction(err); - return; - } - default: { - logger.write("[ERROR] run -> loop -> initializeUserBot -> onInizialized > Unhandled err.result received. -> err.result = " + err.result); - logger.write("[ERROR] run -> loop -> initializeUserBot -> onInizialized > Unhandled err.result received. -> err.message = " + err.message); - - callBackFunction(global.DEFAULT_FAIL_RESPONSE); - return; } } + + } catch (err) { + logger.write("[ERROR] run -> loop -> initializeUserBot -> err = " + err.message); + callBackFunction(err); } } function startUserBot() { - if (FULL_LOG === true) { logger.write("[INFO] run -> loop -> startUserBot -> Entering function."); } + try { - usertBot.start(onFinished); + if (FULL_LOG === true) { logger.write("[INFO] run -> loop -> startUserBot -> Entering function."); } - function onFinished(err) { + usertBot.start(onFinished); - switch (err.result) { - case global.DEFAULT_OK_RESPONSE.result: { - logger.write("[INFO] run -> loop -> startUserBot -> onFinished > Execution finished well. :-)"); - saveContext(); - return; - } - case global.DEFAULT_RETRY_RESPONSE.result: { // Something bad happened, but if we retry in a while it might go through the next time. - logger.write("[ERROR] run -> loop -> startUserBot -> onFinished > Retry Later. Requesting Execution Retry."); - nextWaitTime = 'Retry'; - loopControl(nextWaitTime); - return; - } - case global.DEFAULT_FAIL_RESPONSE.result: { // This is an unexpected exception that we do not know how to handle. - logger.write("[ERROR] run -> loop -> startUserBot -> onFinished > Operation Failed. Aborting the process."); + function onFinished(err) { + + try { + + if (FULL_LOG === true) { logger.write("[INFO] run -> loop -> startUserBot -> onFinished -> Entering function."); } + + switch (err.result) { + case global.DEFAULT_OK_RESPONSE.result: { + logger.write("[INFO] run -> loop -> startUserBot -> onFinished -> Execution finished well. :-)"); + saveContext(); + return; + } + case global.DEFAULT_RETRY_RESPONSE.result: { // Something bad happened, but if we retry in a while it might go through the next time. + logger.write("[ERROR] run -> loop -> startUserBot -> onFinished -> Retry Later. Requesting Execution Retry."); + nextWaitTime = 'Retry'; + loopControl(nextWaitTime); + return; + } + case global.DEFAULT_FAIL_RESPONSE.result: { // This is an unexpected exception that we do not know how to handle. + logger.write("[ERROR] run -> loop -> startUserBot -> onFinished -> Operation Failed. Aborting the process."); + callBackFunction(err); + return; + } + default: { + logger.write("[ERROR] run -> loop -> startUserBot -> onFinished -> Unhandled err.result received. -> err.result = " + err.result); + logger.write("[ERROR] run -> loop -> startUserBot -> onFinished -> Unhandled err.result received. -> err.message = " + err.message); + + callBackFunction(global.DEFAULT_FAIL_RESPONSE); + return; + } + } + + } catch (err) { + logger.write("[ERROR] run -> loop -> startUserBot -> onFinished -> err = " + err.message); callBackFunction(err); - return; - } - default: { - logger.write("[ERROR] run -> loop -> startUserBot -> onFinished > Unhandled err.result received. -> err.result = " + err.result); - logger.write("[ERROR] run -> loop -> startUserBot -> onFinished > Unhandled err.result received. -> err.message = " + err.message); - - callBackFunction(global.DEFAULT_FAIL_RESPONSE); - return; } } + + } catch (err) { + logger.write("[ERROR] run -> loop -> startUserBot -> err = " + err.message); + callBackFunction(err); } } function saveContext() { - if (FULL_LOG === true) { logger.write("[INFO] run -> loop -> saveContext -> Entering function."); } + try { - context.saveThemAll(onFinished); + if (FULL_LOG === true) { logger.write("[INFO] run -> loop -> saveContext -> Entering function."); } - function onFinished(err) { + context.saveThemAll(onFinished); - switch (err.result) { - case global.DEFAULT_OK_RESPONSE.result: { - logger.write("[INFO] run -> loop -> saveContext -> onFinished > Execution finished well. :-)"); - nextWaitTime = 'Normal'; - loopControl(nextWaitTime); - return; - } - case global.DEFAULT_RETRY_RESPONSE.result: { // Something bad happened, but if we retry in a while it might go through the next time. - logger.write("[ERROR] run -> loop -> saveContext -> onFinished > Can not retry at this point."); - callBackFunction(global.DEFAULT_FAIL_RESPONSE); - return; - } - case global.DEFAULT_FAIL_RESPONSE.result: { // This is an unexpected exception that we do not know how to handle. - logger.write("[ERROR] run -> loop -> saveContext -> onFinished > Operation Failed. Aborting the process."); + function onFinished(err) { + + try { + + if (FULL_LOG === true) { logger.write("[INFO] run -> loop -> saveContext -> onFinished -> Entering function."); } + + switch (err.result) { + case global.DEFAULT_OK_RESPONSE.result: { + logger.write("[INFO] run -> loop -> saveContext -> onFinished -> Execution finished well. :-)"); + nextWaitTime = 'Normal'; + loopControl(nextWaitTime); + return; + } + case global.DEFAULT_RETRY_RESPONSE.result: { // Something bad happened, but if we retry in a while it might go through the next time. + logger.write("[ERROR] run -> loop -> saveContext -> onFinished -> Can not retry at this point."); + callBackFunction(global.DEFAULT_FAIL_RESPONSE); + return; + } + case global.DEFAULT_FAIL_RESPONSE.result: { // This is an unexpected exception that we do not know how to handle. + logger.write("[ERROR] run -> loop -> saveContext -> onFinished -> Operation Failed. Aborting the process."); + callBackFunction(err); + return; + } + default: { + logger.write("[ERROR] run -> loop -> saveContext -> onFinished -> Unhandled err.result received. -> err.result = " + err.result); + logger.write("[ERROR] run -> loop -> saveContext -> onFinished -> Unhandled err.result received. -> err.message = " + err.message); + + callBackFunction(global.DEFAULT_FAIL_RESPONSE); + return; + } + } + + } catch (err) { + logger.write("[ERROR] run -> loop -> saveContext -> onFinished -> err = " + err.message); callBackFunction(err); - return; - } - default: { - logger.write("[ERROR] run -> loop -> saveContext -> onFinished > Unhandled err.result received. -> err.result = " + err.result); - logger.write("[ERROR] run -> loop -> saveContext -> onFinished > Unhandled err.result received. -> err.message = " + err.message); - - callBackFunction(global.DEFAULT_FAIL_RESPONSE); - return; } } + + } catch (err) { + logger.write("[ERROR] run -> loop -> saveContext -> err = " + err.message); + callBackFunction(err); } } diff --git a/this.config.json b/this.config.json index e55753f2c..a7fd1af67 100644 --- a/this.config.json +++ b/this.config.json @@ -17,12 +17,12 @@ "process": "Multi-Period-Market" }, { - "enabled": "true", + "enabled": "false", "botPath": "../Bots/AAMasters/AAOlivia-Indicator-Bot", "process": "Multi-Period-Daily" }, { - "enabled": "false", + "enabled": "true", "botPath": "../Bots/AAMasters/AABruce-Indicator-Bot", "process": "One-Min-Daily-Candles-Volumes" },