/** * OHLCV Service for real-time candlestick data streaming via WebSocket. * * Wraps {@link BackendWebSocketService} through the messenger pattern to * provide subscribe/unsubscribe semantics for OHLCV market-data channels. * Includes reference counting, grace-period unsubscribe, idempotency checks, * chain-status forwarding, and automatic resubscription on reconnect. */ import type { TraceCallback } from "@metamask/controller-utils"; import type { Messenger } from "@metamask/messenger"; import type { BackendWebSocketServiceConnectionStateChangedEvent } from "../BackendWebSocketService.cjs"; import type { BackendWebSocketServiceMethodActions } from "../BackendWebSocketService-method-action-types.cjs"; import type { OHLCVServiceMethodActions } from "./OHLCVService-method-action-types.cjs"; import type { OHLCVBar, OHLCVSubscriptionOptions } from "./types.cjs"; declare const SERVICE_NAME = "OHLCVService"; /** * System notification data for chain status updates on market-data channels. */ export type OHLCVSystemNotificationData = { chainIds: string[]; status: 'down' | 'up'; timestamp?: number; }; /** * Configuration options for the OHLCV service. */ export type OHLCVServiceOptions = { /** Optional callback to trace performance of OHLCV operations (default: no-op) */ traceFn?: TraceCallback; }; export type OHLCVServiceActions = OHLCVServiceMethodActions; export declare const OHLCV_SERVICE_ALLOWED_ACTIONS: readonly ["BackendWebSocketService:connect", "BackendWebSocketService:forceReconnection", "BackendWebSocketService:subscribe", "BackendWebSocketService:getConnectionInfo", "BackendWebSocketService:channelHasSubscription", "BackendWebSocketService:getSubscriptionsByChannel", "BackendWebSocketService:findSubscriptionsByChannelPrefix", "BackendWebSocketService:addChannelCallback", "BackendWebSocketService:removeChannelCallback"]; export declare const OHLCV_SERVICE_ALLOWED_EVENTS: readonly ["BackendWebSocketService:connectionStateChanged"]; export type AllowedActions = BackendWebSocketServiceMethodActions; export type OHLCVServiceBarUpdatedEvent = { type: `OHLCVService:barUpdated`; payload: [{ channel: string; bar: OHLCVBar; }]; }; export type OHLCVServiceChainStatusChangedEvent = { type: `OHLCVService:chainStatusChanged`; payload: [{ chainIds: string[]; status: 'up' | 'down'; timestamp?: number; }]; }; export type OHLCVServiceSubscriptionErrorEvent = { type: `OHLCVService:subscriptionError`; payload: [{ channel: string; error: string; operation: string; }]; }; export type OHLCVServiceEvents = OHLCVServiceBarUpdatedEvent | OHLCVServiceChainStatusChangedEvent | OHLCVServiceSubscriptionErrorEvent; export type AllowedEvents = BackendWebSocketServiceConnectionStateChangedEvent; export type OHLCVServiceMessenger = Messenger; /** * Service for real-time OHLCV candlestick streaming via the backend WebSocket * gateway. Communicates with {@link BackendWebSocketService} exclusively * through the messenger — no direct import of the class. * * Features: * - Reference counting: multiple UI consumers share one WebSocket subscription * - Grace-period unsubscribe: avoids rapid unsub/resub during navigation * - Idempotency: duplicate subscribe calls for the same channel are no-ops * - Reconnect resilience: resubscribes all active channels on reconnect * - Chain-status forwarding: listens to system-notifications for chain up/down * */ export declare class OHLCVService { #private; readonly name = "OHLCVService"; constructor(options: OHLCVServiceOptions & { messenger: OHLCVServiceMessenger; }); /** * Register the system-notifications channel callback. */ init(): void; /** * Subscribe to an OHLCV channel. If this is the first subscriber for the * given asset/interval/currency combination a WebSocket subscription is * created. Additional calls for the same combination only bump the reference * count. * * @param options - The subscription parameters. * @returns A promise that resolves once the subscription is established. */ subscribe(options: OHLCVSubscriptionOptions): Promise; /** * Unsubscribe from an OHLCV channel. Decrements the reference count and, * when it reaches zero, starts a grace-period timer before actually * unsubscribing from the WebSocket to absorb rapid navigation patterns. * * @param options - The subscription parameters to unsubscribe from. * @returns A promise that resolves once the unsubscription is processed. */ unsubscribe(options: OHLCVSubscriptionOptions): Promise; /** * Destroy the service and clean up all resources. */ destroy(): void; } export {}; //# sourceMappingURL=OHLCVService.d.cts.map