From 89d76e9401be6225c0d0df016e518e248db2f12e Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Wed, 6 Jun 2018 16:28:10 +0200 Subject: [PATCH] Logging functionality re-written, all modules affected --- Poloniex-Historic-Trades/User.Bot.js | 67 ++++---- Poloniex-Hole-Fixing/User.bot.js | 232 +++++++++++++-------------- Poloniex-Live-Trades/User.bot.js | 78 +++++---- this.bot.config.json | 4 +- 4 files changed, 182 insertions(+), 199 deletions(-) diff --git a/Poloniex-Historic-Trades/User.Bot.js b/Poloniex-Historic-Trades/User.Bot.js index d6e45549c..2b74f473a 100644 --- a/Poloniex-Historic-Trades/User.Bot.js +++ b/Poloniex-Historic-Trades/User.Bot.js @@ -1,6 +1,5 @@ -exports.newInterval = function newInterval(BOT, UTILITIES, FILE_STORAGE, DEBUG_MODULE, MARKETS_MODULE, POLONIEX_CLIENT_MODULE) { +exports.newInterval = function newInterval(bot, logger, UTILITIES, FILE_STORAGE, MARKETS_MODULE, POLONIEX_CLIENT_MODULE) { - let bot = BOT; const ROOT_DIR = './'; const GMT_SECONDS = ':00.000 GMT+0000'; const GMT_MILI_SECONDS = '.000 GMT+0000'; @@ -16,10 +15,6 @@ const GO_RANDOM = false; const FORCE_MARKET = 2; // This allows to debug the execution of an specific market. Not intended for production. - const logger = DEBUG_MODULE.newDebugLog(); - logger.fileName = MODULE_NAME; - logger.bot = bot; - interval = { initialize: initialize, start: start @@ -27,9 +22,9 @@ let markets; - let charlyStorage = FILE_STORAGE.newFileStorage(bot); + let charlyStorage = FILE_STORAGE.newFileStorage(bot, logger); - let utilities = UTILITIES.newCloudUtilities(bot); + let utilities = UTILITIES.newCloudUtilities(bot, logger); let year; let month; @@ -53,7 +48,7 @@ charlyStorage.initialize(bot.devTeam); - markets = MARKETS_MODULE.newMarkets(bot); + markets = MARKETS_MODULE.newMarkets(bot.logger); markets.initialize(callBackFunction); @@ -83,7 +78,7 @@ This process complements the Live Trades process and write historical trades fil try { if (LOG_INFO === true) { - logger.write("[INFO] Entering function 'start', with year = " + year + " and month = " + month); + logger.write(MODULE_NAME, "[INFO] Entering function 'start', with year = " + year + " and month = " + month); } let processDate = new Date(year + "-" + month + "-1 00:00:00.000 GMT+0000"); @@ -95,7 +90,7 @@ This process complements the Live Trades process and write historical trades fil if ((year === thisDatetime.getUTCFullYear() && month > thisDatetime.getUTCMonth() + 1) || year > thisDatetime.getUTCFullYear()) { - logger.write("[INFO] We are too far in the future. Interval will not execute. Sorry."); + logger.write(MODULE_NAME, "[INFO] We are too far in the future. Interval will not execute. Sorry."); return; } @@ -136,7 +131,7 @@ This process complements the Live Trades process and write historical trades fil try { if (LOG_INFO === true) { - logger.write("[INFO] Entering function 'marketsLoop'"); + logger.write(MODULE_NAME, "[INFO] Entering function 'marketsLoop'"); } currentDate = new Date(); @@ -163,14 +158,14 @@ This process complements the Live Trades process and write historical trades fil try { if (LOG_INFO === true) { - logger.write("[INFO] Entering function 'openMarket'"); + logger.write(MODULE_NAME, "[INFO] Entering function 'openMarket'"); } if (marketQueue.length === 0) { if (LOG_INFO === true) { - logger.write("[INFO] 'openMarket' - marketQueue.length === 0"); + logger.write(MODULE_NAME, "[INFO] 'openMarket' - marketQueue.length === 0"); } const logText = "[WARN] We processed all the markets."; @@ -208,8 +203,8 @@ This process complements the Live Trades process and write historical trades fil } if (LOG_INFO === true) { - logger.write("[INFO] 'openMarket' - marketQueue.length = " + marketQueue.length); - logger.write("[INFO] 'openMarket' - market sucessfully opened : " + market.assetA + "_" + market.assetB); + logger.write(MODULE_NAME, "[INFO] 'openMarket' - marketQueue.length = " + marketQueue.length); + logger.write(MODULE_NAME, "[INFO] 'openMarket' - market sucessfully opened : " + market.assetA + "_" + market.assetB); } if (market.status === markets.ENABLED) { @@ -218,7 +213,7 @@ This process complements the Live Trades process and write historical trades fil } else { - logger.write("[INFO] 'openMarket' - market " + market.assetA + "_" + market.assetB + " skipped because its status is not valid. Status = " + market.status); + logger.write(MODULE_NAME, "[INFO] 'openMarket' - market " + market.assetA + "_" + market.assetB + " skipped because its status is not valid. Status = " + market.status); closeAndOpenMarket(); return; @@ -236,7 +231,7 @@ This process complements the Live Trades process and write historical trades fil function closeMarket() { if (LOG_INFO === true) { - logger.write("[INFO] Entering function 'closeMarket'"); + logger.write(MODULE_NAME, "[INFO] Entering function 'closeMarket'"); } } @@ -244,7 +239,7 @@ This process complements the Live Trades process and write historical trades fil function closeAndOpenMarket() { if (LOG_INFO === true) { - logger.write("[INFO] Entering function 'closeAndOpenMarket'"); + logger.write(MODULE_NAME, "[INFO] Entering function 'closeAndOpenMarket'"); } openMarket(); @@ -271,7 +266,7 @@ This process complements the Live Trades process and write historical trades fil try { if (LOG_INFO === true) { - logger.write("[INFO] Entering function 'getMarketStatusReport'"); + logger.write(MODULE_NAME, "[INFO] Entering function 'getMarketStatusReport'"); } let reportFilePath = EXCHANGE_NAME + "/Processes/" + bot.process; @@ -327,7 +322,7 @@ This process complements the Live Trades process and write historical trades fil try { if (LOG_INFO === true) { - logger.write("[INFO] Entering function 'getMarketStatusReport'"); + logger.write(MODULE_NAME, "[INFO] Entering function 'getMarketStatusReport'"); } let reportFilePath = EXCHANGE_NAME + "/Processes/" + bot.process + "/" + year + "/" + month; @@ -389,7 +384,7 @@ This process complements the Live Trades process and write historical trades fil try { if (LOG_INFO === true) { - logger.write("[INFO] Entering function 'getTheTrades'"); + logger.write(MODULE_NAME, "[INFO] Entering function 'getTheTrades'"); } const firstTradeDate = parseInt(currentDate.valueOf() / 1000); @@ -437,7 +432,7 @@ This process complements the Live Trades process and write historical trades fil let exchangeResponseTime = new Date(); let timeDifference = (exchangeResponseTime.valueOf() - exchangeCallTime.valueOf()) / 1000; - logger.write("[INFO] Entering function 'onExchangeCallReturned' - Call time recorded = " + timeDifference + " seconds."); + logger.write(MODULE_NAME, "[INFO] Entering function 'onExchangeCallReturned' - Call time recorded = " + timeDifference + " seconds."); } if (err || tradesRequested.error !== undefined) { @@ -485,7 +480,7 @@ This process complements the Live Trades process and write historical trades fil function onMarketDeactivated() { - logger.write("[INFO] Market " + market.assetA + "_" + market.assetB + " deactivated. Id = " + market.id); + logger.write(MODULE_NAME, "[INFO] Market " + market.assetA + "_" + market.assetB + " deactivated. Id = " + market.id); closeAndOpenMarket(); return; @@ -529,7 +524,7 @@ This process complements the Live Trades process and write historical trades fil try { if (LOG_INFO === true) { - logger.write("[INFO] Entering function 'tradesReadyToBeSaved'"); + logger.write(MODULE_NAME, "[INFO] Entering function 'tradesReadyToBeSaved'"); } moreIntervalCallsNeeded = true; // If we are requesting trades from the exchange, that means that something is being done. @@ -706,7 +701,7 @@ This process complements the Live Trades process and write historical trades fil */ if (LOG_INFO === true) { - logger.write("[INFO] About to save " + (filesToSave.length + 1) + " files. "); + logger.write(MODULE_NAME, "[INFO] About to save " + (filesToSave.length + 1) + " files. "); } let i = 0; @@ -775,7 +770,7 @@ This process complements the Live Trades process and write historical trades fil } else { if (LOG_INFO === true) { - logger.write("[INFO] Leaving function 'tradesReadyToBeSaved'"); + logger.write(MODULE_NAME, "[INFO] Leaving function 'tradesReadyToBeSaved'"); } let monthCompleteHistory = false; @@ -843,7 +838,7 @@ This process complements the Live Trades process and write historical trades fil try { if (LOG_INFO === true) { - logger.write("[INFO] Entering function 'writeStatusReport'"); + logger.write(MODULE_NAME, "[INFO] Entering function 'writeStatusReport'"); } let reportFilePath = EXCHANGE_NAME + "/Processes/" + bot.process + "/" + year + "/" + month; @@ -872,7 +867,7 @@ This process complements the Live Trades process and write historical trades fil function onFileCreated() { if (LOG_INFO === true) { - logger.write("[INFO] 'writeStatusReport' - Content written: " + fileContent); + logger.write(MODULE_NAME, "[INFO] 'writeStatusReport' - Content written: " + fileContent); } if (isBeginingOfMarket === true) { @@ -903,7 +898,7 @@ This process complements the Live Trades process and write historical trades fil function onMasterFileCreated() { if (LOG_INFO === true) { - logger.write("[INFO] 'writeStatusReport' - Begining of market reached !!! - Content written: " + fileContent); + logger.write(MODULE_NAME, "[INFO] 'writeStatusReport' - Begining of market reached !!! - Content written: " + fileContent); } verifyMarketComplete(isMonthComplete, callBack); @@ -937,7 +932,7 @@ This process complements the Live Trades process and write historical trades fil if (isMonthComplete === true) { - logger.write("[INFO] 'writeStatusReport' - verifyMarketComplete - Month Completed !!! "); + logger.write(MODULE_NAME, "[INFO] 'writeStatusReport' - verifyMarketComplete - Month Completed !!! "); /* @@ -973,7 +968,7 @@ This process complements the Live Trades process and write historical trades fil /* The first month of the market didnt create this file yet. Aborting verification. */ - logger.write("[INFO] 'writeStatusReport' - verifyMarketComplete - Verification ABORTED since the main status report did not exist. "); + logger.write(MODULE_NAME, "[INFO] 'writeStatusReport' - verifyMarketComplete - Verification ABORTED since the main status report did not exist. "); callBack(); @@ -1009,7 +1004,7 @@ This process complements the Live Trades process and write historical trades fil /* If any of the files do not exist, it is enough to know the market is not complete. */ - logger.write("[INFO] 'writeStatusReport' - verifyMarketComplete - Verification ABORTED since the status report for year " + initialYear + " and month " + initialMonth + " did not exist. "); + logger.write(MODULE_NAME, "[INFO] 'writeStatusReport' - verifyMarketComplete - Verification ABORTED since the status report for year " + initialYear + " and month " + initialMonth + " did not exist. "); callBack(); @@ -1025,7 +1020,7 @@ This process complements the Live Trades process and write historical trades fil /* If any of the files says that month is not complete then it is enough to know the market is not complete. */ - logger.write("[INFO] 'writeStatusReport' - verifyMarketComplete - Verification ABORTED since the status report for year " + initialYear + " and month " + initialMonth + " did not have a complete history. "); + logger.write(MODULE_NAME, "[INFO] 'writeStatusReport' - verifyMarketComplete - Verification ABORTED since the status report for year " + initialYear + " and month " + initialMonth + " did not have a complete history. "); callBack(); @@ -1081,7 +1076,7 @@ This process complements the Live Trades process and write historical trades fil function onMasterFileCreated() { - logger.write("[INFO] 'writeStatusReport' - verifyMarketComplete - Verification SUCESSFULL . Market Completed !!! - Content written: " + fileContent); + logger.write(MODULE_NAME, "[INFO] 'writeStatusReport' - verifyMarketComplete - Verification SUCESSFULL . Market Completed !!! - Content written: " + fileContent); callBack(); @@ -1091,7 +1086,7 @@ This process complements the Live Trades process and write historical trades fil } else { - logger.write("[INFO] 'writeStatusReport' - verifyMarketComplete - Verification ABORTED: Month is not complete. "); + logger.write(MODULE_NAME, "[INFO] 'writeStatusReport' - verifyMarketComplete - Verification ABORTED: Month is not complete. "); callBack(); } diff --git a/Poloniex-Hole-Fixing/User.bot.js b/Poloniex-Hole-Fixing/User.bot.js index 7cc90cd4e..e4fa528e0 100644 --- a/Poloniex-Hole-Fixing/User.bot.js +++ b/Poloniex-Hole-Fixing/User.bot.js @@ -1,34 +1,28 @@ -exports.newUserBot = function newUserBot(BOT, COMMONS, UTILITIES, DEBUG_MODULE, BLOB_STORAGE, STATUS_REPORT, POLONIEX_CLIENT_MODULE) { +exports.newUserBot = function newUserBot(bot, logger, COMMONS, UTILITIES, BLOB_STORAGE, STATUS_REPORT, POLONIEX_CLIENT_MODULE) { const FULL_LOG = true; const LOG_FILE_CONTENT = false; - let bot = BOT; - const GMT_SECONDS = ':00.000 GMT+0000'; const GMT_MILI_SECONDS = '.000 GMT+0000'; - const MODULE_NAME = "UserBot"; + const MODULE_NAME = "User Bot"; const EXCHANGE_NAME = "Poloniex"; const TRADES_FOLDER_NAME = "Trades"; - const logger = DEBUG_MODULE.newDebugLog(); - logger.fileName = MODULE_NAME; - logger.bot = bot; - thisObject = { initialize: initialize, start: start }; - let charlyStorage = BLOB_STORAGE.newBlobStorage(bot); + let charlyStorage = BLOB_STORAGE.newBlobStorage(bot, logger); - let utilities = UTILITIES.newCloudUtilities(bot); + let utilities = UTILITIES.newCloudUtilities(bot, logger); let poloniexApiClient = POLONIEX_CLIENT_MODULE.newPoloniexAPIClient(global.EXCHANGE_KEYS[global.EXCHANGE_NAME].Key, global.EXCHANGE_KEYS[global.EXCHANGE_NAME].Secret); - let statusReportModule = STATUS_REPORT.newStatusReport(BOT, DEBUG_MODULE, BLOB_STORAGE, UTILITIES); + let statusReportModule = STATUS_REPORT.newStatusReport(bot, logger, BLOB_STORAGE, UTILITIES); let year; let month; @@ -49,9 +43,9 @@ logger.fileName = MODULE_NAME + "-" + year + "-" + month; logger.initialize(); - if (FULL_LOG === true) { logger.write("[INFO] initialize -> Entering function."); } - if (FULL_LOG === true) { logger.write("[INFO] initialize -> pYear = " + year); } - if (FULL_LOG === true) { logger.write("[INFO] initialize -> pMonth = " + month); } + if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] initialize -> Entering function."); } + if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] initialize -> pYear = " + year); } + if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] initialize -> pMonth = " + month); } /* The very first validation is about if we are not too far in the future. In those cases we will not proceed and expect this instance to be restarted later. */ @@ -60,25 +54,25 @@ let tomorrow = new Date(today.valueOf() + 1000 * 60 * 60 * 24); if (processDate.valueOf() > tomorrow.valueOf()) { // This means that it should start more than a day from current time. - logger.write("[WARN] initialize -> Too far in the future."); + logger.write(MODULE_NAME, "[WARN] initialize -> Too far in the future."); let customOK = { result: global.CUSTOM_OK_RESPONSE.result, message: "Too far in the future." } - logger.write("[WARN] initialize -> customOK = " + customOK.message); + logger.write(MODULE_NAME, "[WARN] initialize -> customOK = " + customOK.message); callBackFunction(customOK); return; } if (processDate.valueOf() > today.valueOf()) { // This means that is should start in less than a day from current time. - logger.write("[WARN] initialize -> Too far in the future."); + logger.write(MODULE_NAME, "[WARN] initialize -> Too far in the future."); let customOK = { result: global.CUSTOM_OK_RESPONSE.result, message: "Not needed now, but soon." } - logger.write("[WARN] initialize -> customOK = " + customOK.message); + logger.write(MODULE_NAME, "[WARN] initialize -> customOK = " + customOK.message); callBackFunction(customOK); return; } @@ -89,17 +83,17 @@ if (err.result === global.DEFAULT_OK_RESPONSE.result) { - if (FULL_LOG === true) { logger.write("[INFO] initialize -> onCharlyInizialized -> Initialization Succeed."); } + if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] initialize -> onCharlyInizialized -> Initialization Succeed."); } callBackFunction(global.DEFAULT_OK_RESPONSE); } else { - logger.write("[ERROR] initialize -> onCharlyInizialized -> err = " + err.message); + logger.write(MODULE_NAME, "[ERROR] initialize -> onCharlyInizialized -> err = " + err.message); callBackFunction(err); } } } catch (err) { - logger.write("[ERROR] initialize -> err = " + err.message); + logger.write(MODULE_NAME, "[ERROR] initialize -> err = " + err.message); callBackFunction(global.DEFAULT_FAIL_RESPONSE); } } @@ -146,7 +140,7 @@ What is the lastFile pointer? try { - if (FULL_LOG === true) { logger.write("[INFO] start -> Entering function."); } + if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> Entering function."); } let processDate = new Date(year + "-" + month + "-1 00:00:00.000 GMT+0000"); let lastMinuteOfMonth = new Date(year + "-" + month + "-1 00:00:00.000 GMT+0000"); @@ -198,16 +192,16 @@ What is the lastFile pointer? try { - if (FULL_LOG === true) { logger.write("[INFO] start -> getContextVariables -> Entering function."); } + if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> getContextVariables -> Entering function."); } let thisReport; let reportKey; reportKey = "AAMasters" + "-" + "AACharly" + "-" + "Poloniex-Live-Trades" + "-" + "dataSet.V1"; - if (FULL_LOG === true) { logger.write("[INFO] start -> getContextVariables -> reportKey = " + reportKey); } + if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> getContextVariables -> reportKey = " + reportKey); } if (statusDependencies.statusReports.get(reportKey).status === "Status Report is corrupt.") { - logger.write("[ERROR] start -> getContextVariables -> Can not continue because dependecy Status Report is corrupt. "); + logger.write(MODULE_NAME, "[ERROR] start -> getContextVariables -> Can not continue because dependecy Status Report is corrupt. "); callBackFunction(global.DEFAULT_RETRY_RESPONSE); return; } @@ -215,13 +209,13 @@ What is the lastFile pointer? thisReport = statusDependencies.statusReports.get(reportKey).file; if (thisReport.lastFile === undefined) { - logger.write("[WARN] start -> getContextVariables -> Undefined Last File. -> reportKey = " + reportKey); + logger.write(MODULE_NAME, "[WARN] start -> getContextVariables -> Undefined Last File. -> reportKey = " + reportKey); let customOK = { result: global.CUSTOM_OK_RESPONSE.result, message: "Dependency does not exist." } - logger.write("[WARN] start -> getContextVariables -> customOK = " + customOK.message); + logger.write(MODULE_NAME, "[WARN] start -> getContextVariables -> customOK = " + customOK.message); callBackFunction(customOK); return; } @@ -229,10 +223,10 @@ What is the lastFile pointer? lastLiveTradeFile = new Date(thisReport.lastFile.year + "-" + thisReport.lastFile.month + "-" + thisReport.lastFile.days + " " + thisReport.lastFile.hours + ":" + thisReport.lastFile.minutes + GMT_SECONDS); reportKey = "AAMasters" + "-" + "AACharly" + "-" + "Poloniex-Historic-Trades" + "-" + "dataSet.V1"; - if (FULL_LOG === true) { logger.write("[INFO] start -> getContextVariables -> reportKey = " + reportKey); } + if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> getContextVariables -> reportKey = " + reportKey); } if (statusDependencies.statusReports.get(reportKey).status === "Status Report is corrupt.") { - logger.write("[ERROR] start -> getContextVariables -> Can not continue because dependecy Status Report is corrupt. "); + logger.write(MODULE_NAME, "[ERROR] start -> getContextVariables -> Can not continue because dependecy Status Report is corrupt. "); callBackFunction(global.DEFAULT_RETRY_RESPONSE); return; } @@ -240,14 +234,14 @@ What is the lastFile pointer? thisReport = statusDependencies.statusReports.get(reportKey).file; if (thisReport.lastFile === undefined) { - logger.write("[WARN] start -> getContextVariables -> Undefined Last File. -> reportKey = " + reportKey); - logger.write("[HINT] start -> getContextVariables -> It is too early too run this process since the trade history of the market is not there yet."); + logger.write(MODULE_NAME, "[WARN] start -> getContextVariables -> Undefined Last File. -> reportKey = " + reportKey); + logger.write(MODULE_NAME, "[HINT] start -> getContextVariables -> It is too early too run this process since the trade history of the market is not there yet."); let customOK = { result: global.CUSTOM_OK_RESPONSE.result, message: "Dependency does not exist." } - logger.write("[WARN] start -> getContextVariables -> customOK = " + customOK.message); + logger.write(MODULE_NAME, "[WARN] start -> getContextVariables -> customOK = " + customOK.message); callBackFunction(customOK); return; } @@ -263,33 +257,33 @@ What is the lastFile pointer? || (processDate.getUTCFullYear() === lastHistoricTradeFile.getUTCFullYear() && processDate.getUTCMonth() < lastHistoricTradeFile.getUTCMonth()) ) { - logger.write("[WARN] start -> getContextVariables -> The current year / month is before the start of the market history for market."); + logger.write(MODULE_NAME, "[WARN] start -> getContextVariables -> The current year / month is before the start of the market history for market."); let customOK = { result: global.CUSTOM_OK_RESPONSE.result, message: "Month before it is needed." } - logger.write("[WARN] start -> getContextVariables -> customOK = " + customOK.message); + logger.write(MODULE_NAME, "[WARN] start -> getContextVariables -> customOK = " + customOK.message); callBackFunction(customOK); return; } } else { - logger.write("[WARN] start -> getContextVariables -> Trade History is not complete."); + logger.write(MODULE_NAME, "[WARN] start -> getContextVariables -> Trade History is not complete."); let customOK = { result: global.CUSTOM_OK_RESPONSE.result, message: "Dependency not ready." } - logger.write("[WARN] start -> getContextVariables -> customOK = " + customOK.message); + logger.write(MODULE_NAME, "[WARN] start -> getContextVariables -> customOK = " + customOK.message); callBackFunction(customOK); return; } reportKey = "AAMasters" + "-" + "AACharly" + "-" + "Poloniex-Hole-Fixing" + "-" + "dataSet.V1" + "-" + year + "-" + month; - if (FULL_LOG === true) { logger.write("[INFO] start -> getContextVariables -> reportKey = " + reportKey); } + if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> getContextVariables -> reportKey = " + reportKey); } if (statusDependencies.statusReports.get(reportKey).status === "Status Report is corrupt.") { - logger.write("[ERROR] start -> getContextVariables -> Can not continue because self dependecy Status Report is corrupt. Aborting Process."); + logger.write(MODULE_NAME, "[ERROR] start -> getContextVariables -> Can not continue because self dependecy Status Report is corrupt. Aborting Process."); callBackFunction(global.DEFAULT_FAIL_RESPONSE); return; } @@ -332,13 +326,13 @@ What is the lastFile pointer? if (holeFixingStatusReport.monthChecked === true) { - logger.write("[WARN] start -> getContextVariables -> The current year / month was already fully checked for market."); + logger.write(MODULE_NAME, "[WARN] start -> getContextVariables -> The current year / month was already fully checked for market."); let customOK = { result: global.CUSTOM_OK_RESPONSE.result, message: "Month fully processed." } - logger.write("[WARN] start -> getContextVariables -> customOK = " + customOK.message); + logger.write(MODULE_NAME, "[WARN] start -> getContextVariables -> customOK = " + customOK.message); callBackFunction(customOK); return; @@ -355,10 +349,10 @@ What is the lastFile pointer? } } } catch (err) { - logger.write("[ERROR] start -> getContextVariables -> err = " + err.message); + logger.write(MODULE_NAME, "[ERROR] start -> getContextVariables -> err = " + err.message); if (err.message === "Cannot read property 'file' of undefined") { - logger.write("[HINT] start -> getContextVariables -> Check the bot configuration to see if all of its statusDependencies declarations are correct. "); - logger.write("[HINT] start -> getContextVariables -> Dependencies loaded -> keys = " + JSON.stringify(statusDependencies.keys)); + logger.write(MODULE_NAME, "[HINT] start -> getContextVariables -> Check the bot configuration to see if all of its statusDependencies declarations are correct. "); + logger.write(MODULE_NAME, "[HINT] start -> getContextVariables -> Dependencies loaded -> keys = " + JSON.stringify(statusDependencies.keys)); } callBackFunction(global.DEFAULT_FAIL_RESPONSE); } @@ -368,7 +362,7 @@ What is the lastFile pointer? try { - if (FULL_LOG === true) { logger.write("[INFO] start -> findNextHole -> Entering function."); } + if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> findNextHole -> Entering function."); } /* @@ -393,25 +387,25 @@ What is the lastFile pointer? date = new Date(date.valueOf() + 60 * 1000); - if (FULL_LOG === true) { logger.write("[INFO] start -> findNextHole -> readNextFile -> Entering function."); } - if (FULL_LOG === true) { logger.write("[INFO] start -> findNextHole -> readNextFile -> date = " + date.toUTCString()); } + if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> findNextHole -> readNextFile -> Entering function."); } + if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> findNextHole -> readNextFile -> date = " + date.toUTCString()); } if (date.valueOf() > lastLiveTradeFile.valueOf()) { /* This mean we reached the forward end of the market */ - if (FULL_LOG === true) { logger.write("[INFO] start -> findNextHole -> readNextFile -> Head of the market reached at date = " + date.toUTCString()); } - if (FULL_LOG === true) { logger.write("[INFO] start -> findNextHole -> readNextFile -> lastLiveTradeFile = " + lastLiveTradeFile.toUTCString()); } + if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> findNextHole -> readNextFile -> Head of the market reached at date = " + date.toUTCString()); } + if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> findNextHole -> readNextFile -> lastLiveTradeFile = " + lastLiveTradeFile.toUTCString()); } writeStatusReport(currentDatetime, currentTradeId, false, true, onStatusReportWritten); function onStatusReportWritten(err) { try { - if (FULL_LOG === true) { logger.write("[INFO] start -> findNextHole -> readNextFile -> onStatusReportWritten -> Entering function."); } + if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> findNextHole -> readNextFile -> onStatusReportWritten -> Entering function."); } if (err.result !== global.DEFAULT_OK_RESPONSE.result) { - logger.write("[ERROR] start -> findNextHole -> readNextFile -> onStatusReportWritten -> err = " + err.message); + logger.write(MODULE_NAME, "[ERROR] start -> findNextHole -> readNextFile -> onStatusReportWritten -> err = " + err.message); callBackFunction(err); return; } @@ -419,7 +413,7 @@ What is the lastFile pointer? callBackFunction(global.DEFAULT_OK_RESPONSE); return; } catch (err) { - logger.write("[ERROR] start -> findNextHole -> readNextFile -> onStatusReportWritten -> err = " + err.message); + logger.write(MODULE_NAME, "[ERROR] start -> findNextHole -> readNextFile -> onStatusReportWritten -> err = " + err.message); callBackFunction(global.DEFAULT_FAIL_RESPONSE); return; } @@ -431,17 +425,17 @@ What is the lastFile pointer? if (date.valueOf() > lastMinuteOfMonth.valueOf()) { - if (FULL_LOG === true) { logger.write("[INFO] start -> findNextHole -> readNextFile -> End of the month reached at date = " + date.toUTCString()); } + if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> findNextHole -> readNextFile -> End of the month reached at date = " + date.toUTCString()); } writeStatusReport(currentDatetime, currentTradeId, true, false, onStatusReportWritten); function onStatusReportWritten(err) { try { - if (FULL_LOG === true) { logger.write("[INFO] start -> findNextHole -> readNextFile -> onStatusReportWritten -> Entering function."); } + if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> findNextHole -> readNextFile -> onStatusReportWritten -> Entering function."); } if (err.result !== global.DEFAULT_OK_RESPONSE.result) { - logger.write("[ERROR] start -> findNextHole -> readNextFile -> onStatusReportWritten -> err = " + err.message); + logger.write(MODULE_NAME, "[ERROR] start -> findNextHole -> readNextFile -> onStatusReportWritten -> err = " + err.message); callBackFunction(err); return; } @@ -450,12 +444,12 @@ What is the lastFile pointer? result: global.CUSTOM_OK_RESPONSE.result, message: "End of the month reached." } - logger.write("[WARN] start -> findNextHole -> readNextFile -> onStatusReportWritten -> customOK = " + customOK.message); + logger.write(MODULE_NAME, "[WARN] start -> findNextHole -> readNextFile -> onStatusReportWritten -> customOK = " + customOK.message); callBackFunction(customOK); return; } catch (err) { - logger.write("[ERROR] start -> findNextHole -> readNextFile -> onStatusReportWritten -> err = " + err.message); + logger.write(MODULE_NAME, "[ERROR] start -> findNextHole -> readNextFile -> onStatusReportWritten -> err = " + err.message); callBackFunction(global.DEFAULT_FAIL_RESPONSE); return; } @@ -473,10 +467,10 @@ What is the lastFile pointer? try { - if (FULL_LOG === true) { logger.write("[INFO] start -> findNextHole -> readNextFile -> onNextFileReceived -> Entering function."); } + if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> findNextHole -> readNextFile -> onNextFileReceived -> Entering function."); } if (err.result === global.DEFAULT_FAIL_RESPONSE.result) { - logger.write("[ERROR] start -> findNextHole -> readNextFile -> onNextFileReceived -> err = " + err.message); + logger.write(MODULE_NAME, "[ERROR] start -> findNextHole -> readNextFile -> onNextFileReceived -> err = " + err.message); callBackFunction(err); return; } @@ -485,11 +479,11 @@ What is the lastFile pointer? err.result === global.CUSTOM_FAIL_RESPONSE.result && (err.message === 'Folder does not exist.' || err.message === 'File does not exist.') ) { - logger.write("[INFO] start -> findNextHole -> readNextFile -> onNextFileReceived -> err = " + err.message); + logger.write(MODULE_NAME, "[INFO] start -> findNextHole -> readNextFile -> onNextFileReceived -> err = " + err.message); /* The file does not exist, so this means there is a hole!!! */ - if (FULL_LOG === true) { logger.write("[INFO] start -> findNextHole -> readNextFile -> onNextFileReceived -> onNextFileReceived -> Hole by missing file detected. Date = " + date.toUTCString()); } + if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> findNextHole -> readNextFile -> onNextFileReceived -> onNextFileReceived -> Hole by missing file detected. Date = " + date.toUTCString()); } holeInitialId = currentTradeId; holeInitialDatetime = new Date(currentDatetime.valueOf()); // Field #5 contains the seconds. @@ -507,7 +501,7 @@ What is the lastFile pointer? /* If the file is corrupt, then we are in a similar situation as if it does not exist. */ - if (FULL_LOG === true) { logger.write("[INFO] start -> findNextHole -> readNextFile -> onNextFileReceived -> onNextFileReceived -> Hole by corrupt file detected. Date = " + date.toUTCString()); } + if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> findNextHole -> readNextFile -> onNextFileReceived -> onNextFileReceived -> Hole by corrupt file detected. Date = " + date.toUTCString()); } holeInitialId = currentTradeId; holeInitialDatetime = new Date(currentDatetime.valueOf()); // Field #5 contains the seconds. @@ -519,19 +513,19 @@ What is the lastFile pointer? return; } - logger.write("[ERROR] start -> findNextHole -> readNextFile -> onNextFileReceived -> onNextFileReceived -> Unhandled response received. err = " + err.message); + logger.write(MODULE_NAME, "[ERROR] start -> findNextHole -> readNextFile -> onNextFileReceived -> onNextFileReceived -> Unhandled response received. err = " + err.message); callBackFunction(err); return; } catch (err) { - logger.write("[ERROR] start -> findNextHole -> readNextFile -> onNextFileReceived -> err = " + err.message); + logger.write(MODULE_NAME, "[ERROR] start -> findNextHole -> readNextFile -> onNextFileReceived -> err = " + err.message); callBackFunction(global.DEFAULT_FAIL_RESPONSE); return; } } } catch (err) { - logger.write("[ERROR] start -> findNextHole -> readNextFile -> err = " + err.message); + logger.write(MODULE_NAME, "[ERROR] start -> findNextHole -> readNextFile -> err = " + err.message); callBackFunction(global.DEFAULT_FAIL_RESPONSE); return; } @@ -541,7 +535,7 @@ What is the lastFile pointer? try { - if (FULL_LOG === true) { logger.write("[INFO] start -> findNextHole -> checkHolesInFile -> Entering function."); } + if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> findNextHole -> checkHolesInFile -> Entering function."); } let trades = JSON.parse(text); @@ -556,7 +550,7 @@ What is the lastFile pointer? tradesWithHole = trades; - if (FULL_LOG === true) { logger.write("[INFO] start -> findNextHole -> checkHolesInFile -> Checking File '" + fileName + "' @ " + filePath + " - " + trades.length + " records in it."); } + if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> findNextHole -> checkHolesInFile -> Checking File '" + fileName + "' @ " + filePath + " - " + trades.length + " records in it."); } if (currentTradeId === FIRST_TRADE_RECORD_ID || currentTradeId === UNKNOWN_TRADE_RECORD_ID) { @@ -609,7 +603,7 @@ What is the lastFile pointer? if (currentTradeId === lastRecordedTradeId && lastRecordedCounter >= MAX_HOLE_FIXING_RETRIES) { - if (FULL_LOG === true) { logger.write("[INFO] start -> findNextHole -> checkHolesInFile -> Hole by non consecutive ID detected. MAX_HOLE_FIXING_RETRIES reched, giving up with this validation. Date = " + date.toUTCString()); } + if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> findNextHole -> checkHolesInFile -> Hole by non consecutive ID detected. MAX_HOLE_FIXING_RETRIES reched, giving up with this validation. Date = " + date.toUTCString()); } /* We advance anyway to the next Id since there is no other solution. */ @@ -620,7 +614,7 @@ What is the lastFile pointer? /* Here we have a hole that needs to be fixed !!! */ - if (FULL_LOG === true) { logger.write("[INFO] start -> findNextHole -> checkHolesInFile -> Hole by non consecutive ID detected. Date = " + date.toUTCString()); } + if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> findNextHole -> checkHolesInFile -> Hole by non consecutive ID detected. Date = " + date.toUTCString()); } holeInitialId = currentTradeId; holeInitialDatetime = new Date(currentDatetime.valueOf()); @@ -653,10 +647,10 @@ What is the lastFile pointer? function onStatusReportWritten(err) { try { - if (FULL_LOG === true) { logger.write("[INFO] start -> findNextHole -> checkHolesInFile -> onStatusReportWritten -> Entering function."); } + if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> findNextHole -> checkHolesInFile -> onStatusReportWritten -> Entering function."); } if (err.result !== global.DEFAULT_OK_RESPONSE.result) { - logger.write("[ERROR] start -> findNextHole -> checkHolesInFile -> onStatusReportWritten -> err = " + err.message); + logger.write(MODULE_NAME, "[ERROR] start -> findNextHole -> checkHolesInFile -> onStatusReportWritten -> err = " + err.message); callBackFunction(err); return; } @@ -666,7 +660,7 @@ What is the lastFile pointer? return; } catch (err) { - logger.write("[ERROR] start -> findNextHole -> checkHolesInFile -> onStatusReportWritten -> err = " + err.message); + logger.write(MODULE_NAME, "[ERROR] start -> findNextHole -> checkHolesInFile -> onStatusReportWritten -> err = " + err.message); callBackFunction(global.DEFAULT_FAIL_RESPONSE); return; } @@ -678,7 +672,7 @@ What is the lastFile pointer? } } catch (err) { - logger.write("[ERROR] start -> findNextHole -> checkHolesInFile -> err = " + err.message); + logger.write(MODULE_NAME, "[ERROR] start -> findNextHole -> checkHolesInFile -> err = " + err.message); callBackFunction(global.DEFAULT_FAIL_RESPONSE); return; } @@ -688,13 +682,13 @@ What is the lastFile pointer? try { - if (FULL_LOG === true) { logger.write("[INFO] start -> findNextHole -> findEndOfHole -> Entering function."); } + if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> findNextHole -> findEndOfHole -> Entering function."); } /* Here we will enter a loop where will try to find the next available file recorded and extract from it the Id and Datetime from the first record. */ date = new Date(date.valueOf() + 60 * 1000); - if (FULL_LOG === true) { logger.write("[INFO] start -> findNextHole -> findEndOfHole -> Date = " + date.toUTCString()); } + if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> findNextHole -> findEndOfHole -> Date = " + date.toUTCString()); } if (date.valueOf() > lastLiveTradeFile.valueOf()) { @@ -703,7 +697,7 @@ What is the lastFile pointer? forward side of the market. The situation in unsolvable for now, we will leave it of future execution. */ - if (FULL_LOG === true) { logger.write("[INFO] start -> findNextHole -> findEndOfHole -> Head of the market reached -> Date = " + date.toUTCString()); } + if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> findNextHole -> findEndOfHole -> Head of the market reached -> Date = " + date.toUTCString()); } nextIntervalExecution = true; // Even if we didn-t find the end of the hole, we need to continue the execution of this month interval. @@ -712,10 +706,10 @@ What is the lastFile pointer? function onStatusReportWritten(err) { try { - if (FULL_LOG === true) { logger.write("[INFO] start -> findNextHole -> findEndOfHole -> onStatusReportWritten -> Entering function."); } + if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> findNextHole -> findEndOfHole -> onStatusReportWritten -> Entering function."); } if (err.result !== global.DEFAULT_OK_RESPONSE.result) { - logger.write("[ERROR] start -> findNextHole -> findEndOfHole -> onStatusReportWritten -> err = " + err.message); + logger.write(MODULE_NAME, "[ERROR] start -> findNextHole -> findEndOfHole -> onStatusReportWritten -> err = " + err.message); callBackFunction(err); return; } @@ -723,7 +717,7 @@ What is the lastFile pointer? callBackFunction(global.DEFAULT_OK_RESPONSE); return; } catch (err) { - logger.write("[ERROR] start -> findNextHole -> findEndOfHole -> onStatusReportWritten -> err = " + err.message); + logger.write(MODULE_NAME, "[ERROR] start -> findNextHole -> findEndOfHole -> onStatusReportWritten -> err = " + err.message); callBackFunction(global.DEFAULT_FAIL_RESPONSE); return; } @@ -741,10 +735,10 @@ What is the lastFile pointer? try { - if (FULL_LOG === true) { logger.write("[INFO] start -> findNextHole -> findEndOfHole -> onNextFileReceived -> Entering function."); } + if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> findNextHole -> findEndOfHole -> onNextFileReceived -> Entering function."); } if (err.result === global.DEFAULT_FAIL_RESPONSE.result) { - logger.write("[ERROR] start -> findNextHole -> findEndOfHole -> onNextFileReceived -> err = " + err.message); + logger.write(MODULE_NAME, "[ERROR] start -> findNextHole -> findEndOfHole -> onNextFileReceived -> err = " + err.message); callBackFunction(err); return; } @@ -753,7 +747,7 @@ What is the lastFile pointer? err.result === global.CUSTOM_FAIL_RESPONSE.result && (err.message === 'Folder does not exist.' || err.message === 'File does not exist.') ) { - logger.write("[INFO] start -> findNextHole -> findEndOfHole -> onNextFileReceived -> err = " + err.message); + logger.write(MODULE_NAME, "[INFO] start -> findNextHole -> findEndOfHole -> onNextFileReceived -> err = " + err.message); /* The file does not exist, so this means we need to move forward */ @@ -773,7 +767,7 @@ What is the lastFile pointer? /* If the file is corrupt, then we are in a similar situation as if it does not exist. */ - logger.write("[INFO] start -> findNextHole -> findEndOfHole -> onNextFileReceived -> Corrupt file with no records. -> Date = " + date.toUTCString()); + logger.write(MODULE_NAME, "[INFO] start -> findNextHole -> findEndOfHole -> onNextFileReceived -> Corrupt file with no records. -> Date = " + date.toUTCString()); findEndOfHole(); return; @@ -783,13 +777,13 @@ What is the lastFile pointer? /* This is the same situation that if there is no file, move forward */ - logger.write("[INFO] start -> findNextHole -> findEndOfHole -> onNextFileReceived -> File with no records. -> Date = " + date.toUTCString()); + logger.write(MODULE_NAME, "[INFO] start -> findNextHole -> findEndOfHole -> onNextFileReceived -> File with no records. -> Date = " + date.toUTCString()); findEndOfHole(); return; } - logger.write("[INFO] start -> findNextHole -> findEndOfHole -> onNextFileReceived -> Next available record found at date = " + date.toUTCString()); + logger.write(MODULE_NAME, "[INFO] start -> findNextHole -> findEndOfHole -> onNextFileReceived -> Next available record found at date = " + date.toUTCString()); let fileTradeId = trades[0][0]; // First position in each record. @@ -800,26 +794,26 @@ What is the lastFile pointer? return; } - logger.write("[ERROR] start -> findNextHole -> findEndOfHole -> onNextFileReceived -> Unhandled response received. err = " + err.message); + logger.write(MODULE_NAME, "[ERROR] start -> findNextHole -> findEndOfHole -> onNextFileReceived -> Unhandled response received. err = " + err.message); callBackFunction(err); return; } catch (err) { - logger.write("[ERROR] start -> findNextHole -> findEndOfHole -> onNextFileReceived -> err = " + err.message); + logger.write(MODULE_NAME, "[ERROR] start -> findNextHole -> findEndOfHole -> onNextFileReceived -> err = " + err.message); callBackFunction(global.DEFAULT_FAIL_RESPONSE); return; } } } catch (err) { - logger.write("[ERROR] start -> findNextHole -> findEndOfHole -> err = " + err.message); + logger.write(MODULE_NAME, "[ERROR] start -> findNextHole -> findEndOfHole -> err = " + err.message); callBackFunction(global.DEFAULT_FAIL_RESPONSE); return; } } } catch (err) { - logger.write("[ERROR] start -> findNextHole -> err = " + err.message); + logger.write(MODULE_NAME, "[ERROR] start -> findNextHole -> err = " + err.message); callBackFunction(global.DEFAULT_FAIL_RESPONSE); return; } @@ -829,7 +823,7 @@ What is the lastFile pointer? try { - if (FULL_LOG === true) { logger.write("[INFO] start -> getTheTrades -> Entering function."); } + if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> getTheTrades -> Entering function."); } /* We request to the Exchange API some more records than needed, anyway we will discard records out of the range we need. @@ -846,7 +840,7 @@ What is the lastFile pointer? poloniexApiClient.API.returnPublicTradeHistory(market.assetA, market.assetB, startTime, endTime, onExchangeCallReturned); } catch (err) { - logger.write("[ERROR] start -> getTheTrades -> err = " + err.message); + logger.write(MODULE_NAME, "[ERROR] start -> getTheTrades -> err = " + err.message); callBackFunction(global.DEFAULT_FAIL_RESPONSE); return; } @@ -856,13 +850,13 @@ What is the lastFile pointer? try { - if (FULL_LOG === true) { logger.write("[INFO] start -> onExchangeCallReturned -> Entering function."); } + if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> onExchangeCallReturned -> Entering function."); } if (FULL_LOG === true) { let exchangeResponseTime = new Date(); let timeDifference = (exchangeResponseTime.valueOf() - exchangeCallTime.valueOf()) / 1000; - logger.write("[INFO] start -> onExchangeCallReturned -> Call time recorded = " + timeDifference + " seconds."); + logger.write(MODULE_NAME, "[INFO] start -> onExchangeCallReturned -> Call time recorded = " + timeDifference + " seconds."); } poloniexApiClient.API.analizeResponse(logger, err, exchangeResponse, callBackFunction, onResponseOk); @@ -873,7 +867,7 @@ What is the lastFile pointer? } } catch (err) { - logger.write("[ERROR] start -> onExchangeCallReturned -> err = " + err.message); + logger.write(MODULE_NAME, "[ERROR] start -> onExchangeCallReturned -> err = " + err.message); callBackFunction(global.DEFAULT_FAIL_RESPONSE); return; } @@ -883,7 +877,7 @@ What is the lastFile pointer? try { - if (FULL_LOG === true) { logger.write("[INFO] start -> tradesReadyToBeSaved -> Entering function."); } + if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> tradesReadyToBeSaved -> Entering function."); } /* We have learnt that the records from the exchange dont always come in the right order, sorted by TradeId. That means the we need to sort them @@ -1009,7 +1003,7 @@ What is the lastFile pointer? try { - if (FULL_LOG === true) { logger.write("[INFO] start -> tradesReadyToBeSaved -> storeFileContent -> Entering function."); } + if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> tradesReadyToBeSaved -> storeFileContent -> Entering function."); } let existingFileContent = ""; let separator = ""; @@ -1063,7 +1057,7 @@ What is the lastFile pointer? fileContent = ""; } catch (err) { - logger.write("[ERROR] start -> tradesReadyToBeSaved -> storeFileContent -> err = " + err.message); + logger.write(MODULE_NAME, "[ERROR] start -> tradesReadyToBeSaved -> storeFileContent -> err = " + err.message); callBackFunction(global.DEFAULT_FAIL_RESPONSE); return; } @@ -1080,7 +1074,7 @@ What is the lastFile pointer? try { - if (FULL_LOG === true) { logger.write("[INFO] start -> tradesReadyToBeSaved -> nextRecord -> Entering function."); } + if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> tradesReadyToBeSaved -> nextRecord -> Entering function."); } let fileName = '' + market.assetA + '_' + market.assetB + '.json'; @@ -1098,33 +1092,33 @@ What is the lastFile pointer? try { - if (FULL_LOG === true) { logger.write("[INFO] start -> tradesReadyToBeSaved -> nextRecord -> onFileCreated -> Entering function."); } + if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> tradesReadyToBeSaved -> nextRecord -> onFileCreated -> Entering function."); } if (err.result !== global.DEFAULT_OK_RESPONSE.result) { - logger.write("[ERROR] start -> tradesReadyToBeSaved -> nextRecord -> onFileCreated -> err = " + err.message); + logger.write(MODULE_NAME, "[ERROR] start -> tradesReadyToBeSaved -> nextRecord -> onFileCreated -> err = " + err.message); callBackFunction(err); return; } if (LOG_FILE_CONTENT === true) { - logger.write("[INFO] start -> tradesReadyToBeSaved -> nextRecord -> onFileCreated -> Content written = " + fileContent); + logger.write(MODULE_NAME, "[INFO] start -> tradesReadyToBeSaved -> nextRecord -> onFileCreated -> Content written = " + fileContent); } - logger.write("[WARN] start -> tradesReadyToBeSaved -> nextRecord -> onFileCreated -> Finished with File @ " + market.assetA + "_" + market.assetB); - logger.write("[WARN] start -> tradesReadyToBeSaved -> nextRecord -> onFileCreated -> Records inserted = " + fileRecordCounter); - logger.write("[WARN] start -> tradesReadyToBeSaved -> nextRecord -> onFileCreated -> Path = " + filePath + "/" + fileName + ""); + logger.write(MODULE_NAME, "[INFO] start -> tradesReadyToBeSaved -> nextRecord -> onFileCreated -> Finished with File @ " + market.assetA + "_" + market.assetB); + logger.write(MODULE_NAME, "[INFO] start -> tradesReadyToBeSaved -> nextRecord -> onFileCreated -> Records inserted = " + fileRecordCounter); + logger.write(MODULE_NAME, "[INFO] start -> tradesReadyToBeSaved -> nextRecord -> onFileCreated -> Path = " + filePath + "/" + fileName + ""); controlLoop(); } catch (err) { - logger.write("[ERROR] start -> tradesReadyToBeSaved -> nextRecord -> onFileCreated -> err = " + err.message); + logger.write(MODULE_NAME, "[ERROR] start -> tradesReadyToBeSaved -> nextRecord -> onFileCreated -> err = " + err.message); callBackFunction(global.DEFAULT_FAIL_RESPONSE); return; } } } catch (err) { - logger.write("[ERROR] start -> tradesReadyToBeSaved -> nextRecord -> err = " + err.message); + logger.write(MODULE_NAME, "[ERROR] start -> tradesReadyToBeSaved -> nextRecord -> err = " + err.message); callBackFunction(global.DEFAULT_FAIL_RESPONSE); return; } @@ -1134,7 +1128,7 @@ What is the lastFile pointer? try { - if (FULL_LOG === true) { logger.write("[INFO] start -> tradesReadyToBeSaved -> controlLoop -> Entering function."); } + if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> tradesReadyToBeSaved -> controlLoop -> Entering function."); } i++; @@ -1144,13 +1138,13 @@ What is the lastFile pointer? } else { - if (FULL_LOG === true) { logger.write("[INFO] start -> tradesReadyToBeSaved -> controlLoop -> Leaving function 'tradesReadyToBeSaved'."); } + if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> tradesReadyToBeSaved -> controlLoop -> Leaving function 'tradesReadyToBeSaved'."); } writeStatusReport(undefined, undefined, false, false, onStatusReportWritten); function onStatusReportWritten() { - if (FULL_LOG === true) { logger.write("[INFO] start -> tradesReadyToBeSaved -> controlLoop -> onStatusReportWritten -> Entering function."); } + if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> tradesReadyToBeSaved -> controlLoop -> onStatusReportWritten -> Entering function."); } callBackFunction(global.DEFAULT_OK_RESPONSE); return; @@ -1158,14 +1152,14 @@ What is the lastFile pointer? } } catch (err) { - logger.write("[ERROR] start -> tradesReadyToBeSaved -> controlLoop -> err = " + err.message); + logger.write(MODULE_NAME, "[ERROR] start -> tradesReadyToBeSaved -> controlLoop -> err = " + err.message); callBackFunction(global.DEFAULT_FAIL_RESPONSE); return; } } } catch (err) { - logger.write("[ERROR] start -> tradesReadyToBeSaved -> err = " + err.message); + logger.write(MODULE_NAME, "[ERROR] start -> tradesReadyToBeSaved -> err = " + err.message); callBackFunction(global.DEFAULT_FAIL_RESPONSE); return; } @@ -1175,7 +1169,7 @@ What is the lastFile pointer? try { - if (FULL_LOG === true) { logger.write("[INFO] start -> writeStatusReport -> Entering function."); } + if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> writeStatusReport -> Entering function."); } /* If no parameters are provided, that means that last good information is the begining of the hole. If they are provided is because no hole was detected until the @@ -1241,10 +1235,10 @@ What is the lastFile pointer? function onSaved(err) { - if (FULL_LOG === true) { logger.write("[INFO] start -> writeStatusReport -> onSaved -> Entering function."); } + if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> writeStatusReport -> onSaved -> Entering function."); } if (err.result !== global.DEFAULT_OK_RESPONSE.result) { - logger.write("[ERROR] start -> writeStatusReport -> onSaved -> err = " + err.message); + logger.write(MODULE_NAME, "[ERROR] start -> writeStatusReport -> onSaved -> err = " + err.message); callBackFunction(err); return; } @@ -1291,7 +1285,7 @@ What is the lastFile pointer? } } catch (err) { - logger.write("[ERROR] start -> writeStatusReport -> err = " + err.message); + logger.write(MODULE_NAME, "[ERROR] start -> writeStatusReport -> err = " + err.message); callBackFunction(global.DEFAULT_FAIL_RESPONSE); return; } @@ -1300,7 +1294,7 @@ What is the lastFile pointer? function createMainStatusReport(lastTradeDatetime, lastTradeId, callBack) { try { - if (FULL_LOG === true) { logger.write("[INFO] start -> createMainStatusReport -> Entering function."); } + if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> createMainStatusReport -> Entering function."); } let key = bot.devTeam + "-" + bot.codeName + "-" + bot.process + "-" + bot.dataSetVersion; @@ -1331,10 +1325,10 @@ What is the lastFile pointer? function onSaved(err) { - if (FULL_LOG === true) { logger.write("[INFO] start -> createMainStatusReport -> onSaved -> Entering function."); } + if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> createMainStatusReport -> onSaved -> Entering function."); } if (err.result !== global.DEFAULT_OK_RESPONSE.result) { - logger.write("[ERROR] start -> createMainStatusReport -> onSaved -> err = " + err.message); + logger.write(MODULE_NAME, "[ERROR] start -> createMainStatusReport -> onSaved -> err = " + err.message); callBackFunction(err); return; } @@ -1344,14 +1338,14 @@ What is the lastFile pointer? } } catch (err) { - logger.write("[ERROR] start -> createMainStatusReport -> err = " + err.message); + logger.write(MODULE_NAME, "[ERROR] start -> createMainStatusReport -> err = " + err.message); callBackFunction(global.DEFAULT_FAIL_RESPONSE); return; } } } catch (err) { - logger.write("[ERROR] start -> err = " + err.message); + logger.write(MODULE_NAME, "[ERROR] start -> err = " + err.message); callBackFunction(global.DEFAULT_FAIL_RESPONSE); return; } diff --git a/Poloniex-Live-Trades/User.bot.js b/Poloniex-Live-Trades/User.bot.js index 90888471b..ec8fd0fff 100644 --- a/Poloniex-Live-Trades/User.bot.js +++ b/Poloniex-Live-Trades/User.bot.js @@ -1,31 +1,25 @@ -exports.newUserBot = function newUserBot(BOT, COMMONS, UTILITIES, DEBUG_MODULE, BLOB_STORAGE, STATUS_REPORT, POLONIEX_CLIENT_MODULE) { +exports.newUserBot = function newUserBot(bot, logger, COMMONS, UTILITIES, BLOB_STORAGE, STATUS_REPORT, POLONIEX_CLIENT_MODULE) { const FULL_LOG = true; const LOG_FILE_CONTENT = false; - let bot = BOT; - const GMT_SECONDS = ':00.000 GMT+0000'; const GMT_MILI_SECONDS = '.000 GMT+0000'; - const MODULE_NAME = "UserBot"; + const MODULE_NAME = "User Bot"; const EXCHANGE_NAME = "Poloniex"; const TRADES_FOLDER_NAME = "Trades"; - const logger = DEBUG_MODULE.newDebugLog(); - logger.fileName = MODULE_NAME; - logger.bot = bot; - thisObject = { initialize: initialize, start: start }; - let charlyStorage = BLOB_STORAGE.newBlobStorage(bot); + let charlyStorage = BLOB_STORAGE.newBlobStorage(bot, logger); - let utilities = UTILITIES.newCloudUtilities(bot); + let utilities = UTILITIES.newCloudUtilities(bot, logger); let poloniexApiClient = POLONIEX_CLIENT_MODULE.newPoloniexAPIClient(global.EXCHANGE_KEYS[global.EXCHANGE_NAME].Key, global.EXCHANGE_KEYS[global.EXCHANGE_NAME].Secret); let statusDependencies; @@ -39,7 +33,7 @@ logger.fileName = MODULE_NAME; logger.initialize(); - if (FULL_LOG === true) { logger.write("[INFO] initialize -> Entering function."); } + if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] initialize -> Entering function."); } statusDependencies = pStatusDependencies; @@ -49,17 +43,17 @@ if (err.result === global.DEFAULT_OK_RESPONSE.result) { - if (FULL_LOG === true) { logger.write("[INFO] initialize -> onCharlyInizialized -> Initialization Succeed."); } + if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] initialize -> onCharlyInizialized -> Initialization Succeed."); } callBackFunction(global.DEFAULT_OK_RESPONSE); } else { - logger.write("[ERROR] initialize -> onCharlyInizialized -> err = " + err.message); + logger.write(MODULE_NAME, "[ERROR] initialize -> onCharlyInizialized -> err = " + err.message); callBackFunction(err); } } } catch (err) { - logger.write("[ERROR] initialize -> err = " + err.message); + logger.write(MODULE_NAME, "[ERROR] initialize -> err = " + err.message); callBackFunction(global.DEFAULT_FAIL_RESPONSE); } } @@ -93,7 +87,7 @@ Array of records with this information: try { - if (FULL_LOG === true) { logger.write("[INFO] start -> Entering function."); } + if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> Entering function."); } let market = global.MARKET; @@ -117,7 +111,7 @@ Array of records with this information: try { - if (FULL_LOG === true) { logger.write("[INFO] start -> firstSteps -> Entering function."); } + if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> firstSteps -> Entering function."); } currentDate = bot.processDatetime; @@ -132,7 +126,7 @@ Array of records with this information: getTheTrades(); } catch (err) { - logger.write("[ERROR] start -> firstSteps -> err = " + err.message); + logger.write(MODULE_NAME, "[ERROR] start -> firstSteps -> err = " + err.message); callBackFunction(global.DEFAULT_FAIL_RESPONSE); } } @@ -141,7 +135,7 @@ Array of records with this information: try { - if (FULL_LOG === true) { logger.write("[INFO] start -> getTheTrades -> Entering function."); } + if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> getTheTrades -> Entering function."); } const datetime = parseInt(currentDate.valueOf() / 1000); @@ -158,7 +152,7 @@ Array of records with this information: poloniexApiClient.API.returnPublicTradeHistory(market.assetA, market.assetB, startTime, endTime, onExchangeCallReturned); } catch (err) { - logger.write("[ERROR] start -> getTheTrades -> err = " + err.message); + logger.write(MODULE_NAME, "[ERROR] start -> getTheTrades -> err = " + err.message); callBackFunction(global.DEFAULT_FAIL_RESPONSE); } } @@ -167,13 +161,13 @@ Array of records with this information: try { - if (FULL_LOG === true) { logger.write("[INFO] start -> onExchangeCallReturned -> Entering function."); } + if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> onExchangeCallReturned -> Entering function."); } if (FULL_LOG === true) { let exchangeResponseTime = new Date(); let timeDifference = (exchangeResponseTime.valueOf() - exchangeCallTime.valueOf()) / 1000; - logger.write("[INFO] start -> onExchangeCallReturned -> Call time recorded = " + timeDifference + " seconds."); + logger.write(MODULE_NAME, "[INFO] start -> onExchangeCallReturned -> Call time recorded = " + timeDifference + " seconds."); } poloniexApiClient.API.analizeResponse(logger, err, exchangeResponse, callBackFunction, onResponseOk); @@ -184,7 +178,7 @@ Array of records with this information: } } catch (err) { - logger.write("[ERROR] start -> onExchangeCallReturned -> err = " + err.message); + logger.write(MODULE_NAME, "[ERROR] start -> onExchangeCallReturned -> err = " + err.message); callBackFunction(global.DEFAULT_FAIL_RESPONSE); } } @@ -193,7 +187,7 @@ Array of records with this information: try { - if (FULL_LOG === true) { logger.write("[INFO] start -> tradesReadyToBeSaved -> Entering function."); } + if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> tradesReadyToBeSaved -> Entering function."); } let fileRecordCounterA = 0; let fileRecordCounterB = 0; @@ -251,28 +245,28 @@ Array of records with this information: function onFirstFileACreated(err) { - if (FULL_LOG === true) { logger.write("[INFO] start -> tradesReadyToBeSaved -> onFirstFileACreated -> Entering function."); } + if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> tradesReadyToBeSaved -> onFirstFileACreated -> Entering function."); } if (err.result !== global.DEFAULT_OK_RESPONSE.result) { - logger.write("[ERROR] start -> tradesReadyToBeSaved -> onFirstFileACreated -> err = " + err.message); + logger.write(MODULE_NAME, "[ERROR] start -> tradesReadyToBeSaved -> onFirstFileACreated -> err = " + err.message); callBackFunction(err); return; } if (LOG_FILE_CONTENT === true) { - logger.write("[INFO] start -> tradesReadyToBeSaved -> onFirstFileACreated -> Content written = " + fileContent); + logger.write(MODULE_NAME, "[INFO] start -> tradesReadyToBeSaved -> onFirstFileACreated -> Content written = " + fileContent); } - logger.write("[WARN] start -> tradesReadyToBeSaved -> onFirstFileACreated -> Finished with File A @ " + market.assetA + "_" + market.assetB); - logger.write("[WARN] start -> tradesReadyToBeSaved -> onFirstFileACreated -> Records inserted = " + fileRecordCounterA); - logger.write("[WARN] start -> tradesReadyToBeSaved -> onFirstFileACreated -> Path = " + filePathA + "/" + fileNameA + ""); + logger.write(MODULE_NAME, "[INFO] start -> tradesReadyToBeSaved -> onFirstFileACreated -> Finished with File A @ " + market.assetA + "_" + market.assetB); + logger.write(MODULE_NAME, "[INFO] start -> tradesReadyToBeSaved -> onFirstFileACreated -> Records inserted = " + fileRecordCounterA); + logger.write(MODULE_NAME, "[INFO] start -> tradesReadyToBeSaved -> onFirstFileACreated -> Path = " + filePathA + "/" + fileNameA + ""); generateFileB(); } function generateFileB() { - if (FULL_LOG === true) { logger.write("[INFO] start -> tradesReadyToBeSaved -> generateFileB -> Entering function."); } + if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> tradesReadyToBeSaved -> generateFileB -> Entering function."); } fileContent = ""; needSeparator = false; @@ -318,27 +312,27 @@ Array of records with this information: function onFileBCreated(err) { - if (FULL_LOG === true) { logger.write("[INFO] start -> tradesReadyToBeSaved -> onFileBCreated -> Entering function."); } + if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> tradesReadyToBeSaved -> onFileBCreated -> Entering function."); } if (err.result !== global.DEFAULT_OK_RESPONSE.result) { - logger.write("[ERROR] start -> tradesReadyToBeSaved -> onFileBCreated -> err = " + err.message); + logger.write(MODULE_NAME, "[ERROR] start -> tradesReadyToBeSaved -> onFileBCreated -> err = " + err.message); callBackFunction(err); return; } if (LOG_FILE_CONTENT === true) { - logger.write("[INFO] start -> tradesReadyToBeSaved -> onFileBCreated -> Content written = " + fileContent); + logger.write(MODULE_NAME, "[INFO] start -> tradesReadyToBeSaved -> onFileBCreated -> Content written = " + fileContent); } - logger.write("[WARN] start -> tradesReadyToBeSaved -> onFileBCreated -> Finished with File B @ " + market.assetA + "_" + market.assetB); - logger.write("[WARN] start -> tradesReadyToBeSaved -> onFileBCreated -> Content written -> Records inserted = " + fileRecordCounterB); - logger.write("[WARN] start -> tradesReadyToBeSaved -> onFileBCreated -> Content written -> Path = " + filePathB + "/" + fileNameB + ""); + logger.write(MODULE_NAME, "[INFO] start -> tradesReadyToBeSaved -> onFileBCreated -> Finished with File B @ " + market.assetA + "_" + market.assetB); + logger.write(MODULE_NAME, "[INFO] start -> tradesReadyToBeSaved -> onFileBCreated -> Content written -> Records inserted = " + fileRecordCounterB); + logger.write(MODULE_NAME, "[INFO] start -> tradesReadyToBeSaved -> onFileBCreated -> Content written -> Path = " + filePathB + "/" + fileNameB + ""); writeStatusReport(); } } } catch (err) { - logger.write("[ERROR] start -> tradesReadyToBeSaved -> err = " + err.message); + logger.write(MODULE_NAME, "[ERROR] start -> tradesReadyToBeSaved -> err = " + err.message); callBackFunction(global.DEFAULT_FAIL_RESPONSE); } } @@ -347,7 +341,7 @@ Array of records with this information: try { - if (FULL_LOG === true) { logger.write("[INFO] start -> writeStatusReport -> Entering function."); } + if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> writeStatusReport -> Entering function."); } let key = bot.devTeam + "-" + bot.codeName + "-" + bot.process + "-" + bot.dataSetVersion; @@ -374,10 +368,10 @@ Array of records with this information: function onSaved(err) { - if (FULL_LOG === true) { logger.write("[INFO] start -> writeStatusReport -> onSaved -> Entering function."); } + if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> writeStatusReport -> onSaved -> Entering function."); } if (err.result !== global.DEFAULT_OK_RESPONSE.result) { - logger.write("[ERROR] start -> writeStatusReport -> onSaved -> err = " + err.message); + logger.write(MODULE_NAME, "[ERROR] start -> writeStatusReport -> onSaved -> err = " + err.message); callBackFunction(err); return; } @@ -386,13 +380,13 @@ Array of records with this information: } } catch (err) { - logger.write("[ERROR] start -> writeStatusReport -> err = " + err.message); + logger.write(MODULE_NAME, "[ERROR] start -> writeStatusReport -> err = " + err.message); callBackFunction(global.DEFAULT_FAIL_RESPONSE); } } } catch (err) { - logger.write("[ERROR] start -> err = " + err.message); + 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 7a3a0e014..14d8bd1ae 100644 --- a/this.bot.config.json +++ b/this.bot.config.json @@ -104,12 +104,12 @@ "description": "Scans the trades saved by the Live Trades and Historic Trades processes searching for missing records. Once a hole is found on the data set, it patches it by retrieving the missing records from the exchange.", "startMode": { "allMonths": { - "run": "false", + "run": "true", "minYear": "2018", "maxYear": "2018" }, "oneMonth": { - "run": "true", + "run": "false", "year": "2018", "month": "04" },