@orangecharts/wrun-chart-host 0.6.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 (136) hide show
  1. package/README.md +13 -5
  2. package/dist/constants/marketCapabilities.constants.d.ts +5 -0
  3. package/dist/constants/marketCapabilities.constants.js +16 -0
  4. package/dist/host-ports.types.d.ts +35 -3
  5. package/dist/index.d.ts +11 -1
  6. package/dist/index.js +11 -1
  7. package/dist/indicators/controls/tpo-session.util.js +42 -18
  8. package/dist/market-data/billing.interface.d.ts +2 -1
  9. package/dist/settings-templates/indicator-fields.js +10 -0
  10. package/dist/utility/chart/crypto-index.leaf.d.ts +16 -0
  11. package/dist/utility/chart/crypto-index.leaf.js +19 -0
  12. package/dist/utility/chart/index-mode-admission.util.js +9 -1
  13. package/dist/utility/chart/index-mode.util.d.ts +11 -5
  14. package/dist/utility/chart/index-mode.util.js +22 -10
  15. package/dist/utility/chart/kscript-source-answer-budget.leaf.d.ts +36 -0
  16. package/dist/utility/chart/kscript-source-answer-budget.leaf.js +39 -0
  17. package/dist/utility/chart/kscript-source-degrade.leaf.d.ts +38 -1
  18. package/dist/utility/chart/kscript-source-degrade.leaf.js +39 -1
  19. package/dist/utility/chart/live-bucket.util.d.ts +2 -1
  20. package/dist/utility/chart/live-bucket.util.js +47 -15
  21. package/dist/utility/chart/local-kscript-warmup-depth.util.d.ts +15 -1
  22. package/dist/utility/chart/local-kscript-warmup-depth.util.js +9 -0
  23. package/dist/utility/chart/market-session-schedule.util.d.ts +3 -1
  24. package/dist/utility/chart/market-session-schedule.util.js +24 -2
  25. package/dist/utility/chart/marketKind.util.d.ts +12 -7
  26. package/dist/utility/chart/marketKind.util.js +15 -5
  27. package/dist/utility/chart/ny-calendar.util.d.ts +104 -0
  28. package/dist/utility/chart/ny-calendar.util.js +346 -0
  29. package/dist/utility/chart/om-panel.util.d.ts +14 -2
  30. package/dist/utility/chart/om-panel.util.js +108 -40
  31. package/dist/utility/chart/rth-session.util.d.ts +10 -7
  32. package/dist/utility/chart/rth-session.util.js +17 -22
  33. package/dist/utility/chart/trading-day.util.js +90 -18
  34. package/dist/utility/chart/us-equities-session.util.js +20 -67
  35. package/dist/utility/chart/wrun-bar-session-facts.util.js +14 -1
  36. package/dist/utility/common/time.util.d.ts +7 -1
  37. package/dist/utility/common/time.util.js +11 -41
  38. package/dist/utility/number-format.util.d.ts +17 -7
  39. package/dist/utility/number-format.util.js +18 -8
  40. package/dist/utility/options/option-symbol.util.js +13 -2
  41. package/dist/utility/symbol-selection/contract-expiry.util.js +9 -1
  42. package/dist/utility/watchlist/import/import-request.leaf.d.ts +4 -1
  43. package/dist/utility/watchlist/import/import-request.leaf.js +5 -2
  44. package/dist/utility/watchlist/import/tradingview-symbols.leaf.d.ts +25 -4
  45. package/dist/utility/watchlist/import/tradingview-symbols.leaf.js +62 -4
  46. package/dist/utility/wrun/run-schedule/wrun-chart-gate-reader.util.d.ts +19 -0
  47. package/dist/utility/wrun/run-schedule/wrun-chart-gate-reader.util.js +57 -0
  48. package/dist/utility/wrun/run-schedule/wrun-gate-reader-warm.util.d.ts +23 -0
  49. package/dist/utility/wrun/run-schedule/wrun-gate-reader-warm.util.js +90 -0
  50. package/dist/utility/wrun/run-schedule/wrun-lane-groups.util.d.ts +39 -0
  51. package/dist/utility/wrun/run-schedule/wrun-lane-groups.util.js +60 -0
  52. package/dist/utility/wrun/run-schedule/wrun-late-reads.util.d.ts +77 -0
  53. package/dist/utility/wrun/run-schedule/wrun-late-reads.util.js +195 -0
  54. package/dist/utility/wrun/run-schedule/wrun-own-candles.util.d.ts +56 -0
  55. package/dist/utility/wrun/run-schedule/wrun-own-candles.util.js +70 -0
  56. package/dist/utility/wrun/run-schedule/wrun-prefix-feeds.util.d.ts +53 -0
  57. package/dist/utility/wrun/run-schedule/wrun-prefix-feeds.util.js +239 -0
  58. package/dist/utility/wrun/sources/lanes/option_stats_10m.d.ts +16 -0
  59. package/dist/utility/wrun/sources/lanes/option_stats_10m.js +14 -0
  60. package/dist/utility/wrun/sources/lanes/options_flow.d.ts +43 -18
  61. package/dist/utility/wrun/sources/lanes/options_flow.js +209 -72
  62. package/dist/utility/wrun/sources/lanes/token_supply.js +5 -31
  63. package/dist/utility/wrun/sources/opra-option-lanes.util.d.ts +3 -18
  64. package/dist/utility/wrun/sources/opra-option-lanes.util.js +12 -57
  65. package/dist/utility/wrun/sources/row-lane-registry.d.ts +1 -1
  66. package/dist/utility/wrun/sources/row-lane-registry.js +22 -8
  67. package/dist/utility/wrun/sources/row-lanes/option_contract_flow.d.ts +61 -0
  68. package/dist/utility/wrun/sources/row-lanes/option_contract_flow.js +103 -8
  69. package/dist/utility/wrun/sources/row-lanes/option_contract_state.d.ts +5 -0
  70. package/dist/utility/wrun/sources/row-lanes/option_contract_state.js +24 -12
  71. package/dist/utility/wrun/sources/row-lanes/option_prints.d.ts +55 -0
  72. package/dist/utility/wrun/sources/row-lanes/option_prints.js +95 -18
  73. package/dist/utility/wrun/sources/row-lanes/option_strikes.d.ts +15 -1
  74. package/dist/utility/wrun/sources/row-lanes/option_strikes.js +23 -8
  75. package/dist/utility/wrun/sources/row-lanes/option_surface.js +11 -11
  76. package/dist/utility/wrun/sources/wrun-poll-lane.types.d.ts +14 -2
  77. package/dist/utility/wrun/sources/wrun-poll-lane.types.js +6 -3
  78. package/dist/utility/wrun/sources/wrun-poll-lanes.util.d.ts +43 -8
  79. package/dist/utility/wrun/sources/wrun-poll-lanes.util.js +77 -11
  80. package/dist/utility/wrun/sources/wrun-row-lane.types.d.ts +31 -16
  81. package/dist/utility/wrun/sources/wrun-row-lane.types.js +2 -0
  82. package/dist/utility/wrun/sources/wrun-row-lanes.util.d.ts +52 -12
  83. package/dist/utility/wrun/sources/wrun-row-lanes.util.js +110 -46
  84. package/dist/utility/wrun/wrun-browser-sources.leaf.d.ts +10 -0
  85. package/dist/utility/wrun/wrun-browser-sources.leaf.js +12 -0
  86. package/dist/utility/wrun/wrun-coin-lane-live.util.d.ts +3 -3
  87. package/dist/utility/wrun/wrun-coin-lane-live.util.js +53 -18
  88. package/dist/utility/wrun/wrun-color-settings.util.d.ts +6 -0
  89. package/dist/utility/wrun/wrun-color-settings.util.js +45 -0
  90. package/dist/utility/wrun/wrun-draft-overlay.util.js +14 -8
  91. package/dist/utility/wrun/wrun-failure-cause.d.ts +1 -1
  92. package/dist/utility/wrun/wrun-failure-cause.js +14 -0
  93. package/dist/utility/wrun/wrun-frames.js +6 -2
  94. package/dist/utility/wrun/wrun-host.service.d.ts +26 -18
  95. package/dist/utility/wrun/wrun-host.service.js +49 -52
  96. package/dist/utility/wrun/wrun-hosted-wire-caps.d.ts +1 -1
  97. package/dist/utility/wrun/wrun-hosted-wire-caps.js +2 -0
  98. package/dist/utility/wrun/wrun-input-requirements.leaf.js +7 -4
  99. package/dist/utility/wrun/wrun-kit-run-tables.util.d.ts +24 -0
  100. package/dist/utility/wrun/wrun-kit-run-tables.util.js +87 -0
  101. package/dist/utility/wrun/wrun-lifecycle.contract.d.ts +2 -1
  102. package/dist/utility/wrun/wrun-live-tick.util.d.ts +8 -2
  103. package/dist/utility/wrun/wrun-live-tick.util.js +35 -16
  104. package/dist/utility/wrun/wrun-opra-flow.leaf.d.ts +40 -13
  105. package/dist/utility/wrun/wrun-opra-flow.leaf.js +39 -12
  106. package/dist/utility/wrun/wrun-option-contract-flow.util.d.ts +70 -21
  107. package/dist/utility/wrun/wrun-option-contract-flow.util.js +257 -112
  108. package/dist/utility/wrun/wrun-option-prints.util.d.ts +62 -22
  109. package/dist/utility/wrun/wrun-option-prints.util.js +148 -46
  110. package/dist/utility/wrun/wrun-option-views.util.d.ts +262 -0
  111. package/dist/utility/wrun/wrun-option-views.util.js +356 -0
  112. package/dist/utility/wrun/wrun-options-chain.util.d.ts +23 -2
  113. package/dist/utility/wrun/wrun-options-chain.util.js +37 -3
  114. package/dist/utility/wrun/wrun-overlay-drivers.util.d.ts +18 -3
  115. package/dist/utility/wrun/wrun-overlay-drivers.util.js +32 -7
  116. package/dist/utility/wrun/wrun-overlay-recovery.util.d.ts +9 -3
  117. package/dist/utility/wrun/wrun-overlay-recovery.util.js +146 -18
  118. package/dist/utility/wrun/wrun-overlay-run.util.d.ts +50 -6
  119. package/dist/utility/wrun/wrun-overlay-run.util.js +816 -243
  120. package/dist/utility/wrun/wrun-pin-spelling.util.d.ts +5 -0
  121. package/dist/utility/wrun/wrun-pin-spelling.util.js +28 -12
  122. package/dist/utility/wrun/wrun-pin-venues.util.js +4 -6
  123. package/dist/utility/wrun/wrun-present-bits.util.d.ts +9 -0
  124. package/dist/utility/wrun/wrun-present-bits.util.js +39 -0
  125. package/dist/utility/wrun/wrun-refusal-surface.util.d.ts +3 -2
  126. package/dist/utility/wrun/wrun-refusal-surface.util.js +5 -4
  127. package/dist/utility/wrun/wrun-refusal.util.d.ts +66 -6
  128. package/dist/utility/wrun/wrun-refusal.util.js +335 -40
  129. package/dist/utility/wrun/wrun-source-rows.util.js +11 -0
  130. package/dist/utility/wrun/wrun-tier-grid.util.d.ts +28 -3
  131. package/dist/utility/wrun/wrun-tier-grid.util.js +79 -19
  132. package/dist/utility/wrun/wrun-transient-rerun.util.d.ts +14 -3
  133. package/dist/utility/wrun/wrun-transient-rerun.util.js +33 -8
  134. package/package.json +5 -5
  135. package/dist/utility/wrun/wrun-opra-underlying.util.d.ts +0 -12
  136. package/dist/utility/wrun/wrun-opra-underlying.util.js +0 -1
@@ -0,0 +1,346 @@
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 const NY_TIME_ZONE = 'America/New_York';
35
+ /** Session edges as wall-clock minutes after New York midnight. */
36
+ export const NY_PRE_MARKET_OPEN_MINUTES = 4 * 60;
37
+ export const NY_REGULAR_OPEN_MINUTES = 9 * 60 + 30;
38
+ export const NY_REGULAR_CLOSE_MINUTES = 16 * 60;
39
+ export const NY_POST_MARKET_CLOSE_MINUTES = 20 * 60;
40
+ const SECOND_MS = 1_000;
41
+ const MINUTE_MS = 60_000;
42
+ const HOUR_MS = 3_600_000;
43
+ const DAY_MS = 86_400_000;
44
+ const DAY_S = 86_400;
45
+ const EST_OFFSET_MS = -5 * HOUR_MS;
46
+ /** Test oracle: New York dates resolved (`computed`), instants looked up (`lookups`), zone UTC days read (`zoneDays`). */
47
+ export const __nyCalendarStats = { computed: 0, lookups: 0, zoneDays: 0 };
48
+ // ─── The zone clock: any IANA zone, one Intl reading per UTC day ────────────
49
+ /** The Date range edge (ECMA-262 TimeClip): an instant past it is not a date. */
50
+ const MAX_TIME_MS = 8.64e15;
51
+ /**
52
+ * The instants the zone clock serves: from the year 100 (Intl and `Date.UTC` agree on the year from
53
+ * there) to two days inside the Date range edge (a UTC day's readings stay inside it).
54
+ */
55
+ const ZONE_CLOCK_MIN_MS = Date.UTC(100, 0, 2);
56
+ const ZONE_CLOCK_MAX_MS = MAX_TIME_MS - 2 * DAY_MS;
57
+ /** UTC days kept per zone, oldest out first: eleven years. */
58
+ const ZONE_DAYS_MAX = 4096;
59
+ const zoneClocks = new Map();
60
+ /** The zone's clock; throws the RangeError Intl throws for a zone it does not know. */
61
+ function zoneClockOf(zone) {
62
+ let clock = zoneClocks.get(zone);
63
+ if (clock === undefined) {
64
+ clock = {
65
+ formatter: new Intl.DateTimeFormat('en-US', {
66
+ timeZone: zone,
67
+ hourCycle: 'h23',
68
+ year: 'numeric',
69
+ month: 'numeric',
70
+ day: 'numeric',
71
+ hour: 'numeric',
72
+ minute: 'numeric',
73
+ second: 'numeric',
74
+ }),
75
+ days: new Map(),
76
+ last: null,
77
+ };
78
+ zoneClocks.set(zone, clock);
79
+ }
80
+ return clock;
81
+ }
82
+ /** The zone's offset at the whole ms `tMs` as Intl renders it: wall clock minus UTC, whole seconds. */
83
+ function readOffsetMs(formatter, tMs) {
84
+ let year = 1970;
85
+ let month = 1;
86
+ let day = 1;
87
+ let hour = 0;
88
+ let minute = 0;
89
+ let second = 0;
90
+ for (const part of formatter.formatToParts(tMs)) {
91
+ switch (part.type) {
92
+ case 'year':
93
+ year = Number(part.value);
94
+ break;
95
+ case 'month':
96
+ month = Number(part.value);
97
+ break;
98
+ case 'day':
99
+ day = Number(part.value);
100
+ break;
101
+ case 'hour':
102
+ // Some ICU builds render midnight as 24 even under h23.
103
+ hour = Number(part.value) % 24;
104
+ break;
105
+ case 'minute':
106
+ minute = Number(part.value);
107
+ break;
108
+ case 'second':
109
+ second = Number(part.value);
110
+ break;
111
+ default:
112
+ break;
113
+ }
114
+ }
115
+ return Date.UTC(year, month - 1, day, hour, minute, second) - Math.floor(tMs / SECOND_MS) * SECOND_MS;
116
+ }
117
+ function resolveZoneUtcDay(formatter, dayNumber) {
118
+ const startMs = dayNumber * DAY_MS;
119
+ const offsetMs = readOffsetMs(formatter, startMs);
120
+ const endOffsetMs = readOffsetMs(formatter, startMs + DAY_MS - SECOND_MS);
121
+ if (endOffsetMs === offsetMs) {
122
+ return Object.freeze({
123
+ dayNumber,
124
+ offsetMs,
125
+ transitionMs: Number.POSITIVE_INFINITY,
126
+ laterOffsetMs: offsetMs,
127
+ irregular: false,
128
+ });
129
+ }
130
+ // An offset changes on a whole second: bisect the day's seconds for the first one off `offsetMs`.
131
+ let lo = 0;
132
+ let hi = DAY_S - 1;
133
+ let hiOffsetMs = endOffsetMs;
134
+ while (hi - lo > 1) {
135
+ const mid = (lo + hi) >>> 1;
136
+ const midOffsetMs = readOffsetMs(formatter, startMs + mid * SECOND_MS);
137
+ if (midOffsetMs === offsetMs) {
138
+ lo = mid;
139
+ }
140
+ else {
141
+ hi = mid;
142
+ hiOffsetMs = midOffsetMs;
143
+ }
144
+ }
145
+ return Object.freeze({
146
+ dayNumber,
147
+ offsetMs,
148
+ transitionMs: startMs + hi * SECOND_MS,
149
+ laterOffsetMs: hiOffsetMs,
150
+ irregular: hiOffsetMs !== endOffsetMs,
151
+ });
152
+ }
153
+ function zoneUtcDayOf(clock, dayNumber) {
154
+ const last = clock.last;
155
+ if (last !== null && last.dayNumber === dayNumber)
156
+ return last;
157
+ let day = clock.days.get(dayNumber);
158
+ if (day === undefined) {
159
+ day = resolveZoneUtcDay(clock.formatter, dayNumber);
160
+ __nyCalendarStats.zoneDays += 1;
161
+ if (clock.days.size >= ZONE_DAYS_MAX) {
162
+ const oldest = clock.days.keys().next();
163
+ if (!oldest.done)
164
+ clock.days.delete(oldest.value);
165
+ }
166
+ clock.days.set(dayNumber, day);
167
+ }
168
+ clock.last = day;
169
+ return day;
170
+ }
171
+ /**
172
+ * `zone`'s offset at `tMs` (wall clock minus UTC, ms; a fractional ms truncates, as a Date's does).
173
+ * NaN outside the instants the clock serves (from the year 100 to the Date range edge): the caller
174
+ * keeps its own reading there. Throws Intl's RangeError for a zone it does not know.
175
+ */
176
+ export function zoneOffsetMsAt(zone, tMs) {
177
+ if (!(tMs >= ZONE_CLOCK_MIN_MS && tMs <= ZONE_CLOCK_MAX_MS))
178
+ return Number.NaN;
179
+ const clock = zoneClockOf(zone);
180
+ const t = Math.trunc(tMs);
181
+ const day = zoneUtcDayOf(clock, Math.floor(t / DAY_MS));
182
+ if (day.irregular)
183
+ return readOffsetMs(clock.formatter, t);
184
+ return t < day.transitionMs ? day.offsetMs : day.laterOffsetMs;
185
+ }
186
+ /** The wall clock `tMs` reads in `zone`, as a UTC-shaped epoch at ms precision; NaN outside the span served. */
187
+ export function zoneWallMsAt(zone, tMs) {
188
+ const offsetMs = zoneOffsetMsAt(zone, tMs);
189
+ return Number.isNaN(offsetMs) ? offsetMs : Math.trunc(tMs) + offsetMs;
190
+ }
191
+ /**
192
+ * The instant `zone`'s wall clock reads `wallMs` (a UTC-shaped epoch), by fixed-point iteration from
193
+ * `seedOffsetMs` (the offset at `wallMs` read as an instant, when absent): an instant whose own offset
194
+ * is the one it was solved with is the answer, so a wall time on either side of a change settles on
195
+ * its own offset in one or two reads. A wall time a change skips or repeats settles on one of its
196
+ * readings: callers keep their edges off the change. NaN outside the span served.
197
+ */
198
+ export function zoneWallToUtcMs(zone, wallMs, seedOffsetMs = zoneOffsetMsAt(zone, wallMs)) {
199
+ let offsetMs = seedOffsetMs;
200
+ for (let read = 0; read < 3; read += 1) {
201
+ const candidateMs = wallMs - offsetMs;
202
+ const actualMs = zoneOffsetMsAt(zone, candidateMs);
203
+ if (actualMs === offsetMs || Number.isNaN(actualMs))
204
+ return Number.isNaN(actualMs) ? actualMs : candidateMs;
205
+ offsetMs = actualMs;
206
+ }
207
+ return wallMs - offsetMs;
208
+ }
209
+ // ─── The New York calendar ───────────────────────────────────────────────────
210
+ /** The dates whose span and session edges stay inside the instants the zone clock serves. */
211
+ const MIN_DAY_NUMBER = Math.ceil(ZONE_CLOCK_MIN_MS / DAY_MS) + 1;
212
+ const MAX_DAY_NUMBER = Math.floor(ZONE_CLOCK_MAX_MS / DAY_MS) - 2;
213
+ /** New York dates kept, oldest out first: eight years of trade dates; a sorted scan never revisits an evicted one. */
214
+ const NY_CALENDAR_MEMO_MAX = 2048;
215
+ /** 1970-01-01 was a Thursday. */
216
+ const weekdayOf = (dayNumber) => (((dayNumber + 4) % 7) + 7) % 7;
217
+ const isTradeDateNumber = (dayNumber) => {
218
+ const weekday = weekdayOf(dayNumber);
219
+ return weekday >= 1 && weekday <= 5;
220
+ };
221
+ function resolveDay(dayNumber) {
222
+ // The offset after the 02:00 transition hour, read at 12:00Z (07:00 or 08:00 New York), seeds every edge.
223
+ const seedOffsetMs = zoneOffsetMsAt(NY_TIME_ZONE, dayNumber * DAY_MS + 12 * HOUR_MS);
224
+ const at = (day, minutes) => zoneWallToUtcMs(NY_TIME_ZONE, day * DAY_MS + minutes * MINUTE_MS, seedOffsetMs);
225
+ const regularOpenMs = at(dayNumber, NY_REGULAR_OPEN_MINUTES);
226
+ const weekday = weekdayOf(dayNumber);
227
+ return Object.freeze({
228
+ dayNumber,
229
+ weekday,
230
+ isTradeDate: weekday >= 1 && weekday <= 5,
231
+ dayStartMs: at(dayNumber, 0),
232
+ dayEndMs: at(dayNumber + 1, 0),
233
+ utcOffsetMs: dayNumber * DAY_MS + NY_REGULAR_OPEN_MINUTES * MINUTE_MS - regularOpenMs,
234
+ preMarketOpenMs: at(dayNumber, NY_PRE_MARKET_OPEN_MINUTES),
235
+ regularOpenMs,
236
+ regularCloseMs: at(dayNumber, NY_REGULAR_CLOSE_MINUTES),
237
+ postMarketCloseMs: at(dayNumber, NY_POST_MARKET_CLOSE_MINUTES),
238
+ });
239
+ }
240
+ const daysByNumber = new Map();
241
+ /** The date the last instant fell on: a sorted scan hits it for a whole day without a Map read. */
242
+ let lastDay = null;
243
+ /** Test hook: empty memos (the New York dates and every zone's UTC days) and zeroed counters. */
244
+ export function __resetNyCalendarMemo() {
245
+ daysByNumber.clear();
246
+ lastDay = null;
247
+ for (const clock of zoneClocks.values()) {
248
+ clock.days.clear();
249
+ clock.last = null;
250
+ }
251
+ __nyCalendarStats.computed = 0;
252
+ __nyCalendarStats.lookups = 0;
253
+ __nyCalendarStats.zoneDays = 0;
254
+ }
255
+ /**
256
+ * The New York calendar date `dayNumber` (days since 1970-01-01), resolved once; null outside the
257
+ * span the zone clock serves, and where the runtime has no New York zone data.
258
+ */
259
+ export function nyCalendarDay(dayNumber) {
260
+ if (!Number.isInteger(dayNumber) || dayNumber < MIN_DAY_NUMBER || dayNumber > MAX_DAY_NUMBER)
261
+ return null;
262
+ const cached = daysByNumber.get(dayNumber);
263
+ if (cached !== undefined)
264
+ return cached;
265
+ let day;
266
+ try {
267
+ day = resolveDay(dayNumber);
268
+ }
269
+ catch {
270
+ return null;
271
+ }
272
+ __nyCalendarStats.computed += 1;
273
+ if (daysByNumber.size >= NY_CALENDAR_MEMO_MAX) {
274
+ const oldest = daysByNumber.keys().next();
275
+ if (!oldest.done)
276
+ daysByNumber.delete(oldest.value);
277
+ }
278
+ daysByNumber.set(dayNumber, day);
279
+ return day;
280
+ }
281
+ /**
282
+ * The New York calendar date holding the instant `tsMs`; a fractional ms truncates, as a Date's
283
+ * does. Null for a non-finite instant or one outside the span the zone clock serves.
284
+ */
285
+ export function nyCalendarDayAt(tsMs) {
286
+ __nyCalendarStats.lookups += 1;
287
+ if (!(tsMs >= -MAX_TIME_MS && tsMs <= MAX_TIME_MS))
288
+ return null;
289
+ const t = Math.trunc(tsMs);
290
+ const hit = lastDay;
291
+ if (hit !== null && t >= hit.dayStartMs && t < hit.dayEndMs)
292
+ return hit;
293
+ // The last offset seen (EST before any) names the date, except within an hour of midnight across a DST change.
294
+ let day = nyCalendarDay(Math.floor((t + (hit?.utcOffsetMs ?? EST_OFFSET_MS)) / DAY_MS));
295
+ while (day !== null && t < day.dayStartMs)
296
+ day = nyCalendarDay(day.dayNumber - 1);
297
+ while (day !== null && t >= day.dayEndMs)
298
+ day = nyCalendarDay(day.dayNumber + 1);
299
+ if (day !== null)
300
+ lastDay = day;
301
+ return day;
302
+ }
303
+ /** The phase of the instant `tsMs` on its own date `day`. */
304
+ function phaseOn(day, tsMs) {
305
+ if (!day.isTradeDate)
306
+ return 'closed';
307
+ const t = Math.trunc(tsMs);
308
+ if (t < day.preMarketOpenMs)
309
+ return 'closed';
310
+ if (t < day.regularOpenMs)
311
+ return 'pre';
312
+ if (t < day.regularCloseMs)
313
+ return 'regular';
314
+ return t < day.postMarketCloseMs ? 'after' : 'closed';
315
+ }
316
+ /** The session phase at `tsMs`: 'closed' on Saturday and Sunday, and for an instant that is not a date. */
317
+ export function nyMarketPhaseAt(tsMs) {
318
+ const day = nyCalendarDayAt(tsMs);
319
+ return day === null ? 'closed' : phaseOn(day, tsMs);
320
+ }
321
+ /** The regular open of the cash session holding `tsMs`; null outside [09:30, 16:00) on a trade date. */
322
+ export function nyRegularSessionOpenMs(tsMs) {
323
+ const day = nyCalendarDayAt(tsMs);
324
+ return day !== null && phaseOn(day, tsMs) === 'regular' ? day.regularOpenMs : null;
325
+ }
326
+ /**
327
+ * The first regular open strictly after `tsMs`: the same date's while before it, else the next
328
+ * Monday-to-Friday date's (weekend dates are skipped by arithmetic, never resolved). Null when
329
+ * there is none at or before `notAfterMs`, or outside the span served: a walk bounded by
330
+ * `notAfterMs` never resolves a date it will not reach (a date's open is after its own 00:00Z).
331
+ */
332
+ export function nyNextRegularOpenAfterMs(tsMs, notAfterMs = Number.POSITIVE_INFINITY) {
333
+ const day = nyCalendarDayAt(tsMs);
334
+ if (day === null)
335
+ return null;
336
+ let openMs = day.regularOpenMs;
337
+ if (!day.isTradeDate || Math.trunc(tsMs) >= openMs) {
338
+ let next = day.dayNumber + 1;
339
+ while (!isTradeDateNumber(next))
340
+ next += 1;
341
+ if (next * DAY_MS > notAfterMs)
342
+ return null;
343
+ openMs = nyCalendarDay(next)?.regularOpenMs ?? null;
344
+ }
345
+ return openMs !== null && openMs <= notAfterMs ? openMs : null;
346
+ }
@@ -47,12 +47,19 @@ export interface ParsedPanelClear {
47
47
  }
48
48
  export type ParsedPanelFrame = ParsedPanel | ParsedPanelClear;
49
49
  export type PanelRejectReason = 'payload is not an object' | 'unknown payload key' | 'invalid chartIndex' | 'invalid payloadId' | 'payloadId does not match chartIndex' | 'invalid revision stamp' | 'invalid clear flag (only true is wire-legal)' | 'clear payload carries baggage' | 'invalid panel' | 'unknown panel key' | 'payloadId does not match panel.id' | `invalid panel.${'id' | 'title' | 'kind' | 'x' | 'place' | 'orientation' | 'series' | 'stacked' | 'labels' | 'bins' | 'hole'}` | `invalid panel.${PanelStyleWord}` | `invalid panel.series.${PanelSeriesStyleWord}` | 'unknown panel.series key' | 'heatmap panels use x: category' | 'histogram panels use x: category' | 'rows is not an array' | 'too many rows' | 'invalid panel row' | 'invalid source' | 'unknown source key' | `invalid source.${'kind' | 'ref' | 'computedAtMs'}`;
50
+ /** The row an `invalid panel row` refusal broke the grammar at: its index in `rows` and why, for diagnostics (a
51
+ * ring event, a log line), never for the viewer's copy. */
52
+ export interface PanelRowRefusal {
53
+ index: number;
54
+ reason: string;
55
+ }
50
56
  export type SetPanelParseResult = {
51
57
  ok: true;
52
58
  data: ParsedPanelFrame;
53
59
  } | {
54
60
  ok: false;
55
61
  rejectReason: PanelRejectReason;
62
+ row?: PanelRowRefusal;
56
63
  };
57
64
  export declare function isPanelClearFrame(frame: ParsedPanelFrame): frame is ParsedPanelClear;
58
65
  /** Reject an entire frame before it can advance any session revision floor.
@@ -60,7 +67,11 @@ export declare function isPanelClearFrame(frame: ParsedPanelFrame): frame is Par
60
67
  * frame's style words are checked here (value, kind, `#rrggbb[aa]` colours)
61
68
  * and a bad one is refused by name (`invalid panel.<word>`); a wrun
62
69
  * declaration's were checked by the kit, except the app's own bar words. A
63
- * word outside the list is refused on both lanes. */
70
+ * word outside the list is refused on both lanes. A row that breaks the row
71
+ * grammar refuses the frame, never a truncation (the frozen wrun-4 rule, alike
72
+ * on every host), and the refusal names the row's index and why (`row`); a
73
+ * missing reading in a cell that only shows a number is that cell's gap,
74
+ * never a break (`missingReading`). */
64
75
  export declare function parseSetPanelData(value: unknown, options?: ParseSetPanelOptions): SetPanelParseResult;
65
76
  /** The meta-level hooks a translated panel asks the engine to call (SC08):
66
77
  * `formatDomainValue` prints every number the pane shows by role,
@@ -104,7 +115,8 @@ export interface PanelTableCellContext {
104
115
  * A number, or a styled cell's `value`, prints through the column's format,
105
116
  * else the table's (SC40); no format keeps the raw print. A styled cell's
106
117
  * own background, text look, alignment and spans map onto the T2 table keys
107
- * (SC14 SC22 SC35); a cell without an alignment takes its column's. */
118
+ * (SC14 SC22 SC35); a cell without an alignment takes its column's. A missing
119
+ * reading (`null`) is an empty cell. */
108
120
  export declare function engineTableCell(cell: ParsedPanel['rows'][number][number], column?: PanelTableColumn, ctx?: PanelTableCellContext): unknown;
109
121
  /** Labels for a time-keyed curve or bars panel, as short as the key set
110
122
  * allows: clock times inside one day, dates for day-aligned keys, a year
@@ -115,8 +115,20 @@ function spark(value) {
115
115
  function colorStops(value) {
116
116
  return Array.isArray(value) && value.length >= 2 && value.length <= 8 && value.every(color);
117
117
  }
118
+ /**
119
+ * A reading the module could not compute: `null`, the spelling the kit's frame writer gives every number that is
120
+ * not finite (`fb_num` / `fb_f64`, JSON's gap), so a contract with no quote yet, a session with no prior one or an
121
+ * average still short of its window writes it. A cell whose reading can be drawn as nothing takes it: a bars, line or
122
+ * heatmap value (a gap), a table cell (an empty cell), a tile's value (the engine's "-"). A cell that places a mark by
123
+ * its number (a key, a scatter point's x and y, a pie slice's size, a histogram bin's count) needs the number, and a
124
+ * row missing it still refuses the frame, alike on every host (the frozen wrun-4 corpus, "invalid panel cells reuse
125
+ * set_panel refusal").
126
+ */
127
+ function missingReading(value) {
128
+ return value === null;
129
+ }
118
130
  function valueCell(value) {
119
- return value === null || finite(value);
131
+ return missingReading(value) || finite(value);
120
132
  }
121
133
  /** A bars value cell: a number, a gap, or `{ value, color? }` (SC19). */
122
134
  function barCell(value) {
@@ -135,9 +147,10 @@ function rowKey(value, x) {
135
147
  return finite(value);
136
148
  return finite(value) && Number.isSafeInteger(value);
137
149
  }
138
- /** A table cell: text, a number, or a styled cell whose spans stay inside the grid (SC35). */
150
+ /** A table cell: text, a number, a missing reading (`null`, drawn as an empty cell), or a styled cell whose spans
151
+ * stay inside the grid (SC35). */
139
152
  function tableCell(value, grid) {
140
- if (typeof value === 'string' || finite(value))
153
+ if (missingReading(value) || typeof value === 'string' || finite(value))
141
154
  return true;
142
155
  if (!isRecord(value) || Object.keys(value).some((key) => !CELL_KEYS.has(key)))
143
156
  return false;
@@ -158,50 +171,93 @@ function tableCell(value, grid) {
158
171
  (nonnegativeInteger(value.font_size) && value.font_size >= 6 && value.font_size <= 64)) &&
159
172
  (value.font_weight === undefined || (typeof value.font_weight === 'string' && FONT_WEIGHTS.has(value.font_weight))));
160
173
  }
161
- function validRow(row, panel, rowIndex, rowCount) {
174
+ /** What a row key must be under each `x` word, as a refusal names it. */
175
+ const KEY_WORDS = {
176
+ category: 'a string',
177
+ time: 'a whole number >= 0',
178
+ number: 'a finite number',
179
+ index: 'a whole number',
180
+ };
181
+ /** The first cell from `from` on that `ok` refuses, named, else undefined. */
182
+ function refusedCell(row, from, ok, what) {
183
+ for (let at = from; at < row.length; at += 1)
184
+ if (!ok(row[at], at))
185
+ return `cell ${at} is not ${what}`;
186
+ return undefined;
187
+ }
188
+ /** The cell count a kind takes, named when the row holds another. */
189
+ function widthProblem(row, min, max, what) {
190
+ if (row.length >= min && row.length <= max)
191
+ return undefined;
192
+ return `the row holds ${row.length} cells, ${what} takes ${min === max ? min : `${min} to ${max}`}`;
193
+ }
194
+ /** Why one frame row breaks the row grammar (one grammar on both lanes), or undefined when it holds; the first
195
+ * broken rule wins. A missing reading (`missingReading`) is no break in a cell that only shows a number. */
196
+ function panelRowProblem(row, panel, rowIndex, rowCount) {
162
197
  if (!Array.isArray(row))
163
- return false;
198
+ return 'the row is not an array';
164
199
  switch (panel.kind) {
165
200
  case 'bars':
166
- return row.length === panel.series.length + 1 && rowKey(row[0], panel.x) && row.slice(1).every(barCell);
167
- case 'line':
168
- return row.length === panel.series.length + 1 && rowKey(row[0], panel.x) && row.slice(1).every(valueCell);
201
+ case 'line': {
202
+ const width = panel.series.length + 1;
203
+ const wrongWidth = widthProblem(row, width, width, 'the key with one value per series');
204
+ if (wrongWidth !== undefined)
205
+ return wrongWidth;
206
+ if (!rowKey(row[0], panel.x))
207
+ return `the key is not ${KEY_WORDS[panel.x]}`;
208
+ return panel.kind === 'bars'
209
+ ? refusedCell(row, 1, barCell, 'a number, null or { value, color }')
210
+ : refusedCell(row, 1, valueCell, 'a number or null');
211
+ }
169
212
  case 'scatter':
170
- return (row.length >= 3 &&
171
- row.length <= 6 &&
172
- (typeof row[0] === 'string' || rowKey(row[0], panel.x === 'number' ? 'number' : 'index')) &&
173
- finite(row[1]) &&
174
- finite(row[2]) &&
175
- (row.length < 4 || (finite(row[3]) && row[3] >= 0)) &&
176
- (row.length < 5 || color(row[4])) &&
177
- (row.length < 6 || typeof row[5] === 'string'));
213
+ return (widthProblem(row, 3, 6, 'a point') ??
214
+ (typeof row[0] === 'string' || rowKey(row[0], panel.x === 'number' ? 'number' : 'index')
215
+ ? undefined
216
+ : `the key is not a string or ${KEY_WORDS[panel.x === 'number' ? 'number' : 'index']}`) ??
217
+ (finite(row[1]) ? undefined : 'x (cell 1) is not a finite number') ??
218
+ (finite(row[2]) ? undefined : 'y (cell 2) is not a finite number') ??
219
+ (row.length < 4 || (finite(row[3]) && row[3] >= 0) ? undefined : 'the size (cell 3) is not a number >= 0') ??
220
+ (row.length < 5 || color(row[4]) ? undefined : 'the colour (cell 4) is not a colour word') ??
221
+ (row.length < 6 || typeof row[5] === 'string' ? undefined : 'the label (cell 5) is not a string'));
178
222
  case 'histogram':
179
- return row.length === 2 && typeof row[0] === 'string' && finite(row[1]);
223
+ return (widthProblem(row, 2, 2, 'a bin') ??
224
+ (typeof row[0] === 'string' ? undefined : 'the label (cell 0) is not a string') ??
225
+ (finite(row[1]) ? undefined : 'the count (cell 1) is not a finite number'));
180
226
  case 'pie':
181
- return (row.length >= 2 &&
182
- row.length <= 3 &&
183
- typeof row[0] === 'string' &&
184
- finite(row[1]) &&
185
- (row.length < 3 || color(row[2])));
227
+ return (widthProblem(row, 2, 3, 'a slice') ??
228
+ (typeof row[0] === 'string' ? undefined : 'the name (cell 0) is not a string') ??
229
+ (finite(row[1]) ? undefined : 'the value (cell 1) is not a finite number') ??
230
+ (row.length < 3 || color(row[2]) ? undefined : 'the colour (cell 2) is not a colour word'));
186
231
  case 'heatmap':
187
- return (row.length === 3 &&
188
- rowKey(row[0], panel.x) &&
189
- (typeof row[1] === 'string' || (finite(row[1]) && Number.isSafeInteger(row[1]))) &&
190
- valueCell(row[2]));
232
+ return (widthProblem(row, 3, 3, 'a cell') ??
233
+ (rowKey(row[0], panel.x) ? undefined : `the x key (cell 0) is not ${KEY_WORDS[panel.x]}`) ??
234
+ (typeof row[1] === 'string' || (finite(row[1]) && Number.isSafeInteger(row[1]))
235
+ ? undefined
236
+ : 'the y key (cell 1) is not a string or a whole number') ??
237
+ (valueCell(row[2]) ? undefined : 'the value (cell 2) is not a number or null'));
191
238
  case 'table': {
192
239
  const columns = panel.series.length;
193
- return (row.length === columns &&
194
- row.every((cell, column) => tableCell(cell, { columns, rows: rowCount, row: rowIndex, column })));
240
+ return (widthProblem(row, columns, columns, 'one cell per series') ??
241
+ refusedCell(row, 0, (cell, column) => tableCell(cell, { columns, rows: rowCount, row: rowIndex, column }), 'a table cell (text, a number, null or a styled cell inside the grid)'));
195
242
  }
196
243
  case 'tiles':
197
- return (row.length >= 2 &&
198
- row.length <= 6 &&
199
- typeof row[0] === 'string' &&
200
- ((typeof row[1] === 'string' && row[1].length <= 64) || finite(row[1])) &&
201
- (row.length < 3 || row[2] === null || typeof row[2] === 'string') &&
202
- (row.length < 4 || row[3] === null || color(row[3])) &&
203
- (row.length < 5 || row[4] === null || spark(row[4])) &&
204
- (row.length < 6 || (typeof row[5] === 'string' && VALUE_FORMATS.has(row[5]))));
244
+ return (widthProblem(row, 2, 6, 'a tile') ??
245
+ (typeof row[0] === 'string' ? undefined : 'the label (cell 0) is not a string') ??
246
+ (missingReading(row[1]) || (typeof row[1] === 'string' && row[1].length <= 64) || finite(row[1])
247
+ ? undefined
248
+ : 'the value (cell 1) is not text of 64 characters at most, a number or null') ??
249
+ (row.length < 3 || row[2] === null || typeof row[2] === 'string'
250
+ ? undefined
251
+ : 'the caption (cell 2) is not a string or null') ??
252
+ (row.length < 4 || row[3] === null || color(row[3])
253
+ ? undefined
254
+ : 'the colour (cell 3) is not a colour word or null') ??
255
+ (row.length < 5 || row[4] === null || spark(row[4])
256
+ ? undefined
257
+ : 'the spark (cell 4) is not 64 finite numbers at most or null') ??
258
+ (row.length < 6 || (typeof row[5] === 'string' && VALUE_FORMATS.has(row[5]))
259
+ ? undefined
260
+ : 'the format (cell 5) is not a value format word'));
205
261
  }
206
262
  }
207
263
  function panelRowCap(kind) {
@@ -229,7 +285,11 @@ function copyCell(cell) {
229
285
  * frame's style words are checked here (value, kind, `#rrggbb[aa]` colours)
230
286
  * and a bad one is refused by name (`invalid panel.<word>`); a wrun
231
287
  * declaration's were checked by the kit, except the app's own bar words. A
232
- * word outside the list is refused on both lanes. */
288
+ * word outside the list is refused on both lanes. A row that breaks the row
289
+ * grammar refuses the frame, never a truncation (the frozen wrun-4 rule, alike
290
+ * on every host), and the refusal names the row's index and why (`row`); a
291
+ * missing reading in a cell that only shows a number is that cell's gap,
292
+ * never a break (`missingReading`). */
233
293
  export function parseSetPanelData(value, options = {}) {
234
294
  const wrun = options.lane === 'wrun';
235
295
  if (!isRecord(value))
@@ -311,8 +371,11 @@ export function parseSetPanelData(value, options = {}) {
311
371
  const rows = value.rows;
312
372
  if (rows.length > panelRowCap(panel.kind))
313
373
  return { ok: false, rejectReason: 'too many rows' };
314
- if (!rows.every((row, index) => validRow(row, panel, index, rows.length)))
315
- return { ok: false, rejectReason: 'invalid panel row' };
374
+ for (let index = 0; index < rows.length; index += 1) {
375
+ const reason = panelRowProblem(rows[index], panel, index, rows.length);
376
+ if (reason !== undefined)
377
+ return { ok: false, rejectReason: 'invalid panel row', row: { index, reason } };
378
+ }
316
379
  let source;
317
380
  if (value.source !== undefined) {
318
381
  if (!isRecord(value.source))
@@ -378,10 +441,14 @@ function numberSpec(entry) {
378
441
  * A number, or a styled cell's `value`, prints through the column's format,
379
442
  * else the table's (SC40); no format keeps the raw print. A styled cell's
380
443
  * own background, text look, alignment and spans map onto the T2 table keys
381
- * (SC14 SC22 SC35); a cell without an alignment takes its column's. */
444
+ * (SC14 SC22 SC35); a cell without an alignment takes its column's. A missing
445
+ * reading (`null`) is an empty cell. */
382
446
  export function engineTableCell(cell, column = {}, ctx = {}) {
383
447
  const spec = column.spec ?? ctx.tableSpec;
384
448
  const print = (value) => spec === undefined ? String(value) : formatWrunNumber(value, { ...spec, priceDigits: ctx.priceDigits });
449
+ // A missing reading is an empty cell (the engine's own "" for null, spelled out for every engine pin).
450
+ if (cell === null)
451
+ return '';
385
452
  const style = boundWrunPanelStyle();
386
453
  const paneColor = (word) => style.wrunPaneColor(word, ctx.theme);
387
454
  if (typeof cell === 'number') {
@@ -724,6 +791,7 @@ export function translatePanelToEngine(frame, ctx = {}) {
724
791
  ...(panel.columns !== undefined ? { columns: panel.columns } : {}),
725
792
  fontFamily,
726
793
  };
794
+ // A missing reading (null) rides as is: the engine prints its own "-" for a tile without a value.
727
795
  const result = finish('tiles', rows.map((row, index) => [index, row[1]]), settings);
728
796
  mergeSettings(result.settings, style.wrunTilesStyle(panel, rows, ctx));
729
797
  return result;
@@ -332,13 +332,16 @@ export declare function rthSessionBucketsPerDay(window: Readonly<RthWindow>, tfM
332
332
  * noon are DST-safe: US transitions run at 02:00 and the two yearly shifts
333
333
  * cancel, so the cursor stays inside 11:00-13:00 local), skips Saturday and
334
334
  * Sunday, and accumulates per-day bucket counts until `barCount` is covered;
335
- * the span then reaches that day's terminal bucket. The count is treated as
336
- * session CAPACITY, which is an upper bound on rows actually present, so
337
- * callers sizing a fetch window should pad with `RTH_SPAN_DENSITY_MARGIN`
338
- * (holidays, early closes and thin contracts under-fill their slots, which
339
- * would otherwise make every window land short). Returns null when the
340
- * symbol resolves no RTH window or inputs are invalid (callers keep the
341
- * naive translation).
335
+ * the span then reaches that day's terminal bucket. The cursor's days are
336
+ * consecutive, so their weekdays follow from the end day's by arithmetic and
337
+ * the walk reads only the per-day memo, never a timezone conversion per day
338
+ * (each lazy-load round asks it again). The count is treated as session
339
+ * CAPACITY, which is an upper bound on rows actually present, so callers
340
+ * sizing a fetch window should pad with `RTH_SPAN_DENSITY_MARGIN` (holidays,
341
+ * early closes and thin contracts under-fill their slots, which would
342
+ * otherwise make every window land short). Returns null when the symbol
343
+ * resolves no RTH window or inputs are invalid (callers keep the naive
344
+ * translation).
342
345
  */
343
346
  export declare function rthSessionWallSpanForBarsMs(symbol: unknown, tfMs: number, barCount: number, endMs: number): number | null;
344
347
  /**