First Debug Session Ended
This commit is contained in:
1 parent
32007193c5
commit
2134635f0c
13 files changed
+194
-171
No files matched your search
+33
-29
@@ -1,5 +1,7 @@
|
||||
exports.newExchangeAPI = function newExchangeAPI(BOT, DEBUG_MODULE, POLONIEX_CLIENT_MODULE) {
|
||||
|
||||
const FULL_LOG = true;
|
||||
|
||||
/*
|
||||
|
||||
This module allows trading bots to connect to the exchange and do trding operations on it. So far it can only work with Poloniex.
|
||||
@@ -29,10 +31,12 @@
|
||||
|
||||
try {
|
||||
|
||||
if (LOG_INFO === true) { logger.write("[INFO] initialize -> Entering function."); }
|
||||
|
||||
let apiKey = readApiKey();
|
||||
poloniexApiClient = new POLONIEX_CLIENT_MODULE(apiKey.Key, apiKey.Secret);
|
||||
|
||||
callBackFunction(DEFAULT_OK_RESPONSE);
|
||||
callBackFunction(global.DEFAULT_OK_RESPONSE);
|
||||
|
||||
function readApiKey() {
|
||||
|
||||
@@ -47,14 +51,14 @@
|
||||
logger.write("[HINT] The file must have the keys to access your poloniex account, in this format -> " + '{ "Key" : "4FB9TMEB-234VH2W1-BYJIXHGM-GL15DSA1", "Secret" : "1a24298skdjdf734uuyhbdagdasdtyut276587256hdsdas765asdasdasd76asdasda765asdasfas6asfda57657asd5a76sd5a7s65d7a6sd57as65d7as65d"}');
|
||||
logger.write("[HINT] You get this key logging in to your Poloniex web account, enabling API keys and getting a new one. ");
|
||||
logger.write("[HINT] Be sure not to allow withdrawls with this Key. When asked at the exchange key page, say no. ");
|
||||
callBackFunction(DEFAULT_FAIL_RESPONSE);
|
||||
callBackFunction(global.DEFAULT_FAIL_RESPONSE);
|
||||
}
|
||||
}
|
||||
|
||||
} catch (err) {
|
||||
|
||||
logger.write("[ERROR] initialize -> err = " + err.message);
|
||||
callBackFunction(DEFAULT_FAIL_RESPONSE);
|
||||
callBackFunction(global.DEFAULT_FAIL_RESPONSE);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -74,7 +78,7 @@
|
||||
if (err.message.indexOf("ETIMEDOUT") > 0) {
|
||||
|
||||
logger.write("[WARN] getOpenPositions -> onExchangeCallReturned -> Timeout reached while trying to access the Exchange API. Requesting new execution later. : ERROR = " + err.message);
|
||||
callBackFunction(DEFAULT_RETRY_RESPONSE);
|
||||
callBackFunction(global.DEFAULT_RETRY_RESPONSE);
|
||||
return;
|
||||
|
||||
} else {
|
||||
@@ -82,19 +86,19 @@
|
||||
if (err.message.indexOf("ECONNRESET") > 0) {
|
||||
|
||||
logger.write("[WARN] getOpenPositions -> onExchangeCallReturned -> The exchange reseted the connection. Requesting new execution later. : ERROR = " + err.message);
|
||||
callBackFunction(DEFAULT_RETRY_RESPONSE);
|
||||
callBackFunction(global.DEFAULT_RETRY_RESPONSE);
|
||||
return;
|
||||
|
||||
} else {
|
||||
logger.write("[ERROR] getOpenPositions -> onExchangeCallReturned -> Unexpected error trying to contact the Exchange. This will halt this bot process. : ERROR = " + err.message);
|
||||
callBackFunction(DEFAULT_FAIL_RESPONSE);
|
||||
callBackFunction(global.DEFAULT_FAIL_RESPONSE);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
} catch (err) {
|
||||
logger.write("[ERROR] getOpenPositions -> onExchangeCallReturned -> exchangeResponse.error = " + exchangeResponse.error);
|
||||
callBackFunction(DEFAULT_FAIL_RESPONSE);
|
||||
callBackFunction(global.DEFAULT_FAIL_RESPONSE);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -136,12 +140,12 @@
|
||||
}
|
||||
catch (err) {
|
||||
logger.write("[ERROR] getOpenPositions -> onExchangeCallReturned -> Error = " + err.message);
|
||||
callBackFunction(DEFAULT_FAIL_RESPONSE);
|
||||
callBackFunction(global.DEFAULT_FAIL_RESPONSE);
|
||||
}
|
||||
}
|
||||
} catch (err) {
|
||||
logger.write("[ERROR] getOpenPositions -> Error = " + err.message);
|
||||
callBackFunction(DEFAULT_FAIL_RESPONSE);
|
||||
callBackFunction(global.DEFAULT_FAIL_RESPONSE);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -161,7 +165,7 @@
|
||||
if (err.message.indexOf("ETIMEDOUT") > 0) {
|
||||
|
||||
logger.write("[WARN] getExecutedTrades -> onExchangeCallReturned -> Timeout reached while trying to access the Exchange API. Requesting new execution later. : ERROR = " + err.message);
|
||||
callBackFunction(DEFAULT_RETRY_RESPONSE);
|
||||
callBackFunction(global.DEFAULT_RETRY_RESPONSE);
|
||||
return;
|
||||
|
||||
} else {
|
||||
@@ -169,19 +173,19 @@
|
||||
if (err.message.indexOf("ECONNRESET") > 0) {
|
||||
|
||||
logger.write("[WARN] getExecutedTrades -> onExchangeCallReturned -> The exchange reseted the connection. Requesting new execution later. : ERROR = " + err.message);
|
||||
callBackFunction(DEFAULT_RETRY_RESPONSE);
|
||||
callBackFunction(global.DEFAULT_RETRY_RESPONSE);
|
||||
return;
|
||||
|
||||
} else {
|
||||
logger.write("[ERROR] getExecutedTrades -> onExchangeCallReturned -> Unexpected error trying to contact the Exchange. This will halt this bot process. : ERROR = " + err.message);
|
||||
callBackFunction(DEFAULT_FAIL_RESPONSE);
|
||||
callBackFunction(global.DEFAULT_FAIL_RESPONSE);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
} catch (err) {
|
||||
logger.write("[ERROR] getExecutedTrades -> onExchangeCallReturned -> exchangeResponse.error = " + exchangeResponse.error);
|
||||
callBackFunction(DEFAULT_FAIL_RESPONSE);
|
||||
callBackFunction(global.DEFAULT_FAIL_RESPONSE);
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
@@ -229,12 +233,12 @@
|
||||
}
|
||||
catch (err) {
|
||||
logger.write("[ERROR] getExecutedTrades -> onExchangeCallReturned -> Error = " + err.message);
|
||||
callBackFunction(DEFAULT_FAIL_RESPONSE);
|
||||
callBackFunction(global.DEFAULT_FAIL_RESPONSE);
|
||||
}
|
||||
}
|
||||
} catch (err) {
|
||||
logger.write("[ERROR] getExecutedTrades -> Error = " + err.message);
|
||||
callBackFunction(DEFAULT_FAIL_RESPONSE);
|
||||
callBackFunction(global.DEFAULT_FAIL_RESPONSE);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -253,7 +257,7 @@
|
||||
}
|
||||
|
||||
logger.write("[ERROR] putPosition -> pType must be either 'buy' or 'sell'.");
|
||||
callBackFunction(DEFAULT_FAIL_RESPONSE);
|
||||
callBackFunction(global.DEFAULT_FAIL_RESPONSE);
|
||||
return;
|
||||
|
||||
function onExchangeCallReturned(err, exchangeResponse) {
|
||||
@@ -266,7 +270,7 @@
|
||||
if (err.message.indexOf("ETIMEDOUT") > 0) {
|
||||
|
||||
logger.write("[WARN] putPosition -> onExchangeCallReturned -> Timeout reached while trying to access the Exchange API. Requesting new execution later. : ERROR = " + err.message);
|
||||
callBackFunction(DEFAULT_RETRY_RESPONSE);
|
||||
callBackFunction(global.DEFAULT_RETRY_RESPONSE);
|
||||
return;
|
||||
|
||||
} else {
|
||||
@@ -274,19 +278,19 @@
|
||||
if (err.message.indexOf("ECONNRESET") > 0) {
|
||||
|
||||
logger.write("[WARN] putPosition -> onExchangeCallReturned -> The exchange reseted the connection. Requesting new execution later. : ERROR = " + err.message);
|
||||
callBackFunction(DEFAULT_RETRY_RESPONSE);
|
||||
callBackFunction(global.DEFAULT_RETRY_RESPONSE);
|
||||
return;
|
||||
|
||||
} else {
|
||||
logger.write("[ERROR] putPosition -> onExchangeCallReturned -> Unexpected error trying to contact the Exchange. This will halt this bot process. : ERROR = " + err.message);
|
||||
callBackFunction(DEFAULT_FAIL_RESPONSE);
|
||||
callBackFunction(global.DEFAULT_FAIL_RESPONSE);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
} catch (err) {
|
||||
logger.write("[ERROR] putPosition -> onExchangeCallReturned -> exchangeResponse.error = " + exchangeResponse.error);
|
||||
callBackFunction(DEFAULT_FAIL_RESPONSE);
|
||||
callBackFunction(global.DEFAULT_FAIL_RESPONSE);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -316,13 +320,13 @@
|
||||
}
|
||||
catch (err) {
|
||||
logger.write("[ERROR] putPosition -> onExchangeCallReturned -> Error = " + err.message);
|
||||
callBackFunction(DEFAULT_FAIL_RESPONSE);
|
||||
callBackFunction(global.DEFAULT_FAIL_RESPONSE);
|
||||
}
|
||||
}
|
||||
|
||||
} catch (err) {
|
||||
logger.write("[ERROR] putPosition -> err = " + err.message);
|
||||
callBackFunction(DEFAULT_FAIL_RESPONSE);
|
||||
callBackFunction(global.DEFAULT_FAIL_RESPONSE);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -342,7 +346,7 @@
|
||||
if (err.message.indexOf("ETIMEDOUT") > 0) {
|
||||
|
||||
logger.write("[WARN] movePosition -> onExchangeCallReturned -> Timeout reached while trying to access the Exchange API. Requesting new execution later. : ERROR = " + err.message);
|
||||
callBackFunction(DEFAULT_RETRY_RESPONSE);
|
||||
callBackFunction(global.DEFAULT_RETRY_RESPONSE);
|
||||
return;
|
||||
|
||||
} else {
|
||||
@@ -350,19 +354,19 @@
|
||||
if (err.message.indexOf("ECONNRESET") > 0) {
|
||||
|
||||
logger.write("[WARN] movePosition -> onExchangeCallReturned -> The exchange reseted the connection. Requesting new execution later. : ERROR = " + err.message);
|
||||
callBackFunction(DEFAULT_RETRY_RESPONSE);
|
||||
callBackFunction(global.DEFAULT_RETRY_RESPONSE);
|
||||
return;
|
||||
|
||||
} else {
|
||||
logger.write("[ERROR] movePosition -> onExchangeCallReturned -> Unexpected error trying to contact the Exchange. This will halt this bot process. : ERROR = " + err.message);
|
||||
callBackFunction(DEFAULT_FAIL_RESPONSE);
|
||||
callBackFunction(global.DEFAULT_FAIL_RESPONSE);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
} catch (err) {
|
||||
logger.write("[ERROR] movePosition -> onExchangeCallReturned -> exchangeResponse.error = " + exchangeResponse.error);
|
||||
callBackFunction(DEFAULT_FAIL_RESPONSE);
|
||||
callBackFunction(global.DEFAULT_FAIL_RESPONSE);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -370,7 +374,7 @@
|
||||
|
||||
if (exchangeResponse.success !== 1) {
|
||||
logger.write("[ERROR] movePosition -> onExchangeCallReturned -> exchangeResponse.success = " + exchangeResponse.success);
|
||||
callBackFunction(DEFAULT_FAIL_RESPONSE);
|
||||
callBackFunction(global.DEFAULT_FAIL_RESPONSE);
|
||||
return;
|
||||
}
|
||||
/*
|
||||
@@ -397,13 +401,13 @@
|
||||
}
|
||||
catch (err) {
|
||||
logger.write("[ERROR] movePosition -> onExchangeCallReturned -> Error = " + err.message);
|
||||
callBackFunction(DEFAULT_FAIL_RESPONSE);
|
||||
callBackFunction(global.DEFAULT_FAIL_RESPONSE);
|
||||
}
|
||||
}
|
||||
|
||||
} catch (err) {
|
||||
logger.write("[ERROR] movePosition -> err = " + err.message);
|
||||
callBackFunction(DEFAULT_FAIL_RESPONSE);
|
||||
callBackFunction(global.DEFAULT_FAIL_RESPONSE);
|
||||
}
|
||||
}
|
||||
};
|
||||
Reference in new issue
Block a user