From 44b420b2bbf6227d3c35658ce65049de014f0809 Mon Sep 17 00:00:00 2001 From: Adam Soltys Date: Sun, 6 Oct 2019 18:32:07 -0700 Subject: get fx rates from fixer api --- rates.js | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 rates.js (limited to 'rates.js') diff --git a/rates.js b/rates.js new file mode 100644 index 00000000..d4616780 --- /dev/null +++ b/rates.js @@ -0,0 +1,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); + })(); +}; -- cgit v1.2.3