-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
88 lines (79 loc) · 2.05 KB
/
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
(function() {
const axios = require('axios');
var apiKey;
function removeEmpty(obj) {
for (var propName in obj) {
if (obj[propName] === null || obj[propName] === undefined || obj[propName] == '') {
delete obj[propName];
}
}
return obj;
}
exports.setAPIKey = function(apiKey) {
this.apiKey = apiKey;
};
exports.fetchSymbols = function() {
return axios({
url: 'https://api.forexrateapi.com/v1/symbols',
params: {
api_key: this.apiKey,
},
});
};
exports.fetchLive = function(base, currencies) {
return axios({
url: 'https://api.forexrateapi.com/v1/latest',
params: removeEmpty({
api_key: this.apiKey,
base: base,
currencies: (currencies || []).join(','),
}),
});
};
exports.fetchHistorical = function(date, base, currencies) {
return axios({
url: `https://api.forexrateapi.com/v1/${date}`,
params: removeEmpty({
api_key: this.apiKey,
base: base,
currencies: (currencies || []).join(','),
}),
});
};
exports.convert = function(from, to, amount, date) {
return axios({
url: 'https://api.forexrateapi.com/v1/convert',
params: removeEmpty({
api_key: this.apiKey,
from: from,
to: to,
amount: amount,
date: date,
}),
});
};
exports.timeframe = function(startDate, endDate, base, currencies) {
return axios({
url: 'https://api.forexrateapi.com/v1/timeframe',
params: removeEmpty({
api_key: this.apiKey,
start_date: startDate,
end_date: endDate,
base: base,
currencies: (currencies || []).join(','),
}),
});
};
exports.change = function(startDate, endDate, base, currencies) {
return axios({
url: 'https://api.forexrateapi.com/v1/change',
params: removeEmpty({
api_key: this.apiKey,
start_date: startDate,
end_date: endDate,
base: base,
currencies: (currencies || []).join(','),
}),
});
}
})();