From 6ef1ba19d92687a35c848ccaba6a6f7a6f9eb954 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Thu, 15 Mar 2018 23:35:30 +0100 Subject: [PATCH] Olivia Fully Ported to Alpha --- .vs/AAOlivia-Indicator-Bot/v15/.suo | Bin 28672 -> 26112 bytes Commons.js | 200 +++++---- Multi-Period-Daily/User.bot.js | 654 ++++++++++++---------------- Multi-Period-Market/User.bot.js | 19 +- 4 files changed, 387 insertions(+), 486 deletions(-) diff --git a/.vs/AAOlivia-Indicator-Bot/v15/.suo b/.vs/AAOlivia-Indicator-Bot/v15/.suo index aa9d419a521521a31b39d75774e946e5d3c8baf4..85e07aac9a01c4a12ed9be04ff8f9dd0820d816d 100644 GIT binary patch delta 2214 zcmds&Yiv|i5XbMi-IlxUw!2HWw)8=_mBLa=*_PGJ!gTFOq1;e>GoFy<`n zk+~zvp2r6m?NaE3)#f)GEQu_zLaqd>KrUDf@<9P$hif4V!8+gu#enVWAxl6hcnFk% z4Ip#wwo24(J%t_T-o$N_@p|q_ z?B^#t0Hqfk1c$(3U^pFsJ_uA2@fq~9)kc3M91&d3%ajqD)*nUi=>1J)6HdXtGAUV@(;`kfi z<2WH!#nDh^t-|r<@bW%1y}ZT5iKkE0tdUEODq)uR$@!_+s;McL|3^W#G@Cf5=7LOt z#G@fswZdu4B{vrZ*9`^f5YC%7toA8f&782jB9=p=&>ef7iEF@!v8FC<5hku)US#${ zxd9}au|6eQDUkayRoP3$EInpiF6Z@@j=yaOm&uoH9Z|myK-sm-QoY zx#(w{&cC5>t;I(S7Jh6_avq@#lmC`D$27UXESpL;u6JwJ!drqb&mGOUyrypPi3OLn z=$F;~O468Hp(~}yT5?6Ku)EQPqJNUM`r$8S^C|?B`-@Cw&sFgOC3uD@(VrOC;2${9 zqtel?68g|HIJQZqoa%LS+G8h=_ZQo{6)yxj#$SH!kJqeyX-&yz$XBz1jys(+?nxCg zjaH7++a9a-e3ePqxhWc>5=sMo@6VwNm3tQM<3X8S?`lk*+qiSvV9!9|?!#)~{z2Vt z9BA0zwDAa+qCWB_UV_f;iQ62PV`N0B5zF6LNE6jT%^v?Nni1}?c{r9Ek3`RIE?1-- zpYZEQID1fVtbudTk=-Sf8}06v5|Yyee*8f zb4^dkZd=L9%J8X-neq@hj#|IIP(i*;nRK(nA>Jd=c8YxMxxSjS-*#qwH2M1H&fm}e lcFoImIsYDS;G(Z!uXh3q->Fin#NUt~9bc6eZDDJ_@DJyrduRXv delta 2096 zcmd6nT})e59Kd^S?;W?$@4~1p(1O4!j(Qm%^5tluY(RmQ(J`3lXg5rl1jyQI;K9|0 z`QXR`_rC`dGaq>HMNP==vIpY>8TG}F2~i)6iD8K$nwS_9rlJD=|NU?%#w9)&Px8Cx zfBxs3d(QvsBtBw^4YnW^tFq0gQstt|A-j8fd!%N{J>J0<$F9pTHW7sz!wMZROk35MKA&p2AQiBn* zGvQ?vcNNzDE0eV`HUM#L0Fs==eNgq%T!krCu9@-#ArJcB%ooI~g@VeBKwdE`Pyhk+P`Z}N=7WmF_!r}#zYSK=qs zjBUcK!%tTe=5Q(r+jhT5;iGh*D=M*~5aY>9G!oiTSW~twJxs&MWt1K1Wd*nXDUbZuBcjV=I$OV$2Wm zlDn|V)d-_F_wNGZ=wWJnL7=(C4Y7iG+2#}JO`!r!+iP1BsYodO(+YbKl4?nydx@}J z`k_cgPQ{&?-YQ!Y{}kt~J}oD^^7!_~juVRE)DOav#LMNY5B0NQeyN$eS!ZSNTD?p0 z)UR;4Q7i*`d6){;BOk!)P2(`#ct*`sJ{-RTp4RV7*QPewtis2g&dOib)mQG`R#81e z@F__-dECOPDM_=9-X1DMN&u=aYSB@zH!wNz!bG^bdkPZXgzUR4P?f6Sh}T*47D<_Q z341@{OEO=x)GWcu1&^t<_^02l{3w3@<(RzuZLmA`X8-lQ_K*X_UKM@Ku{t@pP>)&^NomQEP)YI`uF#d{OSaW73~#INSf~n~m=W zciy$FZgywQv_bw8N5LcI;)Y5n8d)o!b`QkElM}Jo(Dd|V)E%0biMkJ%zvh+D&ukI~ z>UxwO>9!h7kyiv?cw%xEZba&Id8eb}m)w!*nEPV%92n1g;rlk7IW<4}cT<_IKYIeE z&6G{)4+T6Qo^LD7W))yoQRG40Re?9R=45;ThVCYE!Av)~z{8dr{_nY$=uYg9lQJ}1 G#eN6gx*d@K diff --git a/Commons.js b/Commons.js index 50c2c7df0..e20499057 100644 --- a/Commons.js +++ b/Commons.js @@ -103,156 +103,176 @@ function getHistoricTrades() { - if (FULL_LOG === true) { logger.write("[INFO] getContextVariables -> getHistoricTrades -> Entering function."); } + 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. + 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"; + reportFilePath = EXCHANGE_NAME + "/Processes/" + "Poloniex-Historic-Trades"; - if (FULL_LOG === true) { logger.write("[INFO] getContextVariables -> getHistoricTrades -> reportFilePath = " + reportFilePath); } + if (FULL_LOG === true) { logger.write("[INFO] getContextVariables -> getHistoricTrades -> reportFilePath = " + reportFilePath); } - charlyFileStorage.getTextFile(reportFilePath, fileName, onFileReceived); + charlyFileStorage.getTextFile(reportFilePath, fileName, onFileReceived); - function onFileReceived(err, text) { + 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); } + 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; + let thisReport; - if (err.result === global.DEFAULT_OK_RESPONSE.result) { - try { - thisReport = JSON.parse(text); + 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); + contextVariables.firstTradeFile = new Date(thisReport.lastFile.year + "-" + thisReport.lastFile.month + "-" + thisReport.lastFile.days + " " + thisReport.lastFile.hours + ":" + thisReport.lastFile.minutes + GMT_SECONDS); - getOneMinDailyCandlesVolumes(); + getOneMinDailyCandlesVolumes(); - } catch (err) { + } 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); - logger.write("[ERROR] getContextVariables -> getHistoricTrades -> onFileReceived -> Asuming this is a temporary situation. Requesting a Retry."); - callBackFunction(global.DEFAULT_RETRY_RESPONSE); + callBackFunction(err); } - } 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() { - if (FULL_LOG === true) { logger.write("[INFO] getContextVariables -> getOneMinDailyCandlesVolumes -> Entering function."); } + try { - /* We need to discover the maxCandle file, which is the last file with candles we can use as input. */ + if (FULL_LOG === true) { logger.write("[INFO] getContextVariables -> getOneMinDailyCandlesVolumes -> Entering function."); } - let date = new Date(); - let currentYear = date.getUTCFullYear(); - let currentMonth = utilities.pad(date.getUTCMonth() + 1, 2); + /* We need to discover the maxCandle file, which is the last file with candles we can use as input. */ - reportFilePath = EXCHANGE_NAME + "/Processes/" + "One-Min-Daily-Candles-Volumes" + "/" + currentYear + "/" + currentMonth; + let date = new Date(); + let currentYear = date.getUTCFullYear(); + let currentMonth = utilities.pad(date.getUTCMonth() + 1, 2); - if (FULL_LOG === true) { logger.write("[INFO] getContextVariables -> getOneMinDailyCandlesVolumes -> reportFilePath = " + reportFilePath); } + reportFilePath = EXCHANGE_NAME + "/Processes/" + "One-Min-Daily-Candles-Volumes" + "/" + currentYear + "/" + currentMonth; - bruceFileStorage.getTextFile(reportFilePath, fileName, onFileReceived); + if (FULL_LOG === true) { logger.write("[INFO] getContextVariables -> getOneMinDailyCandlesVolumes -> reportFilePath = " + reportFilePath); } - function onFileReceived(err, text) { + bruceFileStorage.getTextFile(reportFilePath, fileName, onFileReceived); - if (FULL_LOG === true) { logger.write("[INFO] getContextVariables -> getOneMinDailyCandlesVolumes -> onFileReceived -> Entering function."); } - if (FULL_LOG === true) { logger.write("[INFO] getContextVariables -> getOneMinDailyCandlesVolumes -> onFileReceived -> text = " + text); } + function onFileReceived(err, text) { - let thisReport; + if (FULL_LOG === true) { logger.write("[INFO] getContextVariables -> getOneMinDailyCandlesVolumes -> onFileReceived -> Entering function."); } + if (FULL_LOG === true) { logger.write("[INFO] getContextVariables -> getOneMinDailyCandlesVolumes -> onFileReceived -> text = " + text); } - if (err.result === global.DEFAULT_OK_RESPONSE.result) { - try { - thisReport = JSON.parse(text); + let thisReport; - contextVariables.maxCandleFile = new Date(thisReport.lastFile.year + "-" + thisReport.lastFile.month + "-" + thisReport.lastFile.days + " " + "00:00" + GMT_SECONDS); + if (err.result === global.DEFAULT_OK_RESPONSE.result) { + try { + thisReport = JSON.parse(text); - getThisProcessReport(); + contextVariables.maxCandleFile = new Date(thisReport.lastFile.year + "-" + thisReport.lastFile.month + "-" + thisReport.lastFile.days + " " + "00:00" + GMT_SECONDS); - } catch (err) { + 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); - logger.write("[ERROR] getContextVariables -> getOneMinDailyCandlesVolumes -> onFileReceived -> Asuming this is a temporary situation. Requesting a Retry."); - callBackFunction(global.DEFAULT_RETRY_RESPONSE); + callBackFunction(err); } - } else { - logger.write("[ERROR] getContextVariables -> getHistoricTrades -> onFileReceived -> err = " + err.message); - callBackFunction(err); } } + catch (err) { + logger.write("[ERROR] getContextVariables -> getOneMinDailyCandlesVolumes -> err = " + err.message); + callBackFunction(global.DEFAULT_FAIL_RESPONSE); + } } function getThisProcessReport() { - if (FULL_LOG === true) { logger.write("[INFO] getContextVariables -> getThisProcessReport -> Entering function."); } + try { - statusReportModule.initialize(bot, onInitilized); + if (FULL_LOG === true) { logger.write("[INFO] getContextVariables -> getThisProcessReport -> Entering function."); } - function onInitilized(err) { + statusReportModule.initialize(bot, onInitilized); - try { + function onInitilized(err) { - switch (err.result) { - case global.DEFAULT_OK_RESPONSE.result: { - logger.write("[INFO] getContextVariables -> getThisProcessReport -> onInitilized -> Execution finished well. :-)"); + try { - contextVariables.lastCandleFile = new Date(statusReportModule.file.lastFile); + switch (err.result) { + case global.DEFAULT_OK_RESPONSE.result: { + logger.write("[INFO] getContextVariables -> getThisProcessReport -> onInitilized -> Execution finished well. :-)"); - /* - 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(statusReportModule.file.lastFile); - contextVariables.lastCandleFile = new Date(contextVariables.lastCandleFile.valueOf() - ONE_DAY_IN_MILISECONDS); + /* + 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. + */ - let customOk = { - result: global.CUSTOM_OK_RESPONSE.result, - message: "Status Report did exist." - }; - - callBackFunction(customOk); - - return; - } - case global.CUSTOM_FAIL_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. + contextVariables.lastCandleFile = new Date(contextVariables.lastCandleFile.valueOf() - ONE_DAY_IN_MILISECONDS); let customOk = { result: global.CUSTOM_OK_RESPONSE.result, - message: "Status Report did not exist." + message: "Status Report did 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; } + 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 -> onInitilized -> err = " + err.message); - callBackFunction(global.DEFAULT_FAIL_RESPONSE); - } + } + catch (err) { + logger.write("[ERROR] getContextVariables -> getThisProcessReport -> err = " + err.message); + callBackFunction(global.DEFAULT_FAIL_RESPONSE); } } } diff --git a/Multi-Period-Daily/User.bot.js b/Multi-Period-Daily/User.bot.js index 8ac9e0b66..a9c38deab 100644 --- a/Multi-Period-Daily/User.bot.js +++ b/Multi-Period-Daily/User.bot.js @@ -9,7 +9,7 @@ const GMT_MILI_SECONDS = '.000 GMT+0000'; const ONE_DAY_IN_MILISECONDS = 24 * 60 * 60 * 1000; - const MODULE_NAME = "UserBot"; + const MODULE_NAME = "User Bot"; const EXCHANGE_NAME = "Poloniex"; @@ -25,7 +25,7 @@ logger.fileName = MODULE_NAME; logger.bot = bot; - const commons = COMMONS.newCommons(bot, DEBUG_MODULE); + const commons = COMMONS.newCommons(bot, DEBUG_MODULE, UTILITIES); thisObject = { initialize: initialize, @@ -38,8 +38,7 @@ let utilities = UTILITIES.newUtilities(bot); - let statusReport; - let statusReportModule; + let statusReportModule = STATUS_REPORT.newStatusReport(BOT, DEBUG_MODULE, FILE_STORAGE, UTILITIES); return thisObject; @@ -59,58 +58,7 @@ if (FULL_LOG === true) { logger.write("[INFO] initialize -> yearAssigend = " + yearAssigend); } if (FULL_LOG === true) { logger.write("[INFO] initialize -> monthAssigned = " + monthAssigned); } - initializeCharlyStorage(); - - function initializeCharlyStorage() { - - charlyFileStorage.initialize("AACharly", onCharlyInizialized); - - function onCharlyInizialized(err) { - - if (err.result === global.DEFAULT_OK_RESPONSE.result) { - - initializeBruceStorage(); - - } else { - logger.write("[ERROR] initialize -> 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] initialize -> initializeBruceStorage -> onBruceInizialized -> err = " + err.message); - callBackFunction(err); - } - } - } - - function initializeOliviaStorage() { - - oliviaFileStorage.initialize("AAOlivia", onOliviaInizialized); - - function onOliviaInizialized(err) { - - if (err.result === global.DEFAULT_OK_RESPONSE.result) { - - callBackFunction(global.DEFAULT_OK_RESPONSE); - - } else { - logger.write("[ERROR] initialize -> initializeOliviaStorage -> onOliviaInizialized -> err = " + err.message); - callBackFunction(err); - } - } - } + commons.initializeStorage(charlyFileStorage, bruceFileStorage, oliviaFileStorage, callBackFunction); } catch (err) { logger.write("[ERROR] initialize -> err = " + err.message); @@ -134,142 +82,54 @@ Read the candles and volumes from Bruce and produce a file for each day and for let market = global.MARKET; - + /* Context Variables */ - let lastCandleFile; // Datetime of the last file included on the Index File. - let firstTradeFile; // Datetime of the first trade file in the whole market history. - let maxCandleFile; // Datetime of the last file available to be included in the Index File. + contextVariables = { + lastCandleFile: undefined, // Datetime of the last file included on the Index Files. + 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. + }; + commons.getContextVariables(charlyFileStorage, bruceFileStorage, oliviaFileStorage, contextVariables, statusReportModule, onVariablesReady); - - - function getStatusReport() { + function onVariablesReady(err) { try { - let reportFilePath; - let fileName = "Status.Report." + market.assetA + '_' + market.assetB + ".json" + if (FULL_LOG === true) { logger.write("[INFO] start -> onVariablesReady -> Entering function."); } - getHistoricTrades(); + if (err.result === global.CUSTOM_OK_RESPONSE.result) { - function getHistoricTrades() { - - /* - - 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"; - - charlyFileStorage.getTextFile(reportFilePath, fileName, onStatusReportReceived, true); - - function onStatusReportReceived(text) { - - let statusReport; - - try { - - statusReport = JSON.parse(text); - - firstTradeFile = new Date(statusReport.lastFile.year + "-" + statusReport.lastFile.month + "-" + statusReport.lastFile.days + " " + statusReport.lastFile.hours + ":" + statusReport.lastFile.minutes + GMT_SECONDS); - - getOneMinDailyCandlesVolumes(); - - } catch (err) { - - const logText = "[INFO] 'getStatusReport' - Failed to read main Historic Trades Status Report for market " + market.assetA + '_' + market.assetB + " . Skipping it. "; - logger.write(logText); - - closeAndOpenMarket(); - } - } - } - - function getOneMinDailyCandlesVolumes() { - - /* 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; - - bruceFileStorage.getTextFile(reportFilePath, fileName, onStatusReportReceived, true); - - function onStatusReportReceived(text) { - - let statusReport; - - try { - - statusReport = JSON.parse(text); - - maxCandleFile = new Date(statusReport.lastFile.year + "-" + statusReport.lastFile.month + "-" + statusReport.lastFile.days + " " + "00:00" + GMT_SECONDS); - - getThisProcessReport(); - - } catch (err) { - - /* - - It might happen that the file content is corrupt or it does not exist. In either case we will point our lastCandleFile - to the last day of the previous month. - - */ - - maxCandleFile = new Date(date.valueOf() - ONE_DAY_IN_MILISECONDS); - getThisProcessReport(); - - } - } - } - - function getThisProcessReport() { - - /* If the process run and was interrupted, there should be a status report that allows us to resume execution. */ - - reportFilePath = EXCHANGE_NAME + "/Processes/" + bot.process; - - oliviaFileStorage.getTextFile(reportFilePath, fileName, onStatusReportReceived, true); - - function onStatusReportReceived(text) { - - let statusReport; - - try { - - statusReport = JSON.parse(text); - - lastCandleFile = new Date(statusReport.lastFile.year + "-" + statusReport.lastFile.month + "-" + statusReport.lastFile.days + " " + "00:00" + GMT_SECONDS); + switch (err.message) { + case 'Status Report did exist.': { + logger.write("[INFO] start -> onVariablesReady -> Status Report did exist."); buildCandles(); - - } catch (err) { - - /* - - It might happen that the file content is corrupt or it does not exist. In either case we will point our lastCandleFile - to the begining of the market. - - */ - - lastCandleFile = new Date(firstTradeFile.getUTCFullYear() + "-" + (firstTradeFile.getUTCMonth() + 1) + "-" + firstTradeFile.getUTCDate() + " " + "00:00" + GMT_SECONDS); - - lastCandleFile = new Date(lastCandleFile.valueOf() - ONE_DAY_IN_MILISECONDS); // Go back one day to start well. + return; + } + case 'Status Report did not exist.': { + logger.write("[ERROR] start -> onVariablesReady -> Status Report did not exist."); buildCandles(); - + return; } + default: + { + logger.write("[ERROR] start -> onVariablesReady -> Operation Failed."); + callBackFunction(err); + return; + } } + + } else { + logger.write("[ERROR] start -> onVariablesReady -> Operation Failed."); + callBackFunction(err); + return; } - } - catch (err) { - const logText = "[ERROR] 'getStatusReport' - ERROR : " + err.message; - logger.write(logText); - closeMarket(); + } catch (err) { + logger.write("[ERROR] start -> onVariablesReady -> err = " + err.message); + callBack(global.DEFAULT_FAIL_RESPONSE); } } @@ -277,6 +137,8 @@ Read the candles and volumes from Bruce and produce a file for each day and for try { + if (FULL_LOG === true) { logger.write("[INFO] start -> buildCandles -> Entering function."); } + let outputCandles; let outputVolumes; @@ -284,25 +146,20 @@ Read the candles and volumes from Bruce and produce a file for each day and for function advanceTime() { - lastCandleFile = new Date(lastCandleFile.valueOf() + ONE_DAY_IN_MILISECONDS); + if (FULL_LOG === true) { logger.write("[INFO] start -> buildCandles -> advanceTime -> Entering function."); } - const logText = "[INFO] New processing time @ " + lastCandleFile.getUTCFullYear() + "/" + (lastCandleFile.getUTCMonth() + 1) + "/" + lastCandleFile.getUTCDate() + "."; - console.log(logText); - logger.write(logText); + contextVariables.lastCandleFile = new Date(contextVariables.lastCandleFile.valueOf() + ONE_DAY_IN_MILISECONDS); + + if (FULL_LOG === true) { logger.write("[INFO] start -> buildCandles -> advanceTime -> New processing time @ " + contextVariables.lastCandleFile.getUTCFullYear() + "/" + (contextVariables.lastCandleFile.getUTCMonth() + 1) + "/" + contextVariables.lastCandleFile.getUTCDate() + "."); } /* Validation that we are not going past the head of the market. */ - if (lastCandleFile.valueOf() > maxCandleFile.valueOf()) { + if (contextVariables.lastCandleFile.valueOf() > contextVariables.maxCandleFile.valueOf()) { - nextIntervalExecution = true; // we request a new thisObject execution. - - const logText = "[INFO] 'buildCandles' - Head of the market found @ " + lastCandleFile.getUTCFullYear() + "/" + (lastCandleFile.getUTCMonth() + 1) + "/" + lastCandleFile.getUTCDate() + "."; - logger.write(logText); - - closeAndOpenMarket(); + if (FULL_LOG === true) { logger.write("[INFO] start -> buildCandles -> advanceTime -> Head of the market found @ " + contextVariables.lastCandleFile.getUTCFullYear() + "/" + (contextVariables.lastCandleFile.getUTCMonth() + 1) + "/" + contextVariables.lastCandleFile.getUTCDate() + "."); } + callBackFunction(global.DEFAULT_OK_RESPONSE); // Here is where we finish processing and wait for the platform to run this module again. return; - } /* @@ -314,7 +171,7 @@ Read the candles and volumes from Bruce and produce a file for each day and for outputCandles = []; outputVolumes = []; - for (n = 0; n < outputPeriods.length; n++) { + for (n = 0; n < global.marketFilesPeriods.length; n++) { const emptyArray1 = []; const emptyArray2 = []; @@ -342,191 +199,218 @@ Read the candles and volumes from Bruce and produce a file for each day and for function loopBody() { - const outputPeriod = outputPeriods[n][0]; - const folderName = outputPeriods[n][1]; + if (FULL_LOG === true) { logger.write("[INFO] start -> buildCandles -> periodsLoop -> loopBody -> Entering function."); } + + const outputPeriod = global.marketFilesPeriods[n][0]; + const folderName = global.marketFilesPeriods[n][1]; nextCandleFile(); function nextCandleFile() { - let dateForPath = lastCandleFile.getUTCFullYear() + '/' + utilities.pad(lastCandleFile.getUTCMonth() + 1, 2) + '/' + utilities.pad(lastCandleFile.getUTCDate(), 2); + if (FULL_LOG === true) { logger.write("[INFO] start -> buildCandles -> periodsLoop -> loopBody -> nextCandleFile -> Entering function."); } + + let dateForPath = contextVariables.lastCandleFile.getUTCFullYear() + '/' + utilities.pad(contextVariables.lastCandleFile.getUTCMonth() + 1, 2) + '/' + utilities.pad(contextVariables.lastCandleFile.getUTCDate(), 2); let fileName = market.assetA + '_' + market.assetB + ".json" let filePath = EXCHANGE_NAME + "/Output/" + CANDLES_FOLDER_NAME + '/' + CANDLES_ONE_MIN + '/' + dateForPath; + if (FULL_LOG === true) { logger.write("[INFO] start -> buildCandles -> periodsLoop -> loopBody -> nextCandleFile -> fileName = " + fileName); } + if (FULL_LOG === true) { logger.write("[INFO] start -> buildCandles -> periodsLoop -> loopBody -> nextCandleFile -> filePath = " + filePath); } + bruceFileStorage.getTextFile(filePath, fileName, onFileReceived, true); - function onFileReceived(text) { - - let candlesFile; + function onFileReceived(err, text) { try { - candlesFile = JSON.parse(text); + if (FULL_LOG === true) { logger.write("[INFO] start -> buildCandles -> periodsLoop -> loopBody -> nextCandleFile -> onFileReceived -> Entering function."); } + if (LOG_FILE_CONTENT === true) { logger.write("[INFO] start -> buildCandles -> periodsLoop -> loopBody -> nextCandleFile -> onFileReceived -> text = " + text); } - } catch (err) { + let candlesFile; - const logText = "[ERR] 'buildCandles' - Empty or corrupt candle file found at " + filePath + " for market " + market.assetA + '_' + market.assetB + " . Skipping this Market. "; - logger.write(logText); + if (err.result === global.DEFAULT_OK_RESPONSE.result) { + try { + candlesFile = JSON.parse(text); - closeAndOpenMarket(); + } catch (err) { + logger.write("[ERROR] start -> buildCandles -> periodsLoop -> loopBody -> nextCandleFile -> onFileReceived -> Error Parsing JSON -> err = " + err.message); + logger.write("[ERROR] start -> buildCandles -> periodsLoop -> loopBody -> nextCandleFile -> onFileReceived -> Asuming this is a temporary situation. Requesting a Retry."); + callBackFunction(global.DEFAULT_RETRY_RESPONSE); + return; + } + } else { + logger.write("[ERROR] start -> buildCandles -> periodsLoop -> loopBody -> nextCandleFile -> onFileReceived -> Error Received -> err = " + err.message); + callBackFunction(err); + return; + } - nextIntervalExecution = true; // we request a new thisObject execution. - nextIntervalLapse = 30000; + const inputCandlesPerdiod = 60 * 1000; // 1 min + const inputFilePeriod = 24 * 60 * 60 * 1000; // 24 hs - return; - } + let totalOutputCandles = inputFilePeriod / outputPeriod; + let beginingOutputTime = contextVariables.lastCandleFile.valueOf(); - const inputCandlesPerdiod = 60 * 1000; // 1 min - const inputFilePeriod = 24 * 60 * 60 * 1000; // 24 hs + for (let i = 0; i < totalOutputCandles; i++) { - let totalOutputCandles = inputFilePeriod / outputPeriod; - let beginingOutputTime = lastCandleFile.valueOf(); - - for (let i = 0; i < totalOutputCandles; i++) { - - let outputCandle = { - open: 0, - close: 0, - min: 0, - max: 0, - begin: 0, - end: 0 - }; - - let saveCandle = false; - - outputCandle.begin = beginingOutputTime + i * outputPeriod; - outputCandle.end = beginingOutputTime + (i + 1) * outputPeriod - 1; - - for (let j = 0; j < candlesFile.length; j++) { - - let candle = { - open: candlesFile[j][2], - close: candlesFile[j][3], - min: candlesFile[j][0], - max: candlesFile[j][1], - begin: candlesFile[j][4], - end: candlesFile[j][5] + let outputCandle = { + open: 0, + close: 0, + min: 0, + max: 0, + begin: 0, + end: 0 }; - /* Here we discard all the candles out of range. */ + let saveCandle = false; - if (candle.begin >= outputCandle.begin && candle.end <= outputCandle.end) { + outputCandle.begin = beginingOutputTime + i * outputPeriod; + outputCandle.end = beginingOutputTime + (i + 1) * outputPeriod - 1; - if (saveCandle === false) { // this will set the value only once. + for (let j = 0; j < candlesFile.length; j++) { - outputCandle.open = candle.open; - outputCandle.min = candle.min; - outputCandle.max = candle.max; + let candle = { + open: candlesFile[j][2], + close: candlesFile[j][3], + min: candlesFile[j][0], + max: candlesFile[j][1], + begin: candlesFile[j][4], + end: candlesFile[j][5] + }; + /* Here we discard all the candles out of range. */ + + if (candle.begin >= outputCandle.begin && candle.end <= outputCandle.end) { + + if (saveCandle === false) { // this will set the value only once. + + outputCandle.open = candle.open; + outputCandle.min = candle.min; + outputCandle.max = candle.max; + } + + saveCandle = true; + + outputCandle.close = candle.close; // only the last one will be saved + + if (candle.min < outputCandle.min) { + + outputCandle.min = candle.min; + } + + if (candle.max > outputCandle.max) { + + outputCandle.max = candle.max; + } } + } - saveCandle = true; + if (saveCandle === true) { // then we have a valid candle, otherwise it means there were no candles to fill this one in its time range. - outputCandle.close = candle.close; // only the last one will be saved - - if (candle.min < outputCandle.min) { - - outputCandle.min = candle.min; - - } - - if (candle.max > outputCandle.max) { - - outputCandle.max = candle.max; - - } + outputCandles[n].push(outputCandle); } } - if (saveCandle === true) { // then we have a valid candle, otherwise it means there were no candles to fill this one in its time range. + nextVolumeFile(); - outputCandles[n].push(outputCandle); - - } + } catch (err) { + logger.write("[ERROR] start -> buildCandles -> periodsLoop -> loopBody -> nextCandleFile -> onFileReceived -> err = " + err.message); + callBackFunction(global.DEFAULT_FAIL_RESPONSE); } - - nextVolumeFile(); - } } function nextVolumeFile() { - let dateForPath = lastCandleFile.getUTCFullYear() + '/' + utilities.pad(lastCandleFile.getUTCMonth() + 1, 2) + '/' + utilities.pad(lastCandleFile.getUTCDate(), 2); - let fileName = market.assetA + '_' + market.assetB + ".json" - let filePath = EXCHANGE_NAME + "/Output/" + VOLUMES_FOLDER_NAME + '/' + VOLUMES_ONE_MIN + '/' + dateForPath; + try { - bruceFileStorage.getTextFile(filePath, fileName, onFileReceived, true); + if (FULL_LOG === true) { logger.write("[INFO] start -> buildCandles -> periodsLoop -> loopBody -> nextVolumeFile -> Entering function."); } - function onFileReceived(text) { + let dateForPath = contextVariables.lastCandleFile.getUTCFullYear() + '/' + utilities.pad(contextVariables.lastCandleFile.getUTCMonth() + 1, 2) + '/' + utilities.pad(contextVariables.lastCandleFile.getUTCDate(), 2); + let fileName = market.assetA + '_' + market.assetB + ".json" + let filePath = EXCHANGE_NAME + "/Output/" + VOLUMES_FOLDER_NAME + '/' + VOLUMES_ONE_MIN + '/' + dateForPath; - let volumesFile; + if (FULL_LOG === true) { logger.write("[INFO] start -> buildCandles -> periodsLoop -> loopBody -> nextVolumeFile -> fileName = " + fileName); } + if (FULL_LOG === true) { logger.write("[INFO] start -> buildCandles -> periodsLoop -> loopBody -> nextVolumeFile -> filePath = " + filePath); } - try { + bruceFileStorage.getTextFile(filePath, fileName, onFileReceived, true); - volumesFile = JSON.parse(text); + function onFileReceived(err, text) { - } catch (err) { + if (FULL_LOG === true) { logger.write("[INFO] start -> buildCandles -> periodsLoop -> loopBody -> nextVolumeFile -> onFileReceived -> Entering function."); } + if (LOG_FILE_CONTENT === true) { logger.write("[INFO] start -> buildCandles -> periodsLoop -> loopBody -> nextVolumeFile -> onFileReceived -> text = " + text); } - const logText = "[ERR] 'buildCandles' - Empty or corrupt candle file found at " + filePath + " for market " + market.assetA + '_' + market.assetB + " . Skipping this Market. "; - logger.write(logText); + let volumesFile; - closeAndOpenMarket(); + if (err.result === global.DEFAULT_OK_RESPONSE.result) { + try { + volumesFile = JSON.parse(text); - return; - } + } catch (err) { + logger.write("[ERROR] start -> buildCandles -> periodsLoop -> loopBody -> nextVolumeFile -> onFileReceived -> Error Parsing JSON -> err = " + err.message); + logger.write("[ERROR] start -> buildCandles -> periodsLoop -> loopBody -> nextVolumeFile -> onFileReceived -> Asuming this is a temporary situation. Requesting a Retry."); + callBackFunction(global.DEFAULT_RETRY_RESPONSE); + return; + } + } else { + logger.write("[ERROR] start -> buildCandles -> periodsLoop -> loopBody -> nextVolumeFile -> onFileReceived -> Error Received -> err = " + err.message); + callBackFunction(err); + return; + } - const inputVolumesPerdiod = 60 * 1000; // 1 min - const inputFilePeriod = 24 * 60 * 60 * 1000; // 24 hs + const inputVolumesPerdiod = 60 * 1000; // 1 min + const inputFilePeriod = 24 * 60 * 60 * 1000; // 24 hs - let totalOutputVolumes = inputFilePeriod / outputPeriod; // this should be 2 in this case. - let beginingOutputTime = lastCandleFile.valueOf(); + let totalOutputVolumes = inputFilePeriod / outputPeriod; // this should be 2 in this case. + let beginingOutputTime = contextVariables.lastCandleFile.valueOf(); - for (let i = 0; i < totalOutputVolumes; i++) { + for (let i = 0; i < totalOutputVolumes; i++) { - let outputVolume = { - buy: 0, - sell: 0, - begin: 0, - end: 0 - }; - - let saveVolume = false; - - outputVolume.begin = beginingOutputTime + i * outputPeriod; - outputVolume.end = beginingOutputTime + (i + 1) * outputPeriod - 1; - - for (let j = 0; j < volumesFile.length; j++) { - - let volume = { - buy: volumesFile[j][0], - sell: volumesFile[j][1], - begin: volumesFile[j][2], - end: volumesFile[j][3] + let outputVolume = { + buy: 0, + sell: 0, + begin: 0, + end: 0 }; - /* Here we discard all the Volumes out of range. */ + let saveVolume = false; - if (volume.begin >= outputVolume.begin && volume.end <= outputVolume.end) { + outputVolume.begin = beginingOutputTime + i * outputPeriod; + outputVolume.end = beginingOutputTime + (i + 1) * outputPeriod - 1; - saveVolume = true; + for (let j = 0; j < volumesFile.length; j++) { - outputVolume.buy = outputVolume.buy + volume.buy; - outputVolume.sell = outputVolume.sell + volume.sell; + let volume = { + buy: volumesFile[j][0], + sell: volumesFile[j][1], + begin: volumesFile[j][2], + end: volumesFile[j][3] + }; + + /* Here we discard all the Volumes out of range. */ + + if (volume.begin >= outputVolume.begin && volume.end <= outputVolume.end) { + + saveVolume = true; + + outputVolume.buy = outputVolume.buy + volume.buy; + outputVolume.sell = outputVolume.sell + volume.sell; + + } + } + + if (saveVolume === true) { + + outputVolumes[n].push(outputVolume); } } - if (saveVolume === true) { + writeFiles(outputCandles[n], outputVolumes[n], folderName, controlLoop); - outputVolumes[n].push(outputVolume); - - } } - - writeFiles(outputCandles[n], outputVolumes[n], folderName, controlLoop); - + } catch (err) { + logger.write("[ERROR] start -> buildCandles -> periodsLoop -> loopBody -> nextVolumeFile -> onFileReceived -> err = " + err.message); + callBackFunction(global.DEFAULT_FAIL_RESPONSE); } } } @@ -535,29 +419,27 @@ Read the candles and volumes from Bruce and produce a file for each day and for n++; - if (n < outputPeriods.length) { + if (n < global.marketFilesPeriods.length) { loopBody(); } else { - writeStatusReport(lastCandleFile, advanceTime); - + writeStatusReport(contextVariables.lastCandleFile, advanceTime); } } } } - catch (err) { - const logText = "[ERROR] 'buildCandles' - ERROR : " + err.message; - logger.write(logText); - closeMarket(); + logger.write("[ERROR] start -> buildCandles -> err = " + err.message); + callBackFunction(global.DEFAULT_FAIL_RESPONSE); } - } function writeFiles(candles, volumes, folderName, callBack) { + if (FULL_LOG === true) { logger.write("[INFO] start -> writeFiles -> Entering function."); } + /* Here we will write the contents of the Candles and Volumens files. @@ -570,9 +452,10 @@ Read the candles and volumes from Bruce and produce a file for each day and for function writeCandles() { + if (FULL_LOG === true) { logger.write("[INFO] start -> writeFiles -> writeCandles -> Entering function."); } + let separator = ""; let fileRecordCounter = 0; - let fileContent = ""; for (i = 0; i < candles.length; i++) { @@ -590,34 +473,53 @@ Read the candles and volumes from Bruce and produce a file for each day and for fileContent = "[" + fileContent + "]"; let fileName = '' + market.assetA + '_' + market.assetB + '.json'; + let dateForPath = contextVariables.lastCandleFile.getUTCFullYear() + '/' + utilities.pad(contextVariables.lastCandleFile.getUTCMonth() + 1, 2) + '/' + utilities.pad(contextVariables.lastCandleFile.getUTCDate(), 2); + let filePath = global.FILE_PATH_ROOT + "/Output/" + CANDLES_FOLDER_NAME + "/" + bot.process + "/" + folderName + "/" + dateForPath; - let dateForPath = lastCandleFile.getUTCFullYear() + '/' + utilities.pad(lastCandleFile.getUTCMonth() + 1, 2) + '/' + utilities.pad(lastCandleFile.getUTCDate(), 2); - - let filePath = EXCHANGE_NAME + "/Output/" + CANDLES_FOLDER_NAME + "/" + bot.process + "/" + folderName + "/" + dateForPath; + if (FULL_LOG === true) { logger.write("[INFO] start -> writeFiles -> writeCandles -> fileName = " + fileName); } + if (FULL_LOG === true) { logger.write("[INFO] start -> writeFiles -> writeCandles -> filePath = " + filePath); } utilities.createFolderIfNeeded(filePath, oliviaFileStorage, onFolderCreated); - function onFolderCreated() { + function onFolderCreated(err) { + + if (FULL_LOG === true) { logger.write("[INFO] start -> writeFiles -> writeCandles -> onFolderCreated -> Entering function."); } + + if (err.result !== global.DEFAULT_OK_RESPONSE.result) { + logger.write("[ERROR] start -> writeFiles -> writeCandles -> onFolderCreated -> err = " + err.message); + callBackFunction(err); + return; + } oliviaFileStorage.createTextFile(filePath, fileName, fileContent + '\n', onFileCreated); - function onFileCreated() { + function onFileCreated(err) { - const logText = "[WARN] Finished with File @ " + market.assetA + "_" + market.assetB + ", " + fileRecordCounter + " records inserted into " + filePath + "/" + fileName + ""; - console.log(logText); - logger.write(logText); + if (FULL_LOG === true) { logger.write("[INFO] start -> writeFiles -> writeCandles -> onFolderCreated -> onFileCreated -> Entering function."); } + + if (err.result !== global.DEFAULT_OK_RESPONSE.result) { + logger.write("[ERROR] start -> writeFiles -> writeCandles -> onFolderCreated -> onFileCreated -> err = " + err.message); + callBackFunction(err); + return; + } + + if (LOG_FILE_CONTENT === true) { + logger.write("[INFO] start -> writeFiles -> writeCandles -> onFolderCreated -> onFileCreated -> Content written = " + fileContent); + } + + logger.write("[WARN] start -> writeFiles -> writeCandles -> onFolderCreated -> onFileCreated -> Finished with File @ " + market.assetA + "_" + market.assetB + ", " + fileRecordCounter + " records inserted into " + filePath + "/" + fileName); writeVolumes(); } } - } function writeVolumes() { + if (FULL_LOG === true) { logger.write("[INFO] start -> writeFiles -> writeVolumes -> Entering function."); } + let separator = ""; let fileRecordCounter = 0; - let fileContent = ""; for (i = 0; i < volumes.length; i++) { @@ -635,89 +537,69 @@ Read the candles and volumes from Bruce and produce a file for each day and for fileContent = "[" + fileContent + "]"; let fileName = '' + market.assetA + '_' + market.assetB + '.json'; + let dateForPath = contextVariables.lastCandleFile.getUTCFullYear() + '/' + utilities.pad(contextVariables.lastCandleFile.getUTCMonth() + 1, 2) + '/' + utilities.pad(contextVariables.lastCandleFile.getUTCDate(), 2); + let filePath = global.FILE_PATH_ROOT + "/Output/" + VOLUMES_FOLDER_NAME + "/" + bot.process + "/" + folderName + "/" + dateForPath; - let dateForPath = lastCandleFile.getUTCFullYear() + '/' + utilities.pad(lastCandleFile.getUTCMonth() + 1, 2) + '/' + utilities.pad(lastCandleFile.getUTCDate(), 2); - - let filePath = EXCHANGE_NAME + "/Output/" + VOLUMES_FOLDER_NAME + "/" + bot.process + "/" + folderName + "/" + dateForPath; + if (FULL_LOG === true) { logger.write("[INFO] start -> writeFiles -> writeVolumes -> fileName = " + fileName); } + if (FULL_LOG === true) { logger.write("[INFO] start -> writeFiles -> writeVolumes -> filePath = " + filePath); } utilities.createFolderIfNeeded(filePath, oliviaFileStorage, onFolderCreated); - function onFolderCreated() { + function onFolderCreated(err) { + + if (FULL_LOG === true) { logger.write("[INFO] start -> writeFiles -> writeVolumes -> onFolderCreated -> Entering function."); } + + if (err.result !== global.DEFAULT_OK_RESPONSE.result) { + logger.write("[ERROR] start -> writeFiles -> writeVolumes -> onFolderCreated -> err = " + err.message); + callBackFunction(err); + return; + } oliviaFileStorage.createTextFile(filePath, fileName, fileContent + '\n', onFileCreated); - function onFileCreated() { + function onFileCreated(err) { - const logText = "[WARN] Finished with File @ " + market.assetA + "_" + market.assetB + ", " + fileRecordCounter + " records inserted into " + filePath + "/" + fileName + ""; - console.log(logText); - logger.write(logText); + if (FULL_LOG === true) { logger.write("[INFO] start -> writeFiles -> writeVolumes -> onFolderCreated -> onFileCreated -> Entering function."); } + + if (err.result !== global.DEFAULT_OK_RESPONSE.result) { + logger.write("[ERROR] start -> writeFiles -> writeVolumes -> onFolderCreated -> onFileCreated -> err = " + err.message); + callBackFunction(err); + return; + } + + if (LOG_FILE_CONTENT === true) { + logger.write("[INFO] start -> writeFiles -> writeVolumes -> onFolderCreated -> onFileCreated -> Content written = " + fileContent); + } + + logger.write("[WARN] start -> writeFiles -> writeVolumes -> onFolderCreated -> onFileCreated -> Finished with File @ " + market.assetA + "_" + market.assetB + ", " + fileRecordCounter + " records inserted into " + filePath + "/" + fileName); callBack(); } } } } - catch (err) { - const logText = "[ERROR] 'writeFiles' - ERROR : " + err.message; - logger.write(logText); - closeMarket(); + logger.write("[ERROR] start -> writeFiles -> err = " + err.message); + callBackFunction(global.DEFAULT_FAIL_RESPONSE); } } function writeStatusReport(lastFileDate, callBack) { - if (LOG_INFO === true) { - logger.write("[INFO] Entering function 'writeStatusReport'"); - } + if (FULL_LOG === true) { logger.write("[INFO] start -> writeStatusReport -> Entering function."); } + if (FULL_LOG === true) { logger.write("[INFO] start -> writeStatusReport -> lastFileDate = " + lastFileDate); } try { - let reportFilePath = EXCHANGE_NAME + "/Processes/" + bot.process; - - utilities.createFolderIfNeeded(reportFilePath, oliviaFileStorage, onFolderCreated); - - function onFolderCreated() { - - try { - - let fileName = "Status.Report." + market.assetA + '_' + market.assetB + ".json"; - - let report = { - lastFile: { - year: lastFileDate.getUTCFullYear(), - month: (lastFileDate.getUTCMonth() + 1), - days: lastFileDate.getUTCDate() - } - }; - - let fileContent = JSON.stringify(report); - - oliviaFileStorage.createTextFile(reportFilePath, fileName, fileContent + '\n', onFileCreated); - - function onFileCreated() { - - if (LOG_INFO === true) { - logger.write("[INFO] 'writeStatusReport' - Content written: " + fileContent); - } - - callBack(); - } - } - catch (err) { - const logText = "[ERROR] 'writeStatusReport - onFolderCreated' - ERROR : " + err.message; - logger.write(logText); - closeMarket(); - } - } + statusReportModule.file.lastExecution = global.processDatetime; + statusReportModule.file.lastFile = lastFileDate; + statusReportModule.save(callBack); } catch (err) { - const logText = "[ERROR] 'writeStatusReport' - ERROR : " + err.message; - logger.write(logText); - closeMarket(); + logger.write("[ERROR] start -> writeStatusReport -> err = " + err.message); + callBackFunction(global.DEFAULT_FAIL_RESPONSE); } - } } diff --git a/Multi-Period-Market/User.bot.js b/Multi-Period-Market/User.bot.js index 948e8a192..cd0f39191 100644 --- a/Multi-Period-Market/User.bot.js +++ b/Multi-Period-Market/User.bot.js @@ -9,7 +9,7 @@ const GMT_MILI_SECONDS = '.000 GMT+0000'; const ONE_DAY_IN_MILISECONDS = 24 * 60 * 60 * 1000; - const MODULE_NAME = "UserBot"; + const MODULE_NAME = "User Bot"; const EXCHANGE_NAME = "Poloniex"; @@ -422,13 +422,15 @@ Read the candles and volumes from Bruce and produce a single Index File for Mark candlesFile = JSON.parse(text); } catch (err) { - logger.write("[ERROR] start -> buildCandles -> periodsLoop -> loopBody -> nextCandleFile -> onFileReceived -> err = " + err.message); + logger.write("[ERROR] start -> buildCandles -> periodsLoop -> loopBody -> nextCandleFile -> onFileReceived -> Error Parsing JSON -> err = " + err.message); logger.write("[ERROR] start -> buildCandles -> periodsLoop -> loopBody -> nextCandleFile -> onFileReceived -> Asuming this is a temporary situation. Requesting a Retry."); callBackFunction(global.DEFAULT_RETRY_RESPONSE); + return; } } else { - logger.write("[ERROR] start -> buildCandles -> periodsLoop -> loopBody -> nextCandleFile -> onFileReceived -> err = " + err.message); + logger.write("[ERROR] start -> buildCandles -> periodsLoop -> loopBody -> nextCandleFile -> onFileReceived -> Error Received -> err = " + err.message); callBackFunction(err); + return; } const inputCandlesPerdiod = 60 * 1000; // 1 min @@ -473,7 +475,6 @@ Read the candles and volumes from Bruce and produce a single Index File for Mark outputCandle.open = candle.open; outputCandle.min = candle.min; outputCandle.max = candle.max; - } saveCandle = true; @@ -483,13 +484,11 @@ Read the candles and volumes from Bruce and produce a single Index File for Mark if (candle.min < outputCandle.min) { outputCandle.min = candle.min; - } if (candle.max > outputCandle.max) { outputCandle.max = candle.max; - } } } @@ -536,13 +535,15 @@ Read the candles and volumes from Bruce and produce a single Index File for Mark volumesFile = JSON.parse(text); } catch (err) { - logger.write("[ERROR] start -> buildCandles -> periodsLoop -> loopBody -> nextVolumeFile -> onFileReceived -> err = " + err.message); + logger.write("[ERROR] start -> buildCandles -> periodsLoop -> loopBody -> nextVolumeFile -> onFileReceived -> Error Parsing JSON -> err = " + err.message); logger.write("[ERROR] start -> buildCandles -> periodsLoop -> loopBody -> nextVolumeFile -> onFileReceived -> Asuming this is a temporary situation. Requesting a Retry."); callBackFunction(global.DEFAULT_RETRY_RESPONSE); + return; } } else { - logger.write("[ERROR] start -> buildCandles -> periodsLoop -> loopBody -> nextVolumeFile -> onFileReceived -> err = " + err.message); + logger.write("[ERROR] start -> buildCandles -> periodsLoop -> loopBody -> nextVolumeFile -> onFileReceived -> Error Received -> err = " + err.message); callBackFunction(err); + return; } const inputVolumesPerdiod = 60 * 1000; // 1 min @@ -614,7 +615,6 @@ Read the candles and volumes from Bruce and produce a single Index File for Mark } else { writeStatusReport(contextVariables.lastCandleFile, advanceTime); - } } } @@ -700,7 +700,6 @@ Read the candles and volumes from Bruce and produce a single Index File for Mark writeVolumes(); } } - } function writeVolumes() {