tardis-dev
Version:
Convenient access to tick-level historical and real-time cryptocurrency market data via Node.js
52 lines • 1.83 kB
JavaScript
import { RealTimeFeedBase } from "./realtimefeed.js";
export class BitnomialRealTimeFeed extends 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';
}
}
//# sourceMappingURL=bitnomial.js.map