From f988a336038673ff4db62524252a1f38ee02eddb Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Wed, 14 Mar 2018 19:51:09 +0100 Subject: [PATCH] Ready to Debug the first Indicator Bot Process in Alpha --- .vs/AACloudPlatform/v15/.suo | Bin 78848 -> 73216 bytes Indicator Bot Main Loop.js | 170 +++-------------------------------- Run.js | 22 ++--- 3 files changed, 22 insertions(+), 170 deletions(-) diff --git a/.vs/AACloudPlatform/v15/.suo b/.vs/AACloudPlatform/v15/.suo index d00fbcd3a01e0872db7b9cd1d4a627a560292681..7560b6487ea3fce41c9453d6a3f812709af86523 100644 GIT binary patch delta 2086 zcmcJQe@v8R9Ki4U+l%)8^yV}%ags7=a6!z)W2E^T zcj!!BR~+P%<>V+@8AikqBFQNvClg^)dgTp{6G-L~*+d%lo8!=IkRxBD*({=zD8~ZB z%aZVctp{NfEDCK96hSR$Sfb&05=`q6~28%L7PMU_H`+C*J8 zBAv)5CJ}aVPS`5R2~%k{jSyan24yNqE0N}Pjf#AX29<=^;PSf0Vxh)9Rm6FQl+P0L zi06p;!~!DR7Lp5z6~rQ9F|mZG7VT=)IP}7SczjWI{Z?8~2y{f04s_QOVF?fT?x-ff zVxtY7$6Dh$*n@x2`$Mdae)C=p*WPIuFv}8`<9i@rVT?1m4e*GZ7f2}v$sm$wIx3@` z>9J-(CkC_ayv8<5jYpQ`VL?tD##tAkJI99hi)P+xb%J7M%2F1Hm08%OVW6l`XbW`? zlT+>cs_Vg9JvtyC2}kjkW$`Tgaq!KQxtwCXGvas;uACdgW3qa|XDb|x?os=e2Hy*2 z0tR2mRdOX?c2E+Z0(PCYX&JjSG~DcKpkV`GL+nZuL{37gui4HIB4-_%g2Rve7H2Uh*A)`YG3we>ot)G@TO z7<4{m#OkMa@`F2y)V`8q(qur8VqRlUYVNvv% zi&p4V4S3-^oymCKis2VOSh+QL7L+qgIm&!zgN;EGQ2p;En4=lgm?uO$ylbL_r+E8m?{0bt{BF$Bowrl9|DAv#@&+|yY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loop.js index f8e432170..575cbe481 100644 --- a/Indicator Bot Main Loop.js +++ b/Indicator Bot Main Loop.js @@ -55,154 +55,46 @@ const UTILITIES = require(ROOT_DIR + 'Utilities'); const AZURE_FILE_STORAGE = require(ROOT_DIR + 'Azure File Storage'); const DEBUG_MODULE = require(ROOT_DIR + 'Debug Log'); - const POLONIEX_CLIENT_MODULE = require(ROOT_DIR + 'Poloniex API Client'); - const EXCHANGE_API = require(ROOT_DIR + 'ExchangeAPI'); - const CONTEXT = require(ROOT_DIR + 'Context'); - const DATASOURCE = require(ROOT_DIR + 'Datasource'); - const ASSISTANT = require(ROOT_DIR + 'Assistant'); const STATUS_REPORT = require(ROOT_DIR + 'Status Report'); /* We define the datetime for the process that we are running now. This will be the official processing time for both the infraestructure and the bot. */ global.processDatetime = new Date(); // This will be considered the process date and time, so as to have it consistenly all over the execution. - global.processDatetime = new Date(global.processDatetime.valueOf() - 30 * 24 * 60 * 60 * 1000); // we go 30 days back in time since candles are currently not up to date. /* We will prepare first the infraestructure needed for the bot to run. There are 3 modules we need to sucessfullly initialize first. */ - let context; - let datasource; - let exchangeAPI; - let assistant; + let statusReport; let userBot; let nextWaitTime; - initializeContext(); + initializeStatusReport(); - function initializeContext() { + function initializeStatusReport() { - if (FULL_LOG === true) { logger.write("[INFO] run -> loop -> initializeContext -> Entering function."); } + if (FULL_LOG === true) { logger.write("[INFO] run -> loop -> initializeStatusReport -> Entering function."); } - context = CONTEXT.newContext(bot, DEBUG_MODULE, AZURE_FILE_STORAGE, UTILITIES, STATUS_REPORT); - context.initialize(onInizialized); + statusReport = STATUS_REPORT.newContext(bot, DEBUG_MODULE, FILE_STORAGE, UTILITIES); + statusReport.initialize(onInizialized); function onInizialized(err) { switch (err.result) { case global.DEFAULT_OK_RESPONSE.result: { - logger.write("[INFO] run -> loop -> initializeContext -> onInizialized > Execution finished well. :-)"); - initializeDatasource(); - return; - } - break; - case global.DEFAULT_RETRY_RESPONSE.result: { // Something bad happened, but if we retry in a while it might go through the next time. - logger.write("[ERROR] run -> loop -> initializeContext -> onInizialized > Retry Later. Requesting Execution Retry."); - nextWaitTime = 'Retry'; - loopControl(nextWaitTime); - return; - } - break; - case global.DEFAULT_FAIL_RESPONSE.result: { // This is an unexpected exception that we do not know how to handle. - logger.write("[ERROR] run -> loop -> initializeContext -> onInizialized > Operation Failed. Aborting the process."); - callBackFunction(err); - return; - } - break; - } - } - } - - function initializeDatasource() { - - if (FULL_LOG === true) { logger.write("[INFO] run -> loop -> initializeDatasource -> Entering function."); } - - datasource = DATASOURCE.newDatasource(bot, DEBUG_MODULE, AZURE_FILE_STORAGE, UTILITIES); - datasource.initialize(onInizialized); - - function onInizialized(err) { - - switch (err.result) { - case global.DEFAULT_OK_RESPONSE.result: { - logger.write("[INFO] run -> loop -> initializeDatasource -> onInizialized > Execution finished well. :-)"); - initializeExchangeAPI(); - return; - } - break; - case global.DEFAULT_RETRY_RESPONSE.result: { // Something bad happened, but if we retry in a while it might go through the next time. - logger.write("[ERROR] run -> loop -> initializeDatasource -> onInizialized > Retry Later. Requesting Execution Retry."); - nextWaitTime = 'Retry'; - loopControl(nextWaitTime); - return; - } - break; - case global.DEFAULT_FAIL_RESPONSE.result: { // This is an unexpected exception that we do not know how to handle. - logger.write("[ERROR] run -> loop -> initializeDatasource -> onInizialized > Operation Failed. Aborting the process."); - callBackFunction(err); - return; - } - break; - } - } - } - - function initializeExchangeAPI() { - - if (FULL_LOG === true) { logger.write("[INFO] run -> loop -> initializeExchangeAPI -> Entering function."); } - - exchangeAPI = EXCHANGE_API.newExchangeAPI(bot, DEBUG_MODULE, POLONIEX_CLIENT_MODULE); - exchangeAPI.initialize(onInizialized); - - function onInizialized(err) { - - switch (err.result) { - case global.DEFAULT_OK_RESPONSE.result: { - logger.write("[INFO] run -> loop -> initializeExchangeAPI -> onInizialized > Execution finished well. :-)"); - initializeAssistant(); - return; - } - break; - case global.DEFAULT_RETRY_RESPONSE.result: { // Something bad happened, but if we retry in a while it might go through the next time. - logger.write("[ERROR] run -> loop -> initializeExchangeAPI -> onInizialized > Retry Later. Requesting Execution Retry."); - nextWaitTime = 'Retry'; - loopControl(nextWaitTime); - return; - } - break; - case global.DEFAULT_FAIL_RESPONSE.result: { // This is an unexpected exception that we do not know how to handle. - logger.write("[ERROR] run -> loop -> initializeExchangeAPI -> onInizialized > Operation Failed. Aborting the process."); - callBackFunction(err); - return; - } - break; - } - } - } - - function initializeAssistant() { - - if (FULL_LOG === true) { logger.write("[INFO] run -> loop -> initializeAssistant -> Entering function."); } - - assistant = ASSISTANT.newAssistant(bot, DEBUG_MODULE); - assistant.initialize(context, exchangeAPI, datasource, onInizialized); - - function onInizialized(err) { - - switch (err.result) { - case global.DEFAULT_OK_RESPONSE.result: { - logger.write("[INFO] run -> loop -> initializeAssistant -> onInizialized > Execution finished well. :-)"); + logger.write("[INFO] run -> loop -> initializeStatusReport -> onInizialized > Execution finished well. :-)"); initializeUserBot(); return; } break; case global.DEFAULT_RETRY_RESPONSE.result: { // Something bad happened, but if we retry in a while it might go through the next time. - logger.write("[ERROR] run -> loop -> initializeAssistant -> onInizialized > Retry Later. Requesting Execution Retry."); + logger.write("[ERROR] run -> loop -> initializeStatusReport -> onInizialized > Retry Later. Requesting Execution Retry."); nextWaitTime = 'Retry'; loopControl(nextWaitTime); return; } break; case global.DEFAULT_FAIL_RESPONSE.result: { // This is an unexpected exception that we do not know how to handle. - logger.write("[ERROR] run -> loop -> initializeAssistant -> onInizialized > Operation Failed. Aborting the process."); + logger.write("[ERROR] run -> loop -> initializeStatusReport -> onInizialized > Operation Failed. Aborting the process."); callBackFunction(err); return; } @@ -215,14 +107,9 @@ if (FULL_LOG === true) { logger.write("[INFO] run -> loop -> initializeUserBot -> Entering function."); } - usertBot = USER_BOT_MODULE.newUserBot(bot, DEBUG_MODULE); + usertBot = USER_BOT_MODULE.newUserBot(bot, UTILITIES, DEBUG_MODULE, FILE_STORAGE, STATUS_REPORT); - let platform = { - datasource: datasource, - assistant: assistant - }; - - usertBot.initialize(platform, onInizialized); + usertBot.initialize(undefined, undefined, onInizialized); function onInizialized(err) { @@ -261,7 +148,8 @@ switch (err.result) { case global.DEFAULT_OK_RESPONSE.result: { logger.write("[INFO] run -> loop -> startUserBot -> onFinished > Execution finished well. :-)"); - saveContext(); + nextWaitTime = 'Normal'; + loopControl(nextWaitTime); return; } break; @@ -282,38 +170,6 @@ } } - function saveContext() { - - if (FULL_LOG === true) { logger.write("[INFO] run -> loop -> saveContext -> Entering function."); } - - context.saveThemAll(onFinished); - - function onFinished(err) { - - switch (err.result) { - case global.DEFAULT_OK_RESPONSE.result: { - logger.write("[INFO] run -> loop -> saveContext -> onFinished > Execution finished well. :-)"); - nextWaitTime = 'Normal'; - loopControl(nextWaitTime); - return; - } - break; - case global.DEFAULT_RETRY_RESPONSE.result: { // Something bad happened, but if we retry in a while it might go through the next time. - logger.write("[ERROR] run -> loop -> saveContext -> onFinished > Can not retry at this point."); - callBackFunction(global.DEFAULT_FAIL_RESPONSE); - return; - } - break; - case global.DEFAULT_FAIL_RESPONSE.result: { // This is an unexpected exception that we do not know how to handle. - logger.write("[ERROR] run -> loop -> saveContext -> onFinished > Operation Failed. Aborting the process."); - callBackFunction(err); - return; - } - break; - } - } - } - } catch (err) { logger.write("[ERROR] run -> loop -> err = " + err.message); callBackFunction(err); diff --git a/Run.js b/Run.js index 4d6768d76..b4c6bc5bf 100644 --- a/Run.js +++ b/Run.js @@ -200,23 +200,19 @@ for (let i = 0; i < botConfig.processes.length; i++) { startProcess(); function startProcess() { - - if (bot.type === "Trading") { - runTradingBot(processConfig); - return; - } - - const newIntervalExecutor = INTERVAL_EXECUTOR_MODULE.newIntervalExecutor(bot); - - newIntervalExecutor.initialize(global.PLATFORM_CONFIG.bot.path, processConfig, undefined, undefined, onInitializeReady); - - function onInitializeReady() { - newIntervalExecutor.start(); + switch (bot.type) { + case 'Trading': { + runTradingBot(processConfig); + return; + } + case 'Indicator': { + runIndicatorBot(processConfig); + return; + } } } } - } catch (err) { console.log(err.message); logger.write(err.message);