From 2aa10bda634776a0c694c232baa090fdd9de387d Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Sun, 18 Mar 2018 21:50:06 +0100 Subject: [PATCH] Write Status Report converted to Alpha --- .vs/AACharly-Extraction-Bot/v15/.suo | Bin 29696 -> 29696 bytes Poloniex-Hole-Fixing/User.bot.js | 291 ++++++++++++--------------- this.bot.config.json | 11 + 3 files changed, 137 insertions(+), 165 deletions(-) diff --git a/.vs/AACharly-Extraction-Bot/v15/.suo b/.vs/AACharly-Extraction-Bot/v15/.suo index b64466692c3a6ff8866ed12bf8339c26c21c10b8..64c907c810d28d3df3537f9e291812616ebaeafe 100644 GIT binary patch delta 383 zcmZp8!PxMEaYGIhtAg&+xxY3SGW}*|O_<1F{(W;H8#@={hs~7&?q=K{I2ag&85kIt z8Fo+JpWZMzK2l_IM})@Yed(2pY`7+G2+^HvpP?{0GRRqW2@6mi7zi9##|qKL1LQM< z#5S)D3TB*a7^E>dK0|SGk9*1Fga{F!R?f-(@#2$nVl?;}85kIW7z{EUP;L8=D6`0o zX|h9T2FL-MJ0kQL1xui685lSYOb4-#>qXIC6jsMc@|}H0RYV% BZE^qr delta 261 zcmZp8!PxMEaYGIhYe4a-f-jp3nSL{~2Kcxz0GVv;T$?LY0vI=+5d2}X`9PQh<02cb z$rCdpC;J9D3(B!DK!Lyk8z5VD^V* writeStatusReport -> Entering function."); } - utilities.createFolderIfNeeded(reportFilePath, charlyFileStorage, onFolderCreated); + /* + 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 + forward end of the market. + */ - function onFolderCreated() { + let key = bot.devTeam + "-" + bot.codeName + "-" + bot.process + "-" + bot.dataSetVersion + "-" + year + "-" + month; - try { + let statusReport = dependencies.statusReports.get(key); - /* + if (lastTradeId === undefined) { - Here we will calculate the "counter". The counter keeps track of how many times the process tried to fix the same hole. This allows - the process to know when a hole is not fixable. To do that we need to compre the current status report with the information we ve got - about the hole. If it is the same, we add to the counter. + lastTradeId = holeInitialId; + lastTradeDatetime = holeInitialDatetime; + } - */ + let lastFileWithoutHoles = new Date(lastTradeDatetime.valueOf() - 60 * 1000); // It is the previous file where the last verified trade is. - let counter = 0; + /* + Here we will calculate the "counter". The counter keeps track of how many times the process tried to fix the same hole. This allows + the process to know when a hole is not fixable. To do that we need to compare the current status report with the information we ve got + about the hole. If it is the same, we add to the counter. + */ - try { + let counter = 0; - if (holeFixingStatusReport.lastTrade.id === lastTradeId) { + try { - counter = holeFixingStatusReport.lastTrade.counter; + if (holeFixingStatusReport.lastTrade.id === lastTradeId) { - if (counter === undefined) { counter = 0; } - counter++; - - } - - } catch (err) { // we are here when the status report did not exist. - - counter = 0; - - } - - let fileName = "Status.Report." + market.assetA + '_' + market.assetB + ".json"; - - let report = { - lastFile: { - year: lastFileWithoutHoles.getUTCFullYear(), - month: (lastFileWithoutHoles.getUTCMonth() + 1), - days: lastFileWithoutHoles.getUTCDate(), - hours: lastFileWithoutHoles.getUTCHours(), - minutes: lastFileWithoutHoles.getUTCMinutes() - }, - lastTrade: { - year: lastTradeDatetime.getUTCFullYear(), - month: (lastTradeDatetime.getUTCMonth() + 1), - days: lastTradeDatetime.getUTCDate(), - hours: lastTradeDatetime.getUTCHours(), - minutes: lastTradeDatetime.getUTCMinutes(), - seconds: lastTradeDatetime.getUTCSeconds(), - id: lastTradeId, - counter: counter - }, - monthChecked: monthChecked, - atHeadOfMarket: atHeadOfMarket - }; - - let fileContent = JSON.stringify(report); - - charlyFileStorage.createTextFile(reportFilePath, fileName, fileContent + '\n', onFileBCreated); - - function onFileBCreated() { - - if (LOG_INFO === true) { - logger.write("[INFO] 'writeStatusReport' - Content written: " + fileContent); - } - - /* - - If we are at the same month of the begining of the market, we need to create the main status report file. - We will re-create it even every time the month status report is created. When this month check finished, other months later - will update it. - - */ - - if (processDate.getUTCMonth() === lastHistoricTradeFile.getUTCMonth() && processDate.getUTCFullYear() === lastHistoricTradeFile.getUTCFullYear()) { - - createMainStatusReport(lastTradeDatetime, lastTradeId, onMainReportCreated); - - function onMainReportCreated () { - - verifyMarketComplete(monthChecked, callBack); - - } - - } else { - - verifyMarketComplete(monthChecked, callBack); - - } - - } + counter = holeFixingStatusReport.lastTrade.counter; + if (counter === undefined) { counter = 0; } + counter++; } - catch (err) { - const logText = "[ERROR] 'writeStatusReport - onFolderCreated' - ERROR : " + err.message; - logger.write(logText); - closeMarket(); + + } catch (err) { // we are here when the status report did not exist. + counter = 0; + } + + statusReport.file = { + lastFile: { + year: lastFileWithoutHoles.getUTCFullYear(), + month: (lastFileWithoutHoles.getUTCMonth() + 1), + days: lastFileWithoutHoles.getUTCDate(), + hours: lastFileWithoutHoles.getUTCHours(), + minutes: lastFileWithoutHoles.getUTCMinutes() + }, + lastTrade: { + year: lastTradeDatetime.getUTCFullYear(), + month: (lastTradeDatetime.getUTCMonth() + 1), + days: lastTradeDatetime.getUTCDate(), + hours: lastTradeDatetime.getUTCHours(), + minutes: lastTradeDatetime.getUTCMinutes(), + seconds: lastTradeDatetime.getUTCSeconds(), + id: lastTradeId, + counter: counter + }, + monthChecked: monthChecked, + atHeadOfMarket: atHeadOfMarket + }; + + statusReport.save(onSaved); + + function onSaved(err) { + + if (FULL_LOG === true) { logger.write("[INFO] start -> writeStatusReport -> onSaved -> Entering function."); } + + if (err.result !== global.DEFAULT_OK_RESPONSE.result) { + logger.write("[ERROR] start -> writeStatusReport -> onSaved -> err = " + err.message); + callBackFunction(err); + return; + } + + /* + If we are at the same month of the begining of the market, we need to create the main status report file. + We will re-create it even every time the month status report is created. When this month check finished, other months later + will update it. + */ + + if (processDate.getUTCMonth() === lastHistoricTradeFile.getUTCMonth() && processDate.getUTCFullYear() === lastHistoricTradeFile.getUTCFullYear()) { + + createMainStatusReport(lastTradeDatetime, lastTradeId, onMainReportCreated); + + function onMainReportCreated() { + + verifyMarketComplete(monthChecked, callBack); + } + + } else { + + verifyMarketComplete(monthChecked, callBack); } } + } catch (err) { + logger.write("[ERROR] start -> writeStatusReport -> err = " + err.message); + callBackFunction(global.DEFAULT_FAIL_RESPONSE); + return; } - catch (err) { - const logText = "[ERROR] 'writeStatusReport' - ERROR : " + err.message; - logger.write(logText); - closeMarket(); - } - } - function createMainStatusReport(lastTradeDatetime, lastTradeId,callBack) { + function createMainStatusReport(lastTradeDatetime, lastTradeId, callBack) { + try { + if (FULL_LOG === true) { logger.write("[INFO] start -> createMainStatusReport -> Entering function."); } - let reportFilePath = EXCHANGE_NAME + "/Processes/" + bot.process; + let key = bot.devTeam + "-" + bot.codeName + "-" + bot.process + "-" + bot.dataSetVersion; - utilities.createFolderIfNeeded(reportFilePath, charlyFileStorage, onFolderCreated); + let statusReport = dependencies.statusReports.get(key); - function onFolderCreated() { - - try { - - let lastFileWithoutHoles = new Date(lastTradeDatetime.valueOf() - 60 * 1000); // It is the previous file where the last verified trade is. - - let fileName = "Status.Report." + market.assetA + '_' + market.assetB + ".json"; - - let report = { - lastFile: { - year: lastFileWithoutHoles.getUTCFullYear(), - month: (lastFileWithoutHoles.getUTCMonth() + 1), - days: lastFileWithoutHoles.getUTCDate(), - hours: lastFileWithoutHoles.getUTCHours(), - minutes: lastFileWithoutHoles.getUTCMinutes() - }, - lastTrade: { - year: lastTradeDatetime.getUTCFullYear(), - month: (lastTradeDatetime.getUTCMonth() + 1), - days: lastTradeDatetime.getUTCDate(), - hours: lastTradeDatetime.getUTCHours(), - minutes: lastTradeDatetime.getUTCMinutes(), - seconds: lastTradeDatetime.getUTCSeconds(), - id: lastTradeId - } - }; - - let fileContent = JSON.stringify(report); - - charlyFileStorage.createTextFile(reportFilePath, fileName, fileContent + '\n', onFileBCreated); - - function onFileBCreated() { - - if (LOG_INFO === true) { - logger.write("[INFO] 'createMainStatusReport' - Content written: " + fileContent); - } - - callBack(); - - } + let lastFileWithoutHoles = new Date(lastTradeDatetime.valueOf() - 60 * 1000); // It is the previous file where the last verified trade is. + statusReport.file = { + lastFile: { + year: lastFileWithoutHoles.getUTCFullYear(), + month: (lastFileWithoutHoles.getUTCMonth() + 1), + days: lastFileWithoutHoles.getUTCDate(), + hours: lastFileWithoutHoles.getUTCHours(), + minutes: lastFileWithoutHoles.getUTCMinutes() + }, + lastTrade: { + year: lastTradeDatetime.getUTCFullYear(), + month: (lastTradeDatetime.getUTCMonth() + 1), + days: lastTradeDatetime.getUTCDate(), + hours: lastTradeDatetime.getUTCHours(), + minutes: lastTradeDatetime.getUTCMinutes(), + seconds: lastTradeDatetime.getUTCSeconds(), + id: lastTradeId } - catch (err) { - const logText = "[ERROR] 'createMainStatusReport - onFolderCreated' - ERROR : " + err.message; - logger.write(logText); - closeMarket(); + }; + + statusReport.save(onSaved); + + function onSaved(err) { + + if (FULL_LOG === true) { logger.write("[INFO] start -> createMainStatusReport -> onSaved -> Entering function."); } + + if (err.result !== global.DEFAULT_OK_RESPONSE.result) { + logger.write("[ERROR] start -> createMainStatusReport -> onSaved -> err = " + err.message); + callBackFunction(err); + return; } + + callBack(); + return; } - } catch (err) { - const logText = "[ERROR] 'createMainStatusReport' - ERROR : " + err.message; - logger.write(logText); - closeMarket(); + logger.write("[ERROR] start -> createMainStatusReport -> err = " + err.message); + callBackFunction(global.DEFAULT_FAIL_RESPONSE); + return; } } @@ -1481,6 +1441,7 @@ What is the lastFile pointer? } catch (err) { logger.write("[ERROR] start -> err = " + err.message); callBackFunction(global.DEFAULT_FAIL_RESPONSE); + return; } } }; diff --git a/this.bot.config.json b/this.bot.config.json index 6e439ebaa..c85870772 100644 --- a/this.bot.config.json +++ b/this.bot.config.json @@ -130,6 +130,17 @@ "process": "Poloniex-Historic-Trades", "dataSetVersion": "dataSet.V1" }, + { + "devTeam": "AAMasters", + "bot": "AACharly", + "botVersion": { + "major": 1, + "minor": 0 + }, + "process": "Poloniex-Hole-Fixing", + "dataSetVersion": "dataSet.V1", + "dataSetSection": "Month" + }, { "devTeam": "AAMasters", "bot": "AACharly",