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:
+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);
|
||||
}
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user