From eeb39fc0d0f3c47faf6a4a721ce0c203a7832dc9 Mon Sep 17 00:00:00 2001 From: Adam Soltys Date: Sat, 14 Jun 2014 23:07:26 -0700 Subject: Get rates from bitcoinaverage.com --- routes/calculator.coffee | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) (limited to 'routes') diff --git a/routes/calculator.coffee b/routes/calculator.coffee index 8cc6aa49..dc9a6d43 100644 --- a/routes/calculator.coffee +++ b/routes/calculator.coffee @@ -8,19 +8,21 @@ exports.show = (req, res) -> ) exports.ticker = (req, res) -> - options = - host: 'api.bitcoinaverage.com', - path: "/exchanges/CAD" + fs = require('fs') + fs.readFile("./public/js/rates.json", (err, data) -> + req.query.currency ||= 'CAD' + req.query.symbol ||= 'quadrigacx' + req.query.type ||= 'bid' - require('https').get(options, (r) -> - r.setEncoding('utf-8') - r.on('data', (chunk) -> - exchange = JSON.parse(chunk).cavirtex.rates[req.query.type].toString() + try + exchange = JSON.parse(data)[req.query.currency][req.query.symbol]['rates'][req.query.type].toString() + catch e + exchange = "0" - res.writeHead(200, - 'Content-Length': exchange.length, - 'Content-Type': 'text/plain') - res.write(exchange) - res.end() - ) + res.writeHead(200, + 'Content-Length': exchange.length, + 'Content-Type': 'text/plain') + res.write(exchange) + res.end() ) + -- cgit v1.2.3