UNPKG

tardis-dev

Version:

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

55 lines 2.07 kB
import { RealTimeFeedBase } from "./realtimefeed.js"; export class HitBtcRealTimeFeed extends RealTimeFeedBase { wssURL = 'wss://api.hitbtc.com/api/2/ws'; channelMappings = { subscribeOrderbook: ['snapshotOrderbook', 'updateOrderbook'], subscribeTrades: ['updateTrades', 'snapshotTrades'] }; mapToSubscribeMessages(filters) { const subscriptions = filters .map((filter) => { if (!filter.symbols || filter.symbols.length === 0) { throw new Error('HitBtcRealTimeFeed requires explicitly specified symbols when subscribing to live feed'); } const subscribeToOrderBook = this.channelMappings.subscribeOrderbook.includes(filter.channel); const subscribeToTrades = this.channelMappings.subscribeTrades.includes(filter.channel); let method; if (subscribeToOrderBook) { method = 'subscribeOrderbook'; } else if (subscribeToTrades) { method = 'subscribeTrades'; } else { throw new Error(`Invalid channel: ${filter.channel}`); } return filter.symbols.map((symbol) => { return { method, symbol }; }); }) .flatMap((s) => s) .reduce((prev, current) => { const matchingExisting = prev.find((c) => c.method === current.method && c.symbol === current.symbol); if (matchingExisting === undefined) { prev.push(current); } return prev; }, []); return subscriptions.map((subscription, index) => { return { method: subscription.method, params: { symbol: subscription.symbol }, id: index + 1 }; }); } messageIsError(message) { return message.error !== undefined; } } //# sourceMappingURL=hitbtc.js.map