diff --git a/.vs/AACharly-Extraction-Bot/v15/.suo b/.vs/AACharly-Extraction-Bot/v15/.suo index 42f18ca2d..964d72990 100644 Binary files a/.vs/AACharly-Extraction-Bot/v15/.suo and b/.vs/AACharly-Extraction-Bot/v15/.suo differ diff --git a/Poloniex-Hole-Fixing/User.bot.js b/Poloniex-Hole-Fixing/User.bot.js index 400e26d0a..d2ce5ce07 100644 --- a/Poloniex-Hole-Fixing/User.bot.js +++ b/Poloniex-Hole-Fixing/User.bot.js @@ -32,9 +32,11 @@ let year; let month; + let dependencies; + return thisObject; - function initialize(yearAssigend, monthAssigned, callBackFunction) { + function initialize(pDependencies, callBackFunction, yearAssigend, monthAssigned) { try { @@ -169,7 +171,7 @@ What is the lastFile pointer? let holeFixingStatusReport; // Current hole Fixing Status Report. - marketsLoop(); + getStatusReport(); /* @@ -194,58 +196,84 @@ What is the lastFile pointer? try { - let reportFilePath; - let fileName = "Status.Report." + market.assetA + '_' + market.assetB + ".json" - getLivesTrades(); function getLivesTrades() { - reportFilePath = EXCHANGE_NAME + "/Processes/" + "Poloniex-Live-Trades"; + try { - charlyFileStorage.getTextFile(reportFilePath, fileName, onStatusReportReceived, true); + if (FULL_LOG === true) { logger.write("[INFO] start -> getStatusReport -> getLivesTrades -> Entering function."); } - function onStatusReportReceived(text) { + let reportOwner = { + codeName: "Charly", + devTeam: "AAMasters", + process: "Poloniex Live Trades" + }; - if (text === undefined) { + statusReportModule.initialize(reportOwner, onInitilized); - /* The file does not exist, so this means it is too early to run this process. */ + function onInitilized(err) { - const logText = "[INFO] 'getStatusReport' - Market " + market.assetA + '_' + market.assetB + " is too early too prcess it, since there are no Live Trades reports about it yet. Skipping it. "; - logger.write(logText); + if (err.result !== global.DEFAULT_OK_RESPONSE.result) { + logger.write("[ERROR] start -> getStatusReport -> getLivesTrades -> onInitilized -> err = " + err.message); + callBackFunction(err); + return; + } - closeAndOpenMarket(); + statusReportModule.load(onLoad); + } - } else { - - let statusReport; + function onLoad(err) { try { - statusReport = JSON.parse(text); + switch (err.result) { + case global.DEFAULT_OK_RESPONSE.result: { + logger.write("[INFO] start -> getStatusReport -> getLivesTrades -> onLoad -> Execution finished well. :-)"); - lastLiveTradeFile = new Date(statusReport.lastFile.year + "-" + statusReport.lastFile.month + "-" + statusReport.lastFile.days + " " + statusReport.lastFile.hours + ":" + statusReport.lastFile.minutes + GMT_SECONDS); + lastLiveTradeFile = new Date(statusReport.lastFile.year + "-" + statusReport.lastFile.month + "-" + statusReport.lastFile.days + " " + statusReport.lastFile.hours + ":" + statusReport.lastFile.minutes + GMT_SECONDS); + getHistoricTrades(); - } catch (err) { + return; + } + case global.CUSTOM_OK_RESPONSE.result: { // We need to see if we can handle this. + logger.write("[ERROR] start -> getStatusReport -> getLivesTrades -> onLoad -> err.message = " + err.message); - /* + if (err.message === "Status Report was never created.") { - It might happen the the file contect is corrupt if it is read exactly at the moment the other process is writting it. - In this situation we just assume the current datetime is a good engough value. - - */ - - lastLiveTradeFile = new Date(); + logger.write("[ERROR] start -> getStatusReport -> getLivesTrades -> onLoad -> Can not run this process if Live Trades process never ran sucessfully."); + callBackFunction(global.DEFAULT_FAIL_RESPONSE); + return; + } else { + logger.write("[WARN] start -> getStatusReport -> getLivesTrades -> onLoad -> Response not understood."); + callBackFunction(err); + return; + } + + } + default: + { + logger.write("[ERROR] start -> getStatusReport -> getLivesTrades -> onLoad -> Operation Failed."); + callBackFunction(err); + return; + } + } + } + catch (err) { + logger.write("[ERROR] start -> getStatusReport -> getLivesTrades -> onLoad -> err = " + err.message); + callBackFunction(global.DEFAULT_FAIL_RESPONSE); } - - /* We get from the file the datetime of the last file created. */ - - getHistoricTrades(); - } } + catch (err) { + logger.write("[ERROR] start -> getStatusReport -> getLivesTrades -> err = " + err.message); + callBackFunction(global.DEFAULT_FAIL_RESPONSE); + } } + + + function getHistoricTrades() { @@ -310,6 +338,9 @@ What is the lastFile pointer? } } + + + function getHoleFixing() { reportFilePath = EXCHANGE_NAME + "/Processes/" + "Poloniex-Hole-Fixing" + "/" + year + "/" + month; diff --git a/Poloniex-Live-Trades/User.bot.js b/Poloniex-Live-Trades/User.bot.js index 310d9e109..fd4577ad7 100644 --- a/Poloniex-Live-Trades/User.bot.js +++ b/Poloniex-Live-Trades/User.bot.js @@ -29,23 +29,19 @@ let poloniexApiClient = new POLONIEX_CLIENT_MODULE(); 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. - - */ - 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); } + + dependencies = pDependencies; charlyFileStorage.initialize("AACharly", onCharlyInizialized); @@ -387,56 +383,40 @@ Array of records with this information: if (FULL_LOG === true) { logger.write("[INFO] start -> writeStatusReport -> Entering function."); } - statusReportModule.initialize(bot, onInitilized); + let key = bot.devTeam + "-" + bot.codeName + "-" + bot.process + "-" + bot.dataSetVersion; - function onInitilized(err) { + let statusReport = dependencies.statusReports.get(key); - try { - - if (FULL_LOG === true) { logger.write("[INFO] start -> writeStatusReport -> onInitilized -> Entering function."); } - - if (err.result !== global.DEFAULT_OK_RESPONSE.result) { - logger.write("[ERROR] start -> writeStatusReport -> err = " + err.message); - callBackFunction(err); - return; - } - - statusReportModule.file = { - firstFile: { // This file might be incomplete. - year: currentDate.getUTCFullYear(), - month: (currentDate.getUTCMonth() + 1), - days: currentDate.getUTCDate(), - hours: currentDate.getUTCHours(), - minutes: currentDate.getUTCMinutes() - }, - lastFile: { // This will point to the last file written with is complete. That means it has all the trades in it. - year: previousMinute.getUTCFullYear(), - month: (previousMinute.getUTCMonth() + 1), - days: previousMinute.getUTCDate(), - hours: previousMinute.getUTCHours(), - minutes: previousMinute.getUTCMinutes() - } - }; - - statusReportModule.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; - } - - callBackFunction(global.DEFAULT_OK_RESPONSE); - } - - } catch (err) { - logger.write("[ERROR] start -> writeStatusReport -> onInitilized -> err = " + err.message); - callBackFunction(global.DEFAULT_FAIL_RESPONSE); + statusReport.file = { + firstFile: { // This date points to the file that might be incomplete. + year: currentDate.getUTCFullYear(), + month: (currentDate.getUTCMonth() + 1), + days: currentDate.getUTCDate(), + hours: currentDate.getUTCHours(), + minutes: currentDate.getUTCMinutes() + }, + lastFile: { // This will point to the last file written with is complete. That means it has all the trades in it. + year: previousMinute.getUTCFullYear(), + month: (previousMinute.getUTCMonth() + 1), + days: previousMinute.getUTCDate(), + hours: previousMinute.getUTCHours(), + minutes: previousMinute.getUTCMinutes() } + }; + + 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; + } + + callBackFunction(global.DEFAULT_OK_RESPONSE); } } catch (err) { diff --git a/this.bot.config.json b/this.bot.config.json index 2a5ca82c2..b6f3216e2 100644 --- a/this.bot.config.json +++ b/this.bot.config.json @@ -29,7 +29,19 @@ } }, "executionWaitTime": 60000, - "retryWaitTime": 10000 + "retryWaitTime": 10000, + "dependencies": [ + { + "devTeam": "AAMasters", + "bot": "AACharly", + "botVersion": { + "major": 1, + "minor": 0 + }, + "process": "Poloniex-Live-Trades", + "dataSetVersion": "dataSet.V1" + } + ] }, { "name": "Poloniex-Historic-Trades", @@ -50,7 +62,29 @@ } }, "executionWaitTime": 30000, - "retryWaitTime": 10000 + "retryWaitTime": 10000, + "dependencies": [ + { + "devTeam": "AAMasters", + "bot": "AACharly", + "botVersion": { + "major": 1, + "minor": 0 + }, + "process": "Poloniex-Live-Trades", + "dataSetVersion": "dataSet.V1" + }, + { + "devTeam": "AAMasters", + "bot": "AACharly", + "botVersion": { + "major": 1, + "minor": 0 + }, + "process": "Poloniex-Historic-Trades", + "dataSetVersion": "dataSet.V1" + } + ] }, { "name": "Poloniex-Hole-Fixing", @@ -71,7 +105,39 @@ } }, "executionWaitTime": 60000, - "retryWaitTime": 10000 + "retryWaitTime": 10000, + "dependencies": [ + { + "devTeam": "AAMasters", + "bot": "AACharly", + "botVersion": { + "major": 1, + "minor": 0 + }, + "process": "Poloniex-Live-Trades", + "dataSetVersion": "dataSet.V1" + }, + { + "devTeam": "AAMasters", + "bot": "AACharly", + "botVersion": { + "major": 1, + "minor": 0 + }, + "process": "Poloniex-Historic-Trades", + "dataSetVersion": "dataSet.V1" + }, + { + "devTeam": "AAMasters", + "bot": "AACharly", + "botVersion": { + "major": 1, + "minor": 0 + }, + "process": "Poloniex-Hole-Fixing", + "dataSetVersion": "dataSet.V1" + } + ] } ] }