This commit is contained in:
joeuhren
2019-06-07 20:05:28 -06:00
parent 60fb8e29b4
commit a175e03bfa
13 changed files with 332 additions and 36 deletions
+7 -1
View File
@@ -1,4 +1,10 @@
NOTE: All updates require the explorer to be restarted
1.0.0
1.0.1 [June 7, 2019]
-Added stex.com market support
-Added a new public api /ext/getbasicstats
-Fixed all depreciation warnings regarding mongo db.update statements
-Updated outdated mongodb and mongoose references
1.0.0 [May 27, 2019]
-Initial release
+13
View File
@@ -117,6 +117,19 @@ app.use('/ext/getcurrentprice', function(req,res){
});
});
app.use('/ext/getbasicstats', function(req,res){
lib.get_blockcount(function(blockcount){
lib.get_supply(function(supply){
db.get_stats(settings.coin, function (stats){
lib.get_masternodecount(function(masternodestotal){
eval('var p_ext = { "block_count": blockcount, "money_supply": supply, "last_price_'+settings.markets.exchange.toLowerCase()+'": stats.last_price, "last_price_usd": stats.last_usd_price, "masternode_count": masternodestotal.total }');
res.send(p_ext);
});
});
});
});
});
app.use('/ext/connections', function(req,res){
db.get_peers(function(peers){
res.send({data: peers});
+19 -13
View File
@@ -17,6 +17,7 @@ var mongoose = require('mongoose')
, empoex = require('./markets/empoex')
, ccex = require('./markets/ccex')
, coinexchange = require('./markets/coinexchange')
, stex = require('./markets/stex')
, coindesk = require('./apis/coindesk');
function find_address(hash, cb) {
@@ -45,7 +46,7 @@ function update_address(hash, txid, amount, type, cb) {
if (address) {
// if coinbase (new coins PoW), update sent only and return cb.
if ( hash == 'coinbase' ) {
Address.update({a_id:hash}, {
Address.updateOne({a_id:hash}, {
sent: address.sent + amount,
balance: 0,
}, function() {
@@ -67,7 +68,7 @@ function update_address(hash, txid, amount, type, cb) {
if ( tx_array.length > settings.txcount ) {
tx_array.shift();
}
Address.update({a_id:hash}, {
Address.updateOne({a_id:hash}, {
txs: tx_array,
received: received,
sent: sent,
@@ -79,7 +80,7 @@ function update_address(hash, txid, amount, type, cb) {
if (type == tx_array[index].type) {
return cb(); //duplicate
} else {
Address.update({a_id:hash}, {
Address.updateOne({a_id:hash}, {
txs: tx_array,
received: received,
sent: sent,
@@ -236,6 +237,11 @@ function get_market_data(market, cb) {
return cb(err, obj);
});
break;
case 'stex':
stex.get_data(settings.markets.coin, settings.markets.exchange, settings.markets.stex_id, function(err, obj){
return cb(err, obj);
});
break;
default:
return cb(null);
}
@@ -263,7 +269,7 @@ module.exports = {
Stats.findOne({last_usd_price: {$exists: false}}, function(err, stats) {
if (stats) {
// the last_usd_price needs to be added to the collection
Stats.update({coin: coin}, {
Stats.updateOne({coin: coin}, {
last_usd_price: 0,
}, function() { return cb(null); });
}
@@ -317,7 +323,7 @@ module.exports = {
update_richlist: function(list, cb){
if(list == 'received') {
Address.find({}).sort({received: 'desc'}).limit(100).exec(function(err, addresses){
Richlist.update({coin: settings.coin}, {
Richlist.updateOne({coin: settings.coin}, {
received: addresses,
}, function() {
return cb();
@@ -325,7 +331,7 @@ module.exports = {
});
} else { //balance
Address.find({}).sort({balance: 'desc'}).limit(100).exec(function(err, addresses){
Richlist.update({coin: settings.coin}, {
Richlist.updateOne({coin: settings.coin}, {
balance: addresses,
}, function() {
return cb();
@@ -563,7 +569,7 @@ module.exports = {
});
}, function(){
console.log(newVotes);
Heavy.update({coin: coin}, {
Heavy.updateOne({coin: coin}, {
lvote: vote,
reward: reward,
supply: supply,
@@ -592,7 +598,7 @@ module.exports = {
update_markets_db: function(market, cb) {
get_market_data(market, function (err, obj) {
if (err == null) {
Markets.update({market:market}, {
Markets.updateOne({market:market}, {
chartdata: JSON.stringify(obj.chartdata),
buys: obj.buys,
sells: obj.sells,
@@ -600,7 +606,7 @@ module.exports = {
summary: obj.stats,
}, function() {
if ( market == settings.markets.default ) {
Stats.update({coin:settings.coin}, {
Stats.updateOne({coin:settings.coin}, {
last_price: obj.stats.last,
}, function(){
return cb(null);
@@ -623,7 +629,7 @@ module.exports = {
// Get current stats
Stats.findOne({coin:settings.coin}, function(err, stats) {
// Update the last usd price
Stats.update({coin:settings.coin}, {
Stats.updateOne({coin:settings.coin}, {
last_usd_price: (last_usd * stats.last_price),
}, function(){
return cb(null);
@@ -644,7 +650,7 @@ module.exports = {
}
lib.get_supply( function (supply){
lib.get_connectioncount(function (connections) {
Stats.update({coin: coin}, {
Stats.updateOne({coin: coin}, {
coin: coin,
count : count,
supply: supply,
@@ -664,7 +670,7 @@ module.exports = {
var x = loop.iteration();
if (x % 5000 === 0) {
Tx.find({}).where('blockindex').lt(start + x).sort({timestamp: 'desc'}).limit(settings.index.last_txs).exec(function(err, txs){
Stats.update({coin: coin}, {
Stats.updateOne({coin: coin}, {
last: start + x - 1,
last_txs: '' //not used anymore left to clear out existing objects
}, function() {});
@@ -710,7 +716,7 @@ module.exports = {
});
}, function(){
Tx.find({}).sort({timestamp: 'desc'}).limit(settings.index.last_txs).exec(function(err, txs){
Stats.update({coin: coin}, {
Stats.updateOne({coin: coin}, {
last: end,
last_txs: '' //not used anymore left to clear out existing objects
}, function() {
+1
View File
@@ -148,6 +148,7 @@ exports.cryptopia = "Cryptopia",
exports.empoex = "Empoex",
exports.ccex = "C-Cex",
exports.coinexchange = "CoinExchange",
exports.stex = "Stex",
exports.reloadLocale = function reloadLocale(locale) {
// Discover where the locale file lives
+19 -13
View File
@@ -17,6 +17,7 @@ var mongoose = require('mongoose')
, empoex = require('./markets/empoex')
, ccex = require('./markets/ccex')
, coinexchange = require('./markets/coinexchange')
, stex = require('./markets/stex')
, coindesk = require('./apis/coindesk');
function find_address(hash, cb) {
@@ -45,7 +46,7 @@ function update_address(hash, txid, amount, type, cb) {
if (address) {
// if coinbase (new coins PoW), update sent only and return cb.
if ( hash == 'coinbase' ) {
Address.update({a_id:hash}, {
Address.updateOne({a_id:hash}, {
sent: address.sent + amount,
balance: 0,
}, function() {
@@ -67,7 +68,7 @@ function update_address(hash, txid, amount, type, cb) {
if ( tx_array.length > settings.txcount ) {
tx_array.shift();
}
Address.update({a_id:hash}, {
Address.updateOne({a_id:hash}, {
txs: tx_array,
received: received,
sent: sent,
@@ -79,7 +80,7 @@ function update_address(hash, txid, amount, type, cb) {
if (type == tx_array[index].type) {
return cb(); //duplicate
} else {
Address.update({a_id:hash}, {
Address.updateOne({a_id:hash}, {
txs: tx_array,
received: received,
sent: sent,
@@ -236,6 +237,11 @@ function get_market_data(market, cb) {
return cb(err, obj);
});
break;
case 'stex':
stex.get_data(settings.markets.coin, settings.markets.exchange, settings.markets.stex_id, function(err, obj){
return cb(err, obj);
});
break;
default:
return cb(null);
}
@@ -263,7 +269,7 @@ module.exports = {
Stats.findOne({last_usd_price: {$exists: false}}, function(err, stats) {
if (stats) {
// the last_usd_price needs to be added to the collection
Stats.update({coin: coin}, {
Stats.updateOne({coin: coin}, {
last_usd_price: 0,
}, function() { return cb(null); });
}
@@ -317,7 +323,7 @@ module.exports = {
update_richlist: function(list, cb){
if(list == 'received') {
Address.find({}).sort({received: 'desc'}).limit(100).exec(function(err, addresses){
Richlist.update({coin: settings.coin}, {
Richlist.updateOne({coin: settings.coin}, {
received: addresses,
}, function() {
return cb();
@@ -325,7 +331,7 @@ module.exports = {
});
} else { //balance
Address.find({}).sort({balance: 'desc'}).limit(100).exec(function(err, addresses){
Richlist.update({coin: settings.coin}, {
Richlist.updateOne({coin: settings.coin}, {
balance: addresses,
}, function() {
return cb();
@@ -563,7 +569,7 @@ module.exports = {
});
}, function(){
console.log(newVotes);
Heavy.update({coin: coin}, {
Heavy.updateOne({coin: coin}, {
lvote: vote,
reward: reward,
supply: supply,
@@ -592,7 +598,7 @@ module.exports = {
update_markets_db: function(market, cb) {
get_market_data(market, function (err, obj) {
if (err == null) {
Markets.update({market:market}, {
Markets.updateOne({market:market}, {
chartdata: JSON.stringify(obj.chartdata),
buys: obj.buys,
sells: obj.sells,
@@ -600,7 +606,7 @@ module.exports = {
summary: obj.stats,
}, function() {
if ( market == settings.markets.default ) {
Stats.update({coin:settings.coin}, {
Stats.updateOne({coin:settings.coin}, {
last_price: obj.stats.last,
}, function(){
return cb(null);
@@ -623,7 +629,7 @@ module.exports = {
// Get current stats
Stats.findOne({coin:settings.coin}, function(err, stats) {
// Update the last usd price
Stats.update({coin:settings.coin}, {
Stats.updateOne({coin:settings.coin}, {
last_usd_price: (last_usd * stats.last_price),
}, function(){
return cb(null);
@@ -644,7 +650,7 @@ module.exports = {
}
lib.get_supply( function (supply){
lib.get_connectioncount(function (connections) {
Stats.update({coin: coin}, {
Stats.updateOne({coin: coin}, {
coin: coin,
count : count,
supply: supply,
@@ -664,7 +670,7 @@ module.exports = {
var x = loop.iteration();
if (x % 5000 === 0) {
Tx.find({}).where('blockindex').lt(start + x).sort({timestamp: 'desc'}).limit(settings.index.last_txs).exec(function(err, txs){
Stats.update({coin: coin}, {
Stats.updateOne({coin: coin}, {
last: start + x - 1,
last_txs: '' //not used anymore left to clear out existing objects
}, function() {});
@@ -710,7 +716,7 @@ module.exports = {
});
}, function(){
Tx.find({}).sort({timestamp: 'desc'}).limit(settings.index.last_txs).exec(function(err, txs){
Stats.update({coin: coin}, {
Stats.updateOne({coin: coin}, {
last: end,
last_txs: '' //not used anymore left to clear out existing objects
}, function() {
+140
View File
@@ -0,0 +1,140 @@
var request = require('request');
var base_url = 'https://api3.stex.com/public';
function get_summary(coin, exchange, stex_id, cb) {
var summary = {};
request({ uri: base_url + '/ticker/' + stex_id, json: true, headers: {'User-Agent': 'eiquidus'} }, function (error, response, body) {
if (error)
return cb(error, null);
else if (body.success === true) {
summary['bid'] = parseFloat(body.data['bid']).toFixed(8);
summary['ask'] = parseFloat(body.data['ask']).toFixed(8);
summary['volume'] = body.data['volume'];
summary['high'] = parseFloat(body.data['high']).toFixed(8);
summary['low'] = parseFloat(body.data['low']).toFixed(8);
summary['last'] = parseFloat(body.data['last']).toFixed(8);
return cb(null, summary);
} else
return cb(error, null);
}).on('error', function(err) {
return cb(error, null);
});
}
function get_trades(coin, exchange, stex_id, cb) {
var req_url = base_url + '/trades/' + stex_id + '?sort=DESC&limit=100';
request({ uri: req_url, json: true, headers: {'User-Agent': 'eiquidus'} }, function (error, response, body) {
if (body.success == true) {
var tTrades = body.data;
var trades = [];
for (var i = 0; i < tTrades.length; i++) {
var Trade = {
orderpair: coin,
ordertype: tTrades[i].type,
amount: parseFloat(tTrades[i].amount).toFixed(8),
price: parseFloat(tTrades[i].price).toFixed(8),
// total: parseFloat(tTrades[i].Total).toFixed(8)
// Necessary because API will return 0.00 for small volume transactions
total: (parseFloat(tTrades[i].amount).toFixed(8) * parseFloat(tTrades[i].price)).toFixed(8),
timestamp: tTrades[i].timestamp
}
trades.push(Trade);
}
return cb(null, trades);
}
else
return cb(body.message, null);
}).on('error', function(err) {
return cb(error, null);
});
}
function get_orders(coin, exchange, stex_id, cb) {
var req_url = base_url + '/orderbook/' + stex_id + '?limit_bids=100&limit_asks=100';
request({ uri: req_url, json: true, headers: {'User-Agent': 'eiquidus'} }, function (error, response, body) {
if (body.success == true) {
var orders = body.data;
var buys = [];
var sells = [];
if (orders['bid'].length > 0){
for (var i = 0; i < orders['bid'].length; i++) {
var order = {
amount: parseFloat(orders.bid[i].amount).toFixed(8),
price: parseFloat(orders.bid[i].price).toFixed(8),
// total: parseFloat(orders.bid[i].Total).toFixed(8)
// Necessary because API will return 0.00 for small volume transactions
total: (parseFloat(orders.bid[i].amount).toFixed(8) * parseFloat(orders.bid[i].price)).toFixed(8)
}
buys.push(order);
}
}
if (orders['ask'].length > 0) {
for (var x = 0; x < orders['ask'].length; x++) {
var order = {
amount: parseFloat(orders.ask[x].amount).toFixed(8),
price: parseFloat(orders.ask[x].price).toFixed(8),
// total: parseFloat(orders.ask[x].Total).toFixed(8)
// Necessary because API will return 0.00 for small volume transactions
total: (parseFloat(orders.ask[x].amount).toFixed(8) * parseFloat(orders.ask[x].price)).toFixed(8)
}
sells.push(order);
}
}
return cb(null, buys, sells);
}
else
return cb(body.message, [], [])
}).on('error', function(err) {
return cb(error, null, null);
});
}
function get_chartdata(coin, exchange, stex_id, cb) {
// do not collect chart data for now
return cb(null, []);
/*
var req_url = base_url + '/chart/' + stex_id + '/30?timeStart=' + start + '&timeEnd=' + end + '&limit=100';
var end = Date.now();
end = end / 1000;
start = end - 86400;
request({ uri: req_url, json: true, headers: {'User-Agent': 'eiquidus'} }, function (error, response, chartdata) {
if (error) {
return cb(error, []);
} else {
if (chartdata.success == true) {
var processed = [];
for (var i = 0; i < chartdata.data.length; i++) {
processed.push([chartdata.data[i].time, parseFloat(chartdata.data[i].open), parseFloat(chartdata.data[i].high), parseFloat(chartdata.data[i].low), parseFloat(chartdata.data[i].close)]);
if (i == chartdata.data.length - 1)
return cb(null, processed);
}
}
else
return cb(chartdata.message, []);
}
});
*/
}
module.exports = {
get_data: function (coin, exchange, stex_id, cb) {
var error = null;
get_chartdata(coin, exchange, stex_id, function (err, chartdata) {
if (err) { chartdata = []; error = err; }
get_orders(coin, exchange, stex_id, function (err, buys, sells) {
if (err) { error = err; }
get_trades(coin, exchange, stex_id, function (err, trades) {
if (err) { error = err; }
get_summary(coin, exchange, stex_id, function (err, stats) {
if (err) { error = err; }
return cb(error, { buys: buys, sells: sells, chartdata: chartdata, trades: trades, stats: stats });
});
});
});
});
}
};
+1
View File
@@ -98,6 +98,7 @@ exports.markets = {
"cryptopia_id": "",
"ccex_key" : "Get-Your-Own-Key",
"coinexchange_id": "",
"stex_id": "",
"default": ""
};
+1
View File
@@ -138,6 +138,7 @@
"cryptopia": "Cryptopia",
"ccex": "C-Cex",
"coinexchange": "CoinExchange",
"stex": "Stex",
// Heavy rewards view
"heavy_title": "Reward/voting information",
+3 -3
View File
@@ -17,11 +17,11 @@
"pug": "~2.0.3",
"request": "2.88.0",
"jsonminify": "0.4.1",
"mongodb": "3.2.6",
"mongoose": "5.5.11",
"mongodb": "3.2.7",
"mongoose": "5.5.13",
"qr-image": "~3.2.0"
},
"devDependencies": {
"jasmine": "~3.4.0"
}
}
}
+14 -5
View File
@@ -146,11 +146,11 @@ is_locked(function (exists) {
if (mode == 'reindex') {
Tx.remove({}, function(err) {
Address.remove({}, function(err2) {
Richlist.update({coin: settings.coin}, {
Richlist.updateOne({coin: settings.coin}, {
received: [],
balance: [],
}, function(err3) {
Stats.update({coin: settings.coin}, {
Stats.updateOne({coin: settings.coin}, {
last: 0,
}, function() {
console.log('index cleared (reindex)');
@@ -203,21 +203,30 @@ is_locked(function (exists) {
if (!err) {
console.log('%s market data updated successfully.', mkt);
complete++;
if (complete == markets.length)
get_last_usd_price();
} else {
console.log('%s: %s', mkt, err);
complete++;
if (complete == markets.length)
get_last_usd_price();
}
});
} else {
console.log('error: entry for %s does not exists in markets db.', mkt);
complete++;
if (complete == markets.length)
get_last_usd_price();
}
});
}
// Get the last usd price for coinstats
db.get_last_usd_price(function(retVal) { exit(); });
}
});
});
}
});
});
function get_last_usd_price() {
// Get the last usd price for coinstats
db.get_last_usd_price(function(retVal) { exit(); });
}
+2 -1
View File
@@ -107,7 +107,7 @@
},
// market settings
//supported markets: bittrex, poloniex, yobit, empoex, bleutrade, cryptopia, ccex, coinexchange
//supported markets: bittrex, poloniex, yobit, empoex, bleutrade, cryptopia, ccex, coinexchange, stex
//default market is loaded by default and determines last price in header
"markets": {
"coin": "EXOR",
@@ -116,6 +116,7 @@
"cryptopia_id": "",
"ccex_key" : "Get-Your-Own-Key",
"coinexchange_id": "",
"stex_id": "",
"default": ""
},
+6
View File
@@ -158,6 +158,12 @@ block content
div
em Returns last known exchange price
a(href='/ext/getcurrentprice') #{address}/ext/getcurrentprice
li
p
div(style='font-weight:bold;') getbasicstats
div
em Returns basic statistics about the coin including: block count, circulating supply, USD price, BTC price and # of masternodes
a(href='/ext/getbasicstats') #{address}/ext/getbasicstats
hr
h3 Linking (GET)
p
+106
View File
@@ -0,0 +1,106 @@
extends menu
block market_view
.row
.col-md-12
.panel.panel-default
.panel-heading
strong #{settings.locale.stex} - #{marketdata.coin}/#{marketdata.exchange} - #{settings.locale.mkt_hours}
a(href='#')
span.fas.fa-chart-line.pull-right.view-chart-disabled.iquidus.market-toggle(data-toggle='tooltip', data-placement='bottom', title=settings.locale.mkt_no_chart)
table.table.table-bordered.summary-table
thead
tr
th #{settings.locale.mkt_high}
th #{settings.locale.mkt_low}
th #{settings.locale.mkt_volume}
th.hidden-xs #{settings.locale.mkt_top_bid}
th.hidden-xs #{settings.locale.mkt_top_ask}
th.hidden-xs #{settings.locale.mkt_last}
tbody
tr
td #{marketdata.data.summary.high}
td #{marketdata.data.summary.low}
td #{marketdata.data.summary.volume}
td.hidden-xs #{marketdata.data.summary.bid}
td.hidden-xs #{marketdata.data.summary.ask}
td.hidden-xs #{marketdata.data.summary.last}
.row
.col-md-6.col-xs-12
.panel.panel-default
.panel-heading
h3.panel-title #{settings.locale.mkt_buy_orders}
table.table.table-striped.table-bordered.order-table
thead
tr
th #{settings.locale.mkt_price} (#{marketdata.exchange})
th #{settings.locale.mkt_amount} (#{marketdata.coin})
th.hidden-xs #{settings.locale.mkt_total} (#{marketdata.exchange})
tbody
each buy in marketdata.data.buys
tr
td
=buy.price
td
=buy.amount
td.hidden-xs
=buy.total
.col-md-6.col-xs-12
.panel.panel-default
.panel-heading
h3.panel-title #{settings.locale.mkt_sell_orders}
table.table.table-striped.table-bordered.order-table
thead
tr
th #{settings.locale.mkt_price} (#{marketdata.exchange})
th #{settings.locale.mkt_amount} (#{marketdata.coin})
th.hidden-xs #{settings.locale.mkt_total} (#{marketdata.exchange})
tbody
each sell in marketdata.data.sells
tr
td
=sell.price
td
=sell.amount
td.hidden-xs
=sell.total
.row
.col-md-12
.panel.panel-default
.panel-heading
h3.panel-title #{settings.locale.mkt_trade_history}
table.table.table-hover.history-table.table-bordered(cellspacing="0")
thead
tr
th.hidden-xs #{settings.locale.mkt_type}
th #{settings.locale.mkt_amount} (#{marketdata.coin})
th #{settings.locale.mkt_price} (#{marketdata.exchange})
th #{settings.locale.mkt_total} (#{marketdata.exchange})
th.hidden-xs #{settings.locale.mkt_time_stamp}
tbody
each order in marketdata.data.history
if order.ordertype.toUpperCase() == 'BUY'
tr.success
td.hidden-xs
=order.ordertype
td
=order.amount
td
=order.price
td
=order.total
td.hidden-xs
=(new Date(order.timestamp * 1000).toUTCString())
else
tr.danger
td.hidden-xs
=order.ordertype
td
=order.amount
td
=order.price
td
=order.total
td.hidden-xs
=(new Date(order.timestamp * 1000).toUTCString())
.footer-padding