diff options
Diffstat (limited to 'lib/binance.js')
| -rw-r--r-- | lib/binance.js | 21 |
1 files changed, 13 insertions, 8 deletions
diff --git a/lib/binance.js b/lib/binance.js index 0f91ce8c..3e25e277 100644 --- a/lib/binance.js +++ b/lib/binance.js @@ -1,9 +1,14 @@ -import WebSocket from 'ws'; +import app from "../app.js"; +import WebSocket from "ws"; +import { err } from "./logging.js"; +import { rates } from "./store.js"; export default () => { - const binance = new WebSocket("wss://stream.binance.com:9443/ws/btcusdt@ticker"); + const binance = new WebSocket( + "wss://stream.binance.com:9443/ws/btcusdt@ticker" + ); - binance.onmessage = async function (event) { + binance.onmessage = async function(event) { try { let msg = JSON.parse(event.data); @@ -11,7 +16,7 @@ export default () => { if (!fx) return; let rates = {}; - Object.keys(fx).map((symbol) => { + Object.keys(fx).map(symbol => { rates[symbol] = msg.c * fx[symbol]; }); @@ -20,13 +25,13 @@ export default () => { app.set("last", msg.c); app.set("rates", rates); } catch (e) { - l.error("binance message error", e.message); + err("binance message error", e.message); } }; - binance.onerror = async function (error) { - console.log("binance socket error", error); - } + binance.onerror = async function(error) { + err("binance socket error", error); + }; return binance; }; |
