Add support for USD price lookup of any altcoin
-Market sync now sets the last USD price based on the default market pair even if it is not BTC -Removed the coindesk api which was only really useful for getting the USD price of BTC -Added a couple coingecko apis which are used to get the current USD value of the default market pair -Updated the readme, settings file comments and info/api page with better verbiage regarding the market price which was previously only measured in BTC
This commit is contained in:
@@ -86,7 +86,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 following 7 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 7 cryptocurrency exchanges are supported:
|
||||
- [AltMarkets](https://altmarkets.io)
|
||||
- [Bittrex](https://bittrex.com)
|
||||
- [Bleutrade](https://bleutrade.com)
|
||||
@@ -114,8 +114,8 @@ Table of Contents
|
||||
- **getbalance:** Returns current balance of given address
|
||||
- **getlasttxs:** Returns transactions greater than a specific number of coins, starting from a particular offset
|
||||
- **getcurrentprice:** Returns last known exchange price
|
||||
- **getbasicstats:** Returns basic statistics about the coin including: block count, circulating supply, USD price, BTC price and # of masternodes *\*# of masternodes is only applicable to masternode coins*
|
||||
- **getsummary:** Returns a summary of coin data including: difficulty, hybrid difficulty, circulating supply, hash rate, BTC price, network connection count, block count, count of online masternodes and count of offline masternodes *\*masternode counts are only applicable to masternode coins*
|
||||
- **getbasicstats:** Returns basic statistics about the coin including: block count, circulating supply, USD price, default market price and # of masternodes *\*# of masternodes is only applicable to masternode coins*
|
||||
- **getsummary:** Returns a summary of coin data including: difficulty, hybrid difficulty, circulating supply, hash rate, default market price, network connection count, block count, count of online masternodes and count of offline masternodes *\*masternode counts are only applicable to masternode coins*
|
||||
- **getnetworkpeers:** Returns the list of network peers that have connected to the explorer node in the last 24 hours
|
||||
- **getmasternodelist:** Returns the complete list of masternodes on the network *\*only applicable to masternode coins*
|
||||
- **getmasternoderewards:** Returns a list of masternode reward transactions for a specific address that arrived after a specific block height *\*only applicable to masternode coins*
|
||||
@@ -152,8 +152,8 @@ Table of Contents
|
||||
- **Difficulty:** Displays the current proof-of-work and/or proof-of-stake difficulty
|
||||
- **Masternodes:** Displays a count of online and unreachable masternodes *\*only applicable to masternode coins*
|
||||
- **Coin Supply:** Displays the current circulating coin supply value
|
||||
- **Price:** Displays the current market price in BTC
|
||||
- **Market Cap:** Displays the current market cap value in BTC
|
||||
- **Price:** Displays the current market price (value measured using default market pair)
|
||||
- **Market Cap:** Displays the current market cap value in (value measured using default market pair)
|
||||
- **Logo:** Display an image of your coin logo
|
||||
- Add as many custom social links to the explorer footer as desired. Useful for linking to github, twitter, coinmarketcap or any other social media or external links as necessary.
|
||||
- Custom rpc/api command support which increases blockchain compatibility. Supported cmds:
|
||||
|
||||
@@ -1,23 +0,0 @@
|
||||
var request = require('postman-request');
|
||||
|
||||
function get_usd_value(cb) {
|
||||
request({ uri: 'https://api.coindesk.com/v1/bpi/currentprice/USD.json', json: true, headers: {'User-Agent': 'eiquidus'} }, function (error, response, body) {
|
||||
if (error)
|
||||
return cb(error, 0);
|
||||
else
|
||||
return cb(null, body.bpi.USD['rate_float'].toFixed(4));
|
||||
});
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
get_data: function (cb) {
|
||||
var error = null;
|
||||
|
||||
get_usd_value(function (err, last_usd) {
|
||||
if (err)
|
||||
error = err;
|
||||
|
||||
return cb(error, last_usd);
|
||||
});
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,43 @@
|
||||
var request = require('postman-request');
|
||||
var base_url = 'https://api.coingecko.com/api/v3/';
|
||||
|
||||
function get_coin_list(cb) {
|
||||
request({ uri: base_url + 'coins/list?include_platform=false', json: true, headers: {'User-Agent': 'eiquidus'} }, function (error, response, body) {
|
||||
if (error)
|
||||
return cb(error, []);
|
||||
else
|
||||
return cb(null, body);
|
||||
});
|
||||
}
|
||||
|
||||
function get_usd_value(id, cb) {
|
||||
request({ uri: base_url + 'simple/price?ids=' + id + '&vs_currencies=usd', json: true, headers: {'User-Agent': 'eiquidus'} }, function (error, response, body) {
|
||||
if (error)
|
||||
return cb(error, 0);
|
||||
else
|
||||
return cb(null, body[id].usd);
|
||||
});
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
get_coin_data: function (cb) {
|
||||
var error = null;
|
||||
|
||||
get_coin_list(function (err, coin_list) {
|
||||
if (err)
|
||||
error = err;
|
||||
|
||||
return cb(error, coin_list);
|
||||
});
|
||||
},
|
||||
get_data: function (id, cb) {
|
||||
var error = null;
|
||||
|
||||
get_usd_value(id, function (err, last_usd) {
|
||||
if (err)
|
||||
error = err;
|
||||
|
||||
return cb(error, last_usd);
|
||||
});
|
||||
}
|
||||
};
|
||||
+42
-17
@@ -12,7 +12,7 @@ var mongoose = require('mongoose'),
|
||||
settings = require('./settings'),
|
||||
locale = require('./locale'),
|
||||
fs = require('fs'),
|
||||
coindesk = require('./apis/coindesk'),
|
||||
coingecko = require('./apis/coingecko'),
|
||||
async = require('async');
|
||||
|
||||
function find_address(hash, caseSensitive, cb) {
|
||||
@@ -817,8 +817,8 @@ module.exports = {
|
||||
history: obj.trades,
|
||||
summary: obj.stats
|
||||
}, function() {
|
||||
// check if this is the default market and trading pair and that the price is recorded in BTC
|
||||
if (market == settings.markets_page.default_exchange.exchange_name && settings.markets_page.default_exchange.trading_pair.toUpperCase() == coin_symbol.toUpperCase() + '/' + pair_symbol.toUpperCase() && pair_symbol.toUpperCase() == 'BTC') {
|
||||
// check if this is the default market and trading pair
|
||||
if (market == settings.markets_page.default_exchange.exchange_name && settings.markets_page.default_exchange.trading_pair.toUpperCase() == coin_symbol.toUpperCase() + '/' + pair_symbol.toUpperCase()) {
|
||||
// this is the default market so update the last price stats
|
||||
Stats.updateOne({coin: settings.coin.name}, {
|
||||
last_price: obj.stats.last
|
||||
@@ -843,22 +843,47 @@ module.exports = {
|
||||
},
|
||||
|
||||
get_last_usd_price: function(cb) {
|
||||
// check if the default market price is enabled and being recorded in BTC
|
||||
if (settings.markets_page.exchanges[settings.markets_page.default_exchange.exchange_name].enabled == true && settings.markets_page.exchanges[settings.markets_page.default_exchange.exchange_name].trading_pairs.findIndex(p => p.toLowerCase().indexOf('/btc') > -1) > -1) {
|
||||
// convert btc to usd via coindesk api
|
||||
coindesk.get_data(function (err, last_usd) {
|
||||
// get current stats
|
||||
Stats.findOne({coin: settings.coin.name}, function(err, stats) {
|
||||
// update the last usd price
|
||||
Stats.updateOne({coin: settings.coin.name}, {
|
||||
last_usd_price: (last_usd * stats.last_price)
|
||||
}, function() {
|
||||
return cb(null);
|
||||
});
|
||||
});
|
||||
// check if the default market is enabled
|
||||
if (settings.markets_page.exchanges[settings.markets_page.default_exchange.exchange_name].enabled == true) {
|
||||
// get the list of coins from coingecko
|
||||
coingecko.get_coin_data(function (err, coin_list) {
|
||||
// check for errors
|
||||
if (err == null) {
|
||||
var symbol = settings.markets_page.default_exchange.trading_pair.split('/')[1];
|
||||
var index = coin_list.findIndex(p => p.symbol.toLowerCase() == symbol.toLowerCase());
|
||||
|
||||
// check if the default market pair is found in the coin list
|
||||
if (index > -1) {
|
||||
// get the usd value of the default market pair from coingecko
|
||||
coingecko.get_data(coin_list[index].id, function (err, last_usd) {
|
||||
// check for errors
|
||||
if (err == null) {
|
||||
// get current stats
|
||||
Stats.findOne({coin: settings.coin.name}, function(err, stats) {
|
||||
// update the last usd price
|
||||
Stats.updateOne({coin: settings.coin.name}, {
|
||||
last_usd_price: (last_usd * stats.last_price)
|
||||
}, function() {
|
||||
// last usd price updated successfully
|
||||
return cb(null);
|
||||
});
|
||||
});
|
||||
} else {
|
||||
// return error msg
|
||||
return cb(err);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
// return error msg
|
||||
return cb('cannot find symbol ' + symbol + ' in the coingecko api');
|
||||
}
|
||||
} else {
|
||||
// return error msg
|
||||
return cb(err);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
// only btc conversion supported so just exit without updating last price for now
|
||||
// default exchange is not enabled so just exit without updating last price for now
|
||||
return cb(null);
|
||||
}
|
||||
},
|
||||
|
||||
+4
-4
@@ -202,7 +202,7 @@ exports.shared_pages = {
|
||||
// The panel will be disabled with a value of 0
|
||||
"display_order": 1
|
||||
},
|
||||
// price_panel: a collection of settings that pertain to the price panel which displays the current market price in BTC
|
||||
// price_panel: a collection of settings that pertain to the price panel which displays the current market price measured against the default market pair
|
||||
"price_panel": {
|
||||
// enabled: Enable/disable the price panel (true/false)
|
||||
// If set to false, the price panel will be completely inaccessible
|
||||
@@ -212,7 +212,7 @@ exports.shared_pages = {
|
||||
// The panel will be disabled with a value of 0
|
||||
"display_order": 4
|
||||
},
|
||||
// market_cap_panel: a collection of settings that pertain to the market cap panel which displays the current market cap value in BTC
|
||||
// market_cap_panel: a collection of settings that pertain to the market cap panel which displays the current market cap value measured against the default market pair
|
||||
"market_cap_panel": {
|
||||
// enabled: Enable/disable the market cap panel (true/false)
|
||||
// If set to false, the market cap panel will be completely inaccessible
|
||||
@@ -890,7 +890,7 @@ exports.api_page = {
|
||||
"enabled": true
|
||||
},
|
||||
// getbasicstats: a collection of settings that pertain to the /ext/getbasicstats api endpoint
|
||||
// Returns basic statistics about the coin including: block count, circulating supply, USD price, BTC price and # of masternodes (# of masternodes is only applicable to masternode coins)
|
||||
// Returns basic statistics about the coin including: block count, circulating supply, USD price, default market price and # of masternodes (# of masternodes is only applicable to masternode coins)
|
||||
// NOTE: This api is not used internally and is therefore only publicly available
|
||||
"getbasicstats": {
|
||||
// enabled: Enable/disable the /ext/getbasicstats api endpoint (true/false)
|
||||
@@ -898,7 +898,7 @@ exports.api_page = {
|
||||
"enabled": true
|
||||
},
|
||||
// getsummary: a collection of settings that pertain to the /ext/getsummary api endpoint
|
||||
// Returns a summary of coin data including: difficulty, hybrid difficulty, circulating supply, hash rate, BTC price, network connection count, block count, count of online masternodes and count of offline masternodes (masternode counts are only applicable to masternode coins)
|
||||
// Returns a summary of coin data including: difficulty, hybrid difficulty, circulating supply, hash rate, default market price, network connection count, block count, count of online masternodes and count of offline masternodes (masternode counts are only applicable to masternode coins)
|
||||
// NOTE: This api is used internally via ajax call to populate many of the panel boxes that are found at the top of all pages. Disabling the api from here will not stop the panel boxes from displaying data
|
||||
"getsummary": {
|
||||
// enabled: Enable/disable the /ext/getsummary api endpoint (true/false)
|
||||
|
||||
+13
-6
@@ -572,13 +572,20 @@ function remove_sync_message() {
|
||||
}
|
||||
|
||||
function get_last_usd_price() {
|
||||
// Get the last usd price for coinstats
|
||||
db.get_last_usd_price(function(retVal) {
|
||||
// update markets_last_updated value
|
||||
db.update_last_updated_stats(settings.coin.name, { markets_last_updated: Math.floor(new Date() / 1000) }, function (cb) {
|
||||
console.log('market sync complete');
|
||||
// get the last usd price for coinstats
|
||||
db.get_last_usd_price(function(err) {
|
||||
// check for errors
|
||||
if (err == null) {
|
||||
// update markets_last_updated value
|
||||
db.update_last_updated_stats(settings.coin.name, { markets_last_updated: Math.floor(new Date() / 1000) }, function (cb) {
|
||||
console.log('market sync complete');
|
||||
exit();
|
||||
});
|
||||
} else {
|
||||
// display error msg
|
||||
console.log('error: %s', err);
|
||||
exit();
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -201,7 +201,7 @@
|
||||
// The panel will be disabled with a value of 0
|
||||
"display_order": 1
|
||||
},
|
||||
// price_panel: a collection of settings that pertain to the price panel which displays the current market price in BTC
|
||||
// price_panel: a collection of settings that pertain to the price panel which displays the current market price measured against the default market pair
|
||||
"price_panel": {
|
||||
// enabled: Enable/disable the price panel (true/false)
|
||||
// If set to false, the price panel will be completely inaccessible
|
||||
@@ -211,7 +211,7 @@
|
||||
// The panel will be disabled with a value of 0
|
||||
"display_order": 4
|
||||
},
|
||||
// market_cap_panel: a collection of settings that pertain to the market cap panel which displays the current market cap value in BTC
|
||||
// market_cap_panel: a collection of settings that pertain to the market cap panel which displays the current market cap value measured against the default market pair
|
||||
"market_cap_panel": {
|
||||
// enabled: Enable/disable the market cap panel (true/false)
|
||||
// If set to false, the market cap panel will be completely inaccessible
|
||||
@@ -970,7 +970,7 @@
|
||||
"enabled": true
|
||||
},
|
||||
// getbasicstats: a collection of settings that pertain to the /ext/getbasicstats api endpoint
|
||||
// Returns basic statistics about the coin including: block count, circulating supply, USD price, BTC price and # of masternodes (# of masternodes is only applicable to masternode coins)
|
||||
// Returns basic statistics about the coin including: block count, circulating supply, USD price, default market price and # of masternodes (# of masternodes is only applicable to masternode coins)
|
||||
// NOTE: This api is not used internally and is therefore only publicly available
|
||||
"getbasicstats": {
|
||||
// enabled: Enable/disable the /ext/getbasicstats api endpoint (true/false)
|
||||
@@ -978,7 +978,7 @@
|
||||
"enabled": true
|
||||
},
|
||||
// getsummary: a collection of settings that pertain to the /ext/getsummary api endpoint
|
||||
// Returns a summary of coin data including: difficulty, hybrid difficulty, circulating supply, hash rate, BTC price, network connection count, block count, count of online masternodes and count of offline masternodes (masternode counts are only applicable to masternode coins)
|
||||
// Returns a summary of coin data including: difficulty, hybrid difficulty, circulating supply, hash rate, default market price, network connection count, block count, count of online masternodes and count of offline masternodes (masternode counts are only applicable to masternode coins)
|
||||
// NOTE: This api is used internally via ajax call to populate many of the panel boxes that are found at the top of all pages. Disabling the api from here will not stop the panel boxes from displaying data
|
||||
"getsummary": {
|
||||
// enabled: Enable/disable the /ext/getsummary api endpoint (true/false)
|
||||
|
||||
+2
-2
@@ -236,14 +236,14 @@ block content
|
||||
p
|
||||
div.font-weight-bold getbasicstats
|
||||
div
|
||||
em="Returns basic statistics about the coin including: block count, circulating supply, USD price, BTC price" + (settings.api_page.public_apis.rpc.getmasternodecount.enabled == true && settings.api_cmds['getmasternodecount'] != null && settings.api_cmds['getmasternodecount'] != '' ? ', ' + '# of masternodes' : '')
|
||||
em="Returns basic statistics about the coin including: block count, circulating supply, USD price, " + settings.markets_page.default_exchange.trading_pair.split('/')[1].toUpperCase() + " price" + (settings.api_page.public_apis.rpc.getmasternodecount.enabled == true && settings.api_cmds['getmasternodecount'] != null && settings.api_cmds['getmasternodecount'] != '' ? ', ' + '# of masternodes' : '')
|
||||
a(href='/ext/getbasicstats') #{address}/ext/getbasicstats
|
||||
if settings.api_page.public_apis.ext.getsummary.enabled == true
|
||||
li
|
||||
p
|
||||
div.font-weight-bold getsummary
|
||||
div
|
||||
em="Returns a summary of coin data including: difficulty, hybrid difficulty, circulating supply, hash rate, BTC price, network connection count, block count" + (settings.api_page.public_apis.rpc.getmasternodecount.enabled == true && settings.api_cmds['getmasternodecount'] != null && settings.api_cmds['getmasternodecount'] != '' ? ', ' + 'count of online masternodes' + ', ' + 'count of offline masternodes' : '')
|
||||
em="Returns a summary of coin data including: difficulty, hybrid difficulty, circulating supply, hash rate, " + settings.markets_page.default_exchange.trading_pair.split('/')[1].toUpperCase() + " price, network connection count, block count" + (settings.api_page.public_apis.rpc.getmasternodecount.enabled == true && settings.api_cmds['getmasternodecount'] != null && settings.api_cmds['getmasternodecount'] != '' ? ', ' + 'count of online masternodes' + ', ' + 'count of offline masternodes' : '')
|
||||
a(href='/ext/getsummary') #{address}/ext/getsummary
|
||||
if settings.api_page.public_apis.ext.getmasternodelist.enabled == true && settings.api_cmds['getmasternodelist'] != null && settings.api_cmds['getmasternodelist'] != ''
|
||||
li
|
||||
|
||||
Reference in New Issue
Block a user