diff options
| author | Adam Soltys <[email protected]> | 2022-09-02 15:06:43 -0700 |
|---|---|---|
| committer | Adam Soltys <[email protected]> | 2022-09-02 15:06:43 -0700 |
| commit | d1cc66d1a02b75f90fbf0c05910777c76228259a (patch) | |
| tree | 7b93dc6a2fc0ec9d03676d6b4093fedf9733f128 /lib/binance.js | |
| parent | 3161dd7ee95b6c7d70f8341298dd4fab84cda8b0 (diff) | |
| download | coinos-server-d1cc66d1a02b75f90fbf0c05910777c76228259a.tar.gz coinos-server-d1cc66d1a02b75f90fbf0c05910777c76228259a.zip | |
es6 migration
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; }; |
