get ticker working with ccxt

This commit is contained in:
Luis Fernando Molina committed 2020-02-06 16:06:22 +01:00
1 parent 6ee36b0687
commit 1dc1e8b676
3 files changed
+47 -101

No files matched your search

+45 -5
View File
@@ -1,8 +1,9 @@
exports.newExchangeAPI = function newExchangeAPI(logger, exchangeName) {
exports.newExchangeAPI = function newExchangeAPI(logger, BOT) {
let MODULE_NAME = "Exchange API";
let LOG_INFO = true;
let apiClient;
let bot = BOT
let thisObject = {
initialize: initialize,
@@ -14,11 +15,41 @@
getMaxDecimalPositions: getMaxDecimalPositions
};
let exchangeId
let options = {}
let exchange
const symbol = bot.market.baseAsset + '/' + bot.market.quotedAsset
const ccxt = require('ccxt')
return thisObject;
function initialize(callBackFunction) {
try {
exchangeId = bot.exchange.toLowerCase()
callBackFunction(global.DEFAULT_OK_RESPONSE);
let key = process.env.KEY
let secret = process.env.SECRET
if (key === "undefined") { key = undefined }
if (secret === "undefined") { secret = undefined }
const exchangeClass = ccxt[exchangeId]
const exchangeConstructorParams = {
'apiKey': key,
'secret': secret,
'timeout': 30000,
'enableRateLimit': true,
verbose: false,
options: options
}
exchange = new exchangeClass(exchangeConstructorParams)
callBackFunction(global.DEFAULT_OK_RESPONSE)
} catch (err) {
logError("initialize -> err = " + err.message);
callBackFunction(global.DEFAULT_FAIL_RESPONSE);
}
}
function getMaxDecimalPositions() {
@@ -34,13 +65,22 @@
* last Number
* };
*/
function getTicker(pMarket, callBack) {
async function getTicker(pMarket, callBackFunction) {
try {
logInfo("getTicker -> Entering function.");
apiClient.getTicker(pMarket, callBack);
let ticker
if (exchange.has['fetchTicker']) {
ticker = await (exchange.fetchTicker(symbol))
callBackFunction(global.DEFAULT_OK_RESPONSE, ticker)
} else {
logError("getTicker -> Exchange does not support fetchTicker command.");
callBackFunction(global.DEFAULT_FAIL_RESPONSE);
}
} catch (err) {
logError("getTicker -> err = " + err.message);
callBack(global.DEFAULT_FAIL_RESPONSE);
callBackFunction(global.DEFAULT_FAIL_RESPONSE);
}
}