@liberfi.io/ui-tradingview 0.1.225 → 0.1.227

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -7,6 +7,7 @@ TradingView K-line charting component for Liberfi React SDK. This package wraps
7
7
  - **Multi-instance isolation** — Every chart instance is keyed by a `storageId` (prefix). State atoms use `atomFamily(prefix)` so multiple charts coexist without creating extra jotai Providers or stores.
8
8
  - **No RxJS** — All reactive state lives in jotai atoms. Internal bridge-level events (symbol changes, crosshair moves) use a lightweight `EventEmitter`.
9
9
  - **Injectable DataFeed** — The consumer provides the `ITvChartDataFeedModule` implementation and the TradingView `Widget` constructor. This package does not bundle the charting library or data-fetching logic.
10
+ - **Stable datafeed seam** — `TradingViewDatafeedAdapter` separates history candles from live subscribe/unsubscribe, pins timestamp unit mapping, drops out-of-order ticks, and makes unsubscribe idempotent.
10
11
  - **Composable toolbar** — The built-in toolbar ships default controls (resolutions, kline style, indicators, settings, fullscreen, snapshot) that can be individually toggled or fully replaced via slots.
11
12
 
12
13
  ## Installation
@@ -98,17 +99,18 @@ Composable toolbar with slot-based customization.
98
99
 
99
100
  ### Types & Enums
100
101
 
101
- | Type / Enum | Description |
102
- | ------------------------ | -------------------------------------------------- |
103
- | `TvChartConfig` | Configuration passed to `initConfig` |
104
- | `TvChartResolution` | `"1s" \| "5s" \| ... \| "1d"` |
105
- | `TvChartKlineStyle` | Candles, Bars, Line, Area, HeikenAshi, etc. |
106
- | `TvChartLayout` | Layout presets (1A, 2A, 3A, etc.) |
107
- | `TvChartTheme` | `"light" \| "dark"` |
108
- | `TvChartFeature` | Feature flags (MultiCharts, VolumeForceOverlay...) |
109
- | `ITvChartDataFeedModule` | Interface consumers implement for data fetching |
110
- | `ITvChartSymbolResolver` | Interface for symbol info resolution |
111
- | `ChartAreaState` | Shape of per-area state in atoms |
102
+ | Type / Enum | Description |
103
+ | ---------------------------- | ------------------------------------------------------------------------------- |
104
+ | `TvChartConfig` | Configuration passed to `initConfig` |
105
+ | `TvChartResolution` | `"1s" \| "5s" \| ... \| "1d"` |
106
+ | `TvChartKlineStyle` | Candles, Bars, Line, Area, HeikenAshi, etc. |
107
+ | `TvChartLayout` | Layout presets (1A, 2A, 3A, etc.) |
108
+ | `TvChartTheme` | `"light" \| "dark"` |
109
+ | `TvChartFeature` | Feature flags (MultiCharts, VolumeForceOverlay...) |
110
+ | `ITvChartDataFeedModule` | Interface consumers implement for data fetching |
111
+ | `TradingViewDatafeedAdapter` | Recommended seam over a `CandleSource` `{ getHistory, subscribe, unsubscribe }` |
112
+ | `ITvChartSymbolResolver` | Interface for symbol info resolution |
113
+ | `ChartAreaState` | Shape of per-area state in atoms |
112
114
 
113
115
  ### Atoms
114
116
 
@@ -133,6 +135,35 @@ All atoms are `atomFamily` instances keyed by `prefix` (storageId). Advanced con
133
135
 
134
136
  ## Usage Examples
135
137
 
138
+ ### Candle source via `TradingViewDatafeedAdapter`
139
+
140
+ `ChartDataFeed` remains the TradingView library class. Implement candles with `TradingViewDatafeedAdapter` and pass the adapter as `initConfig.datafeed`.
141
+
142
+ ```ts
143
+ import {
144
+ TradingViewDatafeedAdapter,
145
+ type CandleSource,
146
+ } from "@liberfi.io/ui-tradingview";
147
+
148
+ const source: CandleSource = {
149
+ async getHistory({ periodParams }) {
150
+ return fetchHistory(periodParams); // `[]` if empty
151
+ },
152
+ subscribe(request, onCandle) {
153
+ listenLive(request, onCandle);
154
+ },
155
+ unsubscribe(listenerGuid) {
156
+ stopLive(listenerGuid);
157
+ },
158
+ };
159
+
160
+ const datafeed = new TradingViewDatafeedAdapter(source, {
161
+ resolveSymbol: (symbolName) => resolve(symbolName),
162
+ });
163
+ ```
164
+
165
+ Numeric timestamps with 10 or fewer digits are unix seconds; longer values and `Date` objects are milliseconds. Unsubscribe is idempotent: a second `unsubscribeBars(guid)` does not call the source again.
166
+
136
167
  ### Basic Usage
137
168
 
138
169
  ```tsx
@@ -226,7 +257,7 @@ function App() {
226
257
 
227
258
  - Add `TradingViewAreaTitle` injection into TradingView widget iframe for multi-chart layouts
228
259
  - Support consumer-provided color palettes via props
229
- - Add built-in `ITvChartDataFeedModule` implementation for common REST/WebSocket patterns
260
+ - Wire Storybook `ClientDataFeedModule` through `TradingViewDatafeedAdapter`
230
261
  - Support chart comparison mode
231
262
  - Add keyboard shortcut customization
232
263
  - Expose drawing tools API
package/dist/index.d.mts CHANGED
@@ -340,8 +340,8 @@ declare class ChartWidget {
340
340
  get chartWidget(): IChartWidgetApi | null;
341
341
  setChartStyle(chartType: SeriesType): void;
342
342
  getChartStyle(): SeriesType;
343
- handleSymbolChange(symbol: string, _prevSymbol: string): Promise<void>;
344
- handleResolutionChange(resolution: TvChartResolution, _prevResolution: string): Promise<void>;
343
+ handleSymbolChange(symbol: string, prevSymbol: string): Promise<void>;
344
+ handleResolutionChange(resolution: TvChartResolution, prevResolution: string): Promise<void>;
345
345
  setPrecision(precision: number | null): void;
346
346
  dataReady(): Promise<void>;
347
347
  timeScaleWidth(): number;
@@ -403,7 +403,7 @@ declare class ChartLibraryWidget {
403
403
  openSettingsDialog(): void;
404
404
  takeClientScreenshot(): Promise<HTMLCanvasElement> | undefined;
405
405
  onLayoutChange(layout: TvChartLayout): void;
406
- onThemeChange(theme: string, _reverseColor: boolean): Promise<void>;
406
+ onThemeChange(theme: string, reverseColor: boolean): Promise<void>;
407
407
  }
408
408
 
409
409
  /**
@@ -560,6 +560,10 @@ interface TvChartSymbolInfo extends LibrarySymbolInfo {
560
560
  quote: TvChartQuoteType;
561
561
  precision: number;
562
562
  }
563
+ /**
564
+ * Injectable history + live datafeed. Prefer {@link TradingViewDatafeedAdapter}
565
+ * as the stable seam; ChartManager.datafeed remains this interface.
566
+ */
563
567
  interface ITvChartDataFeedModule {
564
568
  onReady(options: {
565
569
  setting: ChartSettings;
@@ -658,9 +662,10 @@ declare class TvChartHandle {
658
662
  getSetting(): ChartSettings;
659
663
  getChartManager(): ChartManager;
660
664
  }
661
- interface TradingViewProviderProps extends PropsWithChildren<TradingViewConfigProps> {
662
- }
663
- declare const TradingViewProvider: react.ForwardRefExoticComponent<TradingViewProviderProps & react.RefAttributes<TvChartHandle>>;
665
+ type TradingViewProviderProps = PropsWithChildren<TradingViewConfigProps>;
666
+ declare const TradingViewProvider: react.ForwardRefExoticComponent<TradingViewConfigProps & {
667
+ children?: react.ReactNode | undefined;
668
+ } & react.RefAttributes<TvChartHandle>>;
664
669
 
665
670
  interface TradingViewToolbarProps {
666
671
  /** Extra elements to render before the default toolbar items */
@@ -778,8 +783,10 @@ declare function useActiveAreaManager(): ChartAreaManager | null;
778
783
  declare function useSymbolInfo(): LibrarySymbolInfo | null;
779
784
 
780
785
  /**
781
- * DataFeed adapter that conforms to the TradingView Datafeed API.
782
- * Delegates actual data fetching to the injectable ITvChartDataFeedModule.
786
+ * TradingView Charting Library Datafeed API class.
787
+ * Delegates history, live subscribe/unsubscribe, and symbol resolve to the
788
+ * injectable {@link ITvChartDataFeedModule}. Consumers should implement that
789
+ * module with {@link TradingViewDatafeedAdapter} rather than changing this class.
783
790
  */
784
791
  declare class ChartDataFeed {
785
792
  private settings;
@@ -803,15 +810,108 @@ declare class ChartDataFeed {
803
810
  * TradingView that the datafeed supports the quotes API but has no quote data
804
811
  * beyond what is already on the chart, which suppresses the internal errors.
805
812
  */
806
- getQuotes(symbols: string[], onDataCallback: (data: any[]) => void, _onErrorCallback: (reason: string) => void): void;
813
+ getQuotes(symbols: string[], onDataCallback: (data: any[]) => void, onErrorCallback: (reason: string) => void): void;
807
814
  /**
808
815
  * TradingView calls subscribeQuotes to receive real-time price ticks for the
809
816
  * header display. We return a no-op here because the chart already receives
810
817
  * real-time data via subscribeBars. Implementing this stub prevents the
811
818
  * internal qs_* session from remaining in a pending/broken state.
812
819
  */
813
- subscribeQuotes(_symbols: string[], _fastSymbols: string[], _onRealtimeCallback: (data: any[]) => void, _listenerGuid: string): void;
814
- unsubscribeQuotes(_listenerGuid: string): void;
820
+ subscribeQuotes(symbols: string[], fastSymbols: string[], onRealtimeCallback: (data: any[]) => void, listenerGuid: string): void;
821
+ unsubscribeQuotes(listenerGuid: string): void;
822
+ }
823
+
824
+ /**
825
+ * Raw candle the consumer source returns. `time` may be unix seconds
826
+ * (≤10 digits), milliseconds (>10 digits), or a `Date`.
827
+ * {@link TradingViewDatafeedAdapter} owns unit mapping via
828
+ * {@link getTvChartTickTimestamp}.
829
+ */
830
+ interface TradingViewCandle {
831
+ time: number | Date;
832
+ open: number;
833
+ high: number;
834
+ low: number;
835
+ close: number;
836
+ volume?: number;
837
+ }
838
+ interface TradingViewHistoryRequest {
839
+ symbolInfo: LibrarySymbolInfo;
840
+ resolution: ResolutionString;
841
+ periodParams: PeriodParams;
842
+ }
843
+ interface TradingViewLiveSubscribeRequest {
844
+ symbolInfo: LibrarySymbolInfo;
845
+ resolution: ResolutionString;
846
+ listenerGuid: string;
847
+ onResetCacheNeededCallback: () => void;
848
+ }
849
+ /**
850
+ * Consumer candle backend. The adapter wraps this with timestamp mapping,
851
+ * out-of-order live-bar filtering, and idempotent unsubscribe.
852
+ */
853
+ interface CandleSource {
854
+ getHistory(request: TradingViewHistoryRequest): Promise<readonly TradingViewCandle[]>;
855
+ subscribe(request: TradingViewLiveSubscribeRequest, onCandle: (candle: TradingViewCandle) => void): void;
856
+ unsubscribe(listenerGuid: string): void;
857
+ }
858
+ interface TradingViewDatafeedAdapterOptions {
859
+ resolveSymbol?: ITvChartDataFeedModule["resolveSymbol"];
860
+ onReady?: ITvChartDataFeedModule["onReady"];
861
+ onDestroy?: ITvChartDataFeedModule["onDestroy"];
862
+ getMarks?: ITvChartDataFeedModule["getMarks"];
863
+ getFirstBarTime?: ITvChartDataFeedModule["getFirstBarTime"];
864
+ /** Viewport width (px) below which {@link isTvChartMobileViewport} is true. */
865
+ mobileBreakpointPx?: number;
866
+ }
867
+ /** Tailwind `md` — unit-level mobile/resize seam, no widget required. */
868
+ declare const DEFAULT_TV_CHART_MOBILE_BREAKPOINT_PX = 768;
869
+ declare function isTvChartMobileViewport(widthPx: number, breakpointPx?: number): boolean;
870
+ /**
871
+ * Consumer-facing TradingView datafeed seam.
872
+ *
873
+ * Implements {@link ITvChartDataFeedModule} so `ChartManager.datafeed` and
874
+ * `ChartDataFeed` stay unchanged. History, live subscribe, and unsubscribe
875
+ * are explicit methods; symbol resolve / onReady / onDestroy are delegated.
876
+ */
877
+ declare class TradingViewDatafeedAdapter implements ITvChartDataFeedModule {
878
+ private readonly source;
879
+ private readonly options;
880
+ private readonly liveListeners;
881
+ private readonly lastHistoryBarTime;
882
+ private liveGeneration;
883
+ constructor(source: CandleSource, options?: TradingViewDatafeedAdapterOptions);
884
+ isMobileViewport(widthPx: number): boolean;
885
+ onReady(options: {
886
+ setting: ChartSettings;
887
+ chartManager: ChartManager;
888
+ instance: ChartWidgetBridge;
889
+ }): Promise<void>;
890
+ onDestroy(): void;
891
+ resolveSymbol(symbolName: string, extension?: SymbolResolveExtension): Promise<LibrarySymbolInfo | null>;
892
+ getBars(symbolInfo: LibrarySymbolInfo, resolution: ResolutionString, periodParams: PeriodParams): Promise<Bar[]>;
893
+ subscribeBars(symbolInfo: LibrarySymbolInfo, resolution: ResolutionString, onTick: SubscribeBarsCallback, listenerGuid: string, onResetCacheNeededCallback: () => void): void;
894
+ unsubscribeBars(listenerGuid: string): void;
895
+ getMarks(symbolInfo: LibrarySymbolInfo, from: number, to: number, onDataCallback: GetMarksCallback<Mark>, resolution: ResolutionString): void;
896
+ getFirstBarTime(symbolInfo: LibrarySymbolInfo, resolution: string, options: {
897
+ timezone: Timezone;
898
+ }): Promise<void>;
899
+ /**
900
+ * Fetch history candles, map timestamps, and return `[]` when the source
901
+ * has no data. {@link ChartDataFeed} maps `[]` to `{ noData: true }`.
902
+ */
903
+ getHistoryBars(symbolInfo: LibrarySymbolInfo, resolution: ResolutionString, periodParams: PeriodParams): Promise<Bar[]>;
904
+ /**
905
+ * Subscribe to live candles. Out-of-order ticks (`time < last bar time`)
906
+ * are dropped. Re-subscribing the same guid unsubscribes the previous
907
+ * source listener first.
908
+ */
909
+ subscribeLiveBars(symbolInfo: LibrarySymbolInfo, resolution: ResolutionString, onTick: SubscribeBarsCallback, listenerGuid: string, onResetCacheNeededCallback: () => void): void;
910
+ /**
911
+ * Unsubscribe a live listener. The source is called at most once per guid;
912
+ * a second call is a no-op (Map delete).
913
+ */
914
+ unsubscribeLiveBars(listenerGuid: string): void;
815
915
  }
816
916
 
817
917
  /**
@@ -842,9 +942,9 @@ declare class ChartSaveLoadAdapter {
842
942
  get shouldResetColorPalette(): boolean;
843
943
  toJSON(): null;
844
944
  getAllCharts(): Promise<any[]>;
845
- removeChart(_index: number): void;
945
+ removeChart(index: number): void;
846
946
  saveChart(chart: any): Promise<string>;
847
- getChartContent(_: any): Promise<string>;
947
+ getChartContent(content: any): Promise<string>;
848
948
  saveLineToolsAndGroups(_storageId: string, chartIndex: string, data: any): Promise<void>;
849
949
  loadLineToolsAndGroups(_storageId: string, chartIndex: string, _tool: string, symbolToLoad?: {
850
950
  symbol?: string;
@@ -862,12 +962,35 @@ declare class ChartSaveLoadAdapter {
862
962
  declare class ChartSettingsAdapter {
863
963
  private storagePrefix;
864
964
  initialSettings: Record<string, any>;
865
- constructor(settings: ChartSettings, _chartManager: ChartManager, _bridge: ChartWidgetBridge);
965
+ constructor(settings: ChartSettings, chartManager: ChartManager, bridge: ChartWidgetBridge);
866
966
  toJSON(): null;
867
967
  removeValue(key: string): void;
868
968
  setValue(key: string, value: any): void;
869
969
  }
870
970
 
971
+ declare const ENABLED_TV_CHART_FEATURES: TvChartFeature[];
972
+ declare const DEFAULT_TV_CHART_RESOLUTIONS: TvChartResolution[];
973
+ declare const ALL_TV_CHART_RESOLUTIONS: TvChartResolution[];
974
+ declare const SUPPORTED_TV_CHART_LAYOUTS: TvChartLayout[];
975
+ declare const TV_CHART_THEME_COLORS: {
976
+ decrease: string;
977
+ increase: string;
978
+ chartBg: string;
979
+ card: string;
980
+ };
981
+
982
+ declare function parseSymbol(symbol: string): TvChartSymbol;
983
+ declare function stringifySymbol(symbol: TvChartSymbol): string;
984
+ declare function stringifySymbolShort(symbol: TvChartSymbol): string;
985
+ declare function getTvChartLibraryTheme(theme: string): ThemeName;
986
+ declare function getTvChartLibraryResolution(resolution?: TvChartResolution): ResolutionString;
987
+ declare function getTvChartResolutionReverse(resolution: string): TvChartResolution;
988
+ declare function getTvChartLibraryLocale(locale: string): LanguageCode;
989
+ declare function getTvChartLibraryLayout(layout: TvChartLayout): LayoutType;
990
+ declare function getTvChartLayoutReverse(layout: LayoutType): TvChartLayout;
991
+ declare function getTvChartResolutionFrame(resolution: TvChartResolution): number;
992
+ declare function getTvChartTickTimestamp(time: number, timeframe: number): number;
993
+
871
994
  declare const chartLoadingFamily: jotai_vanilla_utils_atomFamily.AtomFamily<string, jotai.PrimitiveAtom<boolean> & {
872
995
  init: boolean;
873
996
  }>;
@@ -931,27 +1054,4 @@ declare const settingsDataFamily: jotai_vanilla_utils_atomFamily.AtomFamily<stri
931
1054
  areaContents: ChartAreaState[];
932
1055
  }>>;
933
1056
 
934
- declare const ENABLED_TV_CHART_FEATURES: TvChartFeature[];
935
- declare const DEFAULT_TV_CHART_RESOLUTIONS: TvChartResolution[];
936
- declare const ALL_TV_CHART_RESOLUTIONS: TvChartResolution[];
937
- declare const SUPPORTED_TV_CHART_LAYOUTS: TvChartLayout[];
938
- declare const TV_CHART_THEME_COLORS: {
939
- decrease: string;
940
- increase: string;
941
- chartBg: string;
942
- card: string;
943
- };
944
-
945
- declare function parseSymbol(symbol: string): TvChartSymbol;
946
- declare function stringifySymbol(symbol: TvChartSymbol): string;
947
- declare function stringifySymbolShort(symbol: TvChartSymbol): string;
948
- declare function getTvChartLibraryTheme(theme: string): ThemeName;
949
- declare function getTvChartLibraryResolution(resolution?: TvChartResolution): ResolutionString;
950
- declare function getTvChartResolutionReverse(resolution: string): TvChartResolution;
951
- declare function getTvChartLibraryLocale(locale: string): LanguageCode;
952
- declare function getTvChartLibraryLayout(layout: TvChartLayout): LayoutType;
953
- declare function getTvChartLayoutReverse(layout: LayoutType): TvChartLayout;
954
- declare function getTvChartResolutionFrame(resolution: TvChartResolution): number;
955
- declare function getTvChartTickTimestamp(time: number, timeframe: number): number;
956
-
957
- export { ALL_TV_CHART_RESOLUTIONS, type Bar, ChartAreaManager, type ChartAreaState, ChartDataFeed, ChartLibraryWidget, ChartManager, ChartSaveLoadAdapter, ChartSettings, ChartSettingsAdapter, ChartSettingsStore, ChartSymbolResolver, ChartWidget, ChartWidgetBridge, type ChartingLibraryWidgetOptions, DEFAULT_TV_CHART_RESOLUTIONS, ENABLED_TV_CHART_FEATURES, EventEmitter, type HistoryMetaInfo, type IChartWidgetApi, type IChartingLibraryWidget, type ITvChartDataFeedModule, type ITvChartSymbolResolver, type LanguageCode, type LibrarySymbolInfo, type Mark, type PeriodParams, type ResolutionString, SUPPORTED_TV_CHART_LAYOUTS, type SeriesFormatterFactory, type SubscribeBarsCallback, type SymbolResolveExtension, TV_CHART_THEME_COLORS, type ThemeName, type Timezone, TradingView, TradingViewAreaTitle, TradingViewConfig, type TradingViewConfigProps, TradingViewFullscreen, type TradingViewInstance, TradingViewKlineStyleSelect, TradingViewLayout, TradingViewOpenIndicator, TradingViewOpenSettings, type TradingViewProps, TradingViewProvider, type TradingViewProviderProps, TradingViewResolutions, TradingViewSnapshot, TradingViewToolbar, type TradingViewToolbarProps, TradingViewToolbarProvider, TradingViewWidgetContainer, TradingViewWidgetProvider, type TvChartConfig, type TvChartContextValue, TvChartErrorResetType, TvChartFeature, TvChartHandle, TvChartKlineStyle, TvChartLayout, TvChartPriceType, TvChartQuoteType, type TvChartResolution, type TvChartSymbol, type TvChartSymbolChange, type TvChartSymbolInfo, TvChartTheme, TvChartType, type WidgetConstructor, chartAreasFamily, chartFullscreenFamily, chartLoadingFamily, chartPinnedResolutionsFamily, chartSelectedIndexFamily, chartShowDrawingToolbarFamily, getTvChartLayoutReverse, getTvChartLibraryLayout, getTvChartLibraryLocale, getTvChartLibraryResolution, getTvChartLibraryTheme, getTvChartResolutionFrame, getTvChartResolutionReverse, getTvChartTickTimestamp, parseSymbol, settingsBackgroundColorFamily, settingsChartTypeFamily, settingsDataFamily, settingsDisabledFeaturesFamily, settingsEnabledFeaturesFamily, settingsLayoutFamily, settingsLocaleFamily, settingsReverseColorFamily, settingsStorageIdFamily, settingsThemeFamily, settingsTickerSymbolFamily, settingsTimezoneFamily, stringifySymbol, stringifySymbolShort, useActiveAreaManager, useChartManager, useSymbolInfo, useTvChartContext, useTvChartManager, useTvChartPrefix, useTvChartToolbarContext, widgetReadyFamily };
1057
+ export { ALL_TV_CHART_RESOLUTIONS, type Bar, type CandleSource, ChartAreaManager, type ChartAreaState, ChartDataFeed, ChartLibraryWidget, ChartManager, ChartSaveLoadAdapter, ChartSettings, ChartSettingsAdapter, ChartSettingsStore, ChartSymbolResolver, ChartWidget, ChartWidgetBridge, type ChartingLibraryWidgetOptions, DEFAULT_TV_CHART_MOBILE_BREAKPOINT_PX, DEFAULT_TV_CHART_RESOLUTIONS, ENABLED_TV_CHART_FEATURES, EventEmitter, type HistoryMetaInfo, type IChartWidgetApi, type IChartingLibraryWidget, type ITvChartDataFeedModule, type ITvChartSymbolResolver, type LanguageCode, type LibrarySymbolInfo, type Mark, type PeriodParams, type ResolutionString, SUPPORTED_TV_CHART_LAYOUTS, type SeriesFormatterFactory, type SubscribeBarsCallback, type SymbolResolveExtension, TV_CHART_THEME_COLORS, type ThemeName, type Timezone, TradingView, TradingViewAreaTitle, type TradingViewCandle, TradingViewConfig, type TradingViewConfigProps, TradingViewDatafeedAdapter, type TradingViewDatafeedAdapterOptions, TradingViewFullscreen, type TradingViewHistoryRequest, type TradingViewInstance, TradingViewKlineStyleSelect, TradingViewLayout, type TradingViewLiveSubscribeRequest, TradingViewOpenIndicator, TradingViewOpenSettings, type TradingViewProps, TradingViewProvider, type TradingViewProviderProps, TradingViewResolutions, TradingViewSnapshot, TradingViewToolbar, type TradingViewToolbarProps, TradingViewToolbarProvider, TradingViewWidgetContainer, TradingViewWidgetProvider, type TvChartConfig, type TvChartContextValue, TvChartErrorResetType, TvChartFeature, TvChartHandle, TvChartKlineStyle, TvChartLayout, TvChartPriceType, TvChartQuoteType, type TvChartResolution, type TvChartSymbol, type TvChartSymbolChange, type TvChartSymbolInfo, TvChartTheme, TvChartType, type WidgetConstructor, chartAreasFamily, chartFullscreenFamily, chartLoadingFamily, chartPinnedResolutionsFamily, chartSelectedIndexFamily, chartShowDrawingToolbarFamily, getTvChartLayoutReverse, getTvChartLibraryLayout, getTvChartLibraryLocale, getTvChartLibraryResolution, getTvChartLibraryTheme, getTvChartResolutionFrame, getTvChartResolutionReverse, getTvChartTickTimestamp, isTvChartMobileViewport, parseSymbol, settingsBackgroundColorFamily, settingsChartTypeFamily, settingsDataFamily, settingsDisabledFeaturesFamily, settingsEnabledFeaturesFamily, settingsLayoutFamily, settingsLocaleFamily, settingsReverseColorFamily, settingsStorageIdFamily, settingsThemeFamily, settingsTickerSymbolFamily, settingsTimezoneFamily, stringifySymbol, stringifySymbolShort, useActiveAreaManager, useChartManager, useSymbolInfo, useTvChartContext, useTvChartManager, useTvChartPrefix, useTvChartToolbarContext, widgetReadyFamily };
package/dist/index.d.ts CHANGED
@@ -340,8 +340,8 @@ declare class ChartWidget {
340
340
  get chartWidget(): IChartWidgetApi | null;
341
341
  setChartStyle(chartType: SeriesType): void;
342
342
  getChartStyle(): SeriesType;
343
- handleSymbolChange(symbol: string, _prevSymbol: string): Promise<void>;
344
- handleResolutionChange(resolution: TvChartResolution, _prevResolution: string): Promise<void>;
343
+ handleSymbolChange(symbol: string, prevSymbol: string): Promise<void>;
344
+ handleResolutionChange(resolution: TvChartResolution, prevResolution: string): Promise<void>;
345
345
  setPrecision(precision: number | null): void;
346
346
  dataReady(): Promise<void>;
347
347
  timeScaleWidth(): number;
@@ -403,7 +403,7 @@ declare class ChartLibraryWidget {
403
403
  openSettingsDialog(): void;
404
404
  takeClientScreenshot(): Promise<HTMLCanvasElement> | undefined;
405
405
  onLayoutChange(layout: TvChartLayout): void;
406
- onThemeChange(theme: string, _reverseColor: boolean): Promise<void>;
406
+ onThemeChange(theme: string, reverseColor: boolean): Promise<void>;
407
407
  }
408
408
 
409
409
  /**
@@ -560,6 +560,10 @@ interface TvChartSymbolInfo extends LibrarySymbolInfo {
560
560
  quote: TvChartQuoteType;
561
561
  precision: number;
562
562
  }
563
+ /**
564
+ * Injectable history + live datafeed. Prefer {@link TradingViewDatafeedAdapter}
565
+ * as the stable seam; ChartManager.datafeed remains this interface.
566
+ */
563
567
  interface ITvChartDataFeedModule {
564
568
  onReady(options: {
565
569
  setting: ChartSettings;
@@ -658,9 +662,10 @@ declare class TvChartHandle {
658
662
  getSetting(): ChartSettings;
659
663
  getChartManager(): ChartManager;
660
664
  }
661
- interface TradingViewProviderProps extends PropsWithChildren<TradingViewConfigProps> {
662
- }
663
- declare const TradingViewProvider: react.ForwardRefExoticComponent<TradingViewProviderProps & react.RefAttributes<TvChartHandle>>;
665
+ type TradingViewProviderProps = PropsWithChildren<TradingViewConfigProps>;
666
+ declare const TradingViewProvider: react.ForwardRefExoticComponent<TradingViewConfigProps & {
667
+ children?: react.ReactNode | undefined;
668
+ } & react.RefAttributes<TvChartHandle>>;
664
669
 
665
670
  interface TradingViewToolbarProps {
666
671
  /** Extra elements to render before the default toolbar items */
@@ -778,8 +783,10 @@ declare function useActiveAreaManager(): ChartAreaManager | null;
778
783
  declare function useSymbolInfo(): LibrarySymbolInfo | null;
779
784
 
780
785
  /**
781
- * DataFeed adapter that conforms to the TradingView Datafeed API.
782
- * Delegates actual data fetching to the injectable ITvChartDataFeedModule.
786
+ * TradingView Charting Library Datafeed API class.
787
+ * Delegates history, live subscribe/unsubscribe, and symbol resolve to the
788
+ * injectable {@link ITvChartDataFeedModule}. Consumers should implement that
789
+ * module with {@link TradingViewDatafeedAdapter} rather than changing this class.
783
790
  */
784
791
  declare class ChartDataFeed {
785
792
  private settings;
@@ -803,15 +810,108 @@ declare class ChartDataFeed {
803
810
  * TradingView that the datafeed supports the quotes API but has no quote data
804
811
  * beyond what is already on the chart, which suppresses the internal errors.
805
812
  */
806
- getQuotes(symbols: string[], onDataCallback: (data: any[]) => void, _onErrorCallback: (reason: string) => void): void;
813
+ getQuotes(symbols: string[], onDataCallback: (data: any[]) => void, onErrorCallback: (reason: string) => void): void;
807
814
  /**
808
815
  * TradingView calls subscribeQuotes to receive real-time price ticks for the
809
816
  * header display. We return a no-op here because the chart already receives
810
817
  * real-time data via subscribeBars. Implementing this stub prevents the
811
818
  * internal qs_* session from remaining in a pending/broken state.
812
819
  */
813
- subscribeQuotes(_symbols: string[], _fastSymbols: string[], _onRealtimeCallback: (data: any[]) => void, _listenerGuid: string): void;
814
- unsubscribeQuotes(_listenerGuid: string): void;
820
+ subscribeQuotes(symbols: string[], fastSymbols: string[], onRealtimeCallback: (data: any[]) => void, listenerGuid: string): void;
821
+ unsubscribeQuotes(listenerGuid: string): void;
822
+ }
823
+
824
+ /**
825
+ * Raw candle the consumer source returns. `time` may be unix seconds
826
+ * (≤10 digits), milliseconds (>10 digits), or a `Date`.
827
+ * {@link TradingViewDatafeedAdapter} owns unit mapping via
828
+ * {@link getTvChartTickTimestamp}.
829
+ */
830
+ interface TradingViewCandle {
831
+ time: number | Date;
832
+ open: number;
833
+ high: number;
834
+ low: number;
835
+ close: number;
836
+ volume?: number;
837
+ }
838
+ interface TradingViewHistoryRequest {
839
+ symbolInfo: LibrarySymbolInfo;
840
+ resolution: ResolutionString;
841
+ periodParams: PeriodParams;
842
+ }
843
+ interface TradingViewLiveSubscribeRequest {
844
+ symbolInfo: LibrarySymbolInfo;
845
+ resolution: ResolutionString;
846
+ listenerGuid: string;
847
+ onResetCacheNeededCallback: () => void;
848
+ }
849
+ /**
850
+ * Consumer candle backend. The adapter wraps this with timestamp mapping,
851
+ * out-of-order live-bar filtering, and idempotent unsubscribe.
852
+ */
853
+ interface CandleSource {
854
+ getHistory(request: TradingViewHistoryRequest): Promise<readonly TradingViewCandle[]>;
855
+ subscribe(request: TradingViewLiveSubscribeRequest, onCandle: (candle: TradingViewCandle) => void): void;
856
+ unsubscribe(listenerGuid: string): void;
857
+ }
858
+ interface TradingViewDatafeedAdapterOptions {
859
+ resolveSymbol?: ITvChartDataFeedModule["resolveSymbol"];
860
+ onReady?: ITvChartDataFeedModule["onReady"];
861
+ onDestroy?: ITvChartDataFeedModule["onDestroy"];
862
+ getMarks?: ITvChartDataFeedModule["getMarks"];
863
+ getFirstBarTime?: ITvChartDataFeedModule["getFirstBarTime"];
864
+ /** Viewport width (px) below which {@link isTvChartMobileViewport} is true. */
865
+ mobileBreakpointPx?: number;
866
+ }
867
+ /** Tailwind `md` — unit-level mobile/resize seam, no widget required. */
868
+ declare const DEFAULT_TV_CHART_MOBILE_BREAKPOINT_PX = 768;
869
+ declare function isTvChartMobileViewport(widthPx: number, breakpointPx?: number): boolean;
870
+ /**
871
+ * Consumer-facing TradingView datafeed seam.
872
+ *
873
+ * Implements {@link ITvChartDataFeedModule} so `ChartManager.datafeed` and
874
+ * `ChartDataFeed` stay unchanged. History, live subscribe, and unsubscribe
875
+ * are explicit methods; symbol resolve / onReady / onDestroy are delegated.
876
+ */
877
+ declare class TradingViewDatafeedAdapter implements ITvChartDataFeedModule {
878
+ private readonly source;
879
+ private readonly options;
880
+ private readonly liveListeners;
881
+ private readonly lastHistoryBarTime;
882
+ private liveGeneration;
883
+ constructor(source: CandleSource, options?: TradingViewDatafeedAdapterOptions);
884
+ isMobileViewport(widthPx: number): boolean;
885
+ onReady(options: {
886
+ setting: ChartSettings;
887
+ chartManager: ChartManager;
888
+ instance: ChartWidgetBridge;
889
+ }): Promise<void>;
890
+ onDestroy(): void;
891
+ resolveSymbol(symbolName: string, extension?: SymbolResolveExtension): Promise<LibrarySymbolInfo | null>;
892
+ getBars(symbolInfo: LibrarySymbolInfo, resolution: ResolutionString, periodParams: PeriodParams): Promise<Bar[]>;
893
+ subscribeBars(symbolInfo: LibrarySymbolInfo, resolution: ResolutionString, onTick: SubscribeBarsCallback, listenerGuid: string, onResetCacheNeededCallback: () => void): void;
894
+ unsubscribeBars(listenerGuid: string): void;
895
+ getMarks(symbolInfo: LibrarySymbolInfo, from: number, to: number, onDataCallback: GetMarksCallback<Mark>, resolution: ResolutionString): void;
896
+ getFirstBarTime(symbolInfo: LibrarySymbolInfo, resolution: string, options: {
897
+ timezone: Timezone;
898
+ }): Promise<void>;
899
+ /**
900
+ * Fetch history candles, map timestamps, and return `[]` when the source
901
+ * has no data. {@link ChartDataFeed} maps `[]` to `{ noData: true }`.
902
+ */
903
+ getHistoryBars(symbolInfo: LibrarySymbolInfo, resolution: ResolutionString, periodParams: PeriodParams): Promise<Bar[]>;
904
+ /**
905
+ * Subscribe to live candles. Out-of-order ticks (`time < last bar time`)
906
+ * are dropped. Re-subscribing the same guid unsubscribes the previous
907
+ * source listener first.
908
+ */
909
+ subscribeLiveBars(symbolInfo: LibrarySymbolInfo, resolution: ResolutionString, onTick: SubscribeBarsCallback, listenerGuid: string, onResetCacheNeededCallback: () => void): void;
910
+ /**
911
+ * Unsubscribe a live listener. The source is called at most once per guid;
912
+ * a second call is a no-op (Map delete).
913
+ */
914
+ unsubscribeLiveBars(listenerGuid: string): void;
815
915
  }
816
916
 
817
917
  /**
@@ -842,9 +942,9 @@ declare class ChartSaveLoadAdapter {
842
942
  get shouldResetColorPalette(): boolean;
843
943
  toJSON(): null;
844
944
  getAllCharts(): Promise<any[]>;
845
- removeChart(_index: number): void;
945
+ removeChart(index: number): void;
846
946
  saveChart(chart: any): Promise<string>;
847
- getChartContent(_: any): Promise<string>;
947
+ getChartContent(content: any): Promise<string>;
848
948
  saveLineToolsAndGroups(_storageId: string, chartIndex: string, data: any): Promise<void>;
849
949
  loadLineToolsAndGroups(_storageId: string, chartIndex: string, _tool: string, symbolToLoad?: {
850
950
  symbol?: string;
@@ -862,12 +962,35 @@ declare class ChartSaveLoadAdapter {
862
962
  declare class ChartSettingsAdapter {
863
963
  private storagePrefix;
864
964
  initialSettings: Record<string, any>;
865
- constructor(settings: ChartSettings, _chartManager: ChartManager, _bridge: ChartWidgetBridge);
965
+ constructor(settings: ChartSettings, chartManager: ChartManager, bridge: ChartWidgetBridge);
866
966
  toJSON(): null;
867
967
  removeValue(key: string): void;
868
968
  setValue(key: string, value: any): void;
869
969
  }
870
970
 
971
+ declare const ENABLED_TV_CHART_FEATURES: TvChartFeature[];
972
+ declare const DEFAULT_TV_CHART_RESOLUTIONS: TvChartResolution[];
973
+ declare const ALL_TV_CHART_RESOLUTIONS: TvChartResolution[];
974
+ declare const SUPPORTED_TV_CHART_LAYOUTS: TvChartLayout[];
975
+ declare const TV_CHART_THEME_COLORS: {
976
+ decrease: string;
977
+ increase: string;
978
+ chartBg: string;
979
+ card: string;
980
+ };
981
+
982
+ declare function parseSymbol(symbol: string): TvChartSymbol;
983
+ declare function stringifySymbol(symbol: TvChartSymbol): string;
984
+ declare function stringifySymbolShort(symbol: TvChartSymbol): string;
985
+ declare function getTvChartLibraryTheme(theme: string): ThemeName;
986
+ declare function getTvChartLibraryResolution(resolution?: TvChartResolution): ResolutionString;
987
+ declare function getTvChartResolutionReverse(resolution: string): TvChartResolution;
988
+ declare function getTvChartLibraryLocale(locale: string): LanguageCode;
989
+ declare function getTvChartLibraryLayout(layout: TvChartLayout): LayoutType;
990
+ declare function getTvChartLayoutReverse(layout: LayoutType): TvChartLayout;
991
+ declare function getTvChartResolutionFrame(resolution: TvChartResolution): number;
992
+ declare function getTvChartTickTimestamp(time: number, timeframe: number): number;
993
+
871
994
  declare const chartLoadingFamily: jotai_vanilla_utils_atomFamily.AtomFamily<string, jotai.PrimitiveAtom<boolean> & {
872
995
  init: boolean;
873
996
  }>;
@@ -931,27 +1054,4 @@ declare const settingsDataFamily: jotai_vanilla_utils_atomFamily.AtomFamily<stri
931
1054
  areaContents: ChartAreaState[];
932
1055
  }>>;
933
1056
 
934
- declare const ENABLED_TV_CHART_FEATURES: TvChartFeature[];
935
- declare const DEFAULT_TV_CHART_RESOLUTIONS: TvChartResolution[];
936
- declare const ALL_TV_CHART_RESOLUTIONS: TvChartResolution[];
937
- declare const SUPPORTED_TV_CHART_LAYOUTS: TvChartLayout[];
938
- declare const TV_CHART_THEME_COLORS: {
939
- decrease: string;
940
- increase: string;
941
- chartBg: string;
942
- card: string;
943
- };
944
-
945
- declare function parseSymbol(symbol: string): TvChartSymbol;
946
- declare function stringifySymbol(symbol: TvChartSymbol): string;
947
- declare function stringifySymbolShort(symbol: TvChartSymbol): string;
948
- declare function getTvChartLibraryTheme(theme: string): ThemeName;
949
- declare function getTvChartLibraryResolution(resolution?: TvChartResolution): ResolutionString;
950
- declare function getTvChartResolutionReverse(resolution: string): TvChartResolution;
951
- declare function getTvChartLibraryLocale(locale: string): LanguageCode;
952
- declare function getTvChartLibraryLayout(layout: TvChartLayout): LayoutType;
953
- declare function getTvChartLayoutReverse(layout: LayoutType): TvChartLayout;
954
- declare function getTvChartResolutionFrame(resolution: TvChartResolution): number;
955
- declare function getTvChartTickTimestamp(time: number, timeframe: number): number;
956
-
957
- export { ALL_TV_CHART_RESOLUTIONS, type Bar, ChartAreaManager, type ChartAreaState, ChartDataFeed, ChartLibraryWidget, ChartManager, ChartSaveLoadAdapter, ChartSettings, ChartSettingsAdapter, ChartSettingsStore, ChartSymbolResolver, ChartWidget, ChartWidgetBridge, type ChartingLibraryWidgetOptions, DEFAULT_TV_CHART_RESOLUTIONS, ENABLED_TV_CHART_FEATURES, EventEmitter, type HistoryMetaInfo, type IChartWidgetApi, type IChartingLibraryWidget, type ITvChartDataFeedModule, type ITvChartSymbolResolver, type LanguageCode, type LibrarySymbolInfo, type Mark, type PeriodParams, type ResolutionString, SUPPORTED_TV_CHART_LAYOUTS, type SeriesFormatterFactory, type SubscribeBarsCallback, type SymbolResolveExtension, TV_CHART_THEME_COLORS, type ThemeName, type Timezone, TradingView, TradingViewAreaTitle, TradingViewConfig, type TradingViewConfigProps, TradingViewFullscreen, type TradingViewInstance, TradingViewKlineStyleSelect, TradingViewLayout, TradingViewOpenIndicator, TradingViewOpenSettings, type TradingViewProps, TradingViewProvider, type TradingViewProviderProps, TradingViewResolutions, TradingViewSnapshot, TradingViewToolbar, type TradingViewToolbarProps, TradingViewToolbarProvider, TradingViewWidgetContainer, TradingViewWidgetProvider, type TvChartConfig, type TvChartContextValue, TvChartErrorResetType, TvChartFeature, TvChartHandle, TvChartKlineStyle, TvChartLayout, TvChartPriceType, TvChartQuoteType, type TvChartResolution, type TvChartSymbol, type TvChartSymbolChange, type TvChartSymbolInfo, TvChartTheme, TvChartType, type WidgetConstructor, chartAreasFamily, chartFullscreenFamily, chartLoadingFamily, chartPinnedResolutionsFamily, chartSelectedIndexFamily, chartShowDrawingToolbarFamily, getTvChartLayoutReverse, getTvChartLibraryLayout, getTvChartLibraryLocale, getTvChartLibraryResolution, getTvChartLibraryTheme, getTvChartResolutionFrame, getTvChartResolutionReverse, getTvChartTickTimestamp, parseSymbol, settingsBackgroundColorFamily, settingsChartTypeFamily, settingsDataFamily, settingsDisabledFeaturesFamily, settingsEnabledFeaturesFamily, settingsLayoutFamily, settingsLocaleFamily, settingsReverseColorFamily, settingsStorageIdFamily, settingsThemeFamily, settingsTickerSymbolFamily, settingsTimezoneFamily, stringifySymbol, stringifySymbolShort, useActiveAreaManager, useChartManager, useSymbolInfo, useTvChartContext, useTvChartManager, useTvChartPrefix, useTvChartToolbarContext, widgetReadyFamily };
1057
+ export { ALL_TV_CHART_RESOLUTIONS, type Bar, type CandleSource, ChartAreaManager, type ChartAreaState, ChartDataFeed, ChartLibraryWidget, ChartManager, ChartSaveLoadAdapter, ChartSettings, ChartSettingsAdapter, ChartSettingsStore, ChartSymbolResolver, ChartWidget, ChartWidgetBridge, type ChartingLibraryWidgetOptions, DEFAULT_TV_CHART_MOBILE_BREAKPOINT_PX, DEFAULT_TV_CHART_RESOLUTIONS, ENABLED_TV_CHART_FEATURES, EventEmitter, type HistoryMetaInfo, type IChartWidgetApi, type IChartingLibraryWidget, type ITvChartDataFeedModule, type ITvChartSymbolResolver, type LanguageCode, type LibrarySymbolInfo, type Mark, type PeriodParams, type ResolutionString, SUPPORTED_TV_CHART_LAYOUTS, type SeriesFormatterFactory, type SubscribeBarsCallback, type SymbolResolveExtension, TV_CHART_THEME_COLORS, type ThemeName, type Timezone, TradingView, TradingViewAreaTitle, type TradingViewCandle, TradingViewConfig, type TradingViewConfigProps, TradingViewDatafeedAdapter, type TradingViewDatafeedAdapterOptions, TradingViewFullscreen, type TradingViewHistoryRequest, type TradingViewInstance, TradingViewKlineStyleSelect, TradingViewLayout, type TradingViewLiveSubscribeRequest, TradingViewOpenIndicator, TradingViewOpenSettings, type TradingViewProps, TradingViewProvider, type TradingViewProviderProps, TradingViewResolutions, TradingViewSnapshot, TradingViewToolbar, type TradingViewToolbarProps, TradingViewToolbarProvider, TradingViewWidgetContainer, TradingViewWidgetProvider, type TvChartConfig, type TvChartContextValue, TvChartErrorResetType, TvChartFeature, TvChartHandle, TvChartKlineStyle, TvChartLayout, TvChartPriceType, TvChartQuoteType, type TvChartResolution, type TvChartSymbol, type TvChartSymbolChange, type TvChartSymbolInfo, TvChartTheme, TvChartType, type WidgetConstructor, chartAreasFamily, chartFullscreenFamily, chartLoadingFamily, chartPinnedResolutionsFamily, chartSelectedIndexFamily, chartShowDrawingToolbarFamily, getTvChartLayoutReverse, getTvChartLibraryLayout, getTvChartLibraryLocale, getTvChartLibraryResolution, getTvChartLibraryTheme, getTvChartResolutionFrame, getTvChartResolutionReverse, getTvChartTickTimestamp, isTvChartMobileViewport, parseSymbol, settingsBackgroundColorFamily, settingsChartTypeFamily, settingsDataFamily, settingsDisabledFeaturesFamily, settingsEnabledFeaturesFamily, settingsLayoutFamily, settingsLocaleFamily, settingsReverseColorFamily, settingsStorageIdFamily, settingsThemeFamily, settingsTickerSymbolFamily, settingsTimezoneFamily, stringifySymbol, stringifySymbolShort, useActiveAreaManager, useChartManager, useSymbolInfo, useTvChartContext, useTvChartManager, useTvChartPrefix, useTvChartToolbarContext, widgetReadyFamily };