From dbacf59da1f833a238c8a155e1e588b194ca2376 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Wed, 14 Mar 2018 16:51:03 +0100 Subject: [PATCH] getContextVariables() re implemented to Aplha level --- .vs/AAOlivia-Indicator-Bot/v15/.suo | Bin 23040 -> 23040 bytes Multi-Period-Market/Interval.js | 80 ++++++++++++++-------------- 2 files changed, 41 insertions(+), 39 deletions(-) diff --git a/.vs/AAOlivia-Indicator-Bot/v15/.suo b/.vs/AAOlivia-Indicator-Bot/v15/.suo index 522e38a7ff105907cbcecffed0849852fd83176f..345922152152404b106c48b0de6545c181719006 100644 GIT binary patch delta 67 zcmZqJ!q~8daYGIhYeVmb8>==KGW}*|b*NDJuzGVL+Zk`h{>^ql-i)j*3=9nRoBM*- RGck5TL=FN)WPu_@OaOsI7v2B> delta 67 zcmZqJ!q~8daYGIh>jt(2>j|3+nSL{~D)jAh0W#Uncr(7=Y!~Fs$ePB?z`(G%FL*r@ Ix=0Zd05s+nKmY&$ diff --git a/Multi-Period-Market/Interval.js b/Multi-Period-Market/Interval.js index e0151ac05..e442ec646 100644 --- a/Multi-Period-Market/Interval.js +++ b/Multi-Period-Market/Interval.js @@ -105,6 +105,8 @@ Read the candles and volumes from Bruce and produce a single Index File for Mark let reportFilePath; let fileName = "Status.Report." + market.assetA + '_' + market.assetB + ".json" + if (FULL_LOG === true) { logger.write("[INFO] start -> getContextVariables -> fileName = " + fileName); } + getHistoricTrades(); function getHistoricTrades() { @@ -119,29 +121,33 @@ Read the candles and volumes from Bruce and produce a single Index File for Mark reportFilePath = EXCHANGE_NAME + "/Processes/" + "Poloniex-Historic-Trades"; - charlyAzureFileStorage.getTextFile(reportFilePath, fileName, onFileReceived, true); + if (FULL_LOG === true) { logger.write("[INFO] start -> getContextVariables -> getHistoricTrades -> reportFilePath = " + reportFilePath); } - function onFileReceived(text) { + charlyAzureFileStorage.getTextFile(reportFilePath, fileName, onFileReceived); + + function onFileReceived(err, text) { if (FULL_LOG === true) { logger.write("[INFO] start -> getContextVariables -> getHistoricTrades -> onFileReceived -> Entering function."); } if (FULL_LOG === true) { logger.write("[INFO] start -> getContextVariables -> getHistoricTrades -> onFileReceived -> text = " + text); } - let statusReport; + let thisReport; + + if (err.result === global.CUSTOM_OK_RESPONSE.result) { + try { + thisReport = JSON.parse(text); - try { + firstTradeFile = new Date(thisReport.lastFile.year + "-" + thisReport.lastFile.month + "-" + thisReport.lastFile.days + " " + thisReport.lastFile.hours + ":" + thisReport.lastFile.minutes + GMT_SECONDS); - statusReport = JSON.parse(text); + getOneMinDailyCandlesVolumes(); - 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] 'getContextVariables' - Failed to read main Historic Trades Status Report for market " + market.assetA + '_' + market.assetB + " . Skipping it. "; - logger.write(logText); - - + } catch (err) { + logger.write("[ERROR] start -> getContextVariables -> getHistoricTrades -> onFileReceived -> err = " + err.message); + logger.write("[ERROR] start -> getContextVariables -> getHistoricTrades -> onFileReceived -> Asuming this is a temporary situation. Requesting a Retry."); + callBackFunction(global.DEFAULT_RETRY_RESPONSE); + } + } else { + logger.write("[ERROR] start -> getContextVariables -> getHistoricTrades -> onFileReceived -> err = " + err.message); + callBackFunction(err); } } } @@ -158,35 +164,33 @@ Read the candles and volumes from Bruce and produce a single Index File for Mark reportFilePath = EXCHANGE_NAME + "/Processes/" + "One-Min-Daily-Candles-Volumes" + "/" + currentYear + "/" + currentMonth; - bruceAzureFileStorage.getTextFile(reportFilePath, fileName, onFileReceived, true); + if (FULL_LOG === true) { logger.write("[INFO] start -> getContextVariables -> getOneMinDailyCandlesVolumes -> reportFilePath = " + reportFilePath); } - function onFileReceived(text) { + bruceAzureFileStorage.getTextFile(reportFilePath, fileName, onFileReceived); + + function onFileReceived(err, text) { if (FULL_LOG === true) { logger.write("[INFO] start -> getContextVariables -> getOneMinDailyCandlesVolumes -> onFileReceived -> Entering function."); } if (FULL_LOG === true) { logger.write("[INFO] start -> getContextVariables -> getOneMinDailyCandlesVolumes -> onFileReceived -> text = " + text); } - let statusReport; + let thisReport; - try { + if (err.result === global.CUSTOM_OK_RESPONSE.result) { + try { + thisReport = JSON.parse(text); - statusReport = JSON.parse(text); + maxCandleFile = new Date(thisReport.lastFile.year + "-" + thisReport.lastFile.month + "-" + thisReport.lastFile.days + " " + "00:00" + GMT_SECONDS); - 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(); + getThisProcessReport(); + } catch (err) { + logger.write("[ERROR] start -> getContextVariables -> getOneMinDailyCandlesVolumes -> onFileReceived -> err = " + err.message); + logger.write("[ERROR] start -> getContextVariables -> getOneMinDailyCandlesVolumes -> onFileReceived -> Asuming this is a temporary situation. Requesting a Retry."); + callBackFunction(global.DEFAULT_RETRY_RESPONSE); + } + } else { + logger.write("[ERROR] start -> getContextVariables -> getHistoricTrades -> onFileReceived -> err = " + err.message); + callBackFunction(err); } } } @@ -209,10 +213,8 @@ Read the candles and volumes from Bruce and produce a single Index File for Mark lastCandleFile = new Date(statusReport.lastFile.year + "-" + statusReport.lastFile.month + "-" + statusReport.lastFile.days + " " + "00:00" + GMT_SECONDS); /* - 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. - */ lastCandleFile = new Date(lastCandleFile.valueOf() - ONE_DAY_IN_MILISECONDS); @@ -232,14 +234,14 @@ Read the candles and volumes from Bruce and produce a single Index File for Mark buildCandles(); } else { - callBack(err); // we cant handle this here. + callBackFunction(err); // we cant handle this here. } return; } default: { logger.write("[ERROR] initialize -> getStatusReport -> Operation Failed."); - callBack(err); + callBackFunction(err); return; } }