From 69c9564f14b4444e407ece6f5064b6b842f46630 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Mon, 19 Mar 2018 13:03:18 +0100 Subject: [PATCH] Hole Fixing upgraded to Alpha --- .vs/AACharly-Extraction-Bot/v15/.suo | Bin 29696 -> 31232 bytes Poloniex-Hole-Fixing/User.bot.js | 286 ++++++++------------------- 2 files changed, 84 insertions(+), 202 deletions(-) diff --git a/.vs/AACharly-Extraction-Bot/v15/.suo b/.vs/AACharly-Extraction-Bot/v15/.suo index 64c907c810d28d3df3537f9e291812616ebaeafe..3f9e652db344074d2bd368c447c0cbfb50b9c506 100644 GIT binary patch delta 1995 zcmd5-ZD?C%6u$3GGPCX`P1@L`ZE#DIe#|X1)qXf_IyJ!$I!V)yjj?p5>a^SXp;MU}GRMv!XwSU~~1)6kBK!M1NEZgCXdCb|N@xMLSsIb8d5MQ3n$gJmI)DRy@Oe2mG0wG}7^N&r4%1Lqegz}-L@ z-~?QN8_*034|>V$GS)#j9(7o@f;Scptc*u%jSsIXjN8B`qc)L|cNd~-e}CfgD~PTV z8ZEk~XvR?gk0NYYAEEwDCb+wW4aZT9wGq&D%r{|Q4va?|lnQVkP^<0Takk;)76D%1 zUO>0qURe9VcL4VR0iYhZA9w(00Ga@{X$Id3u+N9U9|R_&4q-`Sak`*bQHA?wkx@bx zAt2&hv+Zh8x6CR0v0Q{dgqE>f(SoQ>LCBt81wRR#D(wI2Jhvq*ZtKUDD%kzmPo^Y9 zGc`Txg_^j?Sg|e*Qp!5RC8A{U*m`x=DrX#Fr3#+(zT)p!la4t9&B}q;v(PL8Or6qm z__a$3X-GOI9g?1x4r09n@*$~T8kUlf4M~HL>;~_JJ_J4tNm8?Km1Mz{;e;^pn@qAKxKY`Ujo@8a06 zRovQZfgZpB|AbyiVnDY-vzCC%Js;V&o%!n0!QtxE{^7{^T?@Sl_2dhuMaC8W|JBEz z7Z$;R@g1Zm+r)Elj+TqtC|n$%q_4}o79QV!OSU;>Gmfk;kVz{LEtj_`9;od2$?POJ*N znV#+l*~6|&$dnBprtkVo=+glg{n+ZLJBovRjY(+!J`6zu zqcI}+rK?xH-TPj2_g&9BN9S*ywX1Xe0g-FHV!CZld8xhY3pEyhS^QT`lv1r qP{!G-IVzdIY;5Rm`u5G^AK&!sITwGM4fKA|IYm3lGKqe_ zIdf*dIrk)9LEu(C*6Qg)vH-zQk?gUx&d@G1IXI(~u#jLOlo84a9A~kSy@;@w;3Oo2 zjwn}JMyMq$C#)pQ?#^TyRJ%FH*GRTZSWReB{dKBtRrSnRunJPbRwB7ns4DJB>RSFG zmK7A97fW9*ORX6rCBLNw6U`?S5KM$TLLtFQV4_8=lR>9VBtuKqw4Ho-#9%Y5AR`$p zTep_|Subu0ca!5!D%gNOJMDPa=^^dNqERr+T`PB;rvN8}I%Am9e#7I-wun4<9=LX*_&F^e z6Ihgz!YN4hl*}1N2V~Q7`C>dfjkGiYrd&QBo`Vv%p8bT3H)jCvEN@qY+8IdKbj_vD zH=0Y|n5D10UXgDYSy`Cg^#pLHZIuF^TSCz^ZRCfj*WJLNH-X*$GL*c-BlUSX`>5Qt zm! z)zsV+bGc<%cI|2E-6zYjmYCb!ivjO5$ZbHvX`em4{s_!3xevX*{oK29W zMBJC2;?TwonDjX?u&EsX4sRvBbI~ctR?L3Rt2UF_mX6(@&q$Oh-v#~0^`Q)HJPG*A z9uNK$F6V2LK74H_ilWE%_Fqhd0H?wSse3EUp-Vep@&6y7421+R&EEZqBK$qvSFqdP z_9dToOvxMqAsrtTK!?4J6_)4EozWd%+4ujNDIc7Cd%gr8hOVVHB~k;Uc*Z4SqhL|S H`@QfEDl<`D diff --git a/Poloniex-Hole-Fixing/User.bot.js b/Poloniex-Hole-Fixing/User.bot.js index 2aa75e280..9a119314f 100644 --- a/Poloniex-Hole-Fixing/User.bot.js +++ b/Poloniex-Hole-Fixing/User.bot.js @@ -355,12 +355,24 @@ What is the lastFile pointer? writeStatusReport(currentDatetime, currentTradeId, false, true, onStatusReportWritten); - function onStatusReportWritten() { + function onStatusReportWritten(err) { - if (FULL_LOG === true) { logger.write("[INFO] start -> findNextHole -> readNextFile -> onStatusReportWritten -> Entering function."); } + try { + if (FULL_LOG === true) { logger.write("[INFO] start -> findNextHole -> readNextFile -> onStatusReportWritten -> Entering function."); } - callBackFunction(global.DEFAULT_OK_RESPONSE); - return; + if (err.result !== global.DEFAULT_OK_RESPONSE.result) { + logger.write("[ERROR] start -> findNextHole -> readNextFile -> onStatusReportWritten -> err = " + err.message); + callBackFunction(err); + return; + } + + callBackFunction(global.DEFAULT_OK_RESPONSE); + return; + } catch (err) { + logger.write("[ERROR] start -> findNextHole -> readNextFile -> onStatusReportWritten -> err = " + err.message); + callBackFunction(global.DEFAULT_FAIL_RESPONSE); + return; + } } return; } @@ -373,17 +385,30 @@ What is the lastFile pointer? writeStatusReport(currentDatetime, currentTradeId, true, false, onStatusReportWritten); - function onStatusReportWritten() { + function onStatusReportWritten(err) { - if (FULL_LOG === true) { logger.write("[INFO] start -> findNextHole -> readNextFile -> onStatusReportWritten -> Entering function."); } + try { + if (FULL_LOG === true) { logger.write("[INFO] start -> findNextHole -> readNextFile -> onStatusReportWritten -> Entering function."); } - let customOK = { - result: global.CUSTOM_OK_RESPONSE.result, - message: "End of the month reached." + if (err.result !== global.DEFAULT_OK_RESPONSE.result) { + logger.write("[ERROR] start -> findNextHole -> readNextFile -> onStatusReportWritten -> err = " + err.message); + callBackFunction(err); + return; + } + + let customOK = { + result: global.CUSTOM_OK_RESPONSE.result, + message: "End of the month reached." + } + logger.write("[WARN] start -> findNextHole -> readNextFile -> onStatusReportWritten -> customOK = " + customOK.message); + callBackFunction(customOK); + + return; + } catch (err) { + logger.write("[ERROR] start -> findNextHole -> readNextFile -> onStatusReportWritten -> err = " + err.message); + callBackFunction(global.DEFAULT_FAIL_RESPONSE); + return; } - logger.write("[WARN] start -> findNextHole -> readNextFile -> onStatusReportWritten -> customOK = " + customOK.message); - callBackFunction(customOK); - return; } return; } @@ -575,22 +600,27 @@ What is the lastFile pointer? writeStatusReport(currentDatetime, currentTradeId, false, false, onStatusReportWritten); - function onStatusReportWritten() { + function onStatusReportWritten(err) { try { - if (FULL_LOG === true) { logger.write("[INFO] start -> findNextHole -> checkHolesInFile -> onStatusReportWritten -> Entering function."); } + if (err.result !== global.DEFAULT_OK_RESPONSE.result) { + logger.write("[ERROR] start -> findNextHole -> checkHolesInFile -> onStatusReportWritten -> err = " + err.message); + callBackFunction(err); + return; + } + fileCheckedCounter = 0; readNextFile(); + return; } catch (err) { logger.write("[ERROR] start -> findNextHole -> checkHolesInFile -> onStatusReportWritten -> err = " + err.message); callBackFunction(global.DEFAULT_FAIL_RESPONSE); return; } } - } else { readNextFile(); @@ -629,12 +659,24 @@ What is the lastFile pointer? writeStatusReport(currentDatetime, currentTradeId, false, false, onStatusReportWritten); - function onStatusReportWritten() { + function onStatusReportWritten(err) { - if (FULL_LOG === true) { logger.write("[INFO] start -> findNextHole -> findEndOfHole -> onStatusReportWritten -> Entering function."); } + try { + if (FULL_LOG === true) { logger.write("[INFO] start -> findNextHole -> findEndOfHole -> onStatusReportWritten -> Entering function."); } - callBackFunction(global.DEFAULT_OK_RESPONSE); - return; + if (err.result !== global.DEFAULT_OK_RESPONSE.result) { + logger.write("[ERROR] start -> findNextHole -> findEndOfHole -> onStatusReportWritten -> err = " + err.message); + callBackFunction(err); + return; + } + + callBackFunction(global.DEFAULT_OK_RESPONSE); + return; + } catch (err) { + logger.write("[ERROR] start -> findNextHole -> findEndOfHole -> onStatusReportWritten -> err = " + err.message); + callBackFunction(global.DEFAULT_FAIL_RESPONSE); + return; + } } return; } @@ -1189,12 +1231,32 @@ What is the lastFile pointer? function onMainReportCreated() { - verifyMarketComplete(monthChecked, callBack); + if (monthChecked === true) { + + let key = bot.devTeam + "-" + bot.codeName + "-" + bot.process + "-" + bot.dataSetVersion; + let statusReport = dependencies.statusReports.get(key); + statusReport.verifyMarketComplete(callBack); + return; + + } else { + callBack(global.DEFAULT_OK_RESPONSE); + return; + } } } else { - verifyMarketComplete(monthChecked, callBack); + if (monthChecked === true) { + + let key = bot.devTeam + "-" + bot.codeName + "-" + bot.process + "-" + bot.dataSetVersion; + let statusReport = dependencies.statusReports.get(key); + statusReport.verifyMarketComplete(callBack); + return; + + } else { + callBack(global.DEFAULT_OK_RESPONSE); + return; + } } } @@ -1247,7 +1309,7 @@ What is the lastFile pointer? return; } - callBack(); + callBack(global.DEFAULT_OK_RESPONSE); return; } } @@ -1258,186 +1320,6 @@ What is the lastFile pointer? } } - function verifyMarketComplete(isMonthComplete, callBack) { - - if (isMonthComplete === true) { - - logger.write("[INFO] 'writeStatusReport' - verifyMarketComplete - Month Completed !!! "); - - /* - - The mission of this function is to update the main status report. This report contains the date of the last file sucessfully checked - but in a consecutive way. - - For example: if the market starts in March, and March, April and June are checked, then the file will be the last of June even if September is also checked. - - */ - - let initialYear; - let initialMonth; - - let finalYear = (new Date()).getUTCFullYear(); - let finalMonth = (new Date()).getUTCMonth() + 1; - - let reportFilePath = EXCHANGE_NAME + "/Processes/" + bot.process; - let fileName = "Status.Report." + market.assetA + '_' + market.assetB + ".json"; - - /* Lets read the main status report */ - - charlyFileStorage.getTextFile(reportFilePath, fileName, onFileReceived, true); - - function onFileReceived(text) { - - if (text === undefined) { - - /* The first month of the market didnt create this file yet. Aborting verification. */ - - logger.write("[INFO] 'writeStatusReport' - verifyMarketComplete - Verification ABORTED since the main status report does not exist. "); - - callBack(); - - } else { - - let statusReport = JSON.parse(text); - - initialYear = statusReport.lastFile.year; - initialMonth = statusReport.lastFile.month; - - loopCycle(); - } - - } - - function loopCycle() { - - /* - - Here we read the status report file of each month / year to verify if it is complete or not. - - */ - let paddedInitialMonth = utilities.pad(initialMonth, 2); - - let reportFilePath = EXCHANGE_NAME + "/Processes/" + bot.process + "/" + initialYear + "/" + paddedInitialMonth; - let fileName = "Status.Report." + market.assetA + '_' + market.assetB + ".json"; - - charlyFileStorage.getTextFile(reportFilePath, fileName, onStatusReportFileReceived, true); - - function onStatusReportFileReceived(text) { - - if (text === undefined) { - - /* If any of the files do not exist, it means that the continuity has ben broken and this checking procedure must be aborted */ - - logger.write("[INFO] 'writeStatusReport' - verifyMarketComplete - Verification ABORTED since the status report for year " + initialYear + " and month " + initialMonth + " did not exist. "); - - callBack(); - - } else { - - let statusReport = JSON.parse(text); - - if (statusReport.monthChecked === true) { - - readAndWriteNewReport(statusReport); - - } else { - - /* If any of the files says that month is not checked then it is enough to know the market continuity is broken. */ - - logger.write("[INFO] 'writeStatusReport' - verifyMarketComplete - Verification ABORTED since the status report for year " + initialYear + " and month " + initialMonth + " is not hole checked. "); - - callBack(); - - } - } - } - } - - - - function readAndWriteNewReport(monthlyStatusReport) { - - /* We will read the current file to preserve its data, and save it again with the new lastFile */ - - let reportFilePath = EXCHANGE_NAME + "/Processes/" + bot.process; - let fileName = "Status.Report." + market.assetA + '_' + market.assetB + ".json"; - - charlyFileStorage.getTextFile(reportFilePath, fileName, onFileReceived, true); - - function onFileReceived(text) { - - let statusReport = JSON.parse(text); - - /* - - Only if the last trade ID of the month being evaluated is bigger the trade Id at the status report we do replace it, otherwise not. - - */ - - if (monthlyStatusReport.lastTrade.id > statusReport.lastTrade.id) { - - statusReport.lastFile = monthlyStatusReport.lastFile; - statusReport.lastTrade = monthlyStatusReport.lastTrade; - statusReport.lastTrade.counter = undefined; - - let fileContent = JSON.stringify(statusReport); - - charlyFileStorage.createTextFile(reportFilePath, fileName, fileContent + '\n', onMasterFileCreated); - - function onMasterFileCreated() { - - logger.write("[INFO] 'writeStatusReport' - verifyMarketComplete - Main Status Report Updated - Content written: " + fileContent); - - loop(); // Lets see the next month. - - } - - } else { - - logger.write("[INFO] 'writeStatusReport' - verifyMarketComplete - Main Status Report Not Updated since current Trade Id (" + monthlyStatusReport.lastTrade.id + ") is <= than Id at main status report file. (" + statusReport.lastTrade.id + ")" ); - - loop(); // Lets see the next month. - - } - } - } - - - function loop() { - - initialMonth++; - - if (initialMonth > 12) { - - initialMonth = 1; - initialYear++; - - } - - if ((initialYear === finalYear && initialMonth > finalMonth) || (initialYear > finalYear)) { - - /* We arrived to the point where we have checked all the status reports of every month and they are all complete. */ - - logger.write("[INFO] 'writeStatusReport' - verifyMarketComplete - Verification Finished. "); - - callBack(); - - return; - } - - loopCycle(); - - } - - } else { - - logger.write("[INFO] 'writeStatusReport' - verifyMarketComplete - Verification ABORTED: Month is not checked. "); - callBack(); - - } - - } - } catch (err) { logger.write("[ERROR] start -> err = " + err.message); callBackFunction(global.DEFAULT_FAIL_RESPONSE);