@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,135 @@
|
|
|
1
|
+
import type { TradeLine } from '../lib/types';
|
|
2
|
+
import { type Order, type Fill, type Position, type BracketAmendment, type PriceTick, type TradingEvent } from '../lib/types/trading-types';
|
|
3
|
+
export interface UseTradingStateOptions {
|
|
4
|
+
/**
|
|
5
|
+
* Subscribe to all trading lifecycle events.
|
|
6
|
+
* Stable reference - wrap in useCallback if defined inline.
|
|
7
|
+
*/
|
|
8
|
+
onEvent?: (event: TradingEvent) => void;
|
|
9
|
+
/**
|
|
10
|
+
* Override the PnL label shown in position line pills.
|
|
11
|
+
* Default: "+$420.00 - +2.10%"
|
|
12
|
+
*/
|
|
13
|
+
formatPnlLabel?: (pnl: number, pct: number) => string;
|
|
14
|
+
/**
|
|
15
|
+
* Minimum tick size - used to snap bracket order line prices on drag.
|
|
16
|
+
*/
|
|
17
|
+
tickSize?: number;
|
|
18
|
+
/**
|
|
19
|
+
* Dollar value per 1 price-unit move per contract.
|
|
20
|
+
* Sourced from SymbolInfo.contract.multiplier when available.
|
|
21
|
+
* Falls back to per-symbol string matching when omitted.
|
|
22
|
+
*/
|
|
23
|
+
tickValue?: number;
|
|
24
|
+
/**
|
|
25
|
+
* Which price to use for unrealized PnL mark.
|
|
26
|
+
*
|
|
27
|
+
* 'conservative' (default) - bid for long positions, ask for short.
|
|
28
|
+
* This is the exchange-standard mark-to-market convention: it reflects
|
|
29
|
+
* the price you would actually receive if you exited right now.
|
|
30
|
+
* A long exits by selling -> filled at bid.
|
|
31
|
+
* A short exits by buying -> filled at ask.
|
|
32
|
+
*
|
|
33
|
+
* 'mid' - midpoint of bid/ask. Overstates PnL by half the spread on
|
|
34
|
+
* both sides. Useful for display purposes only.
|
|
35
|
+
*
|
|
36
|
+
* 'last' - last trade price. Natural for replay/backtest scenarios.
|
|
37
|
+
* Falls back to mid if no last price is available.
|
|
38
|
+
*
|
|
39
|
+
* 'bid' - always bid regardless of side.
|
|
40
|
+
* 'ask' - always ask regardless of side.
|
|
41
|
+
*/
|
|
42
|
+
markMode?: 'conservative' | 'bid' | 'ask' | 'mid' | 'last';
|
|
43
|
+
/**
|
|
44
|
+
* If true, bracket TP/SL lines are only shown when the parent position
|
|
45
|
+
* line is hovered. Default: false (always visible).
|
|
46
|
+
*/
|
|
47
|
+
bracketLinesOnHoverOnly?: boolean;
|
|
48
|
+
onUpdatePosition?: (position: Position) => void;
|
|
49
|
+
onUpdateOrder?: (order: Order) => void;
|
|
50
|
+
/**
|
|
51
|
+
* Called when the user drags a working order line to a new price.
|
|
52
|
+
* You should send the amend request to your broker here.
|
|
53
|
+
*/
|
|
54
|
+
onAmendOrder?: (orderId: string, newPrice: number) => void;
|
|
55
|
+
/**
|
|
56
|
+
* Called when the user drags a TP or SL bracket line to a new price.
|
|
57
|
+
* Receives a full BracketAmendment so your broker adapter has everything
|
|
58
|
+
* it needs: position id, which side, the array index, the level id (if
|
|
59
|
+
* you assigned one), the new price and the qty of that level.
|
|
60
|
+
*/
|
|
61
|
+
onAmendBracket?: (amendment: BracketAmendment) => void;
|
|
62
|
+
/**
|
|
63
|
+
* Called when the user clicks the x button on an order line.
|
|
64
|
+
*/
|
|
65
|
+
onCancelOrder?: (orderId: string) => void;
|
|
66
|
+
/**
|
|
67
|
+
* Called when the user clicks the x button on a position line.
|
|
68
|
+
*/
|
|
69
|
+
onClosePosition?: (positionId: string) => void;
|
|
70
|
+
/**
|
|
71
|
+
* Called when the user clicks the ↕ (reverse) button on a position line.
|
|
72
|
+
*/
|
|
73
|
+
onReversePosition?: (positionId: string) => void;
|
|
74
|
+
/**
|
|
75
|
+
* Called when user right-clicks any trade line.
|
|
76
|
+
*/
|
|
77
|
+
onContextMenu?: (kind: 'order' | 'position', id: string, price: number, y: number) => void;
|
|
78
|
+
}
|
|
79
|
+
export interface TradingState {
|
|
80
|
+
orders: Map<string, Order>;
|
|
81
|
+
positions: Map<string, Position>;
|
|
82
|
+
fills: Fill[];
|
|
83
|
+
tradeLines: TradeLine[];
|
|
84
|
+
}
|
|
85
|
+
export interface UseTradingStateReturn extends TradingState {
|
|
86
|
+
upsertOrder: (order: Order) => void;
|
|
87
|
+
removeOrder: (orderId: string) => void;
|
|
88
|
+
applyFill: (fill: Fill) => void;
|
|
89
|
+
upsertPosition: (position: Position) => void;
|
|
90
|
+
toast: (title: string, options?: {
|
|
91
|
+
description?: string;
|
|
92
|
+
tone?: 'profit' | 'loss' | 'neutral';
|
|
93
|
+
}) => void;
|
|
94
|
+
removePosition: (positionId: string) => void;
|
|
95
|
+
tick: (priceTick: PriceTick) => void;
|
|
96
|
+
syncOrders: (orders: Order[]) => void;
|
|
97
|
+
syncPositions: (positions: Position[]) => void;
|
|
98
|
+
reset: () => void;
|
|
99
|
+
/**
|
|
100
|
+
* The canonical lines map. Pass as `linesRef` to useTradeLines so drag
|
|
101
|
+
* price updates bypass React state during the drag and go straight to the
|
|
102
|
+
* canvas via redraw().
|
|
103
|
+
*/
|
|
104
|
+
linesRef: React.MutableRefObject<Map<string, TradeLine>>;
|
|
105
|
+
/**
|
|
106
|
+
* Id of the bracket line currently being dragged. Pass to useTradeLines so
|
|
107
|
+
* it can flag the active drag; while set, line rebuilds (e.g. from playback
|
|
108
|
+
* ticks) preserve that line's live price instead of reverting it.
|
|
109
|
+
*/
|
|
110
|
+
draggingLineIdRef: React.MutableRefObject<string | null>;
|
|
111
|
+
/**
|
|
112
|
+
* Register the chart's redraw callback. Call this once after the chart
|
|
113
|
+
* mounts, e.g. in a useEffect. Enables handle.setLabel / handle.setPrice
|
|
114
|
+
* to repaint the canvas without a React re-render.
|
|
115
|
+
*
|
|
116
|
+
* useEffect(() => {
|
|
117
|
+
* trading.registerRedraw(redraw);
|
|
118
|
+
* }, [redraw]);
|
|
119
|
+
*/
|
|
120
|
+
registerRedraw: (fn: () => void) => void;
|
|
121
|
+
/**
|
|
122
|
+
* Pass this directly to useTradeLines as the `onGhostMove` prop.
|
|
123
|
+
*
|
|
124
|
+
* When the user drags a ghost TP/SL pill:
|
|
125
|
+
* - If a real level already exists at that slot index, its price is updated.
|
|
126
|
+
* - If the slot is new (index === existing levels length), a new level is
|
|
127
|
+
* appended with qty defaulting to the full remaining position qty minus
|
|
128
|
+
* the qty already committed to other levels of the same kind.
|
|
129
|
+
* - onAmendBracket is called with the full BracketAmendment.
|
|
130
|
+
*
|
|
131
|
+
* lineId format expected: "position:<positionId>"
|
|
132
|
+
*/
|
|
133
|
+
handleGhostMove: (lineId: string, kind: 'tp' | 'sl', index: number, price: number) => void;
|
|
134
|
+
}
|
|
135
|
+
export declare function useTradingState(options?: UseTradingStateOptions): UseTradingStateReturn;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import type { Fill, Order, Position, PositionClose } from '../lib/types/trading-types';
|
|
2
|
+
export interface AccountSnapshot {
|
|
3
|
+
balance: number;
|
|
4
|
+
equity: number;
|
|
5
|
+
realizedPnl: number;
|
|
6
|
+
unrealizedPnl: number;
|
|
7
|
+
openPositionCount: number;
|
|
8
|
+
currency: string;
|
|
9
|
+
}
|
|
10
|
+
export interface IAccountAdapter {
|
|
11
|
+
readonly id: string;
|
|
12
|
+
/**
|
|
13
|
+
* AccountManager calls this once on attach so the adapter can register
|
|
14
|
+
* its push callbacks.
|
|
15
|
+
*/
|
|
16
|
+
attach(callbacks: AccountAdapterCallbacks): void;
|
|
17
|
+
/**
|
|
18
|
+
* Called when AccountManager is destroyed or the adapter is swapped out.
|
|
19
|
+
*/
|
|
20
|
+
detach(): void;
|
|
21
|
+
destroy(): void;
|
|
22
|
+
}
|
|
23
|
+
export interface AccountAdapterCallbacks {
|
|
24
|
+
onFill: (fill: Fill & {
|
|
25
|
+
ts: bigint;
|
|
26
|
+
}) => void;
|
|
27
|
+
onPositionUpdate: (position: Position & {
|
|
28
|
+
ts: bigint;
|
|
29
|
+
}) => void;
|
|
30
|
+
onPositionClose: (close: PositionClose & {
|
|
31
|
+
ts: bigint;
|
|
32
|
+
}) => void;
|
|
33
|
+
onBalanceUpdate: (balance: number, ts: bigint) => void;
|
|
34
|
+
/** Optional - adapters that surface individual orders can push them here. */
|
|
35
|
+
onOrderUpdate?: (order: Order & {
|
|
36
|
+
ts: bigint;
|
|
37
|
+
}) => void;
|
|
38
|
+
}
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import { SessionMapper } from '../core/SessionMapper';
|
|
2
|
+
import { type SessionStatus } from '../core/SessionUtils';
|
|
3
|
+
import type { TradingSession } from './IDataAdapter';
|
|
4
|
+
import type { ViewBounds } from '../lib/types';
|
|
5
|
+
export type PriceScaleMode = 'linear' | 'log' | 'percent';
|
|
6
|
+
export interface ICoordinateTransformer {
|
|
7
|
+
tsToX(ts: bigint, view: ViewBounds, chartW: number): number;
|
|
8
|
+
priceToY(price: number, view: ViewBounds, chartH: number): number;
|
|
9
|
+
xToTs(x: number, view: ViewBounds, chartW: number): bigint;
|
|
10
|
+
yToPrice(y: number, view: ViewBounds, chartH: number): number;
|
|
11
|
+
}
|
|
12
|
+
export declare class LiveTransformer {
|
|
13
|
+
private view;
|
|
14
|
+
private mode;
|
|
15
|
+
private _sessionMapper;
|
|
16
|
+
private _barNs;
|
|
17
|
+
private _barAlignedStarts;
|
|
18
|
+
private _sessionMapperVersion;
|
|
19
|
+
private _ordinal;
|
|
20
|
+
setOrdinal(columnTs: BigInt64Array | null): void;
|
|
21
|
+
getOrdinal(): BigInt64Array | null;
|
|
22
|
+
private _ordinalActive;
|
|
23
|
+
setSessionMapper(mapper: SessionMapper | null): void;
|
|
24
|
+
getSessionMapper(): SessionMapper | null;
|
|
25
|
+
/** Fractional column index for a timestamp (monotonic; extrapolates past the ends). */
|
|
26
|
+
tsToFracIndex(ts: bigint): number;
|
|
27
|
+
/** Inverse of tsToFracIndex (lerps between columns; extrapolates past the ends). */
|
|
28
|
+
indexToTs(idx: number): bigint;
|
|
29
|
+
private _idxMin;
|
|
30
|
+
private _idxMax;
|
|
31
|
+
/** Pixel x for a (fractional) column index under the current view. */
|
|
32
|
+
indexToX(i: number, chartW: number): number;
|
|
33
|
+
/** Fractional column index at a pixel x under the current view. */
|
|
34
|
+
xToIndex(x: number, chartW: number): number;
|
|
35
|
+
/** Fast (index) => x closure for the current frame (renderer hot path). */
|
|
36
|
+
makeIndexToXFn(chartW: number): (i: number) => number;
|
|
37
|
+
private _session;
|
|
38
|
+
setSession(session: TradingSession | null): void;
|
|
39
|
+
/** Returns the market status (open/closed/pre-post/always) for any UTC ns timestamp. */
|
|
40
|
+
getSessionStatus(ts: bigint): SessionStatus;
|
|
41
|
+
/**
|
|
42
|
+
* Must be called whenever the active timeframe changes. Triggers a recompute
|
|
43
|
+
* of the per-session bar-alignment offsets on next access.
|
|
44
|
+
*/
|
|
45
|
+
setBarNs(barNs: bigint): void;
|
|
46
|
+
private _ensureBarAlignedStarts;
|
|
47
|
+
/**
|
|
48
|
+
* Map a real UTC timestamp to bar-aligned market time.
|
|
49
|
+
*
|
|
50
|
+
* - Inside segment i: barAlignedStarts[i] + (ts - seg.realStart)
|
|
51
|
+
* - In a gap between sessions: linearly interpolated into the padding zone
|
|
52
|
+
* of the previous segment (preserves continuity during pan/zoom)
|
|
53
|
+
* - Before first segment / after last segment: linear extrapolation
|
|
54
|
+
*/
|
|
55
|
+
private _tsToBarAligned;
|
|
56
|
+
/**
|
|
57
|
+
* Inverse of _tsToBarAligned.
|
|
58
|
+
* - In segment i's real zone: exact real timestamp
|
|
59
|
+
* - In segment i's padding zone: linearly mapped back to real gap timestamp
|
|
60
|
+
* - Before/after covered range: linear extrapolation
|
|
61
|
+
*/
|
|
62
|
+
private _barAlignedToTs;
|
|
63
|
+
/** Called by ChartInner on every view change (pan, zoom, data load). */
|
|
64
|
+
update(view: ViewBounds): void;
|
|
65
|
+
/**
|
|
66
|
+
* Called by ChartInner when ChartSettings.priceScaleMode changes.
|
|
67
|
+
* All subsequent priceToY / yToPrice calls use the new math automatically.
|
|
68
|
+
*/
|
|
69
|
+
setScaleMode(mode: PriceScaleMode): void;
|
|
70
|
+
getScaleMode(): PriceScaleMode;
|
|
71
|
+
getView(): ViewBounds;
|
|
72
|
+
tsToX(ts: bigint, chartW: number): number;
|
|
73
|
+
/**
|
|
74
|
+
* Returns a fast (ts: bigint) => x closure for the current view + chartW.
|
|
75
|
+
* Computes mMin and scale once at call time (2 binary searches total instead
|
|
76
|
+
* of 2N), then uses a per-closure segment hint so sequential point access
|
|
77
|
+
* (the common case for lines and fills) is O(1) per point.
|
|
78
|
+
* Call once per draw command; pass the closure to each point in the series.
|
|
79
|
+
*/
|
|
80
|
+
makeTsToXFn(chartW: number): (ts: bigint) => number;
|
|
81
|
+
/**
|
|
82
|
+
* Returns a fast (price: number) => y closure for the current frame.
|
|
83
|
+
* Linear path is fully pre-baked; log/percent fall back to the method.
|
|
84
|
+
*/
|
|
85
|
+
makePriceToYFn(chartH: number): (price: number) => number;
|
|
86
|
+
priceToY(price: number, chartH: number): number;
|
|
87
|
+
xToTs(x: number, chartW: number): bigint;
|
|
88
|
+
yToPrice(y: number, chartH: number): number;
|
|
89
|
+
/**
|
|
90
|
+
* Pixel width of one bar at the current view and canvas size.
|
|
91
|
+
* Use in renderer instead of computing barPx from tRange manually.
|
|
92
|
+
*/
|
|
93
|
+
getBarPx(chartW: number): number;
|
|
94
|
+
tsToXAt(ts: bigint, view: ViewBounds, chartW: number): number;
|
|
95
|
+
priceToYAt(price: number, view: ViewBounds, chartH: number): number;
|
|
96
|
+
xToTsAt(x: number, view: ViewBounds, chartW: number): bigint;
|
|
97
|
+
yToPriceAt(y: number, view: ViewBounds, chartH: number): number;
|
|
98
|
+
private _linearPriceToY;
|
|
99
|
+
private _linearYToPrice;
|
|
100
|
+
private _logPriceToY;
|
|
101
|
+
private _logYToPrice;
|
|
102
|
+
private _pctPriceToY;
|
|
103
|
+
private _pctYToPrice;
|
|
104
|
+
}
|
|
105
|
+
export type TransformedDrawHook = (ctx: CanvasRenderingContext2D, transformer: LiveTransformer) => void;
|
|
@@ -0,0 +1,402 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The single source of truth for how data enters DepthChart.
|
|
3
|
+
*/
|
|
4
|
+
export type { MboEvent } from '../lib/types';
|
|
5
|
+
import { ReactNode } from 'react';
|
|
6
|
+
import type { Timeframe } from '../lib/timeframes';
|
|
7
|
+
export type DataLevel = 'l3' | 'l2' | 'ohlcv' | 'tick';
|
|
8
|
+
export type DayOfWeek = 'Mon' | 'Tue' | 'Wed' | 'Thu' | 'Fri' | 'Sat' | 'Sun';
|
|
9
|
+
export interface SessionCorrection {
|
|
10
|
+
/** ISO date: '2024-11-29' */
|
|
11
|
+
date: string;
|
|
12
|
+
/** Time range in HHMM-HHMM format: '0930-1300' */
|
|
13
|
+
hours: string;
|
|
14
|
+
}
|
|
15
|
+
export interface TradingSubsession {
|
|
16
|
+
id: string;
|
|
17
|
+
label: string;
|
|
18
|
+
/** HHMM-HHMM, e.g. '0400-0930'. Overnight: '1800-0000' */
|
|
19
|
+
hours: string;
|
|
20
|
+
days?: DayOfWeek[];
|
|
21
|
+
}
|
|
22
|
+
export interface TradingSession {
|
|
23
|
+
/**
|
|
24
|
+
* Trading hours in HHMM-HHMM format.
|
|
25
|
+
* '24/7' or 'always' -> never closed.
|
|
26
|
+
* Overnight sessions work naturally: '1800-1700' means open 6pm, close 5pm next day.
|
|
27
|
+
*/
|
|
28
|
+
hours: '24/7' | 'always' | string;
|
|
29
|
+
/** IANA timezone, e.g. 'America/New_York'. Required unless hours is '24/7'/'always'. */
|
|
30
|
+
timezone: string;
|
|
31
|
+
/** Trading days. Defaults to Mon-Fri when omitted. */
|
|
32
|
+
days?: DayOfWeek[];
|
|
33
|
+
/** Named subsessions (pre/post market, etc.) - purely for display. */
|
|
34
|
+
subsessions?: TradingSubsession[];
|
|
35
|
+
/** Non-trading holidays. ISO dates: ['2024-11-28', '2024-12-25'] */
|
|
36
|
+
holidays?: string[];
|
|
37
|
+
/** Partial-session corrections, e.g. early close days. */
|
|
38
|
+
corrections?: SessionCorrection[];
|
|
39
|
+
}
|
|
40
|
+
export interface FractionalFormat {
|
|
41
|
+
/** Denominator of the fraction. E.g. 32 for 1/32nds (T-Bonds). */
|
|
42
|
+
denominator: number;
|
|
43
|
+
/** Sub-denominator for 1/4 of 1/32 etc. (ZF, ZB). */
|
|
44
|
+
subDenominator?: number;
|
|
45
|
+
}
|
|
46
|
+
export interface PriceFormat {
|
|
47
|
+
/** Decimal places for display, e.g. 2 for 19234.25 */
|
|
48
|
+
precision: number;
|
|
49
|
+
/** Minimum price increment, e.g. 0.25 for NQ */
|
|
50
|
+
minTick: number;
|
|
51
|
+
/** Set for fractional instruments (T-Bonds, Corn futures). */
|
|
52
|
+
fractional?: FractionalFormat;
|
|
53
|
+
}
|
|
54
|
+
export type SymbolType = 'future' | 'stock' | 'forex' | 'crypto' | 'index' | 'option' | 'spread' | 'bond' | 'etf' | 'custom';
|
|
55
|
+
/**
|
|
56
|
+
* How an instrument trades. Reached through `SymbolInfo.contract`, which is the
|
|
57
|
+
* only thing that owns it - the account holds a balance, not a tick size, so
|
|
58
|
+
* nothing about sizing or pricing should be read off it. Resolve one with
|
|
59
|
+
* `specForSymbol(info)`.
|
|
60
|
+
*/
|
|
61
|
+
export interface ContractSpec {
|
|
62
|
+
/** Point value / multiplier. E.g. 20 for NQ ($20/pt). */
|
|
63
|
+
multiplier?: number;
|
|
64
|
+
/** Minimum price increment (alias for priceFormat.minTick). */
|
|
65
|
+
tickSize?: number;
|
|
66
|
+
/** Cash value of one tick. */
|
|
67
|
+
tickValue?: number;
|
|
68
|
+
/** Settlement currency. */
|
|
69
|
+
currency?: string;
|
|
70
|
+
/**
|
|
71
|
+
* Smallest tradable increment of quantity.
|
|
72
|
+
*
|
|
73
|
+
* 1 for a listed future, where a third of a contract does not exist. Spot
|
|
74
|
+
* and perpetual venues are the other case entirely - Binance will sell you
|
|
75
|
+
* 0.001 BTC - so this is what separates "size" from "contract count", and
|
|
76
|
+
* order sizing floors to it rather than to whole numbers.
|
|
77
|
+
*
|
|
78
|
+
* Defaults to 1, which is the safe reading for anything that forgot to say.
|
|
79
|
+
*/
|
|
80
|
+
qtyStep?: number;
|
|
81
|
+
/** Smallest order the venue will accept. Defaults to `qtyStep`. */
|
|
82
|
+
minQty?: number;
|
|
83
|
+
/** ISO date of expiry. */
|
|
84
|
+
expiresAt?: string;
|
|
85
|
+
/** True for continuous/front-month contracts (/NQ1 etc.) */
|
|
86
|
+
continuous?: boolean;
|
|
87
|
+
}
|
|
88
|
+
export type SymbolIcon =
|
|
89
|
+
/** Shorthand for { src }. */
|
|
90
|
+
string
|
|
91
|
+
/** Image URL, data: URI, or imported SVG path. */
|
|
92
|
+
| {
|
|
93
|
+
src: string;
|
|
94
|
+
alt?: string;
|
|
95
|
+
}
|
|
96
|
+
/** Monogram fallback - depth draws the chip. */
|
|
97
|
+
| {
|
|
98
|
+
text: string;
|
|
99
|
+
color?: string;
|
|
100
|
+
}
|
|
101
|
+
/** Escape hatch: any component, sized by the renderer. */
|
|
102
|
+
| {
|
|
103
|
+
render: (props: {
|
|
104
|
+
size: number;
|
|
105
|
+
}) => ReactNode;
|
|
106
|
+
};
|
|
107
|
+
export interface SymbolInfo {
|
|
108
|
+
symbol: string;
|
|
109
|
+
description?: string;
|
|
110
|
+
/** Full name shown in the symbol picker. Falls back to description. */
|
|
111
|
+
longName?: string;
|
|
112
|
+
exchange?: string;
|
|
113
|
+
/** Listed (primary) exchange, if different from routing exchange. */
|
|
114
|
+
listedExchange?: string;
|
|
115
|
+
/** Instrument type. */
|
|
116
|
+
type: SymbolType;
|
|
117
|
+
/** Data level this adapter produces. */
|
|
118
|
+
dataLevel: DataLevel;
|
|
119
|
+
/** Icon for this symbol. */
|
|
120
|
+
icon?: SymbolIcon;
|
|
121
|
+
legendIcon?: SymbolIcon;
|
|
122
|
+
/**
|
|
123
|
+
* Price formatting. When omitted, tickSize is used as a fallback for
|
|
124
|
+
* minTick and precision is inferred from it.
|
|
125
|
+
*/
|
|
126
|
+
priceFormat: PriceFormat;
|
|
127
|
+
/** @deprecated Minimum price increment. Fallback for `priceFormat.minTick`. */
|
|
128
|
+
tickSize?: number;
|
|
129
|
+
/**
|
|
130
|
+
* Symbol timezone. Used as the default for session.timezone when not
|
|
131
|
+
* specified there. Falls back to 'UTC'.
|
|
132
|
+
*/
|
|
133
|
+
timezone?: string;
|
|
134
|
+
/** Trading session. When absent, the symbol is treated as 24/7. */
|
|
135
|
+
session?: TradingSession;
|
|
136
|
+
/**
|
|
137
|
+
* How the instrument trades: what a tick is worth, what a point is worth,
|
|
138
|
+
* and the smallest size the venue accepts. The single source for all of it.
|
|
139
|
+
*
|
|
140
|
+
* Every instrument type, not only futures and options - spot crypto has a
|
|
141
|
+
* tick size and a (fractional) size step just as much as a listed contract
|
|
142
|
+
* does, and anything that sizes an order needs both.
|
|
143
|
+
*/
|
|
144
|
+
contract?: ContractSpec;
|
|
145
|
+
/** Locale for number formatting. E.g. 'en-US'. */
|
|
146
|
+
locale?: string;
|
|
147
|
+
/** Volume decimal places. 0 = always integer. Default 0. */
|
|
148
|
+
volumePrecision?: number;
|
|
149
|
+
/** Subsymbols shown in the symbol picker (e.g. individual contracts under /NQ1). */
|
|
150
|
+
subsymbols?: SymbolInfo[];
|
|
151
|
+
/**
|
|
152
|
+
* Extra search terms. The built-in matcher searches these alongside symbol,
|
|
153
|
+
* name and exchange, so `keywords: ['gold', 'bullion']` makes XAUUSD
|
|
154
|
+
* reachable by typing "gold". Adapters that search server-side
|
|
155
|
+
* (`symbolSearch: 'server'`) own their own matching and can ignore this.
|
|
156
|
+
*/
|
|
157
|
+
keywords?: string[];
|
|
158
|
+
/**
|
|
159
|
+
* Ascending-sorted list of barNs values this adapter can natively serve.
|
|
160
|
+
*
|
|
161
|
+
* DataEngine picks the coarsest supported resolution <= the active timeframe
|
|
162
|
+
* for all fetches. When the active timeframe drops below a loaded segment's
|
|
163
|
+
* resolution, DataEngine re-fetches that segment at the finer resolution
|
|
164
|
+
* and emits `data:refine` so ChartInner can replace the stale bars.
|
|
165
|
+
*
|
|
166
|
+
* Example: `[60_000_000_000n, 300_000_000_000n, 3_600_000_000_000n]`
|
|
167
|
+
* declares native support for 1m, 5m, and 1h bars.
|
|
168
|
+
*
|
|
169
|
+
* If omitted or empty, the adapter is assumed to handle any barNs (legacy behavior).
|
|
170
|
+
*/
|
|
171
|
+
supportedResolutions?: bigint[];
|
|
172
|
+
/** Arbitrary extra metadata. Not processed by the engine. */
|
|
173
|
+
meta?: Record<string, unknown>;
|
|
174
|
+
}
|
|
175
|
+
export interface OhlcvBar {
|
|
176
|
+
/** Unix timestamp in milliseconds (ms since epoch). */
|
|
177
|
+
time: number;
|
|
178
|
+
open: number;
|
|
179
|
+
high: number;
|
|
180
|
+
low: number;
|
|
181
|
+
close: number;
|
|
182
|
+
volume: number;
|
|
183
|
+
/** Best bid at bar close. When absent the engine falls back to close minus half a tick. */
|
|
184
|
+
bid?: number;
|
|
185
|
+
/** Best ask at bar close. When absent the engine falls back to close plus half a tick. */
|
|
186
|
+
ask?: number;
|
|
187
|
+
}
|
|
188
|
+
export interface TickEvent {
|
|
189
|
+
/** Unix timestamp in milliseconds (ms since epoch). */
|
|
190
|
+
time: number;
|
|
191
|
+
price: number;
|
|
192
|
+
size: number;
|
|
193
|
+
side: 'B' | 'A' | 'N';
|
|
194
|
+
}
|
|
195
|
+
export interface L2Snapshot {
|
|
196
|
+
/** Unix timestamp in milliseconds (ms since epoch). */
|
|
197
|
+
time: number;
|
|
198
|
+
bids: Array<{
|
|
199
|
+
price: number;
|
|
200
|
+
size: number;
|
|
201
|
+
}>;
|
|
202
|
+
asks: Array<{
|
|
203
|
+
price: number;
|
|
204
|
+
size: number;
|
|
205
|
+
}>;
|
|
206
|
+
}
|
|
207
|
+
/**
|
|
208
|
+
* A half-open time range `[from, to)` since the Unix epoch, with `from` always
|
|
209
|
+
* <= `to` (see {@link FetchRequest.direction} for which edge a fetch extends).
|
|
210
|
+
*
|
|
211
|
+
* The same instant is offered in three units so adapters can use whichever maps
|
|
212
|
+
* cleanest onto their backend: nanoseconds are canonical (full precision); the
|
|
213
|
+
* `Ms` / `Iso` forms are derived conveniences. The ISO strings carry
|
|
214
|
+
* nanosecond precision, e.g. `'2024-05-29T00:00:00.000000000Z'`.
|
|
215
|
+
*
|
|
216
|
+
* Build one with {@link makeTimeRange} so the derived forms stay consistent.
|
|
217
|
+
*/
|
|
218
|
+
export interface TimeRange {
|
|
219
|
+
/** Start, ns since epoch (inclusive). Canonical. */
|
|
220
|
+
fromNs: bigint;
|
|
221
|
+
/** End, ns since epoch (exclusive). Canonical. */
|
|
222
|
+
toNs: bigint;
|
|
223
|
+
/** Start, ms since epoch (inclusive). Truncated from `fromNs`. */
|
|
224
|
+
fromMs: number;
|
|
225
|
+
/** End, ms since epoch (exclusive). Truncated from `toNs`. */
|
|
226
|
+
toMs: number;
|
|
227
|
+
/** Start as a nanosecond-precision ISO 8601 string. */
|
|
228
|
+
fromIso: string;
|
|
229
|
+
/** End as a nanosecond-precision ISO 8601 string. */
|
|
230
|
+
toIso: string;
|
|
231
|
+
}
|
|
232
|
+
/**
|
|
233
|
+
* Nanosecond-precision ISO 8601 string for a ns-since-epoch instant, e.g.
|
|
234
|
+
* `'2024-05-29T00:00:00.000000000Z'`. Use {@link Date} on the `Ms` forms if you
|
|
235
|
+
* only need millisecond precision.
|
|
236
|
+
*/
|
|
237
|
+
export declare function nsToIso(ns: bigint): string;
|
|
238
|
+
/** Build a {@link TimeRange} from ns bounds, filling in the ms/ISO conveniences. */
|
|
239
|
+
export declare function makeTimeRange(fromNs: bigint, toNs: bigint): TimeRange;
|
|
240
|
+
export interface FetchRequest {
|
|
241
|
+
/**
|
|
242
|
+
* The instrument being requested, with its price format, session, data
|
|
243
|
+
* level and any other metadata. Multi-symbol adapters key off
|
|
244
|
+
* `symbolInfo.symbol`; single-symbol adapters can ignore it.
|
|
245
|
+
*/
|
|
246
|
+
symbolInfo: SymbolInfo;
|
|
247
|
+
/**
|
|
248
|
+
* Chronological span to cover. `range.fromNs` is always <= `range.toNs`
|
|
249
|
+
* regardless of `direction` - the bounds are never reversed.
|
|
250
|
+
*/
|
|
251
|
+
range: TimeRange;
|
|
252
|
+
/**
|
|
253
|
+
* Target bar resolution, with its human label and default bar count.
|
|
254
|
+
* Read `timeframe.barNs` for the bar duration in nanoseconds.
|
|
255
|
+
*/
|
|
256
|
+
timeframe: Timeframe;
|
|
257
|
+
/**
|
|
258
|
+
* Which edge of the loaded data this fetch is extending:
|
|
259
|
+
* - `initial` - the first load for a window.
|
|
260
|
+
* - `forward` - newer bars, appended to the right.
|
|
261
|
+
* - `backward` - older bars, prepended to the left.
|
|
262
|
+
*/
|
|
263
|
+
direction: 'initial' | 'forward' | 'backward';
|
|
264
|
+
/**
|
|
265
|
+
* When set, also return bars at this finer resolution (ns) as
|
|
266
|
+
* `supplementalBars`, for smoother playback. The engine sets this
|
|
267
|
+
* automatically from the adapter's getCapabilities().
|
|
268
|
+
*/
|
|
269
|
+
supplementalBarNs?: bigint;
|
|
270
|
+
}
|
|
271
|
+
export interface SupplementalBarSet {
|
|
272
|
+
/** barNs of the finer-resolution data */
|
|
273
|
+
resolution: bigint;
|
|
274
|
+
bars: OhlcvBar[];
|
|
275
|
+
}
|
|
276
|
+
export interface BarResponse {
|
|
277
|
+
/** Raw MBO events (L3). Leave empty for other data levels or _preProcessed. */
|
|
278
|
+
events: import('../lib/types').MboEvent[];
|
|
279
|
+
/** OHLCV bars - populate for dataLevel === 'ohlcv' */
|
|
280
|
+
ohlcvBars?: OhlcvBar[];
|
|
281
|
+
/**
|
|
282
|
+
* Optional finer-resolution bars for the same time range.
|
|
283
|
+
* The engine uses these to produce smoother playback via real prices instead
|
|
284
|
+
* of the synthetic interpolation fallback.
|
|
285
|
+
*/
|
|
286
|
+
supplementalBars?: SupplementalBarSet[];
|
|
287
|
+
/** Tick events - populate for dataLevel === 'tick' */
|
|
288
|
+
ticks?: TickEvent[];
|
|
289
|
+
/** L2 depth snapshots - populate for dataLevel === 'l2' */
|
|
290
|
+
l2Snapshots?: L2Snapshot[];
|
|
291
|
+
hasMore: boolean;
|
|
292
|
+
coveredFrom?: bigint;
|
|
293
|
+
coveredTo?: bigint;
|
|
294
|
+
_preProcessed?: PreProcessedPayload;
|
|
295
|
+
}
|
|
296
|
+
export interface AdapterCapabilities {
|
|
297
|
+
/**
|
|
298
|
+
* Finer-resolution bar granularities this adapter can supply as
|
|
299
|
+
* supplementalBars alongside OHLCV responses (sorted finest-first).
|
|
300
|
+
* E.g. [1_000_000_000n] means S1 data is available.
|
|
301
|
+
*/
|
|
302
|
+
supplementalResolutions?: bigint[];
|
|
303
|
+
/**
|
|
304
|
+
* Who filters symbol searches. See {@link SymbolSearchMode}.
|
|
305
|
+
* Defaults to 'none'.
|
|
306
|
+
*/
|
|
307
|
+
symbolSearch?: SymbolSearchMode;
|
|
308
|
+
/**
|
|
309
|
+
* How long the picker waits after a keystroke before searching, in ms.
|
|
310
|
+
*
|
|
311
|
+
* Defaults to 200 for `symbolSearch: 'server'` - enough to stop a request
|
|
312
|
+
* per character going out over the network - and 0 for 'none', which matches
|
|
313
|
+
* in memory. Override it when the default misreads your adapter: set 0 if you
|
|
314
|
+
* declare 'server' but search a list you already hold in memory, or raise it
|
|
315
|
+
* if each search is expensive or rate-limited.
|
|
316
|
+
*/
|
|
317
|
+
symbolSearchDebounceMs?: number;
|
|
318
|
+
}
|
|
319
|
+
export interface BarPreviewResponse {
|
|
320
|
+
symbol: string;
|
|
321
|
+
bars: {
|
|
322
|
+
open: number;
|
|
323
|
+
high: number;
|
|
324
|
+
low: number;
|
|
325
|
+
close: number;
|
|
326
|
+
volume: number;
|
|
327
|
+
time: number;
|
|
328
|
+
}[];
|
|
329
|
+
}
|
|
330
|
+
export interface PreProcessedPayload {
|
|
331
|
+
compactBuf: ArrayBuffer;
|
|
332
|
+
trades: import('../lib/types').SerialTrade[];
|
|
333
|
+
priceHistory: import('../lib/types').PriceHistory[];
|
|
334
|
+
footprintBars: import('../lib/types/footprint').FootprintBar[];
|
|
335
|
+
dataStart: number;
|
|
336
|
+
dataEnd: number;
|
|
337
|
+
}
|
|
338
|
+
/**
|
|
339
|
+
* Who filters a {@link SymbolSearchRequest}.
|
|
340
|
+
*
|
|
341
|
+
* 'none' (default) - the adapter ignores `query` and the facets and returns its
|
|
342
|
+
* whole universe. The engine calls `searchSymbols` once, caches the result, and
|
|
343
|
+
* matches + ranks locally on every keystroke. Right for any universe small
|
|
344
|
+
* enough to ship to the client.
|
|
345
|
+
*
|
|
346
|
+
* 'server' - the adapter honors `query`, the facets, `limit` and `cursor`. The
|
|
347
|
+
* engine forwards every (debounced) keystroke and does no matching of its own.
|
|
348
|
+
* Right for a broker or exchange with tens of thousands of instruments.
|
|
349
|
+
*/
|
|
350
|
+
export type SymbolSearchMode = 'server' | 'none';
|
|
351
|
+
export interface SymbolSearchRequest {
|
|
352
|
+
/** Free text. `''` means browse: the picker just opened, nothing typed. */
|
|
353
|
+
query: string;
|
|
354
|
+
/** Facet filters. Undefined means "any". */
|
|
355
|
+
type?: SymbolType;
|
|
356
|
+
exchange?: string;
|
|
357
|
+
dataLevel?: DataLevel;
|
|
358
|
+
/** How many results the caller wants. Adapters may return fewer. */
|
|
359
|
+
limit?: number;
|
|
360
|
+
/** Opaque cursor from a previous response. Set when paging in more results. */
|
|
361
|
+
cursor?: string;
|
|
362
|
+
/**
|
|
363
|
+
* Aborted when this search is superseded (the user typed again) or
|
|
364
|
+
* abandoned (the picker closed). Honor it if your transport can - the
|
|
365
|
+
* engine drops late responses either way.
|
|
366
|
+
*/
|
|
367
|
+
signal?: AbortSignal;
|
|
368
|
+
}
|
|
369
|
+
export interface SymbolSearchResponse {
|
|
370
|
+
symbols: SymbolInfo[];
|
|
371
|
+
/** True when more results exist past this page. */
|
|
372
|
+
hasMore?: boolean;
|
|
373
|
+
/** Pass back as `request.cursor` to fetch the next page. */
|
|
374
|
+
cursor?: string;
|
|
375
|
+
}
|
|
376
|
+
export interface IDataAdapter {
|
|
377
|
+
resolveSymbol(symbol: string): SymbolInfo | Promise<SymbolInfo>;
|
|
378
|
+
/**
|
|
379
|
+
* Supply symbols for the picker. Return a bare array to hand over the whole
|
|
380
|
+
* universe and let the engine match locally; return a
|
|
381
|
+
* {@link SymbolSearchResponse} to page results yourself. Which of the two
|
|
382
|
+
* the engine expects is decided by `getCapabilities().symbolSearch`.
|
|
383
|
+
*/
|
|
384
|
+
searchSymbols(request: SymbolSearchRequest): Promise<SymbolSearchResponse | SymbolInfo[]>;
|
|
385
|
+
fetchBars(request: FetchRequest): Promise<BarResponse>;
|
|
386
|
+
fetchPreview?(request: FetchRequest): Promise<BarPreviewResponse>;
|
|
387
|
+
subscribeRealtime?(onBar: (bar: BarResponse) => void): () => void;
|
|
388
|
+
connect?(): Promise<void>;
|
|
389
|
+
destroy?(): void;
|
|
390
|
+
/**
|
|
391
|
+
* Declare what supplemental resolutions this adapter can provide.
|
|
392
|
+
* Called once after resolveSymbol(). The engine attaches the finest
|
|
393
|
+
* declared resolution as supplementalResolution in every FetchRequest.
|
|
394
|
+
*/
|
|
395
|
+
getCapabilities?(): AdapterCapabilities;
|
|
396
|
+
}
|
|
397
|
+
export type DataAdapterErrorCode = 'unauthenticated' | 'forbidden' | 'not_found' | 'no_data' | 'rate_limited' | 'server_error' | 'network_error' | 'decode_error' | 'unknown';
|
|
398
|
+
export declare class DataAdapterError extends Error {
|
|
399
|
+
readonly code: DataAdapterErrorCode;
|
|
400
|
+
readonly httpStatus?: number;
|
|
401
|
+
constructor(code: DataAdapterErrorCode, message: string, httpStatus?: number);
|
|
402
|
+
}
|