forked from Sfippa/api-client-v1-node
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
28 lines (22 loc) · 817 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
'use strict';
var API = require('../api')
, UrlPattern = require('url-pattern');
var endpoints = {
ticker : new UrlPattern('/ticker(?api_code=:apiCode)'),
tobtc : new UrlPattern('/tobtc?value=:value¤cy=:currency(&api_code=:apiCode)')
};
var api = new API('https://blockchain.info', endpoints);
module.exports = {
getTicker : getTicker,
toBTC : toBTC
};
function getTicker(options) {
options = options || {};
return api.request('ticker', { apiCode: options.apiCode })
.then(function (data) { return data[options.currency] || data; });
}
function toBTC(amount, currency, options) {
options = options || {};
return api.request('tobtc', { value: amount, currency: currency, apiCode: options.apiCode })
.then(function (amount) { return amount.replace(',', ''); });
}