Skip to content
Permalink
Browse files

Merge pull request #307 from TheHolyRogerCoin/altmarkets

Add AltMarkets.io Exchange support to Markets
  • Loading branch information
iquidus committed Nov 20, 2019
2 parents 1ed4734 + ef8af68 commit 3e6925a5b9556ff2b9d0f4272c95256d04eedb8d
Showing with 229 additions and 1 deletion.
  1. +7 −1 lib/database.js
  2. +1 −0 lib/locale.js
  3. +103 −0 lib/markets/altmarkets.js
  4. +1 −0 locale/en.json
  5. +117 −0 views/markets/altmarkets.jade
@@ -15,7 +15,8 @@ var mongoose = require('mongoose')
, cryptopia = require('./markets/cryptopia')
, yobit = require('./markets/yobit')
, empoex = require('./markets/empoex')
, ccex = require('./markets/ccex');
, ccex = require('./markets/ccex')
, altmarkets = require('./markets/altmarkets');
// , BTC38 = require('./markets/BTC38');

function find_address(hash, cb) {
@@ -190,6 +191,11 @@ function save_tx(txid, cb) {

function get_market_data(market, cb) {
switch(market) {
case 'altmarkets':
altmarkets.get_data(settings.markets.coin, settings.markets.exchange, function(err, obj){
return cb(err, obj);
});
break;
case 'bittrex':
bittrex.get_data(settings.markets.coin, settings.markets.exchange, function(err, obj){
return cb(err, obj);
@@ -136,6 +136,7 @@ exports.heavy_lastxvotes = "Last 20 votes",

exports.poloniex = "Poloniex",
exports.bittrex = "Bittrex",
exports.altmarkets = "AltMarkets",
exports.bleutrade = "Bleutrade",
exports.yobit = "Yobit",
exports.cryptsy = "Cryptsy",
@@ -0,0 +1,103 @@
var request = require('request');

var base_url = 'https://altmarkets.io/api/v2/';

function get_summary(coin, exchange, cb) {
var req_url = base_url + 'tickers/' + coin.toLowerCase() + exchange.toLowerCase();
var summary = {};
request({uri: req_url, json: true}, function (error, response, body) {
if (error) {
return cb(error, null);
} else {
if (body.error) {
return cb(body.error, null);
} else {
summary['bid'] = parseFloat(body['ticker']['buy']).toFixed(8);
summary['ask'] = parseFloat(body['ticker']['sell']).toFixed(8);
summary['volume'] = parseFloat(body['ticker']['vol']).toFixed(8);
summary['volume_btc'] = parseFloat(body['ticker']['quotevol']).toFixed(8);
summary['high'] = parseFloat(body['ticker']['high']).toFixed(8);
summary['low'] = parseFloat(body['ticker']['low']).toFixed(8);
summary['last'] = parseFloat(body['ticker']['last']).toFixed(8);
request({ uri: base_url + 'k?market=' + coin.toLowerCase() + "" + exchange.toLowerCase() + '&period=1&time_to=' + (Math.round(Date.now()/1000)-(60*60*24)) + '&limit=1', json: true }, function (error, response, body) {
if (error) {
return cb(error, null);
} else {
if (body.error) {
return cb(body.error, null);
} else {
var prevlast = body[0][4];
summary['change'] = -(100-(((1/prevlast)*summary['last'])*100));
return cb(null, summary);
}
}
});
}
}
});
}

function get_trades(coin, exchange, cb) {
var req_url = base_url + "trades?market=" + coin.toLowerCase() + "" + exchange.toLowerCase() + "&limit=50&order_by=desc";
request({uri: req_url, json: true}, function (error, response, body) {
if (body.error) {
return cb(body.error, null);
} else {
return cb (null, body);
}
});
}

function get_orders(coin, exchange, cb) {
var req_url = base_url + 'depth?market=' + coin.toLowerCase() + exchange.toLowerCase();
request({uri: req_url, json: true}, function (error, response, body) {
if (body.error) {
return cb(body.error, [], [])
} else {
var orders = body;
var buys = [];
var sells = [];
if (orders['bids'].length > 0){
for (var i = 0; i < orders['bids'].length; i++) {
var order = {
amount: parseFloat(orders.bids[i][1]).toFixed(8),
price: parseFloat(orders.bids[i][0]).toFixed(8),
// total: parseFloat(orders.bids[i].Total).toFixed(8)
// Necessary because API will return 0.00 for small volume transactions
total: (parseFloat(orders.bids[i][1]).toFixed(8) * parseFloat(orders.bids[i][0])).toFixed(8)
}
buys.push(order);
}
} else {}
if (orders['asks'].length > 0) {
for (var x = 0; x < orders['asks'].length; x++) {
var order = {
amount: parseFloat(orders.asks[x][1]).toFixed(8),
price: parseFloat(orders.asks[x][0]).toFixed(8),
// total: parseFloat(orders.asks[x].Total).toFixed(8)
// Necessary because API will return 0.00 for small volume transactions
total: (parseFloat(orders.asks[x][1]).toFixed(8) * parseFloat(orders.asks[x][0])).toFixed(8)
}
sells.push(order);
}
} else {}
return cb(null, buys, sells);
}
});
}

module.exports = {
get_data: function(coin, exchange, cb) {
var error = null;
get_orders(coin, exchange, function(err, buys, sells) {
if (err) { error = err; }
get_trades(coin, exchange, function(err, trades) {
if (err) { error = err; }
get_summary(coin, exchange, function(err, stats) {
if (err) { error = err; }
return cb(error, {buys: buys, sells: sells, chartdata: [], trades: trades, stats: stats});
});
});
});
}
};
@@ -127,6 +127,7 @@
// Markets
"poloniex": "Poloniex",
"bittrex": "Bittrex",
"altmarkets": "AltMarkets",
"bleutrade": "Bleutrade",
"yobit": "Yobit",
"empoex": "Empoex",
@@ -0,0 +1,117 @@
extends menu

block market_view
.row
.col-md-12
.panel.panel-default
.panel-heading
strong #{settings.locale.altmarkets} - #{marketdata.coin}/#{marketdata.exchange} - #{settings.locale.mkt_hours}
a(href='#')
span.fa.fa-line-chart.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} (#{marketdata.coin})
th #{settings.locale.mkt_volume} (#{marketdata.exchange})
th.hidden-xs #{settings.locale.mkt_top_bid}
th.hidden-xs #{settings.locale.mkt_top_ask}
th.hidden-xs #{settings.locale.mkt_last}
th #{settings.locale.mkt_change}
tbody
tr
td #{marketdata.data.summary.high}
td #{marketdata.data.summary.low}
td #{marketdata.data.summary.volume}
td #{marketdata.data.summary.volume_btc}
td.hidden-xs #{marketdata.data.summary.bid}
td.hidden-xs #{marketdata.data.summary.ask}
td.hidden-xs #{marketdata.data.summary.last}
- var altmarkets_change = (marketdata.data.summary.change).toFixed(4);
if altmarkets_change >= 0
td.success +#{altmarkets_change} %
else
td.danger #{altmarkets_change} %
.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.side == 'up'
tr.success
td.hidden-xs
=order.side
td
=parseFloat(order.volume).toFixed(8)
td
=parseFloat(order.price).toFixed(8)
td
=parseFloat(order.funds).toFixed(8)
td.hidden-xs
=(new Date(order.timestamp * 1000).toUTCString())
else
tr.danger
td.hidden-xs
=order.side
td
=parseFloat(order.volume).toFixed(8)
td
=parseFloat(order.price).toFixed(8)
td
=parseFloat(order.funds).toFixed(8)
td.hidden-xs
=(new Date(order.timestamp * 1000).toUTCString())

.footer-padding

0 comments on commit 3e6925a

Please sign in to comment.
You can’t perform that action at this time.