diff options
| author | Adam Soltys <[email protected]> | 2019-10-06 18:32:07 -0700 |
|---|---|---|
| committer | Adam Soltys <[email protected]> | 2019-10-06 18:32:07 -0700 |
| commit | 44b420b2bbf6227d3c35658ce65049de014f0809 (patch) | |
| tree | d9d886e5db17ca5c2d5830eb87e4187f0e5d285a /rates.js | |
| parent | b61477bfebe726b9200e10c1e789564a75b865b4 (diff) | |
| download | coinos-server-44b420b2bbf6227d3c35658ce65049de014f0809.tar.gz coinos-server-44b420b2bbf6227d3c35658ce65049de014f0809.zip | |
get fx rates from fixer api
Diffstat (limited to 'rates.js')
| -rw-r--r-- | rates.js | 27 |
1 files changed, 27 insertions, 0 deletions
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); + })(); +}; |
