@orangecharts/wrun-chart-host 0.5.0 → 0.7.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.
Files changed (157) hide show
  1. package/README.md +17 -8
  2. package/dist/constants/feature-flags.constants.js +7 -2
  3. package/dist/constants/marketCapabilities.constants.d.ts +5 -0
  4. package/dist/constants/marketCapabilities.constants.js +16 -0
  5. package/dist/host-env.d.ts +3 -19
  6. package/dist/host-ports.types.d.ts +36 -17
  7. package/dist/index.d.ts +12 -1
  8. package/dist/index.js +12 -1
  9. package/dist/indicators/controls/tpo-session.util.js +42 -18
  10. package/dist/interfaces/wrun-runtime.interface.d.ts +88 -13
  11. package/dist/interfaces/wrun-runtime.interface.js +17 -3
  12. package/dist/market-data/billing.interface.d.ts +2 -1
  13. package/dist/settings-templates/indicator-fields.js +10 -0
  14. package/dist/utility/chart/chart-mount-epoch.util.d.ts +12 -0
  15. package/dist/utility/chart/chart-mount-epoch.util.js +32 -0
  16. package/dist/utility/chart/crypto-index.leaf.d.ts +16 -0
  17. package/dist/utility/chart/crypto-index.leaf.js +19 -0
  18. package/dist/utility/chart/index-mode-admission.util.js +9 -1
  19. package/dist/utility/chart/index-mode.util.d.ts +11 -5
  20. package/dist/utility/chart/index-mode.util.js +22 -10
  21. package/dist/utility/chart/kscript-source-answer-budget.leaf.d.ts +36 -0
  22. package/dist/utility/chart/kscript-source-answer-budget.leaf.js +39 -0
  23. package/dist/utility/chart/kscript-source-degrade.leaf.d.ts +38 -1
  24. package/dist/utility/chart/kscript-source-degrade.leaf.js +39 -1
  25. package/dist/utility/chart/live-bucket.util.d.ts +2 -1
  26. package/dist/utility/chart/live-bucket.util.js +47 -15
  27. package/dist/utility/chart/local-kscript-warmup-depth.util.d.ts +15 -1
  28. package/dist/utility/chart/local-kscript-warmup-depth.util.js +9 -0
  29. package/dist/utility/chart/market-session-schedule.util.d.ts +3 -1
  30. package/dist/utility/chart/market-session-schedule.util.js +24 -2
  31. package/dist/utility/chart/marketKind.util.d.ts +12 -7
  32. package/dist/utility/chart/marketKind.util.js +15 -5
  33. package/dist/utility/chart/ny-calendar.util.d.ts +104 -0
  34. package/dist/utility/chart/ny-calendar.util.js +346 -0
  35. package/dist/utility/chart/om-panel.util.d.ts +14 -2
  36. package/dist/utility/chart/om-panel.util.js +108 -40
  37. package/dist/utility/chart/rth-session.util.d.ts +10 -7
  38. package/dist/utility/chart/rth-session.util.js +17 -22
  39. package/dist/utility/chart/trading-day.util.js +90 -18
  40. package/dist/utility/chart/us-equities-session.util.js +20 -67
  41. package/dist/utility/chart/wrun-bar-session-facts.util.js +14 -1
  42. package/dist/utility/common/time.util.d.ts +7 -1
  43. package/dist/utility/common/time.util.js +11 -41
  44. package/dist/utility/number-format.util.d.ts +17 -7
  45. package/dist/utility/number-format.util.js +18 -8
  46. package/dist/utility/options/option-symbol.util.js +13 -2
  47. package/dist/utility/symbol-selection/contract-expiry.util.js +9 -1
  48. package/dist/utility/watchlist/import/import-request.leaf.d.ts +4 -1
  49. package/dist/utility/watchlist/import/import-request.leaf.js +5 -2
  50. package/dist/utility/watchlist/import/tradingview-symbols.leaf.d.ts +25 -4
  51. package/dist/utility/watchlist/import/tradingview-symbols.leaf.js +62 -4
  52. package/dist/utility/wrun/run-schedule/wrun-chart-gate-reader.util.d.ts +19 -0
  53. package/dist/utility/wrun/run-schedule/wrun-chart-gate-reader.util.js +57 -0
  54. package/dist/utility/wrun/run-schedule/wrun-gate-reader-warm.util.d.ts +23 -0
  55. package/dist/utility/wrun/run-schedule/wrun-gate-reader-warm.util.js +90 -0
  56. package/dist/utility/wrun/run-schedule/wrun-lane-groups.util.d.ts +39 -0
  57. package/dist/utility/wrun/run-schedule/wrun-lane-groups.util.js +60 -0
  58. package/dist/utility/wrun/run-schedule/wrun-late-reads.util.d.ts +77 -0
  59. package/dist/utility/wrun/run-schedule/wrun-late-reads.util.js +195 -0
  60. package/dist/utility/wrun/run-schedule/wrun-own-candles.util.d.ts +56 -0
  61. package/dist/utility/wrun/run-schedule/wrun-own-candles.util.js +70 -0
  62. package/dist/utility/wrun/run-schedule/wrun-prefix-feeds.util.d.ts +53 -0
  63. package/dist/utility/wrun/run-schedule/wrun-prefix-feeds.util.js +239 -0
  64. package/dist/utility/wrun/sources/lanes/option_stats_10m.d.ts +16 -0
  65. package/dist/utility/wrun/sources/lanes/option_stats_10m.js +14 -0
  66. package/dist/utility/wrun/sources/lanes/options_flow.d.ts +43 -18
  67. package/dist/utility/wrun/sources/lanes/options_flow.js +209 -72
  68. package/dist/utility/wrun/sources/lanes/token_supply.js +5 -31
  69. package/dist/utility/wrun/sources/opra-option-lanes.util.d.ts +3 -18
  70. package/dist/utility/wrun/sources/opra-option-lanes.util.js +12 -57
  71. package/dist/utility/wrun/sources/row-lane-registry.d.ts +1 -1
  72. package/dist/utility/wrun/sources/row-lane-registry.js +22 -8
  73. package/dist/utility/wrun/sources/row-lanes/option_contract_flow.d.ts +61 -0
  74. package/dist/utility/wrun/sources/row-lanes/option_contract_flow.js +103 -8
  75. package/dist/utility/wrun/sources/row-lanes/option_contract_state.d.ts +5 -0
  76. package/dist/utility/wrun/sources/row-lanes/option_contract_state.js +24 -12
  77. package/dist/utility/wrun/sources/row-lanes/option_prints.d.ts +55 -0
  78. package/dist/utility/wrun/sources/row-lanes/option_prints.js +95 -18
  79. package/dist/utility/wrun/sources/row-lanes/option_strikes.d.ts +15 -1
  80. package/dist/utility/wrun/sources/row-lanes/option_strikes.js +23 -8
  81. package/dist/utility/wrun/sources/row-lanes/option_surface.js +11 -11
  82. package/dist/utility/wrun/sources/wrun-poll-lane.types.d.ts +14 -2
  83. package/dist/utility/wrun/sources/wrun-poll-lane.types.js +6 -3
  84. package/dist/utility/wrun/sources/wrun-poll-lanes.util.d.ts +43 -8
  85. package/dist/utility/wrun/sources/wrun-poll-lanes.util.js +77 -11
  86. package/dist/utility/wrun/sources/wrun-row-lane.types.d.ts +31 -16
  87. package/dist/utility/wrun/sources/wrun-row-lane.types.js +2 -0
  88. package/dist/utility/wrun/sources/wrun-row-lanes.util.d.ts +52 -12
  89. package/dist/utility/wrun/sources/wrun-row-lanes.util.js +110 -46
  90. package/dist/utility/wrun/wrun-bar-count.util.d.ts +17 -6
  91. package/dist/utility/wrun/wrun-bar-count.util.js +27 -12
  92. package/dist/utility/wrun/wrun-browser-sources.leaf.d.ts +10 -0
  93. package/dist/utility/wrun/wrun-browser-sources.leaf.js +12 -0
  94. package/dist/utility/wrun/wrun-coin-lane-live.util.d.ts +3 -3
  95. package/dist/utility/wrun/wrun-coin-lane-live.util.js +53 -18
  96. package/dist/utility/wrun/wrun-color-settings.util.d.ts +6 -0
  97. package/dist/utility/wrun/wrun-color-settings.util.js +45 -0
  98. package/dist/utility/wrun/wrun-draft-overlay.util.js +14 -8
  99. package/dist/utility/wrun/wrun-failure-cause.d.ts +1 -1
  100. package/dist/utility/wrun/wrun-failure-cause.js +14 -0
  101. package/dist/utility/wrun/wrun-frames.js +6 -2
  102. package/dist/utility/wrun/wrun-host.service.d.ts +131 -59
  103. package/dist/utility/wrun/wrun-host.service.js +391 -194
  104. package/dist/utility/wrun/wrun-hosted-wire-caps.d.ts +1 -1
  105. package/dist/utility/wrun/wrun-hosted-wire-caps.js +2 -0
  106. package/dist/utility/wrun/wrun-hover.util.d.ts +3 -0
  107. package/dist/utility/wrun/wrun-hover.util.js +25 -4
  108. package/dist/utility/wrun/wrun-input-requirements.leaf.js +7 -4
  109. package/dist/utility/wrun/wrun-kit-run-tables.util.d.ts +24 -0
  110. package/dist/utility/wrun/wrun-kit-run-tables.util.js +87 -0
  111. package/dist/utility/wrun/wrun-lifecycle.contract.d.ts +2 -1
  112. package/dist/utility/wrun/wrun-live-tick.util.d.ts +8 -2
  113. package/dist/utility/wrun/wrun-live-tick.util.js +35 -16
  114. package/dist/utility/wrun/wrun-opra-flow.leaf.d.ts +40 -13
  115. package/dist/utility/wrun/wrun-opra-flow.leaf.js +39 -12
  116. package/dist/utility/wrun/wrun-option-contract-flow.util.d.ts +70 -21
  117. package/dist/utility/wrun/wrun-option-contract-flow.util.js +257 -112
  118. package/dist/utility/wrun/wrun-option-prints.util.d.ts +62 -22
  119. package/dist/utility/wrun/wrun-option-prints.util.js +148 -46
  120. package/dist/utility/wrun/wrun-option-views.util.d.ts +262 -0
  121. package/dist/utility/wrun/wrun-option-views.util.js +356 -0
  122. package/dist/utility/wrun/wrun-options-chain.util.d.ts +23 -2
  123. package/dist/utility/wrun/wrun-options-chain.util.js +37 -3
  124. package/dist/utility/wrun/wrun-overlay-drivers.util.d.ts +20 -5
  125. package/dist/utility/wrun/wrun-overlay-drivers.util.js +32 -7
  126. package/dist/utility/wrun/wrun-overlay-recovery.util.d.ts +9 -3
  127. package/dist/utility/wrun/wrun-overlay-recovery.util.js +146 -18
  128. package/dist/utility/wrun/wrun-overlay-run.util.d.ts +52 -8
  129. package/dist/utility/wrun/wrun-overlay-run.util.js +816 -243
  130. package/dist/utility/wrun/wrun-pack.util.d.ts +2 -1
  131. package/dist/utility/wrun/wrun-pin-spelling.util.d.ts +5 -0
  132. package/dist/utility/wrun/wrun-pin-spelling.util.js +28 -12
  133. package/dist/utility/wrun/wrun-pin-venues.util.js +4 -6
  134. package/dist/utility/wrun/wrun-prefix-cohort.util.d.ts +1 -1
  135. package/dist/utility/wrun/wrun-prefix-cohort.util.js +1 -1
  136. package/dist/utility/wrun/wrun-present-bits.util.d.ts +9 -0
  137. package/dist/utility/wrun/wrun-present-bits.util.js +39 -0
  138. package/dist/utility/wrun/wrun-refusal-surface.util.d.ts +3 -2
  139. package/dist/utility/wrun/wrun-refusal-surface.util.js +5 -4
  140. package/dist/utility/wrun/wrun-refusal.util.d.ts +66 -6
  141. package/dist/utility/wrun/wrun-refusal.util.js +335 -40
  142. package/dist/utility/wrun/wrun-registry-errors.util.d.ts +5 -3
  143. package/dist/utility/wrun/wrun-sandbox-row-source.d.ts +2 -2
  144. package/dist/utility/wrun/wrun-sha256.leaf.d.ts +13 -0
  145. package/dist/utility/wrun/wrun-sha256.leaf.js +84 -0
  146. package/dist/utility/wrun/wrun-source-rows.util.js +11 -0
  147. package/dist/utility/wrun/wrun-tier-grid.util.d.ts +28 -3
  148. package/dist/utility/wrun/wrun-tier-grid.util.js +79 -19
  149. package/dist/utility/wrun/wrun-transient-rerun.util.d.ts +14 -3
  150. package/dist/utility/wrun/wrun-transient-rerun.util.js +33 -8
  151. package/dist/workers/wrun/wrun-abi-host.d.ts +15 -2
  152. package/dist/workers/wrun/wrun-abi-host.js +31 -12
  153. package/dist/workers/wrun/wrun-engine-handler.d.ts +11 -28
  154. package/dist/workers/wrun/wrun-engine-handler.js +181 -12
  155. package/package.json +5 -5
  156. package/dist/utility/wrun/wrun-opra-underlying.util.d.ts +0 -12
  157. package/dist/utility/wrun/wrun-opra-underlying.util.js +0 -1
@@ -61,6 +61,7 @@ export declare function liveBucketStartMs(tsMs: number, intervalMs: number, venu
61
61
  * `liveBucketStartMs`: a regular-session stock chart's hourly columns sit on its 13:30Z (EDT) candles,
62
62
  * a CME chart's on its session lattice, and an off-session instant contributes none. The bar holding
63
63
  * `fromMs` counts only when it opens inside the range. A probe still inside the last bar (a lattice
64
- * bar the fall-back Sunday stretches) or off session steps forward a quarter hour at most.
64
+ * bar the fall-back Sunday stretches) or off session steps forward a quarter hour at most; on a
65
+ * regular-session stock grid it steps session to session (`resumeProbeMs`) onto the same probes.
65
66
  */
66
67
  export declare function liveBucketStartsInRange(fromMs: number, toMs: number, intervalMs: number, venue?: LiveBucketVenue | null): number[];
@@ -30,6 +30,7 @@ import { checkIsEconomic } from './marketKind.util.js';
30
30
  import { extractTokensFromTransformations, parsedTransformations } from '../common/transformations.util.js';
31
31
  import { isChartRthActive, isFootprintRthFoldTfMs, isRthBucketExactIntervalMs, rthAnchoredBucketStartMs, } from './rth-session.util.js';
32
32
  import { isEquityRegularSessionGated, usEquityAnchoredBucketStartMs, usEquitySessionGridBucketStartMs, } from './us-equities-session.util.js';
33
+ import { nyNextRegularOpenAfterMs } from './ny-calendar.util.js';
33
34
  const THREE_DAYS_MS = Intervals.map_unit['3d'];
34
35
  /**
35
36
  * A chart's bar-grid identity as a worker reads it (plain, cloneable fields only): the venue a worker
@@ -107,7 +108,7 @@ export function cmeSessionLatticeBucketMs(tsMs, intervalMs, venue) {
107
108
  return null;
108
109
  return isCmeSessionLatticeVenue(venue) ? cmeSessionBucketMs(tsMs, intervalMs) : null;
109
110
  }
110
- export function liveBucketStartMs(tsMs, intervalMs, venue) {
111
+ function liveBucketGrid(intervalMs, venue) {
111
112
  // Calendar and weekly bars: a CME venue's trade-date months and weeks (a
112
113
  // month opens at the 17:00 Chicago open before its first trade date), else
113
114
  // the plain grid. Regular-session US equities group the session's daily bars
@@ -115,45 +116,76 @@ export function liveBucketStartMs(tsMs, intervalMs, venue) {
115
116
  // market; if the gateway stamps them on the first trade date's open instead,
116
117
  // this branch needs the session's own month key.
117
118
  if (calendarMonthsOfMs(intervalMs) !== null || intervalMs === TimeIntervalConstant.week) {
118
- return isCmeSessionLatticeVenue(venue)
119
- ? cmeSessionBucketMs(tsMs, intervalMs)
120
- : plainBucketStartMs(tsMs, intervalMs);
119
+ return isCmeSessionLatticeVenue(venue) ? 'cme-session' : 'plain';
121
120
  }
122
121
  if (venue && !isRthBucketExactIntervalMs(intervalMs)) {
123
- if (isChartRthActive(venue.exchange, venue.symbol, venue.sessionType, intervalMs)) {
124
- return rthAnchoredBucketStartMs(venue.symbol, tsMs, intervalMs);
125
- }
122
+ if (isChartRthActive(venue.exchange, venue.symbol, venue.sessionType, intervalMs))
123
+ return 'rth-anchored';
126
124
  if (isEquityRegularSessionGated(venue.exchange, venue.sessionType)) {
127
125
  if (isFootprintRthFoldTfMs(intervalMs))
128
- return usEquityAnchoredBucketStartMs(tsMs, intervalMs);
126
+ return 'equity-anchored';
129
127
  if (intervalMs === THREE_DAYS_MS)
130
- return usEquitySessionGridBucketStartMs(tsMs);
128
+ return 'equity-session-group';
131
129
  }
132
- if (isCmeSessionLatticeIntervalMs(intervalMs) && isCmeSessionLatticeVenue(venue)) {
130
+ if (isCmeSessionLatticeIntervalMs(intervalMs) && isCmeSessionLatticeVenue(venue))
131
+ return 'cme-session';
132
+ }
133
+ return 'utc-floor';
134
+ }
135
+ function bucketStartOnGrid(grid, tsMs, intervalMs, venue) {
136
+ switch (grid) {
137
+ case 'cme-session':
133
138
  return cmeSessionBucketMs(tsMs, intervalMs);
134
- }
139
+ case 'plain':
140
+ return plainBucketStartMs(tsMs, intervalMs);
141
+ case 'rth-anchored':
142
+ return rthAnchoredBucketStartMs(venue?.symbol, tsMs, intervalMs);
143
+ case 'equity-anchored':
144
+ return usEquityAnchoredBucketStartMs(tsMs, intervalMs);
145
+ case 'equity-session-group':
146
+ return usEquitySessionGridBucketStartMs(tsMs);
147
+ default:
148
+ return tsMs - (tsMs % intervalMs);
135
149
  }
136
- return tsMs - (tsMs % intervalMs);
150
+ }
151
+ export function liveBucketStartMs(tsMs, intervalMs, venue) {
152
+ return bucketStartOnGrid(liveBucketGrid(intervalMs, venue), tsMs, intervalMs, venue);
137
153
  }
138
154
  /** The probe step through an off-session gap: every open the anchored grids sit on is on the quarter hour. */
139
155
  const OFF_SESSION_PROBE_MS = 15 * 60_000;
156
+ /**
157
+ * Where the walk resumes after `probeMs` opened no new bar (`offSession`: no bar holds it). A
158
+ * regular-session stock grid opens bars only inside the cash session, and its 3d bar spans whole
159
+ * sessions, so every probe before the next regular open would come back empty: the walk lands on
160
+ * the first probe of the same quarter-hour run at or after that open, one New York calendar lookup
161
+ * per trade date, and ends when no open comes by `toMs`. Every other grid steps a quarter hour.
162
+ */
163
+ function resumeProbeMs(grid, probeMs, stepMs, offSession, toMs) {
164
+ if (grid === 'equity-session-group' || (grid === 'equity-anchored' && offSession)) {
165
+ const openMs = nyNextRegularOpenAfterMs(probeMs, toMs);
166
+ return openMs === null ? Number.POSITIVE_INFINITY : probeMs + Math.ceil((openMs - probeMs) / stepMs) * stepMs;
167
+ }
168
+ return probeMs + stepMs;
169
+ }
140
170
  /**
141
171
  * The starts of the venue's bars that open inside `[fromMs, toMs]`, ascending, each keyed by
142
172
  * `liveBucketStartMs`: a regular-session stock chart's hourly columns sit on its 13:30Z (EDT) candles,
143
173
  * a CME chart's on its session lattice, and an off-session instant contributes none. The bar holding
144
174
  * `fromMs` counts only when it opens inside the range. A probe still inside the last bar (a lattice
145
- * bar the fall-back Sunday stretches) or off session steps forward a quarter hour at most.
175
+ * bar the fall-back Sunday stretches) or off session steps forward a quarter hour at most; on a
176
+ * regular-session stock grid it steps session to session (`resumeProbeMs`) onto the same probes.
146
177
  */
147
178
  export function liveBucketStartsInRange(fromMs, toMs, intervalMs, venue) {
148
179
  const starts = [];
149
180
  if (!(intervalMs > 0) || !Number.isFinite(fromMs) || !Number.isFinite(toMs))
150
181
  return starts;
182
+ const grid = liveBucketGrid(intervalMs, venue);
151
183
  const stepMs = Math.min(intervalMs, OFF_SESSION_PROBE_MS);
152
184
  let last = -Infinity;
153
185
  for (let probe = fromMs; probe <= toMs;) {
154
- const start = liveBucketStartMs(probe, intervalMs, venue);
186
+ const start = bucketStartOnGrid(grid, probe, intervalMs, venue);
155
187
  if (start === null || start <= last) {
156
- probe += stepMs;
188
+ probe = resumeProbeMs(grid, probe, stepMs, start === null, toMs);
157
189
  continue;
158
190
  }
159
191
  last = start;
@@ -45,7 +45,9 @@ type LocalKScriptWarmupDepthSkipReason = 'no-rows' | 'no-viewport' | 'warmup-off
45
45
  /** A source of the script is still loading, degraded, or never settled: an all-NaN run is not warmup evidence. */
46
46
  | 'sources-pending'
47
47
  /** The script declares a lookback of 0 and simply printed nothing: an empty output is not a warmup gap. */
48
- | 'zero-lookback-empty';
48
+ | 'zero-lookback-empty'
49
+ /** The visible first value is where a source's history begins (`sourceReachFromTs`): no page can move it. */
50
+ | 'source-reach';
49
51
  export type LocalKScriptWarmupDepthDecision = {
50
52
  fetch: true;
51
53
  reason: 'warmup-visible' | 'no-values-yet' | 'declared-depth';
@@ -105,6 +107,15 @@ export interface LocalKScriptWarmupDepthInput {
105
107
  lookbackBars: number | null;
106
108
  /** Every source of the engine settled for the current timeline (the proxy's sourceSettlementLedger). */
107
109
  sourcesSettled: boolean;
110
+ /**
111
+ * Where the rows of the result's history sources begin at the clock, null or absent when unknown or when a source
112
+ * reads without a reach (the wrun lane: `wrunRunSourceReachFromMs`, the earliest of its row lanes' reaches, a
113
+ * horizon's served start or the oldest bar a lane's longest-kept tier holds). A visible first value at or after it,
114
+ * with the reach at or after the loaded start, is that history beginning, not a warm-up: a page of candles older
115
+ * than the loaded start holds none of the source's rows, so it cannot move the first value ('source-reach'). Spot
116
+ * Exposures on a 52-day 1h viewport bought a 500-bar page this way for strike rows kept 7 days (INT 2026-10-20).
117
+ */
118
+ sourceReachFromTs?: number | null;
108
119
  }
109
120
  /**
110
121
  * Bars in the loaded main window: floor((last - first) / interval) + 1. Null
@@ -124,6 +135,9 @@ export declare function loadedBarsOfWindow(loadedFirstTs: number | null | undefi
124
135
  * value at the loaded start, is the one non-observed reason ('declared-depth',
125
136
  * sized to the shortfall, one page at a time; a shortfall under the absolute
126
137
  * gap floor, or the caller's `minGapBars`, is left alone like any other small gap).
138
+ * A visible first value that a source's history explains (`sourceReachFromTs`:
139
+ * that history begins inside the loaded window and the first value at or after
140
+ * it) owes no page: older candles hold none of the source's rows.
127
141
  */
128
142
  export declare function chooseLocalKScriptWarmupDepth(input: LocalKScriptWarmupDepthInput): LocalKScriptWarmupDepthDecision;
129
143
  export interface WarmupOutputLike {
@@ -87,6 +87,9 @@ export function loadedBarsOfWindow(loadedFirstTs, loadedLastTs, intervalMs) {
87
87
  * value at the loaded start, is the one non-observed reason ('declared-depth',
88
88
  * sized to the shortfall, one page at a time; a shortfall under the absolute
89
89
  * gap floor, or the caller's `minGapBars`, is left alone like any other small gap).
90
+ * A visible first value that a source's history explains (`sourceReachFromTs`:
91
+ * that history begins inside the loaded window and the first value at or after
92
+ * it) owes no page: older candles hold none of the source's rows.
90
93
  */
91
94
  export function chooseLocalKScriptWarmupDepth(input) {
92
95
  if (!isFiniteTs(input.loadedFirstTs))
@@ -171,6 +174,12 @@ export function chooseLocalKScriptWarmupDepth(input) {
171
174
  const minGapBars = Math.max(LOCAL_KSCRIPT_WARMUP_DEPTH_MIN_GAP_BARS, Math.ceil(viewportBars * LOCAL_KSCRIPT_WARMUP_DEPTH_MIN_GAP_VIEWPORT_FRACTION));
172
175
  if (missingBars < minGapBars)
173
176
  return { fetch: false, reason: 'gap-too-small' };
177
+ // A first value a source's history explains: that history begins inside the loaded window and the first value sits
178
+ // at or after its start, so a page of older candles holds none of the source's rows and cannot move it.
179
+ const reachTs = input.sourceReachFromTs;
180
+ if (isFiniteTs(reachTs) && reachTs >= input.loadedFirstTs && input.firstValueTs >= reachTs) {
181
+ return { fetch: false, reason: 'source-reach' };
182
+ }
174
183
  // The need is the observed visible gap, capped at two buckets. A known
175
184
  // lookback caps it further at max(lookback, one bucket): a script declaring
176
185
  // 5 bars never gets a second bucket even behind a 300-bar visible gap, a
@@ -16,7 +16,9 @@
16
16
  * until the data latch corrects it. Known-coarse by design (v1).
17
17
  *
18
18
  * All math is done in exchange wall-clock parts obtained through Intl with an
19
- * explicit timeZone, then converted back to UTC instants with the dual-offset
19
+ * explicit timeZone (the zone clock in ny-calendar.util: one Intl reading per
20
+ * UTC day, so the 1 Hz status tick does date arithmetic, not ~20 Intl calls),
21
+ * then converted back to UTC instants with the dual-offset
20
22
  * probe (try CST/CDT, keep the one that renders back to the intended wall
21
23
  * time). The session boundaries (16:00/17:00) are never inside a DST jump
22
24
  * (those happen at 02:00 local), so the probe is always unambiguous.
@@ -16,12 +16,15 @@
16
16
  * until the data latch corrects it. Known-coarse by design (v1).
17
17
  *
18
18
  * All math is done in exchange wall-clock parts obtained through Intl with an
19
- * explicit timeZone, then converted back to UTC instants with the dual-offset
19
+ * explicit timeZone (the zone clock in ny-calendar.util: one Intl reading per
20
+ * UTC day, so the 1 Hz status tick does date arithmetic, not ~20 Intl calls),
21
+ * then converted back to UTC instants with the dual-offset
20
22
  * probe (try CST/CDT, keep the one that renders back to the intended wall
21
23
  * time). The session boundaries (16:00/17:00) are never inside a DST jump
22
24
  * (those happen at 02:00 local), so the probe is always unambiguous.
23
25
  */
24
26
  import { cmeServedAccessForExchange } from './cme-cache-context.util.js';
27
+ import { zoneWallMsAt } from './ny-calendar.util.js';
25
28
  import { getRthWindowForSymbol, rthSessionOpenMs } from './rth-session.util.js';
26
29
  import { delayedDefaultSecondsFor, gateProviderForExchange } from '../v2/gate-plane.util.js';
27
30
  export const GOVERNED_FUTURES_TIME_ZONE = 'America/Chicago';
@@ -40,7 +43,8 @@ const partsFormatter = new Intl.DateTimeFormat('en-US', {
40
43
  minute: 'numeric',
41
44
  hourCycle: 'h23',
42
45
  });
43
- function wallClockPartsAt(utcMs) {
46
+ /** The Chicago wall clock read from Intl: for the instants the zone clock does not serve (it throws for a non-date). */
47
+ function readWallClockParts(utcMs) {
44
48
  const parts = {};
45
49
  for (const p of partsFormatter.formatToParts(new Date(utcMs)))
46
50
  parts[p.type] = p.value;
@@ -54,6 +58,24 @@ function wallClockPartsAt(utcMs) {
54
58
  minute: Number(parts.minute),
55
59
  };
56
60
  }
61
+ /**
62
+ * The Chicago wall clock at `utcMs`: one Intl reading per UTC day (the zone clock in
63
+ * ny-calendar.util), then date arithmetic. A status reads it about 20 times, every second.
64
+ */
65
+ function wallClockPartsAt(utcMs) {
66
+ const wallMs = zoneWallMsAt(GOVERNED_FUTURES_TIME_ZONE, utcMs);
67
+ if (Number.isNaN(wallMs))
68
+ return readWallClockParts(utcMs);
69
+ const wall = new Date(wallMs);
70
+ return {
71
+ year: wall.getUTCFullYear(),
72
+ month: wall.getUTCMonth() + 1,
73
+ day: wall.getUTCDate(),
74
+ weekday: wall.getUTCDay(),
75
+ hour: wall.getUTCHours(),
76
+ minute: wall.getUTCMinutes(),
77
+ };
78
+ }
57
79
  /**
58
80
  * UTC instant for a Chicago wall-clock time on the calendar day of `dayAnchorUtcMs`
59
81
  * (anchored at noon UTC so day arithmetic never straddles a DST jump). Probes the
@@ -4,12 +4,13 @@ import { type OmTargetMetadata } from './om-target.util.js';
4
4
  /**
5
5
  * The frontend's market-kind vocabulary: TitanCharts' `MarketKind` union plus
6
6
  * FE-owned kinds for governed CME venues (`'futures'`), HyperLiquid
7
- * prediction markets (`'hip4'`) and economic series (`'economic'`: FRED and
8
- * the ECONOMICS catalog publishers, which the engine still knows as `'fred'`).
7
+ * prediction markets (`'hip4'`), economic series (`'economic'`: FRED and
8
+ * the ECONOMICS catalog publishers, which the engine still knows as `'fred'`)
9
+ * and the crypto-wide indices (`'cryptoIndex'`: CRYPTOCAP's BTC.D, TOTAL, ...).
9
10
  * TitanCharts does not know these kinds; anything handed into the engine
10
11
  * narrows through `toTitanMarketKind`.
11
12
  */
12
- export type VenueMarketKind = Exclude<MarketKind, 'fred'> | 'economic' | 'futures' | 'hip4' | 'options';
13
+ export type VenueMarketKind = Exclude<MarketKind, 'fred'> | 'economic' | 'futures' | 'hip4' | 'options' | 'cryptoIndex';
13
14
  /** Which wire path serves an economic series (see `economicSource`). */
14
15
  export type EconomicSource = 'fred' | 'observation';
15
16
  /**
@@ -123,14 +124,18 @@ export declare function checkIsForexCommodityOrFutures(exchange: string | undefi
123
124
  * Narrow the FE kind to TitanCharts' `MarketKind` union at the engine
124
125
  * boundary. `'futures'` maps to `'commodity'` for session handling; `'hip4'`
125
126
  * maps to `'polymarket'` for the prediction renderer; `'economic'` maps to
126
- * the engine's `'fred'` (single-value series treatment). FE-internal code
127
- * always sees the honest venue kind.
127
+ * the engine's `'fred'` (single-value series treatment); `'cryptoIndex'`
128
+ * maps to `'crypto'`: the indices print 24/7 (about every 250 ms after a
129
+ * price move, every 5 s per coin) onto uniform bars from 1m up, the crypto
130
+ * treatment's own shape, gap policy included. FE-internal code always sees
131
+ * the honest venue kind.
128
132
  */
129
133
  export declare function toTitanMarketKind(kind: VenueMarketKind): MarketKind;
130
134
  /**
131
135
  * True when TitanCharts must omit the dedicated 'volume' legend overlay:
132
- * economic series and forex/commodity venues ship no per-bar volume. Governed
133
- * CME futures DO ship contracts volume on TRADE_AGG bars, so they keep it.
136
+ * economic series, forex/commodity venues and the crypto indices ship no
137
+ * per-bar volume. Governed CME futures DO ship contracts volume on TRADE_AGG
138
+ * bars, so they keep it.
134
139
  */
135
140
  export declare function venueOmitsVolumeOverlay(exchange: string | undefined | null): boolean;
136
141
  export declare function checkIsDex(exchange: string | undefined | null): boolean;
@@ -1,6 +1,7 @@
1
1
  import { MARKET_CAPABILITIES, ONCHAIN_POOL_CAPABILITIES, } from '../../constants/marketCapabilities.constants.js';
2
2
  import { isBlkExchange } from '../blk-market.util.js';
3
3
  import { ECONOMIC_EXCHANGES, FRED_EXCHANGE } from '../../constants/economic.constants.js';
4
+ import { CRYPTO_INDEX_EXCHANGES } from './crypto-index.leaf.js';
4
5
  import { isCmeGoverned, normalizeExchangeCode } from './cme-realtime.util.js';
5
6
  import { isGovernedPlaneExchange } from '../v2/gate-plane.util.js';
6
7
  import { isOmTargetPane } from './om-target.util.js';
@@ -76,6 +77,9 @@ const EXCHANGE_TO_KIND = {
76
77
  // Economic series: FRED plus the ECONOMICS catalog venue and the observation
77
78
  // publishers (economic.constants.ts owns the list).
78
79
  ...Object.fromEntries(ECONOMIC_EXCHANGES.map((code) => [code, 'economic'])),
80
+ // Crypto-wide indices (CRYPTOCAP): value prints 24/7 with no trades,
81
+ // volume or book behind them (crypto-index.leaf owns the list).
82
+ ...Object.fromEntries(CRYPTO_INDEX_EXCHANGES.map((code) => [code, 'cryptoIndex'])),
79
83
  // Polymarket
80
84
  POLYMARKET: 'polymarket',
81
85
  // Hip3 (Hyperliquid synthetic derivatives)
@@ -278,8 +282,11 @@ export function checkIsForexCommodityOrFutures(exchange) {
278
282
  * Narrow the FE kind to TitanCharts' `MarketKind` union at the engine
279
283
  * boundary. `'futures'` maps to `'commodity'` for session handling; `'hip4'`
280
284
  * maps to `'polymarket'` for the prediction renderer; `'economic'` maps to
281
- * the engine's `'fred'` (single-value series treatment). FE-internal code
282
- * always sees the honest venue kind.
285
+ * the engine's `'fred'` (single-value series treatment); `'cryptoIndex'`
286
+ * maps to `'crypto'`: the indices print 24/7 (about every 250 ms after a
287
+ * price move, every 5 s per coin) onto uniform bars from 1m up, the crypto
288
+ * treatment's own shape, gap policy included. FE-internal code always sees
289
+ * the honest venue kind.
283
290
  */
284
291
  export function toTitanMarketKind(kind) {
285
292
  if (kind === 'futures' || kind === 'options')
@@ -288,15 +295,18 @@ export function toTitanMarketKind(kind) {
288
295
  return 'polymarket';
289
296
  if (kind === 'economic')
290
297
  return 'fred';
298
+ if (kind === 'cryptoIndex')
299
+ return 'crypto';
291
300
  return kind;
292
301
  }
293
302
  /**
294
303
  * True when TitanCharts must omit the dedicated 'volume' legend overlay:
295
- * economic series and forex/commodity venues ship no per-bar volume. Governed
296
- * CME futures DO ship contracts volume on TRADE_AGG bars, so they keep it.
304
+ * economic series, forex/commodity venues and the crypto indices ship no
305
+ * per-bar volume. Governed CME futures DO ship contracts volume on TRADE_AGG
306
+ * bars, so they keep it.
297
307
  */
298
308
  export function venueOmitsVolumeOverlay(exchange) {
299
- return checkIsEconomic(exchange) || checkIsForexOrCommodity(exchange);
309
+ return checkIsEconomic(exchange) || checkIsForexOrCommodity(exchange) || getMarketKind(exchange) === 'cryptoIndex';
300
310
  }
301
311
  export function checkIsDex(exchange) {
302
312
  return getMarketKind(exchange) === 'dex';
@@ -0,0 +1,104 @@
1
+ /**
2
+ * The shared point for per-row timezone math: a zone clock for any IANA zone (one Intl reading per
3
+ * UTC day), and on it the New York calendar behind every US equities session question (the pre /
4
+ * regular / after phase, the 09:30 anchored bucket, the next regular open), resolved once per date.
5
+ *
6
+ * Why this exists (CPU profiles 2026-10-20, UW-PARITY reports/INDICATOR-LOAD-BUDGET.md): on 45m
7
+ * to 12h stock bars every landed row re-derived the New York wall clock through dayjs
8
+ * (`checkUSMarketHours`, plus a format and a parse for the anchored bucket), about 24 us per
9
+ * conversion. One 1h Flow Marks add spent 8.9 s in dayjs `.tz`, and the host-bar walk
10
+ * (`liveBucketStartsInRange`) probed every quarter hour through nights and weekends at three
11
+ * conversions a probe. The same mistake sat in the Chicago schedule (about 20 Intl readings per
12
+ * status, every second), the regional session windows, the option symbol dates and the bar facts.
13
+ * An offset changes twice a year, so each zone reads it once per UTC day into a bounded memo and
14
+ * every row does integer math against it.
15
+ *
16
+ * The zone clock (`zoneOffsetMsAt`, `zoneWallMsAt`, `zoneWallToUtcMs`) reads Intl at a UTC day's
17
+ * first and last second; a day whose two readings differ is bisected to the second the offset
18
+ * changes on. Exact for any zone that changes its offset at most once per UTC day (every zone the
19
+ * app reads); a second change inside one day is detected and read per instant. It serves the
20
+ * instants from the year 100 to the Date range edge: a caller keeps its own reading outside them.
21
+ *
22
+ * The New York calendar, per date (DST-exact on the 23h and 25h days): its span [00:00, next 00:00)
23
+ * and its session edges in UTC ms, on the weekday cycle `checkUSMarketHours` has always read:
24
+ * pre 04:00 -> 09:30
25
+ * regular 09:30 -> 16:00
26
+ * after 16:00 -> 20:00
27
+ * closed everything else, and all of Saturday and Sunday
28
+ * Holidays and half days are NOT modelled (the v1 scope of us-equities-session.util): an
29
+ * exchange holiday reads as a normal weekday.
30
+ *
31
+ * Host-independent (dayjs re-parsed the zone's wall string in the host zone, which misreads an
32
+ * hour on the host's own DST days). Pure and worker-safe: Intl only, no dayjs.
33
+ */
34
+ export declare const NY_TIME_ZONE = "America/New_York";
35
+ /** Session edges as wall-clock minutes after New York midnight. */
36
+ export declare const NY_PRE_MARKET_OPEN_MINUTES: number;
37
+ export declare const NY_REGULAR_OPEN_MINUTES: number;
38
+ export declare const NY_REGULAR_CLOSE_MINUTES: number;
39
+ export declare const NY_POST_MARKET_CLOSE_MINUTES: number;
40
+ export type NyMarketPhase = 'pre' | 'regular' | 'after' | 'closed';
41
+ /** One New York calendar date, resolved once: its span and its session edges in UTC ms. */
42
+ export interface NyCalendarDay {
43
+ /** The date as whole days since 1970-01-01 (its 00:00Z over 86,400,000). */
44
+ readonly dayNumber: number;
45
+ /** 0 Sunday to 6 Saturday. */
46
+ readonly weekday: number;
47
+ /** Monday to Friday: a date with sessions (holidays are not modelled). */
48
+ readonly isTradeDate: boolean;
49
+ /** New York midnight that starts the date, and the next one: the date is [dayStartMs, dayEndMs). */
50
+ readonly dayStartMs: number;
51
+ readonly dayEndMs: number;
52
+ /** Wall clock minus UTC at the regular open, in ms (-4h in EDT, -5h in EST). */
53
+ readonly utcOffsetMs: number;
54
+ readonly preMarketOpenMs: number;
55
+ readonly regularOpenMs: number;
56
+ /** The regular close, which is also the after-hours open. */
57
+ readonly regularCloseMs: number;
58
+ readonly postMarketCloseMs: number;
59
+ }
60
+ /** Test oracle: New York dates resolved (`computed`), instants looked up (`lookups`), zone UTC days read (`zoneDays`). */
61
+ export declare const __nyCalendarStats: {
62
+ computed: number;
63
+ lookups: number;
64
+ zoneDays: number;
65
+ };
66
+ /**
67
+ * `zone`'s offset at `tMs` (wall clock minus UTC, ms; a fractional ms truncates, as a Date's does).
68
+ * NaN outside the instants the clock serves (from the year 100 to the Date range edge): the caller
69
+ * keeps its own reading there. Throws Intl's RangeError for a zone it does not know.
70
+ */
71
+ export declare function zoneOffsetMsAt(zone: string, tMs: number): number;
72
+ /** The wall clock `tMs` reads in `zone`, as a UTC-shaped epoch at ms precision; NaN outside the span served. */
73
+ export declare function zoneWallMsAt(zone: string, tMs: number): number;
74
+ /**
75
+ * The instant `zone`'s wall clock reads `wallMs` (a UTC-shaped epoch), by fixed-point iteration from
76
+ * `seedOffsetMs` (the offset at `wallMs` read as an instant, when absent): an instant whose own offset
77
+ * is the one it was solved with is the answer, so a wall time on either side of a change settles on
78
+ * its own offset in one or two reads. A wall time a change skips or repeats settles on one of its
79
+ * readings: callers keep their edges off the change. NaN outside the span served.
80
+ */
81
+ export declare function zoneWallToUtcMs(zone: string, wallMs: number, seedOffsetMs?: number): number;
82
+ /** Test hook: empty memos (the New York dates and every zone's UTC days) and zeroed counters. */
83
+ export declare function __resetNyCalendarMemo(): void;
84
+ /**
85
+ * The New York calendar date `dayNumber` (days since 1970-01-01), resolved once; null outside the
86
+ * span the zone clock serves, and where the runtime has no New York zone data.
87
+ */
88
+ export declare function nyCalendarDay(dayNumber: number): NyCalendarDay | null;
89
+ /**
90
+ * The New York calendar date holding the instant `tsMs`; a fractional ms truncates, as a Date's
91
+ * does. Null for a non-finite instant or one outside the span the zone clock serves.
92
+ */
93
+ export declare function nyCalendarDayAt(tsMs: number): NyCalendarDay | null;
94
+ /** The session phase at `tsMs`: 'closed' on Saturday and Sunday, and for an instant that is not a date. */
95
+ export declare function nyMarketPhaseAt(tsMs: number): NyMarketPhase;
96
+ /** The regular open of the cash session holding `tsMs`; null outside [09:30, 16:00) on a trade date. */
97
+ export declare function nyRegularSessionOpenMs(tsMs: number): number | null;
98
+ /**
99
+ * The first regular open strictly after `tsMs`: the same date's while before it, else the next
100
+ * Monday-to-Friday date's (weekend dates are skipped by arithmetic, never resolved). Null when
101
+ * there is none at or before `notAfterMs`, or outside the span served: a walk bounded by
102
+ * `notAfterMs` never resolves a date it will not reach (a date's open is after its own 00:00Z).
103
+ */
104
+ export declare function nyNextRegularOpenAfterMs(tsMs: number, notAfterMs?: number): number | null;