diff options
| author | Adam Soltys <[email protected]> | 2014-06-14 23:07:26 -0700 |
|---|---|---|
| committer | Adam Soltys <[email protected]> | 2014-06-14 23:07:26 -0700 |
| commit | eeb39fc0d0f3c47faf6a4a721ce0c203a7832dc9 (patch) | |
| tree | 019a98ab99002e750328e8e2546ce4b2b8a0d421 /routes | |
| parent | 26a8814cb9a267e3d44fb9d09f02da4c70af8600 (diff) | |
| download | coinos-server-eeb39fc0d0f3c47faf6a4a721ce0c203a7832dc9.tar.gz coinos-server-eeb39fc0d0f3c47faf6a4a721ce0c203a7832dc9.zip | |
Get rates from bitcoinaverage.com
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() ) + |
