Adding multi exchange support fixes
This commit is contained in:
1 parent
8cfff9a076
commit
52b5cea91c
8 files changed
+187
-136
No files matched your search
@@ -32,6 +32,7 @@ function newCloudVM() {
|
||||
window.CURRENT_EXECUTION_AT = "Browser";
|
||||
window.STORAGE_PERMISSIONS = ecosystem.getStoragePermissions();
|
||||
|
||||
window.EXCHANGE_NAME = "Poloniex";
|
||||
window.MARKET = {
|
||||
assetA: "USDT",
|
||||
assetB: "BTC"
|
||||
|
||||
+66
-54
@@ -3,28 +3,25 @@
|
||||
const INFO_LOG = true;
|
||||
const LOG_FILE_CONTENT = true;
|
||||
|
||||
const MODULE_NAME = "CloudVM -> Poloniex Client API";
|
||||
|
||||
const MODULE_NAME = "CloudVM -> Exchange API";
|
||||
|
||||
let thisObject = {
|
||||
API: {
|
||||
returnOpenOrders: returnOpenOrders,
|
||||
returnOrderTrades: returnOrderTrades,
|
||||
buy: buy,
|
||||
sell: sell,
|
||||
moveOrder: moveOrder,
|
||||
returnTicker: returnTicker
|
||||
}
|
||||
initialize: initialize,
|
||||
getTicker: getTicker,
|
||||
getOpenPositions: getOpenPositions,
|
||||
getExecutedTrades: getExecutedTrades,
|
||||
putPosition: putPosition,
|
||||
movePosition: movePosition,
|
||||
getPublicTradeHistory: getPublicTradeHistory
|
||||
};
|
||||
|
||||
return thisObject;
|
||||
|
||||
function returnOpenOrders(pMarketAssetA, pMarketAssetB, callBackFunction) {
|
||||
function initialize(callBackFunction) {
|
||||
|
||||
let path = "ExchangeAPI" + "/"
|
||||
+ "returnOpenOrders" + "/"
|
||||
+ window.SESSION_TOKEN + "/"
|
||||
+ pMarketAssetA + "/"
|
||||
+ pMarketAssetB
|
||||
let path = "ExchangeAPI" + "/"
|
||||
+ "initialize" + "/"
|
||||
+ window.SESSION_TOKEN
|
||||
;
|
||||
|
||||
callServer(undefined, path + "/NO-LOG", onServerResponse);
|
||||
@@ -32,15 +29,49 @@
|
||||
function onServerResponse(pServerResponse) {
|
||||
|
||||
let response = JSON.parse(pServerResponse);
|
||||
callBackFunction(response.err, response.exchangeResponse);
|
||||
callBackFunction(response);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
function returnOrderTrades(pPositionId, callBackFunction) {
|
||||
function getTicker(pMarket, callBackFunction) {
|
||||
|
||||
let path = "ExchangeAPI" + "/"
|
||||
+ "returnOrderTrades" + "/"
|
||||
+ "getTicker" + "/"
|
||||
+ window.SESSION_TOKEN
|
||||
;
|
||||
|
||||
callServer(undefined, path + "/NO-LOG", onServerResponse);
|
||||
|
||||
function onServerResponse(pServerResponse) {
|
||||
|
||||
let response = JSON.parse(pServerResponse);
|
||||
callBackFunction(response);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
function getOpenPositions(pMarket, callBackFunction) {
|
||||
|
||||
let path = "ExchangeAPI" + "/"
|
||||
+ "getOpenPositions" + "/"
|
||||
+ window.SESSION_TOKEN
|
||||
;
|
||||
|
||||
callServer(undefined, path + "/NO-LOG", onServerResponse);
|
||||
|
||||
function onServerResponse(pServerResponse) {
|
||||
|
||||
let response = JSON.parse(pServerResponse);
|
||||
callBackFunction(response);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
function getExecutedTrades(pPositionId, callBackFunction) {
|
||||
|
||||
let path = "ExchangeAPI" + "/"
|
||||
+ "getExecutedTrades" + "/"
|
||||
+ window.SESSION_TOKEN + "/"
|
||||
+ pPositionId
|
||||
;
|
||||
@@ -50,19 +81,19 @@
|
||||
function onServerResponse(pServerResponse) {
|
||||
|
||||
let response = JSON.parse(pServerResponse);
|
||||
callBackFunction(response.err, response.exchangeResponse);
|
||||
callBackFunction(response);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
function buy(pMarketAssetA, pMarketAssetB, pRate, pAmountB, callBackFunction) {
|
||||
|
||||
function putPosition(pMarket, pType, pRate, pAmountA, pAmountB, callBackFunction) {
|
||||
|
||||
let path = "ExchangeAPI" + "/"
|
||||
+ "buy" + "/"
|
||||
+ "putPosition" + "/"
|
||||
+ window.SESSION_TOKEN + "/"
|
||||
+ pMarketAssetA + "/"
|
||||
+ pMarketAssetB + "/"
|
||||
+ pType + "/"
|
||||
+ pRate + "/"
|
||||
+ pAmountA + "/"
|
||||
+ pAmountB
|
||||
;
|
||||
|
||||
@@ -71,36 +102,15 @@
|
||||
function onServerResponse(pServerResponse) {
|
||||
|
||||
let response = JSON.parse(pServerResponse);
|
||||
callBackFunction(response.err, response.exchangeResponse);
|
||||
callBackFunction(response);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
function sell(pMarketAssetA, pMarketAssetB, pRate, pAmountB, callBackFunction) {
|
||||
function movePosition(pPositionId, pNewRate, pPositionAmountB, callBackFunction) {
|
||||
|
||||
let path = "ExchangeAPI" + "/"
|
||||
+ "sell" + "/"
|
||||
+ window.SESSION_TOKEN + "/"
|
||||
+ pMarketAssetA + "/"
|
||||
+ pMarketAssetB + "/"
|
||||
+ pRate + "/"
|
||||
+ pAmountB
|
||||
;
|
||||
|
||||
callServer(undefined, path + "/NO-LOG", onServerResponse);
|
||||
|
||||
function onServerResponse(pServerResponse) {
|
||||
|
||||
let response = JSON.parse(pServerResponse);
|
||||
callBackFunction(response.err, response.exchangeResponse);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
function moveOrder(pPositionId, pNewRate, pPositionAmountB, callBackFunction) {
|
||||
|
||||
let path = "ExchangeAPI" + "/"
|
||||
+ "moveOrder" + "/"
|
||||
+ "movePosition" + "/"
|
||||
+ window.SESSION_TOKEN + "/"
|
||||
+ pPositionId + "/"
|
||||
+ pNewRate + "/"
|
||||
@@ -112,16 +122,18 @@
|
||||
function onServerResponse(pServerResponse) {
|
||||
|
||||
let response = JSON.parse(pServerResponse);
|
||||
callBackFunction(response.err, response.exchangeResponse);
|
||||
callBackFunction(response);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
function returnTicker(callBackFunction) {
|
||||
function getPublicTradeHistory(pMarket, startTime, endTime, callBackFunction) {
|
||||
|
||||
let path = "ExchangeAPI" + "/"
|
||||
+ "returnTicker" + "/"
|
||||
+ window.SESSION_TOKEN
|
||||
+ "getPublicTradeHistory" + "/"
|
||||
+ window.SESSION_TOKEN + "/"
|
||||
+ startTime + "/"
|
||||
+ endTime
|
||||
;
|
||||
|
||||
callServer(undefined, path + "/NO-LOG", onServerResponse);
|
||||
@@ -129,7 +141,7 @@
|
||||
function onServerResponse(pServerResponse) {
|
||||
|
||||
let response = JSON.parse(pServerResponse);
|
||||
callBackFunction(response.err, response.exchangeResponse);
|
||||
callBackFunction(response);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
exports.newExchangeAPI = function newExchangeAPI(bot, logger) {
|
||||
exports.newExchangeAPI = function newExchangeAPI() {
|
||||
|
||||
/*
|
||||
|
||||
@@ -29,18 +29,16 @@
|
||||
function initialize(callBackFunction) {
|
||||
try {
|
||||
|
||||
if (global.LOG_CONTROL[MODULE_NAME].logInfo === true) { logger.write(MODULE_NAME, "[INFO] initialize -> Entering function."); }
|
||||
if (CONSOLE_LOG === true) { console.log("[INFO] initialize -> Entering function."); }
|
||||
|
||||
let exchange = global.EXCHANGE_NAME.toLowerCase() + 'Client.js';
|
||||
let api = require('./Wrappers/' + exchange);
|
||||
if (!bot.instanceIndex)
|
||||
bot.instanceIndex = 0;
|
||||
apiClient = api.newAPIClient(global.EXCHANGE_KEYS[global.EXCHANGE_NAME][bot.instanceIndex].Key, global.EXCHANGE_KEYS[global.EXCHANGE_NAME][bot.instanceIndex].Secret, logger);
|
||||
apiClient = api.newAPIClient(global.EXCHANGE_KEYS[global.EXCHANGE_NAME].Key, global.EXCHANGE_KEYS[global.EXCHANGE_NAME].Secret);
|
||||
|
||||
callBackFunction(global.DEFAULT_OK_RESPONSE);
|
||||
|
||||
} catch (err) {
|
||||
logger.write(MODULE_NAME, "[ERROR] initialize -> err = " + err.message);
|
||||
console.log("[ERROR] initialize -> err = " + err.message);
|
||||
callBackFunction(global.DEFAULT_FAIL_RESPONSE);
|
||||
}
|
||||
}
|
||||
@@ -84,12 +82,12 @@
|
||||
function getExchangeProperties() {
|
||||
try {
|
||||
|
||||
if (global.LOG_CONTROL[MODULE_NAME].logInfo === true) { logger.write(MODULE_NAME, "[INFO] getExchangeProperties -> Entering function."); }
|
||||
if (CONSOLE_LOG === true) { console.log("[INFO] getExchangeProperties -> Entering function."); }
|
||||
|
||||
return apiClient.getExchangeProperties();
|
||||
|
||||
} catch (err) {
|
||||
logger.write(MODULE_NAME, "[ERROR] getExchangeProperties -> err = " + err.message);
|
||||
console.log("[ERROR] getExchangeProperties -> err = " + err.message);
|
||||
callBack(global.DEFAULT_FAIL_RESPONSE);
|
||||
}
|
||||
}
|
||||
@@ -106,12 +104,12 @@
|
||||
function getTicker(pMarket, callBack) {
|
||||
try {
|
||||
|
||||
if (global.LOG_CONTROL[MODULE_NAME].logInfo === true) { logger.write(MODULE_NAME, "[INFO] getTicker -> Entering function."); }
|
||||
if (CONSOLE_LOG === true) { console.log("[INFO] getTicker -> Entering function."); }
|
||||
|
||||
apiClient.getTicker(pMarket, callBack);
|
||||
|
||||
} catch (err) {
|
||||
logger.write(MODULE_NAME, "[ERROR] getTicker -> err = " + err.message);
|
||||
console.log("[ERROR] getTicker -> err = " + err.message);
|
||||
callBack(global.DEFAULT_FAIL_RESPONSE);
|
||||
}
|
||||
}
|
||||
@@ -124,13 +122,13 @@
|
||||
function getOpenPositions(pMarket, callBack) {
|
||||
try {
|
||||
|
||||
if (global.LOG_CONTROL[MODULE_NAME].logInfo === true) { logger.write(MODULE_NAME, "[INFO] getOpenPositions -> Entering function."); }
|
||||
if (global.LOG_CONTROL[MODULE_NAME].logInfo === true) { logger.write(MODULE_NAME, "[INFO] getOpenPositions -> pMarket = " + JSON.stringify(pMarket)); }
|
||||
if (CONSOLE_LOG === true) { console.log("[INFO] getOpenPositions -> Entering function."); }
|
||||
if (CONSOLE_LOG === true) { console.log("[INFO] getOpenPositions -> pMarket = " + JSON.stringify(pMarket)); }
|
||||
|
||||
apiClient.getOpenPositions(pMarket, callBack);
|
||||
|
||||
} catch (err) {
|
||||
logger.write(MODULE_NAME, "[ERROR] getOpenPositions -> Error = " + err.message);
|
||||
console.log("[ERROR] getOpenPositions -> Error = " + err.message);
|
||||
callBack(global.DEFAULT_FAIL_RESPONSE);
|
||||
}
|
||||
}
|
||||
@@ -142,13 +140,13 @@
|
||||
function getExecutedTrades(pPositionId, callBack) {
|
||||
try {
|
||||
|
||||
if (global.LOG_CONTROL[MODULE_NAME].logInfo === true) { logger.write(MODULE_NAME, "[INFO] getExecutedTrades -> Entering function."); }
|
||||
if (global.LOG_CONTROL[MODULE_NAME].logInfo === true) { logger.write(MODULE_NAME, "[INFO] getExecutedTrades -> pPositionId = " + pPositionId); }
|
||||
if (CONSOLE_LOG === true) { console.log("[INFO] getExecutedTrades -> Entering function."); }
|
||||
if (CONSOLE_LOG === true) { console.log("[INFO] getExecutedTrades -> pPositionId = " + pPositionId); }
|
||||
|
||||
apiClient.getExecutedTrades(pPositionId, callBack);
|
||||
|
||||
} catch (err) {
|
||||
logger.write(MODULE_NAME, "[ERROR] getExecutedTrades -> Error = " + err.message);
|
||||
console.log("[ERROR] getExecutedTrades -> Error = " + err.message);
|
||||
callBack(global.DEFAULT_FAIL_RESPONSE);
|
||||
}
|
||||
}
|
||||
@@ -160,12 +158,12 @@
|
||||
function putPosition(pMarket, pType, pRate, pAmountA, pAmountB, callBack) {
|
||||
try {
|
||||
|
||||
if (global.LOG_CONTROL[MODULE_NAME].logInfo === true) { logger.write(MODULE_NAME, "[INFO] putPosition -> Entering function."); }
|
||||
if (global.LOG_CONTROL[MODULE_NAME].logInfo === true) { logger.write(MODULE_NAME, "[INFO] putPosition -> pMarket = " + JSON.stringify(pMarket)); }
|
||||
if (global.LOG_CONTROL[MODULE_NAME].logInfo === true) { logger.write(MODULE_NAME, "[INFO] putPosition -> pType = " + pType); }
|
||||
if (global.LOG_CONTROL[MODULE_NAME].logInfo === true) { logger.write(MODULE_NAME, "[INFO] putPosition -> pRate = " + truncDecimals(pRate)); }
|
||||
if (global.LOG_CONTROL[MODULE_NAME].logInfo === true) { logger.write(MODULE_NAME, "[INFO] putPosition -> pAmountA = " + truncDecimals(pAmountA)); }
|
||||
if (global.LOG_CONTROL[MODULE_NAME].logInfo === true) { logger.write(MODULE_NAME, "[INFO] putPosition -> pAmountB = " + truncDecimals(pAmountB)); }
|
||||
if (CONSOLE_LOG === true) { console.log("[INFO] putPosition -> Entering function."); }
|
||||
if (CONSOLE_LOG === true) { console.log("[INFO] putPosition -> pMarket = " + JSON.stringify(pMarket)); }
|
||||
if (CONSOLE_LOG === true) { console.log("[INFO] putPosition -> pType = " + pType); }
|
||||
if (CONSOLE_LOG === true) { console.log("[INFO] putPosition -> pRate = " + truncDecimals(pRate)); }
|
||||
if (CONSOLE_LOG === true) { console.log("[INFO] putPosition -> pAmountA = " + truncDecimals(pAmountA)); }
|
||||
if (CONSOLE_LOG === true) { console.log("[INFO] putPosition -> pAmountB = " + truncDecimals(pAmountB)); }
|
||||
|
||||
let check = isValidOrder({
|
||||
market: getMarketConfig(),
|
||||
@@ -185,16 +183,16 @@
|
||||
return;
|
||||
}
|
||||
|
||||
logger.write(MODULE_NAME, "[ERROR] putPosition -> pType must be either 'buy' or 'sell'.");
|
||||
console.log("[ERROR] putPosition -> pType must be either 'buy' or 'sell'.");
|
||||
callBack(global.DEFAULT_FAIL_RESPONSE);
|
||||
|
||||
} else {
|
||||
logger.write(MODULE_NAME, "[ERROR] putPosition -> The order is invalid: " + check.reason);
|
||||
console.log("[ERROR] putPosition -> The order is invalid: " + check.reason);
|
||||
callBack(global.DEFAULT_FAIL_RESPONSE);
|
||||
}
|
||||
|
||||
} catch (err) {
|
||||
logger.write(MODULE_NAME, "[ERROR] putPosition -> err = " + err.message);
|
||||
console.log("[ERROR] putPosition -> err = " + err.message);
|
||||
callBack(global.DEFAULT_FAIL_RESPONSE);
|
||||
}
|
||||
}
|
||||
@@ -206,14 +204,14 @@
|
||||
function movePosition(pPosition, pNewRate, pNewAmountB, callBack) {
|
||||
try {
|
||||
|
||||
if (global.LOG_CONTROL[MODULE_NAME].logInfo === true) { logger.write(MODULE_NAME, "[INFO] movePosition -> Entering function."); }
|
||||
if (global.LOG_CONTROL[MODULE_NAME].logInfo === true) { logger.write(MODULE_NAME, "[INFO] movePosition -> pPosition = " + JSON.stringify(pPosition)); }
|
||||
if (global.LOG_CONTROL[MODULE_NAME].logInfo === true) { logger.write(MODULE_NAME, "[INFO] movePosition -> pNewRate = " + truncDecimals(pNewRate)); }
|
||||
if (CONSOLE_LOG === true) { console.log("[INFO] movePosition -> Entering function."); }
|
||||
if (CONSOLE_LOG === true) { console.log("[INFO] movePosition -> pPosition = " + JSON.stringify(pPosition)); }
|
||||
if (CONSOLE_LOG === true) { console.log("[INFO] movePosition -> pNewRate = " + truncDecimals(pNewRate)); }
|
||||
|
||||
apiClient.movePosition(pPosition, truncDecimals(pNewRate), truncDecimals(pNewAmountB), callBack);
|
||||
|
||||
} catch (err) {
|
||||
logger.write(MODULE_NAME, "[ERROR] movePosition -> err = " + err.message);
|
||||
console.log("[ERROR] movePosition -> err = " + err.message);
|
||||
callBack(global.DEFAULT_FAIL_RESPONSE);
|
||||
}
|
||||
}
|
||||
@@ -235,12 +233,12 @@
|
||||
function getPublicTradeHistory(assetA, assetB, startTime, endTime, callBack) {
|
||||
try {
|
||||
|
||||
if (global.LOG_CONTROL[MODULE_NAME].logInfo === true) { logger.write(MODULE_NAME, "[INFO] getTradeHistory -> Entering function."); }
|
||||
if (CONSOLE_LOG === true) { console.log("[INFO] getTradeHistory -> Entering function."); }
|
||||
|
||||
apiClient.getPublicTradeHistory(assetA, assetB, startTime, endTime, callBack);
|
||||
|
||||
} catch (err) {
|
||||
logger.write(MODULE_NAME, "[ERROR] getTradeHistory -> err = " + err.message);
|
||||
console.log("[ERROR] getTradeHistory -> err = " + err.message);
|
||||
callBack(global.DEFAULT_FAIL_RESPONSE);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
exports.newAPIClient = function newAPIClient(pKey, pSecret, logger) {
|
||||
exports.newAPIClient = function newAPIClient(pKey, pSecret) {
|
||||
|
||||
/*
|
||||
/* ATENTION: This Library is used both a the cloud (AACloud) and also at the AAWeb on the server side without any modifications.
|
||||
@@ -256,11 +256,11 @@
|
||||
orderId: pPosition.id
|
||||
};
|
||||
|
||||
if (global.LOG_CONTROL[MODULE_NAME].logInfo === true) { logger.write(MODULE_NAME, "[INFO] moveOrder -> Step1 - Cancelling Position: " + JSON.stringify(pPosition)); }
|
||||
if (global.LOG_CONTROL[MODULE_NAME].logInfo === true) { console.log("[INFO] moveOrder -> Step1 - Cancelling Position: " + JSON.stringify(pPosition)); }
|
||||
|
||||
const handle = (err, response) => {
|
||||
if (err.result === global.DEFAULT_OK_RESPONSE.result) {
|
||||
if (global.LOG_CONTROL[MODULE_NAME].logInfo === true) { logger.write(MODULE_NAME, "[INFO] moveOrder -> Step1 Complete - Position Cancelled. Proceeding to put the new position."); }
|
||||
if (global.LOG_CONTROL[MODULE_NAME].logInfo === true) { console.log("[INFO] moveOrder -> Step1 Complete - Position Cancelled. Proceeding to put the new position."); }
|
||||
|
||||
if (position.type === "buy")
|
||||
thisObject.buy(global.MARKET.assetA, global.MARKET.assetB, pNewRate, pNewAmountB, callBack);
|
||||
@@ -292,7 +292,7 @@
|
||||
*/
|
||||
function getPublicTradeHistory(assetA, assetB, startTime, endTime, callBack) {
|
||||
|
||||
if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] getPublicTradeHistory -> Not implemented yet."); }
|
||||
if (CONSOLE_LOG === true) { console.log("[INFO] getPublicTradeHistory -> Not implemented yet."); }
|
||||
callBack(global.DEFAULT_FAIL_RESPONSE);
|
||||
}
|
||||
|
||||
@@ -315,8 +315,8 @@
|
||||
let stringExchangeResponse = JSON.stringify(exchangeResponse);
|
||||
|
||||
try {
|
||||
if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] analizeResponse -> exchangeErr = " + stringExchangeErr); }
|
||||
if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] analizeResponse -> exchangeResponse = " + stringExchangeResponse); }
|
||||
if (CONSOLE_LOG === true) { console.log("[INFO] analizeResponse -> exchangeErr = " + stringExchangeErr); }
|
||||
if (CONSOLE_LOG === true) { console.log("[INFO] analizeResponse -> exchangeResponse = " + stringExchangeResponse); }
|
||||
|
||||
if (exchangeErr) {
|
||||
error = global.DEFAULT_FAIL_RESPONSE;
|
||||
@@ -351,7 +351,7 @@
|
||||
return callBack(error, exchangeResponse);
|
||||
|
||||
} catch (err) {
|
||||
logger.write(MODULE_NAME, "[ERROR] analizeResponse -> err.message = " + err.message);
|
||||
console.log("[ERROR] analizeResponse -> err.message = " + err.message);
|
||||
return callBack(global.DEFAULT_FAIL_RESPONSE, exchangeResponse);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
exports.newAPIClient = function newAPIClient(pKey, pSecret, logger) {
|
||||
exports.newAPIClient = function newAPIClient(pKey, pSecret) {
|
||||
|
||||
/*
|
||||
/* ATENTION: This Library is used both a the cloud (AACloud) and also at the AAWeb on the server side without any modifications.
|
||||
@@ -299,8 +299,8 @@
|
||||
let stringExchangeResponse = JSON.stringify(exchangeResponse);
|
||||
|
||||
try {
|
||||
if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] analizeResponse -> exchangeErr = " + stringExchangeErr); }
|
||||
if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] analizeResponse -> exchangeResponse = " + stringExchangeResponse); }
|
||||
if (FULL_LOG === true) { console.log("[INFO] analizeResponse -> exchangeErr = " + stringExchangeErr); }
|
||||
if (FULL_LOG === true) { console.log("[INFO] analizeResponse -> exchangeResponse = " + stringExchangeResponse); }
|
||||
|
||||
if (exchangeErr) {
|
||||
error = global.DEFAULT_FAIL_RESPONSE;
|
||||
@@ -344,7 +344,7 @@
|
||||
return callBack(error, exchangeResponse);
|
||||
|
||||
} catch (err) {
|
||||
logger.write(MODULE_NAME, "[ERROR] analizeResponse -> err.message = " + err.message);
|
||||
console.log("[ERROR] analizeResponse -> err.message = " + err.message);
|
||||
return callBack(global.DEFAULT_FAIL_RESPONSE, exchangeResponse);
|
||||
}
|
||||
}
|
||||
|
||||
Generated
+14
-4
@@ -13,7 +13,7 @@
|
||||
"debug": "3.1.0",
|
||||
"is-array-buffer": "1.0.0",
|
||||
"is-stream": "1.1.0",
|
||||
"lodash": "4.17.5",
|
||||
"lodash": "4.17.11",
|
||||
"url-template": "2.0.8"
|
||||
}
|
||||
},
|
||||
@@ -342,9 +342,9 @@
|
||||
}
|
||||
},
|
||||
"lodash": {
|
||||
"version": "4.17.5",
|
||||
"resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.5.tgz",
|
||||
"integrity": "sha512-svL3uiZf1RwhH+cWrfZn3A4+U58wbP0tGVTLQPbjplZxZ8ROD9VLuNgsRniTlLe7OlSqR79RUehXgpBW/s0IQw=="
|
||||
"version": "4.17.11",
|
||||
"resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.11.tgz",
|
||||
"integrity": "sha512-cQKh8igo5QUhZ7lg38DYWAxMvjSAKG0A8wGSVimP07SIUEK2UO+arSRKbRZWtelMtN5V0Hkwh5ryOto/SshYIg=="
|
||||
},
|
||||
"md5.js": {
|
||||
"version": "1.3.4",
|
||||
@@ -373,6 +373,11 @@
|
||||
"resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz",
|
||||
"integrity": "sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g="
|
||||
},
|
||||
"nonce": {
|
||||
"version": "1.0.4",
|
||||
"resolved": "https://registry.npmjs.org/nonce/-/nonce-1.0.4.tgz",
|
||||
"integrity": "sha1-7nMCrejBvvR28wG4yR9cxRpIdhI="
|
||||
},
|
||||
"oauth-sign": {
|
||||
"version": "0.8.2",
|
||||
"resolved": "https://registry.npmjs.org/oauth-sign/-/oauth-sign-0.8.2.tgz",
|
||||
@@ -447,6 +452,11 @@
|
||||
}
|
||||
}
|
||||
},
|
||||
"retry": {
|
||||
"version": "0.12.0",
|
||||
"resolved": "https://registry.npmjs.org/retry/-/retry-0.12.0.tgz",
|
||||
"integrity": "sha1-G0KmJmoh8HQh0bC1S33BZ7AcATs="
|
||||
},
|
||||
"safe-buffer": {
|
||||
"version": "5.1.2",
|
||||
"resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.1.2.tgz",
|
||||
|
||||
+6
-4
@@ -7,9 +7,11 @@
|
||||
"name": "Luis-Fernando-Molina"
|
||||
},
|
||||
"dependencies": {
|
||||
"azure-storage": "^2.8.2",
|
||||
"@octokit/rest": "^14.0.9",
|
||||
"atob": "^2.1.1"
|
||||
, "nonce": "^1.0.4"
|
||||
}
|
||||
"atob": "^2.1.1",
|
||||
"azure-storage": "^2.8.2",
|
||||
"lodash": "^4.17.11",
|
||||
"nonce": "^1.0.4",
|
||||
"retry": "^0.12.0"
|
||||
}
|
||||
}
|
||||
@@ -737,6 +737,8 @@ function onBrowserRequest(request, response) {
|
||||
let exchangeKey = session.exchangeKeys[0].key; // 0 because we only deal with one exchange for now.
|
||||
let exchangeSecret = session.exchangeKeys[0].secret;
|
||||
|
||||
global.EXCHANGE_NAME = "Poloniex";
|
||||
|
||||
global.EXCHANGE_KEYS = {
|
||||
"Poloniex": {
|
||||
"Key": exchangeKey,
|
||||
@@ -747,51 +749,77 @@ function onBrowserRequest(request, response) {
|
||||
const EXCHANGE_API = require('./Server/Exchange/' + 'ExchangeAPI');
|
||||
let exchangeAPI = EXCHANGE_API.newExchangeAPI();
|
||||
|
||||
switch (requestParameters[2]) {
|
||||
exchangeAPI.initialize(onInizialized);
|
||||
|
||||
case "returnOpenOrders": {
|
||||
exchangeAPI.returnOpenOrders(requestParameters[4], requestParameters[5], onExchangeResponse);
|
||||
break;
|
||||
function onInizialized(err) {
|
||||
if (CONSOLE_LOG === true) { console.log("[INFO] server -> onBrowserRequest -> ExchangeAPI -> onInizialized -> Entering function."); }
|
||||
|
||||
switch (err.result) {
|
||||
case global.DEFAULT_OK_RESPONSE.result: {
|
||||
if (CONSOLE_LOG === true) { console.log("[INFO] server -> onBrowserRequest -> ExchangeAPI -> onInizialized -> Execution finished well."); }
|
||||
callExchangeAPIMethod();
|
||||
return;
|
||||
}
|
||||
case global.DEFAULT_RETRY_RESPONSE.result: { // Something bad happened, but if we retry in a while it might go through the next time.
|
||||
console.log("[ERROR] server -> onBrowserRequest -> ExchangeAPI -> onInizialized -> Retry Later. Requesting Execution Retry.");
|
||||
respondWithContent("", response);
|
||||
return;
|
||||
}
|
||||
case global.DEFAULT_FAIL_RESPONSE.result: { // This is an unexpected exception that we do not know how to handle.
|
||||
console.log("[ERROR] server -> onBrowserRequest -> ExchangeAPI -> onInizialized -> Operation Failed. Aborting the process.");
|
||||
respondWithContent("", response);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function callExchangeAPIMethod() {
|
||||
switch (requestParameters[2]) {
|
||||
|
||||
case "returnOrderTrades": {
|
||||
exchangeAPI.returnOrderTrades(requestParameters[4], onExchangeResponse);
|
||||
break;
|
||||
}
|
||||
case "getTicker": {
|
||||
exchangeAPI.getTicker(global.MARKET, onExchangeResponse);
|
||||
break;
|
||||
}
|
||||
|
||||
case "buy": {
|
||||
exchangeAPI.buy(requestParameters[4], requestParameters[5], requestParameters[6], requestParameters[7], onExchangeResponse);
|
||||
break;
|
||||
}
|
||||
case "getOpenPositions": {
|
||||
exchangeAPI.getOpenPositions(global.MARKET, onExchangeResponse);
|
||||
break;
|
||||
}
|
||||
|
||||
case "sell": {
|
||||
exchangeAPI.sell(requestParameters[4], requestParameters[5], requestParameters[6], requestParameters[7], onExchangeResponse);
|
||||
break;
|
||||
}
|
||||
case "getExecutedTrades": {
|
||||
exchangeAPI.getExecutedTrades(requestParameters[4], onExchangeResponse);
|
||||
break;
|
||||
}
|
||||
|
||||
case "moveOrder": {
|
||||
exchangeAPI.moveOrder(requestParameters[4], requestParameters[5], requestParameters[6], onExchangeResponse);
|
||||
break;
|
||||
}
|
||||
case "putPosition": {
|
||||
exchangeAPI.putPosition(global.MARKET, requestParameters[4], requestParameters[5], requestParameters[6], requestParameters[7], onExchangeResponse);
|
||||
break;
|
||||
}
|
||||
|
||||
case "returnTicker": {
|
||||
exchangeAPI.returnTicker(onExchangeResponse);
|
||||
break;
|
||||
case "movePosition": {
|
||||
exchangeAPI.moveOrder(requestParameters[4], requestParameters[5], requestParameters[6], onExchangeResponse);
|
||||
break;
|
||||
}
|
||||
|
||||
case "getPublicTradeHistory": {
|
||||
exchangeAPI.getPublicTradeHistory(global.MARKET, requestParameters[4], requestParameters[5], requestParameters[6], onExchangeResponse);
|
||||
break;
|
||||
}
|
||||
|
||||
case "initialize": {
|
||||
onExchangeResponse(global.DEFAULT_OK_RESPONSE);
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
function onExchangeResponse(err, exchangeResponse) {
|
||||
function onExchangeResponse(exchangeResponse) {
|
||||
|
||||
/* Delete these secrets before they get logged. */
|
||||
|
||||
requestParameters[3] = "";
|
||||
|
||||
let serverResponse = {
|
||||
err: err,
|
||||
exchangeResponse: exchangeResponse
|
||||
}
|
||||
|
||||
respondWithContent(JSON.stringify(serverResponse), response);
|
||||
requestParameters[3] = "";
|
||||
respondWithContent(JSON.stringify(exchangeResponse), response);
|
||||
}
|
||||
|
||||
return;
|
||||
|
||||
Reference in new issue
Block a user