diff --git a/README.md b/README.md index 99624f9..0ec9c9b 100644 --- a/README.md +++ b/README.md @@ -107,7 +107,7 @@ Table of Contents - [NonKyc](https://nonkyc.io) - [Poloniex](https://poloniex.com) - [SouthXchange](https://southxchange.com) - - [Xeggex](https://xeggex.com) *\*no chart support due to a lack of OHLCV api data* + - [Xeggex](https://xeggex.com) - [Yobit](https://yobit.io) *\*no chart support due to a lack of OHLCV api data* - **API:** A listing of available public API's that can be used to retrieve information from the network without the need for a local wallet. The following public API's are supported: - **RPC API calls** (Return data from coind) diff --git a/lib/markets/xeggex.js b/lib/markets/xeggex.js index 8e8907f..1780199 100644 --- a/lib/markets/xeggex.js +++ b/lib/markets/xeggex.js @@ -113,6 +113,43 @@ function get_orders(coin, exchange, api_error_msg, cb) { }); } +function get_chartdata(coin, exchange, api_error_msg, cb) { + const end = Date.now() / 1000; + const start = end - 86400; + const req_url = base_url + '/market/candles/?symbol=' + coin + '_' + exchange + '&from=' + parseInt(start).toString() + '&to=' + parseInt(end).toString() + '&resolution=15' ; + + // pause for 2 seconds before continuing + rateLimit.schedule(function() { + request({uri: req_url, json: true}, function (error, response, body) { + if (error) + return cb(error, null); + else if (body == null || body == '' || typeof body !== 'object' || typeof body == 'string' || body instanceof String) + return cb(api_error_msg, null); + else if (body.error != null) + return cb((body.error.message != null ? body.error.message : api_error_msg), null); + else { + try { + let chartdata = []; + + for (let c = 0; c < body.bars.length; c++) { + chartdata.push([ + parseInt(body.bars[c].time), + parseFloat(body.bars[c].open) || 0, + parseFloat(body.bars[c].high) || 0, + parseFloat(body.bars[c].low) || 0, + parseFloat(body.bars[c].close) || 0 + ]); + } + + return cb(null, chartdata); + } catch(err) { + return cb(api_error_msg, null); + } + } + }); + }); +} + module.exports = { market_name: 'Xeggex', market_logo: 'iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAMAAAAoLQ9TAAAAsVBMVEUAAABvY0FMTUHMoUJZV0FDSkFJTUG7l0KNd0GGcUF3akF8bEH4xEL4x0PzuUPzuUPgskPhukPetEPVs0LLpUK8n0KpjUGli0G4lkKagEJSU0H+zkPzv0PktUPWq0PeuELTqEPHnULYtEPSqkLar0LRqUPIokPKokO3lEK2k0K+m0K0kkKniEFmYEFlX0H/0kT/00P/6UT/1UP/40P/4EP/2UP/60T/5UP/xUP+xEP9xEOWOrtXAAAAL3RSTlMAKwjKGQ0Fk2BQRDz89/Hw69POxbWso52OaBX69+7kysjIw7+8u66soJ6Ig3kjHAzaxeEAAACkSURBVBjThc03gsIwFADRkRyxyRl2yTl+SbZJ9z8YhQsKCl431fBlaBoPMTHEIs+GiQiahdevOh3m1b7nJgH4poPvWrp3YSlXgIrtou4ebG0FAA4Wle8Y3SJKYaLyNiprf1Y1E/Inn17ZlHWWpiGl0+1MlCfc92Un2QbmVtEtL2OZ4feClozpGB/0tPAG/5nWrjZYFM2Ao6u/xIwgNvKouyE/vQGJsQ9k11uR2AAAAABJRU5ErkJggg==', @@ -124,9 +161,14 @@ module.exports = { get_trades(settings.coin, settings.exchange, settings.api_error_msg, function(trade_error, trades) { if (trade_error == null) { get_summary(settings.coin, settings.exchange, settings.api_error_msg, function(summary_error, stats) { - if (summary_error == null) - return cb(null, {buys: buys, sells: sells, trades: trades, stats: stats, chartdata: null}); - else + if (summary_error == null) { + get_chartdata(settings.coin, settings.exchange, settings.api_error_msg, function (chart_error, chartdata) { + if (chart_error == null) + return cb(null, {buys: buys, sells: sells, trades: trades, stats: stats, chartdata: chartdata}); + else + return cb(chart_error, null); + }); + } else return cb(summary_error, null); }); } else diff --git a/lib/settings.js b/lib/settings.js index b47f416..cbee3d1 100644 --- a/lib/settings.js +++ b/lib/settings.js @@ -904,7 +904,6 @@ exports.markets_page = { "trading_pairs": [ "LTC/BTC" ] }, // xeggex: a collection of settings that pertain to the xeggex exchange - // NOTE: xeggex does not display a 24-hour chart due to a lack of OHLCV api data "xeggex": { // enabled: Enable/disable the xeggex exchange (true/false) // If set to false, the xeggex page will be completely inaccessible and no market data will be downloaded for this exchange diff --git a/settings.json.template b/settings.json.template index fd39886..f6b332e 100644 --- a/settings.json.template +++ b/settings.json.template @@ -988,7 +988,6 @@ "trading_pairs": [ "LTC/BTC" ] }, // xeggex: a collection of settings that pertain to the xeggex exchange - // NOTE: xeggex does not display a 24-hour chart due to a lack of OHLCV api data "xeggex": { // enabled: Enable/disable the xeggex exchange (true/false) // If set to false, the xeggex page will be completely inaccessible and no market data will be downloaded for this exchange