From d803cea5cb3f80bb3689423ea9531399e1072ee5 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Tue, 13 Mar 2018 16:18:45 +0100 Subject: [PATCH] New case of exchange connection problem --- .vs/AACloudPlatform/v15/.suo | Bin 72192 -> 76800 bytes Context.js | 2 +- ExchangeAPI.js | 54 +++++++++++++++++------------------ 3 files changed, 27 insertions(+), 29 deletions(-) diff --git a/.vs/AACloudPlatform/v15/.suo b/.vs/AACloudPlatform/v15/.suo index 3ce3bc9e2a59cbf7b465346a2a0548b2cc7f6803..65e2cac23a5b7d37e7c96237b4f014c6dc9bfa61 100644 GIT binary patch delta 2082 zcmbtVe@xX?6u;;D10Js@@x)L9$9qPKsLzK%2n_oY$Q-luk(6axZmp)00*|+hOumy9 zrm@L8$!jJ0d@AB91TISR5B*xLNugpWwpt9gY|hG}q)44~?h6dmQtP~ZcJI08e9!%y z&%Jj~Z&CCwl}%2�D*bvC%Y@30DUO2E?kECp5WYq>#oe?(RN-CDJ-*;(d|~(iOl< zasXCftx^fDYFFIke9B%xSVt%zL=&jcz@owNDH@j$p2io|3{~t=RPBniyJ@L}AQsls zxSAk78?u-2jJg6s(JsY>*)Hel-3K}$9X(PxG-01K&m{63^bPut*w86iaJ8%xJANrN z4}w9FfOEsXHHjSpB6Fs>ND&UcZ;pil-exX?Fc?JQH zPt>EBJ$5nL#`ZMF8ekEv2nZ#4`}leZs?cLASDzsNEdF7;3?;nJ{<(Tx;-ooJwD@eu z-k|iy2pb7cHo5jfby0lt)Y4!zM+F2cg^82;LC93?O6AGU4!d2P*#^Q;88KFp|0W?= zlHZ?yDqYpd&Bmrh_u!Z+4I6$>gq>Jk6@#(Q#Zx(MRHe(e$U&p}k*Vp0A9Yw;9%lad zyzyU9$)Jf75hirXXCAhaIoNXM#x(DKsh?r5w*pEKQXcnp1H|Twy9tCjPB!vKYk%AS z-w1!*T%eW`6^4hs4{@VL2Q+qTTzgxWQSxc1)$6El(Y&>Vkq@w3Hk-|0(^x8zn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DfC^)x!HdCKLG*H z_8h*kHcz+kmvz&;I(RU{#Wam85A4tzA?G4`!{U6^Bx+))@$e=5eg(>d1NbAYI{k!Fw-l|tzU+f%< xUxjNML@r;ERNhDsJd?tItjU`MA@R45*$G(|Ou> diff --git a/Context.js b/Context.js index 826341bbe..d1f36bd15 100644 --- a/Context.js +++ b/Context.js @@ -5,7 +5,7 @@ /* - This module allows trading bots to connect to the exchange and do trding operations on it. So far it can only work with Poloniex. + This module allows deals with keeping the context between different executions of the bot. It deals with these 3 different files that helps the bot process remember where it is standing: 1. The Status Report. diff --git a/ExchangeAPI.js b/ExchangeAPI.js index 9163b3fe8..933b36a38 100644 --- a/ExchangeAPI.js +++ b/ExchangeAPI.js @@ -4,7 +4,7 @@ /* - This module allows trading bots to connect to the exchange and do trding operations on it. So far it can only work with Poloniex. + This module allows trading bots to connect to the exchange and do trading operations on it. So far it can only work with Poloniex. */ @@ -80,11 +80,9 @@ if (FULL_LOG === true) { logger.write("[INFO] getOpenPositions -> onExchangeCallReturned -> err = " + err); } if (FULL_LOG === true) { logger.write("[INFO] getOpenPositions -> onExchangeCallReturned -> exchangeResponse = " + JSON.stringify(exchangeResponse)); } - if (err || exchangeResponse.error !== undefined || JSON.stringify(exchangeResponse).indexOf("Connection timed out") > 0) { + analizeResponse(err, exchangeResponse, callBackFunction, onResponseOk); - somethingWentWrong(err, exchangeResponse, callBackFunction); - - } else { + function onResponseOk() { /* @@ -148,11 +146,9 @@ if (FULL_LOG === true) { logger.write("[INFO] getExecutedTrades -> onExchangeCallReturned -> err = " + err); } if (FULL_LOG === true) { logger.write("[INFO] getExecutedTrades -> onExchangeCallReturned -> exchangeResponse = " + JSON.stringify(exchangeResponse)); } - if (err || exchangeResponse.error !== undefined || JSON.stringify(exchangeResponse).indexOf("Connection timed out") > 0) { + analizeResponse(err, exchangeResponse, callBackFunction, onResponseOk); - somethingWentWrong(err, exchangeResponse, callBackFunction); - - } else { + function onResponseOk() { /* @@ -239,11 +235,9 @@ if (FULL_LOG === true) { logger.write("[INFO] putPosition -> onExchangeCallReturned -> err = " + err); } if (FULL_LOG === true) { logger.write("[INFO] putPosition -> onExchangeCallReturned -> exchangeResponse = " + JSON.stringify(exchangeResponse)); } - if (err || exchangeResponse.error !== undefined || JSON.stringify(exchangeResponse).indexOf("Connection timed out") > 0) { + analizeResponse(err, exchangeResponse, callBackFunction, onResponseOk); - somethingWentWrong(err, exchangeResponse, callBackFunction); - - } else { + function onResponseOk() { /* @@ -297,11 +291,9 @@ try { - if (err || exchangeResponse.error !== undefined || JSON.stringify(exchangeResponse).indexOf("Connection timed out") > 0) { + analizeResponse(err, exchangeResponse, callBackFunction, onResponseOk); - somethingWentWrong(err, exchangeResponse, callBackFunction); - - } else { + function onResponseOk() { if (exchangeResponse.success !== 1) { logger.write("[ERROR] movePosition -> onExchangeCallReturned -> exchangeResponse.success = " + exchangeResponse.success); @@ -342,36 +334,42 @@ } } - function somethingWentWrong(err, exchangeResponse, callBackFunction) { + function analizeResponse(err, exchangeResponse, callBackFunction, innerCallBack) { try { - logger.write("[WARN] somethingWentWrong -> err = " + JSON.stringify(err)); - logger.write("[WARN] somethingWentWrong -> exchangeResponse = " + JSON.stringify(exchangeResponse)); + logger.write("[INFO] analizeResponse -> err = " + JSON.stringify(err)); + logger.write("[INFO] analizeResponse -> exchangeResponse = " + JSON.stringify(exchangeResponse)); - if (JSON.stringify(err).indexOf("ETIMEDOUT") > 0 || JSON.stringify(exchangeResponse).indexOf("Connection timed out") > 0) { + if ( + JSON.stringify(err).indexOf("ETIMEDOUT") > 0 || + JSON.stringify(exchangeResponse).indexOf("Connection timed out") > 0 || + JSON.stringify(exchangeResponse).indexOf("Connection Error") > 0 || + JSON.stringify(err).indexOf("ECONNRESET") > 0) + { - logger.write("[WARN] somethingWentWrong -> Timeout reached while trying to access the Exchange API. Requesting new execution later."); + logger.write("[WARN] analizeResponse -> Timeout reached or connection problem while trying to access the Exchange API. Requesting new execution later."); callBackFunction(global.DEFAULT_RETRY_RESPONSE); return; } else { - if (JSON.stringify(err).indexOf("ECONNRESET") > 0) { + if (err) { - logger.write("[WARN] somethingWentWrong -> The exchange reseted the connection. Requesting new execution later."); - callBackFunction(global.DEFAULT_RETRY_RESPONSE); + logger.write("[ERROR] analizeResponse -> Unexpected error trying to contact the Exchange. This will halt this bot process."); + callBackFunction(global.DEFAULT_FAIL_RESPONSE); return; } else { - logger.write("[ERROR] somethingWentWrong -> Unexpected error trying to contact the Exchange. This will halt this bot process."); - callBackFunction(global.DEFAULT_FAIL_RESPONSE); + + logger.write("[INFO] analizeResponse -> No problem found."); + innerCallBack(); return; } } } catch (err) { - logger.write("[ERROR] somethingWentWrong -> err.message = " + err.message); + logger.write("[ERROR] analizeResponse -> err.message = " + err.message); callBackFunction(global.DEFAULT_FAIL_RESPONSE); return; }