import { Chart, DeepPartial, IndicatorTemplate, KLineData, Nullable, OverlayTemplate, Styles } from 'klinecharts'; export interface SymbolInfo { ticker: string; name?: string; shortName?: string; exchange?: string; market?: string; pricePrecision?: number; volumePrecision?: number; priceCurrency?: string; type?: string; logo?: string; } export interface Period { multiplier: number; timespan: string; text: string; } export type DatafeedSubscribeCallback = (data: KLineData) => void; export interface Datafeed { searchSymbols(search?: string): Promise; getHistoryKLineData(symbol: SymbolInfo, period: Period, from: number, to: number): Promise; subscribe(symbol: SymbolInfo, period: Period, callback: DatafeedSubscribeCallback): void; unsubscribe(symbol: SymbolInfo, period: Period): void; } export interface PersistenceOptions { enabled: boolean; prefix?: string; } export type AlertCondition = "crosses_above" | "crosses_below" | "reaches"; export interface AlertConfig { id: string; symbol: string; condition: AlertCondition; price: number; message?: string; triggered?: boolean; callback?: () => void; } export interface CustomIndicatorConfig { name: string; category: "main" | "sub"; shortName?: string; calcParams?: any[]; figures?: any[]; calc?: (kLineDataList: KLineData[], params: any) => any[]; } export interface ChartProOptions { container: string | HTMLElement; styles?: DeepPartial; watermark?: string | Node; theme?: string; locale?: string; drawingBarVisible?: boolean; symbol: SymbolInfo; period: Period; periods?: Period[]; timezone?: string; mainIndicators?: string[]; subIndicators?: string[]; datafeed: Datafeed; persistence?: PersistenceOptions; chartType?: string; renkoBrickSize?: number; rangeBarSize?: number; onError?: (error: Error) => void; onSettingsChange?: (settings: any) => void; onDrawingsChange?: (ticker: string, drawings: any[]) => void; onLayoutClick?: () => void; } export interface ChartPro { setTheme(theme: string): void; getTheme(): string; setStyles(styles: DeepPartial): void; getStyles(): Styles; setLocale(locale: string): void; getLocale(): string; setTimezone(timezone: string): void; getTimezone(): string; setSymbol(symbol: SymbolInfo): void; getSymbol(): SymbolInfo; setPeriod(period: Period): void; getPeriod(): Period; ready?(): Promise; destroy?(): void; setAlert?(alert: AlertConfig): void; removeAlert?(id: string): void; getAlerts?(): AlertConfig[]; addComparisonSymbol?(symbol: SymbolInfo): void; removeComparisonSymbol?(ticker: string): void; registerCustomIndicator?(config: CustomIndicatorConfig): void; setChartType?(type: string): void; getChartType?(): string; startReplay?(dataSource: "current" | "custom"): void; stopReplay?(): void; showObjectTree?(): void; showStyleEditor?(overlayId: string): void; getSettings?(): any; setSettings?(settings: any): void; getDrawings?(ticker: string): any[]; setDrawings?(ticker: string, drawings: any[]): void; getWidget?(): any; } export type ConnectionStatus = "disconnected" | "connecting" | "connected" | "reconnecting"; export type ConnectionStatusCallback = (status: ConnectionStatus) => void; export declare class DefaultDatafeed implements Datafeed { constructor(apiKey: string); private _apiKey; private _prevSymbolMarket?; private _prevSymbolTicker?; private _ws?; private _callback?; private _connectionStatusCallback?; private _reconnectAttempts; private _maxReconnectAttempts; private _reconnectTimer?; private _currentSymbol?; private _connectionStatus; onConnectionStatusChange(callback: ConnectionStatusCallback): void; getConnectionStatus(): ConnectionStatus; private _setConnectionStatus; searchSymbols(search?: string): Promise; getHistoryKLineData(symbol: SymbolInfo, period: Period, from: number, to: number): Promise; subscribe(symbol: SymbolInfo, period: Period, callback: DatafeedSubscribeCallback): void; unsubscribe(symbol: SymbolInfo, _period: Period): void; destroy(): void; private _connectWebSocket; private _attemptReconnect; private _cleanupWebSocket; } export declare class KLineChartPro implements ChartPro { constructor(options: ChartProOptions); private _container; private _chartApi; private _readyPromise; private _readyResolve; ready(): Promise; setTheme(theme: string): void; getTheme(): string; setStyles(styles: DeepPartial): void; getStyles(): Styles; setLocale(locale: string): void; getLocale(): string; setTimezone(timezone: string): void; getTimezone(): string; setSymbol(symbol: SymbolInfo): void; getSymbol(): SymbolInfo; setPeriod(period: Period): void; getPeriod(): Period; setChartType(type: string): void; getChartType(): string; getSettings(): any; setSettings(settings: any): void; getDrawings(ticker: string): any[]; setDrawings(ticker: string, drawings: any[]): void; getWidget(): any; destroy(): void; } export interface StoredPreferences { theme?: string; locale?: string; timezone?: string; symbol?: SymbolInfo; period?: Period; mainIndicators?: string[]; subIndicators?: string[]; styles?: Record; drawings?: Record; alerts?: AlertConfig[]; customScripts?: Record; indicatorCalcParams?: Record; } /** * Persistence layer using localStorage. * All keys are namespaced with the storage prefix to avoid collisions. */ export declare class ChartStore { private _prefix; private _enabled; constructor(enabled?: boolean, prefix?: string); private _key; private _get; private _set; private _remove; getTheme(): string | null; setTheme(theme: string): void; getLocale(): string | null; setLocale(locale: string): void; getTimezone(): string | null; setTimezone(timezone: string): void; getSymbol(): SymbolInfo | null; setSymbol(symbol: SymbolInfo): void; getPeriod(): Period | null; setPeriod(period: Period): void; getMainIndicators(): string[] | null; setMainIndicators(indicators: string[]): void; getSubIndicators(): Record | null; setSubIndicators(indicators: Record): void; getIndicatorCalcParams(): Record; setIndicatorCalcParam(indicatorName: string, calcParams: any[]): void; getIndicatorCalcParam(indicatorName: string): any[] | null; removeIndicatorCalcParam(indicatorName: string): void; getStyles(): Record | null; setStyles(styles: Record): void; getDrawings(ticker: string): any[] | null; setDrawings(ticker: string, drawings: any[]): void; getChartType(): string | null; setChartType(type: string): void; getRenkoBrickSize(): number | null; setRenkoBrickSize(size: number): void; getRangeBarSize(): number | null; setRangeBarSize(size: number): void; getAlerts(): AlertConfig[]; setAlerts(alerts: AlertConfig[]): void; addAlert(alert: AlertConfig): void; removeAlert(id: string): void; getCustomScripts(): Record; setCustomScripts(scripts: Record): void; addCustomScript(name: string, script: string): void; removeCustomScript(name: string): void; getAll(): StoredPreferences; clear(): void; } export interface DrawingAction { type: "add" | "remove" | "modify"; overlay: any; previousState?: any; } /** * Drawing persistence + undo/redo stack. */ export declare class DrawingStore { private _store; private _undoStack; private _redoStack; private _maxHistory; constructor(store: ChartStore); pushAction(action: DrawingAction): void; canUndo(): boolean; canRedo(): boolean; undo(): DrawingAction | null; redo(): DrawingAction | null; saveDrawings(ticker: string, drawings: any[]): void; loadDrawings(ticker: string): any[]; exportDrawings(ticker: string): string; importDrawings(json: string): { ticker: string; drawings: any[]; } | null; clearHistory(): void; } export interface ComparisonSymbol { symbol: SymbolInfo; data: KLineData[]; color: string; visible: boolean; normalizedData: { timestamp: number; value: number; }[]; indicatorName: string; } /** * Multi-symbol comparison overlay. * Normalizes prices to percentage change from the first visible candle, * then projects onto the main chart's price scale so lines overlay naturally. * * Each comparison symbol gets its own klinecharts indicator drawn on candle_pane. */ export declare class ComparisonManager { private _symbols; private _widget; private _datafeed; private _colorIndex; private _onChange?; private _registeredIndicators; constructor(widget: Nullable, datafeed: Nullable); setOnChange(callback: () => void): void; getSymbols(): ComparisonSymbol[]; addSymbol(symbol: SymbolInfo, period: Period, from: number, to: number): Promise; private _registerComparisonIndicator; removeSymbol(ticker: string): void; toggleVisibility(ticker: string): void; private _normalizeData; clear(): void; destroy(): void; } /** * Retry a function with exponential backoff */ export declare function withRetry(fn: () => Promise, options?: { maxAttempts?: number; baseDelay?: number; maxDelay?: number; onRetry?: (attempt: number, error: Error) => void; }): Promise; /** * Wrap a promise with a timeout */ export declare function withTimeout(promise: Promise, timeoutMs: number, message?: string): Promise; export type ErrorHandler = (error: Error) => void; /** * Centralized error handler */ export declare class ErrorManager { private _handlers; private _lastError; onError(handler: ErrorHandler): () => void; report(error: Error): void; getLastError(): Error | null; clear(): void; } /** * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * http://www.apache.org/licenses/LICENSE-2.0 * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ /** * Central registry for custom indicators and overlays. * When users register custom tools via the public API, * they are added here so the UI menus can dynamically display them. */ export interface CustomRegistryItem { /** Internal name used by klinecharts engine */ name: string; /** Display label shown in menus */ label: string; /** Whether this is a main chart or sub chart indicator (indicators only) */ paneType?: "main" | "sub"; } declare class Registry { private _customIndicators; private _customOverlays; private _listeners; /** Register a custom indicator for UI display */ addIndicator(item: CustomRegistryItem): void; /** Remove a custom indicator from UI display */ removeIndicator(name: string): void; /** Register a custom overlay for UI display */ addOverlay(item: CustomRegistryItem): void; /** Get all registered custom indicators */ getCustomIndicators(): CustomRegistryItem[]; /** Get custom indicators filtered by pane type */ getCustomMainIndicators(): CustomRegistryItem[]; getCustomSubIndicators(): CustomRegistryItem[]; /** Get all registered custom overlays */ getCustomOverlays(): CustomRegistryItem[]; /** Subscribe to changes (for reactive UI updates) */ onChange(listener: () => void): () => void; private _notify; } /** Singleton registry instance */ export declare const customRegistry: Registry; /** * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * http://www.apache.org/licenses/LICENSE-2.0 * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ export interface ShortcutBinding { /** e.g. 'ctrl+z', 'alt+s', 'delete', 'escape', '1', 'f11' */ key: string; description?: string; callback: (e: KeyboardEvent) => void; } /** * Keyboard shortcut manager for chart operations. * Listens to keyboard events and dispatches registered callbacks. */ export declare class KeyboardShortcutManager { private _container?; private _bindings; private _parsedBindings; private _handler; private _enabled; constructor(_container?: HTMLElement | undefined); /** Register a keyboard shortcut */ register(binding: ShortcutBinding): void; /** Remove a keyboard shortcut */ remove(key: string): void; /** Enable/disable all shortcuts */ setEnabled(enabled: boolean): void; /** Get all registered bindings */ getBindings(): ShortcutBinding[]; /** Clean up */ destroy(): void; } export interface ChartTemplate { name: string; mainIndicators: string[]; subIndicators: string[]; styles?: any; period?: { multiplier: number; timespan: string; text: string; }; theme?: string; createdAt: number; } /** * Chart template manager. * Save/load indicator + style configurations as reusable presets. */ export declare class ChartTemplateManager { private _store; constructor(store: ChartStore); /** Save a template */ saveTemplate(template: ChartTemplate): void; /** Load a template by name */ loadTemplate(name: string): ChartTemplate | null; /** Delete a template by name */ deleteTemplate(name: string): void; /** Get all template names */ getTemplateNames(): string[]; /** Get all templates */ getTemplates(): ChartTemplate[]; private _getAll; private _saveAll; } /** * Crosshair sync manager. * Links multiple Chart instances so that crosshair movement on one * chart broadcasts the timestamp to all others. */ export declare class CrosshairSyncManager { private _charts; private _isSyncing; /** Add a chart to the sync group */ addChart(chart: Chart): void; /** Remove a chart from the sync group */ removeChart(chart: Chart): void; /** Get number of linked charts */ getChartCount(): number; /** Clean up all subscriptions */ destroy(): void; } export type ReplayStatus = "idle" | "playing" | "paused" | "ended"; export type ReplayDataSource = "current" | "custom"; export interface ReplayOptions { /** Data source: 'current' = use loaded chart data, 'custom' = load from datafeed */ dataSource: ReplayDataSource; /** Speed in ms per bar (default 500) */ speed?: number; /** Start index (for 'current' source) or start timestamp (for 'custom' source) */ startFrom?: number; } export interface ReplayEventHandlers { onStep?: (index: number, total: number, bar: KLineData) => void; onPlay?: () => void; onPause?: () => void; onEnd?: () => void; onStatusChange?: (status: ReplayStatus) => void; } /** * Bar Replay Manager. * Allows replaying historical data bar by bar for trading practice. * Supports two data sources: * - 'current': Uses already-loaded chart data * - 'custom': Loads data from datafeed for a specific time range */ export declare class BarReplayManager { private _chart; private _datafeed; private _fullData; private _playbackIndex; private _status; private _speed; private _timerId; private _handlers; private _originalData; constructor(chart: Chart, datafeed?: Datafeed); /** Set event handlers */ setHandlers(handlers: ReplayEventHandlers): void; /** Start replay with the given options */ start(options: ReplayOptions): Promise; /** Load custom data from datafeed for replay */ loadData(symbol: SymbolInfo, period: Period, from: number, to: number): Promise; /** Play (auto-advance) */ play(): void; /** Pause playback */ pause(): void; /** Step one bar forward */ stepForward(): void; /** Step one bar backward */ stepBackward(): void; /** Jump to a specific index */ seekTo(index: number): void; /** Set playback speed in ms per bar */ setSpeed(ms: number): void; /** Get current state */ getStatus(): ReplayStatus; getIndex(): number; getTotal(): number; getSpeed(): number; getCurrentBar(): KLineData | null; /** Stop replay and restore original data */ stop(): void; /** Clean up */ destroy(): void; private _applyData; private _setStatus; } declare function load(key: string, ls: Record): void; export interface RegisterOverlayOptions { /** The klinecharts OverlayTemplate */ template: OverlayTemplate; /** Display label in the drawing toolbar menu. Defaults to template.name */ label?: string; } export interface RegisterIndicatorOptions { /** The klinecharts IndicatorTemplate */ template: IndicatorTemplate; /** Display label in the indicator menu. Defaults to template.shortName or template.name */ label?: string; /** Where the indicator appears: 'main' (candle pane) or 'sub' (new pane). Defaults to 'sub' */ paneType?: "main" | "sub"; } /** * Register a custom overlay (drawing tool). * It will be registered with klinecharts AND automatically appear * in the drawing toolbar menu under the "Custom" group. * * @example * ```ts * import { registerCustomOverlay } from '@anthropic/klinecharts-pro' * * // Simple: just pass an OverlayTemplate directly * registerCustomOverlay({ * name: 'myCustomTool', * totalStep: 3, * createPointFigures: ({ coordinates }) => { * return [{ type: 'line', attrs: { coordinates: [coordinates[0], coordinates[1]] } }] * } * }) * * // Advanced: pass options with custom label * registerCustomOverlay({ * template: { name: 'myTool', totalStep: 2, ... }, * label: 'My Custom Tool' * }) * ``` */ export declare function registerCustomOverlay(templateOrOptions: OverlayTemplate | RegisterOverlayOptions): void; /** * Register a custom technical indicator. * It will be registered with klinecharts AND automatically appear * in the indicator modal menu. * * @example * ```ts * import { registerCustomIndicator } from '@anthropic/klinecharts-pro' * * // Simple: just pass an IndicatorTemplate * registerCustomIndicator({ * name: 'MyRSI', * shortName: 'MRSI', * calcParams: [14], * figures: [{ key: 'rsi', title: 'RSI: ', type: 'line' }], * calc: (dataList, indicator) => { * // ... your calculation * return dataList.map(() => ({ rsi: 50 })) * } * }) * * // Advanced: with custom label and pane type * registerCustomIndicator({ * template: { name: 'VWAP', ... }, * label: 'Volume Weighted Average Price', * paneType: 'main' // appears on main candle chart * }) * ``` */ export declare function registerCustomIndicator(templateOrOptions: IndicatorTemplate | RegisterIndicatorOptions): void; export { load as loadLocales, }; export as namespace klinechartspro; export {};