import { Filter } from '../types.ts' import { RealTimeFeedBase, type Sequence } from './realtimefeed.ts' export class DeltaRealTimeFeed extends RealTimeFeedBase { protected readonly wssURL = 'wss://socket.delta.exchange' protected getSequence(message: any): Sequence | undefined { if (message.type === 'l2_updates' && (message.action === 'snapshot' || message.action === 'update')) { return { key: message.symbol, sequence: message.sequence_no, previousSequence: message.sequence_no - 1 } } return undefined } protected mapToSubscribeMessages(filters: Filter[]) { return filters.map((filter) => { if (filter.channel !== 'product_updates' && filter.channel !== 'announcements' && !filter.symbols?.length) { throw new Error('DeltaRealTimeFeed requires explicitly specified symbols when subscribing to live feed') } return { type: 'subscribe', payload: { channels: [ { name: filter.channel, symbols: filter.symbols !== undefined && filter.channel === 'mark_price' ? filter.symbols.map((s) => `MARK:${s}`) : filter.symbols } ] } } }) } protected messageIsError(message: any): boolean { return message.error !== undefined && message.error !== null } protected sendCustomPing = () => { this.send({ type: 'ping' }) } protected messageIsHeartbeat(msg: any) { return msg.type === 'pong' } }