UNPKG

tardis-dev

Version:

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

43 lines 1.5 kB
import { RealTimeFeedBase } from "./realtimefeed.js"; export class CryptoComRealTimeFeed extends RealTimeFeedBase { wssURL = 'wss://stream.crypto.com/exchange/v1/market'; mapToSubscribeMessages(filters) { const channels = filters .map((filter) => { if (!filter.symbols || filter.symbols.length === 0) { throw new Error('CryptoComRealTimeFeed requires explicitly specified symbols when subscribing to live feed'); } return filter.symbols.map((symbol) => { const suffix = filter.channel === 'book' ? '.50' : ''; return `${filter.channel}.${symbol}${suffix}`; }); }) .flatMap((s) => s); return [ { id: 1, method: 'subscribe', nonce: new Date().valueOf(), params: { channels: channels, book_subscription_type: 'SNAPSHOT_AND_UPDATE' } } ]; } messageIsError(message) { return message.code !== undefined && message.code !== 0 && message.code !== 40003; } onMessage(msg) { if (msg.method === 'public/heartbeat') { this.send({ id: msg.id, method: 'public/respond-heartbeat' }); } } messageIsHeartbeat(msg) { return msg.method === 'public/heartbeat'; } } //# sourceMappingURL=cryptocom.js.map