aboutsummaryrefslogtreecommitdiffstats
path: root/lib/rates.js
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2020-08-05 14:11:39 -0700
committerAdam Soltys <[email protected]>2020-08-05 14:11:39 -0700
commit3745752b5c38ad87a00f38d862c127cf7281ac89 (patch)
tree5325eb42b55f6715ab05e24664f58075977e84f7 /lib/rates.js
parent14f944f953dd59106821c9244a89c4eb4a956758 (diff)
downloadcoinos-server-3745752b5c38ad87a00f38d862c127cf7281ac89.tar.gz
coinos-server-3745752b5c38ad87a00f38d862c127cf7281ac89.zip
use exchangerate.host instead of fixer.io
Diffstat (limited to 'lib/rates.js')
-rw-r--r--lib/rates.js25
1 files changed, 13 insertions, 12 deletions
diff --git a/lib/rates.js b/lib/rates.js
index 33982ba3..30ab0dce 100644
--- a/lib/rates.js
+++ b/lib/rates.js
@@ -1,25 +1,26 @@
const axios = require("axios");
+const fs = require("fs");
let binance = require("./binance")();
let fetchRates;
(fetchRates = async () => {
- let fx = require("./devrates");
+ let date, fx;
- if (prod) {
- try {
- let res = await axios.get(
- `http://data.fixer.io/api/latest?access_key=${config.fixer}`
- );
+ try {
+ ({ date, fx } = JSON.parse(fs.readFileSync("fx")));
+ } catch {
+ l.warn("Failed to read fx file");
+ }
- fx = res.data.rates;
+ let today = JSON.stringify(new Date()).replace(/T.*/, "").replace(/"/, "");
- fx &&
- Object.keys(fx).map(symbol => {
- rates[symbol] = fx[symbol] / fx["USD"];
- });
+ if (date !== today) {
+ try {
+ let { data: { rates: fx }} = await axios.get('https://api.exchangerate.host/latest');
+ fs.writeFileSync("fx", JSON.stringify({ date, fx }));
} catch (e) {
- l.error("error fetching rates", e);
+ l.error("error fetching rates", e.message);
}
}