From 15a73ef6ab7bdcbf78742c1a14ce6d5de7e5d5e6 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Wed, 10 Jun 2020 14:10:08 +0200 Subject: [PATCH] Session Errors Implemented --- Session.js | 32 +++++++++++++++++++++++--------- TradingBotProcessMainLoop.js | 25 ++++++++++++++++++++++--- 2 files changed, 45 insertions(+), 12 deletions(-) diff --git a/Session.js b/Session.js index bda97ba8a..088a4415a 100644 --- a/Session.js +++ b/Session.js @@ -60,7 +60,7 @@ bot.SESSION = JSON.parse(message.event.session) bot.DEPENDENCY_FILTER = JSON.parse(message.event.dependencyFilter) bot.RESUME = message.event.resume - bot.SESSION.stop = sessionStop // stop function + bot.SESSION.stop = stopSession // stop function setUpAppSchema() setUpSessionFolderName() @@ -142,7 +142,9 @@ */ if (bot.SESSION.parameters === undefined) { - if (FULL_LOG === true) { parentLogger.write(MODULE_NAME, "[ERROR] initialize -> checkParemeters -> Session Node with no Parameters."); } + let errorMessage = "Session Node with no Parameters." + parentLogger.write(MODULE_NAME, "[ERROR] initialize -> checkParemeters -> " + errorMessage) + bot.sessionError(bot.SESSION, errorMessage) return false } @@ -190,21 +192,29 @@ /* Time Frame */ if (bot.SESSION.parameters.timeFrame === undefined) { - if (FULL_LOG === true) { parentLogger.write(MODULE_NAME, "[ERROR] initialize -> checkParemeters -> Session Parameters Node with no Time Frame."); } + let errorMessage = "Session Parameters Node with no Time Frame." + parentLogger.write(MODULE_NAME, "[ERROR] initialize -> checkParemeters -> " + errorMessage) + bot.sessionError(bot.SESSION.parameters, errorMessage) return false } - if (bot.SESSION.parameters.timeFrame.label === undefined) { - if (FULL_LOG === true) { parentLogger.write(MODULE_NAME, "[ERROR] initialize -> checkParemeters -> Session Parameters Node with no Time Frame Label configuration."); } + if (bot.SESSION.parameters.timeFrame.config.label === undefined) { + let errorMessage = "Session Parameters Node with no Time Frame Label configuration." + parentLogger.write(MODULE_NAME, "[ERROR] initialize -> checkParemeters -> " + errorMessage) + bot.sessionError(bot.SESSION.parameters.timeFrame, errorMessage) return false } /* Session Base Asset */ if (bot.SESSION.parameters.sessionBaseAsset === undefined) { - if (FULL_LOG === true) { parentLogger.write(MODULE_NAME, "[ERROR] initialize -> checkParemeters -> Session Parameters Node with no Session Base Asset."); } + let errorMessage = "Session Parameters Node with no Session Base Asset." + parentLogger.write(MODULE_NAME, "[ERROR] initialize -> checkParemeters -> " + errorMessage) + bot.sessionError(bot.SESSION.parameters, errorMessage) return false } if (bot.SESSION.parameters.sessionBaseAsset.config.initialBalance === undefined) { - if (FULL_LOG === true) { parentLogger.write(MODULE_NAME, "[ERROR] initialize -> checkParemeters -> Session Parameters Session Base Asset with no initialBalance configuration."); } + let errorMessage = "Session Parameters Session Base Asset with no initialBalance configuration." + parentLogger.write(MODULE_NAME, "[ERROR] initialize -> checkParemeters -> " + errorMessage) + bot.sessionError(bot.SESSION.parameters.sessionBaseAsset, errorMessage) return false } if (bot.SESSION.parameters.sessionBaseAsset.config.minimumBalance === undefined) { @@ -216,11 +226,15 @@ /* Session Quoted Asset */ if (bot.SESSION.parameters.sessionQuotedAsset === undefined) { - if (FULL_LOG === true) { parentLogger.write(MODULE_NAME, "[ERROR] initialize -> checkParemeters -> Session Parameters Node with no Session Quoted Asset."); } + let errorMessage = "Session Parameters Node with no Session Quoted Asset." + parentLogger.write(MODULE_NAME, "[ERROR] initialize -> checkParemeters -> " + errorMessage) + bot.sessionError(bot.SESSION.parameters, errorMessage) return false } if (bot.SESSION.parameters.sessionQuotedAsset.config.initialBalance === undefined) { - if (FULL_LOG === true) { parentLogger.write(MODULE_NAME, "[ERROR] initialize -> checkParemeters -> Session Parameters Session Quoted Asset with no initialBalance configuration."); } + let errorMessage = "Session Parameters Session Quoted Asset with no initialBalance configuration." + parentLogger.write(MODULE_NAME, "[ERROR] initialize -> checkParemeters -> " + errorMessage) + bot.sessionError(bot.SESSION.parameters.sessionQuotedAsset, errorMessage) return false } if (bot.SESSION.parameters.sessionQuotedAsset.config.minimumBalance === undefined) { diff --git a/TradingBotProcessMainLoop.js b/TradingBotProcessMainLoop.js index 3d5207e7c..8b2d75d8b 100644 --- a/TradingBotProcessMainLoop.js +++ b/TradingBotProcessMainLoop.js @@ -98,6 +98,13 @@ let fixedTimeLoopIntervalHandle; bot.STOP_SESSION = true; + /* Errors sent to the UI */ + bot.sessionError = sessionError + + /* Heartbeats sent to the UI */ + bot.sessionHeartBeat = sessionHeartBeat + bot.processHeartBeat = processHeartBeat + loop(); function loop() { @@ -122,9 +129,7 @@ let nextWaitTime; - /* Heartbeats sent to the UI */ - bot.sessionHeartBeat = sessionHeartBeat - bot.processHeartBeat = processHeartBeat + /* We tell the UI that we are running. */ processHeartBeat() /* We define here all the modules that the rest of the infraestructure, including the bots themselves can consume. */ @@ -904,6 +909,20 @@ } } + function sessionError(node, errorMessage) { + let event = { + nodeName: node.name, + nodeType: node.type, + nodeId: node.id, + errorMessage: errorMessage + } + global.EVENT_SERVER_CLIENT.raiseEvent(bot.sessionKey, 'Error', event) + + if (global.STOP_TASK_GRACEFULLY === true) { + bot.STOP_SESSION = true + } + } + function processStopped() { global.EVENT_SERVER_CLIENT.raiseEvent(bot.processKey, 'Stopped') }