-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #307 from TheHolyRogerCoin/altmarkets
Add AltMarkets.io Exchange support to Markets
- Loading branch information
Showing
5 changed files
with
229 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -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}); | |||
}); | |||
}); | |||
}); | |||
} | |||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -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 | |||
|