@christtrade/depth 0.12.21

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.
Files changed (171) hide show
  1. package/LICENSE.md +201 -0
  2. package/NOTICE +15 -0
  3. package/README.md +159 -0
  4. package/depth.cjs +1136 -0
  5. package/depth.css +2 -0
  6. package/depth.mjs +1136 -0
  7. package/depth.nopreflight.css +2 -0
  8. package/index.d.ts +1 -0
  9. package/package.json +32 -0
  10. package/types/ChartInner.d.ts +114 -0
  11. package/types/ChartOuter.d.ts +31 -0
  12. package/types/components/account/AccountSummary.d.ts +8 -0
  13. package/types/components/chart/chart-context-menu.d.ts +30 -0
  14. package/types/components/chart/chart-settings-dialog.d.ts +15 -0
  15. package/types/components/chart/chart-status-overlay.d.ts +24 -0
  16. package/types/components/chart/data-status.d.ts +10 -0
  17. package/types/components/chart/pane-legend.d.ts +37 -0
  18. package/types/components/chart/session-status-badge.d.ts +14 -0
  19. package/types/components/chart/status-bar.d.ts +9 -0
  20. package/types/components/chart/symbol-icon.d.ts +9 -0
  21. package/types/components/chart/tz.d.ts +10 -0
  22. package/types/components/drawings/drawing-icons.d.ts +2 -0
  23. package/types/components/drawings/drawing-settings-bar.d.ts +15 -0
  24. package/types/components/drawings/drawing-settings-dialog.d.ts +268 -0
  25. package/types/components/drawings/drawing-toolbar.d.ts +14 -0
  26. package/types/components/drawings/drawing-tools.d.ts +23 -0
  27. package/types/components/indicators/indicators-dialog.d.ts +20 -0
  28. package/types/components/indicators/indicators-settings-dialog.d.ts +164 -0
  29. package/types/components/multi-chart/GridDividers.d.ts +12 -0
  30. package/types/components/multi-chart/LayoutPicker.d.ts +19 -0
  31. package/types/components/plugin-panels/BottomBarPluginHost.d.ts +7 -0
  32. package/types/components/plugin-panels/PluginFixedPanelHost.d.ts +18 -0
  33. package/types/components/plugin-panels/PluginToolbarHost.d.ts +7 -0
  34. package/types/components/plugin-panels/PluginWindowsDropdown.d.ts +7 -0
  35. package/types/components/plugins/plugin-manager-dialog.d.ts +14 -0
  36. package/types/components/toolbar/SymbolSwitcher.d.ts +8 -0
  37. package/types/components/toolbar/chart-icons.d.ts +16 -0
  38. package/types/components/toolbar/chart-type-selector.d.ts +11 -0
  39. package/types/components/toolbar/timeframe-selector.d.ts +15 -0
  40. package/types/components/trading/OrderPanel.d.ts +36 -0
  41. package/types/components/trading/QuickTradingButtons.d.ts +7 -0
  42. package/types/components/trading/order-math.d.ts +94 -0
  43. package/types/components/ui/button.d.ts +11 -0
  44. package/types/components/ui/checkbox.d.ts +4 -0
  45. package/types/components/ui/color-picker.d.ts +12 -0
  46. package/types/components/ui/dialog.d.ts +19 -0
  47. package/types/components/ui/dropdown-menu.d.ts +27 -0
  48. package/types/components/ui/hover-card.d.ts +6 -0
  49. package/types/components/ui/input.d.ts +4 -0
  50. package/types/components/ui/popover.d.ts +7 -0
  51. package/types/components/ui/resizable.d.ts +23 -0
  52. package/types/components/ui/separator.d.ts +4 -0
  53. package/types/components/ui/slider.d.ts +4 -0
  54. package/types/components/ui/switch.d.ts +4 -0
  55. package/types/components/ui/tooltip.d.ts +7 -0
  56. package/types/core/AccountManager.d.ts +142 -0
  57. package/types/core/ChartModel.d.ts +84 -0
  58. package/types/core/ChartState.d.ts +51 -0
  59. package/types/core/ChartTypeRegistry.d.ts +27 -0
  60. package/types/core/DataEngine.d.ts +143 -0
  61. package/types/core/DataSourceRegistry.d.ts +106 -0
  62. package/types/core/DepthChart.d.ts +458 -0
  63. package/types/core/DrawingRegistry.d.ts +133 -0
  64. package/types/core/DrawingStore.d.ts +26 -0
  65. package/types/core/ExecutionEngine.d.ts +95 -0
  66. package/types/core/GlobalChartBus.d.ts +32 -0
  67. package/types/core/Playback.d.ts +48 -0
  68. package/types/core/PlaybackStateRegistry.d.ts +25 -0
  69. package/types/core/PluginRegistry.d.ts +67 -0
  70. package/types/core/PluginSchedule.d.ts +15 -0
  71. package/types/core/RenderEngine.d.ts +143 -0
  72. package/types/core/ScriptedPlugin.d.ts +153 -0
  73. package/types/core/SessionMapper.d.ts +54 -0
  74. package/types/core/SessionUtils.d.ts +53 -0
  75. package/types/core/TypedEventBus.d.ts +691 -0
  76. package/types/core/WasmPluginHost.d.ts +39 -0
  77. package/types/core/index.d.ts +70 -0
  78. package/types/core/plugin-startup.d.ts +33 -0
  79. package/types/core/processing/data-chunk.d.ts +37 -0
  80. package/types/core/processing/data-level.d.ts +13 -0
  81. package/types/core/processing/l2-processor.d.ts +10 -0
  82. package/types/core/processing/l3-processor.d.ts +26 -0
  83. package/types/core/processing/ohlcv-processor.d.ts +14 -0
  84. package/types/core/processing/tick-processor.d.ts +14 -0
  85. package/types/core/script-dsl.d.ts +20 -0
  86. package/types/core/script-scope.d.ts +4 -0
  87. package/types/core/script.worker.d.ts +1 -0
  88. package/types/hooks/useCellBridges.d.ts +36 -0
  89. package/types/hooks/useChartData.d.ts +153 -0
  90. package/types/hooks/useChartHandlers.d.ts +94 -0
  91. package/types/hooks/useChartInteraction.d.ts +160 -0
  92. package/types/hooks/useChartLayout.d.ts +21 -0
  93. package/types/hooks/useChartPlugin.d.ts +34 -0
  94. package/types/hooks/useChartSettings.d.ts +44 -0
  95. package/types/hooks/useChartSubscriptions.d.ts +64 -0
  96. package/types/hooks/useChartView.d.ts +47 -0
  97. package/types/hooks/usePlaybackEngine.d.ts +85 -0
  98. package/types/hooks/useRenderEngine.d.ts +64 -0
  99. package/types/hooks/useTradeLines.d.ts +80 -0
  100. package/types/hooks/useTradingState.d.ts +135 -0
  101. package/types/interfaces/IAccountAdapter.d.ts +38 -0
  102. package/types/interfaces/ICoordinateTransformer.d.ts +105 -0
  103. package/types/interfaces/IDataAdapter.d.ts +402 -0
  104. package/types/interfaces/IExecutionAdapter.d.ts +71 -0
  105. package/types/interfaces/plugins/IChartPlugin.d.ts +254 -0
  106. package/types/interfaces/plugins/IChartTypePlugin.d.ts +126 -0
  107. package/types/interfaces/plugins/IDataSourcePlugin.d.ts +20 -0
  108. package/types/interfaces/plugins/IDrawingPlugin.d.ts +62 -0
  109. package/types/interfaces/plugins/IIndicatorPlugin.d.ts +97 -0
  110. package/types/interfaces/plugins/index.d.ts +5 -0
  111. package/types/lib/bar-grid.d.ts +6 -0
  112. package/types/lib/book.d.ts +5 -0
  113. package/types/lib/clock.d.ts +7 -0
  114. package/types/lib/compact-buffer.d.ts +66 -0
  115. package/types/lib/constants.d.ts +5 -0
  116. package/types/lib/createSimulatedAdapter.d.ts +42 -0
  117. package/types/lib/dpr.d.ts +27 -0
  118. package/types/lib/heatmap.worker.d.ts +1 -0
  119. package/types/lib/indicator-stdlib.d.ts +426 -0
  120. package/types/lib/indicator-worker.d.ts +65 -0
  121. package/types/lib/matchingEngine.d.ts +144 -0
  122. package/types/lib/notifications/tradeToast.d.ts +31 -0
  123. package/types/lib/pointer-lock.d.ts +5 -0
  124. package/types/lib/priceFormat.d.ts +17 -0
  125. package/types/lib/priceTransition.d.ts +22 -0
  126. package/types/lib/renderers/drawFootprintChart.d.ts +5 -0
  127. package/types/lib/renderers/drawTradeLines.d.ts +112 -0
  128. package/types/lib/renderers/drawings-renderer.d.ts +57 -0
  129. package/types/lib/renderers/renderer.d.ts +113 -0
  130. package/types/lib/sampler.d.ts +7 -0
  131. package/types/lib/series/japaneseCharts.d.ts +88 -0
  132. package/types/lib/slice-worker-client.d.ts +138 -0
  133. package/types/lib/slice.worker.d.ts +139 -0
  134. package/types/lib/storage.d.ts +108 -0
  135. package/types/lib/symbol-info.d.ts +12 -0
  136. package/types/lib/symbol-search.d.ts +29 -0
  137. package/types/lib/timeframes.d.ts +46 -0
  138. package/types/lib/tradingview-import.d.ts +32 -0
  139. package/types/lib/types/chart-settings.d.ts +90 -0
  140. package/types/lib/types/drawing-types.d.ts +393 -0
  141. package/types/lib/types/footprint.d.ts +119 -0
  142. package/types/lib/types/heatmap-types.d.ts +30 -0
  143. package/types/lib/types/index.d.ts +147 -0
  144. package/types/lib/types/indicator-types.d.ts +123 -0
  145. package/types/lib/types/layout-sync.d.ts +43 -0
  146. package/types/lib/types/trading-types.d.ts +323 -0
  147. package/types/lib/use-forwarded-ref.d.ts +1 -0
  148. package/types/lib/utils.d.ts +2 -0
  149. package/types/plugins/alligator.d.ts +1 -0
  150. package/types/plugins/atr.d.ts +1 -0
  151. package/types/plugins/awesome-oscillator.d.ts +1 -0
  152. package/types/plugins/bollinger-bands.d.ts +1 -0
  153. package/types/plugins/cci.d.ts +1 -0
  154. package/types/plugins/cvd.d.ts +1 -0
  155. package/types/plugins/donchian.d.ts +1 -0
  156. package/types/plugins/ichimoku.d.ts +1 -0
  157. package/types/plugins/index.d.ts +25 -0
  158. package/types/plugins/keltner.d.ts +1 -0
  159. package/types/plugins/macd.d.ts +1 -0
  160. package/types/plugins/mfi.d.ts +1 -0
  161. package/types/plugins/moving-average.d.ts +1 -0
  162. package/types/plugins/obv.d.ts +1 -0
  163. package/types/plugins/psar.d.ts +1 -0
  164. package/types/plugins/rsi.d.ts +1 -0
  165. package/types/plugins/sessions.d.ts +1 -0
  166. package/types/plugins/stochastic.d.ts +1 -0
  167. package/types/plugins/supertrend.d.ts +1 -0
  168. package/types/plugins/volume.d.ts +1 -0
  169. package/types/plugins/vwap.d.ts +1 -0
  170. package/types/plugins/williams-r.d.ts +1 -0
  171. package/types/react/useDepthChart.d.ts +6 -0
@@ -0,0 +1,160 @@
1
+ import { type MutableRefObject, type RefObject } from 'react';
2
+ import { type Drawing, type DraftDrawing, type Anchor, DrawingAnchorId, ActiveDrawingTool } from '../lib/types/drawing-types';
3
+ import { type ChartPane, type Indicator, type Rect } from '../lib/types/indicator-types';
4
+ import { type Crosshair } from '../lib/renderers/renderer';
5
+ import { type PluginToolActiveContext } from '../core/DrawingRegistry';
6
+ import type { ChartTypePlugin, ChartTypeActiveContext } from '../core/PluginRegistry';
7
+ import { type RenderEngine } from '../core/RenderEngine';
8
+ import { type TypedEventBus } from '../core/TypedEventBus';
9
+ import { type SessionMapper } from '../core/SessionMapper';
10
+ import { type TradingSession, type DataLevel, type SymbolInfo } from '../interfaces/IDataAdapter';
11
+ import { type LiveTransformer } from '../interfaces/ICoordinateTransformer';
12
+ import { type ViewBounds, type PriceHistory, type TradePoint, type OhlcvBarMs } from '../lib/types';
13
+ import { type FootprintBar } from '../lib/types/footprint';
14
+ import { type ChartSettings } from '../lib/types/chart-settings';
15
+ import { type Timeframe } from '../lib/timeframes';
16
+ import { type BookState } from '../lib/types';
17
+ import { type SerialTrade } from '../lib/types';
18
+ import { type FeaturesOptions } from '../core/DepthChart';
19
+ import { type DomPanelHandle } from '../lib/types';
20
+ type ShiftAnchor = {
21
+ ts: bigint;
22
+ price: number;
23
+ x: number;
24
+ y: number;
25
+ };
26
+ export interface UseChartInteractionParams {
27
+ status: 'loading' | 'ready' | 'error';
28
+ /**
29
+ * This chart cell's id. In a multi-chart layout every cell shares one
30
+ * eventBus, so status:compute emissions are tagged with this id and each
31
+ * StatusBar only reacts to its own cell's events.
32
+ */
33
+ cellId: number;
34
+ baseCanvasRef: RefObject<HTMLCanvasElement>;
35
+ uiCanvasRef: RefObject<HTMLCanvasElement>;
36
+ chartAreaRef: RefObject<HTMLDivElement>;
37
+ containerRef: RefObject<HTMLDivElement>;
38
+ viewRef: MutableRefObject<ViewBounds | null>;
39
+ /** Auto-computed right price-axis width (css px). */
40
+ priceScaleWidthRef: MutableRefObject<number>;
41
+ /** Resolved symbol info - used to derive the instrument tick size. */
42
+ symbolInfoRef: MutableRefObject<SymbolInfo | null>;
43
+ layoutsCacheRef: MutableRefObject<Record<string, Rect>>;
44
+ isYAxisAutoRef: MutableRefObject<boolean>;
45
+ drawingsRef: MutableRefObject<Drawing[]>;
46
+ draftRef: MutableRefObject<DraftDrawing | null>;
47
+ selectedDrawingIdRef: MutableRefObject<string | null>;
48
+ hoveredDrawingIdRef: MutableRefObject<string | null>;
49
+ hotAnchorRef: MutableRefObject<DrawingAnchorId | null>;
50
+ draggingAnchorRef: MutableRefObject<{
51
+ drawingId: string;
52
+ anchor: DrawingAnchorId;
53
+ } | null>;
54
+ dragStartRef: MutableRefObject<{
55
+ x: number;
56
+ y: number;
57
+ } | null>;
58
+ dragPrevDataRef: MutableRefObject<{
59
+ ts: bigint;
60
+ price: number;
61
+ } | null>;
62
+ dragPrevPixelRef: MutableRefObject<{
63
+ x: number;
64
+ y: number;
65
+ } | null>;
66
+ fvpLiveRecalcRef: MutableRefObject<boolean>;
67
+ activeCtxRef: MutableRefObject<PluginToolActiveContext | null>;
68
+ panesRef: MutableRefObject<ChartPane[]>;
69
+ indicatorsRef: MutableRefObject<Indicator[]>;
70
+ draggingDividerRef: MutableRefObject<number>;
71
+ dragPaneIdRef: MutableRefObject<string | null>;
72
+ hoveredDividerIdxRef: MutableRefObject<number>;
73
+ hoveredDividerIdxRefLocked: MutableRefObject<boolean>;
74
+ hoveredPaneIdRef: MutableRefObject<string | null>;
75
+ activeToolRef: MutableRefObject<ActiveDrawingTool>;
76
+ chartSettingsRef: MutableRefObject<ChartSettings>;
77
+ activeTimeframeRef: MutableRefObject<Timeframe>;
78
+ sessionMapperRef: MutableRefObject<SessionMapper>;
79
+ resolvedSessionRef: MutableRefObject<TradingSession | null>;
80
+ renderEngineRef: MutableRefObject<RenderEngine | null>;
81
+ pluginChartTypesRef: MutableRefObject<Map<string, ChartTypePlugin>>;
82
+ activeChartTypeBottomBarIds: MutableRefObject<Set<string>>;
83
+ crosshairRef: MutableRefObject<Crosshair | null>;
84
+ isDragging: MutableRefObject<boolean>;
85
+ dragMode: MutableRefObject<string>;
86
+ isHoldingCtrlRef: MutableRefObject<boolean>;
87
+ isHoldingShiftRef: MutableRefObject<boolean>;
88
+ lastMouse: MutableRefObject<{
89
+ x: number;
90
+ y: number;
91
+ }>;
92
+ hasDragged: MutableRefObject<boolean>;
93
+ longPressTimer: MutableRefObject<ReturnType<typeof setTimeout> | null>;
94
+ showTooltipRef: MutableRefObject<boolean>;
95
+ shiftAnchorRef: MutableRefObject<ShiftAnchor | null>;
96
+ shiftAnchor2Ref: MutableRefObject<ShiftAnchor | null>;
97
+ showShiftInfo: MutableRefObject<boolean>;
98
+ lastStatusLineUpdateRef: MutableRefObject<number>;
99
+ horizonRef: MutableRefObject<bigint>;
100
+ tradesRef: MutableRefObject<TradePoint[]>;
101
+ priceHistoryRef: MutableRefObject<PriceHistory[]>;
102
+ allPriceHistoryRef: MutableRefObject<PriceHistory[]>;
103
+ ohlcvBarsRef: MutableRefObject<{
104
+ barNs: bigint;
105
+ bars: OhlcvBarMs[];
106
+ display: OhlcvBarMs[];
107
+ }>;
108
+ previewBarsRef: MutableRefObject<OhlcvBarMs[]>;
109
+ dataLevelRef: MutableRefObject<DataLevel | null>;
110
+ openBarRef: MutableRefObject<FootprintBar | null>;
111
+ candleCacheRef: MutableRefObject<Map<bigint, any> | null>;
112
+ footprintBarsRef: MutableRefObject<FootprintBar[]>;
113
+ datasetStartRef: MutableRefObject<bigint>;
114
+ datasetEndRef: MutableRefObject<bigint>;
115
+ horizonScrollAnimRef: MutableRefObject<any>;
116
+ liveBookRef: MutableRefObject<BookState>;
117
+ tradeLineInteractionRef: MutableRefObject<any>;
118
+ selectedTradeRef: MutableRefObject<TradePoint | null>;
119
+ transformer: LiveTransformer;
120
+ eventBus: TypedEventBus;
121
+ features: FeaturesOptions;
122
+ showTimeframeWindowRef: MutableRefObject<boolean>;
123
+ setActiveTool: (tool: ActiveDrawingTool) => void;
124
+ setSelectedDrawingId: (id: string | null) => void;
125
+ setSettingsBarPos: (pos: {
126
+ x: number;
127
+ y: number;
128
+ } | null) => void;
129
+ setContextMenu: (ctx: any) => void;
130
+ setPanes: (updater: ((prev: ChartPane[]) => ChartPane[]) | ChartPane[]) => void;
131
+ setChartSettings: (updater: ((prev: ChartSettings) => ChartSettings) | ChartSettings) => void;
132
+ setEditingTextId: (id: string | null) => void;
133
+ setOpenSettingsDialog: (open: boolean) => void;
134
+ setShowTimeframeWindow: (show: boolean) => void;
135
+ setTimeframeWindowInput: (input: string) => void;
136
+ setPendingText: (text: {
137
+ x: number;
138
+ y: number;
139
+ anchor: Anchor;
140
+ } | null) => void;
141
+ pushDrawParams: () => void;
142
+ /** Publish this pane's visible time range to a time/date-range-synced layout. */
143
+ publishTimeRangeSync: () => void;
144
+ scheduleResample: () => void;
145
+ runIndicatorWorker: (trades: SerialTrade[], barNs: bigint) => void;
146
+ getTradesUpToHorizon: (horizon: bigint) => TradePoint[];
147
+ updateSettingsBarPos: (id: string | null) => void;
148
+ handleDeleteDrawing: (id: string) => void;
149
+ autofitPanesSilent: () => void;
150
+ autofitIndicatorPanes: () => void;
151
+ getPanel: () => DomPanelHandle | null;
152
+ getLayouts: () => Record<string, Rect>;
153
+ recomputeLayouts: () => void;
154
+ syncPixelLayouts: (panes?: ChartPane[]) => void;
155
+ applyLayoutsToDom: (layouts: Record<string, Rect>) => void;
156
+ buildChartTypeActiveCtx: () => ChartTypeActiveContext;
157
+ hideTimeScale: boolean;
158
+ }
159
+ export declare function useChartInteraction(p: UseChartInteractionParams): void;
160
+ export {};
@@ -0,0 +1,21 @@
1
+ import { type MutableRefObject, type RefObject } from 'react';
2
+ import { type ChartPane, type Rect } from '../lib/types/indicator-types';
3
+ import { type ChartSettings } from '../lib/types/chart-settings';
4
+ export interface UseChartLayoutParams {
5
+ baseCanvasRef: RefObject<HTMLCanvasElement>;
6
+ panesRef: MutableRefObject<ChartPane[]>;
7
+ chartSettingsRef: MutableRefObject<ChartSettings>;
8
+ /** Auto-computed right price-axis width (css px). */
9
+ priceScaleWidthRef: MutableRefObject<number>;
10
+ hideTimeScale: boolean;
11
+ }
12
+ export interface UseChartLayoutResult {
13
+ layoutsCacheRef: MutableRefObject<Record<string, Rect>>;
14
+ legendElemsRef: MutableRefObject<Map<string, HTMLDivElement>>;
15
+ panePixelLayouts: Record<string, Rect>;
16
+ recomputeLayouts: () => void;
17
+ getLayouts: () => Record<string, Rect>;
18
+ syncPixelLayouts: (nextPanes?: ChartPane[]) => void;
19
+ applyLayoutsToDom: (layouts: Record<string, Rect>) => void;
20
+ }
21
+ export declare function useChartLayout(p: UseChartLayoutParams): UseChartLayoutResult;
@@ -0,0 +1,34 @@
1
+ import { type MutableRefObject } from 'react';
2
+ import { type RenderEngine } from '../core/RenderEngine';
3
+ import { type TypedEventBus } from '../core/TypedEventBus';
4
+ import { type ChartTypePlugin, type ChartTypeActiveContext } from '../core/PluginRegistry';
5
+ import { type ChartPane, type Indicator } from '../lib/types/indicator-types';
6
+ import { type DataLevel } from '../interfaces/IDataAdapter';
7
+ import { type Timeframe } from '../lib/timeframes';
8
+ import { type TradePoint } from '../lib/types';
9
+ export interface UseChartPluginParams {
10
+ renderEngineRef: MutableRefObject<RenderEngine | null>;
11
+ uiCanvasRef: MutableRefObject<HTMLCanvasElement | null>;
12
+ eventBus: TypedEventBus;
13
+ indicatorsRef: MutableRefObject<Indicator[]>;
14
+ panesRef: MutableRefObject<ChartPane[]>;
15
+ horizonRef: MutableRefObject<bigint>;
16
+ activeTimeframeRef: MutableRefObject<Timeframe>;
17
+ dataLevelRef: MutableRefObject<DataLevel | null>;
18
+ setPanes: (updater: ChartPane[] | ((prev: ChartPane[]) => ChartPane[])) => void;
19
+ setIndicators: (inds: Indicator[]) => void;
20
+ runIndicatorWorker: (trades: TradePoint[], barNs: bigint) => void;
21
+ getTradesUpToHorizon: (horizon: bigint) => TradePoint[];
22
+ pushDrawParams: () => void;
23
+ }
24
+ export interface UseChartPluginResult {
25
+ pluginChartTypesRef: MutableRefObject<Map<string, ChartTypePlugin>>;
26
+ activeChartTypeBottomBarIds: MutableRefObject<Set<string>>;
27
+ pluginChartTypes: ChartTypePlugin[];
28
+ setPluginChartTypes: (types: ChartTypePlugin[]) => void;
29
+ pluginChartTypeComputedRef: MutableRefObject<Map<string, unknown>>;
30
+ activatePluginIndicator: (indicator: Indicator, pane?: ChartPane) => void;
31
+ replacePluginIndicator: (indicator: Indicator) => void;
32
+ buildChartTypeActiveCtx: () => ChartTypeActiveContext;
33
+ }
34
+ export declare function useChartPlugin(p: UseChartPluginParams): UseChartPluginResult;
@@ -0,0 +1,44 @@
1
+ import { type MutableRefObject } from 'react';
2
+ import { type ViewBounds, type TradePoint, type PriceHistory, type OhlcvBarMs } from '../lib/types';
3
+ import { type FootprintBar } from '../lib/types/footprint';
4
+ import { type ChartSettings } from '../lib/types/chart-settings';
5
+ import { type DataLevel } from '../interfaces/IDataAdapter';
6
+ import { type RenderEngine } from '../core/RenderEngine';
7
+ import { type CompactBuffer } from '../lib/compact-buffer';
8
+ export interface UseChartSettingsParams {
9
+ chartSettingsRef: MutableRefObject<ChartSettings>;
10
+ isYAxisAutoRef: MutableRefObject<boolean>;
11
+ viewRef: MutableRefObject<ViewBounds | null>;
12
+ priceHistoryRef: MutableRefObject<PriceHistory[]>;
13
+ tradesRef: MutableRefObject<TradePoint[]>;
14
+ dataLevelRef: MutableRefObject<DataLevel | null>;
15
+ ohlcvBarsRef: MutableRefObject<{
16
+ barNs: bigint;
17
+ bars: OhlcvBarMs[];
18
+ display: OhlcvBarMs[];
19
+ }>;
20
+ previewBarsRef: MutableRefObject<OhlcvBarMs[]>;
21
+ openBarRef: MutableRefObject<FootprintBar | null>;
22
+ horizonRef: MutableRefObject<bigint>;
23
+ compactBufRef: MutableRefObject<CompactBuffer>;
24
+ selectedDrawingIdRef: MutableRefObject<string | null>;
25
+ renderEngineRef: MutableRefObject<RenderEngine | null>;
26
+ scheduleResample: () => void;
27
+ rebuildContrastBitmap: (contrast: number) => void;
28
+ requestFootprintRebuild: () => void;
29
+ pushDrawParams: () => void;
30
+ updateSettingsBarPos: (id: string | null) => void;
31
+ hidePriceScale: boolean;
32
+ hideTimeScale: boolean;
33
+ /**
34
+ * This pane's model settings. When they differ from the defaults (i.e. the
35
+ * pane was restored from a save, or already customized), they take precedence
36
+ * over the localStorage fallback as the initial settings.
37
+ */
38
+ modelSettings?: ChartSettings;
39
+ }
40
+ export interface UseChartSettingsResult {
41
+ chartSettings: ChartSettings;
42
+ setChartSettings: (updater: ChartSettings | ((prev: ChartSettings) => ChartSettings)) => void;
43
+ }
44
+ export declare function useChartSettings(p: UseChartSettingsParams): UseChartSettingsResult;
@@ -0,0 +1,64 @@
1
+ import { type MutableRefObject } from 'react';
2
+ import { type ChartTypePlugin, type ChartTypeActiveContext } from '../core/PluginRegistry';
3
+ import { type AccountManager } from '../core/AccountManager';
4
+ import { type RenderEngine } from '../core/RenderEngine';
5
+ import { type TypedEventBus } from '../core/TypedEventBus';
6
+ import { type ChartPane, type Indicator } from '../lib/types/indicator-types';
7
+ import { type ChartSettings } from '../lib/types/chart-settings';
8
+ import { type TradePoint, type OhlcvBarMs, type ViewBounds } from '../lib/types';
9
+ import { type DataLevel } from '../interfaces/IDataAdapter';
10
+ import { type FootprintBar } from '../lib/types/footprint';
11
+ import { type SerialTrade } from '../lib/types';
12
+ import { type TradeLineHitMap } from '../lib/renderers/drawTradeLines';
13
+ import { type Timeframe } from '../lib/timeframes';
14
+ import { type CrosshairSync, type SyncInLayout, type TimeRangeSync } from '../lib/types/layout-sync';
15
+ export interface UseChartSubscriptionsParams {
16
+ eventBus: TypedEventBus;
17
+ chartId: number;
18
+ account: AccountManager;
19
+ pluginChartTypesRef: MutableRefObject<Map<string, ChartTypePlugin>>;
20
+ activeChartTypeBottomBarIds: MutableRefObject<Set<string>>;
21
+ hitMapRef: MutableRefObject<TradeLineHitMap>;
22
+ indicatorsRef: MutableRefObject<Indicator[]>;
23
+ panesRef: MutableRefObject<ChartPane[]>;
24
+ renderEngineRef: MutableRefObject<RenderEngine | null>;
25
+ horizonRef: MutableRefObject<bigint>;
26
+ activeTimeframeRef: MutableRefObject<Timeframe>;
27
+ chartSettingsRef: MutableRefObject<ChartSettings>;
28
+ pluginChartTypeComputedRef: MutableRefObject<Map<string, unknown>>;
29
+ dataLevelRef: MutableRefObject<DataLevel | null>;
30
+ previewBarsRef: MutableRefObject<OhlcvBarMs[]>;
31
+ candleCacheRef: MutableRefObject<Map<bigint, any> | null>;
32
+ ohlcvBarsRef: MutableRefObject<{
33
+ barNs: bigint;
34
+ bars: OhlcvBarMs[];
35
+ display: OhlcvBarMs[];
36
+ }>;
37
+ openBarRef: MutableRefObject<FootprintBar | null>;
38
+ viewRef: MutableRefObject<ViewBounds | null>;
39
+ accountSnapRef: MutableRefObject<any>;
40
+ setActiveTool: (tool: any) => void;
41
+ setActiveTimeframe: (tf: Timeframe) => void;
42
+ handleTimeframeChange: (tf: Timeframe) => void;
43
+ setPanes: (updater: ChartPane[] | ((prev: ChartPane[]) => ChartPane[])) => void;
44
+ setIndicators: (inds: Indicator[]) => void;
45
+ setPluginChartTypes: (types: ChartTypePlugin[]) => void;
46
+ setChartSettings: (updater: ChartSettings | ((prev: ChartSettings) => ChartSettings)) => void;
47
+ resetView: () => void;
48
+ buildChartTypeActiveCtx: () => ChartTypeActiveContext;
49
+ pushDrawParams: () => void;
50
+ runIndicatorWorker: (trades: SerialTrade[], barNs: bigint) => void;
51
+ getTradesUpToHorizon: (horizon: bigint) => TradePoint[];
52
+ syncPixelLayouts: (panes?: ChartPane[]) => void;
53
+ autofitIndicatorPanes: () => void;
54
+ handleAddIndicator: (id: string) => void;
55
+ handleRemoveIndicator: (id: string) => void;
56
+ onSymbolChange: (symbol: string) => void;
57
+ /** This layout's live sync switches (a ref: the handlers outlive a render). */
58
+ syncInLayoutRef: MutableRefObject<SyncInLayout>;
59
+ /** Take (or drop) the crosshair another cell is broadcasting. */
60
+ applyCrosshairSync: (sync: CrosshairSync | null) => void;
61
+ /** Follow another cell's time axis. */
62
+ applyTimeRangeSync: (sync: TimeRangeSync) => void;
63
+ }
64
+ export declare function useChartSubscriptions(p: UseChartSubscriptionsParams): void;
@@ -0,0 +1,47 @@
1
+ import { type MutableRefObject } from 'react';
2
+ import { type ViewBounds, type TradePoint, type PriceHistory, type OhlcvBarMs } from '../lib/types';
3
+ import { type ChartSettings } from '../lib/types/chart-settings';
4
+ import { type DataLevel } from '../interfaces/IDataAdapter';
5
+ import { type RenderEngine } from '../core/RenderEngine';
6
+ import { type ChartPane, type Indicator } from '../lib/types/indicator-types';
7
+ import { FootprintBar } from '../core';
8
+ export interface UseChartViewParams {
9
+ viewRef: MutableRefObject<ViewBounds | null>;
10
+ transformer: import('../interfaces/ICoordinateTransformer').LiveTransformer;
11
+ isYAxisAutoRef: MutableRefObject<boolean>;
12
+ setChartSettings: (updater: ChartSettings | ((prev: ChartSettings) => ChartSettings)) => void;
13
+ priceHistoryRef: MutableRefObject<PriceHistory[]>;
14
+ tradesRef: MutableRefObject<TradePoint[]>;
15
+ previewBarsRef: MutableRefObject<OhlcvBarMs[]>;
16
+ ohlcvBarsRef: MutableRefObject<{
17
+ barNs: bigint;
18
+ bars: OhlcvBarMs[];
19
+ display: OhlcvBarMs[];
20
+ }>;
21
+ openBarRef: MutableRefObject<FootprintBar>;
22
+ chartSettingsRef: MutableRefObject<ChartSettings>;
23
+ horizonRef: MutableRefObject<bigint>;
24
+ dataLevelRef: MutableRefObject<DataLevel | null>;
25
+ activeTimeframeRef: MutableRefObject<{
26
+ barNs: bigint;
27
+ label?: string;
28
+ }>;
29
+ scheduleResample: () => void;
30
+ pushDrawParams: () => void;
31
+ /** Publish this pane's visible time range to a time/date-range-synced layout. */
32
+ publishTimeRangeSync: () => void;
33
+ renderEngineRef: MutableRefObject<RenderEngine | null>;
34
+ updateSettingsBarPos: (id: string | null) => void;
35
+ selectedDrawingIdRef: MutableRefObject<string | null>;
36
+ panesRef: MutableRefObject<ChartPane[]>;
37
+ indicatorsRef: MutableRefObject<Indicator[]>;
38
+ setPanes: (updater: ChartPane[] | ((prev: ChartPane[]) => ChartPane[])) => void;
39
+ }
40
+ export interface UseChartViewResult {
41
+ resetYAxis: (setPersistent?: boolean) => void;
42
+ resetXAxis: () => void;
43
+ resetView: () => void;
44
+ autofitPanesSilent: () => void;
45
+ autofitIndicatorPanes: () => void;
46
+ }
47
+ export declare function useChartView(p: UseChartViewParams): UseChartViewResult;
@@ -0,0 +1,85 @@
1
+ import { TypedEventBus } from '../core';
2
+ export declare const BASE_REDRAW_INTERVAL_MS = 100;
3
+ export declare const DEFAULT_STEP_NS = 5000000000n;
4
+ /** Parse a step-size token into nanoseconds. Unknown tokens fall back to 5s. */
5
+ export declare function stepSizeToNs(stepSize: string): bigint;
6
+ export type PlaybackStatus = 'paused' | 'playing';
7
+ export type PlaybackMode = 'step' | 'realtime';
8
+ export type PlaybackState = {
9
+ mode: PlaybackMode;
10
+ status: PlaybackStatus;
11
+ /** Step mode only: snap the horizon to step-size boundaries when advancing. */
12
+ stepSnap: boolean;
13
+ speed: number;
14
+ stepSize: string;
15
+ wallStart: number;
16
+ dataStart: bigint;
17
+ datasetStart: bigint;
18
+ /** Left edge of the *currently loaded* window (moves when we jump-load). */
19
+ loadedStart: bigint;
20
+ dataEnd: bigint;
21
+ rafHandle: number;
22
+ lastBaseRedrawWall: number;
23
+ _stallStart: number | undefined;
24
+ _lastRafTime: number | undefined;
25
+ };
26
+ export type PlaybackUi = {
27
+ mode: PlaybackMode;
28
+ status: PlaybackStatus;
29
+ stepSnap: boolean;
30
+ speed: number;
31
+ stepSize: string;
32
+ datasetStart: bigint;
33
+ datasetEnd: bigint;
34
+ };
35
+ export type PlaybackChartHandle = {
36
+ /**
37
+ * `recenter` = this move was asked for (Go to, a step past the view edge),
38
+ * so the pane should bring its view along. Playback's per-tick follow is the
39
+ * pane's own business and doesn't set it.
40
+ */
41
+ seekHorizon: (t: bigint, recenter?: boolean) => void;
42
+ };
43
+ export interface PrefetchOptions {
44
+ /**
45
+ * Prefetch the next chunk when the estimated time to reach the loaded edge
46
+ * drops below `measuredLoadLatency x safetyFactor`. Higher = more lead.
47
+ * Default 2.5.
48
+ */
49
+ safetyFactor?: number;
50
+ /** Always keep at least this much wall-time of lead, in ms. Default 300. */
51
+ minLeadMs?: number;
52
+ }
53
+ interface UsePlaybackEngineOptions {
54
+ chartRefs: React.MutableRefObject<(PlaybackChartHandle | null)[]>;
55
+ sharedHorizonRef: React.MutableRefObject<bigint>;
56
+ /** Request a forward chunk; `spanNs` is the desired data-time span to fetch. */
57
+ onRequestMore?: (spanNs?: bigint) => void;
58
+ onTick?: (tNs: bigint) => void;
59
+ eventBus: TypedEventBus;
60
+ prefetch?: PrefetchOptions;
61
+ /**
62
+ * The symbol whose data gates the clock - in a layout, the focused pane's.
63
+ * Data events carrying any other symbol are somebody else's pane and must
64
+ * not stop playback. Omit (or return undefined) to accept everything, which
65
+ * is what a single-symbol host wants.
66
+ */
67
+ clockSymbol?: () => string | undefined;
68
+ }
69
+ export declare function usePlaybackEngine({ chartRefs, sharedHorizonRef, onRequestMore, onTick, eventBus, prefetch, clockSymbol, }: UsePlaybackEngineOptions): {
70
+ readonly ui: PlaybackUi;
71
+ readonly notifyDataBounds: (datasetStart: bigint, dataEnd: bigint) => void;
72
+ readonly play: () => void;
73
+ readonly pause: () => void;
74
+ readonly stepForward: () => void;
75
+ readonly stepBack: () => void;
76
+ readonly jumpToStart: () => void;
77
+ readonly jumpToEnd: () => void;
78
+ readonly setSpeed: (s: number) => void;
79
+ readonly setStepSize: (s: string) => void;
80
+ readonly setMode: (mode: PlaybackMode) => void;
81
+ readonly setStepSnap: (snap: boolean) => void;
82
+ readonly scrub: (t: bigint) => void;
83
+ readonly pbRef: import("react").MutableRefObject<PlaybackState>;
84
+ };
85
+ export {};
@@ -0,0 +1,64 @@
1
+ import { type MutableRefObject, type RefObject } from 'react';
2
+ import { RenderEngine } from '../core/RenderEngine';
3
+ import { type TypedEventBus } from '../core/TypedEventBus';
4
+ import { type ViewBounds, type TradePoint, type PriceHistory, type OhlcvBarMs } from '../lib/types';
5
+ import { type ChartPane, type Indicator, type Rect } from '../lib/types/indicator-types';
6
+ import { type FootprintBar } from '../lib/types/footprint';
7
+ import { type ChartSettings } from '../lib/types/chart-settings';
8
+ import { type DataLevel } from '../interfaces/IDataAdapter';
9
+ import { type LiveTransformer } from '../interfaces/ICoordinateTransformer';
10
+ type HeatmapBitmapOffsets = {
11
+ x: number;
12
+ y: number;
13
+ w: number;
14
+ h: number;
15
+ };
16
+ type CacheBounds = {
17
+ tMin: bigint;
18
+ tMax: bigint;
19
+ pMin: number;
20
+ pMax: number;
21
+ };
22
+ export interface UseRenderEngineParams {
23
+ renderEngineRef: MutableRefObject<RenderEngine | null>;
24
+ baseCanvasRef: RefObject<HTMLCanvasElement>;
25
+ drawingsCanvasRef: RefObject<HTMLCanvasElement>;
26
+ uiCanvasRef: RefObject<HTMLCanvasElement>;
27
+ eventBus: TypedEventBus;
28
+ /** Which cell of the layout this chart is - stamped onto bus events so the
29
+ * other cells can tell our repaints from theirs. */
30
+ chartId: number;
31
+ viewRef: MutableRefObject<ViewBounds | null>;
32
+ /** Auto-computed right price-axis width (css px). */
33
+ priceScaleWidthRef: MutableRefObject<number>;
34
+ tradesRef: MutableRefObject<TradePoint[]>;
35
+ getLayouts: () => Record<string, Rect>;
36
+ heatmapBitmapRef: MutableRefObject<ImageBitmap | null>;
37
+ cacheBoundsRef: MutableRefObject<CacheBounds | null>;
38
+ heatmapBitmapOffsetsRef: MutableRefObject<HeatmapBitmapOffsets>;
39
+ panesRef: MutableRefObject<ChartPane[]>;
40
+ indicatorsRef: MutableRefObject<Indicator[]>;
41
+ priceHistoryRef: MutableRefObject<PriceHistory[]>;
42
+ footprintBarsRef: MutableRefObject<FootprintBar[]>;
43
+ activeTimeframeRef: MutableRefObject<{
44
+ barNs: bigint;
45
+ }>;
46
+ chartSettingsRef: MutableRefObject<ChartSettings>;
47
+ horizonRef: MutableRefObject<bigint>;
48
+ candleCacheRef: MutableRefObject<Map<bigint, any> | null>;
49
+ openBarRef: MutableRefObject<FootprintBar | null>;
50
+ dataLevelRef: MutableRefObject<DataLevel | null>;
51
+ ohlcvBarsRef: MutableRefObject<{
52
+ barNs: bigint;
53
+ bars: OhlcvBarMs[];
54
+ display: OhlcvBarMs[];
55
+ }>;
56
+ previewBarsRef: MutableRefObject<OhlcvBarMs[]>;
57
+ transformer: LiveTransformer;
58
+ hideTimeScale: boolean;
59
+ }
60
+ export interface UseRenderEngineResult {
61
+ doBaseRedraw: () => void;
62
+ }
63
+ export declare function useRenderEngine(p: UseRenderEngineParams): UseRenderEngineResult;
64
+ export {};
@@ -0,0 +1,80 @@
1
+ import type { TradeLine, ViewBounds } from '../lib/types';
2
+ import { type TradeLineHitMap, type GhostInteractionState } from '../lib/renderers/drawTradeLines';
3
+ import type { ChartSettings } from '../lib/types/chart-settings';
4
+ import { LiveTransformer, type SymbolInfo } from '../core';
5
+ import { Rect } from '../lib/types/indicator-types';
6
+ type CursorStyle = 'default' | 'ns-resize' | 'pointer' | 'grab' | 'grabbing' | 'not-allowed';
7
+ interface UseTradeLines {
8
+ tradeLines: TradeLine[];
9
+ onLinesChange: (lines: TradeLine[]) => void;
10
+ onSyncLines: (lines: TradeLine[]) => void;
11
+ onLineDelete: (line: TradeLine) => void;
12
+ hitMapRef: React.MutableRefObject<TradeLineHitMap>;
13
+ chartWRef: React.MutableRefObject<number>;
14
+ chartHRef: React.MutableRefObject<number>;
15
+ /** Y offset (CSS px) of the main chart pane from the top of the canvas. Non-zero when indicator panes sit above the main area. */
16
+ chartOYRef?: React.MutableRefObject<number>;
17
+ getLayouts: () => Record<string, Rect>;
18
+ boundsRef: React.MutableRefObject<ViewBounds>;
19
+ chartSettingsRef: React.MutableRefObject<ChartSettings>;
20
+ redraw: () => void;
21
+ /** Resolved symbol info - the instrument tick size for price snapping is derived from it. */
22
+ symbolInfoRef?: React.MutableRefObject<SymbolInfo | null>;
23
+ /**
24
+ * Optional ref to the canonical lines map from useTradingState.
25
+ * When provided, line price updates during drag are written directly into
26
+ * this map (no React state update) so the canvas sees fresh values on
27
+ * every animation frame without triggering re-renders.
28
+ */
29
+ linesRef?: React.MutableRefObject<Map<string, TradeLine>>;
30
+ /** Live lookup for lines that bypass React state. See `findLine`. */
31
+ resolveLine?: (id: string) => TradeLine | undefined;
32
+ /**
33
+ * Shared with useTradingState. We write the active line id here on drag
34
+ * start and clear it on drag end, so line rebuilds (e.g. from playback
35
+ * ticks) know to preserve the line currently under the cursor.
36
+ */
37
+ draggingLineIdRef?: React.MutableRefObject<string | null>;
38
+ transformer: LiveTransformer;
39
+ /**
40
+ * Called when the user finishes dragging a ghost TP/SL pill (mouseup).
41
+ * lineId - the entry line this ghost belongs to (e.g. "position:abc123")
42
+ * kind - 'tp' | 'sl'
43
+ * index - 0-based slot index
44
+ * price - final price (snapped to tickSize)
45
+ */
46
+ onGhostMove?: (lineId: string, kind: 'tp' | 'sl', index: number, price: number) => void;
47
+ }
48
+ interface UseTradeLinesReturn {
49
+ hoveredLineId: string | null;
50
+ draggingLineId: string | null;
51
+ /** Last computed cursor. One render behind - for rendering, not for reading
52
+ * inside a pointer handler; use `cursorRef` there. */
53
+ cursor: CursorStyle;
54
+ /**
55
+ * The same value, written synchronously.
56
+ *
57
+ * The chart's own mousemove handler runs `onMouseMove` and then decides, in
58
+ * that same tick, whether the trade lines have claimed the cursor. Reading
59
+ * React state there is always one event stale, which is worst exactly when
60
+ * it matters: move onto a line and stop, and the state set by that last
61
+ * event has no following event to apply it - the pointer keeps the chart's
62
+ * crosshair until you jiggle the mouse.
63
+ */
64
+ cursorRef: React.MutableRefObject<CursorStyle>;
65
+ /**
66
+ * Returns the current ghost interaction state.
67
+ * Call this inside your redraw callback - it reads from the ref so it is
68
+ * always up-to-date without needing React state.
69
+ */
70
+ getGhostState: () => GhostInteractionState;
71
+ onMouseMove: (e: React.MouseEvent<HTMLCanvasElement>) => void;
72
+ onMouseDown: (e: React.MouseEvent<HTMLCanvasElement>) => void;
73
+ onMouseUp: (e: React.MouseEvent<HTMLCanvasElement>) => void;
74
+ onMouseLeave: (e: React.MouseEvent<HTMLCanvasElement>) => void;
75
+ onContextMenu: (e: React.MouseEvent<HTMLCanvasElement>) => void;
76
+ onDoubleClick: (e: React.MouseEvent<HTMLCanvasElement>) => void;
77
+ onClick: (e: React.MouseEvent<HTMLCanvasElement>) => void;
78
+ }
79
+ export declare function useTradeLines({ tradeLines, onLinesChange, onSyncLines, onLineDelete, hitMapRef, chartWRef, chartHRef, chartOYRef, getLayouts, boundsRef, chartSettingsRef, redraw, symbolInfoRef, onGhostMove, linesRef, resolveLine, draggingLineIdRef, transformer, }: UseTradeLines): UseTradeLinesReturn;
80
+ export {};