From 370fbb33c06fe31cc2abad7e792180dac47bf9c6 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Mon, 5 Mar 2018 20:23:03 +0100 Subject: [PATCH] Exchange API migration completed --- .vs/AAMariam-Trading-Bot/v15/.suo | Bin 27648 -> 27648 bytes Trading-Process/Interval.js | 117 ++++++------------------------ 2 files changed, 23 insertions(+), 94 deletions(-) diff --git a/.vs/AAMariam-Trading-Bot/v15/.suo b/.vs/AAMariam-Trading-Bot/v15/.suo index ec670f22dff60a066a654d914e1e8d51901ea39c..25d2d6041e5758168dba216511581fbf32927927 100644 GIT binary patch delta 749 zcma)3&r1S96yBL#b+Oq(U4NyarA29lghAJ8AtFhMt_7Vs2XoKvd#HW=1$*ugE<}ee zfd?U}g)aUfUb<9oWX%-}eDE0Nd*A!sH}jf3((IAP8YK)CX)bUphpwOCihi<^BuP=s z9}Kuj7lF$U@fieE%x?sjypQ9iC#sp2s*@PDWHut6 z6!WC#@l1NyES__i2}~U`?wqNY3bbhj`s`F)MQCWz;aWrXDs^oDYrZmY&9tH&RnSEY zUe%8xGk`2H^AF`QmkCpTb>RAkMg%1|M$I)CMPTSxs0PIUNbr?BV#0oYjGuDZng@*L zrA;f*aXR@OGPOg~-lUdp41D?>Ib5$3jr{AWu1@90UZQrM+AGvv4_YOIi5dG-?7mFW0A6!h2z$h0N1stPTYH62L@dA`2Tt{{ cORb_eGCO%>>$nh$y!rah6-hdAsu$hxF9Qk_p8x;= delta 803 zcmZ`$J!{)g6qTMO`;k1Q$X_xItz5eaj-ifIk~M_dOTpBJW($UNXgUYp56BPD65Z?p zkugJJEg1{R(7|ArwvaXdAcF^&Lfd<#2+6JU;69$tIrqGCpN?+Tqg(Z&!_+doV77jL z`Rn5;9I|h4!Ub<+#cpDkQ?>~3 zrO`_X_P;DlLj92xq_NBCgH{;L{LU#%3}m}-%{D;h#)3df6Oq1r-c=1nM<@zSCK@G& zsWs-$5@MK?M&zVd5p>|E-Q{aZS{BEmhCuWrK^$p0ZuZM#i5$1t7Fq0}XNy9C?1V{| zXTS}|&9{s|m7XE;U1-^TDBEXZ?jZiO%9&STZfD+I&G~nEtIRF7g9rO($dRGYl=OSz z#5iT6EmDXT61XoLj_TFY-fJ_@sb2JOrGV-KZ hlb#@V!o+zb;sEQ;;9WIm-i0Q?euaC*-~2FK_zOJfIU)c6 diff --git a/Trading-Process/Interval.js b/Trading-Process/Interval.js index 9a4e9107b..303c14caf 100644 --- a/Trading-Process/Interval.js +++ b/Trading-Process/Interval.js @@ -1,4 +1,4 @@ -exports.newInterval = function newInterval(BOT, UTILITIES, AZURE_FILE_STORAGE, DEBUG_MODULE, MARKETS_MODULE, exchangeAPI) { +exports.newInterval = function newInterval(BOT, UTILITIES, FILE_STORAGE, DEBUG_MODULE, MARKETS_MODULE, exchangeAPI) { let bot = BOT; @@ -34,10 +34,10 @@ let fs = require('fs'); - let charlyAzureFileStorage = AZURE_FILE_STORAGE.newAzureFileStorage(bot); - let oliviaAzureFileStorage = AZURE_FILE_STORAGE.newAzureFileStorage(bot); - let tomAzureFileStorage = AZURE_FILE_STORAGE.newAzureFileStorage(bot); - let mariamAzureFileStorage = AZURE_FILE_STORAGE.newAzureFileStorage(bot); + let charlyAzureFileStorage = FILE_STORAGE.newAzureFileStorage(bot); + let oliviaAzureFileStorage = FILE_STORAGE.newAzureFileStorage(bot); + let tomAzureFileStorage = FILE_STORAGE.newAzureFileStorage(bot); + let mariamAzureFileStorage = FILE_STORAGE.newAzureFileStorage(bot); let utilities = UTILITIES.newUtilities(bot); @@ -1118,92 +1118,15 @@ function movePositionAtExchange(pPosition, pNewRate, callBackFunction) { - poloniexApiClient.moveOrder(pPosition.id, pNewRate, pPosition.amountB, onExchangeCallReturned); + exchangeAPI.movePosition(pPosition, pNewRate, onResponse); - function onExchangeCallReturned(err, exchangeResponse) { + function onResponse(err, pPositionId) { - try { - - if (err || exchangeResponse.error !== undefined) { - try { - - if (err.message.indexOf("ETIMEDOUT") > 0 || err.message.indexOf("Order execution timed out") > 0) { - - const logText = "[WARN] movePositionAtExchange - onExchangeCallReturned - Timeout reached while trying to access the Exchange API. Requesting new execution later. : ERROR = " + err.message; - logger.write(logText); - - /* We abort the process and request a new execution at the configured amount of time. */ - - callBackFunction(true, nextIntervalLapse); - return; - - } else { - - if (err.message.indexOf("ECONNRESET") > 0) { - - const logText = "[WARN] movePositionAtExchange - onExchangeCallReturned - The exchange reseted the connection. Requesting new execution later. : ERROR = " + err.message; - logger.write(logText); - - /* We abort the process and request a new execution at the configured amount of time. */ - - callBackFunction(true, nextIntervalLapse); - return; - - } else { - - - const logText = "[ERROR] movePositionAtExchange -onExchangeCallReturned - Unexpected error trying to contact the Exchange. This will halt this bot process. : ERROR = " + err.message; - logger.write(logText); - return; - } - } - - } catch (err) { - const logText = "[ERROR] movePositionAtExchange - onExchangeCallReturned : ERROR : exchangeResponse.error = " + exchangeResponse.error; - logger.write(logText); - return; - } - - return; - - } else { - - /* - - This is what we can receive from the exchange. We will ignore the trades list for now, and analize - what happened at the next bot execution. - - { - "orderNumber":31226040, - "resultingTrades": - [{ - "amount":"338.8732", - "date":"2014-10-18 23:03:21", - "rate":"0.00000173", - "total":"0.00058625", - "tradeID":"16164", - "type":"buy" - }] - } - - */ - - /* - - We will add this new position to the executionContext. - - */ - - if (exchangeResponse.success !== 1) { - - const logText = "[ERROR] movePositionAtExchange -onExchangeCallReturned - Exchange said operation was not successful. Since we do not know what this means we will halt this bot process. : ERROR = " + err.message; - logger.write(logText); - return; - - } + switch (err) { + case null: { // Everything went well, we have the information requested. let newPosition = { - id: exchangeResponse.orderNumber, + id: pPositionId, type: pPosition.type, rate: pNewRate, amountA: pPosition.amountB * pNewRate, @@ -1238,16 +1161,22 @@ newHistoryRecord.movedPositions++; newHistoryRecord.rate = pNewRate; - callBackFunction(); + callBack(); } - } - catch (err) { - const logText = "[ERROR] 'movePositionAtExchange -onExchangeCallReturned' - ERROR : " + err.message; - logger.write(logText); - + break; + case 'Retry Later.': { // Something bad happened, but if we retry in a while it might go through the next time. + logger.write("[ERROR] getPositionsAtExchange -> onResponse -> Retry Later. Requesting Interval Retry."); + callBackFunction(true, nextIntervalLapse); + return; + } + break; + case 'Operation Failed.': { // This is an unexpected exception that we do not know how to handle. + logger.write("[ERROR] getPositionsAtExchange -> onResponse -> Operation Failed. Aborting the process."); + return; + } + break; } } - } function writeStatusAndContext() {