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 --- binance.js | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'binance.js') diff --git a/binance.js b/binance.js index 8edcc5da..007f7848 100644 --- a/binance.js +++ b/binance.js @@ -1,6 +1,6 @@ const WebSocket = require("ws"); -module.exports = app => { +module.exports = (app, socket) => { const binance = new WebSocket( "wss://stream.binance.com:9443/ws/btcusdt@ticker" ); @@ -10,5 +10,15 @@ module.exports = app => { app.set("bid", msg.b); app.set("ask", msg.a); app.set("last", msg.l); + + let fx = app.get("rates"); + if (!fx) return; + let rates = {}; + + Object.keys(fx).map(symbol => { + rates[symbol] = msg.a * fx[symbol]; + }); + + socket.emit("rates", rates); }; }; -- cgit v1.2.3