aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2020-03-09 22:30:48 -0700
committerAdam Soltys <[email protected]>2020-03-09 22:30:48 -0700
commit629701a87138e2fedb69e260bc3951cb567b322c (patch)
tree769758de86cc9f99df8789e894f15ffc5a714c72
parent4e2d9a84e9561ce2a95b0f72e424b6bf38cdd74b (diff)
downloadcoinos-server-629701a87138e2fedb69e260bc3951cb567b322c.tar.gz
coinos-server-629701a87138e2fedb69e260bc3951cb567b322c.zip
log binance error
-rw-r--r--authy.js54
-rw-r--r--binance.js28
2 files changed, 17 insertions, 65 deletions
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;