From 06690bdc188d9ccb858f23b79ee5cc7345b05269 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Sat, 17 Mar 2018 13:38:46 +0100 Subject: [PATCH] Dependencies Implemented --- .vs/AAOlivia-Indicator-Bot/v15/.suo | Bin 32768 -> 32768 bytes Commons.js | 243 +--------------------------- Multi-Period-Daily/User.bot.js | 107 ++++++------ Multi-Period-Market/User.bot.js | 107 ++++++------ this.bot.config.json | 68 +++++++- 5 files changed, 192 insertions(+), 333 deletions(-) diff --git a/.vs/AAOlivia-Indicator-Bot/v15/.suo b/.vs/AAOlivia-Indicator-Bot/v15/.suo index 41dd6bea744e4e6a4ed1ccd334a797331d8a25ea..8eb388427c7becc261bf73a6fde1ab2b3da31c32 100644 GIT binary patch delta 2094 zcmc(gZERCj7{|}KYu9abUAwhxKu0?m*u6s6y$NO9Zrx;p83Zt!LAU9~i(#;}x3ITl z1vF>|%I*`t02*X`AV!gKqtOU)AWPH_Oi(}g!DJy~7ByrVmp~Be|8y;3W*QSec#_{e z@6Ubi|2)sR;jk1AOUJz2FtTQaWSSZqyL9u?*WAWXmQk-%PoEjwoM>7a(C1?89Q7Fb z_)9dM@Yqm`ao2-LBx1pEItYXW zOe)n!eVKW?j^0hm;>od&Wi_@|Jz_2+<|BP$Gm|;RzTgNZkAm00>);p|0;-mm@(EXs zHOZW#E0iKR=;DVcWE|iJX&TQ16iOXb%{Af>^j%o-18uUb*RGnqT(!2@;tJX^BUFqk zNUhdPI%ajQEW$`JSOHc7Hz)z(qXcDWmxBsW324G<)kVMfj`gB$j~MyLW;gCbV?XGQ zF0naPm%@7}3CKxV304v{&5JOD$N|dFz;hN_7rPnL8dSosg@Od%ToF84XDy=#~nfAVjhU4SX15+Wln-5?$!-*Dm(^Iki~i z*}@KRA>-lfw)X9uC{=YuUEUc}Y{u{GzFUoRb={BgYDZ2pOt6DP8s z5G#bac+t@Tvsh^yDol-?!V56DjRo-R>$>u50P25KMn9K6$t$LGwHQUGns>fys zu)XX>_BkD>$|c$3P7{aQz;?4;Y#(UV!k$~4E400AM6JI<@0V}QaIBUmDPjO1pNl@)>Tcc)Z+QR99Q(F7nM|ECV9x*chE!*FuZeImo*vmC~y6 zG`Xsp(|g`;`T5vX9(^yn=+(7fa-=GZ85w%0XPKCAd;&dXY%}$=PWH+47sRY0RHBxBb)g z{4WuChugKg8`2Zfebu!!bH?7NLEGAx!Y$r-aG-7iF6!*KMeh1O>MQ+e)^TdZ6*r`L z@HqsS5!dZZSvD#z*k&->746!NG;R?;xp;}L z)4KMWB>hG)M*c3ZHrgdi@mq0NMgqmIIOjiIanap8u$IE@@^Cl+h4zL??();kZm*$n zT>McP-3w&XnQprpaM8hF7Rdpb&hmY2Tgq(pUXc!*Z|mCj?tfi~s-t delta 1882 zcmd5+O>7fa5ZdRPV7*Hrb$YK1X2;EvWtL_A8gaa zMA~gZ2nhtq&IKVPO3D$n4ckLiHN{n>{)hvCmMfwc4v4FzL`b+Z8*gL@5D$?z znKwJ{n>SBYc~#}7+L(Q|y@@Yv&R&yS=Kf)g9LI&~AkFtc*b-nDA>Ub|5j zAtZzsu?evm;X_dThp7FCCPXu0D}wCXP;W=HAX*VS5J5y6g8X?|lWRxAi`h?0n8pv4 zs^5*&5DArNT#J1jq81Ql-g11eK&;8z*5);_N85n`+jcwANDHDEfM`g_swsQCj6Qxz_>igsv#>Y%nhj;#o@w*R4>U)7q8VPt;CKGChDIvKcpJ^ZH0}t z63sj;t~>5C>Y!Q*;6bm9s6kKzX=8K>U`mvm%|Nq50d!E8UezIrg~y^K?4s2R;xB?> z`Kiq9Fw-oBl*#YLQlFhsOQ?MYf2Z`+2MS|O$U4vPQ=Fc5{Vmv$KaMNOhZM5dZ^Jrs z)PG~KK`C?T*_skw6JzfUMKc?Dt#^UBV6pce{Iw;hxg$1eJRMFdTu-_On6VWada`Wl z!k2jjNi6=w;nYy_Q1ZlR*N$!eWIT~f#FNRR!$%T{1cdx`dT1b1q^m7)#`eII)>%+b zUV#I_eQ+`;!PTIo`wsrgYa7DwyQdx0C9Qez=vpy*6@q?g@aj2V;zOcoVg&97xF1!Z zx_c{3cl-hK(O>n@=NSfS=O9~lSp+U(xF5v*5Umt6XT)Z~)pYunvpOf28wzRHIbhvx zkR=)J4Bx2w3Cd?Qu?BZs~4}CU9xJx2t=mI67(ILi3 z3>%D%T!!Cvcfg%aX~jnEg1O;uS0P`o?q1JUr~Azb`Sa~Jp^uG}^3XAEg}vU*aJ{u$ i&y0om+oKA5$q1Q=kRD2B*zNQ)Uccp)m^S&$(EkJVreLZ7 diff --git a/Commons.js b/Commons.js index 60a4cce44..cf510cf27 100644 --- a/Commons.js +++ b/Commons.js @@ -9,8 +9,7 @@ const GMT_SECONDS = ':00.000 GMT+0000'; let thisObject = { - initializeStorage: initializeStorage, - getContextVariables: getContextVariables + initializeStorage: initializeStorage }; let bot = BOT; @@ -23,7 +22,7 @@ return thisObject; - function initializeStorage(charlyFileStorage, bruceFileStorage, oliviaFileStorage, callBackFunction) { + function initializeStorage(oliviaFileStorage, callBackFunction) { try { @@ -33,40 +32,6 @@ function initializeCharlyStorage() { - charlyFileStorage.initialize("AACharly", onCharlyInizialized); - - function onCharlyInizialized(err) { - - if (err.result === global.DEFAULT_OK_RESPONSE.result) { - - initializeBruceStorage(); - - } else { - logger.write("[ERROR] initializeStorage -> initializeCharlyStorage -> onCharlyInizialized -> err = " + err.message); - callBackFunction(err); - } - } - } - - function initializeBruceStorage() { - - bruceFileStorage.initialize("AABruce", onBruceInizialized); - - function onBruceInizialized(err) { - - if (err.result === global.DEFAULT_OK_RESPONSE.result) { - - initializeOliviaStorage(); - - } else { - logger.write("[ERROR] initializeStorage -> initializeBruceStorage -> onBruceInizialized -> err = " + err.message); - callBackFunction(err); - } - } - } - - function initializeOliviaStorage() { - oliviaFileStorage.initialize("AAOlivia", onOliviaInizialized); function onOliviaInizialized(err) { @@ -88,208 +53,4 @@ } } - function getContextVariables(charlyFileStorage, bruceFileStorage, oliviaFileStorage, contextVariables, statusReportModule, callBackFunction) { - - try { - - if (FULL_LOG === true) { logger.write("[INFO] getContextVariables -> Entering function."); } - - let reportFilePath; - let fileName = "Status.Report." + global.MARKET.assetA + '_' + global.MARKET.assetB + ".json" - - if (FULL_LOG === true) { logger.write("[INFO] getContextVariables -> fileName = " + fileName); } - - getHistoricTrades(); - - function getHistoricTrades() { - - try { - if (FULL_LOG === true) { logger.write("[INFO] getContextVariables -> getHistoricTrades -> Entering function."); } - - /* - - We need to know where is the begining of the market, since that will help us know where the Index Files should start. - - */ - - reportFilePath = EXCHANGE_NAME + "/Processes/" + "Poloniex-Historic-Trades"; - - if (FULL_LOG === true) { logger.write("[INFO] getContextVariables -> getHistoricTrades -> reportFilePath = " + reportFilePath); } - - charlyFileStorage.getTextFile(reportFilePath, fileName, onFileReceived); - - function onFileReceived(err, text) { - - if (FULL_LOG === true) { logger.write("[INFO] getContextVariables -> getHistoricTrades -> onFileReceived -> Entering function."); } - if (FULL_LOG === true) { logger.write("[INFO] getContextVariables -> getHistoricTrades -> onFileReceived -> text = " + text); } - - let thisReport; - - if (err.result === global.DEFAULT_OK_RESPONSE.result) { - try { - thisReport = JSON.parse(text); - - contextVariables.firstTradeFile = new Date(thisReport.lastFile.year + "-" + thisReport.lastFile.month + "-" + thisReport.lastFile.days + " " + thisReport.lastFile.hours + ":" + thisReport.lastFile.minutes + GMT_SECONDS); - - getOneMinDailyCandlesVolumes(); - - } catch (err) { - logger.write("[ERROR] getContextVariables -> getHistoricTrades -> onFileReceived -> err = " + err.message); - logger.write("[ERROR] getContextVariables -> getHistoricTrades -> onFileReceived -> Asuming this is a temporary situation. Requesting a Retry."); - callBackFunction(global.DEFAULT_RETRY_RESPONSE); - } - } else { - logger.write("[ERROR] getContextVariables -> getHistoricTrades -> onFileReceived -> err = " + err.message); - callBackFunction(err); - } - } - } - catch (err) { - logger.write("[ERROR] getContextVariables -> getHistoricTrades -> err = " + err.message); - callBackFunction(global.DEFAULT_FAIL_RESPONSE); - } - } - - function getOneMinDailyCandlesVolumes() { - - try { - - if (FULL_LOG === true) { logger.write("[INFO] getContextVariables -> getOneMinDailyCandlesVolumes -> Entering function."); } - - /* We need to discover the maxCandle file, which is the last file with candles we can use as input. */ - - let date = new Date(); - let currentYear = date.getUTCFullYear(); - let currentMonth = utilities.pad(date.getUTCMonth() + 1, 2); - - reportFilePath = EXCHANGE_NAME + "/Processes/" + "One-Min-Daily-Candles-Volumes" + "/" + currentYear + "/" + currentMonth; - - if (FULL_LOG === true) { logger.write("[INFO] getContextVariables -> getOneMinDailyCandlesVolumes -> reportFilePath = " + reportFilePath); } - - bruceFileStorage.getTextFile(reportFilePath, fileName, onFileReceived); - - function onFileReceived(err, text) { - - if (FULL_LOG === true) { logger.write("[INFO] getContextVariables -> getOneMinDailyCandlesVolumes -> onFileReceived -> Entering function."); } - if (FULL_LOG === true) { logger.write("[INFO] getContextVariables -> getOneMinDailyCandlesVolumes -> onFileReceived -> text = " + text); } - - let thisReport; - - if (err.result === global.DEFAULT_OK_RESPONSE.result) { - try { - thisReport = JSON.parse(text); - - contextVariables.maxCandleFile = new Date(thisReport.lastFile.year + "-" + thisReport.lastFile.month + "-" + thisReport.lastFile.days + " " + "00:00" + GMT_SECONDS); - - getThisProcessReport(); - - } catch (err) { - logger.write("[ERROR] getContextVariables -> getOneMinDailyCandlesVolumes -> onFileReceived -> err = " + err.message); - logger.write("[ERROR] getContextVariables -> getOneMinDailyCandlesVolumes -> onFileReceived -> Asuming this is a temporary situation. Requesting a Retry."); - callBackFunction(global.DEFAULT_RETRY_RESPONSE); - } - } else { - logger.write("[ERROR] getContextVariables -> getOneMinDailyCandlesVolumes -> onFileReceived -> err = " + err.message); - callBackFunction(err); - } - } - } - catch (err) { - logger.write("[ERROR] getContextVariables -> getOneMinDailyCandlesVolumes -> err = " + err.message); - callBackFunction(global.DEFAULT_FAIL_RESPONSE); - } - } - - function getThisProcessReport() { - - try { - - if (FULL_LOG === true) { logger.write("[INFO] getContextVariables -> getThisProcessReport -> Entering function."); } - - statusReportModule.initialize(bot, onInitilized); - - function onInitilized(err) { - - if (err.result !== global.DEFAULT_OK_RESPONSE.result) { - logger.write("[ERROR] getContextVariables -> getThisProcessReport -> err = " + err.message); - callBackFunction(err); - return; - } - - statusReportModule.load(onLoad); - } - - function onLoad(err) { - - try { - - switch (err.result) { - case global.DEFAULT_OK_RESPONSE.result: { - logger.write("[INFO] getContextVariables -> getThisProcessReport -> onInitilized -> Execution finished well. :-)"); - - contextVariables.lastCandleFile = new Date(statusReportModule.file.lastFile); - - /* - Here we assume that the last day written might contain incomplete information. This actually happens every time the head of the market is reached. - For that reason we go back one day, the partial information is discarded and added again with whatever new info is available. - */ - - contextVariables.lastCandleFile = new Date(contextVariables.lastCandleFile.valueOf() - ONE_DAY_IN_MILISECONDS); - - let customOk = { - result: global.CUSTOM_OK_RESPONSE.result, - message: "Status Report did exist." - }; - - callBackFunction(customOk); - - return; - } - case global.CUSTOM_OK_RESPONSE.result: { // We need to see if we can handle this. - logger.write("[ERROR] getContextVariables -> getThisProcessReport -> onInitilized -> err.message = " + err.message); - - if (err.message === "Status Report was never created.") { - - contextVariables.lastCandleFile = new Date(contextVariables.firstTradeFile.getUTCFullYear() + "-" + (contextVariables.firstTradeFile.getUTCMonth() + 1) + "-" + contextVariables.firstTradeFile.getUTCDate() + " " + "00:00" + GMT_SECONDS); - - contextVariables.lastCandleFile = new Date(contextVariables.lastCandleFile.valueOf() - ONE_DAY_IN_MILISECONDS); // Go back one day to start well. - - let customOk = { - result: global.CUSTOM_OK_RESPONSE.result, - message: "Status Report did not exist." - }; - - callBackFunction(customOk); - return; - - } else { - callBackFunction(err); // we cant handle this here. - } - return; - } - default: - { - logger.write("[ERROR] getContextVariables -> getThisProcessReport -> onInitilized -> Operation Failed."); - callBackFunction(err); - return; - } - } - } - catch (err) { - logger.write("[ERROR] getContextVariables -> getThisProcessReport -> onInitilized -> err = " + err.message); - callBackFunction(global.DEFAULT_FAIL_RESPONSE); - } - } - } - catch (err) { - logger.write("[ERROR] getContextVariables -> getThisProcessReport -> err = " + err.message); - callBackFunction(global.DEFAULT_FAIL_RESPONSE); - } - } - } - catch (err) { - logger.write("[ERROR] getContextVariables -> err = " + err.message); - callBackFunction(global.DEFAULT_FAIL_RESPONSE); - } - } }; \ No newline at end of file diff --git a/Multi-Period-Daily/User.bot.js b/Multi-Period-Daily/User.bot.js index 89be15000..c5c57b8c9 100644 --- a/Multi-Period-Daily/User.bot.js +++ b/Multi-Period-Daily/User.bot.js @@ -1,4 +1,4 @@ -exports.newUserBot = function newUserBot(BOT, COMMONS, UTILITIES, DEBUG_MODULE, FILE_STORAGE, STATUS_REPORT) { +exports.newUserBot = function newUserBot(BOT, COMMONS, UTILITIES, DEBUG_MODULE, FILE_STORAGE) { const FULL_LOG = true; const LOG_FILE_CONTENT = false; @@ -32,33 +32,25 @@ start: start }; - let charlyFileStorage = FILE_STORAGE.newFileStorage(bot); - let bruceFileStorage = FILE_STORAGE.newFileStorage(bot); let oliviaFileStorage = FILE_STORAGE.newFileStorage(bot); let utilities = UTILITIES.newUtilities(bot); - let statusReportModule = STATUS_REPORT.newStatusReport(BOT, DEBUG_MODULE, FILE_STORAGE, UTILITIES); + let dependencies; return thisObject; - function initialize(yearAssigend, monthAssigned, callBackFunction) { + function initialize(pDependencies, callBackFunction) { try { - /* IMPORTANT NOTE: - - We are ignoring in this UserBot the received Year and Month. thisObject is not depending on Year Month since it procecess the whole market at once. - - */ - logger.fileName = MODULE_NAME; if (FULL_LOG === true) { logger.write("[INFO] initialize -> Entering function."); } - if (FULL_LOG === true) { logger.write("[INFO] initialize -> yearAssigend = " + yearAssigend); } - if (FULL_LOG === true) { logger.write("[INFO] initialize -> monthAssigned = " + monthAssigned); } - commons.initializeStorage(charlyFileStorage, bruceFileStorage, oliviaFileStorage, onInizialized); + dependencies = pDependencies; + + commons.initializeStorage(oliviaFileStorage, onInizialized); function onInizialized(err) { @@ -98,51 +90,73 @@ Read the candles and volumes from Bruce and produce a file for each day and for /* Context Variables */ contextVariables = { - lastCandleFile: undefined, // Datetime of the last file included on the Index Files. + lastCandleFile: undefined, // Datetime of the last file files sucessfully produced by this process. firstTradeFile: undefined, // Datetime of the first trade file in the whole market history. - maxCandleFile: undefined // Datetime of the last file available to be included in the Index File. + maxCandleFile: undefined // Datetime of the last file available to be used as an input of this process. }; - commons.getContextVariables(charlyFileStorage, bruceFileStorage, oliviaFileStorage, contextVariables, statusReportModule, onVariablesReady); + getContextVariables(); - function onVariablesReady(err) { + function getContextVariables() { try { - if (FULL_LOG === true) { logger.write("[INFO] start -> onVariablesReady -> Entering function."); } + if (FULL_LOG === true) { logger.write("[INFO] start -> getContextVariables -> Entering function."); } - if (err.result === global.CUSTOM_OK_RESPONSE.result) { + let thisReport; + let reportKey; - switch (err.message) { - case 'Status Report did exist.': { - logger.write("[INFO] start -> onVariablesReady -> Status Report did exist."); + reportKey = "AAMasters" + "-" + "AACharly" + "-" + "Poloniex-Historic-Trades" + "-" + "dataSet.V1"; + thisReport = dependencies.statusReports.get(reportKey).file; - buildCandles(); - return; - } - case 'Status Report did not exist.': { - logger.write("[ERROR] start -> onVariablesReady -> Status Report did not exist."); + if (thisReport.lastFile === undefined) { + logger.write("[ERROR] start -> getContextVariables -> Undefined Last File. -> reportKey = " + reportKey); + callBackFunction(global.DEFAULT_FAIL_RESPONSE); + return; + } - buildCandles(); - return; - } - default: - { - logger.write("[ERROR] start -> onVariablesReady -> Operation Failed."); - callBackFunction(err); - return; - } - } + contextVariables.firstTradeFile = new Date(thisReport.lastFile.year + "-" + thisReport.lastFile.month + "-" + thisReport.lastFile.days + " " + thisReport.lastFile.hours + ":" + thisReport.lastFile.minutes + GMT_SECONDS); + + reportKey = "AAMasters" + "-" + "AABruce" + "-" + "One-Min-Daily-Candles-Volumes" + "-" + "dataSet.V1"; + thisReport = dependencies.statusReports.get(reportKey).file; + + if (thisReport.lastFile === undefined) { + logger.write("[ERROR] start -> getContextVariables -> Undefined Last File. -> reportKey = " + reportKey); + callBackFunction(global.DEFAULT_FAIL_RESPONSE); + return; + } + + contextVariables.maxCandleFile = new Date(thisReport.lastFile.year + "-" + thisReport.lastFile.month + "-" + thisReport.lastFile.days + " " + thisReport.lastFile.hours + ":" + thisReport.lastFile.minutes + GMT_SECONDS); + + reportKey = "AAMasters" + "-" + "AAOlivia" + "-" + "Multi-Period-Daily" + "-" + "dataSet.V1"; + thisReport = dependencies.statusReports.get(reportKey).file; + + if (thisReport.lastFile === undefined) { + + contextVariables.lastCandleFile = new Date(thisReport.lastFile); + + /* + Here we assume that the last day written might contain incomplete information. This actually happens every time the head of the market is reached. + For that reason we go back one day, the partial information is discarded and added again with whatever new info is available. + */ + + contextVariables.lastCandleFile = new Date(contextVariables.lastCandleFile.valueOf() - ONE_DAY_IN_MILISECONDS); + + buildCandles(); + return; } else { - logger.write("[ERROR] start -> onVariablesReady -> Operation Failed."); - callBackFunction(err); + + contextVariables.lastCandleFile = new Date(contextVariables.firstTradeFile.getUTCFullYear() + "-" + (contextVariables.firstTradeFile.getUTCMonth() + 1) + "-" + contextVariables.firstTradeFile.getUTCDate() + " " + "00:00" + GMT_SECONDS); + contextVariables.lastCandleFile = new Date(contextVariables.lastCandleFile.valueOf() - ONE_DAY_IN_MILISECONDS); // Go back one day to start well. + + buildCandles(); return; } } catch (err) { - logger.write("[ERROR] start -> onVariablesReady -> err = " + err.message); - callBack(global.DEFAULT_FAIL_RESPONSE); + logger.write("[ERROR] start -> getContextVariables -> err = " + err.message); + callBackFunction(global.DEFAULT_FAIL_RESPONSE); } } @@ -604,9 +618,12 @@ Read the candles and volumes from Bruce and produce a file for each day and for try { - statusReportModule.file.lastExecution = global.processDatetime; - statusReportModule.file.lastFile = lastFileDate; - statusReportModule.save(callBack); + let reportKey = "AAMasters" + "-" + "AAOlivia" + "-" + "Multi-Period-Daily" + "-" + "dataSet.V1"; + let thisReport = dependencies.statusReports.get(key); + + thisReport.file.lastExecution = global.processDatetime; + thisReport.file.lastFile = lastFileDate; + thisReport.save(callBack); } catch (err) { diff --git a/Multi-Period-Market/User.bot.js b/Multi-Period-Market/User.bot.js index 74d1e4926..8bb40210b 100644 --- a/Multi-Period-Market/User.bot.js +++ b/Multi-Period-Market/User.bot.js @@ -1,4 +1,4 @@ -exports.newUserBot = function newUserBot(BOT, COMMONS, UTILITIES, DEBUG_MODULE, FILE_STORAGE, STATUS_REPORT) { +exports.newUserBot = function newUserBot(BOT, COMMONS, UTILITIES, DEBUG_MODULE, FILE_STORAGE) { const FULL_LOG = true; const LOG_FILE_CONTENT = false; @@ -32,33 +32,25 @@ start: start }; - let charlyFileStorage = FILE_STORAGE.newFileStorage(bot); - let bruceFileStorage = FILE_STORAGE.newFileStorage(bot); let oliviaFileStorage = FILE_STORAGE.newFileStorage(bot); let utilities = UTILITIES.newUtilities(bot); - let statusReportModule = STATUS_REPORT.newStatusReport(BOT, DEBUG_MODULE, FILE_STORAGE, UTILITIES); + let dependencies; return thisObject; - function initialize(yearAssigend, monthAssigned, callBackFunction) { + function initialize(pDependencies, callBackFunction) { try { - /* IMPORTANT NOTE: - - We are ignoring in this UserBot the received Year and Month. thisObject is not depending on Year Month since it procecess the whole market at once. - - */ - logger.fileName = MODULE_NAME; if (FULL_LOG === true) { logger.write("[INFO] initialize -> Entering function."); } - if (FULL_LOG === true) { logger.write("[INFO] initialize -> yearAssigend = " + yearAssigend); } - if (FULL_LOG === true) { logger.write("[INFO] initialize -> monthAssigned = " + monthAssigned); } - commons.initializeStorage(charlyFileStorage, bruceFileStorage, oliviaFileStorage, onInizialized); + dependencies = pDependencies; + + commons.initializeStorage(oliviaFileStorage, onInizialized); function onInizialized(err) { @@ -98,51 +90,73 @@ Read the candles and volumes from Bruce and produce a single Index File for Mark /* Context Variables */ contextVariables = { - lastCandleFile: undefined, // Datetime of the last file included on the Index Files. + lastCandleFile: undefined, // Datetime of the last file files sucessfully produced by this process. firstTradeFile: undefined, // Datetime of the first trade file in the whole market history. - maxCandleFile: undefined // Datetime of the last file available to be included in the Index File. + maxCandleFile: undefined // Datetime of the last file available to be used as an input of this process. }; - commons.getContextVariables(charlyFileStorage, bruceFileStorage, oliviaFileStorage, contextVariables, statusReportModule, onVariablesReady); + getContextVariables(); - function onVariablesReady(err) { + function getContextVariables() { try { - if (FULL_LOG === true) { logger.write("[INFO] start -> onVariablesReady -> Entering function."); } + if (FULL_LOG === true) { logger.write("[INFO] start -> getContextVariables -> Entering function."); } - if (err.result === global.CUSTOM_OK_RESPONSE.result) { + let thisReport; + let reportKey; - switch (err.message) { - case 'Status Report did exist.': { - logger.write("[INFO] start -> onVariablesReady -> Status Report did exist."); + reportKey = "AAMasters" + "-" + "AACharly" + "-" + "Poloniex-Historic-Trades" + "-" + "dataSet.V1"; + thisReport = dependencies.statusReports.get(reportKey).file; - findPreviousContent(); - return; - } - case 'Status Report did not exist.': { - logger.write("[ERROR] start -> onVariablesReady -> Status Report did not exist."); + if (thisReport.lastFile === undefined) { + logger.write("[ERROR] start -> getContextVariables -> Undefined Last File. -> reportKey = " + reportKey); + callBackFunction(global.DEFAULT_FAIL_RESPONSE); + return; + } - buildCandles(); - return; - } - default: - { - logger.write("[ERROR] start -> onVariablesReady -> Operation Failed."); - callBackFunction(err); - return; - } - } + contextVariables.firstTradeFile = new Date(thisReport.lastFile.year + "-" + thisReport.lastFile.month + "-" + thisReport.lastFile.days + " " + thisReport.lastFile.hours + ":" + thisReport.lastFile.minutes + GMT_SECONDS); + + reportKey = "AAMasters" + "-" + "AABruce" + "-" + "One-Min-Daily-Candles-Volumes" + "-" + "dataSet.V1"; + thisReport = dependencies.statusReports.get(reportKey).file; + + if (thisReport.lastFile === undefined) { + logger.write("[ERROR] start -> getContextVariables -> Undefined Last File. -> reportKey = " + reportKey); + callBackFunction(global.DEFAULT_FAIL_RESPONSE); + return; + } + + contextVariables.maxCandleFile = new Date(thisReport.lastFile.year + "-" + thisReport.lastFile.month + "-" + thisReport.lastFile.days + " " + thisReport.lastFile.hours + ":" + thisReport.lastFile.minutes + GMT_SECONDS); + + reportKey = "AAMasters" + "-" + "AAOlivia" + "-" + "Multi-Period-Daily" + "-" + "dataSet.V1"; + thisReport = dependencies.statusReports.get(reportKey).file; + + if (thisReport.lastFile === undefined) { + + contextVariables.lastCandleFile = new Date(thisReport.lastFile); + + /* + Here we assume that the last day written might contain incomplete information. This actually happens every time the head of the market is reached. + For that reason we go back one day, the partial information is discarded and added again with whatever new info is available. + */ + + contextVariables.lastCandleFile = new Date(contextVariables.lastCandleFile.valueOf() - ONE_DAY_IN_MILISECONDS); + + findPreviousContent(); + return; } else { - logger.write("[ERROR] start -> onVariablesReady -> Operation Failed."); - callBackFunction(err); + + contextVariables.lastCandleFile = new Date(contextVariables.firstTradeFile.getUTCFullYear() + "-" + (contextVariables.firstTradeFile.getUTCMonth() + 1) + "-" + contextVariables.firstTradeFile.getUTCDate() + " " + "00:00" + GMT_SECONDS); + contextVariables.lastCandleFile = new Date(contextVariables.lastCandleFile.valueOf() - ONE_DAY_IN_MILISECONDS); // Go back one day to start well. + + buildCandles(); return; } } catch (err) { - logger.write("[ERROR] start -> onVariablesReady -> err = " + err.message); - callBack(global.DEFAULT_FAIL_RESPONSE); + logger.write("[ERROR] start -> getContextVariables -> err = " + err.message); + callBackFunction(global.DEFAULT_FAIL_RESPONSE); } } @@ -791,9 +805,12 @@ Read the candles and volumes from Bruce and produce a single Index File for Mark try { - statusReportModule.file.lastExecution = global.processDatetime; - statusReportModule.file.lastFile = lastFileDate; - statusReportModule.save(callBack); + let reportKey = "AAMasters" + "-" + "AAOlivia" + "-" + "Multi-Period-Market" + "-" + "dataSet.V1"; + let thisReport = dependencies.statusReports.get(key); + + thisReport.file.lastExecution = global.processDatetime; + thisReport.file.lastFile = lastFileDate; + thisReport.save(callBack); } catch (err) { diff --git a/this.bot.config.json b/this.bot.config.json index ac5dc1c9f..a6876fc47 100644 --- a/this.bot.config.json +++ b/this.bot.config.json @@ -29,7 +29,39 @@ } }, "executionWaitTime": 3600000, - "retryWaitTime": 10000 + "retryWaitTime": 10000, + "dependencies": [ + { + "devTeam": "AAMasters", + "bot": "AACharly", + "botVersion": { + "major": 1, + "minor": 0 + }, + "process": "Poloniex-Historic-Trades", + "dataSetVersion": "dataSet.V1" + }, + { + "devTeam": "AAMasters", + "bot": "AABruce", + "botVersion": { + "major": 1, + "minor": 0 + }, + "process": "One-Min-Daily-Candles-Volumes", + "dataSetVersion": "dataSet.V1" + }, + { + "devTeam": "AAMasters", + "bot": "AAOlivia", + "botVersion": { + "major": 1, + "minor": 0 + }, + "process": "Multi-Period-Market", + "dataSetVersion": "dataSet.V1" + } + ] }, { "name": "Multi-Period-Daily", @@ -50,7 +82,39 @@ } }, "executionWaitTime": 60000, - "retryWaitTime": 10000 + "retryWaitTime": 10000, + "dependencies": [ + { + "devTeam": "AAMasters", + "bot": "AACharly", + "botVersion": { + "major": 1, + "minor": 0 + }, + "process": "Poloniex-Historic-Trades", + "dataSetVersion": "dataSet.V1" + }, + { + "devTeam": "AAMasters", + "bot": "AABruce", + "botVersion": { + "major": 1, + "minor": 0 + }, + "process": "One-Min-Daily-Candles-Volumes", + "dataSetVersion": "dataSet.V1" + }, + { + "devTeam": "AAMasters", + "bot": "AAOlivia", + "botVersion": { + "major": 1, + "minor": 0 + }, + "process": "Multi-Period-Daily", + "dataSetVersion": "dataSet.V1" + } + ] } ], "products": [