From bec23ebdce09e2cfb569413aaa8a8a92625ec66f Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Sat, 17 Mar 2018 13:39:02 +0100 Subject: [PATCH] Dependencies Implemented --- .vs/AACharly-Extraction-Bot/v15/.suo | Bin 24576 -> 27648 bytes Poloniex-Hole-Fixing/User.bot.js | 93 ++++++++++++++++++--------- Poloniex-Live-Trades/User.bot.js | 92 +++++++++++--------------- this.bot.config.json | 72 ++++++++++++++++++++- 4 files changed, 167 insertions(+), 90 deletions(-) diff --git a/.vs/AACharly-Extraction-Bot/v15/.suo b/.vs/AACharly-Extraction-Bot/v15/.suo index 42f18ca2d40a45b1a25b3ab04bb5626d3b2d8c52..964d7299051c088f553065f67c8860f37fa698d5 100644 GIT binary patch delta 1974 zcmdT^T}+!*82--Jzpth3%3zf8x6-n;8 zc5RE^0p+ZgGMXN<4Whej%yJCMP7OY2R$|%?`5~5VgT`HK0k#5mfZMCka~IroHG1y3 zj(Q~zosrC8547EdQ9h%sAp6T~0mw422M8AI53eNrEGr(ju6(Up?;@mn4E)28GWy36 z&;vueu?EXH%?e6L9%jb3iZ#%bw#&%rv}3e`+l)^^;udV&%Ce@96fX?B0M5P@;7&OB z63)Jybq93LoI42td>;K|>a+Dii2^Yo4vqn7;s`m%j={04~XeTPB3 zSSKwtD0K5LAz=dNpGHm0KpLTTx2*cTx0oT2 zFGGPEoo*&j=kEQg5;-Yu>zX?ipP4>3Hj-YK1cBdBjj&9qxQl-49;e*l{j8{6rWfOG zSW|Q_?#{ZDCr_sO4>BtyGG)8&D{|J6B2Oa78Fwa**FT{6np6b20iy1@V_CP=m z1^3X(puMIK0Tvs-Dn=kujF5Z%%p?1Pq2Q=5EX%TQBshFjmPhxFhQq^iJmo;XO(+|9 zmG(q#7HKFNg(o}RjCR?p3k!I+y&y-HnVRcY7;R6C)6WU_CXW1S7u!1!cx`Urc$HY{ zIt|5}5#?oC?Y+;wFfoc(1$7*#_KUAoS?ZOM`h!e$*l+8?)hQy+V|bhzV*qJ zz#laFbihi#4mPxub9G@;{*Lp_3lDt0vd9^8lG5*_%7b0SAl;M2v|#e-f{Y*|PY3XO zv-3cpv*S|kh)5TnJ4Iha?KFANtFHFy*nj3-Lyrcfz~Axys~8M}w@hFx&~mJqYy-8F zi+L$GRIAg$_#NF&E!J7s?C@;j%; BExP~! delta 1282 zcmchWO-vI}5Xbkut=*-Rx-G@FSONJ61u1Q%U`zy83K~r)m5U@Adot0Ba_B)4sq>&UsEHb5oaEP;otf7+^WS#*6`9t^ z+%aNaZuU@9$o;0T=kXeGavZ1GAxV?uBBW`jSdIxZ0^>tY@KU4Rfe%l3ND9e<5Qg0p zKhP{dbPe+{sb(va$?U@fx^1&#Y(t6=c6L9)dWvC84CJw>9y4{|6RXvfZibkoJ_xc= z3NZa=qwuF8VDag9#(_A+j@8CS%38f?Ycwv%-wdXs*Qsnpy%rp@{Km0C(w z>fI84xr0W2{MJcob)Rf+^tt^_{k$CUPmzw5aPseT*8`d#4Y zz5{O~Hi$-CJmuQ(e6F^roNwK3>lkc+*_c!`fH&oAC>yW?OX_&ULSQ!RbllF>(I=2F z!rmVbTC{BYrDwv;LU`4HISyJ{kAi&J1=r$sC~Yl=$x&}!l~#%+{7b?{ca^lhUeR|h z?!59oV@s}mSun%KKoFw6R)~gNu+;NTId$NlZh{h46CE5JxeK3$D^)El6PW9|03R+b oFbNzF*xXtBoBhr}idsP%l_6yx{6?(S4&mWP_q7;Rts^q|3Rq8W4gdfE 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" + } + ] } ] }