tardis-dev
Version:
Convenient access to tick-level historical and real-time cryptocurrency market data via Node.js
49 lines • 2.21 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.BinanceEuropeanOptionsRealTimeFeed = void 0;
const handy_1 = require("../handy");
const realtimefeed_1 = require("./realtimefeed");
class BinanceEuropeanOptionsRealTimeFeed extends realtimefeed_1.RealTimeFeedBase {
constructor() {
super(...arguments);
this.wssURL = 'wss://nbstream.binance.com/eoptions/stream';
}
mapToSubscribeMessages(filters) {
const payload = filters.map((filter, index) => {
if (!filter.symbols || filter.symbols.length === 0) {
throw new Error('BinanceEuropeanOptionsRealTimeFeed requires explicitly specified symbols when subscribing to live feed');
}
return {
method: 'SUBSCRIBE',
params: filter.symbols.map((symbol) => {
if (filter.channel === 'depth100') {
return `${symbol}@${filter.channel}@100ms`;
}
if (filter.channel === 'openInterest') {
const matchingTickerChannel = filters.find((f) => f.channel === 'ticker');
if (matchingTickerChannel !== undefined && matchingTickerChannel.symbols !== undefined) {
const expirations = matchingTickerChannel.symbols
.map((s) => {
const symbolParts = s.split('-');
return `${symbolParts[1]}`;
})
.filter(handy_1.onlyUnique);
return `${symbol}@${filter.channel}@${expirations}`;
}
}
return `${symbol}@${filter.channel}`;
}),
id: index + 1
};
});
return payload;
}
messageIsError(message) {
if (message.data !== undefined && message.data.e === 'error') {
return true;
}
return false;
}
}
exports.BinanceEuropeanOptionsRealTimeFeed = BinanceEuropeanOptionsRealTimeFeed;
//# sourceMappingURL=binanceeuropeanoptions.js.map