diff options
| author | Adam Soltys <[email protected]> | 2020-03-11 15:10:40 -0700 |
|---|---|---|
| committer | Adam Soltys <[email protected]> | 2020-03-11 15:10:40 -0700 |
| commit | c0888fab024cc9f7c99812bfabf9d7774312dbf7 (patch) | |
| tree | cad95683af97432f6092a2c2bae10fbb7a588db5 /lib/rates.js | |
| parent | bf2b51f0c2ae9b8f0f330dde6411e45fc0da8a25 (diff) | |
| download | coinos-server-c0888fab024cc9f7c99812bfabf9d7774312dbf7.tar.gz coinos-server-c0888fab024cc9f7c99812bfabf9d7774312dbf7.zip | |
refactor
Diffstat (limited to 'lib/rates.js')
| -rw-r--r-- | lib/rates.js | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/lib/rates.js b/lib/rates.js new file mode 100644 index 00000000..702e586e --- /dev/null +++ b/lib/rates.js @@ -0,0 +1,38 @@ +const axios = require("axios"); + +let binance = require("./binance")(); + +let fetchRates; +(fetchRates = async () => { + let rates = require("./devrates"); + + if (process.env.NODE_ENV === "production") { + try { + let res = await axios.get( + `http://data.fixer.io/api/latest?access_key=${config.fixer}` + ); + + let fx = res.data.rates; + + fx && + Object.keys(fx).map(symbol => { + rates[symbol] = fx[symbol] / fx["USD"]; + }); + } catch (e) { + l.error("error fetching rates", e); + } + } + + app.set("fxrates", rates); + + setTimeout(fetchRates, 7200000); +})(); + +setInterval(() => { + socket.emit("rates", app.get("rates")); +}, 1000); + +setInterval(() => { + binance.terminate(); + binance = require("./binance")(); +}, 360000); |
