From b225123d1f4f8564b83fe5e8b32ee74032cf7dca Mon Sep 17 00:00:00 2001 From: Matias Benitez Date: Fri, 6 Jul 2018 10:51:43 -0300 Subject: [PATCH] Adding email config and notifications for errors --- Run.js | 20 +++++++++++++++++++- TradingBotProcessMainLoop.js | 4 ++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/Run.js b/Run.js index b33b6cb63..fbfb498a1 100644 --- a/Run.js +++ b/Run.js @@ -30,6 +30,7 @@ process.on('exit', function (code) { }); global.USER_PROFILE = {}; +global.EMAIL_CONFIG = {}; readStoragePermissions(); @@ -57,7 +58,7 @@ function readStoragePermissions() { global.USER_PROFILE.storagePermissions = permissionsMap; - readExchangeAPIKey(); + readEmailConfiguration(); } catch (err) { console.log("[ERROR] readStoragePermissions -> err = " + err.message); @@ -65,6 +66,23 @@ function readStoragePermissions() { } } +function readEmailConfiguration() { + + let filePath; + + try { + let fs = require('fs'); + filePath = '../' + 'Email-Config' + '/' + 'Email.Config.json'; + global.EMAIL_CONFIG = JSON.parse(fs.readFileSync(filePath, 'utf8')); + + readExchangeAPIKey(); + } + catch (err) { + console.log("[ERROR] readEmailConfiguration -> err = " + err.message); + console.log("[HINT] You need to have a file at this path -> " + filePath); + } +} + function readExchangeAPIKey() { try { diff --git a/TradingBotProcessMainLoop.js b/TradingBotProcessMainLoop.js index 768e97a9a..1e155f837 100644 --- a/TradingBotProcessMainLoop.js +++ b/TradingBotProcessMainLoop.js @@ -851,6 +851,7 @@ clearTimeout(nextLoopTimeoutHandle); clearTimeout(checkLoopHealthHandle); bot.enableCheckLoopHealth = false; + assistant.sendEmail("FAIL", "Operation Failed. Aborting the process. err = " + err.message, true); callBackFunction(err); return; } @@ -863,6 +864,7 @@ clearTimeout(nextLoopTimeoutHandle); clearTimeout(checkLoopHealthHandle); bot.enableCheckLoopHealth = false; + assistant.sendEmail("FAIL", "Operation Failed. Aborting the process. err = " + err.message, true); callBackFunction(global.DEFAULT_FAIL_RESPONSE); return; } @@ -875,6 +877,7 @@ clearTimeout(nextLoopTimeoutHandle); clearTimeout(checkLoopHealthHandle); bot.enableCheckLoopHealth = false; + assistant.sendEmail("FAIL", "Operation Failed. Aborting the process. err = " + err.message, true); callBackFunction(err); } } @@ -886,6 +889,7 @@ clearTimeout(nextLoopTimeoutHandle); clearTimeout(checkLoopHealthHandle); bot.enableCheckLoopHealth = false; + assistant.sendEmail("FAIL", "Operation Failed. Aborting the process. err = " + err.message, true); callBackFunction(err); } }