From d0f70d3d9f120525740ec0460b2924445ed7837a Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Fri, 9 Mar 2018 08:38:42 +0100 Subject: [PATCH] Logging Improved --- .vs/AACloudPlatform/v15/.suo | Bin 76800 -> 76800 bytes Assistant.js | 28 ++++++++++++++++++++ Context.js | 48 ++++++++++++++++++++++------------- Datasource.js | 23 +++++++++++++++++ ExchangeAPI.js | 33 ++++++++++++++++++++++++ 5 files changed, 115 insertions(+), 17 deletions(-) diff --git a/.vs/AACloudPlatform/v15/.suo b/.vs/AACloudPlatform/v15/.suo index 73b8b33245e4a61383703860cf2da3852e25fcf2..9d7b38d67ff5964f0f233f843d976fc032f443ec 100644 GIT binary patch delta 1953 zcmchYe@t6d6vy9r{XuyvC{kIMv94pdVOtpy=1^mJi!7U(2>gMU7f(goGelh#~$!)btND4$tk{Ss z4iL{0^VD|XNnN3}nMN%{EAb++o7h9Ri7ONp(AVk0oG+zpIi)j}l9WYT{{PGqH`>L105_K?YBTCsG%`y6|+W9j^FmRtBW(Y`%<_ zW)2hF?ucKxjm1*=9o*hxrMclH7Ns7Zz^0qrMkhs^2;Tnp{BEZF+7{-QN%>)v`g+!6nisET2~HMW z?9r6+b4cb%N}7+k7M>z_J-8-#Ew~(ok=;O`x-{FciwqCJrj~ZWf3fT`p9lxB z$?Dc^q;1A=&iX63SagM3A9vT1do1C;eWj@5>D2ox3R$_MUxddon%^b{B-XO#7m1(6 zJ#KB1v!ulUH7vT(o`HRpRwh@Uk)Q^D*uDk}L_PM^8!=ov!i=>h)7ANA)rgTTCXBQ@ zw39QWv_s2)*K^{J=?WGwK@NFye9 zC>m6bI+hEU5z*!NyD|>d05@E6Z3nEaBFuz zhPwt4jz{1`EaKx=zJval_10@e6c-A%i+tF5-VQ}r-jj-_PNc(v)tIxlOrLQJ&_1!Y zLS036E>^G?I?vj`*tyjP)65YX7GE~N!}!UdQMZl)GuUINoRGyIzC?SK3>Q)Q$NH6# zZ!;3l1P?n*OJ@&N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xEcyN9o{WW+uVHgP9E@QoIaU_JT%~bO#J7R zh@?crSvssW`jcoSdyY6yNZ-9agB;=`dT3-Ndi`FS@aDO4CxF4w0e)Ngvcn6z`V>yZa1!XhLJT36?SQLIy7V8aoxMgS#@{8L!M6r;MR+UpuAS I0}m8`0;G@sIsgCw diff --git a/Assistant.js b/Assistant.js index 169a7c3cc..206534dd9 100644 --- a/Assistant.js +++ b/Assistant.js @@ -48,6 +48,7 @@ switch (err.result) { case global.DEFAULT_OK_RESPONSE.result: { + logger.write("[INFO] initialize -> onDone -> Execution finished well. :-)"); callBackFunction(global.DEFAULT_OK_RESPONSE); return; } @@ -82,6 +83,8 @@ try { + if (FULL_LOG === true) { logger.write("[INFO] getPositionsAtExchange -> Entering function."); } + /* Here we grab all the positions at the exchange for the account we are using for trading. We will not asume all the positions @@ -94,8 +97,12 @@ function onResponse(err, pExchangePositions) { + if (FULL_LOG === true) { logger.write("[INFO] getPositionsAtExchange -> onResponse -> Entering function."); } + if (FULL_LOG === true) { logger.write("[INFO] getPositionsAtExchange -> onResponse -> pExchangePositions = " + pExchangePositions); } + switch (err.result) { case global.DEFAULT_OK_RESPONSE.result: { // Everything went well, we have the information requested. + logger.write("[INFO] getPositionsAtExchange -> onResponse -> Execution finished well. :-)"); exchangePositions = pExchangePositions; ordersExecutionCheck(callBack); return; @@ -124,6 +131,9 @@ function ordersExecutionCheck(callBack) { try { + + if (FULL_LOG === true) { logger.write("[INFO] ordersExecutionCheck -> Entering function."); } + /* Here we check that all the positions we know we have are still at the exchange. If they are not, we will try to take appropiate @@ -423,13 +433,23 @@ function putPositionAtExchange(pType, pRate, pAmountA, pAmountB, callBack) { try { + if (FULL_LOG === true) { logger.write("[INFO] putPositionAtExchange -> Entering function."); } + if (FULL_LOG === true) { logger.write("[INFO] putPositionAtExchange -> pType = " + pType); } + if (FULL_LOG === true) { logger.write("[INFO] putPositionAtExchange -> pRate = " + pRate); } + if (FULL_LOG === true) { logger.write("[INFO] putPositionAtExchange -> pAmountA = " + pAmountA); } + if (FULL_LOG === true) { logger.write("[INFO] putPositionAtExchange -> pAmountB = " + pAmountB); } + exchangeAPI.putPosition(global.MARKET, pType, pRate, pAmountA, pAmountB, onResponse); function onResponse(err, pPositionId) { try { + if (FULL_LOG === true) { logger.write("[INFO] putPositionAtExchange -> onResponse -> Entering function."); } + if (FULL_LOG === true) { logger.write("[INFO] putPositionAtExchange -> onResponse -> pPositionId = " + pPositionId); } + switch (err.result) { case global.DEFAULT_OK_RESPONSE.result: { // Everything went well, we have the information requested. + logger.write("[INFO] putPositionAtExchange -> onResponse -> Execution finished well. :-)"); let position = { id: pPositionId, @@ -485,13 +505,21 @@ function movePositionAtExchange(pPosition, pNewRate, callBack) { try { + if (FULL_LOG === true) { logger.write("[INFO] movePositionAtExchange -> Entering function."); } + if (FULL_LOG === true) { logger.write("[INFO] movePositionAtExchange -> pPosition = " + pPosition); } + if (FULL_LOG === true) { logger.write("[INFO] movePositionAtExchange -> pNewRate = " + pNewRate); } + exchangeAPI.movePosition(pPosition, pNewRate, onResponse); function onResponse(err, pPositionId) { try { + if (FULL_LOG === true) { logger.write("[INFO] movePositionAtExchange -> onResponse -> Entering function."); } + if (FULL_LOG === true) { logger.write("[INFO] movePositionAtExchange -> onResponse -> pPositionId = " + pPositionId); } + switch (err.result) { case global.DEFAULT_OK_RESPONSE.result: { // Everything went well, we have the information requested. + logger.write("[INFO] movePositionAtExchange -> onResponse -> Execution finished well. :-)"); let newPosition = { id: pPositionId, diff --git a/Context.js b/Context.js index 4a5662d24..1f4da0342 100644 --- a/Context.js +++ b/Context.js @@ -97,7 +97,7 @@ getStatusReport(onDone); } else { - logger.write("[ERROR] initialize -> initializeStorage -> err = " + err.message); + logger.write("[ERROR] initialize -> initializeStorage -> onInizialized -> err = " + err.message); callBackFunction(err); } } @@ -142,6 +142,9 @@ let fileName = "Status.Report.json" let filePath = bot.devTeam + "/" + bot.codeName + "/" + bot.dataSetVersion + "/Processes/" + bot.process + "/" + global.EXCHANGE_NAME; + if (FULL_LOG === true) { logger.write("[INFO] initialize -> getStatusReport -> fileName = " + fileName); } + if (FULL_LOG === true) { logger.write("[INFO] initialize -> getStatusReport -> filePath = " + filePath); } + cloudStorage.getTextFile(filePath, fileName, onFileReceived); function onFileReceived(err, text) { @@ -183,7 +186,7 @@ } } catch (err) { - logger.write("[ERROR] initialize -> getExecutionHistory -> err = " + err.message); + logger.write("[ERROR] initialize -> getStatusReport -> err = " + err.message); callBack(global.DEFAULT_FAIL_RESPONSE); } } @@ -191,11 +194,15 @@ function getExecutionHistory(callBack) { try { + if (FULL_LOG === true) { logger.write("[INFO] initialize -> getExecutionHistory -> Entering function."); } let fileName = "Execution.History.json" let filePath = bot.devTeam + "/" + bot.codeName + "/" + bot.dataSetVersion + "/Output/" + bot.process + "/" + global.EXCHANGE_NAME; + if (FULL_LOG === true) { logger.write("[INFO] initialize -> getExecutionHistory -> fileName = " + fileName); } + if (FULL_LOG === true) { logger.write("[INFO] initialize -> getExecutionHistory -> filePath = " + filePath); } + cloudStorage.getTextFile(filePath, fileName, onFileReceived); function onFileReceived(err, text) { @@ -239,6 +246,7 @@ function getExecutionContext(callBack) { try { + if (FULL_LOG === true) { logger.write("[INFO] initialize -> getExecutionContext -> Entering function."); } let date = new Date(thisObject.statusReport.lastExecution); @@ -247,6 +255,9 @@ let dateForPath = date.getUTCFullYear() + '/' + utilities.pad(date.getUTCMonth() + 1, 2) + '/' + utilities.pad(date.getUTCDate(), 2) + '/' + utilities.pad(date.getUTCHours(), 2) + '/' + utilities.pad(date.getUTCMinutes(), 2); let filePath = bot.devTeam + "/" + bot.codeName + "/" + bot.dataSetVersion + "/Output/" + bot.process + "/" + global.EXCHANGE_NAME + "/" + dateForPath; + if (FULL_LOG === true) { logger.write("[INFO] initialize -> getExecutionContext -> fileName = " + fileName); } + if (FULL_LOG === true) { logger.write("[INFO] initialize -> getExecutionContext -> filePath = " + filePath); } + cloudStorage.getTextFile(filePath, fileName, onFileReceived); function onFileReceived(err, text) { @@ -341,7 +352,7 @@ switch (err.result) { case global.DEFAULT_OK_RESPONSE.result: { - logger.write("[INFO] initialize -> onDone -> Execution finished well. :-)"); + logger.write("[INFO] saveThemAll -> onDone -> Execution finished well. :-)"); callBackFunction(global.DEFAULT_OK_RESPONSE); return; } @@ -368,16 +379,17 @@ function writeExecutionContext(callBack) { - if (FULL_LOG === true) { - logger.write("[INFO] saveThemAll -> writeExecutionContext -> Entering function."); - } - try { + if (FULL_LOG === true) { logger.write("[INFO] saveThemAll -> writeExecutionContext -> Entering function."); } + let fileName = "Execution.Context.json" let dateForPath = global.processDatetime.getUTCFullYear() + '/' + utilities.pad(global.processDatetime.getUTCMonth() + 1, 2) + '/' + utilities.pad(global.processDatetime.getUTCDate(), 2) + '/' + utilities.pad(global.processDatetime.getUTCHours(), 2) + '/' + utilities.pad(global.processDatetime.getUTCMinutes(), 2); let filePath = bot.devTeam + "/" + bot.codeName + "/" + bot.dataSetVersion + "/Output/" + bot.process + "/" + global.EXCHANGE_NAME + "/" + dateForPath; + if (FULL_LOG === true) { logger.write("[INFO] saveThemAll -> writeExecutionContext -> fileName = " + fileName); } + if (FULL_LOG === true) { logger.write("[INFO] saveThemAll -> writeExecutionContext -> filePath = " + filePath); } + utilities.createFolderIfNeeded(filePath, cloudStorage, onFolderCreated); function onFolderCreated(err) { @@ -397,13 +409,13 @@ function onFileCreated(err) { if (err.result !== global.DEFAULT_OK_RESPONSE.result) { - logger.write("[ERROR] saveThemAll -> writeExucutionHistory -> onFolderCreated -> onFileCreated -> err = " + err.message); + logger.write("[ERROR] saveThemAll -> writeExecutionContext -> onFolderCreated -> onFileCreated -> err = " + err.message); callBack(err); return; } if (FULL_LOG === true) { - logger.write("[INFO] saveThemAll -> writeExucutionHistory -> onFolderCreated -> onFileCreated -> Content written = " + fileContent); + logger.write("[INFO] saveThemAll -> writeExecutionContext -> onFolderCreated -> onFileCreated -> Content written = " + fileContent); } writeExucutionHistory(callBack); @@ -424,15 +436,16 @@ function writeExucutionHistory(callBack) { - if (FULL_LOG === true) { - logger.write("[INFO] saveThemAll -> writeExucutionHistory -> Entering function."); - } - try { + if (FULL_LOG === true) { logger.write("[INFO] saveThemAll -> writeExucutionHistory -> Entering function."); } + let fileName = "Execution.History.json" let filePath = bot.devTeam + "/" + bot.codeName + "/" + bot.dataSetVersion + "/Output/" + bot.process + "/" + global.EXCHANGE_NAME; + if (FULL_LOG === true) { logger.write("[INFO] saveThemAll -> writeExucutionHistory -> fileName = " + fileName); } + if (FULL_LOG === true) { logger.write("[INFO] saveThemAll -> writeExucutionHistory -> filePath = " + filePath); } + utilities.createFolderIfNeeded(filePath, cloudStorage, onFolderCreated); function onFolderCreated(err) { @@ -489,15 +502,16 @@ function writeStatusReport(callBack) { - if (FULL_LOG === true) { - logger.write("[INFO] saveThemAll -> writeStatusReport -> Entering function."); - } - try { + if (FULL_LOG === true) { logger.write("[INFO] saveThemAll -> writeStatusReport -> Entering function."); } + let fileName = "Status.Report.json" let filePath = bot.devTeam + "/" + bot.codeName + "/" + bot.dataSetVersion + "/Processes/" + bot.process + "/" + global.EXCHANGE_NAME; + if (FULL_LOG === true) { logger.write("[INFO] saveThemAll -> writeStatusReport -> fileName = " + fileName); } + if (FULL_LOG === true) { logger.write("[INFO] saveThemAll -> writeStatusReport -> filePath = " + filePath); } + utilities.createFolderIfNeeded(filePath, cloudStorage, onFolderCreated); function onFolderCreated(err) { diff --git a/Datasource.js b/Datasource.js index 015307ec7..6a46d044d 100644 --- a/Datasource.js +++ b/Datasource.js @@ -43,6 +43,8 @@ function initializeOliviaStorage() { + if (FULL_LOG === true) { logger.write("[INFO] initializeOliviaStorage -> Entering function."); } + oliviaAzureFileStorage.initialize("AAOlivia", onInizialized); function onInizialized(err) { @@ -57,6 +59,8 @@ function initializeTomStorage() { + if (FULL_LOG === true) { logger.write("[INFO] initializeTomStorage -> Entering function."); } + tomAzureFileStorage.initialize("AATom", onInizialized); function onInizialized(err) { @@ -103,6 +107,8 @@ try { + if (FULL_LOG === true) { logger.write("[INFO] getCandles -> Entering function."); } + /* We will read several files with candles for the current day. We will use these files as an input @@ -116,6 +122,8 @@ try { + if (FULL_LOG === true) { logger.write("[INFO] getCandles -> getMarketFiles -> Entering function."); } + let filesOk = 0; let filesNotOk = 0; @@ -160,6 +168,8 @@ try { + if (FULL_LOG === true) { logger.write("[INFO] getCandles -> getDailyFiles -> Entering function."); } + let filesOk = 0; let filesNotOk = 0; @@ -203,6 +213,9 @@ function getCandlesWeAreIn() { try { + + if (FULL_LOG === true) { logger.write("[INFO] getCandles -> getCandlesWeAreIn -> Entering function."); } + let counter = 0; thisObject.candlesFiles.forEach(getCurrentCandles); @@ -272,6 +285,9 @@ function getPatterns(callBack) { try { + + if (FULL_LOG === true) { logger.write("[INFO] getPatterns -> Entering function."); } + /* We will read several files with pattern calculations for the current day. We will use these files as an input @@ -285,6 +301,8 @@ try { + if (FULL_LOG === true) { logger.write("[INFO] getPatterns -> getMarketFiles -> Entering function."); } + let filesOk = 0; let filesNotOk = 0; @@ -329,6 +347,8 @@ try { + if (FULL_LOG === true) { logger.write("[INFO] getPatterns -> getDailyFiles -> Entering function."); } + let filesOk = 0; let filesNotOk = 0; @@ -372,6 +392,9 @@ function getStairsWeAreIn() { try { + + if (FULL_LOG === true) { logger.write("[INFO] getPatterns -> getStairsWeAreIn -> Entering function."); } + let counter = 0; thisObject.stairsFiles.forEach(getCurrentStairs); diff --git a/ExchangeAPI.js b/ExchangeAPI.js index b94f505d5..6afc989b7 100644 --- a/ExchangeAPI.js +++ b/ExchangeAPI.js @@ -67,12 +67,19 @@ try { + if (FULL_LOG === true) { logger.write("[INFO] getOpenPositions -> Entering function."); } + if (FULL_LOG === true) { logger.write("[INFO] getOpenPositions -> pMarket = " + pMarket); } + poloniexApiClient.returnOpenOrders(pMarket.assetA, pMarket.assetB, onExchangeCallReturned); function onExchangeCallReturned(err, exchangeResponse) { try { + if (FULL_LOG === true) { logger.write("[INFO] getOpenPositions -> onExchangeCallReturned -> Entering function."); } + if (FULL_LOG === true) { logger.write("[INFO] getOpenPositions -> onExchangeCallReturned -> err = " + err); } + if (FULL_LOG === true) { logger.write("[INFO] getOpenPositions -> onExchangeCallReturned -> exchangeResponse = " + exchangeResponse); } + if (err || exchangeResponse.error !== undefined) { try { @@ -154,12 +161,19 @@ try { + if (FULL_LOG === true) { logger.write("[INFO] getExecutedTrades -> Entering function."); } + if (FULL_LOG === true) { logger.write("[INFO] getExecutedTrades -> pPositionId = " + pPositionId); } + poloniexApiClient.returnOrderTrades(pPositionId, onExchangeCallReturned); function onExchangeCallReturned(err, exchangeResponse) { try { + if (FULL_LOG === true) { logger.write("[INFO] getExecutedTrades -> onExchangeCallReturned -> Entering function."); } + if (FULL_LOG === true) { logger.write("[INFO] getExecutedTrades -> onExchangeCallReturned -> err = " + err); } + if (FULL_LOG === true) { logger.write("[INFO] getExecutedTrades -> onExchangeCallReturned -> exchangeResponse = " + exchangeResponse); } + if (err || exchangeResponse.error !== undefined) { try { @@ -247,6 +261,13 @@ try { + if (FULL_LOG === true) { logger.write("[INFO] putPosition -> Entering function."); } + if (FULL_LOG === true) { logger.write("[INFO] putPosition -> pMarket = " + pMarket); } + if (FULL_LOG === true) { logger.write("[INFO] putPosition -> pType = " + pType); } + if (FULL_LOG === true) { logger.write("[INFO] putPosition -> pRate = " + pRate); } + if (FULL_LOG === true) { logger.write("[INFO] putPosition -> pAmountA = " + pAmountA); } + if (FULL_LOG === true) { logger.write("[INFO] putPosition -> pAmountB = " + pAmountB); } + if (pType === "buy") { poloniexApiClient.buy(pMarket.assetA, pMarket.assetB, pRate, pAmountB, onExchangeCallReturned); return; @@ -265,6 +286,10 @@ try { + if (FULL_LOG === true) { logger.write("[INFO] putPosition -> onExchangeCallReturned -> Entering function."); } + if (FULL_LOG === true) { logger.write("[INFO] putPosition -> onExchangeCallReturned -> err = " + err); } + if (FULL_LOG === true) { logger.write("[INFO] putPosition -> onExchangeCallReturned -> exchangeResponse = " + exchangeResponse); } + if (err || exchangeResponse.error !== undefined) { try { @@ -335,10 +360,18 @@ try { + if (FULL_LOG === true) { logger.write("[INFO] movePosition -> Entering function."); } + if (FULL_LOG === true) { logger.write("[INFO] putPosition -> pPosition = " + pPosition); } + if (FULL_LOG === true) { logger.write("[INFO] putPosition -> pNewRate = " + pNewRate); } + poloniexApiClient.moveOrder(pPosition.id, pNewRate, pPosition.amountB, onExchangeCallReturned); function onExchangeCallReturned(err, exchangeResponse) { + if (FULL_LOG === true) { logger.write("[INFO] movePosition -> onExchangeCallReturned -> Entering function."); } + if (FULL_LOG === true) { logger.write("[INFO] movePosition -> onExchangeCallReturned -> err = " + err); } + if (FULL_LOG === true) { logger.write("[INFO] movePosition -> onExchangeCallReturned -> exchangeResponse = " + exchangeResponse); } + try { if (err || exchangeResponse.error !== undefined) {