tardis-dev
Version:
Convenient access to tick-level historical and real-time cryptocurrency market data via Node.js
56 lines • 2.01 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.BitnomialRealTimeFeed = void 0;
const realtimefeed_1 = require("./realtimefeed");
class BitnomialRealTimeFeed extends realtimefeed_1.RealTimeFeedBase {
wssURL = 'wss://bitnomial.com/exchange/ws';
channelMappings = {
book: ['book', 'level']
};
mapToSubscribeMessages(filters) {
const channelsToSubscribe = filters
.map((filter) => {
if (!filter.symbols || filter.symbols.length === 0) {
throw new Error('BitnomialRealTimeFeed requires explicitly specified symbols when subscribing to live feed');
}
const subscribeToBookChannel = this.channelMappings.book.includes(filter.channel);
let channel;
if (subscribeToBookChannel) {
channel = 'book';
}
else {
channel = filter.channel;
}
return {
name: channel,
product_codes: filter.symbols
};
})
.reduce((prev, current) => {
const matchingExisting = prev.find((c) => c.name === current.name);
if (matchingExisting !== undefined) {
for (const symbol of current.product_codes) {
if (matchingExisting.product_codes.includes(symbol) === false) {
matchingExisting.product_codes.push(symbol);
}
}
}
else {
prev.push(current);
}
return prev;
}, []);
return [
{
type: 'subscribe',
product_codes: [],
channels: channelsToSubscribe
}
];
}
messageIsError(message) {
return message.type === 'error' || message.type === 'disconnect';
}
}
exports.BitnomialRealTimeFeed = BitnomialRealTimeFeed;
//# sourceMappingURL=bitnomial.js.map