diff options
Diffstat (limited to 'routes')
| -rw-r--r-- | routes/calculator.coffee | 28 |
1 files changed, 15 insertions, 13 deletions
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() ) + |
