@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.
- package/LICENSE.md +201 -0
- package/NOTICE +15 -0
- package/README.md +159 -0
- package/depth.cjs +1136 -0
- package/depth.css +2 -0
- package/depth.mjs +1136 -0
- package/depth.nopreflight.css +2 -0
- package/index.d.ts +1 -0
- package/package.json +32 -0
- package/types/ChartInner.d.ts +114 -0
- package/types/ChartOuter.d.ts +31 -0
- package/types/components/account/AccountSummary.d.ts +8 -0
- package/types/components/chart/chart-context-menu.d.ts +30 -0
- package/types/components/chart/chart-settings-dialog.d.ts +15 -0
- package/types/components/chart/chart-status-overlay.d.ts +24 -0
- package/types/components/chart/data-status.d.ts +10 -0
- package/types/components/chart/pane-legend.d.ts +37 -0
- package/types/components/chart/session-status-badge.d.ts +14 -0
- package/types/components/chart/status-bar.d.ts +9 -0
- package/types/components/chart/symbol-icon.d.ts +9 -0
- package/types/components/chart/tz.d.ts +10 -0
- package/types/components/drawings/drawing-icons.d.ts +2 -0
- package/types/components/drawings/drawing-settings-bar.d.ts +15 -0
- package/types/components/drawings/drawing-settings-dialog.d.ts +268 -0
- package/types/components/drawings/drawing-toolbar.d.ts +14 -0
- package/types/components/drawings/drawing-tools.d.ts +23 -0
- package/types/components/indicators/indicators-dialog.d.ts +20 -0
- package/types/components/indicators/indicators-settings-dialog.d.ts +164 -0
- package/types/components/multi-chart/GridDividers.d.ts +12 -0
- package/types/components/multi-chart/LayoutPicker.d.ts +19 -0
- package/types/components/plugin-panels/BottomBarPluginHost.d.ts +7 -0
- package/types/components/plugin-panels/PluginFixedPanelHost.d.ts +18 -0
- package/types/components/plugin-panels/PluginToolbarHost.d.ts +7 -0
- package/types/components/plugin-panels/PluginWindowsDropdown.d.ts +7 -0
- package/types/components/plugins/plugin-manager-dialog.d.ts +14 -0
- package/types/components/toolbar/SymbolSwitcher.d.ts +8 -0
- package/types/components/toolbar/chart-icons.d.ts +16 -0
- package/types/components/toolbar/chart-type-selector.d.ts +11 -0
- package/types/components/toolbar/timeframe-selector.d.ts +15 -0
- package/types/components/trading/OrderPanel.d.ts +36 -0
- package/types/components/trading/QuickTradingButtons.d.ts +7 -0
- package/types/components/trading/order-math.d.ts +94 -0
- package/types/components/ui/button.d.ts +11 -0
- package/types/components/ui/checkbox.d.ts +4 -0
- package/types/components/ui/color-picker.d.ts +12 -0
- package/types/components/ui/dialog.d.ts +19 -0
- package/types/components/ui/dropdown-menu.d.ts +27 -0
- package/types/components/ui/hover-card.d.ts +6 -0
- package/types/components/ui/input.d.ts +4 -0
- package/types/components/ui/popover.d.ts +7 -0
- package/types/components/ui/resizable.d.ts +23 -0
- package/types/components/ui/separator.d.ts +4 -0
- package/types/components/ui/slider.d.ts +4 -0
- package/types/components/ui/switch.d.ts +4 -0
- package/types/components/ui/tooltip.d.ts +7 -0
- package/types/core/AccountManager.d.ts +142 -0
- package/types/core/ChartModel.d.ts +84 -0
- package/types/core/ChartState.d.ts +51 -0
- package/types/core/ChartTypeRegistry.d.ts +27 -0
- package/types/core/DataEngine.d.ts +143 -0
- package/types/core/DataSourceRegistry.d.ts +106 -0
- package/types/core/DepthChart.d.ts +458 -0
- package/types/core/DrawingRegistry.d.ts +133 -0
- package/types/core/DrawingStore.d.ts +26 -0
- package/types/core/ExecutionEngine.d.ts +95 -0
- package/types/core/GlobalChartBus.d.ts +32 -0
- package/types/core/Playback.d.ts +48 -0
- package/types/core/PlaybackStateRegistry.d.ts +25 -0
- package/types/core/PluginRegistry.d.ts +67 -0
- package/types/core/PluginSchedule.d.ts +15 -0
- package/types/core/RenderEngine.d.ts +143 -0
- package/types/core/ScriptedPlugin.d.ts +153 -0
- package/types/core/SessionMapper.d.ts +54 -0
- package/types/core/SessionUtils.d.ts +53 -0
- package/types/core/TypedEventBus.d.ts +691 -0
- package/types/core/WasmPluginHost.d.ts +39 -0
- package/types/core/index.d.ts +70 -0
- package/types/core/plugin-startup.d.ts +33 -0
- package/types/core/processing/data-chunk.d.ts +37 -0
- package/types/core/processing/data-level.d.ts +13 -0
- package/types/core/processing/l2-processor.d.ts +10 -0
- package/types/core/processing/l3-processor.d.ts +26 -0
- package/types/core/processing/ohlcv-processor.d.ts +14 -0
- package/types/core/processing/tick-processor.d.ts +14 -0
- package/types/core/script-dsl.d.ts +20 -0
- package/types/core/script-scope.d.ts +4 -0
- package/types/core/script.worker.d.ts +1 -0
- package/types/hooks/useCellBridges.d.ts +36 -0
- package/types/hooks/useChartData.d.ts +153 -0
- package/types/hooks/useChartHandlers.d.ts +94 -0
- package/types/hooks/useChartInteraction.d.ts +160 -0
- package/types/hooks/useChartLayout.d.ts +21 -0
- package/types/hooks/useChartPlugin.d.ts +34 -0
- package/types/hooks/useChartSettings.d.ts +44 -0
- package/types/hooks/useChartSubscriptions.d.ts +64 -0
- package/types/hooks/useChartView.d.ts +47 -0
- package/types/hooks/usePlaybackEngine.d.ts +85 -0
- package/types/hooks/useRenderEngine.d.ts +64 -0
- package/types/hooks/useTradeLines.d.ts +80 -0
- package/types/hooks/useTradingState.d.ts +135 -0
- package/types/interfaces/IAccountAdapter.d.ts +38 -0
- package/types/interfaces/ICoordinateTransformer.d.ts +105 -0
- package/types/interfaces/IDataAdapter.d.ts +402 -0
- package/types/interfaces/IExecutionAdapter.d.ts +71 -0
- package/types/interfaces/plugins/IChartPlugin.d.ts +254 -0
- package/types/interfaces/plugins/IChartTypePlugin.d.ts +126 -0
- package/types/interfaces/plugins/IDataSourcePlugin.d.ts +20 -0
- package/types/interfaces/plugins/IDrawingPlugin.d.ts +62 -0
- package/types/interfaces/plugins/IIndicatorPlugin.d.ts +97 -0
- package/types/interfaces/plugins/index.d.ts +5 -0
- package/types/lib/bar-grid.d.ts +6 -0
- package/types/lib/book.d.ts +5 -0
- package/types/lib/clock.d.ts +7 -0
- package/types/lib/compact-buffer.d.ts +66 -0
- package/types/lib/constants.d.ts +5 -0
- package/types/lib/createSimulatedAdapter.d.ts +42 -0
- package/types/lib/dpr.d.ts +27 -0
- package/types/lib/heatmap.worker.d.ts +1 -0
- package/types/lib/indicator-stdlib.d.ts +426 -0
- package/types/lib/indicator-worker.d.ts +65 -0
- package/types/lib/matchingEngine.d.ts +144 -0
- package/types/lib/notifications/tradeToast.d.ts +31 -0
- package/types/lib/pointer-lock.d.ts +5 -0
- package/types/lib/priceFormat.d.ts +17 -0
- package/types/lib/priceTransition.d.ts +22 -0
- package/types/lib/renderers/drawFootprintChart.d.ts +5 -0
- package/types/lib/renderers/drawTradeLines.d.ts +112 -0
- package/types/lib/renderers/drawings-renderer.d.ts +57 -0
- package/types/lib/renderers/renderer.d.ts +113 -0
- package/types/lib/sampler.d.ts +7 -0
- package/types/lib/series/japaneseCharts.d.ts +88 -0
- package/types/lib/slice-worker-client.d.ts +138 -0
- package/types/lib/slice.worker.d.ts +139 -0
- package/types/lib/storage.d.ts +108 -0
- package/types/lib/symbol-info.d.ts +12 -0
- package/types/lib/symbol-search.d.ts +29 -0
- package/types/lib/timeframes.d.ts +46 -0
- package/types/lib/tradingview-import.d.ts +32 -0
- package/types/lib/types/chart-settings.d.ts +90 -0
- package/types/lib/types/drawing-types.d.ts +393 -0
- package/types/lib/types/footprint.d.ts +119 -0
- package/types/lib/types/heatmap-types.d.ts +30 -0
- package/types/lib/types/index.d.ts +147 -0
- package/types/lib/types/indicator-types.d.ts +123 -0
- package/types/lib/types/layout-sync.d.ts +43 -0
- package/types/lib/types/trading-types.d.ts +323 -0
- package/types/lib/use-forwarded-ref.d.ts +1 -0
- package/types/lib/utils.d.ts +2 -0
- package/types/plugins/alligator.d.ts +1 -0
- package/types/plugins/atr.d.ts +1 -0
- package/types/plugins/awesome-oscillator.d.ts +1 -0
- package/types/plugins/bollinger-bands.d.ts +1 -0
- package/types/plugins/cci.d.ts +1 -0
- package/types/plugins/cvd.d.ts +1 -0
- package/types/plugins/donchian.d.ts +1 -0
- package/types/plugins/ichimoku.d.ts +1 -0
- package/types/plugins/index.d.ts +25 -0
- package/types/plugins/keltner.d.ts +1 -0
- package/types/plugins/macd.d.ts +1 -0
- package/types/plugins/mfi.d.ts +1 -0
- package/types/plugins/moving-average.d.ts +1 -0
- package/types/plugins/obv.d.ts +1 -0
- package/types/plugins/psar.d.ts +1 -0
- package/types/plugins/rsi.d.ts +1 -0
- package/types/plugins/sessions.d.ts +1 -0
- package/types/plugins/stochastic.d.ts +1 -0
- package/types/plugins/supertrend.d.ts +1 -0
- package/types/plugins/volume.d.ts +1 -0
- package/types/plugins/vwap.d.ts +1 -0
- package/types/plugins/williams-r.d.ts +1 -0
- package/types/react/useDepthChart.d.ts +6 -0
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* KEY DESIGN PRINCIPLE - NO MAIN-THREAD DESERIALIZATION:
|
|
3
|
+
*
|
|
4
|
+
* The onmessage handler does ZERO object allocation. It reattaches ArrayBuffers
|
|
5
|
+
* and resolves with raw Float64Array-backed data only. Callers that need JS
|
|
6
|
+
* objects (TradePoint[], PriceHistory[], Map) call the exported lazy helpers.
|
|
7
|
+
*
|
|
8
|
+
* Public API:
|
|
9
|
+
* sliceToMboEventsAsync - off-thread slice, returns MboEvent[]
|
|
10
|
+
* prependMergeAsync - off-thread prepend (raw buffer result)
|
|
11
|
+
* loadIngestAsync - off-thread load post-processing (raw buffer result)
|
|
12
|
+
* appendIngestAsync - off-thread append (raw buffer result)
|
|
13
|
+
*
|
|
14
|
+
* Raw-buffer result helpers (call ONLY when you actually need JS objects,
|
|
15
|
+
* never in the hot onmessage path):
|
|
16
|
+
* deserializeTradesFromBuf
|
|
17
|
+
* deserializePriceHistoryFromBuf
|
|
18
|
+
* deserializeOhlcvCacheFromBuf
|
|
19
|
+
* serializeTrades / serializePriceHistory / serializeOhlcvCache
|
|
20
|
+
*
|
|
21
|
+
* destroySliceWorker()
|
|
22
|
+
*/
|
|
23
|
+
import type { CompactBuffer } from '../lib/compact-buffer';
|
|
24
|
+
import type { MboEvent, PriceHistory } from '../lib/types';
|
|
25
|
+
type TradePoint = {
|
|
26
|
+
ts: bigint;
|
|
27
|
+
price: number;
|
|
28
|
+
size: number;
|
|
29
|
+
side: string;
|
|
30
|
+
};
|
|
31
|
+
type OhlcvEntry = {
|
|
32
|
+
open: number;
|
|
33
|
+
high: number;
|
|
34
|
+
low: number;
|
|
35
|
+
close: number;
|
|
36
|
+
volume: number;
|
|
37
|
+
delta: number;
|
|
38
|
+
};
|
|
39
|
+
export interface PrependMergeOptions {
|
|
40
|
+
cb: CompactBuffer;
|
|
41
|
+
incomingBuf: ArrayBuffer;
|
|
42
|
+
existingTrades: TradePoint[];
|
|
43
|
+
newTrades: TradePoint[];
|
|
44
|
+
existingPriceHistory: PriceHistory[];
|
|
45
|
+
newPriceHistory: PriceHistory[];
|
|
46
|
+
existingOhlcvCache: Map<bigint, OhlcvEntry> | null;
|
|
47
|
+
barNs: bigint;
|
|
48
|
+
existingTradesBufRaw?: ArrayBuffer;
|
|
49
|
+
existingPhBufRaw?: ArrayBuffer;
|
|
50
|
+
existingOhlcvBufRaw?: ArrayBuffer;
|
|
51
|
+
}
|
|
52
|
+
export interface LoadIngestOptions {
|
|
53
|
+
tradesBuf: ArrayBuffer;
|
|
54
|
+
phBuf: ArrayBuffer;
|
|
55
|
+
barNs: bigint;
|
|
56
|
+
}
|
|
57
|
+
export interface AppendIngestOptions {
|
|
58
|
+
cb: CompactBuffer;
|
|
59
|
+
incomingBuf: ArrayBuffer;
|
|
60
|
+
existingTradesBuf: ArrayBuffer;
|
|
61
|
+
newTrades: TradePoint[];
|
|
62
|
+
existingPhBuf: ArrayBuffer;
|
|
63
|
+
newPriceHistory: PriceHistory[];
|
|
64
|
+
existingOhlcvBuf: ArrayBuffer;
|
|
65
|
+
trimBeforeNs: bigint;
|
|
66
|
+
barNs: bigint;
|
|
67
|
+
dataEndNs: bigint;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Raw-buffer results - no JS objects allocated on the main thread.
|
|
71
|
+
* Call deserialize* helpers only when you actually need to iterate.
|
|
72
|
+
*/
|
|
73
|
+
export interface RawIngestResult {
|
|
74
|
+
/** Raw Float64Array (TRADE_STRIDE f64s per trade). */
|
|
75
|
+
tradesBuf: ArrayBuffer;
|
|
76
|
+
/** Raw Float64Array (PH_STRIDE f64s per point). */
|
|
77
|
+
phBuf: ArrayBuffer;
|
|
78
|
+
/** Raw Float64Array - bucketed price history. */
|
|
79
|
+
bucketedPhBuf: ArrayBuffer;
|
|
80
|
+
/** Raw Float64Array (OHLCV_STRIDE f64s per entry). */
|
|
81
|
+
ohlcvBuf: ArrayBuffer;
|
|
82
|
+
}
|
|
83
|
+
export interface PrependMergeRawResult extends RawIngestResult {
|
|
84
|
+
cb: CompactBuffer;
|
|
85
|
+
prependedCount: number;
|
|
86
|
+
}
|
|
87
|
+
export interface LoadIngestRawResult {
|
|
88
|
+
ohlcvBuf: ArrayBuffer;
|
|
89
|
+
bucketedPhBuf: ArrayBuffer;
|
|
90
|
+
tradesBuf: ArrayBuffer;
|
|
91
|
+
phBuf: ArrayBuffer;
|
|
92
|
+
}
|
|
93
|
+
export interface AppendIngestRawResult {
|
|
94
|
+
cb: CompactBuffer;
|
|
95
|
+
mergedTradesBuf: ArrayBuffer;
|
|
96
|
+
mergedPhBuf: ArrayBuffer;
|
|
97
|
+
mergedOhlcvBuf: ArrayBuffer;
|
|
98
|
+
appendedCount: number;
|
|
99
|
+
compactCutCount: number;
|
|
100
|
+
tradeCutCount: number;
|
|
101
|
+
phCutCount: number;
|
|
102
|
+
}
|
|
103
|
+
export declare function serializeTrades(trades: TradePoint[]): ArrayBuffer;
|
|
104
|
+
export declare function serializePriceHistory(ph: PriceHistory[]): ArrayBuffer;
|
|
105
|
+
export declare function serializeOhlcvCache(map: Map<bigint, OhlcvEntry> | null): ArrayBuffer;
|
|
106
|
+
export declare function deserializeTradesFromBuf(buf: ArrayBuffer): TradePoint[];
|
|
107
|
+
export declare function deserializePriceHistoryFromBuf(buf: ArrayBuffer): PriceHistory[];
|
|
108
|
+
export declare function deserializeOhlcvCacheFromBuf(buf: ArrayBuffer, horizon: bigint): Map<bigint, OhlcvEntry>;
|
|
109
|
+
/**
|
|
110
|
+
* Fast typed-array lookup for the candle cache - avoids deserializing the whole cache
|
|
111
|
+
* into a Map just to do a single key lookup during mousemove / status line.
|
|
112
|
+
* Returns null if not found.
|
|
113
|
+
*/
|
|
114
|
+
export declare function lookupOhlcvFromBuf(buf: ArrayBuffer, targetKey: bigint): OhlcvEntry | null;
|
|
115
|
+
export declare function sliceToMboEventsAsync(cb: CompactBuffer, start: number, end: number, messageType: 'init' | 'append' | 'prepend'): Promise<{
|
|
116
|
+
events: MboEvent[];
|
|
117
|
+
cb: CompactBuffer;
|
|
118
|
+
messageType: typeof messageType;
|
|
119
|
+
}>;
|
|
120
|
+
/**
|
|
121
|
+
* Off-thread prepend merge. Returns RAW buffers - caller deserializes lazily.
|
|
122
|
+
* Pass existingTradesBufRaw / existingPhBufRaw / existingOhlcvBufRaw when
|
|
123
|
+
* available (from previous ingest result) to avoid serialising full dataset.
|
|
124
|
+
*/
|
|
125
|
+
export declare function prependMergeAsync(opts: PrependMergeOptions): Promise<PrependMergeRawResult>;
|
|
126
|
+
/**
|
|
127
|
+
* Off-thread load-ingest. Returns RAW buffers - caller deserializes lazily.
|
|
128
|
+
* tradesBuf and phBuf are TRANSFERRED.
|
|
129
|
+
*/
|
|
130
|
+
export declare function loadIngestAsync(opts: LoadIngestOptions): Promise<LoadIngestRawResult>;
|
|
131
|
+
/**
|
|
132
|
+
* Off-thread append-ingest. Returns RAW buffers - caller deserializes lazily.
|
|
133
|
+
* Only serialise the SMALL incremental newTrades / newPriceHistory on the
|
|
134
|
+
* main thread. All existingXxxBuf are transferred (zero-copy).
|
|
135
|
+
*/
|
|
136
|
+
export declare function appendIngestAsync(opts: AppendIngestOptions): Promise<AppendIngestRawResult>;
|
|
137
|
+
export declare function destroySliceWorker(): void;
|
|
138
|
+
export {};
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* slice.worker.ts
|
|
3
|
+
*
|
|
4
|
+
* Message types:
|
|
5
|
+
*
|
|
6
|
+
* 1. 'slice' - decode a range of a CompactBuffer to MboEvent[]
|
|
7
|
+
*
|
|
8
|
+
* 2. 'prepend-merge' - full prepend hot path off-thread:
|
|
9
|
+
* merge compact chunk, trades, priceHistory + bucket, OHLCV cache
|
|
10
|
+
*
|
|
11
|
+
* 3. 'load-ingest' - NEW: everything ingestLoadedData used to do on the
|
|
12
|
+
* main thread after receiving data:
|
|
13
|
+
* - rebuild the candleCache cache from trades
|
|
14
|
+
* - bucket priceHistory
|
|
15
|
+
* Returns typed-array buffers the main thread just assigns to refs.
|
|
16
|
+
*
|
|
17
|
+
* 4. 'append-ingest' - NEW: everything ingestAppendedData used to do on the
|
|
18
|
+
* main thread:
|
|
19
|
+
* - compact buffer grow + memcopy
|
|
20
|
+
* - allTrades / allPriceHistory concat + trim
|
|
21
|
+
* - candleCache cache update + trim
|
|
22
|
+
* Returns typed-array buffers the main thread just assigns to refs.
|
|
23
|
+
*
|
|
24
|
+
* All ArrayBuffers are transferred (zero-copy) in both directions.
|
|
25
|
+
*/
|
|
26
|
+
import { sliceToMboEvents } from '../lib/compact-buffer';
|
|
27
|
+
export interface SliceRequest {
|
|
28
|
+
kind: 'slice';
|
|
29
|
+
id: string;
|
|
30
|
+
buf: ArrayBuffer;
|
|
31
|
+
length: number;
|
|
32
|
+
capacity: number;
|
|
33
|
+
start: number;
|
|
34
|
+
end: number;
|
|
35
|
+
messageType: 'init' | 'append' | 'prepend';
|
|
36
|
+
}
|
|
37
|
+
export interface PrependMergeRequest {
|
|
38
|
+
kind: 'prepend-merge';
|
|
39
|
+
id: string;
|
|
40
|
+
existingBuf: ArrayBuffer;
|
|
41
|
+
existingLength: number;
|
|
42
|
+
existingCapacity: number;
|
|
43
|
+
incomingBuf: ArrayBuffer;
|
|
44
|
+
existingTradesBuf: ArrayBuffer;
|
|
45
|
+
newTradesBuf: ArrayBuffer;
|
|
46
|
+
existingPhBuf: ArrayBuffer;
|
|
47
|
+
newPhBuf: ArrayBuffer;
|
|
48
|
+
existingOhlcvBuf: ArrayBuffer;
|
|
49
|
+
barNsHi: number;
|
|
50
|
+
barNsLo: number;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* 'load-ingest' - off-thread heavy work from ingestLoadedData.
|
|
54
|
+
* The data worker already built the compact buffer; we just need to
|
|
55
|
+
* rebuild candleCache and bucket priceHistory.
|
|
56
|
+
*/
|
|
57
|
+
export interface LoadIngestRequest {
|
|
58
|
+
kind: 'load-ingest';
|
|
59
|
+
id: string;
|
|
60
|
+
/** Serialised trades (TRADE_STRIDE Float64s per trade) */
|
|
61
|
+
tradesBuf: ArrayBuffer;
|
|
62
|
+
/** Serialised priceHistory (PH_STRIDE Float64s per point) */
|
|
63
|
+
phBuf: ArrayBuffer;
|
|
64
|
+
barNsHi: number;
|
|
65
|
+
barNsLo: number;
|
|
66
|
+
}
|
|
67
|
+
export interface LoadIngestResponse {
|
|
68
|
+
kind: 'load-ingest';
|
|
69
|
+
id: string;
|
|
70
|
+
ohlcvBuf: ArrayBuffer;
|
|
71
|
+
bucketedPhBuf: ArrayBuffer;
|
|
72
|
+
/** Returned so main thread can reattach without re-serialising */
|
|
73
|
+
tradesBuf: ArrayBuffer;
|
|
74
|
+
phBuf: ArrayBuffer;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* 'append-ingest' - off-thread heavy work from ingestAppendedData.
|
|
78
|
+
*/
|
|
79
|
+
export interface AppendIngestRequest {
|
|
80
|
+
kind: 'append-ingest';
|
|
81
|
+
id: string;
|
|
82
|
+
existingBuf: ArrayBuffer;
|
|
83
|
+
existingLength: number;
|
|
84
|
+
existingCapacity: number;
|
|
85
|
+
incomingBuf: ArrayBuffer;
|
|
86
|
+
existingTradesBuf: ArrayBuffer;
|
|
87
|
+
newTradesBuf: ArrayBuffer;
|
|
88
|
+
existingPhBuf: ArrayBuffer;
|
|
89
|
+
newPhBuf: ArrayBuffer;
|
|
90
|
+
existingOhlcvBuf: ArrayBuffer;
|
|
91
|
+
/** Trim everything older than this ns. 0 = no trim. */
|
|
92
|
+
trimBeforeNsHi: number;
|
|
93
|
+
trimBeforeNsLo: number;
|
|
94
|
+
barNsHi: number;
|
|
95
|
+
barNsLo: number;
|
|
96
|
+
dataEndNsHi: number;
|
|
97
|
+
dataEndNsLo: number;
|
|
98
|
+
}
|
|
99
|
+
export interface AppendIngestResponse {
|
|
100
|
+
kind: 'append-ingest';
|
|
101
|
+
id: string;
|
|
102
|
+
mergedBuf: ArrayBuffer;
|
|
103
|
+
mergedLength: number;
|
|
104
|
+
mergedCapacity: number;
|
|
105
|
+
mergedTradesBuf: ArrayBuffer;
|
|
106
|
+
mergedPhBuf: ArrayBuffer;
|
|
107
|
+
mergedOhlcvBuf: ArrayBuffer;
|
|
108
|
+
appendedCount: number;
|
|
109
|
+
/** Events trimmed from the compact buffer front (caller adjusts playheadIdx). */
|
|
110
|
+
compactCutCount: number;
|
|
111
|
+
/** Trades trimmed from front. */
|
|
112
|
+
tradeCutCount: number;
|
|
113
|
+
/** PriceHistory points trimmed from front. */
|
|
114
|
+
phCutCount: number;
|
|
115
|
+
newFirstTsHi: number;
|
|
116
|
+
newFirstTsLo: number;
|
|
117
|
+
newLastTsHi: number;
|
|
118
|
+
newLastTsLo: number;
|
|
119
|
+
}
|
|
120
|
+
export type SliceWorkerRequest = SliceRequest | PrependMergeRequest | LoadIngestRequest | AppendIngestRequest;
|
|
121
|
+
export interface SliceResponse {
|
|
122
|
+
kind: 'slice';
|
|
123
|
+
id: string;
|
|
124
|
+
messageType: 'init' | 'append' | 'prepend';
|
|
125
|
+
events: ReturnType<typeof sliceToMboEvents>;
|
|
126
|
+
buf: ArrayBuffer;
|
|
127
|
+
}
|
|
128
|
+
export interface PrependMergeResponse {
|
|
129
|
+
kind: 'prepend-merge';
|
|
130
|
+
id: string;
|
|
131
|
+
mergedBuf: ArrayBuffer;
|
|
132
|
+
mergedLength: number;
|
|
133
|
+
mergedCapacity: number;
|
|
134
|
+
mergedTradesBuf: ArrayBuffer;
|
|
135
|
+
mergedPhBuf: ArrayBuffer;
|
|
136
|
+
bucketedPhBuf: ArrayBuffer;
|
|
137
|
+
mergedOhlcvBuf: ArrayBuffer;
|
|
138
|
+
prependedCount: number;
|
|
139
|
+
}
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
export declare const STORAGE_NAMESPACE = "christtrade:chart:";
|
|
2
|
+
/**
|
|
3
|
+
* Every chart-owned storage key. Add new keys here rather than inlining string
|
|
4
|
+
* literals at the call site - `clearChartStorage` and the migration both key off
|
|
5
|
+
* this namespace.
|
|
6
|
+
*/
|
|
7
|
+
export declare const StorageKey: {
|
|
8
|
+
readonly chartSettings: "christtrade:chart:settings";
|
|
9
|
+
readonly customTimeframes: "christtrade:chart:custom-timeframes";
|
|
10
|
+
readonly favoriteTimeframes: "christtrade:chart:favorite-timeframes";
|
|
11
|
+
readonly drawingTemplates: "christtrade:chart:drawing-templates";
|
|
12
|
+
readonly drawingFavorites: "christtrade:chart:drawing-favorites";
|
|
13
|
+
readonly colorSwatches: "christtrade:chart:color-swatches";
|
|
14
|
+
readonly pluginStartup: "christtrade:chart:plugin-startup";
|
|
15
|
+
readonly pluginPanels: "christtrade:chart:plugin-panels";
|
|
16
|
+
};
|
|
17
|
+
/** sdklaföfkdslfk:Settings blob a plugin owns via `ctx.getSettings()` / `ctx.saveSettings()`. */
|
|
18
|
+
export declare function pluginSettingsKey(pluginId: string): string;
|
|
19
|
+
/** Individual entry in a plugin's namespaced KV store (`ctx.storage`). */
|
|
20
|
+
export declare function pluginStorageKey(pluginId: string, key: string): string;
|
|
21
|
+
/** Prefix covering every key belonging to one plugin's KV store. */
|
|
22
|
+
export declare function pluginStoragePrefix(pluginId: string): string;
|
|
23
|
+
/**
|
|
24
|
+
* Bookkeeping about this device rather than user data - one-shot migration
|
|
25
|
+
* markers and the like. Excluded from clearChartStorage() and from the
|
|
26
|
+
* preferences block of a save document, since it means nothing on another device.
|
|
27
|
+
*/
|
|
28
|
+
export declare const META_PREFIX = "christtrade:chart:meta:";
|
|
29
|
+
/**
|
|
30
|
+
* Where the chart keeps its settings. localStorage-shaped and synchronous, so a
|
|
31
|
+
* host can point it at something else - an account-level store that syncs to a
|
|
32
|
+
* server, for instance - and everything the chart persists follows.
|
|
33
|
+
*/
|
|
34
|
+
export interface ChartStorageBackend {
|
|
35
|
+
getItem(key: string): string | null;
|
|
36
|
+
setItem(key: string, value: string): void;
|
|
37
|
+
removeItem(key: string): void;
|
|
38
|
+
/** Every key held, so the chart can enumerate what it has stored. */
|
|
39
|
+
keys(): string[];
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Replace localStorage as the chart's backing store, or pass `null` to go back
|
|
43
|
+
* to it.
|
|
44
|
+
*
|
|
45
|
+
* Anything already stored on this device that the backend doesn't have is copied
|
|
46
|
+
* across, so switching over carries the user's settings with it instead of
|
|
47
|
+
* resetting them. Install it before constructing a chart - the constructor reads
|
|
48
|
+
* settings on the way up.
|
|
49
|
+
*/
|
|
50
|
+
export declare function setChartStorageBackend(next: ChartStorageBackend | null): void;
|
|
51
|
+
export declare function onChartStorageChange(fn: () => void): () => void;
|
|
52
|
+
/** Whether the chart may read/write localStorage. Defaults to on. */
|
|
53
|
+
export declare function isPersistenceEnabled(): boolean;
|
|
54
|
+
export declare function setPersistenceEnabled(enabled: boolean): void;
|
|
55
|
+
/** Subscribe to persistence toggles. Returns an unsubscribe function. */
|
|
56
|
+
export declare function onPersistenceChange(fn: (enabled: boolean) => void): () => void;
|
|
57
|
+
/** Raw read. Falls back to the session store; null when nothing is set. */
|
|
58
|
+
export declare function readStored(key: string): string | null;
|
|
59
|
+
/** JSON read with a fallback for missing or malformed values. */
|
|
60
|
+
export declare function readJSON<T>(key: string, fallback: T): T;
|
|
61
|
+
/** Raw write. Stays in memory for the session when persistence is off. */
|
|
62
|
+
export declare function writeStored(key: string, value: string): void;
|
|
63
|
+
/** JSON write. Stays in memory for the session when persistence is off. */
|
|
64
|
+
export declare function writeJSON(key: string, value: unknown): void;
|
|
65
|
+
/**
|
|
66
|
+
* Delete a key. Runs even when persistence is off, so "forget this" always
|
|
67
|
+
* means forget it.
|
|
68
|
+
*/
|
|
69
|
+
export declare function removeStored(key: string): void;
|
|
70
|
+
/** Delete every key under `prefix`. Runs regardless of the persistence flag. */
|
|
71
|
+
export declare function removeStoredByPrefix(prefix: string): void;
|
|
72
|
+
/**
|
|
73
|
+
* Every chart-owned key currently holding a value, across both backing stores.
|
|
74
|
+
* Excludes the persistence preference itself.
|
|
75
|
+
*/
|
|
76
|
+
export declare function chartStorageKeys(): string[];
|
|
77
|
+
/**
|
|
78
|
+
* Wipe all chart-owned data, including plugin storage and any un-migrated
|
|
79
|
+
* legacy keys. The persistence preference itself survives.
|
|
80
|
+
*/
|
|
81
|
+
export declare function clearChartStorage(): void;
|
|
82
|
+
/** Rough byte count of everything the chart currently has stored. */
|
|
83
|
+
export declare function chartStorageSize(): number;
|
|
84
|
+
/**
|
|
85
|
+
* Device-level chart preferences - custom and favorite timeframes, favorite
|
|
86
|
+
* drawings, drawing style templates, saved color swatches, and every plugin's
|
|
87
|
+
* settings and KV store.
|
|
88
|
+
*
|
|
89
|
+
* Keyed by full storage key so anything added to StorageKey later, or written by
|
|
90
|
+
* a third-party plugin, rides along without extra plumbing. Values are the parsed
|
|
91
|
+
* JSON rather than raw strings so a save document stays readable; every writer
|
|
92
|
+
* goes through writeJSON, so that round-trips losslessly.
|
|
93
|
+
*
|
|
94
|
+
* Per-pane chart settings are NOT here - those already travel in
|
|
95
|
+
* `ChartSaveState.charts[i].settings`.
|
|
96
|
+
*/
|
|
97
|
+
export type ChartPreferences = Record<string, unknown>;
|
|
98
|
+
export declare function serializeChartPreferences(): ChartPreferences;
|
|
99
|
+
/**
|
|
100
|
+
* Apply a saved preferences block. Writes go through the persistence gate, so
|
|
101
|
+
* restoring with persistence off applies for the session without touching disk.
|
|
102
|
+
*
|
|
103
|
+
* Merges by default: keys absent from `prefs` keep their current value. Pass
|
|
104
|
+
* `{ replace: true }` for an exact "make this device look like the save" restore.
|
|
105
|
+
*/
|
|
106
|
+
export declare function restoreChartPreferences(prefs: ChartPreferences | undefined, opts?: {
|
|
107
|
+
replace?: boolean;
|
|
108
|
+
}): void;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { SymbolInfo } from '../interfaces/IDataAdapter';
|
|
2
|
+
/**
|
|
3
|
+
* A structured-clone-safe copy of a SymbolInfo, with `icon` stripped.
|
|
4
|
+
*
|
|
5
|
+
* `SymbolIcon` may carry a `render` callback, and functions cannot cross a
|
|
6
|
+
* `postMessage` boundary - the clone throws before the worker ever sees it.
|
|
7
|
+
* Icons are a presentation concern, so nothing off the main thread needs them.
|
|
8
|
+
*
|
|
9
|
+
* Call this on any SymbolInfo bound for a worker, `structuredClone`, or
|
|
10
|
+
* persisted layout.
|
|
11
|
+
*/
|
|
12
|
+
export declare function toTransferableSymbolInfo(info: SymbolInfo): SymbolInfo;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The built-in symbol matcher. Used by DataEngine whenever the adapter declares
|
|
3
|
+
* `symbolSearch: 'none'` (the default) - the adapter hands over its universe
|
|
4
|
+
* once and every keystroke is matched here instead of over the network.
|
|
5
|
+
*
|
|
6
|
+
* Adapters that search server-side can still import this to match and rank their
|
|
7
|
+
* own results the same way the built-in picker does.
|
|
8
|
+
*
|
|
9
|
+
* Matching is word-anchored, never substring-anywhere. That distinction is the
|
|
10
|
+
* whole design: a universe of "Spot X / TetherUS" pairs has "eth" sitting inside
|
|
11
|
+
* "t-eth-er" on every single row, so a loose substring rule returns the entire
|
|
12
|
+
* list for the first three characters of "ethusdt". Queries match the start of a
|
|
13
|
+
* word, the start of the ticker, or as a fuzzy subsequence of the ticker - and
|
|
14
|
+
* nothing else.
|
|
15
|
+
*/
|
|
16
|
+
import type { SymbolInfo, SymbolSearchRequest, SymbolSearchResponse } from '../interfaces/IDataAdapter';
|
|
17
|
+
/**
|
|
18
|
+
* Match, rank and page `symbols` against `request`. Non-matching symbols are
|
|
19
|
+
* dropped, not merely sorted down.
|
|
20
|
+
*
|
|
21
|
+
* A parent survives if it or any of its subsymbols matches, so a group stays
|
|
22
|
+
* reachable while searching for one of its contracts. Subsymbols are never
|
|
23
|
+
* hoisted into the result - the picker renders them nested under their parent.
|
|
24
|
+
*/
|
|
25
|
+
export declare function searchSymbolsLocally(symbols: SymbolInfo[], request: SymbolSearchRequest): SymbolSearchResponse;
|
|
26
|
+
/** Adapters may return a bare array for convenience. Normalize to a response. */
|
|
27
|
+
export declare function normalizeSymbolSearchResponse(result: SymbolSearchResponse | SymbolInfo[]): SymbolSearchResponse;
|
|
28
|
+
/** Cache key for a search. Ignores `signal`, which never affects the result. */
|
|
29
|
+
export declare function symbolSearchCacheKey(request: SymbolSearchRequest): string;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
export type TimeframeUnit = 'none' | 'ms' | 's' | 'm' | 'h' | 'd' | 'w';
|
|
2
|
+
export type Timeframe = {
|
|
3
|
+
/** Human-readable label, e.g. "1m", "5m", "1h", "213m" */
|
|
4
|
+
label: string;
|
|
5
|
+
/** Duration of ONE candle/bar in nanoseconds (also used as the view snap span multiplier) */
|
|
6
|
+
barNs: bigint;
|
|
7
|
+
/** Default number of bars to show in the viewport when this TF is selected */
|
|
8
|
+
defaultBars: number;
|
|
9
|
+
/** Whether this is a built-in preset (false = user-created custom) */
|
|
10
|
+
isPreset: boolean;
|
|
11
|
+
};
|
|
12
|
+
export declare const DEFAULT_BARS: Record<string, number>;
|
|
13
|
+
export declare const PRESET_TIMEFRAMES: Timeframe[];
|
|
14
|
+
/**
|
|
15
|
+
* Resolve a timeframe LABEL (e.g. "5m", "213m") back into a Timeframe - a preset
|
|
16
|
+
* when one matches, else a parsed custom one. Lenient: falls back to 1m on an
|
|
17
|
+
* unrecognized label rather than throwing, so a restore never hard-fails.
|
|
18
|
+
*/
|
|
19
|
+
export declare function resolveTimeframe(label: string): Timeframe;
|
|
20
|
+
/**
|
|
21
|
+
* Resolve a raw bar duration (ns) into a full Timeframe. Reuses a built-in
|
|
22
|
+
* preset when one matches exactly; otherwise synthesizes the label and a
|
|
23
|
+
* sensible defaultBars. Used to give data adapters the rich timeframe object
|
|
24
|
+
* for whatever resolution the engine actually decided to fetch at.
|
|
25
|
+
*/
|
|
26
|
+
export declare function timeframeFromBarNs(barNs: bigint): Timeframe;
|
|
27
|
+
/**
|
|
28
|
+
* Given a timeframe and optional bar count, return the total nanosecond span
|
|
29
|
+
* that should be visible in the viewport.
|
|
30
|
+
*/
|
|
31
|
+
export declare function tfViewSpan(tf: Timeframe, bars?: number): bigint;
|
|
32
|
+
/**
|
|
33
|
+
* Parse a user-entered string like "213m", "2h", "45s", "3d" into a Timeframe.
|
|
34
|
+
* Returns null if the input is invalid.
|
|
35
|
+
*/
|
|
36
|
+
export declare function parseCustomTimeframe(input: string): Timeframe | null;
|
|
37
|
+
/**
|
|
38
|
+
* Snap tMin to the nearest bar boundary aligned to Unix epoch.
|
|
39
|
+
* This keeps grid lines consistent regardless of where you're panning.
|
|
40
|
+
*/
|
|
41
|
+
export declare function snapToBars(ts: bigint, barNs: bigint): bigint;
|
|
42
|
+
export declare function loadCustomTimeframes(): Timeframe[];
|
|
43
|
+
export declare function saveCustomTimeframes(tfs: Timeframe[]): void;
|
|
44
|
+
export declare const DEFAULT_FAVORITE_LABELS: string[];
|
|
45
|
+
export declare function loadFavoriteTimeframes(): string[];
|
|
46
|
+
export declare function saveFavoriteTimeframes(labels: string[]): void;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { ChartSettings } from './types/chart-settings';
|
|
2
|
+
/**
|
|
3
|
+
* Map `tradingview.chartproperties` (plus the separately-stored
|
|
4
|
+
* `mainSeriesProperties`, which the library keeps more current) onto our settings.
|
|
5
|
+
* Returns null when there's nothing to import.
|
|
6
|
+
*/
|
|
7
|
+
export declare function readTradingViewChartSettings(): Partial<ChartSettings> | null;
|
|
8
|
+
/**
|
|
9
|
+
* Map `tradingview.chart.favoriteDrawings` onto our drawing tool ids, dropping
|
|
10
|
+
* tools we don't implement. Returns null when there's nothing to import.
|
|
11
|
+
*/
|
|
12
|
+
export declare function readTradingViewFavoriteDrawings(): string[] | null;
|
|
13
|
+
/** True when this browser has TradingView preferences worth importing. */
|
|
14
|
+
export declare function hasTradingViewSettings(): boolean;
|
|
15
|
+
export interface TradingViewImportResult {
|
|
16
|
+
/** Chart settings (colors, grid, margins, chart type, …) were written. */
|
|
17
|
+
settings: boolean;
|
|
18
|
+
/** Favorite drawing tools were written. */
|
|
19
|
+
favorites: boolean;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Seed empty ChristTrade preferences from TradingView's.
|
|
23
|
+
*
|
|
24
|
+
* Each target is imported independently and only when currently unset, so a user
|
|
25
|
+
* who has customized colors but never starred a drawing still gets their
|
|
26
|
+
* favorites across. Runs at most once per device unless `force` is passed.
|
|
27
|
+
*/
|
|
28
|
+
export declare function importTradingViewSettings(opts?: {
|
|
29
|
+
force?: boolean;
|
|
30
|
+
}): TradingViewImportResult;
|
|
31
|
+
/** Forget that the import ran, so the next chart construction retries it. */
|
|
32
|
+
export declare function resetTradingViewImport(): void;
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import type { FootprintMode } from './footprint';
|
|
2
|
+
import type { ChartType } from './index';
|
|
3
|
+
export type ChartSettings = {
|
|
4
|
+
chartType: ChartType;
|
|
5
|
+
upBodyColor: string;
|
|
6
|
+
downBodyColor: string;
|
|
7
|
+
upWickColor: string;
|
|
8
|
+
downWickColor: string;
|
|
9
|
+
upBorderColor: string;
|
|
10
|
+
downBorderColor: string;
|
|
11
|
+
wickColorMatchesBody: boolean;
|
|
12
|
+
borderColorMatchesBody: boolean;
|
|
13
|
+
wickWidth: number;
|
|
14
|
+
borderWidth: number;
|
|
15
|
+
drawEmptyCandles: boolean;
|
|
16
|
+
baselineValue: number | null;
|
|
17
|
+
renkoBrickSize: number | null;
|
|
18
|
+
kagiReversal: number | null;
|
|
19
|
+
lineBreakCount: number;
|
|
20
|
+
footprintMode: FootprintMode;
|
|
21
|
+
footprintVolume: 'none' | 'split' | 'total';
|
|
22
|
+
footprintImbalanceRatio: number;
|
|
23
|
+
footprintStackMinCount: number;
|
|
24
|
+
footprintShowStackedImbalance: boolean;
|
|
25
|
+
footprintShowAbsorption: boolean;
|
|
26
|
+
footprintShowUnfinishedAuction: boolean;
|
|
27
|
+
footprintShowDiagonalImbalance: boolean;
|
|
28
|
+
footprintDiagRatio: number;
|
|
29
|
+
footprintAbsorptionMult: number;
|
|
30
|
+
footprintAbsorptionDeltaFrac: number;
|
|
31
|
+
priceScaleMode: 'normal' | 'log' | 'percent';
|
|
32
|
+
autoScale: boolean;
|
|
33
|
+
priceAxisResizeSensitivity: number;
|
|
34
|
+
invertScale: boolean;
|
|
35
|
+
allowLabelOverlap: boolean;
|
|
36
|
+
/** Smoothly ease the live price line + axis pills toward each new value instead of snapping. */
|
|
37
|
+
animatePriceUpdates: boolean;
|
|
38
|
+
scaleMarginTop: number;
|
|
39
|
+
scaleMarginBottom: number;
|
|
40
|
+
showGrid: boolean;
|
|
41
|
+
gridHorizontalColor: string;
|
|
42
|
+
gridVerticalColor: string;
|
|
43
|
+
crosshairMode: 'normal' | 'magnet' | 'hidden';
|
|
44
|
+
crosshairColor: string;
|
|
45
|
+
crosshairWidth: number;
|
|
46
|
+
crosshairDash: number[];
|
|
47
|
+
showBreaks: boolean;
|
|
48
|
+
breaksColor: string;
|
|
49
|
+
breaksWidth: number;
|
|
50
|
+
breaksDash: number[];
|
|
51
|
+
showStatusLine: boolean;
|
|
52
|
+
statusLineOHLC: boolean;
|
|
53
|
+
statusLineVolume: boolean;
|
|
54
|
+
statusLineDelta: boolean;
|
|
55
|
+
statusLineChange: boolean;
|
|
56
|
+
statusLineFontSize: number;
|
|
57
|
+
backgroundColor: string;
|
|
58
|
+
axisBackgroundColor: string;
|
|
59
|
+
showBidLine: boolean;
|
|
60
|
+
showAskLine: boolean;
|
|
61
|
+
showMidLine: boolean;
|
|
62
|
+
showLastTradeLine: boolean;
|
|
63
|
+
showFills: boolean;
|
|
64
|
+
showTradeDots: boolean;
|
|
65
|
+
tradeDotsSizeMult: number;
|
|
66
|
+
showHeatmap: boolean;
|
|
67
|
+
heatmapContrast: number;
|
|
68
|
+
heatmapColorBid: string;
|
|
69
|
+
heatmapColorAsk: string;
|
|
70
|
+
resamplingDebounce: number;
|
|
71
|
+
priceLineVisible: boolean;
|
|
72
|
+
priceLineColor: string;
|
|
73
|
+
sessionHighlightEnabled: boolean;
|
|
74
|
+
sessionHighlightColor: string;
|
|
75
|
+
horizonScrollEasing: 'none' | 'linear' | 'easeOut' | 'easeInOut';
|
|
76
|
+
horizonScrollDuration: number;
|
|
77
|
+
timezone: string;
|
|
78
|
+
use24HourClock: boolean;
|
|
79
|
+
showTimezoneLabel: boolean;
|
|
80
|
+
/**
|
|
81
|
+
* Settings belonging to plugin chart types, keyed by chart type id. Each
|
|
82
|
+
* plugin owns its own bag - see `ChartTypePlugin.settingsSchema`.
|
|
83
|
+
*/
|
|
84
|
+
pluginSettings: Record<string, Record<string, unknown>>;
|
|
85
|
+
};
|
|
86
|
+
export declare const DEFAULT_CHART_SETTINGS: ChartSettings;
|
|
87
|
+
/** Keys whose value differs from DEFAULT_CHART_SETTINGS (deep value compare). */
|
|
88
|
+
export declare function diffChartSettings(settings: ChartSettings): Partial<ChartSettings>;
|
|
89
|
+
/** Re-expand a settings diff back onto the current defaults. */
|
|
90
|
+
export declare function mergeChartSettings(diff?: Partial<ChartSettings>): ChartSettings;
|