diff --git a/.vs/AACloud/v15/.suo b/.vs/AACloud/v15/.suo index 453ffb7a7..8a24d68e8 100644 Binary files a/.vs/AACloud/v15/.suo and b/.vs/AACloud/v15/.suo differ diff --git a/Context.js b/Context.js index 6a01a25b0..fa1acdcf6 100644 --- a/Context.js +++ b/Context.js @@ -160,7 +160,7 @@ getExecutionHistory(callBack); return; } - case global.CUSTOM_FAIL_RESPONSE.result: { // We need to see if we can handle this. + case global.CUSTOM_OK_RESPONSE.result: { // We need to see if we can handle this. logger.write("[ERROR] initialize -> getStatusReport -> err.message = " + err.message); if (err.message === "Status Report was never created.") { diff --git a/ExchangeAPI.js b/ExchangeAPI.js index 933b36a38..3a6c78ef1 100644 --- a/ExchangeAPI.js +++ b/ExchangeAPI.js @@ -80,7 +80,7 @@ if (FULL_LOG === true) { logger.write("[INFO] getOpenPositions -> onExchangeCallReturned -> err = " + err); } if (FULL_LOG === true) { logger.write("[INFO] getOpenPositions -> onExchangeCallReturned -> exchangeResponse = " + JSON.stringify(exchangeResponse)); } - analizeResponse(err, exchangeResponse, callBackFunction, onResponseOk); + poloniexApiClient.analizeResponse(logger, err, exchangeResponse, callBackFunction, onResponseOk); function onResponseOk() { @@ -146,7 +146,7 @@ if (FULL_LOG === true) { logger.write("[INFO] getExecutedTrades -> onExchangeCallReturned -> err = " + err); } if (FULL_LOG === true) { logger.write("[INFO] getExecutedTrades -> onExchangeCallReturned -> exchangeResponse = " + JSON.stringify(exchangeResponse)); } - analizeResponse(err, exchangeResponse, callBackFunction, onResponseOk); + poloniexApiClient.analizeResponse(logger, err, exchangeResponse, callBackFunction, onResponseOk); function onResponseOk() { @@ -235,7 +235,7 @@ if (FULL_LOG === true) { logger.write("[INFO] putPosition -> onExchangeCallReturned -> err = " + err); } if (FULL_LOG === true) { logger.write("[INFO] putPosition -> onExchangeCallReturned -> exchangeResponse = " + JSON.stringify(exchangeResponse)); } - analizeResponse(err, exchangeResponse, callBackFunction, onResponseOk); + poloniexApiClient.analizeResponse(logger, err, exchangeResponse, callBackFunction, onResponseOk); function onResponseOk() { @@ -291,7 +291,7 @@ try { - analizeResponse(err, exchangeResponse, callBackFunction, onResponseOk); + poloniexApiClient.analizeResponse(logger, err, exchangeResponse, callBackFunction, onResponseOk); function onResponseOk() { @@ -334,44 +334,4 @@ } } - function analizeResponse(err, exchangeResponse, callBackFunction, innerCallBack) { - - try { - - 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 || - JSON.stringify(exchangeResponse).indexOf("Connection Error") > 0 || - JSON.stringify(err).indexOf("ECONNRESET") > 0) - { - - 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 (err) { - - 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("[INFO] analizeResponse -> No problem found."); - innerCallBack(); - return; - } - } - - } catch (err) { - logger.write("[ERROR] analizeResponse -> err.message = " + err.message); - callBackFunction(global.DEFAULT_FAIL_RESPONSE); - return; - } - } }; \ No newline at end of file diff --git a/Poloniex API Client.js b/Poloniex API Client.js index d7e74a657..9ee3bf2b6 100644 --- a/Poloniex API Client.js +++ b/Poloniex API Client.js @@ -389,8 +389,49 @@ toggleAutoRenew: function (orderNumber, callback) { return this._private('toggleAutoRenew', { orderNumber: orderNumber }, callback); - } + }, + analizeResponse: function (logger, exchangeErr, exchangeResponse, notOkCallBack, okCallBack) { + + /* This function analizes the different situations we might encounter trying to access Poloniex and returns appropiate standard errors. */ + + try { + + logger.write("[INFO] analizeResponse -> exchangeErr = " + JSON.stringify(exchangeErr)); + logger.write("[INFO] analizeResponse -> exchangeResponse = " + JSON.stringify(exchangeResponse)); + + if ( + JSON.stringify(exchangeErr).indexOf("ETIMEDOUT") > 0 || + JSON.stringify(exchangeResponse).indexOf("Connection timed out") > 0 || + JSON.stringify(exchangeResponse).indexOf("Connection Error") > 0 || + JSON.stringify(exchangeErr).indexOf("ECONNRESET") > 0) { + + logger.write("[WARN] analizeResponse -> Timeout reached or connection problem while trying to access the Exchange API. Requesting new execution later."); + notOkCallBack(global.DEFAULT_RETRY_RESPONSE); + return; + + } else { + + if (exchangeErr) { + + logger.write("[ERROR] analizeResponse -> Unexpected error trying to contact the Exchange."); + notOkCallBack(global.DEFAULT_FAIL_RESPONSE); + return; + + } else { + + logger.write("[INFO] analizeResponse -> No problem found."); + okCallBack(); + return; + } + } + + } catch (err) { + logger.write("[ERROR] analizeResponse -> err.message = " + err.message); + notOkCallBack(global.DEFAULT_FAIL_RESPONSE); + return; + } + } }; // Backwards Compatibility @@ -403,4 +444,7 @@ Poloniex.prototype.myTradeHistory = Poloniex.prototype.returnTradeHistory; return Poloniex; -})(); \ No newline at end of file +})(); + + + diff --git a/Project.njsproj b/Project.njsproj index 3bd591ef9..6af1a8042 100644 --- a/Project.njsproj +++ b/Project.njsproj @@ -13,7 +13,7 @@ 14.0 $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) Project - Multi-Period-Daily + Trading-Process C:\Program Files\nodejs\node.exe False diff --git a/Run.js b/Run.js index 07afeb2b7..c5238708c 100644 --- a/Run.js +++ b/Run.js @@ -3,7 +3,7 @@ const FULL_LOG = true; /* The following global variable tells the system if it is running on test mode or production. */ -global.RUNNING_MODE = 'Mixed'; // 'Testnet' or 'Production' +global.RUNNING_MODE = 'Production'; // 'Testnet', 'Mixed' or 'Production' /* You do not have funds at the exchange and still want run your bot? No problem activate the exchange simulation mode: */ diff --git a/this.config.json b/this.config.json index 23049ff1b..53b059787 100644 --- a/this.config.json +++ b/this.config.json @@ -6,7 +6,7 @@ "patch": 0 }, "bot": { - "path": "../Bots/AAMasters/AAOlivia-Indicator-Bot" + "path": "../Bots/AAMasters/AAMariam-Trading-Bot" }, "stopGracefully": "false" } \ No newline at end of file