import { Filter } from '../types.ts' import { RealTimeFeedBase, type Sequence } from './realtimefeed.ts' export class CryptofacilitiesRealTimeFeed extends RealTimeFeedBase { protected wssURL = 'wss://futures.kraken.com/ws/v1' protected getSequence(message: any): Sequence | undefined { if (message.feed === 'book' && message.event === undefined) { return { key: message.product_id, sequence: message.seq, previousSequence: message.seq - 1 } } return undefined } protected mapToSubscribeMessages(filters: Filter[]): any[] { return filters .filter((filter) => filter.channel.endsWith('_snapshot') === false) .map((filter) => { if (!filter.symbols || filter.symbols.length === 0) { throw new Error('CryptofacilitiesRealTimeFeed requires explicitly specified symbols when subscribing to live feed') } return { event: 'subscribe', product_ids: filter.symbols, feed: filter.channel } }) } protected messageIsError(message: any): boolean { return message.event === 'error' } protected messageIsHeartbeat(message: any): boolean { return message.feed === 'heartbeat' } }