From dc10f9d55bc09890f5f6e886c165ba7c967e3dc1 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Thu, 10 May 2018 13:45:17 +0200 Subject: [PATCH] Error handling improved --- .vs/AACloud/v15/.suo | Bin 98816 -> 121344 bytes Blob Storage.js | 2 +- Extraction Bot Process Main Loop.js | 270 ++++++++------ Indicator Bot Process Main Loop.js | 270 ++++++++------ Trading Bot Process Main Loop.js | 540 +++++++++++++++++----------- this.config.json | 4 +- 6 files changed, 655 insertions(+), 431 deletions(-) diff --git a/.vs/AACloud/v15/.suo b/.vs/AACloud/v15/.suo index 147d6c6486fa03d42044a54612bef66513719809..0f0ea9c3092f29215344cc5ec1d67152469ffb58 100644 GIT binary patch delta 7574 zcmds64Oo=dm7X&*zzi_RuOJW{5ET^&gQ&rv4$S!f0|=%u#UBJzB7%V-Rb#@WO|#b8 zuFQ#iS(7Gav^GCBBHun`H*L~UNou1>)F!QK62WW|t=z4C|yOM##R9pFy`K?e>8KM$A=MDYE_gc}?=1wGe0avEgf$b*2a66#2? zRUB#6`ht#(Lt7ka1nfZ2k>kLh0d4~RMI0%ID~^m#;IB9StkGNlET5+Raf?Q!)MNG_RlLx5gd>C%gs6o&=H|h zS3-p;5(0CGFu3%n`Tl|`!8qnELD^nf>4@7ZWot-EqiPeaD&9mID(vd~Nt zcxfRWeCd&V&RXzA0Jk|$GRw7wRUHdQT*Yz&~u)79y_!bu`SJKr$>`3ANp=bE$6xJ_o$ z;+HSwz~4WBY6+3164{~hp*CYM=* z{X!q@th{yE;~~P`;P-^I_k#aPNc&0fPXSK@vcT=2Kh^lqiB-s?UDR2bF!~Lx@pI5$ z0M7%nfL{VW;1KZJ&dT!Av0#1&oC74TrDVJZyal`soCW%U0pJ~AKk%=>yMS185v$R+ zIxD~7ZPxcZ>mq$70{X>mJ>5=X=OYCyzH%8o^{(*Q&{$yL&GqxRFQFj(duSSy_>c8- z%_NtR7&7P&S3`yAA0Uuy3ksueMdJf0J9s?P5rLb}l4pD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age.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" },