@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,143 @@
1
+ import { TypedEventBus } from './TypedEventBus';
2
+ import type { IDataAdapter, SymbolInfo, DataLevel, OhlcvBar, TickEvent } from '../interfaces/IDataAdapter';
3
+ import type { FootprintOptions } from '../lib/types/footprint';
4
+ import type { SerialTrade } from '../lib/types';
5
+ import type { PriceHistory } from '../lib/types';
6
+ import type { FootprintBar } from '../lib/types/footprint';
7
+ import type { DataSourceRegistry } from './DataSourceRegistry';
8
+ import { ExecutionEngine } from './ExecutionEngine';
9
+ import { ChartState } from './ChartState';
10
+ import { Timeframe } from '../lib/timeframes';
11
+ export interface DataEngineConfig {
12
+ initialLoad: {
13
+ start: string;
14
+ end: string;
15
+ };
16
+ horizon: string;
17
+ fpOptions?: FootprintOptions;
18
+ initialWindowNs?: bigint;
19
+ scrollWindowNs?: bigint;
20
+ timeframe: Timeframe;
21
+ /** Active symbol - passed in every FetchRequest so one adapter serves many symbols. */
22
+ symbol?: string;
23
+ /**
24
+ * Symbols served by plugins. A symbol one of them claims is fetched through
25
+ * that source instead of the adapter, and their symbols are folded into
26
+ * every picker search alongside the adapter's own.
27
+ */
28
+ plugins?: DataSourceRegistry;
29
+ }
30
+ export interface ChartDataSnapshot {
31
+ readonly dataLevel: DataLevel;
32
+ readonly trades: SerialTrade[];
33
+ readonly footprintBars: FootprintBar[];
34
+ readonly priceHistory: PriceHistory[];
35
+ /** Populated for ohlcv; derived from footprintBars for l3/tick; empty for l2. */
36
+ readonly ohlcvBars: OhlcvBar[];
37
+ /** Populated for tick and l3 (derived from trades). */
38
+ readonly ticks: TickEvent[];
39
+ readonly barNs: bigint;
40
+ /** Unix ms timestamps */
41
+ readonly dataStart: number;
42
+ readonly dataEnd: number;
43
+ readonly symbolInfo: SymbolInfo | null;
44
+ }
45
+ export declare class DataEngine {
46
+ private readonly eventBus;
47
+ private readonly state;
48
+ private adapter;
49
+ private realtimeUnsub;
50
+ private executionEngine;
51
+ private readonly config;
52
+ private destroyed;
53
+ private readonly _states;
54
+ private readonly resolvedSymbols;
55
+ private readonly paneResolutions;
56
+ private fpOptions;
57
+ private initialLoad;
58
+ private horizonIso;
59
+ private scrollWindowNs;
60
+ private activeSymbol;
61
+ private _loadChain;
62
+ private symbolUniverse;
63
+ private symbolUniverseInFlight;
64
+ private symbolSearchAbort;
65
+ private latestSymbolSearchId;
66
+ private readonly symbolSearchCache;
67
+ private readonly unsubs;
68
+ readonly sharedData: {
69
+ dataLevel: DataLevel;
70
+ compactBuf: ArrayBuffer;
71
+ trades: SerialTrade[];
72
+ priceHistory: PriceHistory[];
73
+ footprintBars: FootprintBar[];
74
+ ohlcvBars: OhlcvBar[];
75
+ barNs: bigint;
76
+ dataStart: number;
77
+ dataEnd: number;
78
+ supplemental: Array<{
79
+ resolution: bigint;
80
+ bars: Array<{
81
+ time: number;
82
+ open: number;
83
+ high: number;
84
+ low: number;
85
+ close: number;
86
+ volume: number;
87
+ }>;
88
+ }> | null;
89
+ };
90
+ private maxLookbackBars;
91
+ constructor(eventBus: TypedEventBus, state: ChartState, config: DataEngineConfig);
92
+ private _st;
93
+ private _targetSymbol;
94
+ setAdapter(adapter: IDataAdapter): void;
95
+ private _adapterFor;
96
+ private _applySymbol;
97
+ getResolvedSymbolInfo(symbol: string): SymbolInfo | null;
98
+ attachExecutionEngine(engine: ExecutionEngine): void;
99
+ setLookback(lookback: number): void;
100
+ load(symbol: string): Promise<void>;
101
+ private _load;
102
+ private _loadWindow;
103
+ seekLoad(targetNs: bigint, fromNs?: bigint): Promise<void>;
104
+ reload(horizonNs?: bigint): Promise<void>;
105
+ private _settleGapFills;
106
+ rehydrate(): void;
107
+ rebuildFootprint(barNs: bigint, fpOptions?: FootprintOptions): void;
108
+ getSnapshot(): ChartDataSnapshot;
109
+ destroy(): void;
110
+ private _fetchForward;
111
+ private _fetchBackward;
112
+ private _supplementalFor;
113
+ private _symbolSearchMode;
114
+ private _symbolSearchDebounceMs;
115
+ private _searchSymbols;
116
+ private _loadSymbolUniverse;
117
+ private _withPluginSymbols;
118
+ private _emitSymbolSearch;
119
+ private _cacheSymbolSearch;
120
+ private _cancelSymbolSearch;
121
+ private _activeBarNs;
122
+ private _lookbackBarNs;
123
+ private _onPaneResolution;
124
+ private _refineStaleSegments;
125
+ private _effectiveFetchBarNs;
126
+ private _fetchTimeframe;
127
+ private _process;
128
+ private _handleRealtimeBar;
129
+ private _growMaster;
130
+ private _prependMaster;
131
+ private _masterBarNs;
132
+ private _syncShared;
133
+ private _subscribeToEventBus;
134
+ private _runLoadIngest;
135
+ private _buildPayload;
136
+ private _emitLoad;
137
+ private _emitAppend;
138
+ private _emitPrepend;
139
+ private _emitAdapterError;
140
+ private _onTimeframeChange;
141
+ private _refineSegment;
142
+ private _openWindows;
143
+ }
@@ -0,0 +1,106 @@
1
+ import type { SerialTrade } from '../lib/types';
2
+ import type { AdapterCapabilities, BarPreviewResponse, BarResponse, FetchRequest, IDataAdapter, SymbolInfo, SymbolSearchRequest, SymbolSearchResponse } from '../interfaces/IDataAdapter';
3
+ /**
4
+ * A data source registered by a plugin. Everything an {@link IDataAdapter} can
5
+ * do, plus a claim on the symbols it serves - declare `symbols` when you can
6
+ * list them, or `prefix` for a namespace.
7
+ *
8
+ * Only `fetchBars` is required. The rest have sensible fallbacks, though a
9
+ * source without `resolveSymbol` is priced as a 24/7 two-decimal instrument.
10
+ */
11
+ export interface PluginDataSource {
12
+ /**
13
+ * Exact symbols this source owns. Prefix convention: `"TYPE:DETAILS"`.
14
+ */
15
+ symbols?: string[];
16
+ /**
17
+ * Or claim a namespace: every symbol starting with this belongs to the
18
+ * source, which is what a whole venue behind an API key wants. `''` claims
19
+ * everything the adapter didn't. The longest matching prefix wins, so a
20
+ * specific one still beats a catch-all.
21
+ */
22
+ prefix?: string;
23
+ /**
24
+ * Tick size, price format, session, contract details. Without one the chart
25
+ * falls back to a 24/7 crypto-ish default, which is rarely what you want -
26
+ * order sizing and price formatting both read this.
27
+ */
28
+ resolveSymbol?(symbol: string): SymbolInfo | Promise<SymbolInfo>;
29
+ /**
30
+ * Answer the symbol picker. Results are merged in front of the adapter's
31
+ * own. Return a {@link SymbolSearchResponse} to page results yourself.
32
+ * Without this, `symbols` is matched locally instead.
33
+ */
34
+ searchSymbols?(request: SymbolSearchRequest): SymbolInfo[] | SymbolSearchResponse | Promise<SymbolInfo[] | SymbolSearchResponse>;
35
+ /**
36
+ * Return the bars covering `request.range`. Called for the initial window,
37
+ * for backward pans, for forward prefetch during playback, and again at a
38
+ * finer resolution when a pane needs one - `request.direction` says which.
39
+ */
40
+ fetchBars(request: FetchRequest): Promise<BarResponse>;
41
+ /**
42
+ * Cheap bars for the loading skeleton, drawn before `fetchBars` resolves.
43
+ * Skip it and the chart just waits.
44
+ */
45
+ fetchPreview?(request: FetchRequest): Promise<BarPreviewResponse>;
46
+ /**
47
+ * Push live bars as they arrive - a websocket, a poll, anything. Return the
48
+ * teardown.
49
+ */
50
+ subscribeRealtime?(onBar: (bar: BarResponse) => void): () => void;
51
+ /**
52
+ * A trade arrived on the host adapter's feed. Return bars to append, or
53
+ * null to ignore it. This is the hook for a derived instrument, which has
54
+ * no feed of its own to subscribe to.
55
+ */
56
+ onTick?(params: {
57
+ symbol: string;
58
+ trade: SerialTrade;
59
+ barNs: bigint;
60
+ }): BarResponse | null;
61
+ /**
62
+ * Declare supplemental resolutions and how symbol search is filtered. See
63
+ * {@link AdapterCapabilities}.
64
+ */
65
+ getCapabilities?(): AdapterCapabilities;
66
+ /** Called before the first fetch. Open a socket, refresh a token. */
67
+ connect?(): Promise<void>;
68
+ /** Called when the plugin unregisters the source. */
69
+ destroy?(): void;
70
+ }
71
+ export declare class DataSourceRegistry {
72
+ private readonly bySymbol;
73
+ private readonly byPrefix;
74
+ private readonly resolved;
75
+ private readonly adapters;
76
+ private readonly lastRequest;
77
+ private readonly realtimeSinks;
78
+ register(source: PluginDataSource): () => void;
79
+ sourceFor(symbol: string): PluginDataSource | undefined;
80
+ has(symbol: string): boolean;
81
+ /** The adapter DataEngine should fetch this symbol through, if any. */
82
+ adapterFor(symbol: string): IDataAdapter | null;
83
+ /** The last SymbolInfo handed out for a symbol, if it has been resolved. */
84
+ getResolved(symbol: string): SymbolInfo | null;
85
+ resolve(symbol: string): Promise<SymbolInfo | null>;
86
+ /**
87
+ * Every registered symbol matching a picker query. Sources with their own
88
+ * searchSymbols answer it; the rest have their `symbols` matched here.
89
+ */
90
+ search(request: SymbolSearchRequest): Promise<SymbolInfo[]>;
91
+ /**
92
+ * Longest debounce any registered source wants, or null when none care.
93
+ * A network search behind someone's rate-limited API key shouldnt fire per
94
+ * keystroke just because the host adapter matches in memory.
95
+ */
96
+ searchDebounceMs(): number | null;
97
+ /**
98
+ * Feed a trade from the host adapter to every source building bars off it.
99
+ * Returns true if any of them produced something.
100
+ */
101
+ handleTick(trade: SerialTrade): boolean;
102
+ destroy(): void;
103
+ private sources;
104
+ private capsOf;
105
+ private adapterOf;
106
+ }