diff --git a/README.md b/README.md index a35221e..3f3a5f1 100644 --- a/README.md +++ b/README.md @@ -101,6 +101,7 @@ Table of Contents - [SouthXchange](https://southxchange.com) - [Txbit](https://txbit.io) *\*no chart support due to a lack of OHLCV api data* - [Unnamed](https://unnamed.exchange) + - [Xeggex](https://xeggex.com) *\*no chart support due to a lack of OHLCV api data* - [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) @@ -985,4 +986,4 @@ Redistribution and use in source and binary forms, with or without modification, * Neither the name of Iquidus Technology nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. \ No newline at end of file +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/lib/markets/xeggex.js b/lib/markets/xeggex.js new file mode 100644 index 0000000..7f637ab --- /dev/null +++ b/lib/markets/xeggex.js @@ -0,0 +1,125 @@ +var request = require('postman-request'); +var base_url = 'https://api.xeggex.com/api/v2'; +const market_url_template = 'https://xeggex.com/market/{coin}_{base}'; + +function get_summary(coin, exchange, cb) { + var req_url = base_url + '/market/getbysymbol/' + coin + '_' + exchange; + + request({uri: req_url, json: true}, function (error, response, body) { + if (error) + return cb(error, null); + else { + if (body.message) + return cb(body.message, null); + else { + var retVal = { + 'high': body.highPriceNumber, + 'low': body.lowPriceNumber, + 'volume': body.volumeUsdNumber, + 'bid': body.bestBidNumber, + 'ask': body.bestAskNumber, + 'last': body.lastPriceNumber, + 'prev': body.yesterdayPriceNumber + }; + + return cb (null, retVal); + } + } + }); +} + +function formatTimestamp(unixTimestamp) { + const date = new Date(unixTimestamp * 1000); // Convert to milliseconds + const months = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"]; + + const day = date.getUTCDate(); + const month = months[date.getUTCMonth()]; + const year = date.getUTCFullYear(); + + const hours = String(date.getUTCHours()).padStart(2, '0'); + const minutes = String(date.getUTCMinutes()).padStart(2, '0'); + const seconds = String(date.getUTCSeconds()).padStart(2, '0'); + + return `${month} ${day}, ${year} ${hours}:${minutes}:${seconds} UTC`; +} +function get_trades(coin, exchange, cb) { + + // Now proceed to the second API request + var req_url = base_url + '/historical_trades?ticker_id=' + coin + '_' + exchange + '&limit=300' ; + + request({uri: req_url, json: true}, function (error, response, body) { + if (error) return cb(error, null); + + var trades = []; + + if (body.length > 0) { + for (var i = 0; i < body.length; i++) { + var trade = { + ordertype: body[i]['type'], + price: body[i]['price'], + quantity: body[i]['base_volume'], + timestamp: formatTimestamp(parseInt(new Date(body[i]['trade_timestamp']).getTime()/1000)) + }; + trades.push(trade); + } + } + return cb(null, trades); + }); +} + +function get_orders(coin, exchange, cb) { + var req_url = base_url + '/market/getorderbookbysymbol/' + coin + '_' + exchange + + request({uri: req_url, json: true}, function (error, response, body) { + if (body) { + var orders = body; + var buys = []; + var sells = []; + + if (orders['bids'].length > 0) { + for (var i = 0; i < orders['bids'].length; i++) { + var order = { + price: orders.bids[i].numberprice, + quantity: orders.bids[i].quantity + }; + + buys.push(order); + } + } + + if (orders['asks'].length > 0) { + for (var i = 0; i < orders['asks'].length; i++) { + var order = { + price: orders.asks[i].numberprice, + quantity: orders.asks[i].quantity + }; + + sells.push(order); + } + } + + return cb(null, buys, sells); + } else + return cb(body, [], []); + }); +} + +module.exports = { + market_name: 'Xeggex', + market_logo: 'iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAACXBIWXMAAAsTAAALEwEAmpwYAAAF8WlUWHRYTUw6Y29tLmFkb2JlLnhtcAAAAAAAPD94cGFja2V0IGJlZ2luPSLvu78iIGlkPSJXNU0wTXBDZWhpSHpyZVN6TlRjemtjOWQiPz4gPHg6eG1wbWV0YSB4bWxuczp4PSJhZG9iZTpuczptZXRhLyIgeDp4bXB0az0iQWRvYmUgWE1QIENvcmUgNi4wLWMwMDIgNzkuMTY0NDYwLCAyMDIwLzA1LzEyLTE2OjA0OjE3ICAgICAgICAiPiA8cmRmOlJERiB4bWxuczpyZGY9Imh0dHA6Ly93d3cudzMub3JnLzE5OTkvMDIvMjItcmRmLXN5bnRheC1ucyMiPiA8cmRmOkRlc2NyaXB0aW9uIHJkZjphYm91dD0iIiB4bWxuczp4bXA9Imh0dHA6Ly9ucy5hZG9iZS5jb20veGFwLzEuMC8iIHhtbG5zOnhtcE1NPSJodHRwOi8vbnMuYWRvYmUuY29tL3hhcC8xLjAvbW0vIiB4bWxuczpzdEV2dD0iaHR0cDovL25zLmFkb2JlLmNvbS94YXAvMS4wL3NUeXBlL1Jlc291cmNlRXZlbnQjIiB4bWxuczpkYz0iaHR0cDovL3B1cmwub3JnL2RjL2VsZW1lbnRzLzEuMS8iIHhtbG5zOnBob3Rvc2hvcD0iaHR0cDovL25zLmFkb2JlLmNvbS9waG90b3Nob3AvMS4wLyIgeG1wOkNyZWF0b3JUb29sPSJBZG9iZ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5fnCPNBUXUBxj3/0OJ8l5US+DxQlYmtlpqxp2XjoEZBosSjkNVYA4I85BCxAcplk6jaYHlBxkyoI3iM54hWZWN+DBA40zK0cPghMAR4Iq9il4Ckj1b5LFyUdipf8Cba+9zaJkr9qMf7GT9HC1HxwVxuD2+DbwIHqX4uxBqpcug/SzEOxpFAbcDz9k1id/At3gdXn7zpxjdKXaHcDNC4hCR4aL83HZAbSeLSzL7R2aQLxrGFR1A9Hx35frm18y69NFYCuBc62z09Zmthwmw1aU9Aslzxspbqq0QFKydttR+qoYxI21J/at+dOPXpA31pZFEONfwAie3PFmXOIAAAAASUVORK5CYII=', + market_url_template: market_url_template, + market_url_case: 'u', + get_data: function(settings, cb) { + var error = null; + get_orders(settings.coin, settings.exchange, function(err, buys, sells) { + if (err) { error = err; } + get_trades(settings.coin, settings.exchange, function(err, trades) { + if (err) { error = err; } + get_summary(settings.coin, settings.exchange, function(err, stats) { + if (err) { error = err; } + return cb(error, {buys: buys, sells: sells, trades: trades, stats: stats}); + }); + }); + }); + } +}; diff --git a/lib/settings.js b/lib/settings.js index 1293979..402b72d 100644 --- a/lib/settings.js +++ b/lib/settings.js @@ -803,7 +803,7 @@ exports.markets_page = { "show_market_select": true, // exchanges: Enable/disable api integration with any of the available built-in exchanges // Enabled exchanges display a number of exchange-related metrics including market summary, 24 hour chart, most recent buy/sell orders and latest trade history - // Supported exchanges: altmarkets, bittrex, bleutrade, crex, dex-trade, freiexchange/freixlite, poloniex, southxchange, txbit, unnamed, yobit + // Supported exchanges: altmarkets, bittrex, bleutrade, crex, dex-trade, freiexchange/freixlite, poloniex, southxchange, txbit, unnamed, xeggex, yobit "exchanges": { // altmarkets: a collection of settings that pertain to the altmarkets exchange "altmarkets": { @@ -929,6 +929,19 @@ exports.markets_page = { // Ex: "LTC/BTC", "LTC/USDT", "LTC/ETH" "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 + "enabled": true, + // trading_pairs: An array of market trading pair symbols + // You can add as many trading pairs as necessary + // All entries must specify your coins symbol as it is displayed on the exchange, followed by a slash (/) and ending with the symbol of the market or asset that is being traded against + // Ex: "LTC/BTC", "LTC/USDT", "LTC/ETH" + "trading_pairs": "LTC/USDT" + } }, // default_exchange: a collection of settings that pertain to the default exchange // When the "show_market_dropdown_menu" setting is disabled, the market header menu will navigate directly to the default exchange page @@ -2049,4 +2062,4 @@ Object.byString = function(o, s) { } // populate settings -exports.loadSettings(); \ No newline at end of file +exports.loadSettings(); diff --git a/settings.json.template b/settings.json.template index eb3576b..bd0f9b1 100644 --- a/settings.json.template +++ b/settings.json.template @@ -887,7 +887,7 @@ "show_market_select": true, // exchanges: Enable/disable api integration with any of the available built-in exchanges // Enabled exchanges display a number of exchange-related metrics including market summary, 24 hour chart, most recent buy/sell orders and latest trade history - // Supported exchanges: altmarkets, bittrex, bleutrade, crex, dex-trade, freiexchange/freixlite, poloniex, southxchange, txbit, unnamed, yobit + // Supported exchanges: altmarkets, bittrex, bleutrade, crex, dex-trade, freiexchange/freixlite, poloniex, southxchange, txbit, unnamed, xeggex, yobit "exchanges": { // altmarkets: a collection of settings that pertain to the altmarkets exchange "altmarkets": { @@ -1001,6 +1001,19 @@ // Ex: "LTC/BTC", "LTC/USDT", "LTC/ETH" "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 + "enabled": true, + // trading_pairs: An array of market trading pair symbols + // You can add as many trading pairs as necessary + // All entries must specify your coins symbol as it is displayed on the exchange, followed by a slash (/) and ending with the symbol of the market or asset that is being traded against + // Ex: "LTC/BTC", "LTC/USDT", "LTC/ETH" + "trading_pairs": "LTC/USDT" + } + }, // yobit: a collection of settings that pertain to the yobit exchange // NOTE: yobit does not display a 24-hour chart due to a lack of OHLCV api data "yobit": {