From 629701a87138e2fedb69e260bc3951cb567b322c Mon Sep 17 00:00:00 2001 From: Adam Soltys Date: Mon, 9 Mar 2020 22:30:48 -0700 Subject: log binance error --- authy.js | 54 ------------------------------------------------------ binance.js | 28 +++++++++++++++++----------- 2 files changed, 17 insertions(+), 65 deletions(-) delete mode 100644 authy.js diff --git a/authy.js b/authy.js deleted file mode 100644 index bfca8672..00000000 --- a/authy.js +++ /dev/null @@ -1,54 +0,0 @@ -const { Client } = require("authy-client"); -const config = require("./config"); - -const authy = new Client({ key: config.authy.key }); - -module.exports = async user => { - let { authyId } = user; - - const res = await authy.createApprovalRequest( - { - authyId: user.authyId, - details: { - visible: { - User: user.name - } - }, - logos: [ - { - res: "default", - url: "https://coinos.io/static/img/coinos.png" - } - ], - message: "Login to CoinOS" - }, - { - ttl: 120 - } - ); - - let counter = 0; - - return new Promise((resolve, reject) => { - let poll = setInterval(async () => { - counter++; - const r = await authy.getApprovalRequest({ - id: res.approval_request.uuid - }); - if (r.approval_request.status === "approved") { - clearInterval(poll); - resolve(true); - } - - if (r.approval_request.status === "denied") { - clearInterval(poll); - resolve(false); - } - - if (counter > 60) { - clearInterval(poll); - reject(false); - } - }, 1000); - }); -}; diff --git a/binance.js b/binance.js index 52d06ad9..ccb010e1 100644 --- a/binance.js +++ b/binance.js @@ -1,24 +1,30 @@ const WebSocket = require("ws"); +const l = require("pino")(); + module.exports = (app, socket) => { const binance = new WebSocket( "wss://stream.binance.com:9443/ws/btcusdt@ticker" ); binance.onmessage = async function(event) { - let msg = JSON.parse(event.data); - app.set("bid", msg.b); - app.set("ask", msg.a); - app.set("last", msg.l); + try { + let msg = JSON.parse(event.data); + app.set("bid", msg.b); + app.set("ask", msg.a); + app.set("last", msg.l); - let fx = app.get("fxrates"); - if (!fx) return; - let rates = {}; + let fx = app.get("fxrates"); + if (!fx) return; + let rates = {}; - Object.keys(fx).map(symbol => { - rates[symbol] = msg.a * fx[symbol]; - }); + Object.keys(fx).map(symbol => { + rates[symbol] = msg.a * fx[symbol]; + }); - app.set("rates", rates); + app.set("rates", rates); + } catch(e) { + l.error("binance socket error", e); + } }; return binance; -- cgit v1.2.3