@exchanges/binance
Version:
Exchange provider for Binance API
49 lines • 2.72 kB
JavaScript
;
var __rest = (this && this.__rest) || function (s, e) {
var t = {};
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
t[p] = s[p];
if (s != null && typeof Object.getOwnPropertySymbols === "function")
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
t[p[i]] = s[p[i]];
}
return t;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.partialBookDepthStreams = void 0;
const apiCall_1 = require("../../../apiCall");
const safe_parsing_1 = require("@berish/safe-parsing");
function partialBookDepthStreams(client, symbol, level, updateSpeed, callback) {
if (!symbol)
throw new TypeError('partialBookDepthStreams symbol is empty');
if (typeof symbol !== 'string')
throw new TypeError('partialBookDepthStreams symbol is not string');
if (!level)
throw new TypeError('partialBookDepthStreams level is empty');
if (level !== 5 && level !== 10 && level !== 20)
throw new TypeError('partialBookDepthStreams level is not 5, 10 or 20');
if (!updateSpeed)
throw new TypeError('partialBookDepthStreams updateSpeed is empty');
if (updateSpeed !== '100ms' && updateSpeed !== '1000ms')
throw new TypeError('partialBookDepthStreams updateSpeed is not 100ms or 1000ms');
const parseCallback = callback &&
((data, error) => {
if (error)
return callback(void 0, error);
const response = (0, safe_parsing_1.parse)(data, (_a) => {
var { bids, asks } = _a, other = __rest(_a, ["bids", "asks"]);
return (Object.assign({ bids: (0, safe_parsing_1.parseArray)(bids, ([price, quantity]) => ({
price: (0, safe_parsing_1.parse)(price, safe_parsing_1.numberParser),
quantity: (0, safe_parsing_1.parse)(quantity, safe_parsing_1.numberParser),
})), asks: (0, safe_parsing_1.parseArray)(asks, ([price, quantity]) => ({
price: (0, safe_parsing_1.parse)(price, safe_parsing_1.numberParser),
quantity: (0, safe_parsing_1.parse)(quantity, safe_parsing_1.numberParser),
})) }, other));
});
return callback(response);
});
return (0, apiCall_1.apiCall)({ host: 'spot', path: `${symbol.toLowerCase()}@depth${level}@${updateSpeed}`, securityType: 'SOCKET', client }, parseCallback);
}
exports.partialBookDepthStreams = partialBookDepthStreams;
//# sourceMappingURL=partialBookDepthStreams.js.map