diff --git a/.vs/AACloudPlatform/v15/.suo b/.vs/AACloudPlatform/v15/.suo index 73b8b3324..9d7b38d67 100644 Binary files a/.vs/AACloudPlatform/v15/.suo and b/.vs/AACloudPlatform/v15/.suo differ 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) {