import { type Subscription } from '@lifi/perps-types'; import type { GetQuoteParams } from '../services/getQuote.js'; import type { PerpsSDKClient, QuoteListener } from '../types/provider.js'; import type { EventForSubscription, WsProvider, WsStatusListener } from './types.js'; /** * Factory for a per-provider WS plugin. Invoked once per provider key the * first time `subscribe(...)` is called against it. * * @public */ export type WsProviderFactory = (params: { /** Provider key (e.g. `'lighter'`, `'hyperliquid'`). */ provider: string; /** WS URL discovered from `/providers`. */ wsUrl: string; /** * Markets visible to this provider via `/providers`, optionally filtered * by the consumer's `createPerpsClient({ providers: { [key]: { markets } } })` * config. Each provider interprets these its own way — Hyperliquid uses * them to decide which sub-DEXes to subscribe to; Lighter ignores them. */ markets: string[]; /** * The SDK client. WS providers use it to call core services (e.g. * `getAssets` to source the wire-id ↔ display-symbol map) without * duplicating backend orchestration in the WS layer. */ client: PerpsSDKClient; }) => WsProvider; /** * Options for {@link PerpsWsClient}. * * @public */ export interface PerpsWsClientOptions { /** * Per-provider WS factory map. Each key (e.g. `'hyperliquid'`, * `'lighter'`) maps to a factory that returns a `WsProvider`. Concrete * implementations ship with the provider packages — e.g. * `@lifi/perps-sdk-provider-hyperliquid` exports `HyperliquidWsProvider`, * `@lifi/perps-sdk-provider-lighter` exports `LighterWsProvider`. * Subscribing to a provider key without a registered factory throws. */ wsProviders?: Record; } /** * Realtime client: lazily instantiates a per-provider {@link WsProvider} on * first subscription and fans subscriptions out to it. * * @public */ export declare class PerpsWsClient { private readonly client; private readonly options; private providers; private initPromises; constructor(client: PerpsSDKClient, options?: PerpsWsClientOptions); /** * Subscribe to a realtime channel, lazily creating the provider's WS * connection. Returns an unsubscribe function. * * @param onStatus - Optional listener for the underlying connection's * health. Fires `reconnecting` on a transient drop and the terminal * `disconnected` once auto-reconnect is abandoned, so consumers can * surface a reconnecting/disconnected state instead of silently showing * stale data. * @throws {PerpsError} When no WS provider factory is registered for the * subscription's `dex`. * @public */ subscribe(sub: S, listener: (event: EventForSubscription) => void, onStatus?: WsStatusListener): Promise<() => void>; /** * Stream live fill quotes for `params.symbol` on `params.provider`, lazily * creating the provider's WS connection. The provider's WS plugin layers the * quote on its orderbook channel, so a concurrent orderbook subscription on * the same market shares one wire subscription. Returns an unsubscribe * function. * * @throws {PerpsError} When no WS provider factory is registered for * `params.provider`, or no market matches the symbol+type. * @public */ subscribeQuote(params: GetQuoteParams, onQuote: QuoteListener): Promise<() => void>; /** * Close every open provider WS connection and drop all cached providers. * * @public */ close(): void; /** * Reconnect an already-created provider when its socket reached terminal * `disconnected`. Safe no-op when the provider is unknown or not terminal. * * @public */ reconnect(provider: string): void; private getOrCreateProvider; private initProvider; } //# sourceMappingURL=PerpsWsClient.d.ts.map