UNPKG

tardis-dev

Version:

Convenient access to tick-level historical and real-time cryptocurrency market data via Node.js

54 lines 2.4 kB
"use strict"; 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) { const expirations = matchingTickerChannel .symbols.filter((s) => s.startsWith(symbol)) .map((s) => { const symbolParts = s.split('-'); return `${symbolParts[1]}`; }) .filter(handy_1.onlyUnique); return expirations.map((expiration) => { return `${symbol}@${filter.channel}@${expiration}`; }); } } return [`${symbol}@${filter.channel}`]; }) .flatMap((s) => s), 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