@orangecharts/wrun-chart-host 0.15.0 → 0.17.0
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/README.md +2 -0
- package/dist/constants/economic.constants.d.ts +2 -0
- package/dist/constants/economic.constants.js +2 -0
- package/dist/constants/feature-flags.constants.d.ts +13 -5
- package/dist/constants/feature-flags.constants.js +76 -35
- package/dist/constants/feature-limits.constants.d.ts +72 -4
- package/dist/constants/feature-limits.constants.js +104 -24
- package/dist/constants/interval.constants.js +5 -0
- package/dist/constants/kscript-data-interval-restrictions.constants.d.ts +12 -0
- package/dist/constants/kscript-data-interval-restrictions.constants.js +14 -0
- package/dist/constants/marketCapabilities.constants.d.ts +9 -0
- package/dist/constants/marketCapabilities.constants.js +39 -11
- package/dist/constants/typed-indicator-source.leaf.d.ts +7 -0
- package/dist/constants/typed-indicator-source.leaf.js +47 -0
- package/dist/constants/typed-session-history-venue.leaf.d.ts +7 -0
- package/dist/constants/typed-session-history-venue.leaf.js +9 -0
- package/dist/constants/typed-width-fold.leaf.d.ts +52 -0
- package/dist/constants/typed-width-fold.leaf.js +101 -0
- package/dist/constants/typed-width-source.leaf.d.ts +24 -0
- package/dist/constants/typed-width-source.leaf.js +126 -0
- package/dist/constants/typed-width.leaf.d.ts +57 -0
- package/dist/constants/typed-width.leaf.js +78 -0
- package/dist/host-env.d.ts +10 -0
- package/dist/host-env.js +7 -0
- package/dist/host-ports.types.d.ts +23 -17
- package/dist/index.d.ts +4 -0
- package/dist/index.js +4 -0
- package/dist/interfaces/kscript-diagnostics.interface.d.ts +35 -0
- package/dist/interfaces/wrun-runtime.interface.d.ts +66 -3
- package/dist/interfaces/wrun-runtime.interface.js +11 -0
- package/dist/kscript-data/controls/live-trades-merge.util.d.ts +13 -0
- package/dist/kscript-data/controls/live-trades-merge.util.js +16 -1
- package/dist/market-data/billing.interface.d.ts +12 -45
- package/dist/market-data/billing.interface.js +2 -2
- package/dist/replay/replayLadder.js +7 -4
- package/dist/settings-templates/footprint-rows.d.ts +6 -0
- package/dist/settings-templates/footprint-rows.js +6 -0
- package/dist/settings-templates/frvp-fields.js +14 -0
- package/dist/settings-templates/indicator-fields.js +36 -0
- package/dist/settings-templates/tool-tables.generated.js +19 -1
- package/dist/utility/chart/__fixtures__/live-bucket-regular-golden.json +1706 -0
- package/dist/utility/chart/cache-alignment.util.d.ts +42 -0
- package/dist/utility/chart/cache-alignment.util.js +88 -18
- package/dist/utility/chart/calendar-interval.util.d.ts +83 -1
- package/dist/utility/chart/calendar-interval.util.js +152 -4
- package/dist/utility/chart/candle-bar-end.util.d.ts +11 -4
- package/dist/utility/chart/candle-bar-end.util.js +17 -6
- package/dist/utility/chart/chart-time-domain.util.d.ts +3 -0
- package/dist/utility/chart/chart-time-domain.util.js +13 -4
- package/dist/utility/chart/feed-interval.util.d.ts +4 -2
- package/dist/utility/chart/feed-interval.util.js +5 -2
- package/dist/utility/chart/fetch-dedupe-policy.util.d.ts +3 -1
- package/dist/utility/chart/fetch-dedupe-policy.util.js +19 -1
- package/dist/utility/chart/footprint-display-mode.util.d.ts +2 -0
- package/dist/utility/chart/footprint-display-mode.util.js +5 -0
- package/dist/utility/chart/governed-lanes-gate.util.d.ts +46 -0
- package/dist/utility/chart/governed-lanes-gate.util.js +71 -0
- package/dist/utility/chart/governed-lanes-reader-seat.d.ts +14 -0
- package/dist/utility/chart/governed-lanes-reader-seat.js +14 -0
- package/dist/utility/chart/history-wall.util.d.ts +13 -2
- package/dist/utility/chart/history-wall.util.js +11 -4
- package/dist/utility/chart/index-mode-admission.util.js +9 -1
- package/dist/utility/chart/index-mode.util.d.ts +2 -2
- package/dist/utility/chart/index-mode.util.js +12 -6
- package/dist/utility/chart/index-otc.leaf.d.ts +37 -0
- package/dist/utility/chart/index-otc.leaf.js +68 -0
- package/dist/utility/chart/interval-ladder.util.d.ts +5 -2
- package/dist/utility/chart/interval-ladder.util.js +44 -4
- package/dist/utility/chart/interval-registry.util.d.ts +22 -1
- package/dist/utility/chart/interval-registry.util.js +50 -2
- package/dist/utility/chart/kscript-data-interval-restriction.leaf.d.ts +32 -4
- package/dist/utility/chart/kscript-data-interval-restriction.leaf.js +22 -5
- package/dist/utility/chart/kscript-drawing-safe-area.util.d.ts +10 -0
- package/dist/utility/chart/kscript-drawing-safe-area.util.js +30 -3
- package/dist/utility/chart/kscript-legend-entries.util.d.ts +21 -4
- package/dist/utility/chart/kscript-legend-entries.util.js +27 -5
- package/dist/utility/chart/kscript-main-grid-stages.util.js +74 -24
- package/dist/utility/chart/kscript-provenance-keys.util.js +6 -0
- package/dist/utility/chart/kscript-row-name.leaf.d.ts +13 -0
- package/dist/utility/chart/kscript-row-name.leaf.js +18 -0
- package/dist/utility/chart/kscript-venue-policy.util.d.ts +61 -26
- package/dist/utility/chart/kscript-venue-policy.util.js +138 -37
- package/dist/utility/chart/live-bucket.util.d.ts +29 -4
- package/dist/utility/chart/live-bucket.util.js +45 -12
- package/dist/utility/chart/market-session-schedule.util.d.ts +19 -0
- package/dist/utility/chart/market-session-schedule.util.js +2 -1
- package/dist/utility/chart/market-session.util.d.ts +62 -10
- package/dist/utility/chart/market-session.util.js +93 -13
- package/dist/utility/chart/marketKind.util.d.ts +11 -12
- package/dist/utility/chart/marketKind.util.js +45 -13
- package/dist/utility/chart/mixed-mode.util.d.ts +18 -0
- package/dist/utility/chart/om-target.util.js +6 -4
- package/dist/utility/chart/price-precision.util.d.ts +20 -6
- package/dist/utility/chart/price-precision.util.js +34 -7
- package/dist/utility/chart/profile-frame-window.util.d.ts +15 -0
- package/dist/utility/chart/profile-frame-window.util.js +12 -0
- package/dist/utility/chart/rth-session.util.d.ts +3 -1
- package/dist/utility/chart/rth-session.util.js +3 -1
- package/dist/utility/chart/script-source-session.util.d.ts +43 -0
- package/dist/utility/chart/script-source-session.util.js +61 -0
- package/dist/utility/chart/typed-width-grid.util.d.ts +23 -0
- package/dist/utility/chart/typed-width-grid.util.js +203 -0
- package/dist/utility/common/transformations.util.d.ts +6 -0
- package/dist/utility/common/transformations.util.js +28 -4
- package/dist/utility/market-events/market-events.util.js +3 -0
- package/dist/utility/number-format.util.d.ts +14 -1
- package/dist/utility/number-format.util.js +22 -4
- package/dist/utility/scriptEditor/wrun-runtime-diagnostics.leaf.d.ts +24 -1
- package/dist/utility/scriptEditor/wrun-runtime-diagnostics.leaf.js +115 -0
- package/dist/utility/v2/v2-enums.leaf.js +5 -0
- package/dist/utility/wrun/sources/row-lanes/dark_pool.d.ts +2 -1
- package/dist/utility/wrun/sources/row-lanes/dark_pool.js +4 -3
- package/dist/utility/wrun/wrun-batched-marks.util.d.ts +13 -3
- package/dist/utility/wrun/wrun-batched-marks.util.js +96 -17
- package/dist/utility/wrun/wrun-canvases.util.d.ts +4 -2
- package/dist/utility/wrun/wrun-canvases.util.js +7 -12
- package/dist/utility/wrun/wrun-cap-notice.util.d.ts +5 -0
- package/dist/utility/wrun/wrun-cap-notice.util.js +23 -0
- package/dist/utility/wrun/wrun-card-style.util.d.ts +1 -1
- package/dist/utility/wrun/wrun-card-style.util.js +2 -2
- package/dist/utility/wrun/wrun-chart-market-facts.util.d.ts +23 -8
- package/dist/utility/wrun/wrun-chart-market-facts.util.js +24 -9
- package/dist/utility/wrun/wrun-child-overlay-id.util.d.ts +10 -0
- package/dist/utility/wrun/wrun-child-overlay-id.util.js +24 -0
- package/dist/utility/wrun/wrun-cloud-cme-stamp.util.d.ts +72 -0
- package/dist/utility/wrun/wrun-cloud-cme-stamp.util.js +151 -0
- package/dist/utility/wrun/wrun-cme-root-specs.util.d.ts +10 -6
- package/dist/utility/wrun/wrun-cme-root-specs.util.js +19 -13
- package/dist/utility/wrun/wrun-color-facts.util.d.ts +3 -3
- package/dist/utility/wrun/wrun-color-facts.util.js +8 -5
- package/dist/utility/wrun/wrun-colour-tone.lazy.d.ts +20 -0
- package/dist/utility/wrun/wrun-colour-tone.lazy.js +23 -0
- package/dist/utility/wrun/wrun-colour-tone.util.d.ts +14 -0
- package/dist/utility/wrun/wrun-colour-tone.util.js +119 -0
- package/dist/utility/wrun/wrun-dark-pool.util.d.ts +3 -2
- package/dist/utility/wrun/wrun-dark-pool.util.js +5 -4
- package/dist/utility/wrun/wrun-frames.d.ts +1 -1
- package/dist/utility/wrun/wrun-frames.js +2 -2
- package/dist/utility/wrun/wrun-handles.util.d.ts +1 -1
- package/dist/utility/wrun/wrun-handles.util.js +1 -1
- package/dist/utility/wrun/wrun-host.service.d.ts +32 -2
- package/dist/utility/wrun/wrun-host.service.js +44 -2
- package/dist/utility/wrun/wrun-hosted-wire-caps.d.ts +20 -0
- package/dist/utility/wrun/wrun-hosted-wire-caps.js +85 -2
- package/dist/utility/wrun/wrun-hosted-wire.util.d.ts +37 -0
- package/dist/utility/wrun/wrun-hosted-wire.util.js +54 -0
- package/dist/utility/wrun/wrun-hud-looks.util.d.ts +1 -0
- package/dist/utility/wrun/wrun-hud-looks.util.js +6 -11
- package/dist/utility/wrun/wrun-integration-route.util.d.ts +24 -0
- package/dist/utility/wrun/wrun-integration-route.util.js +19 -0
- package/dist/utility/wrun/wrun-live-intake.util.js +17 -1
- package/dist/utility/wrun/wrun-live-patch.util.d.ts +6 -1
- package/dist/utility/wrun/wrun-live-patch.util.js +10 -4
- package/dist/utility/wrun/wrun-live-tick.util.js +64 -5
- package/dist/utility/wrun/wrun-market-size-defaults.leaf.js +40 -6
- package/dist/utility/wrun/wrun-market-size-defaults.util.d.ts +2 -2
- package/dist/utility/wrun/wrun-market-size-defaults.util.js +10 -8
- package/dist/utility/wrun/wrun-overlay-drivers.util.d.ts +3 -0
- package/dist/utility/wrun/wrun-overlay-drivers.util.js +3 -0
- package/dist/utility/wrun/wrun-overlay-run.util.d.ts +17 -0
- package/dist/utility/wrun/wrun-overlay-run.util.js +318 -55
- package/dist/utility/wrun/wrun-panel-mount.util.d.ts +1 -1
- package/dist/utility/wrun/wrun-panel-mount.util.js +42 -13
- package/dist/utility/wrun/wrun-pin-venues.util.d.ts +3 -2
- package/dist/utility/wrun/wrun-pin-venues.util.js +11 -4
- package/dist/utility/wrun/wrun-refusal.util.d.ts +4 -0
- package/dist/utility/wrun/wrun-refusal.util.js +102 -13
- package/dist/utility/wrun/wrun-registry-errors.util.d.ts +5 -3
- package/dist/utility/wrun/wrun-registry-errors.util.js +5 -3
- package/dist/utility/wrun/wrun-row-source-factory.js +17 -1
- package/dist/utility/wrun/wrun-row-source.d.ts +8 -1
- package/dist/utility/wrun/wrun-run-health.util.js +1 -1
- package/dist/utility/wrun/wrun-sandbox-row-source.d.ts +1 -1
- package/dist/utility/wrun/wrun-sandbox-row-source.js +9 -0
- package/dist/utility/wrun/wrun-session-composition.util.d.ts +3 -2
- package/dist/utility/wrun/wrun-session-composition.util.js +3 -2
- package/dist/utility/wrun/wrun-setting-words.util.d.ts +12 -5
- package/dist/utility/wrun/wrun-setting-words.util.js +25 -8
- package/dist/utility/wrun/wrun-socket-row-source.d.ts +26 -1
- package/dist/utility/wrun/wrun-socket-row-source.js +125 -12
- package/dist/utility/wrun/wrun-source-rows.util.d.ts +3 -3
- package/dist/utility/wrun/wrun-source-rows.util.js +8 -7
- package/dist/utility/wrun/wrun-style-words.util.d.ts +31 -9
- package/dist/utility/wrun/wrun-style-words.util.js +46 -15
- package/dist/utility/wrun/wrun-trades-lane.util.js +2 -1
- package/dist/utility/wrun/wrun-trap-replay.util.d.ts +42 -0
- package/dist/utility/wrun/wrun-trap-replay.util.js +63 -0
- package/dist/utility/wrun/wrun-volume-profile.util.js +6 -5
- package/dist/utility/wrun-display-name.util.d.ts +10 -0
- package/dist/utility/wrun-display-name.util.js +21 -0
- package/dist/utils/replay/replay-buffer-math.d.ts +2 -0
- package/dist/utils/replay/replay-buffer-math.js +2 -0
- package/dist/workers/constants/socket-slots.d.ts +1 -1
- package/dist/workers/utils/time.worker.util.js +2 -2
- package/dist/workers/utils/volume-profile.worker.util.d.ts +9 -0
- package/dist/workers/utils/volume-profile.worker.util.js +20 -0
- package/dist/workers/wrun/wrun-abi-host.d.ts +3 -0
- package/dist/workers/wrun/wrun-abi-host.js +82 -5
- package/dist/workers/wrun/wrun-engine-handler.js +53 -4
- package/dist/workers/wrun/wrun-trap-frames.leaf.d.ts +28 -0
- package/dist/workers/wrun/wrun-trap-frames.leaf.js +108 -0
- package/package.json +11 -11
|
@@ -28,13 +28,27 @@ export declare function resolvePriceDisplayPrecision(exchange: string | undefine
|
|
|
28
28
|
export declare function pricePrecisionFromStep(step: number | undefined | null, mode?: 'axis' | 'step'): number;
|
|
29
29
|
/**
|
|
30
30
|
* The decimals the chart's MAIN price scale prints at (axis ticks, crosshair
|
|
31
|
-
* pill, last-price pill, legend). An engine that
|
|
32
|
-
* steps that axis on tick multiples and rounds the
|
|
33
|
-
* the tick's own decimals are exact (ES 2, YM 0,
|
|
34
|
-
* extra decimal would only print dust ("7784.250").
|
|
35
|
-
*
|
|
31
|
+
* pill, last-price pill, legend) at Value Precision "Default". An engine that
|
|
32
|
+
* holds the instrument tick steps that axis on tick multiples and rounds the
|
|
33
|
+
* crosshair to the tick, so the tick's own decimals are exact (ES 2, YM 0,
|
|
34
|
+
* ZN 6) and the axis look's extra decimal would only print dust ("7784.250").
|
|
35
|
+
*
|
|
36
|
+
* Without an engine tick, the one market decimals resolver
|
|
37
|
+
* (market-price-text.util) answers in two parts, and only a TICK may lower the
|
|
38
|
+
* chart below its axis-step rule:
|
|
39
|
+
* - `tickDecimals`, a real tick's decimals (a crypto venue tick, a CME tick
|
|
40
|
+
* the engine does not hold): they decide, so BINANCE_FUTURES BTCUSDT (tick
|
|
41
|
+
* 0.1) reads 73686.1 on the legend, not 73686.10. The engine does not step
|
|
42
|
+
* this axis on that tick, so a step finer than it (a deep zoom) keeps the
|
|
43
|
+
* decimals the step itself needs, and neighbouring labels never collide;
|
|
44
|
+
* - `observedDecimals`, the most decimals the market's traded prices carried
|
|
45
|
+
* this session: they may only RAISE the axis-step rule. They can under-read
|
|
46
|
+
* (a first price at 73741.50 says 1 of a market that trades in cents), and
|
|
47
|
+
* the legend must never drop a digit of a real close.
|
|
48
|
+
* With neither, the axis-step rule stands. HIP-4's display decimals win every
|
|
49
|
+
* time.
|
|
36
50
|
*/
|
|
37
|
-
export declare function resolveChartPricePrecision(exchange: string | undefined | null, axisStep: number | undefined | null, priceTick: number | undefined | null): number;
|
|
51
|
+
export declare function resolveChartPricePrecision(exchange: string | undefined | null, axisStep: number | undefined | null, priceTick: number | undefined | null, tickDecimals?: number | null, observedDecimals?: number | null): number;
|
|
38
52
|
/** Profile levels use the resolved prediction grid; pending grids use venue display precision. */
|
|
39
53
|
export declare function resolveProfilePricePrecision(exchange: string | undefined | null, blockSize: number | undefined | null, fallbackDigits?: number): number;
|
|
40
54
|
export { formatPriceByMagnitude } from '../number-format.util.js';
|
|
@@ -46,17 +46,44 @@ export function pricePrecisionFromStep(step, mode = 'axis') {
|
|
|
46
46
|
}
|
|
47
47
|
/**
|
|
48
48
|
* The decimals the chart's MAIN price scale prints at (axis ticks, crosshair
|
|
49
|
-
* pill, last-price pill, legend). An engine that
|
|
50
|
-
* steps that axis on tick multiples and rounds the
|
|
51
|
-
* the tick's own decimals are exact (ES 2, YM 0,
|
|
52
|
-
* extra decimal would only print dust ("7784.250").
|
|
53
|
-
*
|
|
49
|
+
* pill, last-price pill, legend) at Value Precision "Default". An engine that
|
|
50
|
+
* holds the instrument tick steps that axis on tick multiples and rounds the
|
|
51
|
+
* crosshair to the tick, so the tick's own decimals are exact (ES 2, YM 0,
|
|
52
|
+
* ZN 6) and the axis look's extra decimal would only print dust ("7784.250").
|
|
53
|
+
*
|
|
54
|
+
* Without an engine tick, the one market decimals resolver
|
|
55
|
+
* (market-price-text.util) answers in two parts, and only a TICK may lower the
|
|
56
|
+
* chart below its axis-step rule:
|
|
57
|
+
* - `tickDecimals`, a real tick's decimals (a crypto venue tick, a CME tick
|
|
58
|
+
* the engine does not hold): they decide, so BINANCE_FUTURES BTCUSDT (tick
|
|
59
|
+
* 0.1) reads 73686.1 on the legend, not 73686.10. The engine does not step
|
|
60
|
+
* this axis on that tick, so a step finer than it (a deep zoom) keeps the
|
|
61
|
+
* decimals the step itself needs, and neighbouring labels never collide;
|
|
62
|
+
* - `observedDecimals`, the most decimals the market's traded prices carried
|
|
63
|
+
* this session: they may only RAISE the axis-step rule. They can under-read
|
|
64
|
+
* (a first price at 73741.50 says 1 of a market that trades in cents), and
|
|
65
|
+
* the legend must never drop a digit of a real close.
|
|
66
|
+
* With neither, the axis-step rule stands. HIP-4's display decimals win every
|
|
67
|
+
* time.
|
|
54
68
|
*/
|
|
55
|
-
export function resolveChartPricePrecision(exchange, axisStep, priceTick) {
|
|
69
|
+
export function resolveChartPricePrecision(exchange, axisStep, priceTick, tickDecimals, observedDecimals) {
|
|
56
70
|
const hasTick = typeof priceTick === 'number' && Number.isFinite(priceTick) && priceTick > 0;
|
|
57
|
-
const
|
|
71
|
+
const tick = wholeDecimals(tickDecimals);
|
|
72
|
+
const venueDecimals = hasTick
|
|
73
|
+
? pricePrecisionFromStep(priceTick, 'step')
|
|
74
|
+
: tick !== null
|
|
75
|
+
? Math.max(tick, stepDecimals(axisStep))
|
|
76
|
+
: Math.max(wholeDecimals(observedDecimals) ?? 0, pricePrecisionFromStep(axisStep));
|
|
58
77
|
return resolvePriceDisplayPrecision(exchange, venueDecimals);
|
|
59
78
|
}
|
|
79
|
+
/** A decimals count the axis can print (0 to 10), else null. */
|
|
80
|
+
function wholeDecimals(decimals) {
|
|
81
|
+
return typeof decimals === 'number' && Number.isInteger(decimals) && decimals >= 0 ? Math.min(decimals, 10) : null;
|
|
82
|
+
}
|
|
83
|
+
/** The decimals an axis step needs to print distinct labels (none for a missing step). */
|
|
84
|
+
function stepDecimals(step) {
|
|
85
|
+
return typeof step === 'number' && Number.isFinite(step) && step > 0 ? pricePrecisionFromStep(step, 'step') : 0;
|
|
86
|
+
}
|
|
60
87
|
/** Profile levels use the resolved prediction grid; pending grids use venue display precision. */
|
|
61
88
|
export function resolveProfilePricePrecision(exchange, blockSize, fallbackDigits = 2) {
|
|
62
89
|
if (!isPredictionExchangeName(exchange))
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A live volume-profile frame's stamp is the exclusive END of its fold window (seconds plus fixed32 nanoseconds). The
|
|
3
|
+
* one reader of that stamp for the footprint's live store and the wrun intake's session check, so a frame closing on
|
|
4
|
+
* the session's edge is judged by an instant inside its own window on both.
|
|
5
|
+
*/
|
|
6
|
+
export interface ProfileFrameStampLike {
|
|
7
|
+
timestamp?: {
|
|
8
|
+
seconds?: unknown;
|
|
9
|
+
nanoseconds?: unknown;
|
|
10
|
+
} | null;
|
|
11
|
+
}
|
|
12
|
+
/** The END of a frame's fold window, epoch ms (absent fixed32 nanoseconds read as 0); null when unstamped. */
|
|
13
|
+
export declare function profileFrameWindowEndMs(aggregation: ProfileFrameStampLike | null | undefined): number | null;
|
|
14
|
+
/** The last instant inside a frame's window (its end minus 1 ms): a window closing on a boundary belongs before it. */
|
|
15
|
+
export declare function profileFrameLastInstantMs(aggregation: ProfileFrameStampLike | null | undefined): number | null;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/** The END of a frame's fold window, epoch ms (absent fixed32 nanoseconds read as 0); null when unstamped. */
|
|
2
|
+
export function profileFrameWindowEndMs(aggregation) {
|
|
3
|
+
const seconds = aggregation?.timestamp?.seconds;
|
|
4
|
+
if (seconds === undefined || seconds === null)
|
|
5
|
+
return null;
|
|
6
|
+
return Number(seconds) * 1000 + Math.floor((Number(aggregation?.timestamp?.nanoseconds ?? 0) || 0) / 1e6);
|
|
7
|
+
}
|
|
8
|
+
/** The last instant inside a frame's window (its end minus 1 ms): a window closing on a boundary belongs before it. */
|
|
9
|
+
export function profileFrameLastInstantMs(aggregation) {
|
|
10
|
+
const endMs = profileFrameWindowEndMs(aggregation);
|
|
11
|
+
return endMs === null ? null : endMs - 1;
|
|
12
|
+
}
|
|
@@ -162,7 +162,9 @@ export declare function isRthSessionHoursActive(settings: RthSessionSettingsLike
|
|
|
162
162
|
* finer tier and refuses a trading-hour plan at a rolled width ("trading
|
|
163
163
|
* hour sessions are not served at this interval"), and a 2m or 10m bucket
|
|
164
164
|
* would straddle the 16:15 close anyway. Every result is a natively served
|
|
165
|
-
* width (1m / 5m / 15m).
|
|
165
|
+
* width (1m / 5m / 15m). Width-only on purpose: a day-plus read that the
|
|
166
|
+
* gateway serves per trading session (a US stock tape) passes through
|
|
167
|
+
* market-session.util `regularSessionReadTfMs`, which knows the market.
|
|
166
168
|
*/
|
|
167
169
|
export declare function rthEffectiveFetchTfMs(chartTfMs: number): number;
|
|
168
170
|
/**
|
|
@@ -389,7 +389,9 @@ const RTH_EFFECTIVE_FETCH_MAX_TF_MS = Intervals.map_unit['15m'];
|
|
|
389
389
|
* finer tier and refuses a trading-hour plan at a rolled width ("trading
|
|
390
390
|
* hour sessions are not served at this interval"), and a 2m or 10m bucket
|
|
391
391
|
* would straddle the 16:15 close anyway. Every result is a natively served
|
|
392
|
-
* width (1m / 5m / 15m).
|
|
392
|
+
* width (1m / 5m / 15m). Width-only on purpose: a day-plus read that the
|
|
393
|
+
* gateway serves per trading session (a US stock tape) passes through
|
|
394
|
+
* market-session.util `regularSessionReadTfMs`, which knows the market.
|
|
393
395
|
*/
|
|
394
396
|
export function rthEffectiveFetchTfMs(chartTfMs) {
|
|
395
397
|
if (!Number.isFinite(chartTfMs) || chartTfMs <= 0)
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The session a script's trade-level data source reads on the chart it runs on: the one decision the source sender
|
|
3
|
+
* (titan-charts `acquireKScriptSourceData`, the request payload's `sessionHours` and the fetch ledger's tag), the
|
|
4
|
+
* workers and the live fold (the wrun intake: no app code calls the kScript data controls' live merge, the browser
|
|
5
|
+
* engine is retired) read, so a print or a profile frame is kept or dropped by the same rule on history and live.
|
|
6
|
+
*
|
|
7
|
+
* - `trades` (K_TRADES, Big Trades' tape): the candle's own session. A US stock chart whose candles are regular
|
|
8
|
+
* (us-equities-session.util `isEquityRegularSessionGated`: every daily and longer bar, an intraday chart not in
|
|
9
|
+
* extended hours) keeps a print only inside 09:30 to 16:00 New York; extended-hours intraday keeps every print.
|
|
10
|
+
* - `volume_profile` (K_VOLUME_PROFILE, Volume Bubbles' and Bar Statistics' per-bar ladder): the footprint's day-plus
|
|
11
|
+
* rule (footprint-rth-request.util): a stock tape read at 1D, 1W or a month on a regular chart reads the regular
|
|
12
|
+
* session per trading day. The gateway serves that read in coins only, so a dollar source reads coins and the worker
|
|
13
|
+
* prices each cell at its midpoint. Intraday widths and 3D read as before.
|
|
14
|
+
* Every other source, market and chart: no field, so its request and identities stay byte-identical.
|
|
15
|
+
*/
|
|
16
|
+
import { SESSION_HOURS_RTH } from './rth-session.util.js';
|
|
17
|
+
/** The chart a source runs on, as its metadata or a wrun live market names it. */
|
|
18
|
+
export interface ScriptSourceChartLike {
|
|
19
|
+
exchange?: unknown;
|
|
20
|
+
symbol?: unknown;
|
|
21
|
+
sessionType?: unknown;
|
|
22
|
+
}
|
|
23
|
+
/** The market a source reads (its resolved exchange and symbol: a Trades chart's tape). */
|
|
24
|
+
export interface ScriptSourceMarketLike {
|
|
25
|
+
exchange?: unknown;
|
|
26
|
+
symbol?: unknown;
|
|
27
|
+
}
|
|
28
|
+
/** The K_TRADES tape's session on a chart of `chartTfMs`: 'rth' where the candle is regular and the tape a US stock's. */
|
|
29
|
+
export declare function tapeSourceSessionHours(chart: ScriptSourceChartLike | null | undefined, chartTfMs: unknown, source: ScriptSourceMarketLike | null | undefined): typeof SESSION_HOURS_RTH | undefined;
|
|
30
|
+
/** The K_VOLUME_PROFILE ladder's session at `readTfMs` on a chart of `chartTfMs`: 'rth' on a stock tape's day-plus read
|
|
31
|
+
* under a regular chart (the footprint's rule, judged in coins: the read the gateway holds to the session). */
|
|
32
|
+
export declare function volumeProfileSourceSessionHours(chart: ScriptSourceChartLike | null | undefined, chartTfMs: unknown, readTfMs: unknown, source: ScriptSourceMarketLike | null | undefined): typeof SESSION_HOURS_RTH | undefined;
|
|
33
|
+
/** The session field a kScript source type's request carries, or undefined for every type and chart that has none. */
|
|
34
|
+
export declare function scriptSourceSessionHours(kScriptType: string, chart: ScriptSourceChartLike | null | undefined, chartTfMs: unknown, readTfMs: unknown, source: ScriptSourceMarketLike | null | undefined): typeof SESSION_HOURS_RTH | undefined;
|
|
35
|
+
/** The fetch ledger's name for a source read: the session rides it, so a session-held read never dedupes against an
|
|
36
|
+
* all-hours one of the same window; a read with no session keeps its own name. */
|
|
37
|
+
export declare function scriptSourceLedgerName(sourceName: string, sessionHours: string | undefined): string;
|
|
38
|
+
/** Whether an instant on `exchange|symbol` belongs to a read of `sessionHours`: always on an all-hours read, inside the
|
|
39
|
+
* market's regular window on an 'rth' one. The one per-print and per-frame check of the history workers and live folds. */
|
|
40
|
+
export declare function isInScriptSourceSession(sessionHours: unknown, exchange: unknown, symbol: unknown, tsMs: number): boolean;
|
|
41
|
+
/** Whether a live ladder frame stamped `tsMs` folds on a chart of `chartTfMs`: a day-plus bar of a regular stock chart
|
|
42
|
+
* holds only frames inside the regular session, as its history read does; every other chart folds every frame. */
|
|
43
|
+
export declare function isVolumeProfileLiveFrameInSession(chart: ScriptSourceChartLike | null | undefined, chartTfMs: unknown, tsMs: number): boolean;
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The session a script's trade-level data source reads on the chart it runs on: the one decision the source sender
|
|
3
|
+
* (titan-charts `acquireKScriptSourceData`, the request payload's `sessionHours` and the fetch ledger's tag), the
|
|
4
|
+
* workers and the live fold (the wrun intake: no app code calls the kScript data controls' live merge, the browser
|
|
5
|
+
* engine is retired) read, so a print or a profile frame is kept or dropped by the same rule on history and live.
|
|
6
|
+
*
|
|
7
|
+
* - `trades` (K_TRADES, Big Trades' tape): the candle's own session. A US stock chart whose candles are regular
|
|
8
|
+
* (us-equities-session.util `isEquityRegularSessionGated`: every daily and longer bar, an intraday chart not in
|
|
9
|
+
* extended hours) keeps a print only inside 09:30 to 16:00 New York; extended-hours intraday keeps every print.
|
|
10
|
+
* - `volume_profile` (K_VOLUME_PROFILE, Volume Bubbles' and Bar Statistics' per-bar ladder): the footprint's day-plus
|
|
11
|
+
* rule (footprint-rth-request.util): a stock tape read at 1D, 1W or a month on a regular chart reads the regular
|
|
12
|
+
* session per trading day. The gateway serves that read in coins only, so a dollar source reads coins and the worker
|
|
13
|
+
* prices each cell at its midpoint. Intraday widths and 3D read as before.
|
|
14
|
+
* Every other source, market and chart: no field, so its request and identities stay byte-identical.
|
|
15
|
+
*/
|
|
16
|
+
import { SESSION_HOURS_RTH } from './rth-session.util.js';
|
|
17
|
+
import { isEquityRegularSessionGated } from './us-equities-session.util.js';
|
|
18
|
+
import { chartRegularSessionKind, isMarketSessionHoursActive, isWithinMarketRegularWindow, marketSessionKind, sessionFilterJudgesTradeInstant, } from './market-session.util.js';
|
|
19
|
+
/** The K_TRADES tape's session on a chart of `chartTfMs`: 'rth' where the candle is regular and the tape a US stock's. */
|
|
20
|
+
export function tapeSourceSessionHours(chart, chartTfMs, source) {
|
|
21
|
+
if (!chart || !source || !isEquityRegularSessionGated(chart.exchange, chart.sessionType, chartTfMs))
|
|
22
|
+
return undefined;
|
|
23
|
+
return marketSessionKind(source.exchange, source.symbol) === 'us-equity' ? SESSION_HOURS_RTH : undefined;
|
|
24
|
+
}
|
|
25
|
+
/** The K_VOLUME_PROFILE ladder's session at `readTfMs` on a chart of `chartTfMs`: 'rth' on a stock tape's day-plus read
|
|
26
|
+
* under a regular chart (the footprint's rule, judged in coins: the read the gateway holds to the session). */
|
|
27
|
+
export function volumeProfileSourceSessionHours(chart, chartTfMs, readTfMs, source) {
|
|
28
|
+
if (!chart || !source || !sessionFilterJudgesTradeInstant(chartTfMs) || !sessionFilterJudgesTradeInstant(readTfMs)) {
|
|
29
|
+
return undefined;
|
|
30
|
+
}
|
|
31
|
+
const chartKind = chartRegularSessionKind(chart.exchange, chart.symbol, chart.sessionType, chartTfMs);
|
|
32
|
+
const read = { exchange: source.exchange, symbol: source.symbol };
|
|
33
|
+
return isMarketSessionHoursActive(read, chartTfMs, chartKind, readTfMs) ? SESSION_HOURS_RTH : undefined;
|
|
34
|
+
}
|
|
35
|
+
/** The session field a kScript source type's request carries, or undefined for every type and chart that has none. */
|
|
36
|
+
export function scriptSourceSessionHours(kScriptType, chart, chartTfMs, readTfMs, source) {
|
|
37
|
+
if (kScriptType === 'K_TRADES')
|
|
38
|
+
return tapeSourceSessionHours(chart, chartTfMs, source);
|
|
39
|
+
if (kScriptType === 'K_VOLUME_PROFILE')
|
|
40
|
+
return volumeProfileSourceSessionHours(chart, chartTfMs, readTfMs, source);
|
|
41
|
+
return undefined;
|
|
42
|
+
}
|
|
43
|
+
/** The fetch ledger's name for a source read: the session rides it, so a session-held read never dedupes against an
|
|
44
|
+
* all-hours one of the same window; a read with no session keeps its own name. */
|
|
45
|
+
export function scriptSourceLedgerName(sourceName, sessionHours) {
|
|
46
|
+
return sessionHours === undefined ? sourceName : `${sourceName}@th-${sessionHours}`;
|
|
47
|
+
}
|
|
48
|
+
/** Whether an instant on `exchange|symbol` belongs to a read of `sessionHours`: always on an all-hours read, inside the
|
|
49
|
+
* market's regular window on an 'rth' one. The one per-print and per-frame check of the history workers and live folds. */
|
|
50
|
+
export function isInScriptSourceSession(sessionHours, exchange, symbol, tsMs) {
|
|
51
|
+
return sessionHours !== SESSION_HOURS_RTH || isWithinMarketRegularWindow(exchange, symbol, tsMs);
|
|
52
|
+
}
|
|
53
|
+
/** Whether a live ladder frame stamped `tsMs` folds on a chart of `chartTfMs`: a day-plus bar of a regular stock chart
|
|
54
|
+
* holds only frames inside the regular session, as its history read does; every other chart folds every frame. */
|
|
55
|
+
export function isVolumeProfileLiveFrameInSession(chart, chartTfMs, tsMs) {
|
|
56
|
+
if (!chart || !sessionFilterJudgesTradeInstant(chartTfMs))
|
|
57
|
+
return true;
|
|
58
|
+
if (chartRegularSessionKind(chart.exchange, chart.symbol, chart.sessionType, chartTfMs) !== 'us-equity')
|
|
59
|
+
return true;
|
|
60
|
+
return isWithinMarketRegularWindow(chart.exchange, chart.symbol, tsMs);
|
|
61
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { LiveBucketVenue } from './live-bucket.util.js';
|
|
2
|
+
/** The grid a custom size rides on a market. */
|
|
3
|
+
export type TypedGridKind = 'utc' | 'cme-session' | 'cme-regular' | 'equity-regular' | 'equity-extended' | 'options' | 'forex';
|
|
4
|
+
/**
|
|
5
|
+
* Which grid a custom size of `widthMs` rides on the chart's market. The order mirrors live-bucket.util
|
|
6
|
+
* `liveBucketGrid`: the chart's CME regular-hours switch first, then the regular-session stock gate, then the session
|
|
7
|
+
* lattice of the exchange. A US option (OPRA) rides its own 09:30 to 16:15 window. A stock tape
|
|
8
|
+
* venue (NASDAQ_TAPE) and the other listing codes the candle gate does not name ride the UTC grid, as their fixed
|
|
9
|
+
* sizes do today. A formula chart (`venue.transformations` with more than one leg) is refused upstream until the
|
|
10
|
+
* formula phase, so it is read here by its `exchange` alone.
|
|
11
|
+
*/
|
|
12
|
+
export declare function typedGridKind(widthMs: number, venue: LiveBucketVenue | null | undefined): TypedGridKind;
|
|
13
|
+
/**
|
|
14
|
+
* The stamp of the custom bar that holds `tsMs`, or null when the market holds no bar there (outside its session).
|
|
15
|
+
* `tsMs` is an instant inside the bar or the stamp of a source row the bar is built from; both give the same stamp.
|
|
16
|
+
*/
|
|
17
|
+
export declare function typedBarStartMs(tsMs: number, widthMs: number, venue: LiveBucketVenue | null | undefined): number | null;
|
|
18
|
+
/**
|
|
19
|
+
* The first instant the bar stamped `barMs` no longer takes rows: the next bar's open, or the session close when the
|
|
20
|
+
* bar is the session's short last one. The stock sessions model no early closes (ny-calendar.util has no half days),
|
|
21
|
+
* so an early close's last bar keeps its full-session end; its rows simply stop.
|
|
22
|
+
*/
|
|
23
|
+
export declare function typedBarEndMs(barMs: number, widthMs: number, venue: LiveBucketVenue | null | undefined): number;
|
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Where a custom size's bars sit on a chart's own market: the one grid the app-built candles, their live merge and
|
|
3
|
+
* (later) the indicator folds read. The product rule: on a market with trading sessions a custom bar starts at the
|
|
4
|
+
* session open and counts from there, and the session's last bar is short; a market that trades round the clock
|
|
5
|
+
* counts from 00:00 UTC (the fixed grid the gateway already serves custom sizes on).
|
|
6
|
+
*
|
|
7
|
+
* The grids, by kind (`typedGridKind`, which reads a venue exactly as live-bucket.util `liveBucketGrid` does):
|
|
8
|
+
* 'utc' `fixedGridFloorMs` at every size (day and week sizes count from Monday 2000-01-03);
|
|
9
|
+
* 'cme-session' the CME session lattice at the custom width (17:00 Chicago, offset = the open modulo the
|
|
10
|
+
* width), held to the product's schedule, so the bar before the daily halt ends at the halt;
|
|
11
|
+
* 'cme-regular' anchored at the regular session's open, as the live bucket's 'rth-anchored' grid is;
|
|
12
|
+
* 'equity-regular' anchored at the 09:30 New York open, the session 09:30 to 16:00;
|
|
13
|
+
* 'equity-extended' anchored at 04:00 New York, the session 04:00 to 20:00 New York on weekdays;
|
|
14
|
+
* 'options' a US option (OPRA): anchored at 09:30 New York, the session 09:30 to 16:15 on weekdays for every
|
|
15
|
+
* root (the app's rule, src/utility/chart/us-options-session.util `US_OPTIONS_SESSION_WINDOW`);
|
|
16
|
+
* 'forex' the forex session lattice at the custom width (17:00 New York).
|
|
17
|
+
* Every size under a day divides 24 hours, so a session grid repeats each day from the open. Day and week sizes ride
|
|
18
|
+
* the 'utc' kind only in this phase: on every other kind `typedBarStartMs` answers null for them on purpose until the
|
|
19
|
+
* phase that groups trade dates lands.
|
|
20
|
+
*
|
|
21
|
+
* The session lattices are composed, never edited: session-lattice.util takes a profile, so a copy of the CME or forex
|
|
22
|
+
* profile whose `intradayLatticeMs` also admits the custom widths runs the gateway's own lattice math at them.
|
|
23
|
+
*
|
|
24
|
+
* LAZY: loaded the first time a chart goes on a custom size the app builds, on the page and in the data worker.
|
|
25
|
+
* No eager module may import this file (tests/perf/typed-width-rules-lazy-closure.spec.ts).
|
|
26
|
+
*/
|
|
27
|
+
import { TYPED_WIDTH_SECONDS } from '../../constants/typed-width.leaf.js';
|
|
28
|
+
import { fixedGridFloorDivMs, fixedGridFloorMs } from './calendar-interval.util.js';
|
|
29
|
+
import { checkIsPolygon, getMarketKind } from './marketKind.util.js';
|
|
30
|
+
import { isGovernedFuturesSymbolOpenAt } from './market-session-schedule.util.js';
|
|
31
|
+
import { chartRegularSessionKind, marketAnchoredBucketEndMs, marketAnchoredBucketStartMs } from './market-session.util.js';
|
|
32
|
+
import { nyCalendarDayAt } from './ny-calendar.util.js';
|
|
33
|
+
import { CME_SESSION_LATTICE, FOREX_SESSION_LATTICE, sessionLatticeBarEndMs, sessionLatticeBucketMs, sessionLatticeOf, } from './session-lattice.util.js';
|
|
34
|
+
import { isEquityRegularSessionGated, usEquityAnchoredBucketStartMs } from './us-equities-session.util.js';
|
|
35
|
+
const MINUTE_MS = 60_000;
|
|
36
|
+
const DAY_MS = 86_400_000;
|
|
37
|
+
/** The twelve custom widths under a day, in ms: the widths the composed lattices admit. */
|
|
38
|
+
const TYPED_INTRADAY_WIDTHS_MS = Object.values(TYPED_WIDTH_SECONDS)
|
|
39
|
+
.filter((seconds) => seconds < 86_400)
|
|
40
|
+
.map((seconds) => seconds * 1000);
|
|
41
|
+
/**
|
|
42
|
+
* Which grid a custom size of `widthMs` rides on the chart's market. The order mirrors live-bucket.util
|
|
43
|
+
* `liveBucketGrid`: the chart's CME regular-hours switch first, then the regular-session stock gate, then the session
|
|
44
|
+
* lattice of the exchange. A US option (OPRA) rides its own 09:30 to 16:15 window. A stock tape
|
|
45
|
+
* venue (NASDAQ_TAPE) and the other listing codes the candle gate does not name ride the UTC grid, as their fixed
|
|
46
|
+
* sizes do today. A formula chart (`venue.transformations` with more than one leg) is refused upstream until the
|
|
47
|
+
* formula phase, so it is read here by its `exchange` alone.
|
|
48
|
+
*/
|
|
49
|
+
export function typedGridKind(widthMs, venue) {
|
|
50
|
+
if (!venue)
|
|
51
|
+
return 'utc';
|
|
52
|
+
const { exchange, symbol, sessionType } = venue;
|
|
53
|
+
if (chartRegularSessionKind(exchange, symbol, sessionType, widthMs) === 'cme')
|
|
54
|
+
return 'cme-regular';
|
|
55
|
+
if (isEquityRegularSessionGated(exchange, sessionType, widthMs))
|
|
56
|
+
return 'equity-regular';
|
|
57
|
+
const code = typeof exchange === 'string' ? exchange : undefined;
|
|
58
|
+
if (getMarketKind(code) === 'options')
|
|
59
|
+
return 'options';
|
|
60
|
+
// A stock listing the regular gate let through: its extended-hours switch is on.
|
|
61
|
+
if (checkIsPolygon(code))
|
|
62
|
+
return 'equity-extended';
|
|
63
|
+
const lattice = sessionLatticeOf(exchange);
|
|
64
|
+
if (lattice === CME_SESSION_LATTICE)
|
|
65
|
+
return 'cme-session';
|
|
66
|
+
if (lattice === FOREX_SESSION_LATTICE)
|
|
67
|
+
return 'forex';
|
|
68
|
+
return 'utc';
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* The session profile with the custom widths admitted to its intraday lattice. It keeps the profile's `id`, so it
|
|
72
|
+
* shares that profile's zone state in session-lattice.util: the formatter and the offset caches depend on the zone
|
|
73
|
+
* alone, and the bar-end cache is keyed by width and stamp, where the base profile answers every preset width the same
|
|
74
|
+
* and never reads a custom width (it refuses one before its cache).
|
|
75
|
+
*/
|
|
76
|
+
const composedProfiles = new Map();
|
|
77
|
+
function composedProfileOf(base) {
|
|
78
|
+
let profile = composedProfiles.get(base);
|
|
79
|
+
if (!profile) {
|
|
80
|
+
profile = Object.freeze({
|
|
81
|
+
...base,
|
|
82
|
+
intradayLatticeMs: new Set([...base.intradayLatticeMs, ...TYPED_INTRADAY_WIDTHS_MS]),
|
|
83
|
+
});
|
|
84
|
+
composedProfiles.set(base, profile);
|
|
85
|
+
}
|
|
86
|
+
return profile;
|
|
87
|
+
}
|
|
88
|
+
const latticeProfileOf = (kind) => composedProfileOf(kind === 'cme-session' ? CME_SESSION_LATTICE : FOREX_SESSION_LATTICE);
|
|
89
|
+
/** The bar holding `tsMs` on a grid of `widthMs` anchored at `openMs`: a session-anchored floor under a day. */
|
|
90
|
+
const anchoredStartMs = (openMs, tsMs, widthMs) => openMs + fixedGridFloorDivMs(tsMs - openMs, widthMs);
|
|
91
|
+
/** A US option's close after the stock close: 16:15 New York (us-options-session.util `LATE_CLOSE_MINUTES`). */
|
|
92
|
+
const OPTIONS_CLOSE_AFTER_STOCK_CLOSE_MS = 15 * MINUTE_MS;
|
|
93
|
+
/**
|
|
94
|
+
* The New York session holding `tsMs` on a weekday, or null outside it: 04:00 to 20:00 for an extended-hours stock,
|
|
95
|
+
* 09:30 to 16:15 for a US option (one window for every root, as the app's options rule draws its bars).
|
|
96
|
+
*/
|
|
97
|
+
function nySessionAt(tsMs, kind) {
|
|
98
|
+
const day = nyCalendarDayAt(tsMs);
|
|
99
|
+
if (day === null || !day.isTradeDate)
|
|
100
|
+
return null;
|
|
101
|
+
const options = kind === 'options';
|
|
102
|
+
const openMs = options ? day.regularOpenMs : day.preMarketOpenMs;
|
|
103
|
+
const closeMs = options ? day.regularCloseMs + OPTIONS_CLOSE_AFTER_STOCK_CLOSE_MS : day.postMarketCloseMs;
|
|
104
|
+
return tsMs < openMs || tsMs >= closeMs ? null : { openMs, closeMs };
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* The first instant in `[openMs, endMs)` the CME product no longer trades by its schedule, else `endMs`: the daily
|
|
108
|
+
* halt (16:00 Chicago) or the Friday close cuts the bar that holds it. A bar holds at most one such edge, on a whole
|
|
109
|
+
* minute, so a minute bisection finds it.
|
|
110
|
+
*/
|
|
111
|
+
function scheduleCloseWithinMs(symbol, openMs, endMs) {
|
|
112
|
+
if (isGovernedFuturesSymbolOpenAt(symbol, endMs - 1) || !isGovernedFuturesSymbolOpenAt(symbol, openMs))
|
|
113
|
+
return endMs;
|
|
114
|
+
let openAt = openMs;
|
|
115
|
+
let closedAt = endMs - 1;
|
|
116
|
+
while (closedAt - openAt > MINUTE_MS) {
|
|
117
|
+
const midMs = openAt + Math.max(1, Math.floor((closedAt - openAt) / (2 * MINUTE_MS))) * MINUTE_MS;
|
|
118
|
+
if (isGovernedFuturesSymbolOpenAt(symbol, midMs))
|
|
119
|
+
openAt = midMs;
|
|
120
|
+
else
|
|
121
|
+
closedAt = midMs;
|
|
122
|
+
}
|
|
123
|
+
return Math.min(openAt + MINUTE_MS, endMs);
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* The stamp of the custom bar that holds `tsMs`, or null when the market holds no bar there (outside its session).
|
|
127
|
+
* `tsMs` is an instant inside the bar or the stamp of a source row the bar is built from; both give the same stamp.
|
|
128
|
+
*/
|
|
129
|
+
export function typedBarStartMs(tsMs, widthMs, venue) {
|
|
130
|
+
if (!Number.isFinite(tsMs) || !(widthMs > 0))
|
|
131
|
+
return null;
|
|
132
|
+
const kind = typedGridKind(widthMs, venue);
|
|
133
|
+
if (kind === 'utc')
|
|
134
|
+
return fixedGridFloorMs(tsMs, widthMs);
|
|
135
|
+
// Day and week sizes on a session market wait for the trade-date phase; a width that does not divide a day has no
|
|
136
|
+
// daily repeat from the open.
|
|
137
|
+
if (!(widthMs < DAY_MS) || !Number.isInteger(DAY_MS / widthMs))
|
|
138
|
+
return null;
|
|
139
|
+
switch (kind) {
|
|
140
|
+
case 'cme-session': {
|
|
141
|
+
const profile = latticeProfileOf(kind);
|
|
142
|
+
const startMs = sessionLatticeBucketMs(profile, tsMs, widthMs);
|
|
143
|
+
if (startMs === null || isGovernedFuturesSymbolOpenAt(venue?.symbol, tsMs))
|
|
144
|
+
return startMs;
|
|
145
|
+
// The lattice keeps stamping through the halts; the product holds no bar while it does not trade. The one
|
|
146
|
+
// closed stretch that does belong to a bar runs from a stamp to a reopen INSIDE that bucket: an always-on root
|
|
147
|
+
// resumes at 04:00 Chicago on Saturday, off the lattice at eight sizes, so the bar that holds the reopen is
|
|
148
|
+
// stamped inside the halt. A read window that ends or starts in that stretch must find the bar. A reopen on a
|
|
149
|
+
// lattice edge (17:00 Chicago, every other root) leaves the whole halt without a bar.
|
|
150
|
+
const endMs = sessionLatticeBarEndMs(profile, startMs, widthMs) ?? startMs + widthMs;
|
|
151
|
+
return isGovernedFuturesSymbolOpenAt(venue?.symbol, endMs - 1) ? startMs : null;
|
|
152
|
+
}
|
|
153
|
+
case 'forex':
|
|
154
|
+
return sessionLatticeBucketMs(latticeProfileOf(kind), tsMs, widthMs);
|
|
155
|
+
case 'cme-regular': {
|
|
156
|
+
const startMs = marketAnchoredBucketStartMs(venue?.exchange, venue?.symbol, tsMs, widthMs);
|
|
157
|
+
// The regular window is a wall-clock filter on every calendar day: a bar exists only while the product trades.
|
|
158
|
+
return startMs !== null && isGovernedFuturesSymbolOpenAt(venue?.symbol, startMs) ? startMs : null;
|
|
159
|
+
}
|
|
160
|
+
case 'equity-regular':
|
|
161
|
+
return usEquityAnchoredBucketStartMs(tsMs, widthMs);
|
|
162
|
+
case 'equity-extended':
|
|
163
|
+
case 'options': {
|
|
164
|
+
const session = nySessionAt(tsMs, kind);
|
|
165
|
+
return session === null ? null : anchoredStartMs(session.openMs, tsMs, widthMs);
|
|
166
|
+
}
|
|
167
|
+
default:
|
|
168
|
+
return null;
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
/**
|
|
172
|
+
* The first instant the bar stamped `barMs` no longer takes rows: the next bar's open, or the session close when the
|
|
173
|
+
* bar is the session's short last one. The stock sessions model no early closes (ny-calendar.util has no half days),
|
|
174
|
+
* so an early close's last bar keeps its full-session end; its rows simply stop.
|
|
175
|
+
*/
|
|
176
|
+
export function typedBarEndMs(barMs, widthMs, venue) {
|
|
177
|
+
const nominalEndMs = barMs + widthMs;
|
|
178
|
+
const kind = typedGridKind(widthMs, venue);
|
|
179
|
+
if (kind === 'utc' || !(widthMs < DAY_MS) || !Number.isFinite(barMs))
|
|
180
|
+
return nominalEndMs;
|
|
181
|
+
switch (kind) {
|
|
182
|
+
case 'cme-session': {
|
|
183
|
+
// The lattice end covers a fall-back night's longer bar; the schedule cuts the bar at the daily halt.
|
|
184
|
+
const latticeEndMs = sessionLatticeBarEndMs(latticeProfileOf(kind), barMs, widthMs) ?? nominalEndMs;
|
|
185
|
+
return scheduleCloseWithinMs(venue?.symbol, barMs, latticeEndMs);
|
|
186
|
+
}
|
|
187
|
+
case 'forex':
|
|
188
|
+
return sessionLatticeBarEndMs(latticeProfileOf(kind), barMs, widthMs) ?? nominalEndMs;
|
|
189
|
+
case 'cme-regular':
|
|
190
|
+
return marketAnchoredBucketEndMs(venue?.exchange, venue?.symbol, barMs, widthMs) ?? nominalEndMs;
|
|
191
|
+
case 'equity-regular': {
|
|
192
|
+
const day = nyCalendarDayAt(barMs);
|
|
193
|
+
return day === null ? nominalEndMs : Math.min(nominalEndMs, day.regularCloseMs);
|
|
194
|
+
}
|
|
195
|
+
case 'equity-extended':
|
|
196
|
+
case 'options': {
|
|
197
|
+
const session = nySessionAt(barMs, kind);
|
|
198
|
+
return session === null ? nominalEndMs : Math.min(nominalEndMs, session.closeMs);
|
|
199
|
+
}
|
|
200
|
+
default:
|
|
201
|
+
return nominalEndMs;
|
|
202
|
+
}
|
|
203
|
+
}
|
|
@@ -121,6 +121,12 @@ export declare function reconcileSymbolWithTransformations(meta: {
|
|
|
121
121
|
chain?: string;
|
|
122
122
|
poolAddress?: string;
|
|
123
123
|
}): boolean;
|
|
124
|
+
/**
|
|
125
|
+
* How many `EXCHANGE|SYMBOL` tokens `sanitizeTransformations` drops from this string: markets a saved layout loses
|
|
126
|
+
* on install. The install reports a non-zero count (chart.ts setCurrentWorkspace), because the loss is silent on
|
|
127
|
+
* screen: the chart opens on the legs that are left.
|
|
128
|
+
*/
|
|
129
|
+
export declare function droppedMarketLegCount(transformations: string): number;
|
|
124
130
|
export declare function sanitizeTransformations(transformations: string): string;
|
|
125
131
|
export declare function processDisplayExchangeSymbol(exchange: string, symbol: string): string;
|
|
126
132
|
/**
|
|
@@ -533,7 +533,13 @@ function transformMergedData(transformations, ovData, lastDataPoint, sameTimeSta
|
|
|
533
533
|
}
|
|
534
534
|
const VALID_NUMBER_RE = /^(\d+\.?\d*|\.\d+)([eE][+-]?\d+)?$/;
|
|
535
535
|
const VALID_EXCHANGE_RE = /^[a-zA-Z0-9_.]+$/;
|
|
536
|
-
|
|
536
|
+
// Every character a market's symbol holds, and nothing markup can use (this string skips the HTML strip,
|
|
537
|
+
// workspace-text-strip.util.ts). Letters and digits of any script (venues list non-Latin names), `_ . - : /`, and
|
|
538
|
+
// the marks of `GC1!` (continuous futures alias), `@107` (Hyperliquid spot) and `#12270` (Hyperliquid outcome
|
|
539
|
+
// market). A symbol outside this set is DROPPED from a saved formula on its next open and its layout file import is
|
|
540
|
+
// refused, so a venue's new mark is added here with a row in tests/utility/common/transformations-sanitize.util.spec.ts.
|
|
541
|
+
// Never whitespace, quotes, brackets or `< > & =`.
|
|
542
|
+
const VALID_SYMBOL_RE = /^[\p{L}\p{N}_.\-:/!@#]+$/u;
|
|
537
543
|
// StreamPoints CME option raw symbols are `<future> <C|P><strike>` (for
|
|
538
544
|
// example `E4DU6 C7740`). The space is part of the symbol, not a formula
|
|
539
545
|
// separator. Keep this deliberately narrower than VALID_SYMBOL_RE: arbitrary
|
|
@@ -638,10 +644,28 @@ export function reconcileSymbolWithTransformations(meta) {
|
|
|
638
644
|
meta.symbol = symbol;
|
|
639
645
|
return true;
|
|
640
646
|
}
|
|
647
|
+
// Parentheses padded with spaces so each is its own token; hyphens stay inside their symbol.
|
|
648
|
+
function transformationTokens(transformations) {
|
|
649
|
+
return transformations
|
|
650
|
+
.replace(/([()])/g, ' $1 ')
|
|
651
|
+
.split(/\s+/)
|
|
652
|
+
.filter(Boolean);
|
|
653
|
+
}
|
|
654
|
+
/**
|
|
655
|
+
* How many `EXCHANGE|SYMBOL` tokens `sanitizeTransformations` drops from this string: markets a saved layout loses
|
|
656
|
+
* on install. The install reports a non-zero count (chart.ts setCurrentWorkspace), because the loss is silent on
|
|
657
|
+
* screen: the chart opens on the legs that are left.
|
|
658
|
+
*/
|
|
659
|
+
export function droppedMarketLegCount(transformations) {
|
|
660
|
+
let dropped = 0;
|
|
661
|
+
for (const token of transformationTokens(transformations)) {
|
|
662
|
+
if (token.includes(delimiter) && !isValidTransformationToken(token))
|
|
663
|
+
dropped += 1;
|
|
664
|
+
}
|
|
665
|
+
return dropped;
|
|
666
|
+
}
|
|
641
667
|
export function sanitizeTransformations(transformations) {
|
|
642
|
-
|
|
643
|
-
const padded = transformations.replace(/([()])/g, ' $1 ');
|
|
644
|
-
const tokens = padded.split(/\s+/).filter(Boolean);
|
|
668
|
+
const tokens = transformationTokens(transformations);
|
|
645
669
|
// Keep valid expression tokens. A CME option leg immediately following an
|
|
646
670
|
// exchange|future token belongs to that same raw symbol, so rejoin it before
|
|
647
671
|
// hydration reconciliation compares transformations with metadata.symbol.
|
|
@@ -8,6 +8,9 @@ export function assetClassForMarketKind(kind) {
|
|
|
8
8
|
case 'futures':
|
|
9
9
|
case 'commodity':
|
|
10
10
|
case 'forex':
|
|
11
|
+
case 'marketIndex':
|
|
12
|
+
// Index and yield charts move on the same macro calendar as forex, so they take its bucket; the default arm
|
|
13
|
+
// would file them under crypto.
|
|
11
14
|
return 'cme';
|
|
12
15
|
case 'tradfi':
|
|
13
16
|
return 'tradfi';
|
|
@@ -60,10 +60,22 @@ export declare function safeDivide(a: number, b: number): number;
|
|
|
60
60
|
export type PriceConvention = 'usEquity' | 'ladder';
|
|
61
61
|
/** The one price-decimals rule: a known tick decides, else a US stock prints 2 from $1 and 4 below, else null. */
|
|
62
62
|
export declare function conventionPriceDecimals(magnitude: number, convention: PriceConvention, tick: number | null | undefined): number | null;
|
|
63
|
-
/**
|
|
63
|
+
/**
|
|
64
|
+
* The magnitude ladder: 1 to 5 decimals by size, and under 1 enough for three significant digits of `magnitude`. The
|
|
65
|
+
* last step of the one market decimals rule (market-price-text.util marketPriceDecimals): it decides only while
|
|
66
|
+
* nothing is known of the market (no tick, no convention, no price of its own seen this session). The only decimals
|
|
67
|
+
* ladder for a market price: tests/utility/chart/market-price-text.decimals.guard.spec.ts fails on a private one.
|
|
68
|
+
*/
|
|
69
|
+
export declare function priceLadderDecimals(magnitude: number): number;
|
|
70
|
+
/**
|
|
71
|
+
* The ticker's digits: the market's tick or convention, else the decimals the market is known to print at
|
|
72
|
+
* (`decimals`: its venue tick's or the decimals its own prices carry, market-price-text.util), else the magnitude
|
|
73
|
+
* ladder; surfaces ask market-price-text.util.
|
|
74
|
+
*/
|
|
64
75
|
export declare function formatPriceByMagnitude(value: number, convention: PriceConvention, opts?: {
|
|
65
76
|
reference?: number;
|
|
66
77
|
tick?: number | null;
|
|
78
|
+
decimals?: number | null;
|
|
67
79
|
}): string;
|
|
68
80
|
export declare function titlePriceDirection(curr: unknown, prev: unknown, lastGlyph?: string): string;
|
|
69
81
|
/**
|
|
@@ -75,6 +87,7 @@ export declare function titlePriceDirection(curr: unknown, prev: unknown, lastGl
|
|
|
75
87
|
*/
|
|
76
88
|
export declare function formatTitlePrice(price: number, convention: PriceConvention, opts?: {
|
|
77
89
|
tick?: number | null;
|
|
90
|
+
decimals?: number | null;
|
|
78
91
|
}): string;
|
|
79
92
|
/** The tab title's price and glyph per chart and market; `formatPrice` prints the market's text (no blind default). */
|
|
80
93
|
export declare function formatChartTitlePrice(price: number, tc: TitleChart, context: {
|
|
@@ -185,7 +185,15 @@ export function conventionPriceDecimals(magnitude, convention, tick) {
|
|
|
185
185
|
return null;
|
|
186
186
|
return Math.abs(magnitude) >= 1 ? US_EQUITY_DECIMALS_FROM_ONE_DOLLAR : US_EQUITY_DECIMALS_BELOW_ONE_DOLLAR;
|
|
187
187
|
}
|
|
188
|
-
/**
|
|
188
|
+
/**
|
|
189
|
+
* The magnitude ladder: 1 to 5 decimals by size, and under 1 enough for three significant digits of `magnitude`. The
|
|
190
|
+
* last step of the one market decimals rule (market-price-text.util marketPriceDecimals): it decides only while
|
|
191
|
+
* nothing is known of the market (no tick, no convention, no price of its own seen this session). The only decimals
|
|
192
|
+
* ladder for a market price: tests/utility/chart/market-price-text.decimals.guard.spec.ts fails on a private one.
|
|
193
|
+
*/
|
|
194
|
+
export function priceLadderDecimals(magnitude) {
|
|
195
|
+
return tickerLadderDecimals(magnitude, magnitude);
|
|
196
|
+
}
|
|
189
197
|
function tickerLadderDecimals(value, magnitude) {
|
|
190
198
|
const ladder = value >= 10000 ? 1 : value >= 1000 ? 2 : value >= 100 ? 3 : value >= 10 ? 4 : 5;
|
|
191
199
|
const floor = magnitude > 0 && magnitude < 1
|
|
@@ -193,12 +201,19 @@ function tickerLadderDecimals(value, magnitude) {
|
|
|
193
201
|
: 0;
|
|
194
202
|
return Math.max(ladder, floor);
|
|
195
203
|
}
|
|
196
|
-
/**
|
|
204
|
+
/** Decimals a caller knows for the market (a whole count in the price axis's range), else null. */
|
|
205
|
+
const knownDecimals = (decimals) => typeof decimals === 'number' && Number.isInteger(decimals) && decimals >= 0 && decimals <= MAX_TICKER_DECIMALS;
|
|
206
|
+
/**
|
|
207
|
+
* The ticker's digits: the market's tick or convention, else the decimals the market is known to print at
|
|
208
|
+
* (`decimals`: its venue tick's or the decimals its own prices carry, market-price-text.util), else the magnitude
|
|
209
|
+
* ladder; surfaces ask market-price-text.util.
|
|
210
|
+
*/
|
|
197
211
|
export function formatPriceByMagnitude(value, convention,
|
|
198
212
|
// `reference`: the price a difference belongs to, whose decimals it prints at.
|
|
199
213
|
opts = {}) {
|
|
200
214
|
const magnitude = Math.abs(opts.reference ?? value);
|
|
201
|
-
const decimals = conventionPriceDecimals(magnitude, convention, opts.tick) ??
|
|
215
|
+
const decimals = conventionPriceDecimals(magnitude, convention, opts.tick) ??
|
|
216
|
+
(knownDecimals(opts.decimals) ? opts.decimals : tickerLadderDecimals(value, magnitude));
|
|
202
217
|
return value >= 10000
|
|
203
218
|
? value.toLocaleString('en-US', { minimumFractionDigits: decimals, maximumFractionDigits: decimals })
|
|
204
219
|
: value.toFixed(decimals);
|
|
@@ -223,7 +238,10 @@ export function titlePriceDirection(curr, prev, lastGlyph = '') {
|
|
|
223
238
|
export function formatTitlePrice(price, convention, opts = {}) {
|
|
224
239
|
if (!Number.isFinite(price))
|
|
225
240
|
return '';
|
|
226
|
-
const [whole, fraction] = formatPriceByMagnitude(Math.abs(price), convention, {
|
|
241
|
+
const [whole, fraction] = formatPriceByMagnitude(Math.abs(price), convention, {
|
|
242
|
+
tick: opts.tick,
|
|
243
|
+
decimals: opts.decimals,
|
|
244
|
+
})
|
|
227
245
|
.replace(/,/g, '')
|
|
228
246
|
.split('.');
|
|
229
247
|
const grouped = whole.replace(/\B(?=(\d{3})+(?!\d))/g, ',');
|