From bcc5a74c4520d422ee88d8032747eb5356d08bb1 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Thu, 7 Jun 2018 01:33:59 +0200 Subject: [PATCH] Better logging --- Trading-Process/User.Bot.js | 48 ++++++++++++++++++------------------- this.bot.config.json | 4 ++-- 2 files changed, 25 insertions(+), 27 deletions(-) diff --git a/Trading-Process/User.Bot.js b/Trading-Process/User.Bot.js index d5011bf72..232027916 100644 --- a/Trading-Process/User.Bot.js +++ b/Trading-Process/User.Bot.js @@ -1,9 +1,8 @@ exports.newUserBot = function newUserBot(bot, logger) { - const FULL_LOG = true; - const MODULE_NAME = 'User Bot'; - const LOG_INFO = true; + const FULL_LOG = true; + const ERROR_LOG = true; let thisObject = { initialize: initialize, @@ -19,19 +18,17 @@ try { - if (LOG_INFO === true) { logger.write('[INFO] initialize -> Entering function.'); } + if (FULL_LOG === true) { logger.write( MODULE_NAME, '[INFO] initialize -> Entering function.'); } logger.fileName = MODULE_NAME; /* Store local values. */ assistant = pAssistant; - logger.write('[INFO] initialize -> Entering function initialize '); - callBackFunction(global.DEFAULT_OK_RESPONSE); } catch (err) { - logger.write('[ERROR] initialize -> onDone -> err = ' + err.message); + if (ERROR_LOG === true) { logger.write(MODULE_NAME, '[ERROR] initialize -> onDone -> err = ' + err.message); } callBackFunction(global.DEFAULT_FAIL_RESPONSE); } } @@ -40,7 +37,7 @@ try { - if (LOG_INFO === true) { logger.write('[INFO] start -> Entering function.'); } + if (FULL_LOG === true) { logger.write( MODULE_NAME, '[INFO] start -> Entering function.'); } /* @@ -63,19 +60,20 @@ switch (err.result) { case global.DEFAULT_OK_RESPONSE.result: { - logger.write('[INFO] start -> onDone -> Execution finished well. :-)'); + if (FULL_LOG === true) { logger.write(MODULE_NAME, '[INFO] start -> onDone -> Execution finished well.'); } + callBackFunction(global.DEFAULT_OK_RESPONSE); 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] start -> onDone -> Retry Later. Requesting Execution Retry.'); + if (ERROR_LOG === true) { logger.write(MODULE_NAME, '[ERROR] start -> onDone -> Retry Later. Requesting Execution Retry.'); } callBackFunction(global.DEFAULT_RETRY_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] start -> onDone -> Operation Failed. Aborting the process.'); + if (ERROR_LOG === true) { logger.write(MODULE_NAME, '[ERROR] start -> onDone -> Operation Failed. Aborting the process.'); } callBackFunction(global.DEFAULT_FAIL_RESPONSE); return; } @@ -83,7 +81,7 @@ } } catch (err) { - logger.write('[ERROR] start -> onDone -> err = ' + err.message); + if (ERROR_LOG === true) { logger.write(MODULE_NAME, '[ERROR] start -> onDone -> err = ' + err.message); } callBackFunction(global.DEFAULT_FAIL_RESPONSE); } } @@ -92,7 +90,7 @@ try { - if (LOG_INFO === true) { logger.write('[INFO] start -> decideWhatToDo -> Entering function.'); } + if (FULL_LOG === true) { logger.write( MODULE_NAME, '[INFO] start -> decideWhatToDo -> Entering function.'); } let balance = assistant.getAvailableBalance(); @@ -107,7 +105,7 @@ if (balanceA === 0 && balanceB === 0) { - if (LOG_INFO === true) { logger.write('[INFO] start -> decideWhatToDo -> Cannot place orders since Available Balance is zero on both Assets.'); } + if (FULL_LOG === true) { logger.write( MODULE_NAME, '[INFO] start -> decideWhatToDo -> Cannot place orders since Available Balance is zero on both Assets.'); } callBack(global.DEFAULT_OK_RESPONSE); return; @@ -152,7 +150,7 @@ } - if (LOG_INFO === true) { logger.write('[INFO] start -> decideWhatToDo -> In some situations it is just fin no to place orders. Passing this turn. '); } + if (FULL_LOG === true) { logger.write( MODULE_NAME, '[INFO] start -> decideWhatToDo -> In some situations it is just fin no to place orders. Passing this turn. '); } callBack(global.DEFAULT_OK_RESPONSE); return; } @@ -165,10 +163,10 @@ amountB = amountA / rate; amountB = Number(amountB.toFixed(8)); - if (LOG_INFO === true) { logger.write('[INFO] start -> decideWhatToDo -> Decided to BUY.'); } - if (LOG_INFO === true) { logger.write('[INFO] start -> decideWhatToDo -> amountA = ' + amountA); } - if (LOG_INFO === true) { logger.write('[INFO] start -> decideWhatToDo -> amountB = ' + amountB); } - if (LOG_INFO === true) { logger.write('[INFO] start -> decideWhatToDo -> rate = ' + rate); } + if (FULL_LOG === true) { logger.write( MODULE_NAME, '[INFO] start -> decideWhatToDo -> Decided to BUY.'); } + if (FULL_LOG === true) { logger.write( MODULE_NAME, '[INFO] start -> decideWhatToDo -> amountA = ' + amountA); } + if (FULL_LOG === true) { logger.write( MODULE_NAME, '[INFO] start -> decideWhatToDo -> amountB = ' + amountB); } + if (FULL_LOG === true) { logger.write( MODULE_NAME, '[INFO] start -> decideWhatToDo -> rate = ' + rate); } assistant.putPosition('buy', rate, amountA, amountB, callBack); @@ -183,10 +181,10 @@ amountA = amountB * rate; amountA = Number(amountA.toFixed(8)); - if (LOG_INFO === true) { logger.write('[INFO] start -> decideWhatToDo -> Decided to SELL.'); } - if (LOG_INFO === true) { logger.write('[INFO] start -> decideWhatToDo -> amountA = ' + amountA); } - if (LOG_INFO === true) { logger.write('[INFO] start -> decideWhatToDo -> amountB = ' + amountB); } - if (LOG_INFO === true) { logger.write('[INFO] start -> decideWhatToDo -> rate = ' + rate); } + if (FULL_LOG === true) { logger.write( MODULE_NAME, '[INFO] start -> decideWhatToDo -> Decided to SELL.'); } + if (FULL_LOG === true) { logger.write( MODULE_NAME, '[INFO] start -> decideWhatToDo -> amountA = ' + amountA); } + if (FULL_LOG === true) { logger.write( MODULE_NAME, '[INFO] start -> decideWhatToDo -> amountB = ' + amountB); } + if (FULL_LOG === true) { logger.write( MODULE_NAME, '[INFO] start -> decideWhatToDo -> rate = ' + rate); } assistant.putPosition('sell', rate, amountA, amountB, callBack); @@ -194,13 +192,13 @@ } } catch (err) { - logger.write('[ERROR] start -> decideWhatToDo -> err = ' + err.message); + if (ERROR_LOG === true) { logger.write(MODULE_NAME, '[ERROR] start -> decideWhatToDo -> err = ' + err.message); } callBack(global.DEFAULT_FAIL_RESPONSE); } } } catch (err) { - logger.write('[ERROR] start -> err = ' + err.message); + if (ERROR_LOG === true) { logger.write(MODULE_NAME, '[ERROR] start -> err = ' + err.message); } callBackFunction(global.DEFAULT_FAIL_RESPONSE); } } diff --git a/this.bot.config.json b/this.bot.config.json index 2d82d9127..921822011 100644 --- a/this.bot.config.json +++ b/this.bot.config.json @@ -21,8 +21,8 @@ }, "backtest": { "run": "true", - "beginDatetime": "2018-04-21T16:00:00.000Z", - "endDatetime": "2018-04-21T17:00:00.000Z", + "beginDatetime": "2018-04-21T18:00:00.000Z", + "endDatetime": "2018-04-21T18:15:00.000Z", "waitTime": 1000 }, "competition": {