From 0673d27ecddb4224ec169df68e741e5df888d3ec Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Wed, 26 Feb 2020 14:40:16 +0100 Subject: [PATCH 01/23] Better logging --- MultiPeriod.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MultiPeriod.js b/MultiPeriod.js index 6364f346a..672b631ac 100644 --- a/MultiPeriod.js +++ b/MultiPeriod.js @@ -454,7 +454,7 @@ previousDay = new Date(bot.multiPeriodProcessDatetime.valueOf() - ONE_DAY_IN_MILISECONDS); if (global.WRITE_LOGS_TO_FILES === 'true') { - logger.newInternalLoop(bot.codeName, bot.process); + logger.newInternalLoop(bot.codeName, bot.process, bot.multiPeriodProcessDatetime); } if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> processTimeFramesDailyFiles -> advanceTime -> bot.multiPeriodProcessDatetime = " + bot.multiPeriodProcessDatetime); } From d1f9a8a0eae55fe12f7596ee040dadc22c39c0a7 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Thu, 27 Feb 2020 10:09:18 +0100 Subject: [PATCH 02/23] better logging --- MultiPeriodDaily.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MultiPeriodDaily.js b/MultiPeriodDaily.js index 71ad6181a..27f1de9c7 100644 --- a/MultiPeriodDaily.js +++ b/MultiPeriodDaily.js @@ -320,7 +320,7 @@ previousDay = new Date(bot.multiPeriodDailyProcessDatetime.valueOf() - ONE_DAY_IN_MILISECONDS); if (global.WRITE_LOGS_TO_FILES === 'true') { - logger.newInternalLoop(bot.codeName, bot.process); + logger.newInternalLoop(bot.codeName, bot.process, bot.multiPeriodDailyProcessDatetime); } if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> processTimeFrames -> advanceTime -> bot.multiPeriodDailyProcessDatetime = " + bot.multiPeriodDailyProcessDatetime); } From bb2b7ce557291d5d9d62eaed2670f463ad0d01c1 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Thu, 27 Feb 2020 16:23:13 +0100 Subject: [PATCH 03/23] code --- Root.js | 1 + 1 file changed, 1 insertion(+) diff --git a/Root.js b/Root.js index 41e18541b..1619c0a99 100644 --- a/Root.js +++ b/Root.js @@ -212,6 +212,7 @@ quotedAsset: global.TASK_NODE.bot.processes[processIndex].marketReference.referenceParent.quotedAsset.referenceParent.code.codeName } botConfig.uiStartDate = global.TASK_NODE.bot.code.startDate + botConfig.code = global.TASK_NODE.bot.code /* This stuff is still hardcoded and unresolved. */ botConfig.version = { From 8135d19dbbb9e76ce5a65cde9f15d239439b9bc0 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Sun, 1 Mar 2020 15:35:55 +0100 Subject: [PATCH 04/23] Stop Gracefully --- MultiPeriodDaily.js | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/MultiPeriodDaily.js b/MultiPeriodDaily.js index 27f1de9c7..d80782859 100644 --- a/MultiPeriodDaily.js +++ b/MultiPeriodDaily.js @@ -338,7 +338,7 @@ } - periodsLoop(); + checkStopTaskGracefully(); } catch (err) { logger.write(MODULE_NAME, "[ERROR] start -> processTimeFrames -> advanceTime -> err = "+ err.stack); @@ -346,6 +346,29 @@ } } + function checkStopTaskGracefully() { + + try { + + if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> processTimeFramesDailyFiles -> checkStopTaskGracefully -> Entering function."); } + + /* Validation that we dont need to stop. */ + + if (global.STOP_TASK_GRACEFULLY === true) { + + callBackFunction(global.DEFAULT_OK_RESPONSE); + return; + + } + + periodsLoop(); + + } catch (err) { + logger.write(MODULE_NAME, "[ERROR] start -> processTimeFramesDailyFiles -> checkStopTaskGracefully -> err = " + err.stack); + callBackFunction(global.DEFAULT_FAIL_RESPONSE); + } + } + function periodsLoop() { try { From f0ce274707ff5627939e41f75238c2c61f05c9b0 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Wed, 4 Mar 2020 12:34:21 +0100 Subject: [PATCH 05/23] better logging --- server.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server.js b/server.js index 8d5c2d432..c7523ea32 100644 --- a/server.js +++ b/server.js @@ -177,7 +177,7 @@ function bootLoader() { } if (global.TASK_NODE.bot.processes[processIndex].marketReference.referenceParent === undefined) { - console.log("[WARN] Task Server -> server -> bootLoader -> Market Reference without a Reference Parent. This process will not be executed. -> Process Instance = " + JSON.stringify(global.TASK_NODE.bot.processes[processIndex].marketReference)); + console.log("[WARN] Task Server -> server -> bootLoader -> Market Reference without a Reference Parent. This process will not be executed. -> Process Instance = " + JSON.stringify(global.TASK_NODE.bot.processes[processIndex].marketReference) + ", bot = " + global.TASK_NODE.bot.name); continue } From 93dd655f25ad2ff185197db16efdc1c3dd919746 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Fri, 6 Mar 2020 09:25:47 +0100 Subject: [PATCH 06/23] Standarizing internal loop logging --- MultiPeriod.js | 7 ++----- MultiPeriodDaily.js | 8 +++----- MultiPeriodMarket.js | 1 + 3 files changed, 6 insertions(+), 10 deletions(-) diff --git a/MultiPeriod.js b/MultiPeriod.js index 672b631ac..2392fa451 100644 --- a/MultiPeriod.js +++ b/MultiPeriod.js @@ -452,11 +452,7 @@ bot.multiPeriodProcessDatetime = new Date(bot.multiPeriodProcessDatetime.valueOf() + ONE_DAY_IN_MILISECONDS); previousDay = new Date(bot.multiPeriodProcessDatetime.valueOf() - ONE_DAY_IN_MILISECONDS); - - if (global.WRITE_LOGS_TO_FILES === 'true') { - logger.newInternalLoop(bot.codeName, bot.process, bot.multiPeriodProcessDatetime); - } - + if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> processTimeFramesDailyFiles -> advanceTime -> bot.multiPeriodProcessDatetime = " + bot.multiPeriodProcessDatetime); } if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> processTimeFramesDailyFiles -> advanceTime -> previousDay = " + previousDay); } @@ -1061,6 +1057,7 @@ thisReport.file.lastExecution = bot.processDatetime; thisReport.save(callBack); + logger.newInternalLoop(bot.codeName, bot.process, bot.multiPeriodProcessDatetime); } catch (err) { logger.write(MODULE_NAME, "[ERROR] start -> writeMarketStatusReport -> err = " + err.stack); diff --git a/MultiPeriodDaily.js b/MultiPeriodDaily.js index d80782859..633c7880c 100644 --- a/MultiPeriodDaily.js +++ b/MultiPeriodDaily.js @@ -318,11 +318,7 @@ bot.multiPeriodDailyProcessDatetime = new Date(bot.multiPeriodDailyProcessDatetime.valueOf() + ONE_DAY_IN_MILISECONDS); previousDay = new Date(bot.multiPeriodDailyProcessDatetime.valueOf() - ONE_DAY_IN_MILISECONDS); - - if (global.WRITE_LOGS_TO_FILES === 'true') { - logger.newInternalLoop(bot.codeName, bot.process, bot.multiPeriodDailyProcessDatetime); - } - + if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> processTimeFrames -> advanceTime -> bot.multiPeriodDailyProcessDatetime = " + bot.multiPeriodDailyProcessDatetime); } if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> processTimeFrames -> advanceTime -> previousDay = " + previousDay); } @@ -804,6 +800,8 @@ thisReport.save(callBack); bot.hasTheBotJustStarted = false; + + logger.newInternalLoop(bot.codeName, bot.process, bot.multiPeriodDailyProcessDatetime); } catch (err) { logger.write(MODULE_NAME, "[ERROR] start -> writeStatusReport -> err = "+ err.stack); diff --git a/MultiPeriodMarket.js b/MultiPeriodMarket.js index 9ba755bb1..134c994ca 100644 --- a/MultiPeriodMarket.js +++ b/MultiPeriodMarket.js @@ -338,6 +338,7 @@ thisReport.file.lastExecution = bot.processDatetime; thisReport.save(callBack); + logger.newInternalLoop(bot.codeName, bot.process, bot.processDatetime); } catch (err) { logger.write(MODULE_NAME, "[ERROR] start -> writeStatusReport -> err = "+ err.stack); From 6e0d4a272e6f92beb64f0b5f2b311cfcc2256083 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Fri, 6 Mar 2020 12:28:27 +0100 Subject: [PATCH 07/23] Dataset Updated Bugs Fixed --- IndicatorBotProcessMainLoop.js | 82 ++-------------------------------- MultiPeriod.js | 2 +- MultiPeriodDaily.js | 7 +++ ProcessOutput.js | 8 ++-- SensorBotProcessMainLoop.js | 80 +-------------------------------- StatusDependencies.js | 4 +- StatusReport.js | 9 +++- TradingBotProcessMainLoop.js | 80 +-------------------------------- 8 files changed, 27 insertions(+), 245 deletions(-) diff --git a/IndicatorBotProcessMainLoop.js b/IndicatorBotProcessMainLoop.js index aa2cd6ac2..8915e5649 100644 --- a/IndicatorBotProcessMainLoop.js +++ b/IndicatorBotProcessMainLoop.js @@ -150,7 +150,6 @@ /* We will prepare first the infraestructure needed for the bot to run. There are 3 modules we need to sucessfullly initialize first. */ - let processOutput let processExecutionEvents let userBot; let processFramework; @@ -315,7 +314,7 @@ if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] run -> loop -> initializeStatusDependencies -> Entering function."); } - statusDependencies = STATUS_DEPENDENCIES.newStatusDependencies(bot, logger, STATUS_REPORT, UTILITIES); + statusDependencies = STATUS_DEPENDENCIES.newStatusDependencies(bot, logger, STATUS_REPORT, UTILITIES, PROCESS_OUTPUT); statusDependencies.initialize(onInizialized); @@ -595,7 +594,7 @@ switch (err.result) { case global.DEFAULT_OK_RESPONSE.result: { logger.write(MODULE_NAME, "[INFO] run -> loop -> startUserBot -> onFinished -> Execution finished well."); - raiseEventsProcessOutput() + finishProcessExecutionEvents() return; } case global.DEFAULT_RETRY_RESPONSE.result: { // Something bad happened, but if we retry in a while it might go through the next time. @@ -785,7 +784,7 @@ switch (err.result) { case global.DEFAULT_OK_RESPONSE.result: { logger.write(MODULE_NAME, "[INFO] run -> loop -> startProcessFramework -> onFinished -> Execution finished well."); - raiseEventsProcessOutput() + finishProcessExecutionEvents() return; } case global.DEFAULT_RETRY_RESPONSE.result: { // Something bad happened, but if we retry in a while it might go through the next time. @@ -868,81 +867,6 @@ } } - function raiseEventsProcessOutput() { - - try { - - if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] run -> loop -> raiseEventsProcessOutput -> Entering function."); } - - processOutput = PROCESS_OUTPUT.newProcessOutput(bot, logger) - - processOutput.raiseEvents(statusDependencies, onFinished); - - function onFinished(err) { - - try { - - if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] run -> loop -> raiseEventsProcessOutput -> onFinished -> Entering function."); } - - switch (err.result) { - case global.DEFAULT_OK_RESPONSE.result: { - logger.write(MODULE_NAME, "[INFO] run -> loop -> raiseEventsProcessOutput -> onFinished -> Execution finished well."); - finishProcessExecutionEvents() - 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(MODULE_NAME, "[WARN] run -> loop -> raiseEventsProcessOutput -> 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. - processStopped() - logger.write(MODULE_NAME, "[ERROR] run -> loop -> raiseEventsProcessOutput -> onFinished -> Operation Failed. Aborting the process."); - logger.persist(); - clearInterval(fixedTimeLoopIntervalHandle); - clearTimeout(nextLoopTimeoutHandle); - clearTimeout(checkLoopHealthHandle); - bot.enableCheckLoopHealth = false; - callBackFunction(err); - return; - } - default: { - logger.write(MODULE_NAME, "[ERROR] run -> loop -> raiseEventsProcessOutput -> onFinished -> Unhandled err.result received. -> err.result = " + err.result); - logger.write(MODULE_NAME, "[ERROR] run -> loop -> raiseEventsProcessOutput -> onFinished -> Unhandled err.result received. -> err = " + err.message); - - logger.persist(); - clearInterval(fixedTimeLoopIntervalHandle); - clearTimeout(nextLoopTimeoutHandle); - clearTimeout(checkLoopHealthHandle); - bot.enableCheckLoopHealth = false; - callBackFunction(global.DEFAULT_FAIL_RESPONSE); - return; - } - } - - } catch (err) { - logger.write(MODULE_NAME, "[ERROR] run -> loop -> raiseEventsProcessOutput -> onFinished -> err = " + err.stack); - logger.persist(); - clearInterval(fixedTimeLoopIntervalHandle); - clearTimeout(nextLoopTimeoutHandle); - clearTimeout(checkLoopHealthHandle); - bot.enableCheckLoopHealth = false; - callBackFunction(err); - } - } - - } catch (err) { - logger.write(MODULE_NAME, "[ERROR] run -> loop -> raiseEventsProcessOutput -> err = " + err.stack); - logger.persist(); - clearInterval(fixedTimeLoopIntervalHandle); - clearTimeout(nextLoopTimeoutHandle); - clearTimeout(checkLoopHealthHandle); - bot.enableCheckLoopHealth = false; - callBackFunction(err); - } - } - function finishProcessExecutionEvents() { try { diff --git a/MultiPeriod.js b/MultiPeriod.js index 2392fa451..2a801d7c6 100644 --- a/MultiPeriod.js +++ b/MultiPeriod.js @@ -1005,7 +1005,7 @@ logger.write(MODULE_NAME, "[INFO] start -> writeDataRange -> onFileCreated -> Content written = " + fileContent); } - let key = bot.dataMine + "-" + bot.codeName + "-" + productCodeName + "-" + currentOutputPeriodName + let key = bot.dataMine + "-" + bot.codeName + "-" + productCodeName + "-" + bot.exchange + "-" + bot.market.baseAsset + '/' + bot.market.quotedAsset let event = { dateRange: dataRange } diff --git a/MultiPeriodDaily.js b/MultiPeriodDaily.js index 633c7880c..886b3d759 100644 --- a/MultiPeriodDaily.js +++ b/MultiPeriodDaily.js @@ -774,6 +774,13 @@ logger.write(MODULE_NAME, "[INFO] start -> writeDataRange -> onFileCreated -> Content written = " + fileContent); } + let key = bot.dataMine + "-" + bot.codeName + "-" + productCodeName + "-" + bot.exchange + "-" + bot.market.baseAsset + '/' + bot.market.quotedAsset + let event = { + dateRange: dataRange + } + + global.SYSTEM_EVENT_HANDLER.raiseEvent(key, 'Data Range Updated', event) + callBack(global.DEFAULT_OK_RESPONSE); } } diff --git a/ProcessOutput.js b/ProcessOutput.js index 6a07bbc34..4d2369ece 100644 --- a/ProcessOutput.js +++ b/ProcessOutput.js @@ -14,7 +14,7 @@ return thisObject; - function raiseEvents(statusDependencies, callBackFunction) { + function raiseEvents(lastFile, callBackFunction) { try { if (global.LOG_CONTROL[MODULE_NAME].logInfo === true) { logger.write(MODULE_NAME, "[INFO] raiseEvents -> Entering function."); } @@ -81,11 +81,9 @@ let product = outputDataset.referenceParent.parentNode.code.codeName let dataset = outputDataset.referenceParent.code.codeName - let statusReport = statusDependencies.reportsByMainUtility.get("Self Reference") - - key = dataMine + "-" + botName + "-" + product + "-" + dataset + key = dataMine + "-" + botName + "-" + product + "-" + dataset + "-" + bot.exchange + "-" + bot.market.baseAsset + '/' + bot.market.quotedAsset let event = { - lastFile: statusReport.file.lastFile + lastFile: lastFile } global.SYSTEM_EVENT_HANDLER.createEventHandler(key, 'Dataset Updated') global.SYSTEM_EVENT_HANDLER.raiseEvent(key, 'Dataset Updated', event) diff --git a/SensorBotProcessMainLoop.js b/SensorBotProcessMainLoop.js index b8e2c49fc..9f97243d3 100644 --- a/SensorBotProcessMainLoop.js +++ b/SensorBotProcessMainLoop.js @@ -155,7 +155,6 @@ /* We will prepare first the infraestructure needed for the bot to run. There are 4 modules we need to sucessfullly initialize first. */ - let processOutput let processExecutionEvents let userBot; let statusDependencies; @@ -319,7 +318,7 @@ if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] run -> loop -> initializeStatusDependencies -> Entering function."); } - statusDependencies = STATUS_DEPENDENCIES.newStatusDependencies(bot, logger, STATUS_REPORT, UTILITIES); + statusDependencies = STATUS_DEPENDENCIES.newStatusDependencies(bot, logger, STATUS_REPORT, UTILITIES, PROCESS_OUTPUT); statusDependencies.initialize(onInizialized); @@ -495,7 +494,7 @@ switch (err.result) { case global.DEFAULT_OK_RESPONSE.result: { logger.write(MODULE_NAME, "[INFO] run -> loop -> startUserBot -> onFinished > Execution finished well."); - raiseEventsProcessOutput() + finishProcessExecutionEvents() return; } case global.DEFAULT_RETRY_RESPONSE.result: { // Something bad happened, but if we retry in a while it might go through the next time. @@ -578,81 +577,6 @@ } } - function raiseEventsProcessOutput() { - - try { - - if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] run -> loop -> raiseEventsProcessOutput -> Entering function."); } - - processOutput = PROCESS_OUTPUT.newProcessOutput(bot, logger) - - processOutput.raiseEvents(statusDependencies, onFinished); - - function onFinished(err) { - - try { - - if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] run -> loop -> raiseEventsProcessOutput -> onFinished -> Entering function."); } - - switch (err.result) { - case global.DEFAULT_OK_RESPONSE.result: { - logger.write(MODULE_NAME, "[INFO] run -> loop -> raiseEventsProcessOutput -> onFinished -> Execution finished well."); - finishProcessExecutionEvents() - 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(MODULE_NAME, "[WARN] run -> loop -> raiseEventsProcessOutput -> 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. - processStopped() - logger.write(MODULE_NAME, "[ERROR] run -> loop -> raiseEventsProcessOutput -> onFinished -> Operation Failed. Aborting the process."); - logger.persist(); - clearInterval(fixedTimeLoopIntervalHandle); - clearTimeout(nextLoopTimeoutHandle); - clearTimeout(checkLoopHealthHandle); - bot.enableCheckLoopHealth = false; - callBackFunction(err); - return; - } - default: { - logger.write(MODULE_NAME, "[ERROR] run -> loop -> raiseEventsProcessOutput -> onFinished -> Unhandled err.result received. -> err.result = " + err.result); - logger.write(MODULE_NAME, "[ERROR] run -> loop -> raiseEventsProcessOutput -> onFinished -> Unhandled err.result received. -> err = " + err.message); - - logger.persist(); - clearInterval(fixedTimeLoopIntervalHandle); - clearTimeout(nextLoopTimeoutHandle); - clearTimeout(checkLoopHealthHandle); - bot.enableCheckLoopHealth = false; - callBackFunction(global.DEFAULT_FAIL_RESPONSE); - return; - } - } - - } catch (err) { - logger.write(MODULE_NAME, "[ERROR] run -> loop -> raiseEventsProcessOutput -> onFinished -> err = " + err.stack); - logger.persist(); - clearInterval(fixedTimeLoopIntervalHandle); - clearTimeout(nextLoopTimeoutHandle); - clearTimeout(checkLoopHealthHandle); - bot.enableCheckLoopHealth = false; - callBackFunction(err); - } - } - - } catch (err) { - logger.write(MODULE_NAME, "[ERROR] run -> loop -> raiseEventsProcessOutput -> err = " + err.stack); - logger.persist(); - clearInterval(fixedTimeLoopIntervalHandle); - clearTimeout(nextLoopTimeoutHandle); - clearTimeout(checkLoopHealthHandle); - bot.enableCheckLoopHealth = false; - callBackFunction(err); - } - } - function finishProcessExecutionEvents() { try { diff --git a/StatusDependencies.js b/StatusDependencies.js index 176188c16..19e7485ca 100644 --- a/StatusDependencies.js +++ b/StatusDependencies.js @@ -1,4 +1,4 @@ -exports.newStatusDependencies = function newStatusDependencies(BOT, logger, STATUS_REPORT, UTILITIES) { +exports.newStatusDependencies = function newStatusDependencies(BOT, logger, STATUS_REPORT, UTILITIES, PROCESS_OUTPUT) { const FULL_LOG = true; const LOG_FILE_CONTENT = false; @@ -53,7 +53,7 @@ for (let i = 0; i < dependenciesToProcess.length; i++) { - let statusReportModule = STATUS_REPORT.newStatusReport(BOT, logger, UTILITIES); + let statusReportModule = STATUS_REPORT.newStatusReport(BOT, logger, UTILITIES, PROCESS_OUTPUT); logger.write(MODULE_NAME, "[INFO] initialize -> onInitilized -> Initializing Status Report # " + (i + 1)); let statusDependency = dependenciesToProcess[i] diff --git a/StatusReport.js b/StatusReport.js index d6cd7210e..3219a6587 100644 --- a/StatusReport.js +++ b/StatusReport.js @@ -1,4 +1,4 @@ -exports.newStatusReport = function newStatusReport(BOT, logger, UTILITIES) { +exports.newStatusReport = function newStatusReport(BOT, logger, UTILITIES, PROCESS_OUTPUT) { /* @@ -255,7 +255,12 @@ logger.write(MODULE_NAME, "[INFO] save -> onFileCreated -> Content written = " + fileContent); } - callBackFunction(global.DEFAULT_OK_RESPONSE); + /* All good, lets emit the event that means data has been updated. */ + + let processOutput = PROCESS_OUTPUT.newProcessOutput(bot, logger) + + processOutput.raiseEvents(thisObject.file.lastFile, callBackFunction); + return; } diff --git a/TradingBotProcessMainLoop.js b/TradingBotProcessMainLoop.js index 85ae4182d..57eee04e8 100644 --- a/TradingBotProcessMainLoop.js +++ b/TradingBotProcessMainLoop.js @@ -189,7 +189,6 @@ /* We will prepare first the infraestructure needed for the bot to run. There are 3 modules we need to sucessfullly initialize first. */ - let processOutput let processExecutionEvents let userBot; let processFramework; @@ -352,7 +351,7 @@ if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] run -> loop -> initializeStatusDependencies -> Entering function."); } - statusDependencies = STATUS_DEPENDENCIES.newStatusDependencies(bot, logger, STATUS_REPORT, UTILITIES); + statusDependencies = STATUS_DEPENDENCIES.newStatusDependencies(bot, logger, STATUS_REPORT, UTILITIES, PROCESS_OUTPUT); statusDependencies.initialize(onInizialized); @@ -701,7 +700,7 @@ case global.DEFAULT_OK_RESPONSE.result: { logger.write(MODULE_NAME, "[INFO] run -> loop -> startProcessFramework -> onFinished -> Execution finished well."); nextWaitTime = 'Normal'; - raiseEventsProcessOutput() + finishProcessExecutionEvents() return; } case global.DEFAULT_RETRY_RESPONSE.result: { // Something bad happened, but if we retry in a while it might go through the next time. @@ -785,81 +784,6 @@ } } - function raiseEventsProcessOutput() { - - try { - - if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] run -> loop -> raiseEventsProcessOutput -> Entering function."); } - - processOutput = PROCESS_OUTPUT.newProcessOutput(bot, logger) - - processOutput.raiseEvents(statusDependencies, onFinished); - - function onFinished(err) { - - try { - - if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] run -> loop -> raiseEventsProcessOutput -> onFinished -> Entering function."); } - - switch (err.result) { - case global.DEFAULT_OK_RESPONSE.result: { - logger.write(MODULE_NAME, "[INFO] run -> loop -> raiseEventsProcessOutput -> onFinished -> Execution finished well."); - finishProcessExecutionEvents() - 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(MODULE_NAME, "[WARN] run -> loop -> raiseEventsProcessOutput -> 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. - processStopped() - logger.write(MODULE_NAME, "[ERROR] run -> loop -> raiseEventsProcessOutput -> onFinished -> Operation Failed. Aborting the process."); - logger.persist(); - clearInterval(fixedTimeLoopIntervalHandle); - clearTimeout(nextLoopTimeoutHandle); - clearTimeout(checkLoopHealthHandle); - bot.enableCheckLoopHealth = false; - callBackFunction(err); - return; - } - default: { - logger.write(MODULE_NAME, "[ERROR] run -> loop -> raiseEventsProcessOutput -> onFinished -> Unhandled err.result received. -> err.result = " + err.result); - logger.write(MODULE_NAME, "[ERROR] run -> loop -> raiseEventsProcessOutput -> onFinished -> Unhandled err.result received. -> err = " + err.message); - - logger.persist(); - clearInterval(fixedTimeLoopIntervalHandle); - clearTimeout(nextLoopTimeoutHandle); - clearTimeout(checkLoopHealthHandle); - bot.enableCheckLoopHealth = false; - callBackFunction(global.DEFAULT_FAIL_RESPONSE); - return; - } - } - - } catch (err) { - logger.write(MODULE_NAME, "[ERROR] run -> loop -> raiseEventsProcessOutput -> onFinished -> err = " + err.stack); - logger.persist(); - clearInterval(fixedTimeLoopIntervalHandle); - clearTimeout(nextLoopTimeoutHandle); - clearTimeout(checkLoopHealthHandle); - bot.enableCheckLoopHealth = false; - callBackFunction(err); - } - } - - } catch (err) { - logger.write(MODULE_NAME, "[ERROR] run -> loop -> raiseEventsProcessOutput -> err = " + err.stack); - logger.persist(); - clearInterval(fixedTimeLoopIntervalHandle); - clearTimeout(nextLoopTimeoutHandle); - clearTimeout(checkLoopHealthHandle); - bot.enableCheckLoopHealth = false; - callBackFunction(err); - } - } - function finishProcessExecutionEvents() { try { From 23a2639c42241bc9da7e69ebeaaa8f8762eeb409 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Wed, 11 Mar 2020 11:11:48 +0100 Subject: [PATCH 08/23] Change in Folder Structure --- Commons.js | 4 ++-- DataSet.js | 4 ++-- MultiPeriod.js | 8 +++---- MultiPeriodDaily.js | 6 +++--- MultiPeriodMarket.js | 2 +- Root.js | 2 +- StatusReport.js | 8 ++++--- TradingBot.js | 51 ++++++++++++++++---------------------------- 8 files changed, 36 insertions(+), 49 deletions(-) diff --git a/Commons.js b/Commons.js index 5ad2fb509..8bf6a01da 100644 --- a/Commons.js +++ b/Commons.js @@ -469,14 +469,14 @@ if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> writeFile -> Entering function."); } let market = bot.market; - let fileName = '' + market.baseAsset + '_' + market.quotedAsset + '.json'; + let fileName = 'Data.json'; let dateForPath = '' if (processingDailyFiles === true) { dateForPath = "/" + currentDay.getUTCFullYear() + '/' + utilities.pad(currentDay.getUTCMonth() + 1, 2) + '/' + utilities.pad(currentDay.getUTCDate(), 2); } - let filePathRoot = contextSummary.dataMine + "/" + contextSummary.bot + "/" + bot.exchange; + let filePathRoot = bot.exchange + "/" + bot.market.baseAsset + "-" + bot.market.quotedAsset + "/" + contextSummary.dataMine + "/" + contextSummary.bot; let filePath = filePathRoot + "/Output/" + contextSummary.product + "/" + contextSummary.dataset + "/" + timeFrameLabel + dateForPath; filePath += '/' + fileName diff --git a/DataSet.js b/DataSet.js index 4ecbbb6b3..ee04b4a21 100644 --- a/DataSet.js +++ b/DataSet.js @@ -104,7 +104,7 @@ exports.newDataSet = function newDataSet(BOT, logger) { if (global.LOG_CONTROL[MODULE_NAME].logInfo === true) { logger.write(MODULE_NAME, "[INFO] getTextFile -> Entering function."); } - let filePathRoot = dataDependencyNode.dataMine + "/" + dataDependencyNode.bot + "/" + bot.exchange; + let filePathRoot = bot.exchange + "/" + bot.market.baseAsset + "-" + bot.market.quotedAsset + "/" + dataDependencyNode.dataMine + "/" + dataDependencyNode.bot; let filePath = filePathRoot + "/Output/" + pFolderPath; filePath += '/' + pFileName @@ -146,7 +146,7 @@ exports.newDataSet = function newDataSet(BOT, logger) { return; } - let filePathRoot = dataDependencyNode.dataMine + "/" + dataDependencyNode.bot + "/" + bot.exchange; + let filePathRoot = bot.exchange + "/" + bot.market.baseAsset + "-" + bot.market.quotedAsset + "/" + dataDependencyNode.dataMine + "/" + dataDependencyNode.bot; let filePath = filePathRoot + "/Output/" + pFolderPath + '/' + pFileName; fileStorage.createTextFile(filePath, pFileContent, onFileCreated); diff --git a/MultiPeriod.js b/MultiPeriod.js index 2a801d7c6..d9047fb3f 100644 --- a/MultiPeriod.js +++ b/MultiPeriod.js @@ -312,7 +312,7 @@ if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> processTimeFramesMarketFiles -> periodsLoopBody -> dependencyLoopBody -> getFile -> Entering function."); } - let fileName = market.baseAsset + '_' + market.quotedAsset + ".json"; + let fileName = "Data.json"; if (dependency.dataSet !== "Multi-Period-Market") { @@ -632,7 +632,7 @@ } else { filePath = dependency.product + '/' + dependency.dataSet + "/" + dateForPath; } - let fileName = market.baseAsset + '_' + market.quotedAsset + ".json"; + let fileName = "Data.json"; dataset.getTextFile(filePath, fileName, onFileReceived); @@ -708,7 +708,7 @@ } else { filePath = dependency.product + '/' + dependency.dataSet + "/" + dateForPath; } - let fileName = market.baseAsset + '_' + market.quotedAsset + ".json"; + let fileName = "Data.json"; dataset.getTextFile(filePath, fileName, onFileReceived); @@ -986,7 +986,7 @@ let fileContent = JSON.stringify(dataRange); - let fileName = '/Data.Range.' + market.baseAsset + '_' + market.quotedAsset + '.json'; + let fileName = '/Data.Range.json'; let filePath = bot.filePathRoot + "/Output/" + bot.SESSION.folderName + "/" + productCodeName + "/" + 'Multi-Period-Daily' + fileName; fileStorage.createTextFile(filePath, fileContent + '\n', onFileCreated); diff --git a/MultiPeriodDaily.js b/MultiPeriodDaily.js index 886b3d759..c9e9acc25 100644 --- a/MultiPeriodDaily.js +++ b/MultiPeriodDaily.js @@ -451,7 +451,7 @@ } else { filePath = dependency.product + '/' + dependency.dataSet + "/" + dateForPath; } - let fileName = market.baseAsset + '_' + market.quotedAsset + ".json"; + let fileName = "Data.json"; dataset.getTextFile(filePath, fileName, onFileReceived); @@ -521,7 +521,7 @@ } else { filePath = dependency.product + '/' + dependency.dataSet + "/" + dateForPath; } - let fileName = market.baseAsset + '_' + market.quotedAsset + ".json"; + let fileName = "Data.json"; dataset.getTextFile(filePath, fileName, onFileReceived); @@ -755,7 +755,7 @@ let fileContent = JSON.stringify(dataRange); - let fileName = '/Data.Range.' + market.baseAsset + '_' + market.quotedAsset + '.json'; + let fileName = '/Data.Range.json'; let filePath = bot.filePathRoot + "/Output/" + productCodeName + "/" + bot.process + fileName; fileStorage.createTextFile(filePath, fileContent + '\n', onFileCreated); diff --git a/MultiPeriodMarket.js b/MultiPeriodMarket.js index 134c994ca..66cf11951 100644 --- a/MultiPeriodMarket.js +++ b/MultiPeriodMarket.js @@ -173,7 +173,7 @@ if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> processTimeFrames -> periodsLoopBody -> dependencyLoopBody -> getFile -> Entering function."); } let dateForPath = bot.processDatetime.getUTCFullYear() + '/' + utilities.pad(bot.processDatetime.getUTCMonth() + 1, 2) + '/' + utilities.pad(bot.processDatetime.getUTCDate(), 2); - let fileName = market.baseAsset + '_' + market.quotedAsset + ".json"; + let fileName = "Data.json"; let filePath if (dependency.dataSet === "Multi-Period-Market") { diff --git a/Root.js b/Root.js index 1619c0a99..cf7957c2a 100644 --- a/Root.js +++ b/Root.js @@ -225,7 +225,7 @@ botConfig.loopCounter = 0; /* File Path Root */ - botConfig.filePathRoot = botConfig.dataMine + "/" + botConfig.codeName + "/" + botConfig.exchange; + botConfig.filePathRoot = botConfig.exchange + "/" + botConfig.market.baseAsset + "-" + botConfig.market.quotedAsset + "/" + botConfig.dataMine + "/" + botConfig.codeName ; /* Process Key */ botConfig.processKey = global.TASK_NODE.bot.processes[processIndex].name + '-' + global.TASK_NODE.bot.processes[processIndex].type + '-' + global.TASK_NODE.bot.processes[processIndex].id diff --git a/StatusReport.js b/StatusReport.js index 3219a6587..4e1eec387 100644 --- a/StatusReport.js +++ b/StatusReport.js @@ -136,14 +136,16 @@ if (global.LOG_CONTROL[MODULE_NAME].logInfo === true) { logger.write(MODULE_NAME, "[INFO] load -> Entering function."); } - let fileName = "Status.Report." + bot.market.baseAsset + '_' + bot.market.quotedAsset + ".json"; + let fileName = "Status.Report.json"; let filePath; let ownerId = statusDependencyNode.dataMine + "-" + statusDependencyNode.bot + "-" + statusDependencyNode.botVersion.major + "-" + statusDependencyNode.botVersion.minor + "-" + statusDependencyNode.process + "-" + statusDependencyNode.dataSetVersion; let botId = bot.dataMine + "-" + bot.codeName + "-" + bot.version.major + "-" + bot.version.minor + "-" + bot.process + "-" + bot.dataSetVersion; if (ownerId !== botId) { - let rootPath = statusDependencyNode.dataMine + "/" + statusDependencyNode.bot + "/" + bot.exchange; + + let rootPath = bot.exchange + "/" + bot.market.baseAsset + "-" + bot.market.quotedAsset + "/" + statusDependencyNode.dataMine + "/" + statusDependencyNode.bot + filePath = rootPath + "/Reports/" + sessionPath + statusDependencyNode.process ; } else { filePath = bot.filePathRoot + "/Reports/" + sessionPath + statusDependencyNode.process ; @@ -233,7 +235,7 @@ return; } - let fileName = "Status.Report." + bot.market.baseAsset + '_' + bot.market.quotedAsset + ".json"; + let fileName = "Status.Report.json"; let filePath = bot.filePathRoot + "/Reports/" + sessionPath + statusDependencyNode.process; filePath += '/' + fileName diff --git a/TradingBot.js b/TradingBot.js index 3129df6d7..ee6647948 100644 --- a/TradingBot.js +++ b/TradingBot.js @@ -219,10 +219,8 @@ fileContent = "[" + fileContent + "]"; - let fileName = '' + market.baseAsset + '_' + market.quotedAsset + '.json'; - - let filePathRoot = bot.dataMine + "/" + bot.codeName + "/" + bot.exchange; - let filePath = filePathRoot + "/Output/" + bot.SESSION.folderName + "/" + SIMULATED_RECORDS_FOLDER_NAME + "/" + "Multi-Period-Market" + "/" + timeFrameLabel; + let fileName = 'Data.json'; + let filePath = bot.filePathRoot + "/Output/" + bot.SESSION.folderName + "/" + SIMULATED_RECORDS_FOLDER_NAME + "/" + "Multi-Period-Market" + "/" + timeFrameLabel; filePath += '/' + fileName fileStorage.createTextFile(filePath, fileContent + '\n', onFileCreated); @@ -297,10 +295,9 @@ fileContent = "[" + fileContent + "]"; fileContent = "[" + JSON.stringify(tradingSystem) + "," + fileContent + "]"; - let fileName = '' + market.baseAsset + '_' + market.quotedAsset + '.json'; - let filePathRoot = bot.dataMine + "/" + bot.codeName + "/" + bot.exchange; - let filePath = filePathRoot + "/Output/" + bot.SESSION.folderName + "/" + CONDITIONS_FOLDER_NAME + "/" + "Multi-Period-Market" + "/" + timeFrameLabel; + let fileName = 'Data.json'; + let filePath = bot.filePathRoot + "/Output/" + bot.SESSION.folderName + "/" + CONDITIONS_FOLDER_NAME + "/" + "Multi-Period-Market" + "/" + timeFrameLabel; filePath += '/' + fileName fileStorage.createTextFile(filePath, fileContent + '\n', onFileCreated); @@ -367,10 +364,9 @@ } fileContent = "[" + fileContent + "]"; - let fileName = '' + market.baseAsset + '_' + market.quotedAsset + '.json'; - let filePathRoot = bot.dataMine + "/" + bot.codeName + "/" + bot.exchange; - let filePath = filePathRoot + "/Output/" + bot.SESSION.folderName + "/" + STRATEGIES_FOLDER_NAME + "/" + "Multi-Period-Market" + "/" + timeFrameLabel; + let fileName = 'Data.json'; + let filePath = bot.filePathRoot + "/Output/" + bot.SESSION.folderName + "/" + STRATEGIES_FOLDER_NAME + "/" + "Multi-Period-Market" + "/" + timeFrameLabel; filePath += '/' + fileName fileStorage.createTextFile(filePath, fileContent + '\n', onFileCreated); @@ -440,10 +436,9 @@ } fileContent = "[" + fileContent + "]"; - let fileName = '' + market.baseAsset + '_' + market.quotedAsset + '.json'; - let filePathRoot = bot.dataMine + "/" + bot.codeName + "/" + bot.exchange; - let filePath = filePathRoot + "/Output/" + bot.SESSION.folderName + "/" + TRADES_FOLDER_NAME + "/" + "Multi-Period-Market" + "/" + timeFrameLabel; + let fileName = 'Data.json'; + let filePath = bot.filePathRoot + "/Output/" + bot.SESSION.folderName + "/" + TRADES_FOLDER_NAME + "/" + "Multi-Period-Market" + "/" + timeFrameLabel; filePath += '/' + fileName fileStorage.createTextFile(filePath, fileContent + '\n', onFileCreated); @@ -566,10 +561,8 @@ fileContent = "[" + fileContent + "]"; - let fileName = '' + market.baseAsset + '_' + market.quotedAsset + '.json'; - - let filePathRoot = bot.dataMine + "/" + bot.codeName + "/" + bot.exchange; - let filePath = filePathRoot + "/Output/" + bot.SESSION.folderName + "/" + SIMULATED_RECORDS_FOLDER_NAME + "/" + "Multi-Period-Daily" + "/" + timeFrameLabel; + let fileName = 'Data.json'; + let filePath = bot.filePathRoot + "/Output/" + bot.SESSION.folderName + "/" + SIMULATED_RECORDS_FOLDER_NAME + "/" + "Multi-Period-Daily" + "/" + timeFrameLabel; filePath += '/' + fileName fileStorage.createTextFile(filePath, fileContent + '\n', onFileCreated); @@ -673,10 +666,8 @@ fileContent = "[" + fileContent + "]"; let dateForPath = currentDay.getUTCFullYear() + '/' + utilities.pad(currentDay.getUTCMonth() + 1, 2) + '/' + utilities.pad(currentDay.getUTCDate(), 2); - let fileName = '' + market.baseAsset + '_' + market.quotedAsset + '.json'; - - let filePathRoot = bot.dataMine + "/" + bot.codeName + "/" + bot.exchange; - let filePath = filePathRoot + "/Output/" + bot.SESSION.folderName + "/" + SIMULATED_RECORDS_FOLDER_NAME + "/" + "Multi-Period-Daily" + "/" + timeFrameLabel + "/" + dateForPath; + let fileName = 'Data.json'; + let filePath = bot.filePathRoot + "/Output/" + bot.SESSION.folderName + "/" + SIMULATED_RECORDS_FOLDER_NAME + "/" + "Multi-Period-Daily" + "/" + timeFrameLabel + "/" + dateForPath; filePath += '/' + fileName fileStorage.createTextFile(filePath, fileContent + '\n', onFileCreated); @@ -761,10 +752,8 @@ fileContent = "[" + JSON.stringify(tradingSystem) + "," + fileContent + "]"; let dateForPath = currentDay.getUTCFullYear() + '/' + utilities.pad(currentDay.getUTCMonth() + 1, 2) + '/' + utilities.pad(currentDay.getUTCDate(), 2); - let fileName = '' + market.baseAsset + '_' + market.quotedAsset + '.json'; - - let filePathRoot = bot.dataMine + "/" + bot.codeName + "/" + bot.exchange; - let filePath = filePathRoot + "/Output/" + bot.SESSION.folderName + "/" + CONDITIONS_FOLDER_NAME + "/" + "Multi-Period-Daily" + "/" + timeFrameLabel + "/" + dateForPath; + let fileName = 'Data.json'; + let filePath = bot.filePathRoot + "/Output/" + bot.SESSION.folderName + "/" + CONDITIONS_FOLDER_NAME + "/" + "Multi-Period-Daily" + "/" + timeFrameLabel + "/" + dateForPath; filePath += '/' + fileName fileStorage.createTextFile(filePath, fileContent + '\n', onFileCreated); @@ -838,10 +827,8 @@ fileContent = "[" + fileContent + "]"; let dateForPath = currentDay.getUTCFullYear() + '/' + utilities.pad(currentDay.getUTCMonth() + 1, 2) + '/' + utilities.pad(currentDay.getUTCDate(), 2); - let fileName = '' + market.baseAsset + '_' + market.quotedAsset + '.json'; - - let filePathRoot = bot.dataMine + "/" + bot.codeName + "/" + bot.exchange; - let filePath = filePathRoot + "/Output/" + bot.SESSION.folderName + "/" + STRATEGIES_FOLDER_NAME + "/" + "Multi-Period-Daily" + "/" + timeFrameLabel + "/" + dateForPath; + let fileName = 'Data.json'; + let filePath = bot.filePathRoot + "/Output/" + bot.SESSION.folderName + "/" + STRATEGIES_FOLDER_NAME + "/" + "Multi-Period-Daily" + "/" + timeFrameLabel + "/" + dateForPath; filePath += '/' + fileName fileStorage.createTextFile(filePath, fileContent + '\n', onFileCreated); @@ -918,10 +905,8 @@ fileContent = "[" + fileContent + "]"; let dateForPath = currentDay.getUTCFullYear() + '/' + utilities.pad(currentDay.getUTCMonth() + 1, 2) + '/' + utilities.pad(currentDay.getUTCDate(), 2); - let fileName = '' + market.baseAsset + '_' + market.quotedAsset + '.json'; - - let filePathRoot = bot.dataMine + "/" + bot.codeName + "/" + bot.exchange; - let filePath = filePathRoot + "/Output/" + bot.SESSION.folderName + "/" + TRADES_FOLDER_NAME + "/" + "Multi-Period-Daily" + "/" + timeFrameLabel + "/" + dateForPath; + let fileName = 'Data.json'; + let filePath = bot.filePathRoot + "/Output/" + bot.SESSION.folderName + "/" + TRADES_FOLDER_NAME + "/" + "Multi-Period-Daily" + "/" + timeFrameLabel + "/" + dateForPath; filePath += '/' + fileName fileStorage.createTextFile(filePath, fileContent + '\n', onFileCreated); From a63ebc1afd949ac1600a43ad6001d177aefb2436 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Wed, 11 Mar 2020 14:21:25 +0100 Subject: [PATCH 09/23] Update Root.js --- Root.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Root.js b/Root.js index cf7957c2a..489b7fd18 100644 --- a/Root.js +++ b/Root.js @@ -205,7 +205,7 @@ /* Simplifying the access to basic info */ botConfig.dataMine = global.TASK_NODE.bot.processes[processIndex].referenceParent.parentNode.parentNode.code.codeName - botConfig.exchange = global.TASK_NODE.bot.processes[processIndex].marketReference.referenceParent.parentNode.parentNode.code.codeName + botConfig.exchange = global.TASK_NODE.bot.processes[processIndex].marketReference.referenceParent.parentNode.parentNode.name botConfig.exchangeNode = global.TASK_NODE.bot.processes[processIndex].marketReference.referenceParent.parentNode.parentNode botConfig.market = { baseAsset: global.TASK_NODE.bot.processes[processIndex].marketReference.referenceParent.baseAsset.referenceParent.code.codeName, From 1735508ae56682bd2f7468105316d525d498d701 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Wed, 11 Mar 2020 18:43:22 +0100 Subject: [PATCH 10/23] Cleaning --- SensorBotProcessMainLoop.js | 4 +--- TradingBot.js | 8 +------- TradingBotProcessMainLoop.js | 2 -- TradingSimulation.js | 2 +- 4 files changed, 3 insertions(+), 13 deletions(-) diff --git a/SensorBotProcessMainLoop.js b/SensorBotProcessMainLoop.js index 9f97243d3..4238fe306 100644 --- a/SensorBotProcessMainLoop.js +++ b/SensorBotProcessMainLoop.js @@ -56,9 +56,7 @@ return; } USER_BOT_MODULE = {} - if (bot.process === "Hole-Fixing") { - //USER_BOT_MODULE.newUserBot = require(process.env.BOTS_PATH + '/aamasters/AAMasters/bots/AACharly-Sensor-Bot/Hole-Fixing/User.Bot').newUserBot - } + try { USER_BOT_MODULE.newUserBot = eval(text); // TODO This needs to be changed function } catch (err) { diff --git a/TradingBot.js b/TradingBot.js index ee6647948..5399f3c34 100644 --- a/TradingBot.js +++ b/TradingBot.js @@ -103,7 +103,7 @@ } } - /* From here we have more or less the same we used to have at JASON */ + const TRADING_SIMULATION = require('./TradingSimulation.js'); let tradingSimulation = TRADING_SIMULATION.newTradingSimulation(bot, logger, UTILITIES); @@ -461,9 +461,6 @@ } - /* Emit event that signals that simulation files were updated */ - global.SYSTEM_EVENT_HANDLER.raiseEvent('Jason-Multi-Period', 'Simulation Files Updated') - callBackFunction(global.DEFAULT_OK_RESPONSE); } @@ -929,9 +926,6 @@ } - /* Emit event that signals that simulation files were updated */ - global.SYSTEM_EVENT_HANDLER.raiseEvent('Jason-Multi-Period', 'Simulation Files Updated') - callBackFunction(global.DEFAULT_OK_RESPONSE); } diff --git a/TradingBotProcessMainLoop.js b/TradingBotProcessMainLoop.js index 57eee04e8..fa1168f52 100644 --- a/TradingBotProcessMainLoop.js +++ b/TradingBotProcessMainLoop.js @@ -69,7 +69,6 @@ } USER_BOT_MODULE = {} - //USER_BOT_MODULE.newUserBot = require(process.env.BOTS_PATH + '/aamasters/AAMasters/bots/AAJason-Trading-Engine-Bot/Multi-Period/User.Bot').newUserBot // Use this for a better debugging experience. You need to bring this js module to this folder in order to work. USER_BOT_MODULE.newUserBot = eval(text); // Use this for production filePath = bot.dataMine + "/" + "bots" + "/" + bot.repo; @@ -86,7 +85,6 @@ } USER_BOT_COMMONS = {} - //USER_BOT_COMMONS.newCommons = require(process.env.BOTS_PATH + '/aamasters/AAMasters/bots/AAJason-Trading-Engine-Bot/Commons').newCommons // Use this for a better debugging experience. You need to bring this js module to this folder in order to work. USER_BOT_COMMONS.newCommons = eval(text); // Use this for production session.initialize(onSessionInitialized) diff --git a/TradingSimulation.js b/TradingSimulation.js index 06c48ab4a..a0a46252a 100644 --- a/TradingSimulation.js +++ b/TradingSimulation.js @@ -570,7 +570,7 @@ let processingDate = loopingDay.getUTCFullYear() + '-' + utilities.pad(loopingDay.getUTCMonth() + 1, 2) + '-' + utilities.pad(loopingDay.getUTCDate(), 2); if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] runSimulation -> loop -> Simulation " + bot.sessionKey + " Loop # " + currentCandleIndex + " @ " + processingDate) } - console.log("Jason -> " + MODULE_NAME + " -> runSimulation -> loop -> Simulation " + bot.sessionKey + " Loop # " + currentCandleIndex + " @ " + processingDate) + console.log("Trading-Engine -> " + MODULE_NAME + " -> runSimulation -> loop -> Simulation " + bot.sessionKey + " Loop # " + currentCandleIndex + " @ " + processingDate) bot.sessionHeartBeat(processingDate) // tell the world we are alive and doing well } From a135458569ab8ddb06170b7833a79a7ec8770098 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Sat, 14 Mar 2020 11:29:50 +0100 Subject: [PATCH 11/23] Logging Improved --- FileStorage.js | 13 +++++++------ IndicatorBotProcessMainLoop.js | 2 +- SensorBotProcessMainLoop.js | 2 +- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/FileStorage.js b/FileStorage.js index 8bca500eb..43a9933d0 100644 --- a/FileStorage.js +++ b/FileStorage.js @@ -8,6 +8,7 @@ exports.newFileStorage = function newFileStorage(logger) { const RETRY_TIME_IN_MILISECONDS = 250 let currentRetryGetTextFile = 0 let currentRetryWriteTextFile = 0 + let currentRetryDeleteTextFile = 0 if (logger === undefined) { // Dummy logger logger = {} @@ -242,14 +243,14 @@ exports.newFileStorage = function newFileStorage(logger) { } function retry() { - if (currentRetryWriteTextFile < MAX_RETRY) { - currentRetryWriteTextFile++ - logger.write(MODULE_NAME, '[WARN] FileStorage -> createTextFile -> retry -> Will try to write the file again -> Retry #: ' + currentRetryWriteTextFile) + if (currentRetryDeleteTextFile < MAX_RETRY) { + currentRetryDeleteTextFile++ + logger.write(MODULE_NAME, '[WARN] FileStorage -> deleteTextFile -> retry -> Will try to delete the file again -> Retry #: ' + currentRetryDeleteTextFile) createTextFile(filePath, fileContent, callBackFunction) } else { - currentRetryWriteTextFile = 0 - logger.write(MODULE_NAME, '[ERROR] FileStorage -> createTextFile -> retry -> Max retries reached writting a file. Giving up.') - logger.write(MODULE_NAME, '[ERROR] FileStorage -> createTextFile -> retry -> file = ' + fileLocation) + currentRetryDeleteTextFile = 0 + logger.write(MODULE_NAME, '[ERROR] FileStorage -> deleteTextFile -> retry -> Max retries reached deleting a file. Giving up.') + logger.write(MODULE_NAME, '[ERROR] FileStorage -> deleteTextFile -> retry -> file = ' + fileLocation) callBackFunction(global.DEFAULT_FAIL_RESPONSE) } } diff --git a/IndicatorBotProcessMainLoop.js b/IndicatorBotProcessMainLoop.js index 8915e5649..17eceba01 100644 --- a/IndicatorBotProcessMainLoop.js +++ b/IndicatorBotProcessMainLoop.js @@ -493,7 +493,7 @@ if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] run -> loop -> initializeUserBot -> Entering function."); } - usertBot = USER_BOT_MODULE.newUserBot(bot, logger, COMMONS_MODULE, UTILITIES, fileStorage); + usertBot = USER_BOT_MODULE.newUserBot(bot, logger, COMMONS_MODULE, UTILITIES, FILE_STORAGE); usertBot.initialize(statusDependencies, onInizialized); diff --git a/SensorBotProcessMainLoop.js b/SensorBotProcessMainLoop.js index 4238fe306..669a503b9 100644 --- a/SensorBotProcessMainLoop.js +++ b/SensorBotProcessMainLoop.js @@ -391,7 +391,7 @@ if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] run -> loop -> initializeUserBot -> Entering function."); } - usertBot = USER_BOT_MODULE.newUserBot(bot, logger, COMMONS_MODULE, UTILITIES, fileStorage, STATUS_REPORT, exchangeAPI); + usertBot = USER_BOT_MODULE.newUserBot(bot, logger, COMMONS_MODULE, UTILITIES, FILE_STORAGE, STATUS_REPORT, exchangeAPI); usertBot.initialize(statusDependencies, onInizialized); From fdf8641914a131699a3354ddc256df9b1ff81bb9 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Tue, 17 Mar 2020 10:21:50 +0100 Subject: [PATCH 12/23] quoted asset fix --- Session.js | 32 ++++++++++++++++++++++++++++++++ TradingBot.js | 3 +++ TradingSimulation.js | 2 ++ 3 files changed, 37 insertions(+) diff --git a/Session.js b/Session.js index 3d61e42aa..872258aad 100644 --- a/Session.js +++ b/Session.js @@ -287,6 +287,22 @@ } } + /* Quoted Asset */ + { + if (tradingSystem.parameters.quotedAsset !== undefined) { + if (tradingSystem.parameters.quotedAsset.referenceParent !== undefined) { + if (tradingSystem.parameters.quotedAsset.referenceParent.referenceParent !== undefined) { + + let code = tradingSystem.parameters.quotedAsset.referenceParent.referenceParent.code + + if (code.codeName !== undefined) { + bot.VALUES_TO_USE.quotedAsset = code.codeName; + } + } + } + } + } + /* Time Frame */ if (tradingSystem.parameters.timeFrame !== undefined) { bot.VALUES_TO_USE.timeFrame = tradingSystem.parameters.timeFrame.code.value @@ -398,6 +414,22 @@ } } + /* Quoted Asset. */ + { + if (bot.SESSION.parameters.quotedAsset !== undefined) { + if (bot.SESSION.parameters.quotedAsset.referenceParent !== undefined) { + if (bot.SESSION.parameters.quotedAsset.referenceParent.referenceParent !== undefined) { + + let code = bot.SESSION.parameters.quotedAsset.referenceParent.referenceParent.code + + if (code.codeName !== undefined) { + bot.VALUES_TO_USE.quotedAsset = code.codeName; + } + } + } + } + } + /* Time Frame */ if (bot.SESSION.parameters.timeFrame !== undefined) { bot.VALUES_TO_USE.timeFrame = bot.SESSION.parameters.timeFrame.code.value diff --git a/TradingBot.js b/TradingBot.js index 5399f3c34..7dacf7836 100644 --- a/TradingBot.js +++ b/TradingBot.js @@ -204,6 +204,7 @@ record.minimumBalanceB + "," + record.maximumBalanceB + "," + record.baseAsset + "," + + record.quotedAsset + "," + record.positionPeriods + "," + record.positionDays + "," + record.distanceToLastTriggerOn + "," + @@ -547,6 +548,7 @@ record.minimumBalanceB + "," + record.maximumBalanceB + "," + record.baseAsset + "," + + record.quotedAsset + "," + record.positionPeriods + "," + record.positionDays + "]"; @@ -651,6 +653,7 @@ record.minimumBalanceB + "," + record.maximumBalanceB + "," + record.baseAsset + "," + + record.quotedAsset + "," + record.positionPeriods + "," + record.positionDays + "]"; diff --git a/TradingSimulation.js b/TradingSimulation.js index a0a46252a..bb3de5360 100644 --- a/TradingSimulation.js +++ b/TradingSimulation.js @@ -2488,6 +2488,7 @@ } let quotedBaseAsset = '"' + bot.VALUES_TO_USE.baseAsset + '"' + let quotedQuotedAsset = '"' + bot.VALUES_TO_USE.quotedAsset + '"' simulationRecord = { begin: candle.begin, @@ -2524,6 +2525,7 @@ minimumBalanceB: bot.VALUES_TO_USE.minimumBalanceB, maximumBalanceB: bot.VALUES_TO_USE.maximumBalanceB, baseAsset: quotedBaseAsset, + quotedAsset: quotedQuotedAsset, positionPeriods: positionPeriods, positionDays: positionDays, distanceToLastTriggerOn: distanceToLast.triggerOn, From 78572f5cc0f45cfb57bed094cf1602f59b902999 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Thu, 19 Mar 2020 14:26:02 +0100 Subject: [PATCH 13/23] Possible fix --- FileStorage.js | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/FileStorage.js b/FileStorage.js index 43a9933d0..374ab653a 100644 --- a/FileStorage.js +++ b/FileStorage.js @@ -5,7 +5,8 @@ exports.newFileStorage = function newFileStorage(logger) { const MODULE_NAME = 'FileStorage' const MAX_RETRY = 30 - const RETRY_TIME_IN_MILISECONDS = 250 + const FAST_RETRY_TIME_IN_MILISECONDS = 500 + const SLOW_RETRY_TIME_IN_MILISECONDS = 5000 let currentRetryGetTextFile = 0 let currentRetryWriteTextFile = 0 let currentRetryDeleteTextFile = 0 @@ -49,7 +50,10 @@ exports.newFileStorage = function newFileStorage(logger) { fs.readFile(fileLocation, onFileRead) function onFileRead(err, text) { - + let retryTimeToUse = FAST_RETRY_TIME_IN_MILISECONDS + if (currentRetryGetTextFile < MAX_RETRY - 3) { + retryTimeToUse = SLOW_RETRY_TIME_IN_MILISECONDS + } if (err) { if (err.code === 'ENOENT') { // since files are deleted before being replaced, it can happen that it does not exist and after a retry it does. @@ -64,7 +68,7 @@ exports.newFileStorage = function newFileStorage(logger) { } else { fileDoesNotExist = true logger.write(MODULE_NAME, '[WARN] FileStorage -> getTextFile -> onFileRead -> File does not exist. Retrying. ') - setTimeout(retry, RETRY_TIME_IN_MILISECONDS) + setTimeout(retry, retryTimeToUse) return } } @@ -72,13 +76,13 @@ exports.newFileStorage = function newFileStorage(logger) { logger.write(MODULE_NAME, '[WARN] FileStorage -> getTextFile -> onFileRead -> Error reading file -> err = ' + err.stack) logger.write(MODULE_NAME, '[WARN] FileStorage -> getTextFile -> onFileRead -> Error reading file -> filePath = ' + filePath) logger.write(MODULE_NAME, '[WARN] FileStorage -> getTextFile -> onFileRead -> Error reading file -> err = ' + err.stack) - setTimeout(retry, RETRY_TIME_IN_MILISECONDS) + setTimeout(retry, retryTimeToUse) return } if (text.toString() === "") { logger.write(MODULE_NAME, '[WARN] FileStorage -> getTextFile -> onFileRead -> Read and Empty File -> filePath = ' + filePath) - setTimeout(retry, RETRY_TIME_IN_MILISECONDS) + setTimeout(retry, retryTimeToUse) return } @@ -145,10 +149,14 @@ exports.newFileStorage = function newFileStorage(logger) { fs.writeFile(fileLocation + '.tmp', fileContent, onFileWritenn) function onFileWritenn(err) { + let retryTimeToUse = FAST_RETRY_TIME_IN_MILISECONDS + if (currentRetryWriteTextFile < MAX_RETRY - 3) { + retryTimeToUse = SLOW_RETRY_TIME_IN_MILISECONDS + } if (err) { logger.write(MODULE_NAME, '[WARN] FileStorage -> createTextFile -> onFileWriten -> Error writing file -> file = ' + fileLocation) logger.write(MODULE_NAME, '[WARN] FileStorage -> createTextFile -> onFileWriten -> Error writing file -> err = ' + err.stack) - setTimeout(retry, RETRY_TIME_IN_MILISECONDS) + setTimeout(retry, retryTimeToUse) } else { const fs = require('fs') @@ -162,7 +170,7 @@ exports.newFileStorage = function newFileStorage(logger) { if (code !== '' && code !== 'ENOENT') { logger.write(MODULE_NAME, '[WARN] FileStorage -> createTextFile -> onFileWriten -> onUnlinked -> Error renaming file -> file = ' + fileLocation) logger.write(MODULE_NAME, '[WARN] FileStorage -> createTextFile -> onFileWriten -> onUnlinked -> Error renaming file -> err = ' + err.stack) - setTimeout(retry, RETRY_TIME_IN_MILISECONDS) + setTimeout(retry, retryTimeToUse) } else { const fs = require('fs') @@ -172,7 +180,7 @@ exports.newFileStorage = function newFileStorage(logger) { if (err) { logger.write(MODULE_NAME, '[WARN] FileStorage -> createTextFile -> onFileWriten -> onUnlinked -> onRenamed -> Error renaming file -> file = ' + fileLocation + '.tmp') logger.write(MODULE_NAME, '[WARN] FileStorage -> createTextFile -> onFileWriten -> onUnlinked -> onRenamed -> Error renaming file -> err = ' + err.stack) - setTimeout(retry, RETRY_TIME_IN_MILISECONDS) + setTimeout(retry, retryTimeToUse) } else { callBackFunction(global.DEFAULT_OK_RESPONSE) From 527bc180056b660b7650ee8113d0501516c9934f Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Thu, 19 Mar 2020 20:52:03 +0100 Subject: [PATCH 14/23] getPercentage implemented --- IndicatorBotProcessMainLoop.js | 5 +++-- MultiPeriodDaily.js | 11 +++++++---- SensorBotProcessMainLoop.js | 5 +++-- TradingBotProcessMainLoop.js | 5 +++-- TradingSimulation.js | 2 +- server.js | 10 ++++++++++ 6 files changed, 27 insertions(+), 11 deletions(-) diff --git a/IndicatorBotProcessMainLoop.js b/IndicatorBotProcessMainLoop.js index 17eceba01..b2593efb9 100644 --- a/IndicatorBotProcessMainLoop.js +++ b/IndicatorBotProcessMainLoop.js @@ -1076,10 +1076,11 @@ } } - function processHeartBeat(processingDate) { + function processHeartBeat(processingDate, percentage) { let event = { seconds: (new Date()).getSeconds(), - processingDate: processingDate + processingDate: processingDate, + percentage: percentage } global.SYSTEM_EVENT_HANDLER.raiseEvent(bot.processKey, 'Heartbeat', event) } diff --git a/MultiPeriodDaily.js b/MultiPeriodDaily.js index c9e9acc25..8666ed61c 100644 --- a/MultiPeriodDaily.js +++ b/MultiPeriodDaily.js @@ -307,6 +307,8 @@ let botNeverRan = true; bot.multiPeriodDailyProcessDatetime = new Date(contextVariables.lastFile.valueOf() - ONE_DAY_IN_MILISECONDS); // Go back one day to start well when we advance time at the begining of the loop. + let fromDate = new Date(bot.multiPeriodDailyProcessDatetime.valueOf()) + let lastDate = new Date() advanceTime(); @@ -334,6 +336,11 @@ } + /* Telling the world we are alive and doing well */ + let currentDateString = bot.multiPeriodDailyProcessDatetime.getUTCFullYear() + '-' + utilities.pad(bot.multiPeriodDailyProcessDatetime.getUTCMonth() + 1, 2) + '-' + utilities.pad(bot.multiPeriodDailyProcessDatetime.getUTCDate(), 2); + let currentDate = new Date(bot.multiPeriodDailyProcessDatetime) + bot.processHeartBeat(currentDateString, global.getPercentage(fromDate, currentDate, lastDate)) + checkStopTaskGracefully(); } catch (err) { @@ -371,10 +378,6 @@ if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> processTimeFrames -> periodsLoop -> Entering function."); } - /* Telling the world we are alive and doing well */ - let processingDate = bot.multiPeriodDailyProcessDatetime.getUTCFullYear() + '-' + utilities.pad(bot.multiPeriodDailyProcessDatetime.getUTCMonth() + 1, 2) + '-' + utilities.pad(bot.multiPeriodDailyProcessDatetime.getUTCDate(), 2); - bot.processHeartBeat(processingDate) - /* We will iterate through all posible periods. diff --git a/SensorBotProcessMainLoop.js b/SensorBotProcessMainLoop.js index 669a503b9..b627387b4 100644 --- a/SensorBotProcessMainLoop.js +++ b/SensorBotProcessMainLoop.js @@ -812,10 +812,11 @@ } } - function processHeartBeat(processingDate) { + function processHeartBeat(processingDate, percentage) { let event = { seconds: (new Date()).getSeconds(), - processingDate: processingDate + processingDate: processingDate, + percentage: percentage } global.SYSTEM_EVENT_HANDLER.raiseEvent(bot.processKey, 'Heartbeat', event) } diff --git a/TradingBotProcessMainLoop.js b/TradingBotProcessMainLoop.js index fa1168f52..472d1af46 100644 --- a/TradingBotProcessMainLoop.js +++ b/TradingBotProcessMainLoop.js @@ -1000,10 +1000,11 @@ } } - function processHeartBeat(processingDate) { + function processHeartBeat(processingDate, percentage) { let event = { seconds: (new Date()).getSeconds(), - processingDate: processingDate + processingDate: processingDate, + percentage: percentage } global.SYSTEM_EVENT_HANDLER.raiseEvent(bot.processKey, 'Heartbeat', event) } diff --git a/TradingSimulation.js b/TradingSimulation.js index bb3de5360..358068502 100644 --- a/TradingSimulation.js +++ b/TradingSimulation.js @@ -4,7 +4,7 @@ const LOG_FILE_CONTENT = false; const MODULE_NAME = "Trading Simulation -> " + bot.SESSION.name; - const ONE_DAY_IN_MILISECONDS = 24 * 60 * 60 * 1000; + const GMT_SECONDS = ':00.000 GMT+0000'; let thisObject = { diff --git a/server.js b/server.js index c7523ea32..6f9c02d52 100644 --- a/server.js +++ b/server.js @@ -25,6 +25,8 @@ global.CUSTOM_FAIL_RESPONSE = { message: "Custom Message" }; +const ONE_DAY_IN_MILISECONDS = 24 * 60 * 60 * 1000; + /* Process Events */ process.on('uncaughtException', function (err) { @@ -260,3 +262,11 @@ function startRoot(processIndex) { } } +global.getPercentage = function (fromDate, currentDate, lastDate) { + let fromDays = Math.trunc(fromDate.valueOf() / ONE_DAY_IN_MILISECONDS) + let currentDays = Math.trunc(currentDate.valueOf() / ONE_DAY_IN_MILISECONDS) + let lastDays = Math.trunc(lastDate.valueOf() / ONE_DAY_IN_MILISECONDS) + let percentage = (currentDays - fromDays) * 100 / (lastDays - fromDays) + return percentage.toFixed(2) + " %" +} + From e2d9f088bdd3286d0c38524e96f66a39432b2a4d Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Thu, 19 Mar 2020 22:16:46 +0100 Subject: [PATCH 15/23] percentage implemented --- Dockerfile | 9 --------- MultiPeriodDaily.js | 4 +++- MultiPeriodMarket.js | 10 +++++++++- docker-compose.yml | 12 ------------ server.js | 16 +++++++++++++++- 5 files changed, 27 insertions(+), 24 deletions(-) delete mode 100644 Dockerfile delete mode 100644 docker-compose.yml diff --git a/Dockerfile b/Dockerfile deleted file mode 100644 index 356128e9b..000000000 --- a/Dockerfile +++ /dev/null @@ -1,9 +0,0 @@ -FROM node:8.16-alpine - -RUN mkdir -p /usr/src/app -WORKDIR /usr/src/app - -COPY package.json ./ -RUN npm install - -COPY . . diff --git a/MultiPeriodDaily.js b/MultiPeriodDaily.js index 8666ed61c..7502a677b 100644 --- a/MultiPeriodDaily.js +++ b/MultiPeriodDaily.js @@ -811,7 +811,9 @@ bot.hasTheBotJustStarted = false; - logger.newInternalLoop(bot.codeName, bot.process, bot.multiPeriodDailyProcessDatetime); + if (global.areEqualDates(bot.multiPeriodDailyProcessDatetime, new Date()) === false) { + logger.newInternalLoop(bot.codeName, bot.process, bot.multiPeriodDailyProcessDatetime); + } } catch (err) { logger.write(MODULE_NAME, "[ERROR] start -> writeStatusReport -> err = "+ err.stack); diff --git a/MultiPeriodMarket.js b/MultiPeriodMarket.js index 66cf11951..4df897da6 100644 --- a/MultiPeriodMarket.js +++ b/MultiPeriodMarket.js @@ -338,7 +338,15 @@ thisReport.file.lastExecution = bot.processDatetime; thisReport.save(callBack); - logger.newInternalLoop(bot.codeName, bot.process, bot.processDatetime); + if (global.areEqualDates(bot.processDatetime, new Date()) === false) { + logger.newInternalLoop(bot.codeName, bot.process, bot.processDatetime); + } + + /* Telling the world we are alive and doing well */ + let currentDateString = bot.processDatetime.getUTCFullYear() + '-' + utilities.pad(bot.processDatetime.getUTCMonth() + 1, 2) + '-' + utilities.pad(bot.processDatetime.getUTCDate(), 2); + let currentDate = new Date(bot.processDatetime) + let lastDate = new Date() + bot.processHeartBeat(currentDateString, global.getPercentage(currentDate, currentDate, lastDate)) } catch (err) { logger.write(MODULE_NAME, "[ERROR] start -> writeStatusReport -> err = "+ err.stack); diff --git a/docker-compose.yml b/docker-compose.yml deleted file mode 100644 index 0a18fee7b..000000000 --- a/docker-compose.yml +++ /dev/null @@ -1,12 +0,0 @@ -version: '3' -services: - node: - image: superalgos/clone-executor:1.0.51 - build: - context: . - dockerfile: ./Dockerfile - container_name: clone-executor - tty: true - stdin_open: true - command: node Run.js - restart: always diff --git a/server.js b/server.js index 6f9c02d52..b89fdff3d 100644 --- a/server.js +++ b/server.js @@ -267,6 +267,20 @@ global.getPercentage = function (fromDate, currentDate, lastDate) { let currentDays = Math.trunc(currentDate.valueOf() / ONE_DAY_IN_MILISECONDS) let lastDays = Math.trunc(lastDate.valueOf() / ONE_DAY_IN_MILISECONDS) let percentage = (currentDays - fromDays) * 100 / (lastDays - fromDays) - return percentage.toFixed(2) + " %" + if ((lastDays - fromDays) === 0) { + percentage = 100 + } + return percentage.toFixed(0) + "%" +} + +global.areEqualDates = function (date1, date2) { + let day1Days = Math.trunc(date1.valueOf() / ONE_DAY_IN_MILISECONDS) + let day2Days = Math.trunc(date2.valueOf() / ONE_DAY_IN_MILISECONDS) + + if (day1Days === day2Days) { + return true + } else { + return false + } } From 8b9bd95fd9444b9b5881d297d5ee50a0e8e5cf4b Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Fri, 20 Mar 2020 11:02:11 +0100 Subject: [PATCH 16/23] logging improved --- DebugLog.js | 17 ++++++++++++----- FileStorage.js | 5 +++-- IndicatorBotProcessMainLoop.js | 4 ++-- MultiPeriodDaily.js | 10 ++++++---- SensorBotProcessMainLoop.js | 4 ++-- TradingBotProcessMainLoop.js | 4 ++-- server.js | 2 +- 7 files changed, 28 insertions(+), 18 deletions(-) diff --git a/DebugLog.js b/DebugLog.js index ba2c83788..7098aea4a 100644 --- a/DebugLog.js +++ b/DebugLog.js @@ -37,18 +37,25 @@ exports.newDebugLog = function newDebugLog() { } } - function newInternalLoop(pBot, pProcess, date) { + function newInternalLoop(pBot, pProcess, date, percentage) { + if (percentage === undefined) { + percentage = "" + } else { + percentage = percentage.toFixed(0) + "%" + } if (date === undefined) { date = thisObject.bot.processDatetime } + date = date.getUTCFullYear() + '-' + strPad(date.getUTCMonth() + 1, 2, "0") + '-' + strPad(date.getUTCDate(), 2, "0"); - console.log(new Date().toISOString() + " " + strPad(pBot, 20) + " " + strPad(pProcess, 30) + " " + strPad(thisObject.bot.exchange, 20) + " " + strPad(thisObject.bot.market.baseAsset + '/' + thisObject.bot.market.quotedAsset, 10) - + " Entered into Internal Loop # " + strPad(internalLoopCounter + 1, 8) + " " + strPad(date.toISOString(), 30)) + console.log(new Date().toISOString() + " " + strPad(thisObject.bot.exchange, 20) + " " + strPad(thisObject.bot.market.baseAsset + '/' + thisObject.bot.market.quotedAsset, 10) + " " + strPad(pBot, 20) + " " + strPad(pProcess, 30) + + " Internal Loop # " + strPad(internalLoopCounter + 1, 8) + " " + strPad(date, 30) + " " + strPad(percentage, 10)) persist(); - function strPad(str, max) { + function strPad(str, max, fill) { + if (fill === undefined) {fill = " "} str = str.toString(); - return str.length < max ? strPad(" " + str, max) : str; + return str.length < max ? strPad(fill + str, max) : str; } } diff --git a/FileStorage.js b/FileStorage.js index 374ab653a..2ec8a47ec 100644 --- a/FileStorage.js +++ b/FileStorage.js @@ -51,7 +51,7 @@ exports.newFileStorage = function newFileStorage(logger) { function onFileRead(err, text) { let retryTimeToUse = FAST_RETRY_TIME_IN_MILISECONDS - if (currentRetryGetTextFile < MAX_RETRY - 3) { + if (currentRetryGetTextFile > MAX_RETRY - 2) { retryTimeToUse = SLOW_RETRY_TIME_IN_MILISECONDS } if (err) { @@ -96,6 +96,7 @@ exports.newFileStorage = function newFileStorage(logger) { } function retry() { + //console.log(new Date(), ' Retry #: ' + currentRetryGetTextFile, fileLocation ) if (currentRetryGetTextFile < MAX_RETRY) { currentRetryGetTextFile++ logger.write(MODULE_NAME, '[WARN] FileStorage -> getTextFile -> retry -> Will try to read the file again -> Retry #: ' + currentRetryGetTextFile) @@ -150,7 +151,7 @@ exports.newFileStorage = function newFileStorage(logger) { function onFileWritenn(err) { let retryTimeToUse = FAST_RETRY_TIME_IN_MILISECONDS - if (currentRetryWriteTextFile < MAX_RETRY - 3) { + if (currentRetryWriteTextFile > MAX_RETRY - 2) { retryTimeToUse = SLOW_RETRY_TIME_IN_MILISECONDS } if (err) { diff --git a/IndicatorBotProcessMainLoop.js b/IndicatorBotProcessMainLoop.js index b2593efb9..1ec9eb324 100644 --- a/IndicatorBotProcessMainLoop.js +++ b/IndicatorBotProcessMainLoop.js @@ -145,8 +145,8 @@ /* High level log entry */ - console.log(new Date().toISOString() + " " + pad(bot.codeName, 20) + " " + pad(bot.process, 30) + " " + pad(bot.exchange, 20) + " " + pad(bot.market.baseAsset + '/' + bot.market.quotedAsset, 10) - + " Entered into Main Loop # " + pad(Number(bot.loopCounter), 8)); + console.log(new Date().toISOString() + " " + pad(bot.exchange, 20) + " " + pad(bot.market.baseAsset + '/' + bot.market.quotedAsset, 10) + " " + pad(bot.codeName, 20) + " " + pad(bot.process, 30) + + " Main Loop # " + pad(Number(bot.loopCounter), 8)) /* We will prepare first the infraestructure needed for the bot to run. There are 3 modules we need to sucessfullly initialize first. */ diff --git a/MultiPeriodDaily.js b/MultiPeriodDaily.js index 7502a677b..516737d4c 100644 --- a/MultiPeriodDaily.js +++ b/MultiPeriodDaily.js @@ -339,7 +339,12 @@ /* Telling the world we are alive and doing well */ let currentDateString = bot.multiPeriodDailyProcessDatetime.getUTCFullYear() + '-' + utilities.pad(bot.multiPeriodDailyProcessDatetime.getUTCMonth() + 1, 2) + '-' + utilities.pad(bot.multiPeriodDailyProcessDatetime.getUTCDate(), 2); let currentDate = new Date(bot.multiPeriodDailyProcessDatetime) - bot.processHeartBeat(currentDateString, global.getPercentage(fromDate, currentDate, lastDate)) + let percentage = global.getPercentage(fromDate, currentDate, lastDate) + bot.processHeartBeat(currentDateString, percentage) + + if (global.areEqualDates(currentDate, new Date()) === false) { + logger.newInternalLoop(bot.codeName, bot.process, currentDate, percentage); + } checkStopTaskGracefully(); @@ -811,9 +816,6 @@ bot.hasTheBotJustStarted = false; - if (global.areEqualDates(bot.multiPeriodDailyProcessDatetime, new Date()) === false) { - logger.newInternalLoop(bot.codeName, bot.process, bot.multiPeriodDailyProcessDatetime); - } } catch (err) { logger.write(MODULE_NAME, "[ERROR] start -> writeStatusReport -> err = "+ err.stack); diff --git a/SensorBotProcessMainLoop.js b/SensorBotProcessMainLoop.js index b627387b4..232131119 100644 --- a/SensorBotProcessMainLoop.js +++ b/SensorBotProcessMainLoop.js @@ -148,8 +148,8 @@ /* High level log entry */ - console.log(new Date().toISOString() + " " + pad(bot.codeName, 20) + " " + pad(bot.process, 30) + " " + pad(bot.exchange, 20) + " " + pad(bot.market.baseAsset + '/' + bot.market.quotedAsset, 10) - + " Entered into Main Loop # " + pad(Number(bot.loopCounter), 8) ) + console.log(new Date().toISOString() + " " + pad(bot.exchange, 20) + " " + pad(bot.market.baseAsset + '/' + bot.market.quotedAsset, 10) + " " + pad(bot.codeName, 20) + " " + pad(bot.process, 30) + + " Main Loop # " + pad(Number(bot.loopCounter), 8) ) /* We will prepare first the infraestructure needed for the bot to run. There are 4 modules we need to sucessfullly initialize first. */ diff --git a/TradingBotProcessMainLoop.js b/TradingBotProcessMainLoop.js index 472d1af46..5d4034129 100644 --- a/TradingBotProcessMainLoop.js +++ b/TradingBotProcessMainLoop.js @@ -157,8 +157,8 @@ /* High level log entry */ - console.log(new Date().toISOString() + " " + pad(bot.codeName, 20) + " " + pad(bot.process, 30) + " " + pad(bot.exchange, 20) + " " + pad(bot.market.baseAsset + '/' + bot.market.quotedAsset, 10) - + " Entered into Main Loop # " + pad(Number(bot.loopCounter), 8) + " " + bot.sessionKey ) + console.log(new Date().toISOString() + " " + pad(bot.exchange, 20) + " " + pad(bot.market.baseAsset + '/' + bot.market.quotedAsset, 10) + " " + pad(bot.codeName, 20) + " " + pad(bot.process, 30) + + " Main Loop # " + pad(Number(bot.loopCounter), 8) + " " + bot.sessionKey) /* Checking if we need to need to emit any event */ diff --git a/server.js b/server.js index b89fdff3d..947341e30 100644 --- a/server.js +++ b/server.js @@ -270,7 +270,7 @@ global.getPercentage = function (fromDate, currentDate, lastDate) { if ((lastDays - fromDays) === 0) { percentage = 100 } - return percentage.toFixed(0) + "%" + return percentage } global.areEqualDates = function (date1, date2) { From f46cee4e5532b754a85f6a5fa626330383bae5d6 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Fri, 20 Mar 2020 13:46:41 +0100 Subject: [PATCH 17/23] Process Status Working --- IndicatorBotProcessMainLoop.js | 6 ++++-- ProcessExecutionEvents.js | 4 ++++ SensorBotProcessMainLoop.js | 6 ++++-- TradingBotProcessMainLoop.js | 6 ++++-- 4 files changed, 16 insertions(+), 6 deletions(-) diff --git a/IndicatorBotProcessMainLoop.js b/IndicatorBotProcessMainLoop.js index 1ec9eb324..9017258db 100644 --- a/IndicatorBotProcessMainLoop.js +++ b/IndicatorBotProcessMainLoop.js @@ -964,6 +964,7 @@ logger.persist(); } + processStopped() callBackFunction(global.DEFAULT_OK_RESPONSE); return; @@ -1076,11 +1077,12 @@ } } - function processHeartBeat(processingDate, percentage) { + function processHeartBeat(processingDate, percentage, status) { let event = { seconds: (new Date()).getSeconds(), processingDate: processingDate, - percentage: percentage + percentage: percentage, + status: status } global.SYSTEM_EVENT_HANDLER.raiseEvent(bot.processKey, 'Heartbeat', event) } diff --git a/ProcessExecutionEvents.js b/ProcessExecutionEvents.js index ed79e1be7..4f26e7708 100644 --- a/ProcessExecutionEvents.js +++ b/ProcessExecutionEvents.js @@ -83,6 +83,8 @@ global.SYSTEM_EVENT_HANDLER.listenToEvent(key, 'Process Execution Finished', undefined, callerId, responseCallBack, eventsCallBack) + bot.processHeartBeat(undefined, undefined, "Waiting for " + processThisDependsOn.parentNode.parentNode.name + "->" + processThisDependsOn.parentNode.code.codeName + "->" + processThisDependsOn.code.codeName) + function responseCallBack(message) { if (message.result !== global.DEFAULT_OK_RESPONSE.result) { logger.write(MODULE_NAME, "[ERROR] start -> responseCallBack -> message = " + JSON.stringify(message)) @@ -110,6 +112,8 @@ global.SYSTEM_EVENT_HANDLER.createEventHandler(currentProcessKey, 'Process Execution Started') global.SYSTEM_EVENT_HANDLER.raiseEvent(currentProcessKey, 'Process Execution Started', event) + bot.processHeartBeat(undefined, undefined,"Running") + if (global.LOG_CONTROL[MODULE_NAME].logInfo === true) { logger.write(MODULE_NAME, "[INFO] start -> eventsCallBack -> " + currentProcessKey + " Process Execution Started because " + key + " Finished."); } } diff --git a/SensorBotProcessMainLoop.js b/SensorBotProcessMainLoop.js index 232131119..4eecc7e54 100644 --- a/SensorBotProcessMainLoop.js +++ b/SensorBotProcessMainLoop.js @@ -676,6 +676,7 @@ clearTimeout(nextLoopTimeoutHandle); clearTimeout(checkLoopHealthHandle); bot.enableCheckLoopHealth = false; + processStopped() callBackFunction(global.DEFAULT_OK_RESPONSE); return; @@ -812,11 +813,12 @@ } } - function processHeartBeat(processingDate, percentage) { + function processHeartBeat(processingDate, percentage, status) { let event = { seconds: (new Date()).getSeconds(), processingDate: processingDate, - percentage: percentage + percentage: percentage, + status: status } global.SYSTEM_EVENT_HANDLER.raiseEvent(bot.processKey, 'Heartbeat', event) } diff --git a/TradingBotProcessMainLoop.js b/TradingBotProcessMainLoop.js index 5d4034129..473a5b93d 100644 --- a/TradingBotProcessMainLoop.js +++ b/TradingBotProcessMainLoop.js @@ -880,6 +880,7 @@ } global.SYSTEM_EVENT_HANDLER.raiseEvent(bot.sessionKey, 'Stopped') + processStopped() callBackFunction(global.DEFAULT_OK_RESPONSE); return; @@ -1000,11 +1001,12 @@ } } - function processHeartBeat(processingDate, percentage) { + function processHeartBeat(processingDate, percentage, status) { let event = { seconds: (new Date()).getSeconds(), processingDate: processingDate, - percentage: percentage + percentage: percentage, + status: status } global.SYSTEM_EVENT_HANDLER.raiseEvent(bot.processKey, 'Heartbeat', event) } From 4c0b364dbf6da7b934ffbcb212c39ffe4a0af174 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Fri, 20 Mar 2020 14:12:09 +0100 Subject: [PATCH 18/23] Status implemented --- IndicatorBotProcessMainLoop.js | 4 ++++ ProcessExecutionEvents.js | 2 +- SensorBotProcessMainLoop.js | 34 ++++++++++++---------------------- TradingBotProcessMainLoop.js | 4 ++++ 4 files changed, 21 insertions(+), 23 deletions(-) diff --git a/IndicatorBotProcessMainLoop.js b/IndicatorBotProcessMainLoop.js index 9017258db..a99c9e97b 100644 --- a/IndicatorBotProcessMainLoop.js +++ b/IndicatorBotProcessMainLoop.js @@ -983,6 +983,7 @@ checkLoopHealthHandle = setTimeout(checkLoopHealth, processConfig.deadWaitTime, bot.loopCounter); } nextLoopTimeoutHandle = setTimeout(loop, processConfig.normalWaitTime); + processHeartBeat(undefined, undefined, "Waiting " + processConfig.normalWaitTime / 1000 + " seconds for next execution.") if(global.WRITE_LOGS_TO_FILES === 'true'){ logger.persist(); } @@ -994,18 +995,21 @@ checkLoopHealthHandle = setTimeout(checkLoopHealth, processConfig.deadWaitTime, bot.loopCounter); } nextLoopTimeoutHandle = setTimeout(loop, processConfig.retryWaitTime); + processHeartBeat(undefined, undefined, "Trying to recover from some problem. Waiting " + processConfig.retryWaitTime / 1000 + " seconds for next execution.") logger.persist(); } break; case 'Sleep': { if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] run -> loop -> loopControl -> Restarting Loop in " + (processConfig.sleepWaitTime / 60000) + " minutes."); } nextLoopTimeoutHandle = setTimeout(loop, processConfig.sleepWaitTime); + processHeartBeat(undefined, undefined, "Waiting " + processConfig.sleepWaitTime / 60000 + " minutes for next execution.") logger.persist(); } break; case 'Coma': { if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] run -> loop -> loopControl -> Restarting Loop in " + (processConfig.comaWaitTime / 3600000) + " hours."); } nextLoopTimeoutHandle = setTimeout(loop, processConfig.comaWaitTime); + processHeartBeat(undefined, undefined, "Waiting " + processConfig.comaWaitTime / 3600000 + " hours for next execution.") logger.persist(); } break; diff --git a/ProcessExecutionEvents.js b/ProcessExecutionEvents.js index 4f26e7708..72741eba4 100644 --- a/ProcessExecutionEvents.js +++ b/ProcessExecutionEvents.js @@ -112,7 +112,7 @@ global.SYSTEM_EVENT_HANDLER.createEventHandler(currentProcessKey, 'Process Execution Started') global.SYSTEM_EVENT_HANDLER.raiseEvent(currentProcessKey, 'Process Execution Started', event) - bot.processHeartBeat(undefined, undefined,"Running") + bot.processHeartBeat(undefined, undefined,"Running...") if (global.LOG_CONTROL[MODULE_NAME].logInfo === true) { logger.write(MODULE_NAME, "[INFO] start -> eventsCallBack -> " + currentProcessKey + " Process Execution Started because " + key + " Finished."); } } diff --git a/SensorBotProcessMainLoop.js b/SensorBotProcessMainLoop.js index 4eecc7e54..f73961f20 100644 --- a/SensorBotProcessMainLoop.js +++ b/SensorBotProcessMainLoop.js @@ -113,7 +113,7 @@ function loop() { try { - + processHeartBeat(undefined, undefined, "Running...") function pad(str, max) { str = str.toString(); return str.length < max ? pad(" " + str, max) : str; @@ -655,9 +655,6 @@ if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] run -> loop -> loopControl -> nextWaitTime = " + nextWaitTime); } /* We show we reached the end of the loop. */ - - processHeartBeat() - /* Here we check if we must stop the loop gracefully. */ shallWeStop(onStop, onContinue); @@ -690,24 +687,14 @@ switch (nextWaitTime) { case 'Normal': { - if (bot.runAtFixedInterval === true) { - if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] run -> loop -> loopControl -> Fixed Interval Normal exit point reached."); } - if (processConfig.deadWaitTime > 0) { - checkLoopHealthHandle = setTimeout(checkLoopHealth, processConfig.deadWaitTime, bot.loopCounter); - } - if(global.WRITE_LOGS_TO_FILES === 'true'){ - logger.persist(); - } - return; - } else { - if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] run -> loop -> loopControl -> Restarting Loop in " + (processConfig.normalWaitTime / 1000) + " seconds."); } - if (processConfig.deadWaitTime > 0) { - checkLoopHealthHandle = setTimeout(checkLoopHealth, processConfig.deadWaitTime, bot.loopCounter); - } - nextLoopTimeoutHandle = setTimeout(loop, processConfig.normalWaitTime); - if(global.WRITE_LOGS_TO_FILES === 'true'){ - logger.persist(); - } + if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] run -> loop -> loopControl -> Restarting Loop in " + (processConfig.normalWaitTime / 1000) + " seconds."); } + if (processConfig.deadWaitTime > 0) { + checkLoopHealthHandle = setTimeout(checkLoopHealth, processConfig.deadWaitTime, bot.loopCounter); + } + nextLoopTimeoutHandle = setTimeout(loop, processConfig.normalWaitTime); + processHeartBeat(undefined, undefined, "Waiting " + processConfig.normalWaitTime / 1000 + " seconds for next execution.") + if(global.WRITE_LOGS_TO_FILES === 'true'){ + logger.persist(); } } break; @@ -717,6 +704,7 @@ checkLoopHealthHandle = setTimeout(checkLoopHealth, processConfig.retryWaitTime * 5, bot.loopCounter); } nextLoopTimeoutHandle = setTimeout(loop, processConfig.retryWaitTime); + processHeartBeat(undefined, undefined, "Trying to recover from some problem. Waiting " + processConfig.retryWaitTime / 1000 + " seconds for next execution.") logger.persist(); } break; @@ -728,6 +716,7 @@ } else { if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] run -> loop -> loopControl -> Restarting Loop in " + (processConfig.sleepWaitTime / 60000) + " minutes."); } nextLoopTimeoutHandle = setTimeout(loop, processConfig.sleepWaitTime); + processHeartBeat(undefined, undefined, "Waiting " + processConfig.sleepWaitTime / 60000 + " minutes for next execution.") logger.persist(); } } @@ -740,6 +729,7 @@ } else { if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] run -> loop -> loopControl -> Restarting Loop in " + (processConfig.comaWaitTime / 3600000) + " hours."); } nextLoopTimeoutHandle = setTimeout(loop, processConfig.comaWaitTime); + processHeartBeat(undefined, undefined, "Waiting " + processConfig.comaWaitTime / 3600000 + " hours for next execution.") logger.persist(); } } diff --git a/TradingBotProcessMainLoop.js b/TradingBotProcessMainLoop.js index 473a5b93d..752f94e8a 100644 --- a/TradingBotProcessMainLoop.js +++ b/TradingBotProcessMainLoop.js @@ -906,6 +906,7 @@ checkLoopHealthHandle = setTimeout(checkLoopHealth, processConfig.deadWaitTime, bot.loopCounter); } nextLoopTimeoutHandle = setTimeout(loop, waitTime); + processHeartBeat(undefined, undefined, "Waiting " + processConfig.waitTime / 1000 + " seconds for next execution.") if (global.WRITE_LOGS_TO_FILES === 'true') { logger.persist(); } @@ -917,18 +918,21 @@ checkLoopHealthHandle = setTimeout(checkLoopHealth, processConfig.deadWaitTime, bot.loopCounter); } nextLoopTimeoutHandle = setTimeout(loop, processConfig.retryWaitTime); + processHeartBeat(undefined, undefined, "Trying to recover from some problem. Waiting " + processConfig.retryWaitTime / 1000 + " seconds for next execution.") logger.persist(); } break; case 'Sleep': { if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] run -> loop -> loopControl -> Restarting Loop in " + (processConfig.sleepWaitTime / 60000) + " minutes."); } nextLoopTimeoutHandle = setTimeout(loop, processConfig.sleepWaitTime); + processHeartBeat(undefined, undefined, "Waiting " + processConfig.sleepWaitTime / 60000 + " minutes for next execution.") logger.persist(); } break; case 'Coma': { if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] run -> loop -> loopControl -> Restarting Loop in " + (processConfig.comaWaitTime / 3600000) + " hours."); } nextLoopTimeoutHandle = setTimeout(loop, processConfig.comaWaitTime); + processHeartBeat(undefined, undefined, "Waiting " + processConfig.comaWaitTime / 3600000 + " hours for next execution.") logger.persist(); } break; From adbc19e5204c4647832d1d2ab76979de9bf3d787 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Sat, 21 Mar 2020 12:11:00 +0100 Subject: [PATCH 19/23] Update TradingSimulation.js --- TradingSimulation.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/TradingSimulation.js b/TradingSimulation.js index 358068502..15d0ae74c 100644 --- a/TradingSimulation.js +++ b/TradingSimulation.js @@ -2,7 +2,7 @@ const FULL_LOG = true; const LOG_FILE_CONTENT = false; - + const ONE_DAY_IN_MILISECONDS = 24 * 60 * 60 * 1000; const MODULE_NAME = "Trading Simulation -> " + bot.SESSION.name; const GMT_SECONDS = ':00.000 GMT+0000'; From a52eb06cf43b83d0a1f2e0dc96509ffe5447161d Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Sat, 21 Mar 2020 12:38:05 +0100 Subject: [PATCH 20/23] Update TradingBotProcessMainLoop.js --- TradingBotProcessMainLoop.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/TradingBotProcessMainLoop.js b/TradingBotProcessMainLoop.js index 752f94e8a..3820e6d33 100644 --- a/TradingBotProcessMainLoop.js +++ b/TradingBotProcessMainLoop.js @@ -117,6 +117,7 @@ try { + processHeartBeat(undefined, undefined, "Running...") function pad(str, max) { str = str.toString(); return str.length < max ? pad(" " + str, max) : str; @@ -906,7 +907,7 @@ checkLoopHealthHandle = setTimeout(checkLoopHealth, processConfig.deadWaitTime, bot.loopCounter); } nextLoopTimeoutHandle = setTimeout(loop, waitTime); - processHeartBeat(undefined, undefined, "Waiting " + processConfig.waitTime / 1000 + " seconds for next execution.") + processHeartBeat(undefined, undefined, "Waiting " + waitTime / 1000 + " seconds for next execution.") if (global.WRITE_LOGS_TO_FILES === 'true') { logger.persist(); } From 15c29233f375c4e9a5913f7f7d2dc94ad33fb7c2 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Sat, 21 Mar 2020 18:01:19 +0100 Subject: [PATCH 21/23] bug fixes --- TradingSimulation.js | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/TradingSimulation.js b/TradingSimulation.js index 15d0ae74c..59413023f 100644 --- a/TradingSimulation.js +++ b/TradingSimulation.js @@ -658,7 +658,7 @@ let key = j + '-' + 'triggerStage' + '-' + 'triggerOn' + '-' + k + '-' + m; if (condition.javascriptCode !== undefined) { - newCondition(key, condition.javascriptCode); + newCondition(key, condition.javascriptCode, chart); } } } @@ -676,7 +676,7 @@ let key = j + '-' + 'triggerStage' + '-' + 'triggerOff' + '-' + k + '-' + m; if (condition.javascriptCode !== undefined) { - newCondition(key, condition.javascriptCode); + newCondition(key, condition.javascriptCode, chart); } } } @@ -694,7 +694,7 @@ let key = j + '-' + 'triggerStage' + '-' + 'takePosition' + '-' + k + '-' + m; if (condition.javascriptCode !== undefined) { - newCondition(key, condition.javascriptCode); + newCondition(key, condition.javascriptCode, chart); } } } @@ -825,7 +825,7 @@ let key = j + '-' + 'openStage' + '-' + 'initialDefinition' + '-' + 'stopLoss' + '-' + p + '-' + k + '-' + m; if (condition.javascriptCode !== undefined) { - newCondition(key, condition.javascriptCode); + newCondition(key, condition.javascriptCode, chart); } } } @@ -891,7 +891,7 @@ let key = j + '-' + 'openStage' + '-' + 'initialDefinition' + '-' + 'takeProfit' + '-' + p + '-' + k + '-' + m; if (condition.javascriptCode !== undefined) { - newCondition(key, condition.javascriptCode); + newCondition(key, condition.javascriptCode, chart); } } } @@ -967,7 +967,7 @@ let key = j + '-' + 'manageStage' + '-' + 'stopLoss' + '-' + p + '-' + k + '-' + m; if (condition.javascriptCode !== undefined) { - newCondition(key, condition.javascriptCode); + newCondition(key, condition.javascriptCode, chart); } } } @@ -1034,7 +1034,7 @@ let key = j + '-' + 'manageStage' + '-' + 'takeProfit' + '-' + p + '-' + k + '-' + m; if (condition.javascriptCode !== undefined) { - newCondition(key, condition.javascriptCode); + newCondition(key, condition.javascriptCode, chart); } } } @@ -1043,7 +1043,7 @@ } } - function newCondition(key, node) { + function newCondition(key, node, chart) { let condition; let error = '' @@ -1103,6 +1103,14 @@ maximumBalance = bot.VALUES_TO_USE.maximumBalanceB } + if (minimumBalance === undefined) { + minimumBalance = 0 + } + + if (maximumBalance === undefined) { + maximumBalance = 10000000000000000 + } + if (balance > minimumBalance && balance < maximumBalance) { /* From ba2e701019aa78c4f4ca8a50d42c78b6926b5d13 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Sun, 22 Mar 2020 10:53:48 +0100 Subject: [PATCH 22/23] Update DebugLog.js --- DebugLog.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DebugLog.js b/DebugLog.js index 7098aea4a..123a45006 100644 --- a/DebugLog.js +++ b/DebugLog.js @@ -41,7 +41,7 @@ exports.newDebugLog = function newDebugLog() { if (percentage === undefined) { percentage = "" } else { - percentage = percentage.toFixed(0) + "%" + percentage = percentage.toFixed(2) + " %" } if (date === undefined) { date = thisObject.bot.processDatetime } From 4ba3ae7f339a9407ac434ac428a44ecb50c8f19f Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Sun, 22 Mar 2020 11:10:49 +0100 Subject: [PATCH 23/23] Cleaning excesive logging --- Root.js | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/Root.js b/Root.js index 489b7fd18..7ed96f1c7 100644 --- a/Root.js +++ b/Root.js @@ -387,7 +387,6 @@ logger.write(MODULE_NAME, "[INFO] start -> bootingBot -> runSensorBot -> onInitializeReady -> whenStartFinishes -> Bot execution finished sucessfully."); logger.write(MODULE_NAME, "[INFO] start -> bootingBot -> runSensorBot -> onInitializeReady -> whenStartFinishes -> Bot Id = " + botId); - console.log(logDisplace + "Root : [INFO] start -> bootingBot -> runSensorBot -> onInitializeReady -> whenStartFinishes -> Bot execution finished sucessfully."); logger.persist(); } else { @@ -452,8 +451,6 @@ logger.write(MODULE_NAME, "[INFO] start -> bootingBot -> runIndicatorBot -> onInitializeReady -> whenStartFinishes -> Bot execution finished sucessfully."); logger.write(MODULE_NAME, "[INFO] start -> bootingBot -> runIndicatorBot -> onInitializeReady -> whenStartFinishes -> Bot Id = " + botId); - - console.log(logDisplace + "Root : [INFO] start -> bootingBot -> runIndicatorBot -> onInitializeReady -> whenStartFinishes -> Bot execution finished sucessfully."); logger.persist(); } else { @@ -518,8 +515,6 @@ logger.write(MODULE_NAME, "[INFO] start -> bootingBot -> runTradingBot -> onInitializeReady -> whenStartFinishes -> Bot execution finished sucessfully."); logger.write(MODULE_NAME, "[INFO] start -> bootingBot -> runTradingBot -> onInitializeReady -> whenStartFinishes -> Bot Id = " + botId); - console.log(logDisplace + "Root : [INFO] start -> bootingBot -> runTradingBot -> onInitializeReady -> whenStartFinishes -> botId = " + botId); - console.log(logDisplace + "Root : [INFO] start -> bootingBot -> runTradingBot -> onInitializeReady -> whenStartFinishes -> Bot execution finished sucessfully."); logger.persist(); } else { @@ -558,7 +553,7 @@ function exitProcessInstance() { global.ENDED_PROCESSES_COUNTER++ - console.log("[INFO] Task Server -> " + global.TASK_NODE.name + " -> exitProcessInstance -> Process #" + global.ENDED_PROCESSES_COUNTER + " from " + global.TOTAL_PROCESS_INSTANCES_CREATED + " exiting."); + //console.log("[INFO] Task Server -> " + global.TASK_NODE.name + " -> exitProcessInstance -> Process #" + global.ENDED_PROCESSES_COUNTER + " from " + global.TOTAL_PROCESS_INSTANCES_CREATED + " exiting."); if (global.ENDED_PROCESSES_COUNTER === global.TOTAL_PROCESS_INSTANCES_CREATED) { global.EXIT_NODE_PROCESS()