@orangecharts/wrun-chart-host 0.14.0 → 0.16.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 (197) hide show
  1. package/README.md +1 -0
  2. package/dist/constants/economic.constants.d.ts +2 -0
  3. package/dist/constants/economic.constants.js +2 -0
  4. package/dist/constants/feature-flags.constants.d.ts +11 -0
  5. package/dist/constants/feature-flags.constants.js +56 -4
  6. package/dist/constants/feature-limits.constants.d.ts +72 -4
  7. package/dist/constants/feature-limits.constants.js +98 -20
  8. package/dist/constants/interval.constants.js +5 -0
  9. package/dist/constants/kscript-data-interval-restrictions.constants.d.ts +12 -0
  10. package/dist/constants/kscript-data-interval-restrictions.constants.js +14 -0
  11. package/dist/constants/typed-width-fold.leaf.d.ts +50 -0
  12. package/dist/constants/typed-width-fold.leaf.js +99 -0
  13. package/dist/constants/typed-width-source.leaf.d.ts +24 -0
  14. package/dist/constants/typed-width-source.leaf.js +126 -0
  15. package/dist/constants/typed-width.leaf.d.ts +57 -0
  16. package/dist/constants/typed-width.leaf.js +78 -0
  17. package/dist/host-env.d.ts +24 -0
  18. package/dist/host-env.js +22 -0
  19. package/dist/host-ports.types.d.ts +11 -0
  20. package/dist/index.d.ts +4 -0
  21. package/dist/index.js +4 -0
  22. package/dist/interfaces/kscript-diagnostics.interface.d.ts +28 -0
  23. package/dist/interfaces/wrun-runtime.interface.d.ts +107 -4
  24. package/dist/interfaces/wrun-runtime.interface.js +11 -0
  25. package/dist/kscript-data/controls/live-trades-merge.util.d.ts +13 -0
  26. package/dist/kscript-data/controls/live-trades-merge.util.js +16 -1
  27. package/dist/market-data/billing.interface.d.ts +12 -45
  28. package/dist/market-data/billing.interface.js +2 -2
  29. package/dist/market-data/venues/index.d.ts +2 -2
  30. package/dist/market-data/venues/opra.js +3 -3
  31. package/dist/market-data/venues/stocks.contract.copy.json +3 -2
  32. package/dist/market-data/venues/stocks.d.ts +2 -2
  33. package/dist/market-data/venues/stocks.js +10 -9
  34. package/dist/replay/replayLadder.js +7 -4
  35. package/dist/settings-templates/footprint-rows.d.ts +6 -0
  36. package/dist/settings-templates/footprint-rows.js +6 -0
  37. package/dist/settings-templates/frvp-fields.js +14 -0
  38. package/dist/settings-templates/indicator-fields.js +46 -0
  39. package/dist/settings-templates/tool-tables.generated.js +19 -1
  40. package/dist/utility/chart/__fixtures__/live-bucket-regular-golden.json +1706 -0
  41. package/dist/utility/chart/cache-alignment.util.d.ts +65 -0
  42. package/dist/utility/chart/cache-alignment.util.js +124 -24
  43. package/dist/utility/chart/calendar-interval.util.d.ts +83 -1
  44. package/dist/utility/chart/calendar-interval.util.js +152 -4
  45. package/dist/utility/chart/candle-bar-end.util.d.ts +11 -4
  46. package/dist/utility/chart/candle-bar-end.util.js +17 -6
  47. package/dist/utility/chart/chart-time-domain.util.d.ts +3 -0
  48. package/dist/utility/chart/chart-time-domain.util.js +13 -4
  49. package/dist/utility/chart/feed-interval.util.d.ts +4 -2
  50. package/dist/utility/chart/feed-interval.util.js +5 -2
  51. package/dist/utility/chart/fetch-dedupe-policy.util.d.ts +3 -1
  52. package/dist/utility/chart/fetch-dedupe-policy.util.js +19 -1
  53. package/dist/utility/chart/footprint-band.util.d.ts +21 -5
  54. package/dist/utility/chart/footprint-band.util.js +53 -14
  55. package/dist/utility/chart/footprint-display-mode.util.d.ts +2 -0
  56. package/dist/utility/chart/footprint-display-mode.util.js +5 -0
  57. package/dist/utility/chart/governed-lanes-gate.util.d.ts +46 -0
  58. package/dist/utility/chart/governed-lanes-gate.util.js +71 -0
  59. package/dist/utility/chart/governed-lanes-reader-seat.d.ts +14 -0
  60. package/dist/utility/chart/governed-lanes-reader-seat.js +14 -0
  61. package/dist/utility/chart/history-wall.util.d.ts +13 -2
  62. package/dist/utility/chart/history-wall.util.js +11 -4
  63. package/dist/utility/chart/interval-ladder.util.d.ts +5 -2
  64. package/dist/utility/chart/interval-ladder.util.js +44 -4
  65. package/dist/utility/chart/interval-registry.util.d.ts +22 -1
  66. package/dist/utility/chart/interval-registry.util.js +50 -2
  67. package/dist/utility/chart/kscript-data-interval-restriction.leaf.d.ts +32 -4
  68. package/dist/utility/chart/kscript-data-interval-restriction.leaf.js +22 -5
  69. package/dist/utility/chart/kscript-drawing-safe-area.util.d.ts +10 -0
  70. package/dist/utility/chart/kscript-drawing-safe-area.util.js +30 -3
  71. package/dist/utility/chart/kscript-legend-entries.util.d.ts +21 -4
  72. package/dist/utility/chart/kscript-legend-entries.util.js +27 -5
  73. package/dist/utility/chart/kscript-main-grid-stages.util.js +74 -24
  74. package/dist/utility/chart/kscript-row-name.leaf.d.ts +13 -0
  75. package/dist/utility/chart/kscript-row-name.leaf.js +18 -0
  76. package/dist/utility/chart/kscript-venue-policy.util.d.ts +61 -26
  77. package/dist/utility/chart/kscript-venue-policy.util.js +138 -37
  78. package/dist/utility/chart/live-bucket.util.d.ts +29 -4
  79. package/dist/utility/chart/live-bucket.util.js +45 -12
  80. package/dist/utility/chart/market-session.util.d.ts +62 -10
  81. package/dist/utility/chart/market-session.util.js +93 -13
  82. package/dist/utility/chart/marketKind.util.d.ts +1 -7
  83. package/dist/utility/chart/marketKind.util.js +6 -8
  84. package/dist/utility/chart/mixed-mode.util.d.ts +17 -0
  85. package/dist/utility/chart/om-target.util.js +6 -4
  86. package/dist/utility/chart/price-precision.util.d.ts +20 -6
  87. package/dist/utility/chart/price-precision.util.js +34 -7
  88. package/dist/utility/chart/profile-frame-window.util.d.ts +15 -0
  89. package/dist/utility/chart/profile-frame-window.util.js +12 -0
  90. package/dist/utility/chart/rth-session.util.d.ts +3 -1
  91. package/dist/utility/chart/rth-session.util.js +3 -1
  92. package/dist/utility/chart/script-source-session.util.d.ts +43 -0
  93. package/dist/utility/chart/script-source-session.util.js +61 -0
  94. package/dist/utility/chart/typed-width-grid.util.d.ts +23 -0
  95. package/dist/utility/chart/typed-width-grid.util.js +203 -0
  96. package/dist/utility/chart/wrun-run-result.util.d.ts +9 -1
  97. package/dist/utility/chart/wrun-run-result.util.js +8 -2
  98. package/dist/utility/common/transformations.util.d.ts +6 -0
  99. package/dist/utility/common/transformations.util.js +28 -4
  100. package/dist/utility/number-format.util.d.ts +14 -1
  101. package/dist/utility/number-format.util.js +22 -4
  102. package/dist/utility/scriptEditor/wrun-runtime-diagnostics.leaf.d.ts +24 -1
  103. package/dist/utility/scriptEditor/wrun-runtime-diagnostics.leaf.js +113 -0
  104. package/dist/utility/v2/v2-enums.leaf.js +3 -0
  105. package/dist/utility/wrun/wrun-batched-marks.util.d.ts +15 -5
  106. package/dist/utility/wrun/wrun-batched-marks.util.js +70 -20
  107. package/dist/utility/wrun/wrun-canvases.util.d.ts +28 -9
  108. package/dist/utility/wrun/wrun-canvases.util.js +99 -39
  109. package/dist/utility/wrun/wrun-cap-notice.util.d.ts +5 -0
  110. package/dist/utility/wrun/wrun-cap-notice.util.js +23 -0
  111. package/dist/utility/wrun/wrun-card-style.util.d.ts +1 -1
  112. package/dist/utility/wrun/wrun-card-style.util.js +2 -2
  113. package/dist/utility/wrun/wrun-chart-market-facts.util.d.ts +8 -0
  114. package/dist/utility/wrun/wrun-chart-market-facts.util.js +13 -1
  115. package/dist/utility/wrun/wrun-child-overlay-id.util.d.ts +10 -0
  116. package/dist/utility/wrun/wrun-child-overlay-id.util.js +24 -0
  117. package/dist/utility/wrun/wrun-cloud-cme-stamp.util.d.ts +72 -0
  118. package/dist/utility/wrun/wrun-cloud-cme-stamp.util.js +151 -0
  119. package/dist/utility/wrun/wrun-color-facts.util.d.ts +3 -3
  120. package/dist/utility/wrun/wrun-color-facts.util.js +8 -5
  121. package/dist/utility/wrun/wrun-colour-tone.lazy.d.ts +20 -0
  122. package/dist/utility/wrun/wrun-colour-tone.lazy.js +23 -0
  123. package/dist/utility/wrun/wrun-colour-tone.util.d.ts +14 -0
  124. package/dist/utility/wrun/wrun-colour-tone.util.js +119 -0
  125. package/dist/utility/wrun/wrun-dark-pool.util.d.ts +3 -2
  126. package/dist/utility/wrun/wrun-dark-pool.util.js +5 -4
  127. package/dist/utility/wrun/wrun-frames.d.ts +1 -1
  128. package/dist/utility/wrun/wrun-frames.js +2 -2
  129. package/dist/utility/wrun/wrun-handles.util.d.ts +1 -1
  130. package/dist/utility/wrun/wrun-handles.util.js +1 -1
  131. package/dist/utility/wrun/wrun-host.service.d.ts +32 -2
  132. package/dist/utility/wrun/wrun-host.service.js +44 -2
  133. package/dist/utility/wrun/wrun-hosted-wire-caps.d.ts +20 -0
  134. package/dist/utility/wrun/wrun-hosted-wire-caps.js +85 -2
  135. package/dist/utility/wrun/wrun-hosted-wire.util.d.ts +37 -0
  136. package/dist/utility/wrun/wrun-hosted-wire.util.js +54 -0
  137. package/dist/utility/wrun/wrun-hover.util.d.ts +8 -2
  138. package/dist/utility/wrun/wrun-hover.util.js +24 -13
  139. package/dist/utility/wrun/wrun-hud-looks.util.d.ts +1 -0
  140. package/dist/utility/wrun/wrun-hud-looks.util.js +6 -11
  141. package/dist/utility/wrun/wrun-integration-route.util.d.ts +24 -0
  142. package/dist/utility/wrun/wrun-integration-route.util.js +19 -0
  143. package/dist/utility/wrun/wrun-live-intake.util.js +17 -1
  144. package/dist/utility/wrun/wrun-live-patch.util.d.ts +6 -1
  145. package/dist/utility/wrun/wrun-live-patch.util.js +10 -4
  146. package/dist/utility/wrun/wrun-live-tick.util.js +81 -19
  147. package/dist/utility/wrun/wrun-output-words.util.d.ts +14 -0
  148. package/dist/utility/wrun/wrun-output-words.util.js +51 -0
  149. package/dist/utility/wrun/wrun-overlay-drivers.util.d.ts +41 -0
  150. package/dist/utility/wrun/wrun-overlay-drivers.util.js +35 -0
  151. package/dist/utility/wrun/wrun-overlay-result.util.d.ts +6 -1
  152. package/dist/utility/wrun/wrun-overlay-result.util.js +2 -0
  153. package/dist/utility/wrun/wrun-overlay-run.util.d.ts +23 -2
  154. package/dist/utility/wrun/wrun-overlay-run.util.js +305 -51
  155. package/dist/utility/wrun/wrun-panel-mount.util.d.ts +10 -2
  156. package/dist/utility/wrun/wrun-panel-mount.util.js +144 -18
  157. package/dist/utility/wrun/wrun-pin-venues.util.js +5 -1
  158. package/dist/utility/wrun/wrun-refusal.util.d.ts +4 -0
  159. package/dist/utility/wrun/wrun-refusal.util.js +102 -13
  160. package/dist/utility/wrun/wrun-registry-errors.util.d.ts +5 -3
  161. package/dist/utility/wrun/wrun-registry-errors.util.js +5 -3
  162. package/dist/utility/wrun/wrun-row-source-factory.js +17 -1
  163. package/dist/utility/wrun/wrun-row-source.d.ts +8 -1
  164. package/dist/utility/wrun/wrun-run-health.util.d.ts +6 -3
  165. package/dist/utility/wrun/wrun-run-health.util.js +5 -2
  166. package/dist/utility/wrun/wrun-sandbox-row-source.d.ts +1 -1
  167. package/dist/utility/wrun/wrun-sandbox-row-source.js +9 -0
  168. package/dist/utility/wrun/wrun-script-inputs.util.d.ts +25 -8
  169. package/dist/utility/wrun/wrun-script-inputs.util.js +145 -45
  170. package/dist/utility/wrun/wrun-setting-words.util.d.ts +12 -5
  171. package/dist/utility/wrun/wrun-setting-words.util.js +25 -8
  172. package/dist/utility/wrun/wrun-socket-row-source.d.ts +26 -1
  173. package/dist/utility/wrun/wrun-socket-row-source.js +125 -12
  174. package/dist/utility/wrun/wrun-source-rows.util.d.ts +3 -3
  175. package/dist/utility/wrun/wrun-source-rows.util.js +8 -7
  176. package/dist/utility/wrun/wrun-style-names.util.d.ts +23 -0
  177. package/dist/utility/wrun/wrun-style-names.util.js +74 -0
  178. package/dist/utility/wrun/wrun-style-words.util.d.ts +31 -9
  179. package/dist/utility/wrun/wrun-style-words.util.js +46 -15
  180. package/dist/utility/wrun/wrun-trades-lane.util.js +2 -1
  181. package/dist/utility/wrun/wrun-trap-replay.util.d.ts +42 -0
  182. package/dist/utility/wrun/wrun-trap-replay.util.js +63 -0
  183. package/dist/utility/wrun/wrun-volume-profile.util.js +6 -5
  184. package/dist/utility/wrun-display-name.util.d.ts +10 -0
  185. package/dist/utility/wrun-display-name.util.js +21 -0
  186. package/dist/utils/replay/replay-buffer-math.d.ts +2 -0
  187. package/dist/utils/replay/replay-buffer-math.js +2 -0
  188. package/dist/workers/constants/socket-slots.d.ts +1 -1
  189. package/dist/workers/utils/time.worker.util.js +2 -2
  190. package/dist/workers/utils/volume-profile.worker.util.d.ts +9 -0
  191. package/dist/workers/utils/volume-profile.worker.util.js +20 -0
  192. package/dist/workers/wrun/wrun-abi-host.d.ts +3 -0
  193. package/dist/workers/wrun/wrun-abi-host.js +82 -5
  194. package/dist/workers/wrun/wrun-engine-handler.js +53 -4
  195. package/dist/workers/wrun/wrun-trap-frames.leaf.d.ts +28 -0
  196. package/dist/workers/wrun/wrun-trap-frames.leaf.js +108 -0
  197. package/package.json +11 -11
@@ -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
+ }
@@ -29,7 +29,10 @@
29
29
  * price", `gex_curve` -> "GEX curve"), the column the kScript engine fills
30
30
  * from plot(label=...) and the legend, the alert pickers and the
31
31
  * price-axis menu read, never the numbered "Plot N" fallback. The lower
32
- * pane's outputs carry the same words.
32
+ * pane's outputs carry the same words. A built-in's port (`builtIn`)
33
+ * names each line its built-in names in that built-in's words instead
34
+ * (wrun-output-words.util wrunOutputWords: MACD's `macdLine` reads "MACD
35
+ * line"), the sheet's label kept everywhere else.
33
36
  * - Panes: an on-price result whose sheet leaves `overlay` undeclared and
34
37
  * draws a `lower` output owns ONE lower pane: a `series` child overlay
35
38
  * (`childOverlays`, mounted below by wrun-panel-mount.util through the
@@ -681,6 +684,11 @@ export interface WrunRunResultOptions {
681
684
  /** A live tick's build memo (wrun-build-memo.util): an output or band mount none of whose columns changed on the
682
685
  * newest row replays what it wrote last build. Full runs, reseeds and pans leave it absent. */
683
686
  buildMemo?: WrunBuildMemo;
687
+ /** The built-in the overlay ports (builtinPortOf over its settings; absent for any other package): every line its
688
+ * built-in names carries the built-in's words in `labels` (wrun-output-words.util wrunOutputWords), never the
689
+ * contract label a proven twin's sheet keeps (`macdLine`). The sheet, the output keys and every binding are as
690
+ * published: only the words change. */
691
+ builtIn?: string;
684
692
  }
685
693
  interface WrunRunResultOutput {
686
694
  plotType: string;
@@ -29,7 +29,10 @@
29
29
  * price", `gex_curve` -> "GEX curve"), the column the kScript engine fills
30
30
  * from plot(label=...) and the legend, the alert pickers and the
31
31
  * price-axis menu read, never the numbered "Plot N" fallback. The lower
32
- * pane's outputs carry the same words.
32
+ * pane's outputs carry the same words. A built-in's port (`builtIn`)
33
+ * names each line its built-in names in that built-in's words instead
34
+ * (wrun-output-words.util wrunOutputWords: MACD's `macdLine` reads "MACD
35
+ * line"), the sheet's label kept everywhere else.
33
36
  * - Panes: an on-price result whose sheet leaves `overlay` undeclared and
34
37
  * draws a `lower` output owns ONE lower pane: a `series` child overlay
35
38
  * (`childOverlays`, mounted below by wrun-panel-mount.util through the
@@ -557,6 +560,7 @@ import { kScriptLegendLines } from './kscript-legend-entries.util.js';
557
560
  import { KSCRIPT_CONTAINER_OUTPUT_KEY } from './kscript-titancharts-container.util.js';
558
561
  import { KSCRIPT_VIEWPORT_MINI_CHART_PLOT_TYPE } from './kscript-viewport-overlays.util.js';
559
562
  import { wrunLegendName } from './wrun-legend-name.util.js';
563
+ import { wrunOutputWords } from '../wrun/wrun-output-words.util.js';
560
564
  import { wrunChartHostEnv } from '../../host-env.js';
561
565
  import { evaluateWrunSpans, isWrunAlphaColor, readWrunBoxSpecs, readWrunSegmentSpecs, wrunSpanEdgeTs, wrunStrategyOf, } from '../wrun/wrun-box-segment.util.js';
562
566
  import { WRUN_BATCHED_MARKS_KINDS, wrunBatchedMarksChildren, } from '../wrun/wrun-batched-marks.util.js';
@@ -747,6 +751,7 @@ export function buildWrunRunResult(options) {
747
751
  options.intervalMs,
748
752
  options.selectContext,
749
753
  options.runTimeline,
754
+ options.builtIn,
750
755
  ], options.rows);
751
756
  try {
752
757
  const budget = options.renderBudget ?? createWrunRenderBudget();
@@ -1737,7 +1742,8 @@ function buildWrunRunResultWithSelection(options, memo) {
1737
1742
  // (Volume Bubbles' twenty) stays inside the integration row budget.
1738
1743
  const lastRunRow = rows.length - 1;
1739
1744
  const markEndRow = (lastMarkRow, tsOf) => lastRunRow < 0 || lastMarkRow === lastRunRow ? undefined : [tsOf(lastRunRow), Number.NaN];
1740
- const labelByName = new Map(orderedOutputs.map((output) => [output.name, wrunLegendName(output.name, output.label)]));
1745
+ // Each line's words (wrunOutputWords): the legend's rule, a built-in port's line in its built-in's words.
1746
+ const labelByName = new Map(orderedOutputs.map((output) => [output.name, wrunOutputWords(output, options.builtIn)]));
1741
1747
  const labelOf = (name) => labelByName.get(name) ?? wrunLegendName(name);
1742
1748
  // Sheet candle groups (frozen sheet contract): four consecutive plot
1743
1749
  // 'candle' outputs mount as ONE candle plot at the first member's slot in
@@ -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
- const VALID_SYMBOL_RE = /^[a-zA-Z0-9_.\-:/]+$/;
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
- // Pad parentheses with spaces to isolate them as tokens, preserving hyphens in symbols
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.
@@ -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
- /** The ticker's digits: the market's decimals, else the magnitude ladder; surfaces ask market-price-text.util. */
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
- /** The magnitude ladder: 1 to 5 decimals by size, and under 1 enough for three significant digits of `magnitude`. */
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
- /** The ticker's digits: the market's decimals, else the magnitude ladder; surfaces ask market-price-text.util. */
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) ?? tickerLadderDecimals(value, magnitude);
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, { tick: opts.tick })
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, ',');
@@ -5,7 +5,8 @@
5
5
  * normalizer every lane reads a diagnostics array through. A leaf with no app edge, so the wrun chart-host package's
6
6
  * socket source and row builder read it (docs/features/kscript/wrun/wrun-chart-host.md, "Leaves").
7
7
  */
8
- import type { RuntimeDiagnostic } from '../../interfaces/kscript-diagnostics.interface.js';
8
+ import type { RuntimeDiagnostic, WrunTrapReason } from '../../interfaces/kscript-diagnostics.interface.js';
9
+ import type { WrunTrapContext } from '../../interfaces/wrun-runtime.interface.js';
9
10
  import type { WrunRefusal } from '../wrun/wrun-refusal.util.js';
10
11
  /**
11
12
  * A browser-run Indicator's AssemblyScript trap (`env.abort`: a throw, a std-lib bounds
@@ -82,6 +83,28 @@ export type WrunAnchorExport = 'init' | 'state' | 'finalize' | 'reset';
82
83
  export declare function wrunRunFailureRuntimeDiagnostic(message: string, context?: {
83
84
  outputNames?: readonly string[];
84
85
  }): RuntimeDiagnostic | null;
86
+ /** What failed, in plain words: a std-lib check by name, the engine's `unreachable`, else the guest's own abort words,
87
+ * else that it called abort(); empty for a record no words name (another engine trap, a host refusal). */
88
+ export declare function wrunTrapWhat(trap: WrunTrapContext, translate: WrunTrapTranslate): string;
89
+ export declare const WRUN_TRAP_LOCALE_PREFIX = "scriptEditor.shellConsole.trap";
90
+ /** A translator (`i18n.global.t` compatible); the leaf has no app edge, so the caller passes it. */
91
+ export type WrunTrapTranslate = (key: string, params?: Record<string, unknown>) => string;
92
+ /** What failed, decided from the record alone (never from a message text). */
93
+ export declare function wrunTrapReasonOf(trap: WrunTrapContext): WrunTrapReason;
94
+ /** Where the trap happened: the bar (1-based, as the row's `barIndex`) and its time, or before the first bar. */
95
+ export declare function wrunTrapWhere(trap: WrunTrapContext, translate: WrunTrapTranslate): string;
96
+ /**
97
+ * The trap row built from the ABI host's record (`WrunTrapContext`, captured at the guest-call boundary): `code`,
98
+ * `stage` and `reason` are decided from the record first, then the words. An abort says what failed in plain words
99
+ * (a std-lib check by name, else the guest's own words, else that it called abort()) and on which bar, without the
100
+ * library path; the row keeps the line and column only when the abort names src/indicator.ts. An `unreachable` keeps
101
+ * today's memory sentence plus the bar. A host failure keeps today's row and words. Every row carries `barIndex`
102
+ * (1-based), `details.hostMessage` (the sandbox's words, untouched) and `details.trap`. Null for a record no row
103
+ * speaks for (another engine trap, a host refusal outside the run failure rows): today's surface.
104
+ */
105
+ export declare function wrunTrapRuntimeDiagnostic(trap: WrunTrapContext, hostMessage: string, translate: WrunTrapTranslate, context?: {
106
+ outputNames?: readonly string[];
107
+ }): RuntimeDiagnostic | null;
85
108
  export interface NormalizeRuntimeDiagnosticsOptions {
86
109
  /**
87
110
  * kScript currently emits RENDER_NO_PLOT when a script only produces drawings.