aboutsummaryrefslogtreecommitdiffstats
path: root/binance.js
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2019-11-05 22:09:50 -0800
committerAdam Soltys <[email protected]>2019-11-05 22:09:50 -0800
commitae5e489e8a21293ae3f4d9a3e1940a62ddd01011 (patch)
tree6935013d4cb90f4830f236697905db2a6c123dc8 /binance.js
parentf59d942805d9809ee7036a45c9178bf32eff07eb (diff)
downloadcoinos-server-ae5e489e8a21293ae3f4d9a3e1940a62ddd01011.tar.gz
coinos-server-ae5e489e8a21293ae3f4d9a3e1940a62ddd01011.zip
cache fx rates and periodically re-establish websocket
Diffstat (limited to 'binance.js')
-rw-r--r--binance.js7
1 files changed, 4 insertions, 3 deletions
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;
};