From 07968c52eb8fc60ebc47f521ab426f707d4b2268 Mon Sep 17 00:00:00 2001 From: Joe Uhren Date: Sun, 24 Jul 2022 19:06:26 -0600 Subject: [PATCH] Add Txbit exchange to markets -Also updated the comments for some of the other markets in the settings.js and settings.json.template files --- README.md | 3 +- lib/markets/txbit.js | 121 +++++++++++++++++++++++++++++++++++++++++ lib/settings.js | 19 ++++++- settings.json.template | 17 +++++- 4 files changed, 155 insertions(+), 5 deletions(-) create mode 100644 lib/markets/txbit.js diff --git a/README.md b/README.md index 934d6b5c..d39a54b6 100644 --- a/README.md +++ b/README.md @@ -89,7 +89,7 @@ Table of Contents - **Movement:** Displays latest blockchain transactions that are greater than a certain configurable amount - **Network:** Displays a list of peers that have connected to the coind wallet in the past 24 hours, along with useful addnode data that can be used to connect your own wallets to the network easier - **Top 100:** Displays the top 100 richest wallet addresses, the top 100 wallet addresses that have the highest total number of coins received based on adding up all received transactions, as well as a table and pie chart breakdown of wealth distribution. Additional support for omitting burned coins from top 100 lists - - **Markets:** Displays a number of exchange-related metrics including market summary, 24 hour chart, most recent buy/sell orders and latest trade history. The last known default exchange price is automatically converted to USD using the coingecko api from [https://www.coingecko.com/en/api](https://www.coingecko.com/en/api). The following 10 cryptocurrency exchanges are supported: + - **Markets:** Displays a number of exchange-related metrics including market summary, 24 hour chart, most recent buy/sell orders and latest trade history. The last known default exchange price is automatically converted to USD using the coingecko api from [https://www.coingecko.com/en/api](https://www.coingecko.com/en/api). The following 11 cryptocurrency exchanges are supported: - [AltMarkets](https://altmarkets.io) - [Bittrex](https://bittrex.com) - [Bleutrade](https://bleutrade.com) @@ -99,6 +99,7 @@ Table of Contents - [Poloniex](https://poloniex.com) - [SouthXchange](https://southxchange.com) - [Stex](https://stex.com) + - [Txbit](https://txbit.io) *\*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) diff --git a/lib/markets/txbit.js b/lib/markets/txbit.js new file mode 100644 index 00000000..af0b9abb --- /dev/null +++ b/lib/markets/txbit.js @@ -0,0 +1,121 @@ +const request = require('postman-request'); +const base_url = 'https://api.txbit.io/api/public/'; +const market_url_template = 'https://txbit.io/Trade/{coin}/{base}'; + +function get_summary(coin, exchange, cb) { + var summary = {}; + + request({ uri: base_url + 'getmarketsummary?market=' + coin + '/' + exchange, json: true}, function (error, response, body) { + if (error) + return cb(error, null); + else if (body.success == null || body.success == false) + return cb(body.message, null); + else { + summary['bid'] = body.result.Bid; + summary['ask'] = body.result.Ask; + summary['high'] = body.result.High; + summary['low'] = body.result.Low; + summary['volume'] = body.result.Volume; + summary['volume_btc'] = body.result.BaseVolume; + summary['last'] = body.result.Last; + summary['prev'] = body.result.PrevDay; + + return cb(null, summary); + } + }).on('error', function(err) { + return cb(error, null); + }); +} + +function get_trades(coin, exchange, cb) { + var req_url = base_url + 'getmarkethistory?market=' + coin + '/' + exchange; + + request({ uri: req_url, json: true}, function (error, response, body) { + if (error) + return cb(error, null); + else if (body.success == null || body.success == false) + return cb(body.message, null); + else { + var trade_body = body.result; + var trades = []; + + for (var i = 0; i < trade_body.length; i++) { + trades.push({ + ordertype: trade_body[i].OrderType, + price: trade_body[i].Price, + quantity: trade_body[i].Quantity, + timestamp: parseInt(new Date(trade_body[i].TimeStamp).getTime()/1000) + }); + } + + return cb(null, trades); + } + }).on('error', function(err) { + return cb(error, null); + }); +} + +function get_orders(coin, exchange, cb) { + var req_url = base_url + 'getorderbook?market=' + coin + '/' + exchange + '&type=both'; + + request({ uri: req_url, json: true}, function (error, response, body) { + if (error) + return cb(error, [], []); + else if (body.success == null || body.success == false) + return cb(body.message, null); + else { + var orders = body.result; + var buys = []; + var sells = []; + const max_records = 250; + + if (orders['buy'].length > 0) { + for (var i = 0; i < orders['buy'].length; i++) { + if (i < max_records) { + buys.push({ + price: orders['buy'][i].Rate, + quantity: orders['buy'][i].Quantity + }); + } else + break; + } + } + + if (orders['sell'].length > 0) { + for (var i = orders['sell'].length - 1; i >= 0; i--) { + if (orders['sell'].length <= max_records || (orders['sell'].length - 1) - i < max_records) { + sells.push({ + price: orders['sell'][i].Rate, + quantity: orders['sell'][i].Quantity + }); + } else + break; + } + } + + return cb(null, buys, sells); + } + }).on('error', function(err) { + return cb(error, null, null); + }); +} + +module.exports = { + market_name: 'Txbit', + market_logo: 'iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAMAAAAoLQ9TAAABF1BMVEUAAAD/rwD/swD/sAD/pwD/sQA2fuH/tAD/sgA5gOH/swAteN//tAD/swD/pwA4f+E5f+H/8r3/vTP///84f+H/swC81vv/qQDz9/3/swA4f+H/swD/+bb/tABCheL+swA4f+E5gOH///83f+H/swA5gOH/pwA8geIbbN0UaNz/sAAjcd4LYtv/qgAweuD/9tn/uBzm8v/c6fqkxPF4qexQj+ZFiOMpdd//3Ir/zlT/vyb/sgD/pAD/owD/mgDN4v/I4P++2v////vW5fnJ3Pe0zvOSuvKKtvJypOproOn/+eb/+OZUkOVNjOQRZtsAWNj/88//4qz/4p7/5Iz/4on/3n//3Hr/0W//x1L/yUv/wkH/sxP/tQC42zL+AAAAInRSTlMAGOLOzsW+rZqUfHdu9/Xs6Ofny8mhmpCOjoaBdjYzJyEVZSx5kAAAANRJREFUGNMtylViAkEQRdEaNATi7slrm+5R3Im7u7H/ddAwnL+69WjMKeXTmXzJoandedOPf013bja519EZ/OBOdjlfI6uoyi+vwF/ALbs5Ct1zoBUMpDS2OFTUF8C9/P/8aBs55DuUa17e1BDBimLJs7SovCddwWm9cYUoMClaYEzoB1R8/XyNtkzRKrPFrVUboSfw3kvT9jgIVzPl1/HV26JDNqFC3ztGJzggKiQT97aMlpwhKyeU5z+e4OxbZmmi0BRV4C3u239if3NlaTmzsUfWCENmIl5ka+2dAAAAAElFTkSuQmCC', + market_url_template: market_url_template, + market_url_case: 'u', + get_data: function(settings, cb) { + var error = null; + get_orders(settings.coin.toUpperCase(), settings.exchange.toUpperCase(), function(err, buys, sells) { + if (err) { error = err; } + get_trades(settings.coin.toUpperCase(), settings.exchange.toUpperCase(), function(err, trades) { + if (err) { error = err; } + get_summary(settings.coin.toUpperCase(), settings.exchange.toUpperCase(), function(err, stats) { + if (err) { error = err; } + return cb(error, {buys: buys, sells: sells, trades: trades, stats: stats}); + }); + }); + }); + } +}; \ No newline at end of file diff --git a/lib/settings.js b/lib/settings.js index c5841572..ff7e68bb 100644 --- a/lib/settings.js +++ b/lib/settings.js @@ -750,7 +750,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, stex, yobit + // Supported exchanges: altmarkets, bittrex, bleutrade, crex, dex-trade, freiexchange/freixlite, poloniex, southxchange, stex, txbit, yobit "exchanges": { // altmarkets: a collection of settings that pertain to the altmarkets exchange "altmarkets": { @@ -796,6 +796,7 @@ exports.markets_page = { // Ex: "LTC/BTC", "LTC/USDT", "LTC/ETH" "trading_pairs": [ "LTC/BTC" ] }, + // dextrade: a collection of settings that pertain to the dex-trade exchange "dextrade": { // enabled: Enable/disable the dex-trade exchange (true/false) // If set to false, the dex-trade page will be completely inaccessible and no market data will be downloaded for this exchange @@ -806,6 +807,8 @@ exports.markets_page = { // Ex: "LTC/BTC", "LTC/USDT", "LTC/ETH" "trading_pairs": [ "LTC/BTC" ] }, + // freiexchange: a collection of settings that pertain to the freiexchange/freixlite exchange + // NOTE: freiexchange does not display a 24-hour chart due to a lack of OHLCV api data "freiexchange": { // enabled: Enable/disable the freiexchange/freixlite exchange (true/false) // If set to false, the freiexchange/freixlite page will be completely inaccessible and no market data will be downloaded for this exchange @@ -849,8 +852,20 @@ exports.markets_page = { // Ex: "LTC/BTC", "LTC/USDT", "LTC/ETH" "trading_pairs": [ "LTC/BTC", "LTC/USDT" ] }, + // txbit: a collection of settings that pertain to the txbit exchange + // NOTE: txbit does not display a 24-hour chart due to a lack of OHLCV api data + "txbit": { + // enabled: Enable/disable the txbit exchange (true/false) + // If set to false, the txbit page will be completely inaccessible and no market data will be downloaded for this exchange + "enabled": false, + // 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/ETH" ] + }, // yobit: a collection of settings that pertain to the yobit exchange - // NOTE: yobit does not display a 24-hour chart due to yobit's lack of OHLCV api data + // NOTE: yobit does not display a 24-hour chart due to a lack of OHLCV api data "yobit": { // enabled: Enable/disable the yobit exchange (true/false) // If set to false, the yobit 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 be005220..64eb4ccf 100644 --- a/settings.json.template +++ b/settings.json.template @@ -834,7 +834,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, stex, yobit + // Supported exchanges: altmarkets, bittrex, bleutrade, crex, dex-trade, freiexchange/freixlite, poloniex, southxchange, stex, txbit, yobit "exchanges": { // altmarkets: a collection of settings that pertain to the altmarkets exchange "altmarkets": { @@ -892,6 +892,7 @@ "trading_pairs": [ "LTC/BTC" ] }, // freiexchange: a collection of settings that pertain to the freiexchange/freixlite exchange + // NOTE: freiexchange does not display a 24-hour chart due to a lack of OHLCV api data "freiexchange": { // enabled: Enable/disable the freiexchange/freixlite exchange (true/false) // If set to false, the freiexchange/freixlite page will be completely inaccessible and no market data will be downloaded for this exchange @@ -935,8 +936,20 @@ // Ex: "LTC/BTC", "LTC/USDT", "LTC/ETH" "trading_pairs": [ "LTC/BTC", "LTC/USDT" ] }, + // txbit: a collection of settings that pertain to the txbit exchange + // NOTE: txbit does not display a 24-hour chart due to a lack of OHLCV api data + "txbit": { + // enabled: Enable/disable the txbit exchange (true/false) + // If set to false, the txbit page will be completely inaccessible and no market data will be downloaded for this exchange + "enabled": false, + // 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/ETH" ] + }, // yobit: a collection of settings that pertain to the yobit exchange - // NOTE: yobit does not display a 24-hour chart due to yobit's lack of OHLCV api data + // NOTE: yobit does not display a 24-hour chart due to a lack of OHLCV api data "yobit": { // enabled: Enable/disable the yobit exchange (true/false) // If set to false, the yobit page will be completely inaccessible and no market data will be downloaded for this exchange