@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,95 @@
1
+ import { IExecutionAdapter } from '../interfaces/IExecutionAdapter';
2
+ import type { PlaceOrderRequest, FillSearchOptions, FillAmbiguity } from '../lib/matchingEngine';
3
+ import { L3MatchingEngine } from '../lib/matchingEngine';
4
+ import type { TypedEventBus } from './TypedEventBus';
5
+ import type { BracketAmendment, Order, Position } from '../lib/types/trading-types';
6
+ import type { MboEvent, PriceHistory } from '../lib/types';
7
+ import type { OhlcvBar } from '../interfaces/IDataAdapter';
8
+ import type { SerialTrade } from '../lib/types';
9
+ /**
10
+ * Vetoes an order before it reaches a book. Return a reason to refuse it, or
11
+ * null to let it through. Pre-trade risk lives here rather than in the caller,
12
+ * since every order route lands on placeOrder and there are several.
13
+ */
14
+ export type OrderGuard = (req: PlaceOrderRequest) => string | null;
15
+ export declare class ExecutionEngine {
16
+ private builtIns;
17
+ private activeSymbol;
18
+ private custom;
19
+ private destroyed;
20
+ private guard;
21
+ private eventBus;
22
+ private fillSearch;
23
+ attachBuiltIn(engine: L3MatchingEngine, symbol: string): void;
24
+ setFillSearch(patch: Partial<FillSearchOptions>): void;
25
+ getFillSearch(): FillSearchOptions;
26
+ hasPendingTriggers(symbol?: string): boolean;
27
+ settleGapBars(bars: Array<{
28
+ tsNs: bigint;
29
+ open: number;
30
+ high: number;
31
+ low: number;
32
+ close: number;
33
+ }>, ambiguity?: FillAmbiguity, symbol?: string): void;
34
+ detachBuiltIn(symbol: string): void;
35
+ /**
36
+ * Switch the active symbol - the default target for calls that don't name
37
+ * one. In a layout this follows the focused pane, so a plugin calling
38
+ * `placeOrder` with no symbol lands on the chart the user is looking at.
39
+ */
40
+ setActiveSymbol(symbol: string): void;
41
+ /** The instrument symbol-less calls currently resolve to. */
42
+ getActiveSymbol(): string;
43
+ /**
44
+ * Last traded price for a symbol. NaN when the book has no price yet - no
45
+ * such instrument, or its data hasn't landed. Callers that act on the number
46
+ * must check `Number.isFinite` first.
47
+ */
48
+ getCurrentPrice(symbol: string): number;
49
+ /** Whether a book can price an order right now. */
50
+ hasPrice(symbol?: string): boolean;
51
+ setCustomAdapter(adapter: IExecutionAdapter | null): void;
52
+ private builtInFor;
53
+ private targetFor;
54
+ private eachBuiltIn;
55
+ ingestCompactBuf(buf: ArrayBuffer, symbol?: string): void;
56
+ ingestOhlcvBars(bars: OhlcvBar[], barNs?: bigint, symbol?: string): void;
57
+ appendOhlcvBars(bars: OhlcvBar[], barNs?: bigint, symbol?: string): void;
58
+ ingestSupplementalBars(bars: Array<{
59
+ time: number;
60
+ open: number;
61
+ high: number;
62
+ low: number;
63
+ close: number;
64
+ volume: number;
65
+ }>, symbol?: string): void;
66
+ appendSupplementalBars(bars: Array<{
67
+ time: number;
68
+ open: number;
69
+ high: number;
70
+ low: number;
71
+ close: number;
72
+ volume: number;
73
+ }>, symbol?: string): void;
74
+ ingestTicks(trades: SerialTrade[], symbol?: string): void;
75
+ ingestPriceHistory(history: PriceHistory[], symbol?: string): void;
76
+ appendTicks(trades: SerialTrade[], symbol?: string): void;
77
+ appendPriceHistory(history: PriceHistory[], symbol?: string): void;
78
+ appendCompactBuf(buf: ArrayBuffer, symbol?: string): void;
79
+ seekTo(tNs: bigint, symbol?: string): void;
80
+ onMboEvent(event: MboEvent, tsNs: bigint, symbol?: string): void;
81
+ /** Refused orders emit `trading:order-blocked` and never reach a book. */
82
+ setOrderGuard(guard: OrderGuard | null): void;
83
+ setEventBus(eventBus: TypedEventBus | null): void;
84
+ placeOrder(req: PlaceOrderRequest): string | Promise<string> | undefined;
85
+ cancelOrder(orderId: string): void;
86
+ amendOrder(orderId: string, newPrice: number): void;
87
+ amendBracket(amendment: BracketAmendment): void;
88
+ closePosition(positionId: string): void;
89
+ reversePosition(positionId: string): void;
90
+ syncPosition(position: Position): void;
91
+ syncOrder(order: Order): void;
92
+ totalFeesPaid(): number;
93
+ totalRealizedPnl(): number;
94
+ destroy(): void;
95
+ }
@@ -0,0 +1,32 @@
1
+ import type { DepthChart } from './DepthChart';
2
+ export type GlobalEventMap = {
3
+ 'global:chart-registered': {
4
+ id: string;
5
+ chart: DepthChart;
6
+ };
7
+ 'global:chart-unregistered': {
8
+ id: string;
9
+ };
10
+ 'global:focus-changed': {
11
+ chartId: string | null;
12
+ };
13
+ [key: string]: unknown;
14
+ };
15
+ export type GlobalHandler<T = unknown> = (data: T) => void;
16
+ export declare class GlobalChartBus {
17
+ private readonly handlers;
18
+ private readonly charts;
19
+ private focusedChartId;
20
+ registerChart(chart: DepthChart): void;
21
+ unregisterChart(id: string): void;
22
+ setFocus(chartId: string): void;
23
+ getChart(id: string): DepthChart | null;
24
+ getCharts(): ReadonlyMap<string, DepthChart>;
25
+ getFocusedChartId(): string | null;
26
+ on<K extends keyof GlobalEventMap>(event: K, handler: GlobalHandler<GlobalEventMap[K]>): () => void;
27
+ emit<K extends keyof GlobalEventMap>(event: K, data: GlobalEventMap[K]): void;
28
+ once<K extends keyof GlobalEventMap>(event: K, handler: GlobalHandler<GlobalEventMap[K]>): () => void;
29
+ broadcastTo<K extends keyof import('./TypedEventBus').ChartEvents>(chartId: string, event: K, data: import('./TypedEventBus').ChartEvents[K]): void;
30
+ broadcastAll<K extends keyof import('./TypedEventBus').ChartEvents>(event: K, data: import('./TypedEventBus').ChartEvents[K]): void;
31
+ }
32
+ export declare const globalChartBus: GlobalChartBus;
@@ -0,0 +1,48 @@
1
+ import { PlaybackMode } from '../hooks/usePlaybackEngine';
2
+ import { TypedEventBus } from './TypedEventBus';
3
+ export declare function toNs(t: bigint | number | Date | string): bigint;
4
+ export declare class PlaybackController {
5
+ private eventBus;
6
+ private isPlaying;
7
+ private currentStepSize;
8
+ private currentSpeed;
9
+ private currentMode;
10
+ private currentStepSnap;
11
+ private currentTime;
12
+ private forwardOnly;
13
+ private floorNs;
14
+ private subscriptions;
15
+ constructor(eventBus: TypedEventBus, initialTimeNs?: bigint);
16
+ play(): void;
17
+ pause(): void;
18
+ playing(): boolean;
19
+ stepSize(): string;
20
+ setStepSize(step: string): void;
21
+ mode(): PlaybackMode;
22
+ setMode(mode: PlaybackMode): void;
23
+ stepSnap(): boolean;
24
+ setStepSnap(snap: boolean): void;
25
+ speed(): number;
26
+ setSpeed(speed: number): void;
27
+ /**
28
+ * Refuse any move that would put the playhead behind where it has already
29
+ * been. The floor starts wherever it is when the lock goes on.
30
+ */
31
+ lockForward(on: boolean): void;
32
+ /** The earliest time the playhead may move to, or null when unlocked. */
33
+ floor(): bigint | null;
34
+ allows(tNs: bigint): boolean;
35
+ private refuse;
36
+ stepBack(): void;
37
+ stepForward(): void;
38
+ /** Where the playhead currently is, in epoch ns. */
39
+ time(): bigint;
40
+ /**
41
+ * Jump the playhead anywhere, pausing first. The target may sit outside the
42
+ * loaded window, in which case the engine streams or re-centers to reach it,
43
+ * and it clamps to the last available bar if the data runs out.
44
+ */
45
+ goTo(t: bigint | number | Date | string): void;
46
+ subscribeToEvents(): void;
47
+ destroy(): void;
48
+ }
@@ -0,0 +1,25 @@
1
+ import type { TypedEventBus } from './TypedEventBus';
2
+ export interface PluginStateSnapshot {
3
+ serialize(): unknown;
4
+ restore(state: unknown): void;
5
+ }
6
+ export declare class PlaybackStateRegistry {
7
+ private readonly eventBus;
8
+ private readonly plugins;
9
+ private readonly checkpoints;
10
+ private lastCheckpointNs;
11
+ private currentHorizonNs;
12
+ private readonly intervalNs;
13
+ private readonly unsubs;
14
+ constructor(eventBus: TypedEventBus, opts?: {
15
+ intervalNs?: bigint;
16
+ });
17
+ register(pluginId: string, snapshot: PluginStateSnapshot): () => void;
18
+ onHorizonAdvance(horizonNs: bigint): void;
19
+ private _snapshot;
20
+ restoreToNearest(targetNs: bigint): bigint | null;
21
+ private _resetAll;
22
+ private _wire;
23
+ getCheckpointCount(): number;
24
+ destroy(): void;
25
+ }
@@ -0,0 +1,67 @@
1
+ import { RenderEngine } from './RenderEngine';
2
+ import { TypedEventBus } from './TypedEventBus';
3
+ export interface PluginIcon {
4
+ viewBox: string;
5
+ paths: string[];
6
+ }
7
+ export type { PluginType, Permission, ToolbarItem, BottomBarItem, BottomBarHandle, FloatingPanelOpts, ContextMenuItem, ThemeDef, SettingSchema, SettingSchemaType, PluginStorage, ServiceApi, ServiceObserver, PluginServices, PluginSchedule, NotifyLevel, NotifyOptions, PluginStateSnapshot, PluginExecutionSurface, PluginLifecycle, PaneOptions, PluginDataSnapshot, PluginContext, ChartPlugin, PluginManifest, } from '../interfaces/plugins/IChartPlugin';
8
+ export type { DrawingPlugin } from '../interfaces/plugins/IDrawingPlugin';
9
+ export type { ChartTypePlugin, ChartTypeRenderContext, ChartTypeActiveContext, ChartTypePointerEvent, ChartTypeKeyEvent, } from '../interfaces/plugins/IChartTypePlugin';
10
+ export type { DataSourcePlugin } from '../interfaces/plugins/IDataSourcePlugin';
11
+ export type { IndicatorPlugin } from '../interfaces/plugins/IIndicatorPlugin';
12
+ import type { ChartPlugin, PluginContext, PluginLifecycle, PluginServices } from '../interfaces/plugins/IChartPlugin';
13
+ /**
14
+ * A pooled plugin as persisted in a save document. The id is kept so a restore
15
+ * re-installs under the same one, and a host that also installs the plugin
16
+ * manually dedups against the restored copy rather than accumulating duplicates.
17
+ */
18
+ export interface InstalledPlugin {
19
+ id: string;
20
+ code: string;
21
+ }
22
+ export declare class PluginRegistry {
23
+ private installed;
24
+ private readonly serviceRegistry;
25
+ private readonly serviceListeners;
26
+ private pendingInstalls;
27
+ private renderEngineReady;
28
+ private eventBus;
29
+ options: {
30
+ enabled: boolean;
31
+ indicator: boolean;
32
+ drawing: boolean;
33
+ 'chart-type': boolean;
34
+ extension: boolean;
35
+ };
36
+ setOptions(options: {
37
+ enabled: boolean;
38
+ indicators: boolean;
39
+ drawings: boolean;
40
+ charts: boolean;
41
+ extensions: boolean;
42
+ }): void;
43
+ setEventBus(bus: TypedEventBus): void;
44
+ /**
45
+ * Is this id installed, or queued for install? Install is async - a plugin
46
+ * registered before the RenderEngine attaches sits in pendingInstalls, and
47
+ * callers have to treat that as installed or they double-install it.
48
+ */
49
+ has(id: string): boolean;
50
+ /** Ids of every installed / pending plugin. */
51
+ getInstalledIds(): string[];
52
+ /** Name and type of every installed / pending plugin, for a manager UI. */
53
+ getInstalledPlugins(): Array<{
54
+ id: string;
55
+ name: string;
56
+ type: ChartPlugin['type'];
57
+ }>;
58
+ register(plugin: ChartPlugin, ctx: PluginContext): Promise<void>;
59
+ notifyRenderEngineReady(engine: RenderEngine): void;
60
+ buildLifecycle(eventBus: TypedEventBus): PluginLifecycle;
61
+ private _doInstall;
62
+ buildServices(pluginId: string): PluginServices;
63
+ private buildRestrictedContext;
64
+ serialize(): InstalledPlugin[];
65
+ unregister(id: string): void;
66
+ destroy(): void;
67
+ }
@@ -0,0 +1,15 @@
1
+ export interface PluginSchedule {
2
+ interval(ms: number, fn: () => void): () => void;
3
+ timeout(ms: number, fn: () => void): () => void;
4
+ raf(fn: () => void): () => void;
5
+ }
6
+ export declare class PluginScheduleImpl implements PluginSchedule {
7
+ private readonly intervals;
8
+ private readonly timeouts;
9
+ private readonly rafIds;
10
+ private destroyed;
11
+ interval(ms: number, fn: () => void): () => void;
12
+ timeout(ms: number, fn: () => void): () => void;
13
+ raf(fn: () => void): () => void;
14
+ destroy(): void;
15
+ }
@@ -0,0 +1,143 @@
1
+ import { TypedEventBus } from './TypedEventBus';
2
+ import type { ChartPane, Rect } from '../lib/types/indicator-types';
3
+ import type { Indicator } from '../lib/types/indicator-types';
4
+ import type { TradePoint, PriceHistory, ViewBounds } from '../lib/types';
5
+ import type { FootprintBar } from '../lib/types/footprint';
6
+ import type { ChartSettings } from '../lib/types/chart-settings';
7
+ import type { Crosshair } from '../lib/renderers/renderer';
8
+ import type { Drawing, DraftDrawing, DrawingAnchorId, ActiveDrawingTool } from '../lib/types/drawing-types';
9
+ import type { TradeLine } from '../lib/types';
10
+ import { LiveTransformer } from '../interfaces/ICoordinateTransformer';
11
+ import { ChartTypePlugin } from './PluginRegistry';
12
+ import { SessionMapper } from './SessionMapper';
13
+ import { AccountSnapshot, DataLevel, SymbolInfo } from '.';
14
+ import type { CrosshairSync } from '../lib/types/layout-sync';
15
+ export type DrawHook = (ctx: CanvasRenderingContext2D, view: ViewBounds, transformer: LiveTransformer) => void;
16
+ export interface DrawParams {
17
+ panes: ChartPane[];
18
+ layouts: Record<string, Rect>;
19
+ indicators: Indicator[];
20
+ trades: TradePoint[];
21
+ priceHistory: PriceHistory[];
22
+ footprintBars: FootprintBar[];
23
+ heatmapBitmap: ImageBitmap | null;
24
+ bitmapOffsets: {
25
+ x: number;
26
+ y: number;
27
+ w: number;
28
+ h: number;
29
+ };
30
+ barNs: bigint;
31
+ chartSettings: ChartSettings;
32
+ horizon: bigint;
33
+ candleCache: Map<bigint, any> | null;
34
+ openBar: FootprintBar | null;
35
+ /** Bars to render as candles - OHLCV adapter data or loading-preview bars. */
36
+ ohlcvBars: {
37
+ time: number;
38
+ open: number;
39
+ high: number;
40
+ low: number;
41
+ close: number;
42
+ volume: number;
43
+ }[];
44
+ crosshair: Crosshair | null;
45
+ drawings: Drawing[];
46
+ draft: DraftDrawing | null;
47
+ tradeLines: TradeLine[];
48
+ hoveredDividerIdx: number;
49
+ hoveringLegend: boolean;
50
+ showTooltip: boolean;
51
+ selectedTrade: TradePoint | null;
52
+ activeTool: ActiveDrawingTool;
53
+ draggingAnchor: any;
54
+ isHoldingCtrl: boolean;
55
+ isHoldingShift: boolean;
56
+ showShiftInfo: boolean;
57
+ shiftInfoAnchor: {
58
+ ts: bigint;
59
+ price: number;
60
+ x: number;
61
+ y: number;
62
+ };
63
+ shiftInfoAnchor2: {
64
+ ts: bigint;
65
+ price: number;
66
+ x: number;
67
+ y: number;
68
+ } | null;
69
+ tradeLineInteraction: any;
70
+ selectedDrawingId: string;
71
+ hoveredDrawingId: string;
72
+ hotAnchor: DrawingAnchorId;
73
+ editingTextId: string;
74
+ transformer: LiveTransformer;
75
+ sessionMapper: SessionMapper;
76
+ isPluginChartType: boolean;
77
+ chartPlugin?: ChartTypePlugin;
78
+ pluginComputed?: unknown;
79
+ dataLevel: DataLevel;
80
+ accountSnapshot: AccountSnapshot;
81
+ symbolInfo: SymbolInfo;
82
+ /**
83
+ * Width (css px) of the right price axis. Derived from the symbol's price
84
+ * precision and the visible range, not a user setting.
85
+ */
86
+ priceScaleWidth: number;
87
+ hidePriceScale: boolean;
88
+ hideTimeScale: boolean;
89
+ /**
90
+ * Crosshair mirrored from another cell of the layout, in data space.
91
+ * Projected onto this chart's own axes at paint time, so pan and zoom keep it
92
+ * on the right bar with no extra traffic. Null when this chart owns the
93
+ * pointer, or nothing is being mirrored.
94
+ */
95
+ syncCrosshair: CrosshairSync | null;
96
+ }
97
+ export declare class RenderEngine {
98
+ private readonly baseCanvas;
99
+ private readonly drawingsCanvas;
100
+ private readonly uiCanvas;
101
+ private readonly eventBus;
102
+ private readonly chartId;
103
+ private rafId;
104
+ private dirty;
105
+ private beforeBaseDraw;
106
+ private afterBaseDraw;
107
+ private afterUIDraw;
108
+ private drawParams;
109
+ private view;
110
+ private readonly priceTransition;
111
+ private resizeObserver;
112
+ private destroyed;
113
+ constructor(baseCanvas: HTMLCanvasElement, drawingsCanvas: HTMLCanvasElement, uiCanvas: HTMLCanvasElement, eventBus: TypedEventBus, chartId?: number);
114
+ private startLoop;
115
+ markDirty(layer: 'base' | 'drawings' | 'ui'): void;
116
+ markAllDirty(): void;
117
+ setDrawParams(params: DrawParams): void;
118
+ setView(v: ViewBounds): void;
119
+ getView(): ViewBounds | null;
120
+ private doBaseRedraw;
121
+ /**
122
+ * Draws the ChristTrade banner into the base layer, in the same pass that
123
+ * paints the price data, so the attribution shares the chart's coordinate
124
+ * space and DPR transform.
125
+ *
126
+ * Apache-2.0 does not require you to keep this. See the Attribution section
127
+ * of the README for the ask, and NOTICE for what the trademark does cover.
128
+ */
129
+ private drawAttribution;
130
+ private doDrawingsRedraw;
131
+ private doUIRedraw;
132
+ addDrawHook(phase: 'before-base' | 'after-base' | 'after-ui', hook: DrawHook): () => void;
133
+ private handleResize;
134
+ private flushSync;
135
+ toDataURL(type?: string): string;
136
+ /**
137
+ * All three layers flattened onto a fresh canvas, in paint order. Use this
138
+ * rather than `toDataURL` when the snapshot should include the drawings and
139
+ * the crosshair/UI layer.
140
+ */
141
+ captureComposite(): HTMLCanvasElement;
142
+ destroy(): void;
143
+ }
@@ -0,0 +1,153 @@
1
+ import type { ChartPlugin } from './PluginRegistry';
2
+ import type { StyleField } from '../components/drawings/drawing-settings-dialog';
3
+ export type ParamDef = {
4
+ label: string;
5
+ type: 'number';
6
+ default: number;
7
+ min?: number;
8
+ max?: number;
9
+ step?: number;
10
+ unit?: string;
11
+ } | {
12
+ label: string;
13
+ type: 'stepperInt';
14
+ default: number;
15
+ min?: number;
16
+ max?: number;
17
+ step?: number;
18
+ } | {
19
+ label: string;
20
+ type: 'slider';
21
+ default: number;
22
+ min: number;
23
+ max: number;
24
+ step?: number;
25
+ suffix?: string;
26
+ } | {
27
+ label: string;
28
+ type: 'rangeWithSteps';
29
+ default: number;
30
+ min: number;
31
+ max: number;
32
+ steps: {
33
+ value: number;
34
+ label: string;
35
+ }[];
36
+ } | {
37
+ label: string;
38
+ type: 'opacity';
39
+ default: number;
40
+ } | {
41
+ label: string;
42
+ type: 'fontSize';
43
+ default: number;
44
+ } | {
45
+ label: string;
46
+ type: 'color';
47
+ default: string;
48
+ } | {
49
+ label: string;
50
+ type: 'text';
51
+ default: string;
52
+ placeholder?: string;
53
+ maxLength?: number;
54
+ } | {
55
+ label: string;
56
+ type: 'select';
57
+ default: string;
58
+ options: string[] | {
59
+ value: string;
60
+ label: string;
61
+ }[];
62
+ } | {
63
+ label: string;
64
+ type: 'buttonGroup';
65
+ default: string;
66
+ options: {
67
+ value: string;
68
+ label: string;
69
+ }[];
70
+ } | {
71
+ label: string;
72
+ type: 'boolean';
73
+ default: boolean;
74
+ } | {
75
+ label: string;
76
+ type: 'checkbox';
77
+ default: boolean;
78
+ description?: string;
79
+ } | {
80
+ label: string;
81
+ type: 'dualColor';
82
+ labelA: string;
83
+ defaultA: string;
84
+ labelB: string;
85
+ defaultB: string;
86
+ } | {
87
+ label: string;
88
+ type: 'dualOpacity';
89
+ labelA: string;
90
+ defaultA: number;
91
+ labelB: string;
92
+ defaultB: number;
93
+ } | {
94
+ label: string;
95
+ type: 'colorGradient';
96
+ defaultStart: string;
97
+ defaultEnd: string;
98
+ } | {
99
+ label: string;
100
+ type: 'colorWithOpacity';
101
+ defaultColor: string;
102
+ defaultOpacity: number;
103
+ } | {
104
+ label: string;
105
+ type: 'toggledColor';
106
+ defaultToggle: boolean;
107
+ defaultColor: string;
108
+ } | {
109
+ label: string;
110
+ type: 'toggledInput';
111
+ toggleLabel: string;
112
+ inputLabel: string;
113
+ defaultToggle: boolean;
114
+ defaultInput: number;
115
+ min?: number;
116
+ max?: number;
117
+ step?: number;
118
+ unit?: string;
119
+ } | {
120
+ label: string;
121
+ type: 'inlineFields';
122
+ fields: Array<{
123
+ type: 'stepperInt';
124
+ key: string;
125
+ label: string;
126
+ default: number;
127
+ min?: number;
128
+ max?: number;
129
+ step?: number;
130
+ } | {
131
+ type: 'buttonGroup';
132
+ key: string;
133
+ label: string;
134
+ default: string;
135
+ options: {
136
+ value: string;
137
+ label: string;
138
+ }[];
139
+ } | {
140
+ type: 'checkbox';
141
+ key: string;
142
+ label: string;
143
+ default: boolean;
144
+ }>;
145
+ };
146
+ export declare function hasFunctionDecl(script: string, name: string): boolean;
147
+ export declare function buildStyleSchema(paramDefs: Record<string, ParamDef>): StyleField[];
148
+ export declare function buildParamDefaults(paramDefs: Record<string, ParamDef>): Record<string, unknown>;
149
+ /**
150
+ * @param category Fallback picker category, used when the script doesn't declare
151
+ * one itself. The built-ins pass theirs here.
152
+ */
153
+ export declare function createScriptedPlugin(script: string, id?: string, category?: string): ChartPlugin;
@@ -0,0 +1,54 @@
1
+ import type { TradingSession } from '../interfaces/IDataAdapter';
2
+ export interface SessionSegment {
3
+ /** Real UTC ns start of this open window */
4
+ realStart: bigint;
5
+ /** Real UTC ns end (exclusive) */
6
+ realEnd: bigint;
7
+ /** Market-ns offset at realStart */
8
+ marketStart: bigint;
9
+ /** Duration of this open window in market-ns (= realEnd - realStart) */
10
+ duration: bigint;
11
+ }
12
+ export declare class SessionMapper {
13
+ segments: SessionSegment[];
14
+ private totalMarketNs;
15
+ /** Real ns range this mapper covers */
16
+ rangeFrom: bigint;
17
+ rangeTo: bigint;
18
+ /** Bumped on every mutation, so LiveTransformer can spot a stale cache. */
19
+ version: number;
20
+ private _buildSegments;
21
+ /** Build the mapper over a real-time range. Resolved to the minute. */
22
+ build(session: TradingSession | null, from: bigint, to: bigint): void;
23
+ /**
24
+ * Extend the mapper backward to cover `newFrom` up to the current start.
25
+ * Only walks the new range, and shifts every existing segment's marketStart
26
+ * to account for the history prepended in front of it.
27
+ */
28
+ extendBackward(session: TradingSession | null, newFrom: bigint): void;
29
+ get hasSession(): boolean;
30
+ /**
31
+ * The open window containing `ts`, or null when it lands in a closed one or
32
+ * outside the built range.
33
+ *
34
+ * Exposed because bar buckets are anchored to the session open: which bar a
35
+ * timestamp falls in is answered from the segment's start rather than an
36
+ * epoch multiple, and several places need to answer it the same way.
37
+ */
38
+ segmentAt(ts: bigint): SessionSegment | null;
39
+ /** Real UTC ns to market ns, snapping a closed window to the nearest edge. */
40
+ tsToMarket(ts: bigint): bigint;
41
+ /** Market ns back to real UTC ns. */
42
+ marketToTs(market: bigint): bigint;
43
+ getBreaks(): {
44
+ ts: bigint;
45
+ type: string;
46
+ }[];
47
+ /** The market span a real [from, to] range covers. */
48
+ realSpanToMarketSpan(from: bigint, to: bigint): bigint;
49
+ /** A real ts to a pixel x in [0, chartW]. tMin/tMax are real ns view bounds. */
50
+ tsToX(ts: bigint, tMin: bigint, tMax: bigint, chartW: number): number;
51
+ /** And back: a pixel x in [0, chartW] to real UTC ns. */
52
+ xToTs(x: number, tMin: bigint, tMax: bigint, chartW: number): bigint;
53
+ }
54
+ export declare function createSessionMapper(): SessionMapper;
@@ -0,0 +1,53 @@
1
+ import type { TradingSession } from '../interfaces/IDataAdapter';
2
+ /**
3
+ * The wall-clock date/time a UTC ns timestamp lands on in an IANA timezone.
4
+ * Month is 1-based, dayOfWeek is 0=Sun.
5
+ */
6
+ export declare function wallClock(ns: bigint, tz: string): {
7
+ year: number;
8
+ month: number;
9
+ day: number;
10
+ dayOfWeek: number;
11
+ minuteOfDay: number;
12
+ isoDate: string;
13
+ };
14
+ export declare function isMarketOpenFromWC(session: TradingSession, minuteOfDay: number, dayOfWeek: number, isoDate: string): boolean;
15
+ export type SessionStatus = {
16
+ kind: 'always';
17
+ } | {
18
+ kind: 'open';
19
+ } | {
20
+ kind: 'sub';
21
+ label: string;
22
+ } | {
23
+ kind: 'closed';
24
+ };
25
+ /**
26
+ * Market status at a UTC ns timestamp. Checks the main session first, then any
27
+ * named subsessions (pre/post market and so on).
28
+ */
29
+ export declare function getSessionStatus(session: TradingSession | null, atNs: bigint): SessionStatus;
30
+ export interface SessionWindow {
31
+ from: bigint;
32
+ to: bigint;
33
+ }
34
+ /** Is the market open at this UTC ns timestamp? */
35
+ export declare function isMarketOpen(session: TradingSession, atNs: bigint): boolean;
36
+ /**
37
+ * Clip a UTC ns range into the open market windows inside it, ascending.
38
+ * Closed windows are dropped, and a 24/7 session returns the range as one
39
+ * window. Resolved to the minute.
40
+ */
41
+ export declare function clipToSession(session: TradingSession, from: bigint, to: bigint): SessionWindow[];
42
+ /** Next market open at or after `fromNs`, or `fromNs` if it's already open. */
43
+ export declare function nextOpenNs(session: TradingSession, fromNs: bigint): bigint;
44
+ /** Most recent close before `fromNs`, or `fromNs` if the market is open. */
45
+ export declare function prevCloseNs(session: TradingSession, fromNs: bigint): bigint;
46
+ /**
47
+ * Walk backward from `fromNs` by `targetDuration` of market-open time, skipping
48
+ * closed windows, so the real span returned covers exactly that much trading.
49
+ *
50
+ * On a Sun 6pm - Fri 5pm ET session, walking back one market hour from Sunday
51
+ * 10pm ET lands on Friday 4pm ET.
52
+ */
53
+ export declare function walkBackMarketNs(session: TradingSession | null, fromNs: bigint, targetMarketNs: bigint): bigint;