Mariam Live Running Well onCloud and at Browser
This commit is contained in:
1 parent
235ac859cb
commit
5bcf4e9f47
3 files changed
+89
-94
No files matched your search
@@ -1,5 +1,8 @@
|
||||
function newPoloniexAPIClient(pKey, pSecret) {
|
||||
|
||||
const FULL_LOG = true;
|
||||
const LOG_FILE_CONTENT = false;
|
||||
|
||||
let key = pKey;
|
||||
let secret = pSecret;
|
||||
|
||||
@@ -26,9 +29,9 @@
|
||||
let stringExchangeResponse = JSON.stringify(exchangeResponse);
|
||||
let stringExchangeErr = JSON.stringify(exchangeErr);
|
||||
|
||||
logger.write("[INFO] analizeResponse -> exchangeErr = " + stringExchangeErr);
|
||||
logger.write("[INFO] analizeResponse -> exchangeResponse = " + stringExchangeResponse);
|
||||
|
||||
if (FULL_LOG === true) { logger.write("[INFO] analizeResponse -> exchangeErr = " + stringExchangeErr); }
|
||||
if (LOG_FILE_CONTENT === true) { logger.write("[INFO] analizeResponse -> exchangeResponse = " + stringExchangeResponse); }
|
||||
|
||||
if (stringExchangeErr.indexOf("ETIMEDOUT") > 0 ||
|
||||
stringExchangeErr.indexOf("ENOTFOUND") > 0 ||
|
||||
stringExchangeErr.indexOf("ECONNREFUSED") > 0 ||
|
||||
@@ -84,7 +87,7 @@
|
||||
+ pMarketAssetB
|
||||
;
|
||||
|
||||
callServer(path, onServerResponse);
|
||||
callServer(path + "/NO-LOG", onServerResponse);
|
||||
|
||||
function onServerResponse(pServerResponse) {
|
||||
|
||||
@@ -103,7 +106,7 @@
|
||||
+ pPositionId
|
||||
;
|
||||
|
||||
callServer(path, onServerResponse);
|
||||
callServer(path + "/NO-LOG", onServerResponse);
|
||||
|
||||
function onServerResponse(pServerResponse) {
|
||||
|
||||
@@ -124,7 +127,7 @@
|
||||
+ pAmountB
|
||||
;
|
||||
|
||||
callServer(path, onServerResponse);
|
||||
callServer(path + "/NO-LOG", onServerResponse);
|
||||
|
||||
function onServerResponse(pServerResponse) {
|
||||
|
||||
@@ -145,7 +148,7 @@
|
||||
+ pAmountB
|
||||
;
|
||||
|
||||
callServer(path, onServerResponse);
|
||||
callServer(path + "/NO-LOG", onServerResponse);
|
||||
|
||||
function onServerResponse(pServerResponse) {
|
||||
|
||||
@@ -166,7 +169,7 @@
|
||||
+ pPositionAmountB
|
||||
;
|
||||
|
||||
callServer(path, onServerResponse);
|
||||
callServer(path + "/NO-LOG", onServerResponse);
|
||||
|
||||
function onServerResponse(pServerResponse) {
|
||||
|
||||
@@ -184,7 +187,7 @@
|
||||
+ secret
|
||||
;
|
||||
|
||||
callServer(path, onServerResponse);
|
||||
callServer(path + "/NO-LOG", onServerResponse);
|
||||
|
||||
function onServerResponse(pServerResponse) {
|
||||
|
||||
|
||||
@@ -8,12 +8,12 @@
|
||||
let newFunction = new API(pKey, pSecret);
|
||||
|
||||
let thisObject = {
|
||||
API: newFunction.prototype
|
||||
API: newFunction
|
||||
};
|
||||
|
||||
return thisObject;
|
||||
|
||||
function API () {
|
||||
function API(key, secret) {
|
||||
'use strict';
|
||||
|
||||
// Module dependencies
|
||||
@@ -38,42 +38,35 @@
|
||||
return currencyA + '_' + currencyB;
|
||||
}
|
||||
|
||||
// Constructor
|
||||
function Poloniex(key, secret) {
|
||||
// Generate headers signed by this user's key and secret.
|
||||
// The secret is encapsulated and never exposed
|
||||
this._getPrivateHeaders = function (parameters) {
|
||||
var paramString, signature;
|
||||
// Generate headers signed by thisObject user's key and secret.
|
||||
// The secret is encapsulated and never exposed
|
||||
function _getPrivateHeaders (parameters) {
|
||||
var paramString, signature;
|
||||
|
||||
if (!key || !secret) {
|
||||
throw 'Poloniex: Error. API key and secret required';
|
||||
}
|
||||
if (!key || !secret) {
|
||||
throw 'Poloniex: Error. API key and secret required';
|
||||
}
|
||||
|
||||
// Convert to `arg1=foo&arg2=bar`
|
||||
paramString = Object.keys(parameters).map(function (param) {
|
||||
return encodeURIComponent(param) + '=' + encodeURIComponent(parameters[param]);
|
||||
}).join('&');
|
||||
// Convert to `arg1=foo&arg2=bar`
|
||||
paramString = Object.keys(parameters).map(function (param) {
|
||||
return encodeURIComponent(param) + '=' + encodeURIComponent(parameters[param]);
|
||||
}).join('&');
|
||||
|
||||
signature = crypto.createHmac('sha512', secret).update(paramString).digest('hex');
|
||||
signature = crypto.createHmac('sha512', secret).update(paramString).digest('hex');
|
||||
|
||||
return {
|
||||
Key: key,
|
||||
Sign: signature
|
||||
};
|
||||
return {
|
||||
Key: key,
|
||||
Sign: signature
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
// Currently, this fails with `Error: CERT_UNTRUSTED`
|
||||
// Poloniex.STRICT_SSL can be set to `false` to avoid this. Use with caution.
|
||||
// Will be removed in future, once this is resolved.
|
||||
Poloniex.STRICT_SSL = true;
|
||||
|
||||
// Customisable user agent string
|
||||
Poloniex.USER_AGENT = USER_AGENT;
|
||||
// Currently, thisObject fails with `Error: CERT_UNTRUSTED`
|
||||
// Poloniex.STRICT_SSL can be set to `false` to avoid thisObject. Use with caution.
|
||||
// Will be removed in future, once thisObject is resolved.
|
||||
const STRICT_SSL = true;
|
||||
|
||||
// Prototype
|
||||
Poloniex.prototype = {
|
||||
constructor: Poloniex,
|
||||
let thisObject = {
|
||||
|
||||
// Make an API request
|
||||
_request: function (options, callback) {
|
||||
@@ -82,8 +75,8 @@
|
||||
}
|
||||
|
||||
options.json = true;
|
||||
options.headers['User-Agent'] = Poloniex.USER_AGENT;
|
||||
options.strictSSL = Poloniex.STRICT_SSL;
|
||||
options.headers['User-Agent'] = USER_AGENT;
|
||||
options.strictSSL = STRICT_SSL;
|
||||
|
||||
request(options, function (err, response, body) {
|
||||
// Empty response
|
||||
@@ -94,7 +87,7 @@
|
||||
callback(err, body);
|
||||
});
|
||||
|
||||
return this;
|
||||
return thisObject;
|
||||
},
|
||||
|
||||
// Make a public API request
|
||||
@@ -115,7 +108,7 @@
|
||||
};
|
||||
|
||||
options.qs.command = command;
|
||||
return this._request(options, callback);
|
||||
return thisObject._request(options, callback);
|
||||
},
|
||||
|
||||
// Make a private API request
|
||||
@@ -135,21 +128,21 @@
|
||||
method: 'POST',
|
||||
url: PRIVATE_API_URL,
|
||||
form: parameters,
|
||||
headers: this._getPrivateHeaders(parameters)
|
||||
headers: _getPrivateHeaders(parameters)
|
||||
};
|
||||
|
||||
return this._request(options, callback);
|
||||
return thisObject._request(options, callback);
|
||||
},
|
||||
|
||||
/////
|
||||
// PUBLIC METHODS
|
||||
|
||||
returnTicker: function (callback) {
|
||||
return this._public('returnTicker', callback);
|
||||
return thisObject._public('returnTicker', callback);
|
||||
},
|
||||
|
||||
return24hVolume: function (callback) {
|
||||
return this._public('return24hVolume', callback);
|
||||
return thisObject._public('return24hVolume', callback);
|
||||
},
|
||||
|
||||
returnOrderBook: function (currencyA, currencyB, depth, callback) {
|
||||
@@ -158,7 +151,7 @@
|
||||
depth: depth
|
||||
};
|
||||
|
||||
return this._public('returnOrderBook', parameters, callback);
|
||||
return thisObject._public('returnOrderBook', parameters, callback);
|
||||
},
|
||||
|
||||
returnOrderBooks: function (depth, callback) {
|
||||
@@ -167,7 +160,7 @@
|
||||
depth: depth
|
||||
};
|
||||
|
||||
return this._public('returnOrderBook', parameters, callback);
|
||||
return thisObject._public('returnOrderBook', parameters, callback);
|
||||
},
|
||||
|
||||
returnPublicTradeHistory: function (currencyA, currencyB, start, end, callback) {
|
||||
@@ -177,7 +170,7 @@
|
||||
end: end
|
||||
};
|
||||
|
||||
return this._public('returnTradeHistory', parameters, callback);
|
||||
return thisObject._public('returnTradeHistory', parameters, callback);
|
||||
},
|
||||
|
||||
returnChartData: function (currencyA, currencyB, period, start, end, callback) {
|
||||
@@ -188,38 +181,38 @@
|
||||
end: end
|
||||
};
|
||||
|
||||
return this._public('returnChartData', parameters, callback);
|
||||
return thisObject._public('returnChartData', parameters, callback);
|
||||
},
|
||||
|
||||
returnCurrencies: function (callback) {
|
||||
return this._public('returnCurrencies', callback);
|
||||
return thisObject._public('returnCurrencies', callback);
|
||||
},
|
||||
|
||||
returnLoanOrders: function (currency, callback) {
|
||||
return this._public('returnLoanOrders', { currency: currency }, callback);
|
||||
return thisObject._public('returnLoanOrders', { currency: currency }, callback);
|
||||
},
|
||||
|
||||
/////
|
||||
// PRIVATE METHODS
|
||||
|
||||
returnBalances: function (callback) {
|
||||
return this._private('returnBalances', {}, callback);
|
||||
return thisObject._private('returnBalances', {}, callback);
|
||||
},
|
||||
|
||||
returnCompleteBalances: function (callback) {
|
||||
return this._private('returnCompleteBalances', {}, callback);
|
||||
return thisObject._private('returnCompleteBalances', {}, callback);
|
||||
},
|
||||
|
||||
returnDepositAddresses: function (callback) {
|
||||
return this._private('returnDepositAddresses', {}, callback);
|
||||
return thisObject._private('returnDepositAddresses', {}, callback);
|
||||
},
|
||||
|
||||
generateNewAddress: function (currency, callback) {
|
||||
return this._private('returnDepositsWithdrawals', { currency: currency }, callback);
|
||||
return thisObject._private('returnDepositsWithdrawals', { currency: currency }, callback);
|
||||
},
|
||||
|
||||
returnDepositsWithdrawals: function (start, end, callback) {
|
||||
return this._private('returnDepositsWithdrawals', { start: start, end: end }, callback);
|
||||
return thisObject._private('returnDepositsWithdrawals', { start: start, end: end }, callback);
|
||||
},
|
||||
|
||||
returnOpenOrders: function (currencyA, currencyB, callback) {
|
||||
@@ -227,7 +220,7 @@
|
||||
currencyPair: joinCurrencies(currencyA, currencyB)
|
||||
};
|
||||
|
||||
return this._private('returnOpenOrders', parameters, callback);
|
||||
return thisObject._private('returnOpenOrders', parameters, callback);
|
||||
},
|
||||
|
||||
returnTradeHistory: function (currencyA, currencyB, callback) {
|
||||
@@ -235,7 +228,7 @@
|
||||
currencyPair: joinCurrencies(currencyA, currencyB)
|
||||
};
|
||||
|
||||
return this._private('returnTradeHistory', parameters, callback);
|
||||
return thisObject._private('returnTradeHistory', parameters, callback);
|
||||
},
|
||||
|
||||
returnOrderTrades: function (orderNumber, callback) {
|
||||
@@ -243,7 +236,7 @@
|
||||
orderNumber: orderNumber
|
||||
};
|
||||
|
||||
return this._private('returnOrderTrades', parameters, callback);
|
||||
return thisObject._private('returnOrderTrades', parameters, callback);
|
||||
},
|
||||
|
||||
buy: function (currencyA, currencyB, rate, amount, callback) {
|
||||
@@ -253,7 +246,7 @@
|
||||
amount: amount
|
||||
};
|
||||
|
||||
return this._private('buy', parameters, callback);
|
||||
return thisObject._private('buy', parameters, callback);
|
||||
},
|
||||
|
||||
sell: function (currencyA, currencyB, rate, amount, callback) {
|
||||
@@ -263,7 +256,7 @@
|
||||
amount: amount
|
||||
};
|
||||
|
||||
return this._private('sell', parameters, callback);
|
||||
return thisObject._private('sell', parameters, callback);
|
||||
},
|
||||
|
||||
cancelOrder: function (currencyA, currencyB, orderNumber, callback) {
|
||||
@@ -272,7 +265,7 @@
|
||||
orderNumber: orderNumber
|
||||
};
|
||||
|
||||
return this._private('cancelOrder', parameters, callback);
|
||||
return thisObject._private('cancelOrder', parameters, callback);
|
||||
},
|
||||
|
||||
moveOrder: function (orderNumber, rate, amount, callback) {
|
||||
@@ -282,7 +275,7 @@
|
||||
amount: amount ? amount : null
|
||||
};
|
||||
|
||||
return this._private('moveOrder', parameters, callback);
|
||||
return thisObject._private('moveOrder', parameters, callback);
|
||||
},
|
||||
|
||||
withdraw: function (currency, amount, address, callback) {
|
||||
@@ -292,11 +285,11 @@
|
||||
address: address
|
||||
};
|
||||
|
||||
return this._private('withdraw', parameters, callback);
|
||||
return thisObject._private('withdraw', parameters, callback);
|
||||
},
|
||||
|
||||
returnFeeInfo: function (callback) {
|
||||
return this._private('returnFeeInfo', {}, callback);
|
||||
return thisObject._private('returnFeeInfo', {}, callback);
|
||||
},
|
||||
|
||||
returnAvailableAccountBalances: function (account, callback) {
|
||||
@@ -304,11 +297,11 @@
|
||||
if (account) {
|
||||
options.account = account;
|
||||
}
|
||||
return this._private('returnAvailableAccountBalances', options, callback);
|
||||
return thisObject._private('returnAvailableAccountBalances', options, callback);
|
||||
},
|
||||
|
||||
returnTradableBalances: function (callback) {
|
||||
return this._private('returnTradableBalances', {}, callback);
|
||||
return thisObject._private('returnTradableBalances', {}, callback);
|
||||
},
|
||||
|
||||
transferBalance: function (currency, amount, fromAccount, toAccount, callback) {
|
||||
@@ -319,11 +312,11 @@
|
||||
toAccount: toAccount
|
||||
};
|
||||
|
||||
return this._private('transferBalance', parameters, callback);
|
||||
return thisObject._private('transferBalance', parameters, callback);
|
||||
},
|
||||
|
||||
returnMarginAccountSummary: function (callback) {
|
||||
return this._private('returnMarginAccountSummary', {}, callback);
|
||||
return thisObject._private('returnMarginAccountSummary', {}, callback);
|
||||
},
|
||||
|
||||
marginBuy: function (currencyA, currencyB, rate, amount, lendingRate, callback) {
|
||||
@@ -334,7 +327,7 @@
|
||||
lendingRate: lendingRate ? lendingRate : null
|
||||
};
|
||||
|
||||
return this._private('marginBuy', parameters, callback);
|
||||
return thisObject._private('marginBuy', parameters, callback);
|
||||
},
|
||||
|
||||
marginSell: function (currencyA, currencyB, rate, amount, lendingRate, callback) {
|
||||
@@ -345,7 +338,7 @@
|
||||
lendingRate: lendingRate ? lendingRate : null
|
||||
};
|
||||
|
||||
return this._private('marginSell', parameters, callback);
|
||||
return thisObject._private('marginSell', parameters, callback);
|
||||
},
|
||||
|
||||
getMarginPosition: function (currencyA, currencyB, callback) {
|
||||
@@ -353,7 +346,7 @@
|
||||
currencyPair: joinCurrencies(currencyA, currencyB)
|
||||
};
|
||||
|
||||
return this._private('getMarginPosition', parameters, callback);
|
||||
return thisObject._private('getMarginPosition', parameters, callback);
|
||||
},
|
||||
|
||||
closeMarginPosition: function (currencyA, currencyB, callback) {
|
||||
@@ -361,7 +354,7 @@
|
||||
currencyPair: joinCurrencies(currencyA, currencyB)
|
||||
};
|
||||
|
||||
return this._private('closeMarginPosition', parameters, callback);
|
||||
return thisObject._private('closeMarginPosition', parameters, callback);
|
||||
},
|
||||
|
||||
createLoanOffer: function (currency, amount, duration, autoRenew, lendingRate, callback) {
|
||||
@@ -373,7 +366,7 @@
|
||||
lendingRate: lendingRate
|
||||
};
|
||||
|
||||
return this._private('createLoanOffer', parameters, callback);
|
||||
return thisObject._private('createLoanOffer', parameters, callback);
|
||||
},
|
||||
|
||||
cancelLoanOffer: function (orderNumber, callback) {
|
||||
@@ -381,15 +374,15 @@
|
||||
orderNumber: orderNumber
|
||||
};
|
||||
|
||||
return this._private('cancelLoanOffer', parameters, callback);
|
||||
return thisObject._private('cancelLoanOffer', parameters, callback);
|
||||
},
|
||||
|
||||
returnOpenLoanOffers: function (callback) {
|
||||
return this._private('returnOpenLoanOffers', {}, callback);
|
||||
return thisObject._private('returnOpenLoanOffers', {}, callback);
|
||||
},
|
||||
|
||||
returnActiveLoans: function (callback) {
|
||||
return this._private('returnActiveLoans', {}, callback);
|
||||
return thisObject._private('returnActiveLoans', {}, callback);
|
||||
},
|
||||
|
||||
returnLendingHistory: function (start, end, limit, callback) {
|
||||
@@ -399,15 +392,18 @@
|
||||
limit: limit
|
||||
};
|
||||
|
||||
return this._private('returnLendingHistory', parameters, callback);
|
||||
return thisObject._private('returnLendingHistory', parameters, callback);
|
||||
},
|
||||
|
||||
toggleAutoRenew: function (orderNumber, callback) {
|
||||
return this._private('toggleAutoRenew', { orderNumber: orderNumber }, callback);
|
||||
return thisObject._private('toggleAutoRenew', { orderNumber: orderNumber }, callback);
|
||||
},
|
||||
|
||||
analizeResponse: function (logger, exchangeErr, exchangeResponse, notOkCallBack, okCallBack) {
|
||||
|
||||
const FULL_LOG = false;
|
||||
const LOG_FILE_CONTENT = false;
|
||||
|
||||
/* This function analizes the different situations we might encounter trying to access Poloniex and returns appropiate standard errors. */
|
||||
|
||||
try {
|
||||
@@ -415,8 +411,8 @@
|
||||
let stringExchangeResponse = JSON.stringify(exchangeResponse);
|
||||
let stringExchangeErr = JSON.stringify(exchangeErr);
|
||||
|
||||
logger.write("[INFO] analizeResponse -> exchangeErr = " + stringExchangeErr);
|
||||
logger.write("[INFO] analizeResponse -> exchangeResponse = " + stringExchangeResponse);
|
||||
if (FULL_LOG === true) { logger.write("[INFO] analizeResponse -> exchangeErr = " + stringExchangeErr); }
|
||||
if (LOG_FILE_CONTENT === true) { logger.write("[INFO] analizeResponse -> exchangeResponse = " + stringExchangeResponse); }
|
||||
|
||||
if (stringExchangeErr.indexOf("ETIMEDOUT") > 0 ||
|
||||
stringExchangeErr.indexOf("ENOTFOUND") > 0 ||
|
||||
@@ -464,16 +460,7 @@
|
||||
}
|
||||
};
|
||||
|
||||
// Backwards Compatibility
|
||||
Poloniex.prototype.getTicker = Poloniex.prototype.returnTicker;
|
||||
Poloniex.prototype.get24hVolume = Poloniex.prototype.return24hVolume;
|
||||
Poloniex.prototype.getOrderBook = Poloniex.prototype.returnOrderBook;
|
||||
Poloniex.prototype.getTradeHistory = Poloniex.prototype.returnChartData;
|
||||
Poloniex.prototype.myBalances = Poloniex.prototype.returnBalances;
|
||||
Poloniex.prototype.myOpenOrders = Poloniex.prototype.returnOpenOrders;
|
||||
Poloniex.prototype.myTradeHistory = Poloniex.prototype.returnTradeHistory;
|
||||
|
||||
return Poloniex;
|
||||
return thisObject;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -121,7 +121,7 @@ function startHtttpServer() {
|
||||
function onBrowserRequest(request, response) {
|
||||
|
||||
if (CONSOLE_LOG === true) { console.log("[INFO] server -> onBrowserRequest -> Entering function."); }
|
||||
if (CONSOLE_LOG === true) { console.log("[INFO] server -> onBrowserRequest -> request.url = " + request.url); }
|
||||
if (CONSOLE_LOG === true && request.url.indexOf("NO-LOG") === -1) { console.log("[INFO] server -> onBrowserRequest -> request.url = " + request.url); }
|
||||
|
||||
var htmlResponse;
|
||||
var requestParameters = request.url.split("/");
|
||||
@@ -414,6 +414,11 @@ function onBrowserRequest(request, response) {
|
||||
|
||||
function onExchangeResponse(err, exchangeResponse) {
|
||||
|
||||
/* Delete these secrets before they get logged. */
|
||||
|
||||
requestParameters[3] = "";
|
||||
requestParameters[4] = "";
|
||||
|
||||
let serverResponse = {
|
||||
err: err,
|
||||
exchangeResponse: exchangeResponse
|
||||
|
||||
Reference in new issue
Block a user