aboutsummaryrefslogtreecommitdiffstats
path: root/rates.js
blob: d4616780ccca527a2535eb3613b25773e99e18df (plain) (blame)
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
const axios = require("axios");
const config = require("./config");
const l = console.log;

module.exports = app => {
  let fetchRates;
  (fetchRates = async () => {
    try {
      let rates = {};
      let res = await axios.get(
        `http://data.fixer.io/api/latest?access_key=${config.fixer}`
      );

      let fx = res.data.rates;

      Object.keys(fx).map(symbol => {
        rates[symbol] = fx[symbol] / fx["USD"];
      });

      app.set("rates", rates);
    } catch (e) {
      l(e);
    }

    setTimeout(fetchRates, 180000);
  })();
};