binance-api-node
Advanced tools
Comparing version 0.11.14 to 0.11.15
@@ -367,3 +367,3 @@ "use strict"; | ||
var transform = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true; | ||
var cache = (Array.isArray(payload) ? payload : [payload]).map(function (symbol) { | ||
var cache = (Array.isArray(payload) ? payload : [payload]).map(function () { | ||
var w = (0, _openWebsocket.default)("".concat(endpoints.base, "/!miniTicker@arr")); | ||
@@ -747,2 +747,12 @@ | ||
exports.userEventHandler = userEventHandler; | ||
var userErrorHandler = function userErrorHandler(cb) { | ||
var transform = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true; | ||
return function (error) { | ||
var _cb; | ||
cb((_cb = {}, _defineProperty(_cb, transform ? 'eventType' : 'type', 'error'), _defineProperty(_cb, "error", error), _cb)); | ||
}; | ||
}; | ||
var STREAM_METHODS = ['get', 'keep', 'close']; | ||
@@ -781,6 +791,8 @@ | ||
var w = null; | ||
var keepClosed = false; | ||
var errorHandler = userErrorHandler(cb, transform); | ||
var keepAlive = function keepAlive(isReconnecting) { | ||
if (currentListenKey) { | ||
keepStreamAlive(keepDataStream, currentListenKey).catch(function () { | ||
keepStreamAlive(keepDataStream, currentListenKey).catch(function (err) { | ||
closeStream({}, true); | ||
@@ -795,2 +807,6 @@ | ||
} | ||
if (opts.emitStreamErrors) { | ||
errorHandler(err); | ||
} | ||
}); | ||
@@ -800,3 +816,7 @@ } | ||
var closeStream = function closeStream(options, catchErrors) { | ||
var closeStream = function closeStream(options) { | ||
var catchErrors = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false; | ||
var setKeepClosed = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false; | ||
keepClosed = setKeepClosed; | ||
if (currentListenKey) { | ||
@@ -822,4 +842,13 @@ clearInterval(int); | ||
var makeStream = function makeStream(isReconnecting) { | ||
return getDataStream().then(function (_ref3) { | ||
return !keepClosed && getDataStream().then(function (_ref3) { | ||
var listenKey = _ref3.listenKey; | ||
if (keepClosed) { | ||
return closeDataStream({ | ||
listenKey: listenKey | ||
}).catch(function (f) { | ||
return f; | ||
}); | ||
} | ||
w = (0, _openWebsocket.default)("".concat(variator === 'futures' ? endpoints.futures : endpoints.base, "/").concat(listenKey)); | ||
@@ -831,2 +860,9 @@ | ||
if (opts.emitSocketErrors) { | ||
w.onerror = function (_ref4) { | ||
var error = _ref4.error; | ||
return errorHandler(error); | ||
}; | ||
} | ||
currentListenKey = listenKey; | ||
@@ -838,9 +874,15 @@ int = setInterval(function () { | ||
return function (options) { | ||
return closeStream(options); | ||
return closeStream(options, false, true); | ||
}; | ||
}).catch(function (err) { | ||
if (isReconnecting) { | ||
setTimeout(function () { | ||
return makeStream(true); | ||
}, 30e3); | ||
if (!keepClosed) { | ||
setTimeout(function () { | ||
return makeStream(true); | ||
}, 30e3); | ||
} | ||
if (opts.emitStreamErrors) { | ||
errorHandler(err); | ||
} | ||
} else { | ||
@@ -847,0 +889,0 @@ throw err; |
{ | ||
"name": "binance-api-node", | ||
"version": "0.11.14", | ||
"version": "0.11.15", | ||
"description": "A node API wrapper for Binance", | ||
@@ -5,0 +5,0 @@ "main": "dist", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
209250
3219