analizeResponse moved to Poloniex API Client
This commit is contained in:
1 parent
bc0fc1391c
commit
55aca58c1b
7 files changed
+54
-50
No files matched your search
Binary file not shown.
+1
-1
@@ -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.") {
|
||||
|
||||
+4
-44
@@ -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;
|
||||
}
|
||||
}
|
||||
};
|
||||
+46
-2
@@ -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;
|
||||
})();
|
||||
})();
|
||||
|
||||
|
||||
|
||||
+1
-1
@@ -13,7 +13,7 @@
|
||||
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">14.0</VisualStudioVersion>
|
||||
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
|
||||
<Name>Project</Name>
|
||||
<ScriptArguments>Multi-Period-Daily</ScriptArguments>
|
||||
<ScriptArguments>Trading-Process</ScriptArguments>
|
||||
<NodeExePath>C:\Program Files\nodejs\node.exe</NodeExePath>
|
||||
<StartWebBrowser>False</StartWebBrowser>
|
||||
</PropertyGroup>
|
||||
|
||||
@@ -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: */
|
||||
|
||||
|
||||
+1
-1
@@ -6,7 +6,7 @@
|
||||
"patch": 0
|
||||
},
|
||||
"bot": {
|
||||
"path": "../Bots/AAMasters/AAOlivia-Indicator-Bot"
|
||||
"path": "../Bots/AAMasters/AAMariam-Trading-Bot"
|
||||
},
|
||||
"stopGracefully": "false"
|
||||
}
|
||||
Reference in new issue
Block a user