Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

binance-api-node

Package Overview
Dependencies
Maintainers
1
Versions
180
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

binance-api-node - npm Package Compare versions

Comparing version 0.8.21 to 0.9.0

85

dist/websocket.js

@@ -333,5 +333,3 @@ 'use strict';

var keepStreamAlive = exports.keepStreamAlive = function keepStreamAlive(method, listenKey) {
return method({ listenKey: listenKey }).catch(function (f) {
return f;
});
return method({ listenKey: listenKey });
};

@@ -346,24 +344,71 @@

return getDataStream().then(function (_ref2) {
var listenKey = _ref2.listenKey;
var currentListenKey = null;
var int = null;
var w = null;
var w = (0, _openWebsocket2.default)(BASE + '/' + listenKey);
w.onmessage = function (msg) {
return userEventHandler(cb)(msg);
};
var keepAlive = function keepAlive(isReconnecting) {
if (currentListenKey) {
keepStreamAlive(keepDataStream, currentListenKey).catch(function () {
closeStream({}, true);
var int = setInterval(function () {
keepStreamAlive(keepDataStream, listenKey);
}, 50e3);
if (isReconnecting) {
setTimeout(function () {
return makeStream(true);
}, 30e3);
} else {
makeStream(true);
}
});
}
};
keepStreamAlive(keepDataStream, listenKey);
var closeStream = function closeStream(options, catchErrors) {
if (currentListenKey) {
clearInterval(int);
return function (options) {
clearInterval(int);
closeDataStream({ listenKey: listenKey }).catch(function (f) {
return f;
});
var p = closeDataStream({ listenKey: currentListenKey });
if (catchErrors) {
p.catch(function (f) {
return f;
});
}
w.close(1000, 'Close handle was called', _extends({ keepClosed: true }, options));
};
});
currentListenKey = null;
}
};
var makeStream = function makeStream(isReconnecting) {
return getDataStream().then(function (_ref2) {
var listenKey = _ref2.listenKey;
w = (0, _openWebsocket2.default)(BASE + '/' + listenKey);
w.onmessage = function (msg) {
return userEventHandler(cb)(msg);
};
currentListenKey = listenKey;
int = setInterval(function () {
return keepAlive(false);
}, 50e3);
keepAlive(true);
return function (options) {
return closeStream(options);
};
}).catch(function (err) {
if (isReconnecting) {
setTimeout(function () {
return makeStream(true);
}, 30e3);
} else {
throw err;
}
});
};
return makeStream(false);
};

@@ -370,0 +415,0 @@ };

{
"name": "binance-api-node",
"version": "0.8.21",
"version": "0.9.0",
"description": "A node API wrapper for Binance",

@@ -5,0 +5,0 @@ "main": "dist",

@@ -260,23 +260,63 @@ import zip from 'lodash.zipobject'

export const keepStreamAlive = (method, listenKey) => method({ listenKey }).catch(f => f)
export const keepStreamAlive = (method, listenKey) => method({ listenKey })
const user = opts => cb => {
const { getDataStream, keepDataStream, closeDataStream } = httpMethods(opts)
let currentListenKey = null
let int = null
let w = null
return getDataStream().then(({ listenKey }) => {
const w = openWebSocket(`${BASE}/${listenKey}`)
w.onmessage = msg => userEventHandler(cb)(msg)
const keepAlive = isReconnecting => {
if (currentListenKey) {
keepStreamAlive(keepDataStream, currentListenKey).catch(() => {
closeStream({}, true)
const int = setInterval(() => {
keepStreamAlive(keepDataStream, listenKey)
}, 50e3)
if (isReconnecting) {
setTimeout(() => makeStream(true), 30e3)
} else {
makeStream(true)
}
})
}
}
keepStreamAlive(keepDataStream, listenKey)
const closeStream = (options, catchErrors) => {
if (currentListenKey) {
clearInterval(int)
return options => {
clearInterval(int)
closeDataStream({ listenKey }).catch(f => f)
const p = closeDataStream({ listenKey: currentListenKey })
if (catchErrors) {
p.catch(f => f)
}
w.close(1000, 'Close handle was called', { keepClosed: true, ...options })
currentListenKey = null
}
})
}
const makeStream = isReconnecting => {
return getDataStream()
.then(({ listenKey }) => {
w = openWebSocket(`${BASE}/${listenKey}`)
w.onmessage = msg => userEventHandler(cb)(msg)
currentListenKey = listenKey
int = setInterval(() => keepAlive(false), 50e3)
keepAlive(true)
return options => closeStream(options)
})
.catch(err => {
if (isReconnecting) {
setTimeout(() => makeStream(true), 30e3)
} else {
throw err
}
})
}
return makeStream(false)
}

@@ -283,0 +323,0 @@

@@ -93,3 +93,3 @@ import test from 'ava'

} catch (e) {
t.is(e.message, 'UNKNOWN_ORDER')
t.is(e.message, 'Unknown order sent.')
}

@@ -96,0 +96,0 @@ })

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc