@orangecharts/wrun-chart-host 0.9.0 → 0.11.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 (252) hide show
  1. package/README.md +2 -0
  2. package/dist/constants/feature-flags.constants.d.ts +15 -1
  3. package/dist/constants/feature-flags.constants.js +130 -24
  4. package/dist/constants/governed-exchanges.constants.d.ts +12 -0
  5. package/dist/constants/governed-exchanges.constants.js +16 -0
  6. package/dist/constants/opra-compliance.constants.d.ts +3 -2
  7. package/dist/constants/opra-compliance.constants.js +3 -2
  8. package/dist/constants/option-venues.constants.d.ts +2 -2
  9. package/dist/constants/scriptEditor/builtin-script-snippets.d.ts +26 -0
  10. package/dist/constants/scriptEditor/builtin-script-snippets.js +6 -0
  11. package/dist/constants/scriptEditor/technicalIndicatorScriptKeys.constants.d.ts +15 -0
  12. package/dist/constants/scriptEditor/technicalIndicatorScriptKeys.constants.js +17 -0
  13. package/dist/constants/venue-presets.constants.d.ts +20 -20
  14. package/dist/constants/venue-presets.constants.js +24 -26
  15. package/dist/host-env.d.ts +21 -5
  16. package/dist/host-env.js +6 -0
  17. package/dist/host-ports.types.d.ts +102 -19
  18. package/dist/index.d.ts +18 -0
  19. package/dist/index.js +18 -0
  20. package/dist/interfaces/cancel-reason.interface.d.ts +1 -1
  21. package/dist/interfaces/cme-realtime.interface.d.ts +16 -9
  22. package/dist/interfaces/cme-realtime.interface.js +6 -3
  23. package/dist/interfaces/kscript-diagnostics.interface.d.ts +12 -0
  24. package/dist/interfaces/opra-realtime.interface.d.ts +1 -5
  25. package/dist/interfaces/prediction-market.interface.d.ts +7 -0
  26. package/dist/interfaces/replay.interface.d.ts +8 -0
  27. package/dist/interfaces/stocks-realtime.interface.d.ts +57 -0
  28. package/dist/interfaces/stocks-realtime.interface.js +32 -0
  29. package/dist/interfaces/wrun-runtime.interface.d.ts +18 -2
  30. package/dist/kscript-data/controls/live-trades-merge.util.d.ts +62 -94
  31. package/dist/kscript-data/controls/live-trades-merge.util.js +106 -171
  32. package/dist/market-data/billing.interface.d.ts +174 -36
  33. package/dist/market-data/billing.interface.js +58 -8
  34. package/dist/market-data/venue.d.ts +152 -7
  35. package/dist/market-data/venues/cme.contract.copy.json +66 -0
  36. package/dist/market-data/venues/cme.d.ts +126 -0
  37. package/dist/market-data/venues/cme.js +133 -0
  38. package/dist/market-data/venues/index.d.ts +294 -7
  39. package/dist/market-data/venues/index.js +49 -6
  40. package/dist/market-data/venues/opra.contract.copy.json +3 -2
  41. package/dist/market-data/venues/opra.d.ts +2 -2
  42. package/dist/market-data/venues/opra.js +5 -2
  43. package/dist/market-data/venues/stocks.contract.copy.json +64 -0
  44. package/dist/market-data/venues/stocks.d.ts +130 -0
  45. package/dist/market-data/venues/stocks.js +117 -0
  46. package/dist/settings-templates/footprint-rows.js +35 -2
  47. package/dist/settings-templates/form-rows.d.ts +2 -1
  48. package/dist/settings-templates/index.js +7 -3
  49. package/dist/settings-templates/indicator-fields.d.ts +5 -4
  50. package/dist/settings-templates/indicator-fields.js +79 -10
  51. package/dist/settings-templates/tool-rules.d.ts +32 -15
  52. package/dist/settings-templates/tool-rules.js +33 -11
  53. package/dist/settings-templates/tool-tables.generated.js +95 -31
  54. package/dist/utility/chart/book-live-bucket.util.d.ts +15 -0
  55. package/dist/utility/chart/book-live-bucket.util.js +47 -0
  56. package/dist/utility/chart/cme-cache-context.util.d.ts +5 -3
  57. package/dist/utility/chart/cme-cache-context.util.js +10 -6
  58. package/dist/utility/chart/cme-realtime.util.js +10 -0
  59. package/dist/utility/chart/cme-user-scripts-gate.util.d.ts +83 -0
  60. package/dist/utility/chart/cme-user-scripts-gate.util.js +142 -0
  61. package/dist/utility/chart/effective-chart-session.util.d.ts +14 -0
  62. package/dist/utility/chart/effective-chart-session.util.js +39 -0
  63. package/dist/utility/chart/host-bar-placement.util.d.ts +28 -0
  64. package/dist/utility/chart/host-bar-placement.util.js +170 -30
  65. package/dist/utility/chart/index-host-tier.util.d.ts +3 -1
  66. package/dist/utility/chart/index-host-tier.util.js +7 -2
  67. package/dist/utility/chart/index-mode-admission.util.js +30 -3
  68. package/dist/utility/chart/kscript-apply-fingerprint.util.js +1 -1
  69. package/dist/utility/chart/kscript-drawing-safe-area.util.d.ts +35 -11
  70. package/dist/utility/chart/kscript-drawing-safe-area.util.js +145 -35
  71. package/dist/utility/chart/kscript-live-coalesce.util.d.ts +9 -7
  72. package/dist/utility/chart/kscript-live-coalesce.util.js +13 -8
  73. package/dist/utility/chart/kscript-live-source-identity.util.d.ts +9 -0
  74. package/dist/utility/chart/kscript-live-source-identity.util.js +10 -1
  75. package/dist/utility/chart/kscript-provenance-keys.util.js +13 -0
  76. package/dist/utility/chart/kscript-standin-identity.leaf.d.ts +5 -1
  77. package/dist/utility/chart/kscript-titancharts-render-keys.constants.d.ts +32 -2
  78. package/dist/utility/chart/kscript-titancharts-render-keys.constants.js +45 -0
  79. package/dist/utility/chart/kscript-venue-policy.util.d.ts +156 -43
  80. package/dist/utility/chart/kscript-venue-policy.util.js +249 -59
  81. package/dist/utility/chart/live-bucket.util.d.ts +24 -8
  82. package/dist/utility/chart/live-bucket.util.js +85 -27
  83. package/dist/utility/chart/market-session-schedule.util.d.ts +10 -0
  84. package/dist/utility/chart/market-session-schedule.util.js +16 -0
  85. package/dist/utility/chart/marketKind.util.js +5 -0
  86. package/dist/utility/chart/mixed-mode.util.d.ts +7 -0
  87. package/dist/utility/chart/mixed-mode.util.js +14 -0
  88. package/dist/utility/chart/opra-read-access.leaf.d.ts +5 -3
  89. package/dist/utility/chart/opra-read-access.leaf.js +5 -3
  90. package/dist/utility/chart/opra-user-scripts-gate.util.d.ts +11 -16
  91. package/dist/utility/chart/opra-user-scripts-gate.util.js +12 -28
  92. package/dist/utility/chart/rth-session.util.d.ts +12 -10
  93. package/dist/utility/chart/rth-session.util.js +25 -21
  94. package/dist/utility/chart/trading-day.util.d.ts +17 -0
  95. package/dist/utility/chart/trading-day.util.js +59 -0
  96. package/dist/utility/chart/window-geometry.leaf.d.ts +8 -0
  97. package/dist/utility/chart/window-geometry.leaf.js +22 -6
  98. package/dist/utility/chart/window-owner.leaf.d.ts +23 -2
  99. package/dist/utility/chart/window-owner.leaf.js +45 -3
  100. package/dist/utility/chart/wrun-bar-session-facts.util.d.ts +33 -15
  101. package/dist/utility/chart/wrun-bar-session-facts.util.js +70 -20
  102. package/dist/utility/chart/wrun-run-result.util.d.ts +12 -0
  103. package/dist/utility/chart/wrun-run-result.util.js +141 -6
  104. package/dist/utility/intl-locale.util.js +5 -0
  105. package/dist/utility/options/option-bar-anchor.util.d.ts +145 -0
  106. package/dist/utility/options/option-bar-anchor.util.js +340 -0
  107. package/dist/utility/options/option-venue.util.d.ts +18 -0
  108. package/dist/utility/options/option-venue.util.js +27 -0
  109. package/dist/utility/scriptEditor/wrun-runtime-diagnostics.leaf.js +4 -0
  110. package/dist/utility/v2/gate-plane.util.d.ts +12 -3
  111. package/dist/utility/v2/gate-plane.util.js +30 -4
  112. package/dist/utility/v2/gate-session-latch.util.js +1 -1
  113. package/dist/utility/v2/stocks-governed.util.d.ts +16 -0
  114. package/dist/utility/v2/stocks-governed.util.js +34 -0
  115. package/dist/utility/wrun/derived-roots.leaf.d.ts +13 -0
  116. package/dist/utility/wrun/derived-roots.leaf.js +27 -0
  117. package/dist/utility/wrun/derived-roots.util.d.ts +205 -0
  118. package/dist/utility/wrun/derived-roots.util.js +451 -0
  119. package/dist/utility/wrun/run-schedule/wrun-chart-gate-reader.util.d.ts +43 -7
  120. package/dist/utility/wrun/run-schedule/wrun-chart-gate-reader.util.js +89 -19
  121. package/dist/utility/wrun/run-schedule/wrun-gate-reader-warm.util.d.ts +9 -4
  122. package/dist/utility/wrun/run-schedule/wrun-gate-reader-warm.util.js +47 -6
  123. package/dist/utility/wrun/run-schedule/wrun-late-reads.util.d.ts +4 -2
  124. package/dist/utility/wrun/run-schedule/wrun-late-reads.util.js +4 -2
  125. package/dist/utility/wrun/run-schedule/wrun-own-candles.util.d.ts +24 -3
  126. package/dist/utility/wrun/run-schedule/wrun-own-candles.util.js +46 -10
  127. package/dist/utility/wrun/sources/lanes/option_daily.js +5 -2
  128. package/dist/utility/wrun/sources/lanes/options_flow.js +5 -2
  129. package/dist/utility/wrun/sources/opra-option-lanes.util.d.ts +64 -19
  130. package/dist/utility/wrun/sources/opra-option-lanes.util.js +105 -35
  131. package/dist/utility/wrun/sources/row-lanes/option_contract_flow.js +2 -1
  132. package/dist/utility/wrun/sources/row-lanes/option_contract_state.js +2 -1
  133. package/dist/utility/wrun/sources/row-lanes/option_prints.d.ts +3 -0
  134. package/dist/utility/wrun/sources/row-lanes/option_prints.js +19 -4
  135. package/dist/utility/wrun/sources/row-lanes/option_strike_flow.js +17 -4
  136. package/dist/utility/wrun/sources/row-lanes/option_strikes.d.ts +52 -13
  137. package/dist/utility/wrun/sources/row-lanes/option_strikes.js +88 -19
  138. package/dist/utility/wrun/sources/row-lanes/option_surface.js +2 -1
  139. package/dist/utility/wrun/sources/wrun-poll-lane.types.d.ts +19 -0
  140. package/dist/utility/wrun/sources/wrun-poll-lanes.util.d.ts +24 -9
  141. package/dist/utility/wrun/sources/wrun-poll-lanes.util.js +41 -10
  142. package/dist/utility/wrun/sources/wrun-row-lane-add-memo.util.d.ts +111 -0
  143. package/dist/utility/wrun/sources/wrun-row-lane-add-memo.util.js +133 -0
  144. package/dist/utility/wrun/sources/wrun-row-lane-first-paint.util.d.ts +15 -3
  145. package/dist/utility/wrun/sources/wrun-row-lane-first-paint.util.js +22 -3
  146. package/dist/utility/wrun/sources/wrun-row-lane.types.d.ts +31 -0
  147. package/dist/utility/wrun/sources/wrun-row-lanes.util.d.ts +197 -13
  148. package/dist/utility/wrun/sources/wrun-row-lanes.util.js +761 -27
  149. package/dist/utility/wrun/wrun-browser-sources.leaf.js +1 -2
  150. package/dist/utility/wrun/wrun-builtin-twin.util.d.ts +12 -0
  151. package/dist/utility/wrun/wrun-builtin-twin.util.js +21 -0
  152. package/dist/utility/wrun/wrun-chart-market-facts.util.d.ts +60 -16
  153. package/dist/utility/wrun/wrun-chart-market-facts.util.js +113 -61
  154. package/dist/utility/wrun/wrun-color-settings.util.d.ts +9 -0
  155. package/dist/utility/wrun/wrun-color-settings.util.js +33 -0
  156. package/dist/utility/wrun/wrun-download-meter.util.d.ts +15 -0
  157. package/dist/utility/wrun/wrun-download-meter.util.js +14 -2
  158. package/dist/utility/wrun/wrun-download-plan.util.d.ts +99 -0
  159. package/dist/utility/wrun/wrun-download-plan.util.js +118 -0
  160. package/dist/utility/wrun/wrun-draft-legend-note.util.d.ts +11 -3
  161. package/dist/utility/wrun/wrun-draft-legend-note.util.js +26 -4
  162. package/dist/utility/wrun/wrun-frames.d.ts +27 -6
  163. package/dist/utility/wrun/wrun-frames.js +73 -10
  164. package/dist/utility/wrun/wrun-handles.util.d.ts +7 -3
  165. package/dist/utility/wrun/wrun-handles.util.js +9 -8
  166. package/dist/utility/wrun/wrun-hosted-wire.util.d.ts +7 -1
  167. package/dist/utility/wrun/wrun-hosted-wire.util.js +12 -2
  168. package/dist/utility/wrun/wrun-hud-looks.util.d.ts +18 -4
  169. package/dist/utility/wrun/wrun-hud-looks.util.js +45 -13
  170. package/dist/utility/wrun/wrun-input-requirements.leaf.d.ts +68 -0
  171. package/dist/utility/wrun/wrun-input-requirements.leaf.js +163 -7
  172. package/dist/utility/wrun/wrun-latest-snapshot.d.ts +11 -0
  173. package/dist/utility/wrun/wrun-leg-close.util.d.ts +59 -23
  174. package/dist/utility/wrun/wrun-leg-close.util.js +186 -28
  175. package/dist/utility/wrun/wrun-live-intake.util.d.ts +35 -15
  176. package/dist/utility/wrun/wrun-live-intake.util.js +243 -126
  177. package/dist/utility/wrun/wrun-live-tick.util.d.ts +13 -5
  178. package/dist/utility/wrun/wrun-live-tick.util.js +279 -99
  179. package/dist/utility/wrun/wrun-market-facts.util.d.ts +13 -3
  180. package/dist/utility/wrun/wrun-market-facts.util.js +13 -3
  181. package/dist/utility/wrun/wrun-market-size-defaults.leaf.d.ts +60 -11
  182. package/dist/utility/wrun/wrun-market-size-defaults.leaf.js +70 -5
  183. package/dist/utility/wrun/wrun-market-size-defaults.util.js +31 -5
  184. package/dist/utility/wrun/wrun-opra-lane.util.d.ts +17 -4
  185. package/dist/utility/wrun/wrun-opra-lane.util.js +6 -4
  186. package/dist/utility/wrun/wrun-option-book-rows.util.d.ts +56 -0
  187. package/dist/utility/wrun/wrun-option-book-rows.util.js +96 -0
  188. package/dist/utility/wrun/wrun-option-strike-flow-forecast.util.d.ts +31 -0
  189. package/dist/utility/wrun/wrun-option-strike-flow-forecast.util.js +119 -0
  190. package/dist/utility/wrun/wrun-option-strike-flow-lane.util.d.ts +23 -6
  191. package/dist/utility/wrun/wrun-option-strike-flow-lane.util.js +47 -11
  192. package/dist/utility/wrun/wrun-option-strike-flow.util.d.ts +86 -19
  193. package/dist/utility/wrun/wrun-option-strike-flow.util.js +168 -62
  194. package/dist/utility/wrun/wrun-option-views.util.d.ts +323 -28
  195. package/dist/utility/wrun/wrun-option-views.util.js +484 -71
  196. package/dist/utility/wrun/wrun-options-chain.util.d.ts +3 -3
  197. package/dist/utility/wrun/wrun-options-chain.util.js +2 -0
  198. package/dist/utility/wrun/wrun-output-style.util.d.ts +6 -2
  199. package/dist/utility/wrun/wrun-output-style.util.js +20 -2
  200. package/dist/utility/wrun/wrun-overlay-drivers.util.d.ts +32 -2
  201. package/dist/utility/wrun/wrun-overlay-drivers.util.js +13 -3
  202. package/dist/utility/wrun/wrun-overlay-lifecycle.util.d.ts +10 -1
  203. package/dist/utility/wrun/wrun-overlay-lifecycle.util.js +52 -4
  204. package/dist/utility/wrun/wrun-overlay-recovery.util.js +3 -1
  205. package/dist/utility/wrun/wrun-overlay-run.util.d.ts +160 -42
  206. package/dist/utility/wrun/wrun-overlay-run.util.js +1244 -209
  207. package/dist/utility/wrun/wrun-pane-format.util.d.ts +2 -1
  208. package/dist/utility/wrun/wrun-pane-format.util.js +7 -3
  209. package/dist/utility/wrun/wrun-panel-mount.util.d.ts +9 -0
  210. package/dist/utility/wrun/wrun-panel-mount.util.js +114 -19
  211. package/dist/utility/wrun/wrun-panel-style.util.d.ts +10 -9
  212. package/dist/utility/wrun/wrun-panel-style.util.js +58 -9
  213. package/dist/utility/wrun/wrun-param-map.util.d.ts +14 -11
  214. package/dist/utility/wrun/wrun-param-map.util.js +10 -5
  215. package/dist/utility/wrun/wrun-param-values.util.d.ts +14 -4
  216. package/dist/utility/wrun/wrun-param-values.util.js +4 -0
  217. package/dist/utility/wrun/wrun-pin-spelling.util.d.ts +15 -2
  218. package/dist/utility/wrun/wrun-pin-spelling.util.js +39 -14
  219. package/dist/utility/wrun/wrun-refusal-surface.util.d.ts +50 -0
  220. package/dist/utility/wrun/wrun-refusal-surface.util.js +68 -0
  221. package/dist/utility/wrun/wrun-refusal.util.d.ts +3 -2
  222. package/dist/utility/wrun/wrun-refusal.util.js +22 -0
  223. package/dist/utility/wrun/wrun-refused-latest.util.d.ts +10 -0
  224. package/dist/utility/wrun/wrun-refused-latest.util.js +12 -0
  225. package/dist/utility/wrun/wrun-registry-errors.util.d.ts +26 -0
  226. package/dist/utility/wrun/wrun-registry-errors.util.js +34 -0
  227. package/dist/utility/wrun/wrun-replay-lane.util.js +3 -2
  228. package/dist/utility/wrun/wrun-row-source.d.ts +11 -0
  229. package/dist/utility/wrun/wrun-run-interval-session.util.d.ts +20 -6
  230. package/dist/utility/wrun/wrun-run-interval-session.util.js +22 -7
  231. package/dist/utility/wrun/wrun-run-interval.util.d.ts +43 -9
  232. package/dist/utility/wrun/wrun-run-interval.util.js +58 -15
  233. package/dist/utility/wrun/wrun-script-inputs.util.d.ts +45 -1
  234. package/dist/utility/wrun/wrun-script-inputs.util.js +112 -4
  235. package/dist/utility/wrun/wrun-setting-words.util.d.ts +7 -3
  236. package/dist/utility/wrun/wrun-setting-words.util.js +13 -5
  237. package/dist/utility/wrun/wrun-socket-row-source.d.ts +27 -2
  238. package/dist/utility/wrun/wrun-socket-row-source.js +118 -8
  239. package/dist/utility/wrun/wrun-source-rows.util.d.ts +29 -18
  240. package/dist/utility/wrun/wrun-source-rows.util.js +61 -27
  241. package/dist/utility/wrun/wrun-style-words.util.js +6 -4
  242. package/dist/utility/wrun/wrun-table-chrome.util.d.ts +3 -2
  243. package/dist/utility/wrun/wrun-table-chrome.util.js +19 -11
  244. package/dist/utility/wrun/wrun-tape-per-order.util.d.ts +2 -0
  245. package/dist/utility/wrun/wrun-tape-per-order.util.js +7 -0
  246. package/dist/utility/wrun/wrun-tape-source.util.d.ts +17 -9
  247. package/dist/utility/wrun/wrun-tape-source.util.js +20 -12
  248. package/dist/utils/replay/replay-buffer-math.d.ts +53 -2
  249. package/dist/utils/replay/replay-buffer-math.js +227 -20
  250. package/dist/workers/constants/socket-slots.d.ts +91 -6
  251. package/dist/workers/constants/socket-slots.js +85 -6
  252. package/package.json +5 -5
@@ -1,8 +1,9 @@
1
1
  /**
2
2
  * The `tape` input source's browser-side contract (WRUN-BIG-TRADES-PLAN C1, and C-DOLLAR for the dollar floor): how a
3
3
  * package's `inputSources.<name> = { source: "tape", min_size | min_value, history }` becomes the ONE acquisition the
4
- * K_TRADES large lane fetches and the live intake folds. Pure: no store, no chart, no fetch; the run pass calls it at
5
- * its head, before any lane fetch, so every refusal here lands by name and at zero fetches.
4
+ * K_TRADES lane fetches and the live intake folds: the large lane wherever the large-print table holds the market, else
5
+ * the raw tape (`wrunTapeLaneExtras`). Pure: no store, no chart, no fetch; the run pass calls it at its head, before any
6
+ * lane fetch, so every refusal here lands by name and at zero fetches.
6
7
  *
7
8
  * - A tape declares exactly ONE floor, `min_size` or `min_value`; both or neither refuses `wrun_tape_floor_invalid`
8
9
  * naming the input. Each is a number literal or a string naming a declared numeric `param`, resolved from the run's
@@ -22,7 +23,8 @@
22
23
  * - The table's own floor ($10k quote on USD-quoted markets, a contracts floor per CME Group root) is a fact a package
23
24
  * cannot lower: a floor below it is served at the table's floor (documented, never enforced here).
24
25
  * - `history: "0" | <duration>`: `"0"` (the default) is the live edge only; a duration `^\d+(s|m|h|d)$` seeds that much
25
- * history from TRADE_LARGE, at most `WRUN_TAPE_HISTORY_MAX_SEC` (30 days); a zero-length spelling ("0m") is the live
26
+ * history from TRADE_LARGE (two hours of the raw tape on a market the table does not hold, `tradesLaneLimits`), at
27
+ * most `WRUN_TAPE_HISTORY_MAX_SEC` (30 days); a zero-length spelling ("0m") is the live
26
28
  * edge too. Anything else refuses `wrun_tape_history_invalid`. The lane serves `min(history, the chart's loaded
27
29
  * window)`, and no more than the gateway's bar limit lets it today (`WRUN_TAPE_HISTORY_SERVED_MAX_SEC`: 15,000
28
30
  * one-minute points, about 10.4 days; k-trades.control.ts opens the ask at the first bar after it), so the
@@ -42,6 +44,7 @@
42
44
  * `wrun_tape_min_value_invalid`, `wrun_tape_history_invalid`).
43
45
  */
44
46
  import type { WrunIndicatorMetadata, WrunInputSource } from '../../interfaces/wrun-runtime.interface.js';
47
+ import { type TradesLargeMarket } from '../../kscript-data/controls/live-trades-merge.util.js';
45
48
  /** A tape `min_size` that resolves to nothing servable (a param the package does not declare, non-finite or not
46
49
  * above zero). */
47
50
  export declare const WRUN_TAPE_MIN_SIZE_INVALID_CODE = "wrun_tape_min_size_invalid";
@@ -157,11 +160,16 @@ export declare function wrunTapeAcquisitionFloor(acquisition: {
157
160
  } | undefined): unknown;
158
161
  /**
159
162
  * The K_TRADES payload extras of a tape acquisition (the run pass's `fetchLane('trades', 'tp', ...)`, which the run
160
- * records as the lane's acquisition: the history fetch, the reconcile's re-ask and the live fold read the SAME
161
- * payload): the large lane, the declared history and the one floor. A dollar floor also carries `valuePerUnit`, the US
162
- * dollars one price unit times one size unit of a live print is worth on the chart's market (the run head's
163
- * `wrunMarketDollarUnit`); without it no live print can be priced and none folds (the history rows carry the gateway's
164
- * own dollar value). A raw floor carries exactly what it always did, so 0.5.0's payload is unchanged.
163
+ * records as the lane's acquisition: the history fetch, the reconcile's re-ask, the live channel and the live fold read
164
+ * the SAME payload): the lane, the declared history and the one floor. The lane is the large-print table (`large`)
165
+ * wherever the table holds the market the tape reads (`tradesLargeServesMarket`), else the raw tape (no `large`: a
166
+ * two-hour seed and the raw TRADE live channel, every fill judged on its own, `tradesLaneLimits`): a CME root the
167
+ * collector does not copy (MGC, MCL, M2K, ...) asked the empty table and drew nothing (#feedback-stream 2149). The
168
+ * market is required, so no caller asks a lane without saying which market's tape it reads; `undefined` (a chart
169
+ * with no market metadata) keeps the large lane. A dollar floor also carries `valuePerUnit`, the US dollars one price
170
+ * unit times one size unit of a live print is worth on the chart's market (the run head's `wrunMarketDollarUnit`);
171
+ * without it no live print can be priced and none folds (the history rows carry the gateway's own dollar value). A raw
172
+ * floor on a market the table holds carries exactly what it always did, so 0.5.0's payload is unchanged.
165
173
  */
166
- export declare function wrunTapeLaneExtras(tape: WrunTapeAcquisition, valuePerUnit: number | undefined): Record<string, unknown>;
174
+ export declare function wrunTapeLaneExtras(tape: WrunTapeAcquisition, valuePerUnit: number | undefined, market: TradesLargeMarket | undefined): Record<string, unknown>;
167
175
  export {};
@@ -1,8 +1,9 @@
1
1
  /**
2
2
  * The `tape` input source's browser-side contract (WRUN-BIG-TRADES-PLAN C1, and C-DOLLAR for the dollar floor): how a
3
3
  * package's `inputSources.<name> = { source: "tape", min_size | min_value, history }` becomes the ONE acquisition the
4
- * K_TRADES large lane fetches and the live intake folds. Pure: no store, no chart, no fetch; the run pass calls it at
5
- * its head, before any lane fetch, so every refusal here lands by name and at zero fetches.
4
+ * K_TRADES lane fetches and the live intake folds: the large lane wherever the large-print table holds the market, else
5
+ * the raw tape (`wrunTapeLaneExtras`). Pure: no store, no chart, no fetch; the run pass calls it at its head, before any
6
+ * lane fetch, so every refusal here lands by name and at zero fetches.
6
7
  *
7
8
  * - A tape declares exactly ONE floor, `min_size` or `min_value`; both or neither refuses `wrun_tape_floor_invalid`
8
9
  * naming the input. Each is a number literal or a string naming a declared numeric `param`, resolved from the run's
@@ -22,7 +23,8 @@
22
23
  * - The table's own floor ($10k quote on USD-quoted markets, a contracts floor per CME Group root) is a fact a package
23
24
  * cannot lower: a floor below it is served at the table's floor (documented, never enforced here).
24
25
  * - `history: "0" | <duration>`: `"0"` (the default) is the live edge only; a duration `^\d+(s|m|h|d)$` seeds that much
25
- * history from TRADE_LARGE, at most `WRUN_TAPE_HISTORY_MAX_SEC` (30 days); a zero-length spelling ("0m") is the live
26
+ * history from TRADE_LARGE (two hours of the raw tape on a market the table does not hold, `tradesLaneLimits`), at
27
+ * most `WRUN_TAPE_HISTORY_MAX_SEC` (30 days); a zero-length spelling ("0m") is the live
26
28
  * edge too. Anything else refuses `wrun_tape_history_invalid`. The lane serves `min(history, the chart's loaded
27
29
  * window)`, and no more than the gateway's bar limit lets it today (`WRUN_TAPE_HISTORY_SERVED_MAX_SEC`: 15,000
28
30
  * one-minute points, about 10.4 days; k-trades.control.ts opens the ask at the first bar after it), so the
@@ -41,7 +43,7 @@
41
43
  * The om daemon shares the vocabulary (`wrun_tape_floor_invalid`, `wrun_tape_min_size_invalid`,
42
44
  * `wrun_tape_min_value_invalid`, `wrun_tape_history_invalid`).
43
45
  */
44
- import { TRADES_LARGE_BAR_LIMIT_SEC } from '../../kscript-data/controls/live-trades-merge.util.js';
46
+ import { TRADES_LARGE_BAR_LIMIT_SEC, tradesLargeServesMarket, } from '../../kscript-data/controls/live-trades-merge.util.js';
45
47
  /** A tape `min_size` that resolves to nothing servable (a param the package does not declare, non-finite or not
46
48
  * above zero). */
47
49
  export const WRUN_TAPE_MIN_SIZE_INVALID_CODE = 'wrun_tape_min_size_invalid';
@@ -276,19 +278,25 @@ export function wrunTapeAcquisitionFloor(acquisition) {
276
278
  }
277
279
  /**
278
280
  * The K_TRADES payload extras of a tape acquisition (the run pass's `fetchLane('trades', 'tp', ...)`, which the run
279
- * records as the lane's acquisition: the history fetch, the reconcile's re-ask and the live fold read the SAME
280
- * payload): the large lane, the declared history and the one floor. A dollar floor also carries `valuePerUnit`, the US
281
- * dollars one price unit times one size unit of a live print is worth on the chart's market (the run head's
282
- * `wrunMarketDollarUnit`); without it no live print can be priced and none folds (the history rows carry the gateway's
283
- * own dollar value). A raw floor carries exactly what it always did, so 0.5.0's payload is unchanged.
281
+ * records as the lane's acquisition: the history fetch, the reconcile's re-ask, the live channel and the live fold read
282
+ * the SAME payload): the lane, the declared history and the one floor. The lane is the large-print table (`large`)
283
+ * wherever the table holds the market the tape reads (`tradesLargeServesMarket`), else the raw tape (no `large`: a
284
+ * two-hour seed and the raw TRADE live channel, every fill judged on its own, `tradesLaneLimits`): a CME root the
285
+ * collector does not copy (MGC, MCL, M2K, ...) asked the empty table and drew nothing (#feedback-stream 2149). The
286
+ * market is required, so no caller asks a lane without saying which market's tape it reads; `undefined` (a chart
287
+ * with no market metadata) keeps the large lane. A dollar floor also carries `valuePerUnit`, the US dollars one price
288
+ * unit times one size unit of a live print is worth on the chart's market (the run head's `wrunMarketDollarUnit`);
289
+ * without it no live print can be priced and none folds (the history rows carry the gateway's own dollar value). A raw
290
+ * floor on a market the table holds carries exactly what it always did, so 0.5.0's payload is unchanged.
284
291
  */
285
- export function wrunTapeLaneExtras(tape, valuePerUnit) {
292
+ export function wrunTapeLaneExtras(tape, valuePerUnit, market) {
293
+ const lane = market === undefined || tradesLargeServesMarket(market) ? { large: true } : {};
286
294
  if (tape.minValue === undefined)
287
- return { minSize: tape.minSize, history: tape.history, large: true };
295
+ return { minSize: tape.minSize, history: tape.history, ...lane };
288
296
  return {
289
297
  minValue: tape.minValue,
290
298
  ...(valuePerUnit !== undefined && Number.isFinite(valuePerUnit) && valuePerUnit > 0 ? { valuePerUnit } : {}),
291
299
  history: tape.history,
292
- large: true,
300
+ ...lane,
293
301
  };
294
302
  }
@@ -1,4 +1,5 @@
1
1
  import type { ReplayBuffer, ReplayFollowRange, ReplayResolution } from '../../interfaces/replay.interface.js';
2
+ import { type LiveBucketVenue } from '../../utility/chart/live-bucket.util.js';
2
3
  type ReplayFollowRangeTarget = {
3
4
  resetRange?: (startKey: number, endKey: number) => void;
4
5
  resetRangeByTs?: (startTs: number, endTs: number) => void;
@@ -131,13 +132,63 @@ export declare function supportedReplaySourceInterval(intervalLabel: string): st
131
132
  export declare function replayCandleSourceInterval(chartIntervalMs: number): string;
132
133
  export declare function alignProbeCursorMs(cursorMs: number, stepMs: number): number;
133
134
  export declare function chartBucketOriginMs(chartIntervalMs: number): number;
134
- export declare function alignChartBucketMs(timestampMs: number, chartIntervalMs: number): number;
135
+ /**
136
+ * The market a replay's chart bars are keyed for: the buffer's `barVenue` (the chart's own, its
137
+ * session included), or null for the plain grid. Every chart-bar read below takes it as a required
138
+ * argument, so no replay reader buckets an instant without naming the market whose history it reveals.
139
+ */
140
+ export type ReplayBarVenue = LiveBucketVenue | null;
141
+ /**
142
+ * The KEY of the chart bar holding `timestampMs` on the chart's own grid: the bucket function its live
143
+ * candles key on (`liveBucketStartMs` over the chart market, its session included: the RTH-anchored
144
+ * bars of a CME chart in RTH, ES 4h at 13:30Z and a 17:30Z stub; the 09:30 New York bars of a
145
+ * regular-session stock; the CME session lattice in ETH, GC 4h in CDT at 22/02/06/10/14/18Z and a
146
+ * trade date keyed 00:00Z; the plain grid elsewhere). Between sessions an instant belongs to the bar
147
+ * still running across them (a stock's three-trade-date 3d bar overnight), else to none: null.
148
+ */
149
+ export declare function replayBarKeyMs(timestampMs: number, chartIntervalMs: number, venue: ReplayBarVenue): number | null;
150
+ /**
151
+ * The OPEN of the bar keyed `barKeyMs`: its key, except a CME trade-date bar (1d, 3d, 1w) keyed
152
+ * 00:00Z, which opens at the 17:00 Chicago open the evening before (`cmeSessionBarOpenMs`).
153
+ */
154
+ export declare function replayBarOpenMs(barKeyMs: number, chartIntervalMs: number, venue: ReplayBarVenue): number;
155
+ /**
156
+ * The END of the bar keyed `barKeyMs`, the instant it stops taking rows: its key plus the interval
157
+ * on the plain grid; the CME lattice's own end (`cmeSessionBarEndMs`: a 1d bar runs to the next
158
+ * 17:00 Chicago open, a fall-back Sunday's 4h bar an hour longer); a calendar bar's calendar end;
159
+ * and on a session grid the end of its last session (an RTH stub at the 20:15Z close, a stock's 3d
160
+ * bar at its third session's 16:00 close), walked once per bar on the quarter-hour probe.
161
+ */
162
+ export declare function replayBarEndMs(barKeyMs: number, chartIntervalMs: number, venue: ReplayBarVenue): number;
163
+ /**
164
+ * A reader of the bar each row belongs to (`replayBarKeyMs`), for rows read in ascending order: the
165
+ * rows inside one probe step share their bar, so the bucket function runs once per step, never once
166
+ * per row (a 4h bar of 1s tick rows).
167
+ */
168
+ export declare function replayBarKeyReader(chartIntervalMs: number, venue: ReplayBarVenue): (rowMs: number) => number | null;
169
+ /**
170
+ * The KEY of the chart bar holding `timestampMs` (`replayBarKeyMs`), or the instant itself where no
171
+ * bar holds it: every bar before it is settled and none has opened, so it cuts as a key would.
172
+ * Cutoffs and row keys read this; window starts read `chartBucketOpenMs`.
173
+ */
174
+ export declare function alignChartBucketMs(timestampMs: number, chartIntervalMs: number, venue: ReplayBarVenue): number;
175
+ /** The OPEN of the bar holding `timestampMs` (`replayBarOpenMs`), or the instant where none holds it.
176
+ * Sub-row folds, fetch windows and retention floors start here. */
177
+ export declare function chartBucketOpenMs(timestampMs: number, chartIntervalMs: number, venue: ReplayBarVenue): number;
178
+ /** The END of the bar holding `timestampMs` (`replayBarEndMs`), or the instant where none holds it. */
179
+ export declare function chartBucketEndMs(timestampMs: number, chartIntervalMs: number, venue: ReplayBarVenue): number;
135
180
  export declare function replayResolutionRestartAnchorMs(args: {
136
181
  userAnchorMs: number | null;
137
182
  rebuildAnchorMs: number;
138
183
  }): number;
139
184
  export declare function sourceIntervalMsForLabel(label: string): number | null;
140
- export declare function aggregateSourceRowsToChartInterval(rows: number[][], sourceInterval: string, chartIntervalMs: number, minMs: number, maxMs: number): number[][];
185
+ /**
186
+ * Finer source rows folded into the chart's own bars (`replayBarKeyMs`: a CME 2h chart in CST on its
187
+ * odd-hour lattice, an RTH chart on its anchored bars), each bar keyed and folded as
188
+ * `aggregateOhlcvRows` folds; a row no bar holds is dropped. Rows already at the chart interval or
189
+ * coarser pass through.
190
+ */
191
+ export declare function aggregateSourceRowsToChartInterval(rows: number[][], sourceInterval: string, chartIntervalMs: number, minMs: number, maxMs: number, venue: ReplayBarVenue): number[][];
141
192
  export declare function chartIntervalLabel(chartIntervalMs: number): string;
142
193
  export declare function replayHeatmapResolutionLabel(tf: ReplayResolution, chartIntervalMs: number): string;
143
194
  export declare function maxLoadedBarsForReplayResolution(tf: ReplayResolution, chartIntervalMs: number): number;
@@ -1,6 +1,9 @@
1
1
  import { Intervals } from '../../constants/interval.constants.js';
2
2
  import { intervalLabelForMs } from '../../utility/chart/interval-registry.util.js';
3
3
  import { CANDLE_TICK_BACKFILL_SEC, FALLBACK_VIEW_BEHIND_MS, FOLLOW_SPAN_ECHO_TOLERANCE_BARS, MONDAY_BUCKET_ORIGIN_MS, REPLAY_COARSE_FORWARD_BATCH, REPLAY_FOLLOW_RIGHT_OFFSET_FRACTION, REPLAY_FORWARD_BATCH, } from '../../constants/replay-ladder.leaf.js';
4
+ import { barEndMs, calendarMonthsOfMs } from '../../utility/chart/calendar-interval.util.js';
5
+ import { cmeSessionBarEndMs, cmeSessionBarOpenMs } from '../../utility/chart/cme-session-bucket.util.js';
6
+ import { cmeSessionLatticeBucketMs, liveBucketStartMs, } from '../../utility/chart/live-bucket.util.js';
4
7
  import { replayResolutionBookEdgeSec, replayResolutionStepMs, tfLabelForMs } from '../../replay/replayLadder.js';
5
8
  const DAY_MS = Intervals.DAY;
6
9
  const WEEK_MS = Intervals.WEEK;
@@ -282,7 +285,8 @@ export function pruneTickCandleRows(buffer, playheadMs, chartIntervalMs = Interv
282
285
  if (!buffer.subRows?.length) {
283
286
  return;
284
287
  }
285
- const anchorBucketStartMs = alignChartBucketMs(buffer.anchorMs, chartIntervalMs);
288
+ const venue = buffer.barVenue ?? null;
289
+ const anchorBucketStartMs = chartBucketOpenMs(buffer.anchorMs, chartIntervalMs, venue);
286
290
  if (!replayUsesSubRowRail(buffer, chartIntervalMs) &&
287
291
  !isIrregularReplayBuffer(buffer) &&
288
292
  buffer.anchorMs === anchorBucketStartMs) {
@@ -291,13 +295,13 @@ export function pruneTickCandleRows(buffer, playheadMs, chartIntervalMs = Interv
291
295
  // rail is ACTIVE those same rows are the anchor bucket's forming source: pruning them
292
296
  // froze the last candle for the whole first bucket and made coverage refetch the
293
297
  // window every tick (fetch -> merge -> prune loop).
294
- const settledAnchorBucketEndMs = anchorBucketStartMs + chartIntervalMs;
298
+ const settledAnchorBucketEndMs = chartBucketEndMs(buffer.anchorMs, chartIntervalMs, venue);
295
299
  buffer.subRows = buffer.subRows.filter((row) => typeof row[0] === 'number' && Number.isFinite(row[0]) && row[0] >= settledAnchorBucketEndMs);
296
300
  }
297
301
  if (buffer.tf.kind !== 'tick' || !buffer.subRows.length) {
298
302
  return;
299
303
  }
300
- const activeBucketStartMs = alignChartBucketMs(playheadMs, chartIntervalMs);
304
+ const activeBucketStartMs = chartBucketOpenMs(playheadMs, chartIntervalMs, venue);
301
305
  const minTs = Math.min(activeBucketStartMs, playheadMs - CANDLE_TICK_BACKFILL_SEC * 1000);
302
306
  buffer.subRows = buffer.subRows.filter((row) => typeof row[0] === 'number' && row[0] >= minTs);
303
307
  }
@@ -409,30 +413,71 @@ export function replaySubRowsHoldFormingRow(buffer, playheadMs, chartIntervalMs,
409
413
  const subRows = buffer.subRows;
410
414
  if (!subRows?.length)
411
415
  return false;
412
- const activeBucketStartMs = alignChartBucketMs(playheadMs, chartIntervalMs);
416
+ const venue = buffer.barVenue ?? null;
417
+ const activeBarMs = replayBarKeyMs(playheadMs, chartIntervalMs, venue);
418
+ if (activeBarMs === null)
419
+ return false;
420
+ const activeBucketStartMs = replayBarOpenMs(activeBarMs, chartIntervalMs, venue);
413
421
  const tickRail = buffer.tf.kind === 'tick';
414
422
  const formingFromMs = tickRail
415
423
  ? Math.max(activeBucketStartMs, Math.floor(playheadMs / stepMs) * stepMs)
416
424
  : activeBucketStartMs;
417
- const firstRow = subRows[sortedLowerBound(subRows, formingFromMs, (row) => row[0])];
418
- if (firstRow === undefined)
419
- return false;
420
- return tickRail ? firstRow[0] <= playheadMs : firstRow[0] + subSourceIntervalMs <= playheadMs;
425
+ // The first row the grid books to the active bar (a fall-back night interleaves other bars' rows).
426
+ const barOf = replayBarKeyReader(chartIntervalMs, venue);
427
+ for (let index = sortedLowerBound(subRows, formingFromMs, (row) => row[0]); index < subRows.length; index++) {
428
+ const rowMs = subRows[index][0];
429
+ if (rowMs > playheadMs)
430
+ return false;
431
+ const barMs = barOf(rowMs);
432
+ if (barMs !== activeBarMs && barMs !== null)
433
+ continue;
434
+ return tickRail ? rowMs <= playheadMs : rowMs + subSourceIntervalMs <= playheadMs;
435
+ }
436
+ return false;
421
437
  }
422
438
  export function formingChartRowFromSubRows(buffer, chartIntervalMs, targetMs) {
423
439
  if (!buffer.subRows?.length) {
424
440
  return null;
425
441
  }
426
- const bucketStartMs = alignChartBucketMs(targetMs, chartIntervalMs);
442
+ // The bar holding the target on the chart's own grid (none outside its session): keyed by
443
+ // replayBarKeyMs, folded from its OPEN (a CME trade date keyed 00:00Z opens at the 17:00 Chicago
444
+ // open the evening before) out of the rows the grid books to it, never a contiguous range: on the
445
+ // fall-back night a CME 45m bar's rows interleave with two other bars'.
446
+ const venue = buffer.barVenue ?? null;
447
+ const bucketKeyMs = replayBarKeyMs(targetMs, chartIntervalMs, venue);
448
+ if (bucketKeyMs === null)
449
+ return null;
450
+ const bucketOpenMs = replayBarOpenMs(bucketKeyMs, chartIntervalMs, venue);
427
451
  // Tick rows are point-in-time events and retain their existing inclusive reveal semantics.
428
452
  // Bar-lane source rows are start-stamped and become playable only after their source interval closes.
429
453
  const completionOffsetMs = buffer.tf.kind === 'tick' ? 0 : replaySubSourceIntervalMs(buffer, chartIntervalMs);
430
- const startIndex = sortedLowerBound(buffer.subRows, bucketStartMs, (row) => row[0]);
454
+ const startIndex = sortedLowerBound(buffer.subRows, bucketOpenMs, (row) => row[0]);
431
455
  const endIndex = sortedPrefixEnd(buffer.subRows, targetMs - completionOffsetMs, (row) => row[0], true);
432
- const rows = aggregateOhlcvRows(buffer.subRows.slice(startIndex, endIndex), chartIntervalMs, bucketStartMs, targetMs, {
433
- originMs: chartBucketOriginMs(chartIntervalMs),
456
+ const barOf = replayBarKeyReader(chartIntervalMs, venue);
457
+ return foldRowsIntoBar(buffer.subRows.slice(startIndex, endIndex), bucketKeyMs, targetMs, (rowMs) => {
458
+ const barMs = barOf(rowMs);
459
+ // A row no bar holds (a daily row stamped before its session's open) belongs to the window it sits in.
460
+ return barMs === bucketKeyMs || barMs === null;
434
461
  });
435
- return rows[0] ?? null;
462
+ }
463
+ /** Rows (ascending) folded into ONE bar keyed `keyMs`: the first open, the high and low over all, the
464
+ * last close, the volume summed (aggregateOhlcvRows' fold); rows past `maxMs`, without a stamp, or
465
+ * that `belongs` refuses are skipped. Null without a row. */
466
+ function foldRowsIntoBar(rows, keyMs, maxMs, belongs) {
467
+ let bar = null;
468
+ for (const row of rows) {
469
+ if (!Number.isFinite(row[0]) || row[0] > maxMs || !belongs(row[0]))
470
+ continue;
471
+ if (bar === null) {
472
+ bar = [keyMs, row[1], row[2], row[3], row[4], row[5] ?? 0];
473
+ continue;
474
+ }
475
+ bar[2] = Math.max(bar[2], row[2]);
476
+ bar[3] = Math.min(bar[3], row[3]);
477
+ bar[4] = row[4];
478
+ bar[5] = (bar[5] ?? 0) + (row[5] ?? 0);
479
+ }
480
+ return bar;
436
481
  }
437
482
  export function mergeHeatmapColumns(existing, incoming) {
438
483
  if (!incoming.length) {
@@ -548,9 +593,148 @@ export function chartBucketOriginMs(chartIntervalMs) {
548
593
  }
549
594
  return 0;
550
595
  }
551
- export function alignChartBucketMs(timestampMs, chartIntervalMs) {
552
- const originMs = chartBucketOriginMs(chartIntervalMs);
553
- return Math.floor((timestampMs - originMs) / chartIntervalMs) * chartIntervalMs + originMs;
596
+ /** Every bar boundary of every grid (the CME lattice, an RTH or regular session's open and close)
597
+ * sits on a quarter hour; a finer or odd width on its own multiples. A probe of this step never
598
+ * straddles a boundary. */
599
+ function barProbeStepMs(chartIntervalMs) {
600
+ let a = Math.max(1, Math.round(chartIntervalMs));
601
+ let b = 15 * 60_000;
602
+ while (b !== 0)
603
+ [a, b] = [b, a % b];
604
+ return a;
605
+ }
606
+ /** How far a bar may run past its nominal end, or lie behind an instant it still holds: a long
607
+ * weekend and a holiday. */
608
+ const BAR_SPAN_HORIZON_MS = 5 * DAY_MS;
609
+ const venueKeyOf = (venue) => `${String(venue.exchange)}|${String(venue.symbol)}|${String(venue.sessionType)}|${String(venue.transformations ?? '')}`;
610
+ /** The bar the chart's own bucket function gives the instant (null where none: outside an RTH or a
611
+ * regular session); the plain grid (origin 0, Monday at 1w) without a market. */
612
+ function liveBarKeyMs(timestampMs, chartIntervalMs, venue) {
613
+ if (!venue) {
614
+ const originMs = chartBucketOriginMs(chartIntervalMs);
615
+ return Math.floor((timestampMs - originMs) / chartIntervalMs) * chartIntervalMs + originMs;
616
+ }
617
+ return liveBucketStartMs(timestampMs, chartIntervalMs, venue);
618
+ }
619
+ const barSpanMemo = new Map();
620
+ const BAR_SPAN_MEMO_MAX = 8192;
621
+ function memoBarSpan(key, compute) {
622
+ const cached = barSpanMemo.get(key);
623
+ if (cached !== undefined)
624
+ return cached;
625
+ const value = compute();
626
+ if (barSpanMemo.size >= BAR_SPAN_MEMO_MAX)
627
+ barSpanMemo.clear();
628
+ barSpanMemo.set(key, value);
629
+ return value;
630
+ }
631
+ /**
632
+ * The KEY of the chart bar holding `timestampMs` on the chart's own grid: the bucket function its live
633
+ * candles key on (`liveBucketStartMs` over the chart market, its session included: the RTH-anchored
634
+ * bars of a CME chart in RTH, ES 4h at 13:30Z and a 17:30Z stub; the 09:30 New York bars of a
635
+ * regular-session stock; the CME session lattice in ETH, GC 4h in CDT at 22/02/06/10/14/18Z and a
636
+ * trade date keyed 00:00Z; the plain grid elsewhere). Between sessions an instant belongs to the bar
637
+ * still running across them (a stock's three-trade-date 3d bar overnight), else to none: null.
638
+ */
639
+ export function replayBarKeyMs(timestampMs, chartIntervalMs, venue) {
640
+ if (!Number.isFinite(timestampMs) || !(chartIntervalMs > 0))
641
+ return null;
642
+ const liveMs = liveBarKeyMs(timestampMs, chartIntervalMs, venue);
643
+ if (liveMs !== null || !venue)
644
+ return liveMs;
645
+ const stepMs = barProbeStepMs(chartIntervalMs);
646
+ const slotMs = Math.floor(timestampMs / stepMs) * stepMs;
647
+ return memoBarSpan(`held|${chartIntervalMs}|${venueKeyOf(venue)}|${slotMs}`, () => {
648
+ for (let probeMs = slotMs - stepMs; probeMs > slotMs - BAR_SPAN_HORIZON_MS; probeMs -= stepMs) {
649
+ const barMs = liveBarKeyMs(probeMs, chartIntervalMs, venue);
650
+ if (barMs === null)
651
+ continue;
652
+ return replayBarEndMs(barMs, chartIntervalMs, venue) > slotMs ? barMs : null;
653
+ }
654
+ return null;
655
+ });
656
+ }
657
+ /**
658
+ * The OPEN of the bar keyed `barKeyMs`: its key, except a CME trade-date bar (1d, 3d, 1w) keyed
659
+ * 00:00Z, which opens at the 17:00 Chicago open the evening before (`cmeSessionBarOpenMs`).
660
+ */
661
+ export function replayBarOpenMs(barKeyMs, chartIntervalMs, venue) {
662
+ if (venue && cmeSessionLatticeBucketMs(barKeyMs, chartIntervalMs, venue) === barKeyMs) {
663
+ return cmeSessionBarOpenMs(barKeyMs, chartIntervalMs) ?? barKeyMs;
664
+ }
665
+ return barKeyMs;
666
+ }
667
+ /**
668
+ * The END of the bar keyed `barKeyMs`, the instant it stops taking rows: its key plus the interval
669
+ * on the plain grid; the CME lattice's own end (`cmeSessionBarEndMs`: a 1d bar runs to the next
670
+ * 17:00 Chicago open, a fall-back Sunday's 4h bar an hour longer); a calendar bar's calendar end;
671
+ * and on a session grid the end of its last session (an RTH stub at the 20:15Z close, a stock's 3d
672
+ * bar at its third session's 16:00 close), walked once per bar on the quarter-hour probe.
673
+ */
674
+ export function replayBarEndMs(barKeyMs, chartIntervalMs, venue) {
675
+ const nominalEndMs = barKeyMs + chartIntervalMs;
676
+ if (!venue)
677
+ return nominalEndMs;
678
+ if (cmeSessionLatticeBucketMs(barKeyMs, chartIntervalMs, venue) === barKeyMs) {
679
+ return cmeSessionBarEndMs(barKeyMs, chartIntervalMs) ?? nominalEndMs;
680
+ }
681
+ if (calendarMonthsOfMs(chartIntervalMs) !== null)
682
+ return barEndMs(barKeyMs, chartIntervalMs);
683
+ // One contiguous run of the grid's width: the instant before the nominal end is the bar's own, the
684
+ // nominal end another bar's or none.
685
+ if (liveBarKeyMs(nominalEndMs - 1, chartIntervalMs, venue) === barKeyMs &&
686
+ liveBarKeyMs(nominalEndMs, chartIntervalMs, venue) !== barKeyMs) {
687
+ return nominalEndMs;
688
+ }
689
+ const stepMs = barProbeStepMs(chartIntervalMs);
690
+ return (memoBarSpan(`end|${chartIntervalMs}|${venueKeyOf(venue)}|${barKeyMs}`, () => {
691
+ let heldEndMs = null;
692
+ for (let probeMs = barKeyMs; probeMs < nominalEndMs + BAR_SPAN_HORIZON_MS; probeMs += stepMs) {
693
+ const barMs = liveBarKeyMs(probeMs, chartIntervalMs, venue);
694
+ if (barMs === barKeyMs)
695
+ heldEndMs = probeMs + stepMs;
696
+ else if (barMs !== null && heldEndMs !== null)
697
+ break;
698
+ }
699
+ return heldEndMs;
700
+ }) ?? nominalEndMs);
701
+ }
702
+ /**
703
+ * A reader of the bar each row belongs to (`replayBarKeyMs`), for rows read in ascending order: the
704
+ * rows inside one probe step share their bar, so the bucket function runs once per step, never once
705
+ * per row (a 4h bar of 1s tick rows).
706
+ */
707
+ export function replayBarKeyReader(chartIntervalMs, venue) {
708
+ const stepMs = barProbeStepMs(chartIntervalMs);
709
+ let slotMs = Number.NaN;
710
+ let slotBarMs = null;
711
+ return (rowMs) => {
712
+ const rowSlotMs = Math.floor(rowMs / stepMs) * stepMs;
713
+ if (rowSlotMs !== slotMs) {
714
+ slotMs = rowSlotMs;
715
+ slotBarMs = replayBarKeyMs(rowSlotMs, chartIntervalMs, venue);
716
+ }
717
+ return slotBarMs;
718
+ };
719
+ }
720
+ /**
721
+ * The KEY of the chart bar holding `timestampMs` (`replayBarKeyMs`), or the instant itself where no
722
+ * bar holds it: every bar before it is settled and none has opened, so it cuts as a key would.
723
+ * Cutoffs and row keys read this; window starts read `chartBucketOpenMs`.
724
+ */
725
+ export function alignChartBucketMs(timestampMs, chartIntervalMs, venue) {
726
+ return replayBarKeyMs(timestampMs, chartIntervalMs, venue) ?? timestampMs;
727
+ }
728
+ /** The OPEN of the bar holding `timestampMs` (`replayBarOpenMs`), or the instant where none holds it.
729
+ * Sub-row folds, fetch windows and retention floors start here. */
730
+ export function chartBucketOpenMs(timestampMs, chartIntervalMs, venue) {
731
+ const barKeyMs = replayBarKeyMs(timestampMs, chartIntervalMs, venue);
732
+ return barKeyMs === null ? timestampMs : replayBarOpenMs(barKeyMs, chartIntervalMs, venue);
733
+ }
734
+ /** The END of the bar holding `timestampMs` (`replayBarEndMs`), or the instant where none holds it. */
735
+ export function chartBucketEndMs(timestampMs, chartIntervalMs, venue) {
736
+ const barKeyMs = replayBarKeyMs(timestampMs, chartIntervalMs, venue);
737
+ return barKeyMs === null ? timestampMs : replayBarEndMs(barKeyMs, chartIntervalMs, venue);
554
738
  }
555
739
  export function replayResolutionRestartAnchorMs(args) {
556
740
  // Continue at the playhead: a resolution or interval pick is a playback
@@ -577,14 +761,37 @@ export function sourceIntervalMsForLabel(label) {
577
761
  }
578
762
  return null;
579
763
  }
580
- export function aggregateSourceRowsToChartInterval(rows, sourceInterval, chartIntervalMs, minMs, maxMs) {
764
+ /**
765
+ * Finer source rows folded into the chart's own bars (`replayBarKeyMs`: a CME 2h chart in CST on its
766
+ * odd-hour lattice, an RTH chart on its anchored bars), each bar keyed and folded as
767
+ * `aggregateOhlcvRows` folds; a row no bar holds is dropped. Rows already at the chart interval or
768
+ * coarser pass through.
769
+ */
770
+ export function aggregateSourceRowsToChartInterval(rows, sourceInterval, chartIntervalMs, minMs, maxMs, venue) {
581
771
  const sourceIntervalMs = sourceIntervalMsForLabel(sourceInterval);
582
772
  if (!sourceIntervalMs || sourceIntervalMs >= chartIntervalMs) {
583
773
  return rows;
584
774
  }
585
- return aggregateOhlcvRows(rows, chartIntervalMs, minMs, maxMs, {
586
- originMs: chartBucketOriginMs(chartIntervalMs),
587
- });
775
+ const byBar = new Map();
776
+ const barOf = replayBarKeyReader(chartIntervalMs, venue);
777
+ const sorted = rows
778
+ .filter((row) => typeof row[0] === 'number' && row[0] >= minMs && row[0] <= maxMs)
779
+ .sort((a, b) => a[0] - b[0]);
780
+ for (const row of sorted) {
781
+ const barMs = barOf(row[0]);
782
+ if (barMs === null || barMs > maxMs)
783
+ continue;
784
+ const existing = byBar.get(barMs);
785
+ if (!existing) {
786
+ byBar.set(barMs, [barMs, row[1], row[2], row[3], row[4], row[5] ?? 0]);
787
+ continue;
788
+ }
789
+ existing[2] = Math.max(existing[2], row[2]);
790
+ existing[3] = Math.min(existing[3], row[3]);
791
+ existing[4] = row[4];
792
+ existing[5] = (existing[5] ?? 0) + (row[5] ?? 0);
793
+ }
794
+ return Array.from(byBar.values()).sort((a, b) => a[0] - b[0]);
588
795
  }
589
796
  export function chartIntervalLabel(chartIntervalMs) {
590
797
  const interval = intervalLabelForMs(chartIntervalMs);