From ae5e489e8a21293ae3f4d9a3e1940a62ddd01011 Mon Sep 17 00:00:00 2001 From: Adam Soltys Date: Tue, 5 Nov 2019 22:09:50 -0800 Subject: cache fx rates and periodically re-establish websocket --- binance.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'binance.js') diff --git a/binance.js b/binance.js index 007f7848..52d06ad9 100644 --- a/binance.js +++ b/binance.js @@ -1,5 +1,4 @@ const WebSocket = require("ws"); - module.exports = (app, socket) => { const binance = new WebSocket( "wss://stream.binance.com:9443/ws/btcusdt@ticker" @@ -11,7 +10,7 @@ module.exports = (app, socket) => { app.set("ask", msg.a); app.set("last", msg.l); - let fx = app.get("rates"); + let fx = app.get("fxrates"); if (!fx) return; let rates = {}; @@ -19,6 +18,8 @@ module.exports = (app, socket) => { rates[symbol] = msg.a * fx[symbol]; }); - socket.emit("rates", rates); + app.set("rates", rates); }; + + return binance; }; -- cgit v1.2.3