From e9fc84ee12527148a575a4514a3130fe45b0f563 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Fri, 16 Mar 2018 10:57:05 +0100 Subject: [PATCH] Initialization Done --- .vs/AACharly-Extraction-Bot/v15/.suo | Bin 18432 -> 22016 bytes Poloniex-Historic-Trades/Interval.js | 30 +++---- Poloniex-Hole-Fixing/Interval.js | 36 ++++---- .../{Interval.js => User.bot.js} | 79 ++++++++++-------- Project.njsproj | 2 +- 5 files changed, 77 insertions(+), 70 deletions(-) rename Poloniex-Live-Trades/{Interval.js => User.bot.js} (90%) diff --git a/.vs/AACharly-Extraction-Bot/v15/.suo b/.vs/AACharly-Extraction-Bot/v15/.suo index 03d2c7d0ef74c2524c942f4c466f05fc07cec905..3bddabaa78bc4c6ecb72fcd3dc70417c42f227d0 100644 GIT binary patch delta 2145 zcmeH|-%FEG7{||fmvhc{`C~4%U{fo9?p?h$-Ik?WdpFINKT;{EE;M(cL<={?OmR`v zO@!>ZEwJdai{ibEKrl)OOvrzro1mMn@+K(zo~bnnGRUByGd`T>Jm-0zopZkDM{#GQ+!yLcDaJF@nZTPM-{S zcr^t~#aT6Qe0kD+mZzl1dOrX83*9pES}nv!AU+fyIDrCO-~bSDG-s}EXhP!%I0~9U3-E&gI0k}1 z10fIwt)Pv{%~snN>YPFYNNC%|8(SBoFlM=h_p zoCBXJ!%vC4Wm=G&#)EMBjWm&e+`{r;mt_WhtnHHbz)_gtMi)ZHH--zCt>&!-eo0!9u#av~+bnwBS6W&pID+ z*@%ctrSybr$)IZ`R-=B}``++p#L)S3A>+|sm9YR}eAw{{2RHG8Z< z9H9mr9}Pbb>M6!3(9)vMHIGTQdaqXr)rZ4gpC41TVzv@{NhboywyxO4*rlQ9xDpu} ziz>Y%{e#i?xxRRG#5E90xQ64ClUG%@rh0shsuB)0sEWJMttmcLRh6JS5LQ*qqxpP+ zDQXYA;^~x;?Mf*zEuFA$yAtMR%xi#FgU8CZ%AAfW+bW9sv^w5M*R*1r153M6d@wvf z!`eKfRPbF9&MG8hmmy*d77jN1zXg7_tN!&ZAYL?a1Esfso(dLni+CkUfp~rm)P1Nm d6-pY#b@zhNy^5Q^c^gcH=4r<3*8O2W{|fKrNk;$x delta 946 zcmcJM&ubGw6vyZ7rrXJOH@j`DqLfWqV;Y-UV=scHCM6=ZmTcNYy(kp#f`^U7T)LpW zN}Bfvh~lvaVQ&6_f(V{8P|roYc{djY_06WpC?4#=VLvKTXIG?nlUa=@SNdS{h@doy8&D4 z6J2cu;*nM@x9CbO`!_9Ppyl(w>I^^G*Wq3BLGe4akz`2W1d%1Ci5zi~m?84SEFtUW zXg*C82;4Dqm@!?uL_wK|#I{zyb*%svuxV{T5&KrvX7YSGK?2cF!FkcN-$V4XT*+hL zeBg(agmH?3mX7V2Wh+6;w6cd^T;FDgDdQ+vIF8NH4Vc3I=sT>8-NbY_yFom81yfd=Rh4H#M;|?-=5`_gQy+DvA>0RLeXlj*DDj$=fHOrtxTuDkl^O2wVI#=&d1hc)t z4gO(bPq(DkV~Plt&&5P*{%!mKe&Q$3!;zAMZpkD(Je#udW8=06OLw(#65k&!I#iO@ zz+T{^N{D-xirA?n;8zp_b}|K_UbRiPNNLeA^ZvM C0x6vU diff --git a/Poloniex-Historic-Trades/Interval.js b/Poloniex-Historic-Trades/Interval.js index 086fb1aab..708476614 100644 --- a/Poloniex-Historic-Trades/Interval.js +++ b/Poloniex-Historic-Trades/Interval.js @@ -1,4 +1,4 @@ -exports.newInterval = function newInterval(BOT, UTILITIES, AZURE_FILE_STORAGE, DEBUG_MODULE, MARKETS_MODULE, POLONIEX_CLIENT_MODULE) { +exports.newInterval = function newInterval(BOT, UTILITIES, FILE_STORAGE, DEBUG_MODULE, MARKETS_MODULE, POLONIEX_CLIENT_MODULE) { let bot = BOT; const ROOT_DIR = './'; @@ -27,7 +27,7 @@ let markets; - let azureFileStorage = AZURE_FILE_STORAGE.newAzureFileStorage(bot); + let charlyFileStorage = FILE_STORAGE.newFileStorage(bot); let utilities = UTILITIES.newUtilities(bot); @@ -51,7 +51,7 @@ console.log(logText); logger.write(logText); - azureFileStorage.initialize(); + charlyFileStorage.initialize(); markets = MARKETS_MODULE.newMarkets(bot); markets.initialize(callBackFunction); @@ -277,7 +277,7 @@ This process complements the Live Trades process and write historical trades fil let reportFilePath = EXCHANGE_NAME + "/Processes/" + bot.process; let fileName = "Status.Report." + market.assetA + '_' + market.assetB + ".json"; - azureFileStorage.getTextFile(reportFilePath, fileName, onFileReceived, true); + charlyFileStorage.getTextFile(reportFilePath, fileName, onFileReceived, true); function onFileReceived(text) { @@ -333,7 +333,7 @@ This process complements the Live Trades process and write historical trades fil let reportFilePath = EXCHANGE_NAME + "/Processes/" + bot.process + "/" + year + "/" + month; let fileName = "Status.Report." + market.assetA + '_' + market.assetB + ".json"; - azureFileStorage.getTextFile(reportFilePath, fileName, onFileReceived, true); + charlyFileStorage.getTextFile(reportFilePath, fileName, onFileReceived, true); function onFileReceived(text) { @@ -726,11 +726,11 @@ This process complements the Live Trades process and write historical trades fil filePath = EXCHANGE_NAME + "/Output/" + TRADES_FOLDER_NAME + '/' + dateForPath; - utilities.createFolderIfNeeded(filePath, azureFileStorage, onFolderCreated); + utilities.createFolderIfNeeded(filePath, charlyFileStorage, onFolderCreated); function onFolderCreated() { - azureFileStorage.createTextFile(filePath, fileName, fileContent + '\n', onFileCreated); + charlyFileStorage.createTextFile(filePath, fileName, fileContent + '\n', onFileCreated); function onFileCreated() { @@ -848,7 +848,7 @@ This process complements the Live Trades process and write historical trades fil let reportFilePath = EXCHANGE_NAME + "/Processes/" + bot.process + "/" + year + "/" + month; - utilities.createFolderIfNeeded(reportFilePath, azureFileStorage, onFolderCreated); + utilities.createFolderIfNeeded(reportFilePath, charlyFileStorage, onFolderCreated); function onFolderCreated() { @@ -867,7 +867,7 @@ This process complements the Live Trades process and write historical trades fil let fileContent = JSON.stringify(report); - azureFileStorage.createTextFile(reportFilePath, fileName, fileContent + '\n', onFileCreated); + charlyFileStorage.createTextFile(reportFilePath, fileName, fileContent + '\n', onFileCreated); function onFileCreated() { @@ -879,7 +879,7 @@ This process complements the Live Trades process and write historical trades fil reportFilePath = EXCHANGE_NAME + "/Processes/" + bot.process; - utilities.createFolderIfNeeded(reportFilePath, azureFileStorage, onFolderCreated); + utilities.createFolderIfNeeded(reportFilePath, charlyFileStorage, onFolderCreated); function onFolderCreated() { @@ -898,7 +898,7 @@ This process complements the Live Trades process and write historical trades fil let fileContent = JSON.stringify(report); - azureFileStorage.createTextFile(reportFilePath, fileName, fileContent + '\n', onMasterFileCreated); + charlyFileStorage.createTextFile(reportFilePath, fileName, fileContent + '\n', onMasterFileCreated); function onMasterFileCreated() { @@ -965,7 +965,7 @@ This process complements the Live Trades process and write historical trades fil /* Lets read the main status report */ - azureFileStorage.getTextFile(reportFilePath, fileName, onFileReceived, true); + charlyFileStorage.getTextFile(reportFilePath, fileName, onFileReceived, true); function onFileReceived(text) { @@ -1001,7 +1001,7 @@ This process complements the Live Trades process and write historical trades fil let reportFilePath = EXCHANGE_NAME + "/Processes/" + bot.process + "/" + initialYear + "/" + paddedInitialMonth; let fileName = "Status.Report." + market.assetA + '_' + market.assetB + ".json"; - azureFileStorage.getTextFile(reportFilePath, fileName, onStatusReportFileReceived, true); + charlyFileStorage.getTextFile(reportFilePath, fileName, onStatusReportFileReceived, true); function onStatusReportFileReceived(text) { @@ -1067,7 +1067,7 @@ This process complements the Live Trades process and write historical trades fil let reportFilePath = EXCHANGE_NAME + "/Processes/" + bot.process; let fileName = "Status.Report." + market.assetA + '_' + market.assetB + ".json"; - azureFileStorage.getTextFile(reportFilePath, fileName, onFileReceived, true); + charlyFileStorage.getTextFile(reportFilePath, fileName, onFileReceived, true); function onFileReceived(text) { @@ -1077,7 +1077,7 @@ This process complements the Live Trades process and write historical trades fil let fileContent = JSON.stringify(statusReport); - azureFileStorage.createTextFile(reportFilePath, fileName, fileContent + '\n', onMasterFileCreated); + charlyFileStorage.createTextFile(reportFilePath, fileName, fileContent + '\n', onMasterFileCreated); function onMasterFileCreated() { diff --git a/Poloniex-Hole-Fixing/Interval.js b/Poloniex-Hole-Fixing/Interval.js index e43165965..00bda4fcb 100644 --- a/Poloniex-Hole-Fixing/Interval.js +++ b/Poloniex-Hole-Fixing/Interval.js @@ -1,4 +1,4 @@ -exports.newInterval = function newInterval(BOT, UTILITIES, AZURE_FILE_STORAGE, DEBUG_MODULE, MARKETS_MODULE, POLONIEX_CLIENT_MODULE) { +exports.newInterval = function newInterval(BOT, UTILITIES, FILE_STORAGE, DEBUG_MODULE, MARKETS_MODULE, POLONIEX_CLIENT_MODULE) { let bot = BOT; const ROOT_DIR = '../'; @@ -27,7 +27,7 @@ let markets; - let azureFileStorage = AZURE_FILE_STORAGE.newAzureFileStorage(bot); + let charlyFileStorage = FILE_STORAGE.newFileStorage(bot); let utilities = UTILITIES.newUtilities(bot); @@ -51,7 +51,7 @@ console.log(logText); logger.write(logText); - azureFileStorage.initialize(); + charlyFileStorage.initialize(); markets = MARKETS_MODULE.newMarkets(bot); markets.initialize(callBackFunction); @@ -338,7 +338,7 @@ What is the lastFile pointer? reportFilePath = EXCHANGE_NAME + "/Processes/" + "Poloniex-Live-Trades"; - azureFileStorage.getTextFile(reportFilePath, fileName, onStatusReportReceived, true); + charlyFileStorage.getTextFile(reportFilePath, fileName, onStatusReportReceived, true); function onStatusReportReceived(text) { @@ -386,7 +386,7 @@ What is the lastFile pointer? reportFilePath = EXCHANGE_NAME + "/Processes/" + "Poloniex-Historic-Trades"; - azureFileStorage.getTextFile(reportFilePath, fileName, onStatusReportReceived, true); + charlyFileStorage.getTextFile(reportFilePath, fileName, onStatusReportReceived, true); function onStatusReportReceived(text) { @@ -449,7 +449,7 @@ What is the lastFile pointer? reportFilePath = EXCHANGE_NAME + "/Processes/" + "Poloniex-Hole-Fixing" + "/" + year + "/" + month; - azureFileStorage.getTextFile(reportFilePath, fileName, onStatusReportReceived, true); + charlyFileStorage.getTextFile(reportFilePath, fileName, onStatusReportReceived, true); function onStatusReportReceived(text) { @@ -606,7 +606,7 @@ What is the lastFile pointer? filePath = EXCHANGE_NAME + "/Output/" + TRADES_FOLDER_NAME + '/' + dateForPath; - azureFileStorage.getTextFile(filePath, fileName, onNextFileReceived, true); + charlyFileStorage.getTextFile(filePath, fileName, onNextFileReceived, true); function onNextFileReceived(text) { @@ -846,7 +846,7 @@ What is the lastFile pointer? filePath = EXCHANGE_NAME + "/Output/" + TRADES_FOLDER_NAME + '/' + dateForPath; - azureFileStorage.getTextFile(filePath, fileName, onNextFileReceived, true); + charlyFileStorage.getTextFile(filePath, fileName, onNextFileReceived, true); function onNextFileReceived(text) { @@ -1298,11 +1298,11 @@ What is the lastFile pointer? filePath = EXCHANGE_NAME + "/Output/" + TRADES_FOLDER_NAME + '/' + dateForPath; - utilities.createFolderIfNeeded(filePath, azureFileStorage, onFolderCreated); + utilities.createFolderIfNeeded(filePath, charlyFileStorage, onFolderCreated); function onFolderCreated() { - azureFileStorage.createTextFile(filePath, fileName, fileContent + '\n', onFileCreated); + charlyFileStorage.createTextFile(filePath, fileName, fileContent + '\n', onFileCreated); function onFileCreated() { @@ -1374,7 +1374,7 @@ What is the lastFile pointer? let reportFilePath = EXCHANGE_NAME + "/Processes/" + bot.process + "/" + year + "/" + month; - utilities.createFolderIfNeeded(reportFilePath, azureFileStorage, onFolderCreated); + utilities.createFolderIfNeeded(reportFilePath, charlyFileStorage, onFolderCreated); function onFolderCreated() { @@ -1433,7 +1433,7 @@ What is the lastFile pointer? let fileContent = JSON.stringify(report); - azureFileStorage.createTextFile(reportFilePath, fileName, fileContent + '\n', onFileBCreated); + charlyFileStorage.createTextFile(reportFilePath, fileName, fileContent + '\n', onFileBCreated); function onFileBCreated() { @@ -1489,7 +1489,7 @@ What is the lastFile pointer? let reportFilePath = EXCHANGE_NAME + "/Processes/" + bot.process; - utilities.createFolderIfNeeded(reportFilePath, azureFileStorage, onFolderCreated); + utilities.createFolderIfNeeded(reportFilePath, charlyFileStorage, onFolderCreated); function onFolderCreated() { @@ -1520,7 +1520,7 @@ What is the lastFile pointer? let fileContent = JSON.stringify(report); - azureFileStorage.createTextFile(reportFilePath, fileName, fileContent + '\n', onFileBCreated); + charlyFileStorage.createTextFile(reportFilePath, fileName, fileContent + '\n', onFileBCreated); function onFileBCreated() { @@ -1575,7 +1575,7 @@ What is the lastFile pointer? /* Lets read the main status report */ - azureFileStorage.getTextFile(reportFilePath, fileName, onFileReceived, true); + charlyFileStorage.getTextFile(reportFilePath, fileName, onFileReceived, true); function onFileReceived(text) { @@ -1611,7 +1611,7 @@ What is the lastFile pointer? let reportFilePath = EXCHANGE_NAME + "/Processes/" + bot.process + "/" + initialYear + "/" + paddedInitialMonth; let fileName = "Status.Report." + market.assetA + '_' + market.assetB + ".json"; - azureFileStorage.getTextFile(reportFilePath, fileName, onStatusReportFileReceived, true); + charlyFileStorage.getTextFile(reportFilePath, fileName, onStatusReportFileReceived, true); function onStatusReportFileReceived(text) { @@ -1653,7 +1653,7 @@ What is the lastFile pointer? let reportFilePath = EXCHANGE_NAME + "/Processes/" + bot.process; let fileName = "Status.Report." + market.assetA + '_' + market.assetB + ".json"; - azureFileStorage.getTextFile(reportFilePath, fileName, onFileReceived, true); + charlyFileStorage.getTextFile(reportFilePath, fileName, onFileReceived, true); function onFileReceived(text) { @@ -1673,7 +1673,7 @@ What is the lastFile pointer? let fileContent = JSON.stringify(statusReport); - azureFileStorage.createTextFile(reportFilePath, fileName, fileContent + '\n', onMasterFileCreated); + charlyFileStorage.createTextFile(reportFilePath, fileName, fileContent + '\n', onMasterFileCreated); function onMasterFileCreated() { diff --git a/Poloniex-Live-Trades/Interval.js b/Poloniex-Live-Trades/User.bot.js similarity index 90% rename from Poloniex-Live-Trades/Interval.js rename to Poloniex-Live-Trades/User.bot.js index 2ce41620d..075c0951a 100644 --- a/Poloniex-Live-Trades/Interval.js +++ b/Poloniex-Live-Trades/User.bot.js @@ -1,59 +1,68 @@ -exports.newInterval = function newInterval(BOT, UTILITIES, AZURE_FILE_STORAGE, DEBUG_MODULE, MARKETS_MODULE, POLONIEX_CLIENT_MODULE) { +exports.newUserBot = function newUserBot(BOT, COMMONS, UTILITIES, DEBUG_MODULE, FILE_STORAGE, STATUS_REPORT, POLONIEX_CLIENT_MODULE) { + + const FULL_LOG = true; + const LOG_FILE_CONTENT = false; let bot = BOT; - const ROOT_DIR = './'; + const GMT_SECONDS = ':00.000 GMT+0000'; const GMT_MILI_SECONDS = '.000 GMT+0000'; - const MODULE_NAME = "Interval"; - const LOG_INFO = true; + const MODULE_NAME = "User Bot"; const EXCHANGE_NAME = "Poloniex"; - const EXCHANGE_ID = 1; const TRADES_FOLDER_NAME = "Trades"; - const GO_RANDOM = false; - const FORCE_MARKET = 2; // This allows to debug the execution of an specific market. Not intended for production. - const FORCED_INITIAL_TIME = undefined; //"2018-01-19 12:15:00.000 GMT+0000" - const logger = DEBUG_MODULE.newDebugLog(); logger.fileName = MODULE_NAME; logger.bot = bot; - interval = { + thisObject = { initialize: initialize, start: start }; - let markets; - - let azureFileStorage = AZURE_FILE_STORAGE.newAzureFileStorage(bot); + let charlyFileStorage = FILE_STORAGE.newFileStorage(bot); let utilities = UTILITIES.newUtilities(bot); return interval; - function initialize(pYear, pMonth, callBackFunction) { // Year and Month ignored at this process. + function initialize(yearAssigend, monthAssigned, callBackFunction) { try { - const logText = "[INFO] initialize - Entering function 'initialize' "; - console.log(logText); - logger.write(logText); + /* IMPORTANT NOTE: - azureFileStorage.initialize(); + We are ignoring in this UserBot the received Year and Month. thisObject is not depending on Year / Month. - markets = MARKETS_MODULE.newMarkets(bot); - markets.initialize(callBackFunction); + */ + 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); } + + charlyFileStorage.initialize("AACharly", onCharlyInizialized); + + function onCharlyInizialized(err) { + + if (err.result === global.DEFAULT_OK_RESPONSE.result) { + + if (FULL_LOG === true) { logger.write("[INFO] initialize -> onCharlyInizialized -> Initialization Succeed."); } + callBackFunction(global.DEFAULT_OK_RESPONSE); + + } else { + logger.write("[ERROR] initialize -> onCharlyInizialized -> err = " + err.message); + callBackFunction(err); + } + } } catch (err) { - - const logText = "[ERROR] initialize - ' ERROR : " + err.message; - console.log(logText); - logger.write(logText); - + logger.write("[ERROR] initialize -> err = " + err.message); + callBackFunction(global.DEFAULT_FAIL_RESPONSE); } } @@ -64,11 +73,9 @@ We are going to generate 2 files: A. The first one will contain all the trades of the current minute and will be store in a folder that we will create for this if it does not exist. This file will be incomplete, since we are at the current minute and some trades will happen after we retrieve the information from the exchange, but this is not a problem, since the second file is going to fix this. This file is only usefull for viewing a partial candle as it is being built -at the end of the chart. +at the head of the market. -B. The second file will contain all the trades of the previous minute. It will be the definitive file the system will use. - -Besides that, we are going to delete the A file of the previous minute, since it is not needed anymore after the B file is there. +B. The second file will contain all the trades of the previous minute. This will override the incomplete file written a minute before. FILE FORMAT ----------- @@ -156,15 +163,15 @@ Array of records with this information: filePathA = EXCHANGE_NAME + "/Output/" + TRADES_FOLDER_NAME + '/' + dateForPathA; filePathB = EXCHANGE_NAME + "/Output/" + TRADES_FOLDER_NAME + '/' + dateForPathB; - utilities.createFolderIfNeeded(filePathA, azureFileStorage, onFolderACreated); + utilities.createFolderIfNeeded(filePathA, charlyFileStorage, onFolderACreated); function onFolderACreated() { - utilities.createFolderIfNeeded(filePathB, azureFileStorage, onFolderBCreated); + utilities.createFolderIfNeeded(filePathB, charlyFileStorage, onFolderBCreated); function onFolderBCreated() { - utilities.createFolderIfNeeded(reportFilePath, azureFileStorage, onFolderCreated); + utilities.createFolderIfNeeded(reportFilePath, charlyFileStorage, onFolderCreated); function onFolderCreated() { @@ -462,7 +469,7 @@ Array of records with this information: fileContent = fileContent + ']'; - azureFileStorage.createTextFile(filePathA, fileNameA, fileContent + '\n', onFirstFileACreated); + charlyFileStorage.createTextFile(filePathA, fileNameA, fileContent + '\n', onFirstFileACreated); function onFirstFileACreated() { @@ -517,7 +524,7 @@ Array of records with this information: fileContent = fileContent + ']'; - azureFileStorage.createTextFile(filePathB, fileNameB, fileContent + '\n', onFileBCreated); + charlyFileStorage.createTextFile(filePathB, fileNameB, fileContent + '\n', onFileBCreated); function onFileBCreated() { @@ -569,7 +576,7 @@ Array of records with this information: let fileName = "Status.Report." + market.assetA + '_' + market.assetB + ".json" - azureFileStorage.getTextFile(reportFilePath, fileName, onFileReceived, true); + charlyFileStorage.getTextFile(reportFilePath, fileName, onFileReceived, true); function onFileReceived(text) { @@ -633,7 +640,7 @@ Array of records with this information: let fileContent = JSON.stringify(report); - azureFileStorage.createTextFile(reportFilePath, fileName, fileContent + '\n', onReportFileCreated); + charlyFileStorage.createTextFile(reportFilePath, fileName, fileContent + '\n', onReportFileCreated); function onReportFileCreated() { diff --git a/Project.njsproj b/Project.njsproj index bc821fd73..27e653411 100644 --- a/Project.njsproj +++ b/Project.njsproj @@ -21,7 +21,7 @@ - +