@orangecharts/wrun-chart-host 0.11.0 → 0.14.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 (311) hide show
  1. package/README.md +1 -0
  2. package/dist/constants/feature-flags.constants.d.ts +3 -4
  3. package/dist/constants/feature-flags.constants.js +34 -52
  4. package/dist/constants/feature-limits.constants.d.ts +1 -1
  5. package/dist/constants/feature-limits.constants.js +5 -4
  6. package/dist/constants/interval.constants.d.ts +7 -0
  7. package/dist/constants/interval.constants.js +7 -0
  8. package/dist/constants/scriptEditor/cme-official-scripts.constants.d.ts +20 -149
  9. package/dist/constants/scriptEditor/cme-official-scripts.constants.js +20 -309
  10. package/dist/constants/stocks-compliance.constants.d.ts +15 -0
  11. package/dist/constants/stocks-compliance.constants.js +15 -0
  12. package/dist/host-env.d.ts +55 -3
  13. package/dist/host-env.js +6 -0
  14. package/dist/host-ports.types.d.ts +36 -3
  15. package/dist/index.d.ts +18 -0
  16. package/dist/index.js +19 -0
  17. package/dist/indicators/controls/tpo-session.util.d.ts +78 -15
  18. package/dist/indicators/controls/tpo-session.util.js +320 -242
  19. package/dist/instances/script-engine-worker-ohlcv-transfer.d.ts +6 -0
  20. package/dist/instances/script-engine-worker-ohlcv-transfer.js +16 -0
  21. package/dist/interfaces/cme-realtime.interface.d.ts +8 -0
  22. package/dist/interfaces/cme-realtime.interface.js +2 -1
  23. package/dist/interfaces/feed.interface.d.ts +15 -1
  24. package/dist/interfaces/replay.interface.d.ts +5 -0
  25. package/dist/interfaces/stocks-realtime.interface.d.ts +4 -3
  26. package/dist/interfaces/stocks-realtime.interface.js +5 -4
  27. package/dist/interfaces/wrun-runtime.interface.d.ts +97 -19
  28. package/dist/kscript-data/controls/live-ohlcv-merge.util.d.ts +17 -0
  29. package/dist/kscript-data/controls/live-ohlcv-merge.util.js +22 -0
  30. package/dist/kscript-data/controls/live-trades-merge.util.d.ts +46 -40
  31. package/dist/kscript-data/controls/live-trades-merge.util.js +80 -107
  32. package/dist/market-data/billing.interface.d.ts +9 -1
  33. package/dist/market-data/venue.d.ts +1 -1
  34. package/dist/market-data/venues/index.d.ts +4 -4
  35. package/dist/market-data/venues/stocks.contract.copy.json +4 -4
  36. package/dist/market-data/venues/stocks.d.ts +4 -4
  37. package/dist/market-data/venues/stocks.js +15 -13
  38. package/dist/settings-templates/frvp-fields.d.ts +12 -1
  39. package/dist/settings-templates/frvp-fields.js +15 -4
  40. package/dist/settings-templates/index.js +12 -5
  41. package/dist/settings-templates/indicator-fields.js +28 -2
  42. package/dist/settings-templates/tool-rules.d.ts +17 -8
  43. package/dist/settings-templates/tool-rules.js +15 -8
  44. package/dist/settings-templates/tool-tables.generated.js +4 -2
  45. package/dist/utility/auth/server-clock.util.d.ts +3 -1
  46. package/dist/utility/auth/server-clock.util.js +3 -1
  47. package/dist/utility/chart/book-live-bucket.util.js +2 -2
  48. package/dist/utility/chart/cache-alignment.util.d.ts +15 -7
  49. package/dist/utility/chart/cache-alignment.util.js +14 -7
  50. package/dist/utility/chart/chart-data-fetch-generation.util.d.ts +2 -0
  51. package/dist/utility/chart/chart-data-fetch-generation.util.js +16 -0
  52. package/dist/utility/chart/cme-session-bucket.util.d.ts +18 -75
  53. package/dist/utility/chart/cme-session-bucket.util.js +25 -332
  54. package/dist/utility/chart/continuous-contracts.util.js +6 -5
  55. package/dist/utility/chart/display-offset.leaf.d.ts +24 -0
  56. package/dist/utility/chart/display-offset.leaf.js +41 -0
  57. package/dist/utility/chart/effective-chart-session.util.d.ts +2 -1
  58. package/dist/utility/chart/effective-chart-session.util.js +13 -5
  59. package/dist/utility/chart/feed-interval.util.d.ts +6 -20
  60. package/dist/utility/chart/feed-interval.util.js +13 -22
  61. package/dist/utility/chart/fetch-dedupe-policy.util.d.ts +27 -7
  62. package/dist/utility/chart/fetch-dedupe-policy.util.js +86 -11
  63. package/dist/utility/chart/host-bar-placement.util.d.ts +7 -4
  64. package/dist/utility/chart/host-bar-placement.util.js +8 -2
  65. package/dist/utility/chart/indicator-inflight-registry.util.d.ts +32 -0
  66. package/dist/utility/chart/indicator-inflight-registry.util.js +52 -0
  67. package/dist/utility/chart/indicator-run-interval.util.d.ts +10 -4
  68. package/dist/utility/chart/indicator-run-interval.util.js +21 -12
  69. package/dist/utility/chart/interval-registry.util.d.ts +1 -1
  70. package/dist/utility/chart/interval-registry.util.js +1 -1
  71. package/dist/utility/chart/kscript-legend-entries.util.d.ts +12 -0
  72. package/dist/utility/chart/kscript-legend-entries.util.js +16 -0
  73. package/dist/utility/chart/kscript-run-interval-projection.util.d.ts +1 -1
  74. package/dist/utility/chart/kscript-run-interval-projection.util.js +4 -2
  75. package/dist/utility/chart/kscript-venue-policy.util.d.ts +53 -62
  76. package/dist/utility/chart/kscript-venue-policy.util.js +85 -94
  77. package/dist/utility/chart/live-bucket.util.d.ts +39 -17
  78. package/dist/utility/chart/live-bucket.util.js +103 -57
  79. package/dist/utility/chart/local-kscript-source-revalidation.util.d.ts +58 -20
  80. package/dist/utility/chart/local-kscript-source-revalidation.util.js +98 -23
  81. package/dist/utility/chart/local-kscript-warmup-depth.util.d.ts +35 -11
  82. package/dist/utility/chart/local-kscript-warmup-depth.util.js +24 -3
  83. package/dist/utility/chart/market-session-schedule.util.d.ts +8 -0
  84. package/dist/utility/chart/market-session-schedule.util.js +39 -1
  85. package/dist/utility/chart/market-session.util.d.ts +136 -0
  86. package/dist/utility/chart/market-session.util.js +341 -0
  87. package/dist/utility/chart/market-sessions.util.d.ts +83 -0
  88. package/dist/utility/chart/market-sessions.util.js +220 -0
  89. package/dist/utility/chart/om-panel.util.d.ts +5 -3
  90. package/dist/utility/chart/om-panel.util.js +42 -7
  91. package/dist/utility/chart/om-target.util.d.ts +14 -1
  92. package/dist/utility/chart/om-target.util.js +22 -5
  93. package/dist/utility/chart/opra-read-access.leaf.d.ts +16 -1
  94. package/dist/utility/chart/opra-read-access.leaf.js +22 -0
  95. package/dist/utility/chart/profile-row-height.util.d.ts +49 -16
  96. package/dist/utility/chart/profile-row-height.util.js +74 -37
  97. package/dist/utility/chart/rth-session.util.d.ts +55 -20
  98. package/dist/utility/chart/rth-session.util.js +94 -46
  99. package/dist/utility/chart/session-interval.util.d.ts +2 -1
  100. package/dist/utility/chart/session-interval.util.js +1 -3
  101. package/dist/utility/chart/session-lattice.util.d.ts +150 -0
  102. package/dist/utility/chart/session-lattice.util.js +488 -0
  103. package/dist/utility/chart/trading-day.util.d.ts +40 -2
  104. package/dist/utility/chart/trading-day.util.js +84 -7
  105. package/dist/utility/chart/us-equities-session.util.d.ts +32 -11
  106. package/dist/utility/chart/us-equities-session.util.js +44 -15
  107. package/dist/utility/chart/window-geometry.leaf.d.ts +28 -7
  108. package/dist/utility/chart/window-geometry.leaf.js +57 -8
  109. package/dist/utility/chart/wrun-bar-session-facts.util.d.ts +21 -14
  110. package/dist/utility/chart/wrun-bar-session-facts.util.js +32 -38
  111. package/dist/utility/chart/wrun-run-result.util.d.ts +29 -12
  112. package/dist/utility/chart/wrun-run-result.util.js +89 -25
  113. package/dist/utility/common/time.util.js +5 -4
  114. package/dist/utility/market-events/earnings-scope.util.d.ts +10 -5
  115. package/dist/utility/market-events/earnings-scope.util.js +17 -9
  116. package/dist/utility/market-events/market-events.util.d.ts +14 -7
  117. package/dist/utility/market-events/market-events.util.js +30 -17
  118. package/dist/utility/number-format.util.d.ts +14 -21
  119. package/dist/utility/number-format.util.js +38 -24
  120. package/dist/utility/options/option-venue-disclosure.util.d.ts +40 -6
  121. package/dist/utility/options/option-venue-disclosure.util.js +71 -11
  122. package/dist/utility/options/option-venue.util.d.ts +1 -1
  123. package/dist/utility/options/option-venue.util.js +1 -1
  124. package/dist/utility/pool-symbol.leaf.d.ts +7 -0
  125. package/dist/utility/pool-symbol.leaf.js +50 -5
  126. package/dist/utility/stocks/stock-display.util.d.ts +15 -0
  127. package/dist/utility/stocks/stock-display.util.js +37 -0
  128. package/dist/utility/symbol-selection/contract-expiry.util.js +5 -4
  129. package/dist/utility/v2/gate-plane.util.d.ts +6 -0
  130. package/dist/utility/v2/gate-plane.util.js +11 -1
  131. package/dist/utility/v2/gate-session-latch.util.d.ts +1 -1
  132. package/dist/utility/v2/gate-session-latch.util.js +3 -3
  133. package/dist/utility/v2/governed-tier.leaf.d.ts +17 -16
  134. package/dist/utility/v2/governed-tier.leaf.js +17 -16
  135. package/dist/utility/v2/stocks-governed.util.d.ts +5 -0
  136. package/dist/utility/v2/stocks-governed.util.js +14 -0
  137. package/dist/utility/v2/v2-enums.leaf.d.ts +13 -0
  138. package/dist/utility/v2/v2-enums.leaf.js +458 -0
  139. package/dist/utility/wrun/derived-roots.leaf.d.ts +21 -1
  140. package/dist/utility/wrun/derived-roots.leaf.js +27 -1
  141. package/dist/utility/wrun/derived-roots.util.d.ts +44 -32
  142. package/dist/utility/wrun/derived-roots.util.js +97 -56
  143. package/dist/utility/wrun/run-schedule/wrun-late-reads.util.d.ts +4 -3
  144. package/dist/utility/wrun/run-schedule/wrun-late-reads.util.js +4 -3
  145. package/dist/utility/wrun/sources/lanes/option_daily.d.ts +2 -1
  146. package/dist/utility/wrun/sources/lanes/option_daily.js +2 -1
  147. package/dist/utility/wrun/sources/lanes/options_flow.d.ts +3 -0
  148. package/dist/utility/wrun/sources/lanes/options_flow.js +23 -5
  149. package/dist/utility/wrun/sources/opra-option-lanes.util.d.ts +3 -4
  150. package/dist/utility/wrun/sources/row-lane-registry.js +9 -4
  151. package/dist/utility/wrun/sources/row-lanes/dark_pool.d.ts +19 -0
  152. package/dist/utility/wrun/sources/row-lanes/dark_pool.js +104 -0
  153. package/dist/utility/wrun/sources/row-lanes/index.js +2 -0
  154. package/dist/utility/wrun/sources/wrun-lane-fetch-abort.util.d.ts +20 -0
  155. package/dist/utility/wrun/sources/wrun-lane-fetch-abort.util.js +103 -0
  156. package/dist/utility/wrun/sources/wrun-poll-lane.types.d.ts +19 -2
  157. package/dist/utility/wrun/sources/wrun-poll-lanes.util.d.ts +15 -13
  158. package/dist/utility/wrun/sources/wrun-poll-lanes.util.js +49 -23
  159. package/dist/utility/wrun/sources/wrun-row-lane.types.d.ts +14 -9
  160. package/dist/utility/wrun/sources/wrun-row-lanes.util.d.ts +75 -27
  161. package/dist/utility/wrun/sources/wrun-row-lanes.util.js +139 -82
  162. package/dist/utility/wrun/wrun-app-layer.leaf.d.ts +78 -0
  163. package/dist/utility/wrun/wrun-app-layer.leaf.js +89 -0
  164. package/dist/utility/wrun/wrun-bar-count.util.d.ts +11 -7
  165. package/dist/utility/wrun/wrun-bar-count.util.js +12 -8
  166. package/dist/utility/wrun/wrun-batched-kinds.leaf.d.ts +13 -0
  167. package/dist/utility/wrun/wrun-batched-kinds.leaf.js +18 -0
  168. package/dist/utility/wrun/wrun-batched-marks.util.d.ts +41 -22
  169. package/dist/utility/wrun/wrun-batched-marks.util.js +255 -59
  170. package/dist/utility/wrun/wrun-batched-readout.util.d.ts +26 -19
  171. package/dist/utility/wrun/wrun-batched-readout.util.js +81 -27
  172. package/dist/utility/wrun/wrun-book-bands.leaf.d.ts +8 -0
  173. package/dist/utility/wrun/wrun-book-bands.leaf.js +7 -0
  174. package/dist/utility/wrun/wrun-candle-equal.leaf.d.ts +19 -0
  175. package/dist/utility/wrun/wrun-candle-equal.leaf.js +40 -0
  176. package/dist/utility/wrun/wrun-canvas-readout.util.d.ts +4 -2
  177. package/dist/utility/wrun/wrun-canvases.util.js +7 -3
  178. package/dist/utility/wrun/wrun-chart-context-names.util.d.ts +6 -3
  179. package/dist/utility/wrun/wrun-chart-context-names.util.js +8 -4
  180. package/dist/utility/wrun/wrun-chart-market-facts.util.d.ts +47 -29
  181. package/dist/utility/wrun/wrun-chart-market-facts.util.js +201 -201
  182. package/dist/utility/wrun/wrun-child-overlay-id.util.js +2 -1
  183. package/dist/utility/wrun/wrun-cme-legs-note.util.d.ts +15 -0
  184. package/dist/utility/wrun/wrun-cme-legs-note.util.js +49 -0
  185. package/dist/utility/wrun/wrun-cme-root-specs.util.d.ts +38 -0
  186. package/dist/utility/wrun/wrun-cme-root-specs.util.js +81 -0
  187. package/dist/utility/wrun/wrun-coin-lane-live.util.js +3 -0
  188. package/dist/utility/wrun/wrun-color-settings.util.d.ts +6 -1
  189. package/dist/utility/wrun/wrun-color-settings.util.js +32 -7
  190. package/dist/utility/wrun/wrun-dark-pool.util.d.ts +50 -0
  191. package/dist/utility/wrun/wrun-dark-pool.util.js +127 -0
  192. package/dist/utility/wrun/wrun-declared-warmup.util.d.ts +67 -12
  193. package/dist/utility/wrun/wrun-declared-warmup.util.js +165 -13
  194. package/dist/utility/wrun/wrun-draft-legend-note.util.d.ts +18 -8
  195. package/dist/utility/wrun/wrun-draft-legend-note.util.js +57 -11
  196. package/dist/utility/wrun/wrun-draft-overlay.util.d.ts +14 -10
  197. package/dist/utility/wrun/wrun-draft-overlay.util.js +26 -14
  198. package/dist/utility/wrun/wrun-earnings-facts.util.js +3 -2
  199. package/dist/utility/wrun/wrun-etf-funds.util.d.ts +2 -0
  200. package/dist/utility/wrun/wrun-etf-funds.util.js +4 -0
  201. package/dist/utility/wrun/wrun-held-lanes.util.js +8 -2
  202. package/dist/utility/wrun/wrun-history-as-of.util.d.ts +77 -0
  203. package/dist/utility/wrun/wrun-history-as-of.util.js +108 -0
  204. package/dist/utility/wrun/wrun-host.service.d.ts +64 -14
  205. package/dist/utility/wrun/wrun-host.service.js +137 -27
  206. package/dist/utility/wrun/wrun-hosted-wire-caps.d.ts +3 -3
  207. package/dist/utility/wrun/wrun-hosted-wire-caps.js +12 -2
  208. package/dist/utility/wrun/wrun-inert-legend.util.d.ts +13 -0
  209. package/dist/utility/wrun/wrun-inert-legend.util.js +31 -3
  210. package/dist/utility/wrun/wrun-input-requirements.leaf.d.ts +7 -5
  211. package/dist/utility/wrun/wrun-input-requirements.leaf.js +16 -6
  212. package/dist/utility/wrun/wrun-install-pacer.util.d.ts +26 -0
  213. package/dist/utility/wrun/wrun-install-pacer.util.js +145 -0
  214. package/dist/utility/wrun/wrun-kit-refusal-stages.types.d.ts +22 -0
  215. package/dist/utility/wrun/wrun-kit-refusal-stages.types.js +1 -0
  216. package/dist/utility/wrun/wrun-lane-refusal.leaf.d.ts +12 -5
  217. package/dist/utility/wrun/wrun-lane-refusal.leaf.js +23 -5
  218. package/dist/utility/wrun/wrun-lane-warmup.util.js +22 -4
  219. package/dist/utility/wrun/wrun-leg-close.util.d.ts +6 -5
  220. package/dist/utility/wrun/wrun-leg-close.util.js +11 -9
  221. package/dist/utility/wrun/wrun-leg-fetch.util.d.ts +3 -1
  222. package/dist/utility/wrun/wrun-leg-fetch.util.js +9 -2
  223. package/dist/utility/wrun/wrun-levels-child.util.d.ts +2 -0
  224. package/dist/utility/wrun/wrun-levels-child.util.js +6 -0
  225. package/dist/utility/wrun/wrun-lifecycle.contract.d.ts +4 -0
  226. package/dist/utility/wrun/wrun-live-intake.util.d.ts +15 -6
  227. package/dist/utility/wrun/wrun-live-intake.util.js +167 -47
  228. package/dist/utility/wrun/wrun-live-tick.util.d.ts +52 -8
  229. package/dist/utility/wrun/wrun-live-tick.util.js +648 -97
  230. package/dist/utility/wrun/wrun-market-facts.util.d.ts +16 -2
  231. package/dist/utility/wrun/wrun-market-facts.util.js +32 -3
  232. package/dist/utility/wrun/wrun-market-size-defaults.leaf.d.ts +27 -27
  233. package/dist/utility/wrun/wrun-market-size-defaults.leaf.js +28 -16
  234. package/dist/utility/wrun/wrun-market-size-defaults.util.js +34 -5
  235. package/dist/utility/wrun/wrun-oi-lane.util.d.ts +10 -7
  236. package/dist/utility/wrun/wrun-oi-lane.util.js +16 -10
  237. package/dist/utility/wrun/wrun-option-strike-flow.util.js +1 -1
  238. package/dist/utility/wrun/wrun-option-views.util.d.ts +2 -2
  239. package/dist/utility/wrun/wrun-option-views.util.js +5 -2
  240. package/dist/utility/wrun/wrun-options-flow-underlying.leaf.d.ts +5 -0
  241. package/dist/utility/wrun/wrun-options-flow-underlying.leaf.js +16 -0
  242. package/dist/utility/wrun/wrun-options-stop.util.d.ts +3 -2
  243. package/dist/utility/wrun/wrun-options-stop.util.js +6 -4
  244. package/dist/utility/wrun/wrun-overlay-drivers.util.d.ts +75 -11
  245. package/dist/utility/wrun/wrun-overlay-drivers.util.js +176 -43
  246. package/dist/utility/wrun/wrun-overlay-lifecycle.util.js +20 -10
  247. package/dist/utility/wrun/wrun-overlay-park.util.d.ts +84 -0
  248. package/dist/utility/wrun/wrun-overlay-park.util.js +135 -0
  249. package/dist/utility/wrun/wrun-overlay-recovery.util.d.ts +37 -4
  250. package/dist/utility/wrun/wrun-overlay-recovery.util.js +26 -14
  251. package/dist/utility/wrun/wrun-overlay-run.util.d.ts +239 -24
  252. package/dist/utility/wrun/wrun-overlay-run.util.js +2204 -405
  253. package/dist/utility/wrun/wrun-pack.util.d.ts +8 -5
  254. package/dist/utility/wrun/wrun-panel-mount.util.d.ts +2 -1
  255. package/dist/utility/wrun/wrun-panel-mount.util.js +20 -14
  256. package/dist/utility/wrun/wrun-panel-style.util.d.ts +4 -2
  257. package/dist/utility/wrun/wrun-panel-style.util.js +3 -2
  258. package/dist/utility/wrun/wrun-pin-spelling.util.d.ts +7 -0
  259. package/dist/utility/wrun/wrun-pin-spelling.util.js +18 -4
  260. package/dist/utility/wrun/wrun-pin-venues.util.d.ts +26 -17
  261. package/dist/utility/wrun/wrun-pin-venues.util.js +43 -36
  262. package/dist/utility/wrun/wrun-pinned-lanes.util.d.ts +58 -0
  263. package/dist/utility/wrun/wrun-pinned-lanes.util.js +72 -0
  264. package/dist/utility/wrun/wrun-prefix-cohort.util.js +2 -1
  265. package/dist/utility/wrun/wrun-prefix-lanes.util.d.ts +22 -9
  266. package/dist/utility/wrun/wrun-prefix-lanes.util.js +145 -26
  267. package/dist/utility/wrun/wrun-prefix-proof.util.d.ts +29 -0
  268. package/dist/utility/wrun/wrun-prefix-proof.util.js +23 -5
  269. package/dist/utility/wrun/wrun-refusal-surface.util.d.ts +9 -1
  270. package/dist/utility/wrun/wrun-refusal-surface.util.js +15 -1
  271. package/dist/utility/wrun/wrun-refusal.util.d.ts +19 -1
  272. package/dist/utility/wrun/wrun-refusal.util.js +103 -16
  273. package/dist/utility/wrun/wrun-registry-errors.util.d.ts +20 -6
  274. package/dist/utility/wrun/wrun-registry-errors.util.js +20 -6
  275. package/dist/utility/wrun/wrun-replay-rows.util.js +6 -10
  276. package/dist/utility/wrun/wrun-run-health.util.d.ts +89 -2
  277. package/dist/utility/wrun/wrun-run-health.util.js +204 -1
  278. package/dist/utility/wrun/wrun-run-interval-session.util.d.ts +2 -2
  279. package/dist/utility/wrun/wrun-run-interval-session.util.js +2 -2
  280. package/dist/utility/wrun/wrun-run-interval.util.d.ts +9 -8
  281. package/dist/utility/wrun/wrun-run-interval.util.js +13 -11
  282. package/dist/utility/wrun/wrun-sandbox-row-source.js +5 -2
  283. package/dist/utility/wrun/wrun-script-inputs.util.d.ts +13 -3
  284. package/dist/utility/wrun/wrun-script-inputs.util.js +51 -13
  285. package/dist/utility/wrun/wrun-session-composition.util.d.ts +81 -0
  286. package/dist/utility/wrun/wrun-session-composition.util.js +169 -0
  287. package/dist/utility/wrun/wrun-setting-words.util.d.ts +10 -7
  288. package/dist/utility/wrun/wrun-setting-words.util.js +25 -7
  289. package/dist/utility/wrun/wrun-source-rows.util.d.ts +94 -28
  290. package/dist/utility/wrun/wrun-source-rows.util.js +738 -93
  291. package/dist/utility/wrun/wrun-stream-clock.util.d.ts +45 -0
  292. package/dist/utility/wrun/wrun-stream-clock.util.js +108 -0
  293. package/dist/utility/wrun/wrun-tape-coins.util.d.ts +116 -0
  294. package/dist/utility/wrun/wrun-tape-coins.util.js +110 -0
  295. package/dist/utility/wrun/wrun-tape-source.util.d.ts +62 -32
  296. package/dist/utility/wrun/wrun-tape-source.util.js +72 -34
  297. package/dist/utility/wrun/wrun-tier-grid.util.d.ts +13 -5
  298. package/dist/utility/wrun/wrun-tier-grid.util.js +23 -13
  299. package/dist/utility/wrun/wrun-tpo-rows.util.js +2 -1
  300. package/dist/utility/wrun/wrun-trades-lane.util.d.ts +73 -0
  301. package/dist/utility/wrun/wrun-trades-lane.util.js +82 -0
  302. package/dist/utility/wrun/wrun-twin-compute-inputs.util.d.ts +5 -0
  303. package/dist/utility/wrun/wrun-twin-compute-inputs.util.js +9 -2
  304. package/dist/utility/wrun/wrun-visibility-table.d.ts +13 -0
  305. package/dist/utility/wrun/wrun-visibility-table.js +9 -0
  306. package/dist/utility/wrun/wrun-volume-profile.util.js +44 -32
  307. package/dist/utils/replay/replay-buffer-math.d.ts +16 -6
  308. package/dist/utils/replay/replay-buffer-math.js +60 -30
  309. package/dist/workers/constants/socket-slots.d.ts +11 -7
  310. package/dist/workers/constants/socket-slots.js +6 -5
  311. package/package.json +11 -11
@@ -0,0 +1,488 @@
1
+ /**
2
+ * Session lattices: the client mirror of how tsdb-gateway labels a session
3
+ * venue's history at 4h, 1d, 1w and the rolled-up presets. The gateway keeps
4
+ * ONE rollup for every venue that owns its trading day (pkg/tsdb/selects/
5
+ * session_profile.go `sessionProfile`, generalised from the CME rollup by
6
+ * !2483): a profile names the wall clock the bars are cut on, the venues, the
7
+ * intervals and the weekend rule, and the rollup re-groups source-tier rows on
8
+ * that wall clock. This module is the same table: a venue with its own trading
9
+ * day is one more profile here, and every live writer, fetch window, run-bar
10
+ * span and trading-day anchor reads the profile instead of naming a venue.
11
+ *
12
+ * The two profiles the gateway serves today:
13
+ *
14
+ * - CME Group (`cmeSession`, cme.go, since c645fd6; the presets since !2151):
15
+ * 17:00 America/Chicago, on the CME trade calendar (a weekday holiday's
16
+ * session belongs to the next trade date, cme-trade-calendar.util, !2154),
17
+ * a weekend day keeps its own date (the 24/7 crypto products trade it).
18
+ * Served for TRADE_AGG, TRADE_SIDE_AGNOSTIC_AGG and the per-symbol
19
+ * VOLUME_PROFILE_AGG / BLOCK_BOOK_SNAPSHOT_AGG of CME, CBOT, NYMEX, COMEX.
20
+ * - Forex (`forexSession`, forex_session.go, !2483, Discord ticket 603): 17:00
21
+ * America/New_York, the day TradingView and MT4 cut on, no calendar, and a
22
+ * session day falling on a weekend moves to the Monday after (Sunday's
23
+ * 17:00 open starts Monday's bar; there is no Sunday bar). Served for
24
+ * FX_OTC TICKER_AGG at 4h and wider only: finer bars nest in the hours.
25
+ *
26
+ * How the gateway stamps a bar (`sessionProfile.bucketExpression`):
27
+ *
28
+ * - intraday widths: `time_bucket(width, ts, timezone => zone, offset =>
29
+ * open modulo the width)`, so the open starts a bar. 4h on a 17:00 open:
30
+ * local 01/05/09/13/17/21 (22/02/06/10/14/18Z in daylight time, an hour
31
+ * later in standard time); 2h and 8h offset 1h, 6h and 12h 5h, 45m 30m,
32
+ * 2m 3m 10m none. The source tier is the coarsest of 1h/15m/5m/1m dividing
33
+ * both the width and that offset (`sourceStepMs`);
34
+ * - 1d: the trade date (the date flips at the open), stamped at 00:00Z of
35
+ * that date, so an evening print belongs to TOMORROW's bar; the weekend
36
+ * rule, then the calendar, move the date;
37
+ * - 3d: the trade dates in threes (the calendar's `DayGroupStart`, else the
38
+ * weekday grid from 2000-01-03), labeled by the first;
39
+ * - 1w: the Monday of the trade-date week, 00:00Z;
40
+ * - 1M 3M 6M 1Y: the months of the trade dates, stamped on the first month's
41
+ * 1st at 00:00Z (29dda19, intervals part 4); a weekend day joins the Friday
42
+ * before, so a stale weekend book never opens a month.
43
+ *
44
+ * A live writer that floored session frames on the UTC grid instead split the
45
+ * forming bar (a 04:00 ET CME candle beside the 02:00 ET one; an FX 4h candle
46
+ * frozen for two hours after each lattice open) and titan dropped the frames
47
+ * keyed before it.
48
+ *
49
+ * Pure and worker-safe: Intl only, no dayjs.
50
+ */
51
+ import { Intervals } from '../../constants/interval.constants.js';
52
+ import { barEndMs, calendarBarStartMs, calendarMonthsOfMs } from './calendar-interval.util.js';
53
+ import { cmeDayGroupStartMs, cmeTradeDateOnOrAfter, cmeTradeDateOnOrBefore, isCmeTradeDate, } from './cme-trade-calendar.util.js';
54
+ const MINUTE_MS = 60_000;
55
+ const HOUR_MS = 3_600_000;
56
+ const DAY_MS = 86_400_000;
57
+ const ONE_DAY_MS = Intervals.map_unit['1d'];
58
+ const THREE_DAYS_MS = Intervals.map_unit['3d'];
59
+ const ONE_WEEK_MS = Intervals.map_unit['1w'];
60
+ const intervalSet = (labels) => new Set(labels.map((label) => Intervals.map_unit[label]));
61
+ const CME_TRADE_CALENDAR = {
62
+ isTradeDate: isCmeTradeDate,
63
+ tradeDateOnOrAfter: cmeTradeDateOnOrAfter,
64
+ tradeDateOnOrBefore: cmeTradeDateOnOrBefore,
65
+ dayGroupStartMs: cmeDayGroupStartMs,
66
+ };
67
+ /** CME Group: 17:00 America/Chicago on the CME trade calendar (gateway `cmeSession`). GLOBEX is a metadata alias with no gate mapping. */
68
+ export const CME_SESSION_LATTICE = Object.freeze({
69
+ id: 'cme',
70
+ timeZone: 'America/Chicago',
71
+ standardOffsetMs: -6 * HOUR_MS,
72
+ daylightOffsetMs: -5 * HOUR_MS,
73
+ openHour: 17,
74
+ exchanges: new Set(['CME', 'CBOT', 'NYMEX', 'COMEX']),
75
+ intradayLatticeMs: intervalSet(['2m', '3m', '10m', '45m', '2h', '4h', '6h', '8h', '12h']),
76
+ weekendToMonday: false,
77
+ calendar: CME_TRADE_CALENDAR,
78
+ });
79
+ /** Forex: 17:00 America/New_York, Sunday's open starts Monday's bar (gateway `forexSession`, 4h and wider only). */
80
+ export const FOREX_SESSION_LATTICE = Object.freeze({
81
+ id: 'forex',
82
+ timeZone: 'America/New_York',
83
+ standardOffsetMs: -5 * HOUR_MS,
84
+ daylightOffsetMs: -4 * HOUR_MS,
85
+ openHour: 17,
86
+ exchanges: new Set(['FX_OTC']),
87
+ intradayLatticeMs: intervalSet(['4h', '6h', '8h', '12h']),
88
+ weekendToMonday: true,
89
+ calendar: null,
90
+ });
91
+ /** Every venue group with a trading day of its own (the gateway's `sessionProfiles`). */
92
+ export const SESSION_LATTICE_PROFILES = Object.freeze([
93
+ CME_SESSION_LATTICE,
94
+ FOREX_SESSION_LATTICE,
95
+ ]);
96
+ /** The profile named `id`, or null. */
97
+ export function sessionLatticeById(id) {
98
+ return SESSION_LATTICE_PROFILES.find((profile) => profile.id === id) ?? null;
99
+ }
100
+ /** The lattice the gateway rolls `exchange` up on, or null for a venue that keeps the UTC aggregates. */
101
+ export function sessionLatticeOf(exchange) {
102
+ if (typeof exchange !== 'string')
103
+ return null;
104
+ const code = exchange.toUpperCase();
105
+ return SESSION_LATTICE_PROFILES.find((profile) => profile.exchanges.has(code)) ?? null;
106
+ }
107
+ /** The intervals the gateway serves on the profile's lattice: its intraday widths, 1d, 3d, 1w and the calendar rungs. */
108
+ export function isSessionLatticeIntervalMs(profile, intervalMs) {
109
+ return (typeof intervalMs === 'number' &&
110
+ (profile.intradayLatticeMs.has(intervalMs) ||
111
+ intervalMs === ONE_DAY_MS ||
112
+ intervalMs === THREE_DAYS_MS ||
113
+ intervalMs === ONE_WEEK_MS ||
114
+ calendarMonthsOfMs(intervalMs) !== null));
115
+ }
116
+ const floorTo = (value, step) => value - (((value % step) + step) % step);
117
+ const isWeekendDay = (dayMs) => {
118
+ const weekday = new Date(dayMs).getUTCDay();
119
+ return weekday === 0 || weekday === 6;
120
+ };
121
+ /** The session open's offset into a width: a 17:00 open sits on the lattice (4h: 01:00, 05:00, ... 21:00). */
122
+ const openOffsetMs = (profile, widthMs) => (profile.openHour * HOUR_MS) % widthMs;
123
+ /** The source tier the gateway re-buckets for a width (`sessionTier`): the coarsest dividing width and offset. */
124
+ function sourceStepMs(profile, widthMs) {
125
+ const offsetMs = openOffsetMs(profile, widthMs);
126
+ for (const stepMs of [HOUR_MS, 15 * MINUTE_MS, 5 * MINUTE_MS]) {
127
+ if (widthMs % stepMs === 0 && offsetMs % stepMs === 0)
128
+ return stepMs;
129
+ }
130
+ return MINUTE_MS;
131
+ }
132
+ const OFFSET_CACHE_MAX = 8192;
133
+ const BAR_END_CACHE_MAX = 8192;
134
+ const states = new Map();
135
+ function stateOf(profile) {
136
+ let state = states.get(profile.id);
137
+ if (!state) {
138
+ state = { formatter: null, offsetByUtcDay: new Map(), offsetByUtcHour: new Map(), barEnd: new Map() };
139
+ states.set(profile.id, state);
140
+ }
141
+ return state;
142
+ }
143
+ function formatterOf(profile) {
144
+ const state = stateOf(profile);
145
+ if (!state.formatter) {
146
+ state.formatter = new Intl.DateTimeFormat('en-US', {
147
+ timeZone: profile.timeZone,
148
+ year: 'numeric',
149
+ month: '2-digit',
150
+ day: '2-digit',
151
+ hour: '2-digit',
152
+ minute: '2-digit',
153
+ second: '2-digit',
154
+ hourCycle: 'h23',
155
+ });
156
+ }
157
+ return state.formatter;
158
+ }
159
+ function intlZoneOffsetMs(profile, utcMs) {
160
+ const wall = { year: 0, month: 1, day: 1, hour: 0, minute: 0, second: 0 };
161
+ for (const part of formatterOf(profile).formatToParts(utcMs)) {
162
+ if (part.type in wall)
163
+ wall[part.type] = Number(part.value);
164
+ }
165
+ return Date.UTC(wall.year, wall.month - 1, wall.day, wall.hour % 24, wall.minute, wall.second) - utcMs;
166
+ }
167
+ function cacheOffset(cache, key, offset) {
168
+ if (cache.size >= OFFSET_CACHE_MAX)
169
+ cache.clear();
170
+ cache.set(key, offset);
171
+ }
172
+ /**
173
+ * The zone's UTC offset at `utcMs`. US transitions happen at 02:00 local, a
174
+ * whole UTC hour, at most once per UTC day, so a day whose first and last
175
+ * hours agree holds one offset throughout: it caches per day (a CVD candle
176
+ * commit buckets years of rows, the live path one frame at a time), and only
177
+ * a transition day falls back to per-hour reads. NaN marks a transition day.
178
+ */
179
+ function zoneOffsetMs(profile, utcMs) {
180
+ const state = stateOf(profile);
181
+ const dayMs = floorTo(utcMs, DAY_MS);
182
+ let dayOffset = state.offsetByUtcDay.get(dayMs);
183
+ if (dayOffset === undefined) {
184
+ const first = intlZoneOffsetMs(profile, dayMs);
185
+ dayOffset = first === intlZoneOffsetMs(profile, dayMs + 23 * HOUR_MS) ? first : Number.NaN;
186
+ cacheOffset(state.offsetByUtcDay, dayMs, dayOffset);
187
+ }
188
+ if (!Number.isNaN(dayOffset))
189
+ return dayOffset;
190
+ const hourMs = floorTo(utcMs, HOUR_MS);
191
+ let hourOffset = state.offsetByUtcHour.get(hourMs);
192
+ if (hourOffset === undefined) {
193
+ hourOffset = intlZoneOffsetMs(profile, hourMs);
194
+ cacheOffset(state.offsetByUtcHour, hourMs, hourOffset);
195
+ }
196
+ return hourOffset;
197
+ }
198
+ /**
199
+ * The instant a zone wall time (expressed as if it were UTC) names, read the
200
+ * way Postgres does (DetermineTimeZoneOffset): a wall time that occurs twice
201
+ * (fall back) or never (spring forward) reads as standard time.
202
+ */
203
+ function wallToUtcMs(profile, wallAsUtcMs) {
204
+ const standard = wallAsUtcMs - profile.standardOffsetMs;
205
+ if (zoneOffsetMs(profile, standard) === profile.standardOffsetMs)
206
+ return standard;
207
+ const daylight = wallAsUtcMs - profile.daylightOffsetMs;
208
+ if (zoneOffsetMs(profile, daylight) === profile.daylightOffsetMs)
209
+ return daylight;
210
+ return standard;
211
+ }
212
+ /** The zone wall clock (as if it were UTC) of the gateway's source row: the 1h bucket holding `tsMs`. */
213
+ function wallOfSourceRow(profile, tsMs) {
214
+ const rowMs = floorTo(tsMs, HOUR_MS);
215
+ return rowMs + zoneOffsetMs(profile, rowMs);
216
+ }
217
+ /** The calendar date of the session close `tsMs` trades toward (gateway `sessionProfile.day`): it flips at the open. */
218
+ function sessionDayMs(profile, tsMs) {
219
+ return floorTo(wallOfSourceRow(profile, tsMs) + (24 - profile.openHour) * HOUR_MS, DAY_MS);
220
+ }
221
+ /** The session day with the weekend rule applied (gateway `tradeDay`): Saturday and Sunday move to the Monday after. */
222
+ function tradeDayMs(profile, dayMs) {
223
+ if (!profile.weekendToMonday)
224
+ return dayMs;
225
+ const weekday = new Date(dayMs).getUTCDay();
226
+ return weekday === 6 ? dayMs + 2 * DAY_MS : weekday === 0 ? dayMs + DAY_MS : dayMs;
227
+ }
228
+ /**
229
+ * The trade date the session day `dayMs` is booked to, stamped at 00:00Z
230
+ * (gateway `currentLabel` at DAY): the weekend rule, then the calendar moves a
231
+ * weekday holiday's session to the next trade date; a weekend day keeps its
232
+ * own date on a profile without the weekend rule.
233
+ */
234
+ function tradeDateOfDay(profile, dayMs) {
235
+ const day = tradeDayMs(profile, dayMs);
236
+ return profile.calendar && !isWeekendDay(day) ? profile.calendar.tradeDateOnOrAfter(day) : day;
237
+ }
238
+ /** The 3d bar's first trade date: on a calendar a weekend day joins the previous trade date's bar, else the weekday grid. */
239
+ function threeDayLabelOfDay(profile, dayMs) {
240
+ const day = tradeDayMs(profile, dayMs);
241
+ if (profile.calendar) {
242
+ const tradeDate = isWeekendDay(day)
243
+ ? profile.calendar.tradeDateOnOrBefore(day)
244
+ : profile.calendar.tradeDateOnOrAfter(day);
245
+ return profile.calendar.dayGroupStartMs(tradeDate, 3);
246
+ }
247
+ return sessionGridStartMs(day);
248
+ }
249
+ /** The Monday (00:00Z) of the trade-date week: date_trunc('week'), ISO weeks from Monday; 1970-01-01 was a Thursday (ISO index 3). */
250
+ function weekLabelOfDay(profile, dayMs) {
251
+ const tradeDate = tradeDateOfDay(profile, dayMs);
252
+ const isoWeekday = (((Math.floor(tradeDate / DAY_MS) + 3) % 7) + 7) % 7;
253
+ return tradeDate - isoWeekday * DAY_MS;
254
+ }
255
+ /**
256
+ * The calendar bar holding the session day (gateway `bucketExpression` at a calendar interval): the months of its
257
+ * trade date, a weekend day counted on the Friday before it, so a stale weekend book never opens a month. Under the
258
+ * weekend rule the day is never a weekend day: it already moved to Monday.
259
+ */
260
+ function calendarLabelOfDay(profile, dayMs, months) {
261
+ const day = tradeDayMs(profile, dayMs);
262
+ const weekday = new Date(day).getUTCDay();
263
+ const tradeDateMs = weekday === 6
264
+ ? day - DAY_MS
265
+ : weekday === 0
266
+ ? day - 2 * DAY_MS
267
+ : profile.calendar
268
+ ? profile.calendar.tradeDateOnOrAfter(day)
269
+ : day;
270
+ return calendarBarStartMs(tradeDateMs, months);
271
+ }
272
+ /** The bar key the gateway stamps for the session day `dayMs` at a label interval (1d, 3d, 1w, the calendar rungs); null elsewhere. */
273
+ function labelOfDay(profile, dayMs, intervalMs) {
274
+ if (intervalMs === ONE_DAY_MS)
275
+ return tradeDateOfDay(profile, dayMs);
276
+ if (intervalMs === THREE_DAYS_MS)
277
+ return threeDayLabelOfDay(profile, dayMs);
278
+ if (intervalMs === ONE_WEEK_MS)
279
+ return weekLabelOfDay(profile, dayMs);
280
+ const months = calendarMonthsOfMs(intervalMs);
281
+ return months === null ? null : calendarLabelOfDay(profile, dayMs, months);
282
+ }
283
+ /** The open that starts the session day `dayMs`: the profile's open hour on the calendar day before it. */
284
+ const sessionOpenMs = (profile, dayMs) => wallToUtcMs(profile, dayMs - DAY_MS + profile.openHour * HOUR_MS);
285
+ /** How far a session day can sit from the label it is booked to: a long weekend and the holidays around it. */
286
+ const LABEL_REACH_DAYS = 7;
287
+ /**
288
+ * The first session day booked to the bar stamped `labelMs`. Labels are monotone in the session day, so the first
289
+ * day in reach whose label is `labelMs` opens the bar: a weekday holiday just before a trade date opens with it (CME
290
+ * 9/8 opens Sunday 9/6; New Year's Day opens January), a weekend before a Monday opens it under the weekend rule
291
+ * (forex Monday holds the weekend's stale prints back to Friday's close), a weekend 1st opens its month on the
292
+ * Monday after (August 2026 opens Sunday 8/2). Null for a stamp the lattice books no day to.
293
+ *
294
+ * A profile without the weekend rule keeps the shared host's reading of its 1d, 3d and 1w opens
295
+ * (`@orangecharts/indicator-kit/host` session-calendar, the copy the wrun lane reads; pinned by
296
+ * tests/utility/chart/cme-calendar.package-parity.spec.ts): a week opens with its Monday's session, and a trade
297
+ * date or a 3d group opens with the weekday holidays right before it, never across a weekend. The gateway books a
298
+ * Friday holiday's session to the Monday after (sessionProfile.sourceRange: "Monday's bar with a Friday holiday's
299
+ * Thursday 17:00 open"), which the scan above would read and the host's copy does not; the two copies move
300
+ * together, not here.
301
+ */
302
+ function firstSessionDayOfLabel(profile, labelMs, intervalMs) {
303
+ if (!profile.weekendToMonday && calendarMonthsOfMs(intervalMs) === null) {
304
+ if (intervalMs === ONE_WEEK_MS)
305
+ return labelMs;
306
+ let day = labelMs;
307
+ for (let prev = day - DAY_MS; !isWeekendDay(prev) && profile.calendar !== null && !profile.calendar.isTradeDate(prev); prev -= DAY_MS) {
308
+ day = prev;
309
+ }
310
+ return day;
311
+ }
312
+ for (let day = labelMs - LABEL_REACH_DAYS * DAY_MS; day <= labelMs + LABEL_REACH_DAYS * DAY_MS; day += DAY_MS) {
313
+ if (labelOfDay(profile, day, intervalMs) === labelMs)
314
+ return day;
315
+ }
316
+ return null;
317
+ }
318
+ /**
319
+ * The gateway's intraday bucket start for the source row holding `tsMs`, in
320
+ * the order TimescaleDB runs `time_bucket` with a timezone and an offset
321
+ * (src/time_bucket.c `ts_timestamptz_timezone_bucket`, 2.25+ #9129): take
322
+ * the offset off in UTC, bucket the zone wall clock from local midnight,
323
+ * read the start back, step back while it lands after the shifted instant
324
+ * (the fall-back guard), put the offset back in UTC. On the fall-back
325
+ * Sunday the 01:00 4h bar spans five real hours from 06:00Z; only CME's 24/7
326
+ * crypto products trade then (forex opens Sunday 17:00, after the change).
327
+ * Every lattice width divides a day, so flooring the wall clock from the
328
+ * epoch is flooring it from local midnight.
329
+ */
330
+ function intradayBucketStartMs(profile, tsMs, widthMs) {
331
+ const offsetMs = openOffsetMs(profile, widthMs);
332
+ const shifted = floorTo(tsMs, sourceStepMs(profile, widthMs)) - offsetMs;
333
+ let start = wallToUtcMs(profile, floorTo(shifted + zoneOffsetMs(profile, shifted), widthMs));
334
+ while (start > shifted)
335
+ start -= widthMs;
336
+ return start + offsetMs;
337
+ }
338
+ const SESSION_GRID_ORIGIN_MS = Date.UTC(2000, 0, 3);
339
+ const SESSION_GRID_DAYS = 3;
340
+ /**
341
+ * The first trade date (00:00Z) of the 3d session bar holding the trade date
342
+ * `dayMs` (gateway `sessionGridStart`, session_grid.go): trade dates are
343
+ * counted in weekdays from 2000-01-03, a Monday, three to a bar; a weekend
344
+ * date counts as the Friday before it. The regular US equities session and
345
+ * the forex lattice (no calendar); CME rides the trade calendar, every other
346
+ * market's 3d is the calendar floor.
347
+ */
348
+ export function sessionGridStartMs(dayMs) {
349
+ const days = Math.floor((dayMs - SESSION_GRID_ORIGIN_MS) / DAY_MS);
350
+ const weeks = Math.floor(days / 7);
351
+ const weekday = 5 * weeks + Math.min(days - 7 * weeks, 4);
352
+ const start = SESSION_GRID_DAYS * Math.floor(weekday / SESSION_GRID_DAYS);
353
+ const startWeeks = Math.floor(start / 5);
354
+ return SESSION_GRID_ORIGIN_MS + (7 * startWeeks + start - 5 * startWeeks) * DAY_MS;
355
+ }
356
+ /**
357
+ * The bar key the gateway stamps for the profile's session bar holding
358
+ * `tsMs`: the intraday bucket start, or the trade-date label (00:00Z of the
359
+ * trade date, not the open instant) at 1d, the first trade date of its 3d
360
+ * group, the Monday of its week at 1w, and the 1st of its trade date's month,
361
+ * quarter, half or year at a calendar length. Null when the interval is not a
362
+ * lattice interval of the profile or the input is not a number.
363
+ */
364
+ export function sessionLatticeBucketMs(profile, tsMs, intervalMs) {
365
+ if (!Number.isFinite(tsMs))
366
+ return null;
367
+ if (profile.intradayLatticeMs.has(intervalMs))
368
+ return intradayBucketStartMs(profile, tsMs, intervalMs);
369
+ if (intervalMs !== ONE_DAY_MS &&
370
+ intervalMs !== THREE_DAYS_MS &&
371
+ intervalMs !== ONE_WEEK_MS &&
372
+ calendarMonthsOfMs(intervalMs) === null) {
373
+ return null;
374
+ }
375
+ return labelOfDay(profile, sessionDayMs(profile, tsMs), intervalMs);
376
+ }
377
+ /** The longest a daily-class bar can run past its stamp: a week and the holidays around it. */
378
+ const DAILY_BAR_SCAN_MS = 21 * DAY_MS;
379
+ /**
380
+ * The instant the session bar stamped `barMs` (a key `sessionLatticeBucketMs` stamps) stops taking
381
+ * source rows: the end of the last source row the lattice books to it, for a reader that must never
382
+ * take a bar before it closes (a pinned wrun leg). At 1d, 3d and 1w the key only advances with the
383
+ * session day, so the bar ends at the first source row booked elsewhere: a 3d bar runs to the open of
384
+ * the next group's first session, a weekend or a weekday holiday inside it (Thursday, Friday and
385
+ * Monday close at Monday's open), a 1d bar to the open that starts the next session day (a forex
386
+ * Monday, which holds the weekend before it, still ends at Monday's 17:00 New York). An intraday bar
387
+ * ends at its stamp plus its width, except across a DST change: on the fall-back Sunday a bucket
388
+ * reaching the repeated hour holds its rows an hour longer (the 01:00 4h bar runs five real hours),
389
+ * and the 45m lattice books rows of the repeated hour back to an earlier stamp, so the end is the end
390
+ * of the LAST row booked to it within its width and an hour. A calendar bar runs to the next one's
391
+ * open (July 2026 to Sunday 8/2 at 17:00 CDT). Null off the lattice intervals, or for a stamp the
392
+ * lattice books no row to.
393
+ */
394
+ export function sessionLatticeBarEndMs(profile, barMs, intervalMs) {
395
+ if (!Number.isFinite(barMs) || !isSessionLatticeIntervalMs(profile, intervalMs))
396
+ return null;
397
+ const state = stateOf(profile);
398
+ const cacheKey = `${intervalMs}:${barMs}`;
399
+ const cached = state.barEnd.get(cacheKey);
400
+ if (cached !== undefined)
401
+ return cached;
402
+ let end = null;
403
+ const months = calendarMonthsOfMs(intervalMs);
404
+ if (months !== null) {
405
+ if (calendarBarStartMs(barMs, months) === barMs) {
406
+ const next = firstSessionDayOfLabel(profile, barEndMs(barMs, intervalMs), intervalMs);
407
+ end = next === null ? null : sessionOpenMs(profile, next);
408
+ }
409
+ }
410
+ else if (profile.intradayLatticeMs.has(intervalMs)) {
411
+ const windowEndMs = barMs + intervalMs + HOUR_MS;
412
+ if (zoneOffsetMs(profile, barMs - intervalMs - HOUR_MS) === zoneOffsetMs(profile, windowEndMs)) {
413
+ // No DST change within reach: the lattice is a plain run of widths here. (A spring-forward
414
+ // change just before the stamp shortens the bar, so the window reaches back a width too.)
415
+ end = sessionLatticeBucketMs(profile, barMs, intervalMs) === barMs ? barMs + intervalMs : null;
416
+ }
417
+ else {
418
+ const stepMs = sourceStepMs(profile, intervalMs);
419
+ for (let rowMs = barMs; rowMs < windowEndMs; rowMs += stepMs) {
420
+ if (sessionLatticeBucketMs(profile, rowMs, intervalMs) === barMs)
421
+ end = rowMs + stepMs;
422
+ }
423
+ }
424
+ }
425
+ else if (sessionLatticeBucketMs(profile, barMs, intervalMs) === barMs) {
426
+ let rowMs = barMs + HOUR_MS;
427
+ while (rowMs < barMs + DAILY_BAR_SCAN_MS && sessionLatticeBucketMs(profile, rowMs, intervalMs) === barMs) {
428
+ rowMs += HOUR_MS;
429
+ }
430
+ end = rowMs < barMs + DAILY_BAR_SCAN_MS ? rowMs : null;
431
+ }
432
+ if (state.barEnd.size >= BAR_END_CACHE_MAX)
433
+ state.barEnd.clear();
434
+ state.barEnd.set(cacheKey, end);
435
+ return end;
436
+ }
437
+ /**
438
+ * The instant the session bar holding `tsMs` opens, for a fetch window that
439
+ * must cover the whole bar: the intraday bucket start, or the open before the
440
+ * first session day booked to the label (1d, 3d, 1w and the calendar rungs,
441
+ * where the bar key is a 00:00Z label that runs ahead of the open): the
442
+ * 17:00 open before a trade date, Sunday's open before a week's Monday, a
443
+ * month's first trade date (August 2026 opens Sunday 8/2). A 1d or 3d bar
444
+ * after a weekday holiday opens with the holiday's session (9/8 opens Sunday
445
+ * 9/6); a forex Monday opens at Friday's close, where its weekend prints
446
+ * start. Null off the lattice intervals.
447
+ */
448
+ export function sessionLatticeBarOpenMs(profile, tsMs, intervalMs) {
449
+ const bucketMs = sessionLatticeBucketMs(profile, tsMs, intervalMs);
450
+ if (bucketMs === null || profile.intradayLatticeMs.has(intervalMs))
451
+ return bucketMs;
452
+ const first = firstSessionDayOfLabel(profile, bucketMs, intervalMs);
453
+ return first === null ? null : sessionOpenMs(profile, first);
454
+ }
455
+ /** How far past a bar's stamp the next bar's first source row can sit: a calendar bar's months and the holidays
456
+ * around its next open, a daily-class bar's long weekend and holidays, an intraday bar's width and the repeated
457
+ * fall-back hour. */
458
+ function nextBarReachMs(profile, intervalMs) {
459
+ const months = calendarMonthsOfMs(intervalMs);
460
+ if (months !== null)
461
+ return (months * 31 + LABEL_REACH_DAYS) * DAY_MS;
462
+ if (profile.intradayLatticeMs.has(intervalMs))
463
+ return intervalMs + 2 * HOUR_MS;
464
+ return DAILY_BAR_SCAN_MS;
465
+ }
466
+ /**
467
+ * The stamp of the session bar after `barMs` (a stamp `sessionLatticeBucketMs` gives), for a walk that must visit
468
+ * every bar of a window once: the first later stamp a source row is booked to, read row by row from `barMs` at the
469
+ * gateway's source step (an hour on the daily and calendar bars). Never the bucket of `barMs + intervalMs`: a
470
+ * lattice bar can outlast its width (the 01:00 4h bar runs five real hours on a fall-back Sunday, a 3d bar holds the
471
+ * weekend inside it, a 31-day month outlasts the 1M width), and inside such a bar that bucket is the bar itself, so
472
+ * a walk stepping it never moves (the k-trades grid spun until the data worker's heap ran out, 2026-11-05). Rows
473
+ * after the change can book back to an earlier stamp (the 45m lattice's repeated hour), so the first LATER stamp is
474
+ * the next bar, never the bar the last row of `barMs` ends at. Null off the lattice intervals or when no later
475
+ * stamp sits within reach.
476
+ */
477
+ export function sessionLatticeNextBarMs(profile, barMs, intervalMs) {
478
+ if (!Number.isFinite(barMs) || !isSessionLatticeIntervalMs(profile, intervalMs))
479
+ return null;
480
+ const stepMs = profile.intradayLatticeMs.has(intervalMs) ? sourceStepMs(profile, intervalMs) : HOUR_MS;
481
+ const reachMs = barMs + nextBarReachMs(profile, intervalMs);
482
+ for (let rowMs = floorTo(barMs, stepMs) + stepMs; rowMs <= reachMs; rowMs += stepMs) {
483
+ const stampMs = sessionLatticeBucketMs(profile, rowMs, intervalMs);
484
+ if (stampMs !== null && stampMs > barMs)
485
+ return stampMs;
486
+ }
487
+ return null;
488
+ }
@@ -40,13 +40,51 @@ export declare const US_OPTIONS_TRADING_DAY_ANCHOR: Readonly<TradingDayAnchor>;
40
40
  * 16:00, so their last quarter hour carries no rows.
41
41
  */
42
42
  export declare const US_OPTIONS_TRADING_DAY_TPO_TIME_RANGE: Readonly<TradingDayTpoTimeRange>;
43
+ /**
44
+ * Forex (FX_OTC): the trading day opens 17:00 America/New_York, read off the
45
+ * forex session lattice so the anchor and the live bar grid share one open.
46
+ * TPO has no wire projection here: the gateway's custom-time-range path takes
47
+ * a 17:00 -> 17:00 window (`detectCrossMidnight`: an end at or before the
48
+ * start is a cross-day session), but TPO is not offered on forex
49
+ * (tradfi.constants FOREX_EXCEPTION_INDICATORS), so the entry waits for it.
50
+ */
51
+ export declare const FX_TRADING_DAY_ANCHOR: Readonly<TradingDayAnchor>;
52
+ /**
53
+ * US stocks on intraday rows: the trading day opens 20:00 America/New_York,
54
+ * at the after-hours close. It is an evening open (openMinutes >= 720), so the
55
+ * day opening 20:00 on X is X+1's trading day and holds X+1's pre-market,
56
+ * regular session and after-hours. In EDT that boundary is 00:00Z, the UTC day
57
+ * exactly; in EST it is 01:00Z, so a winter evening's after-hours (19:00 to
58
+ * 20:00 New York) stays with its own day instead of opening the next one.
59
+ * Answered only through getTradingDayAnchor with a row interval below 12h
60
+ * (its doc says why). TPO has no wire projection for it
61
+ * (getTradingDayTpoTimeRange answers undefined) and passes no interval.
62
+ */
63
+ export declare const US_EQUITIES_TRADING_DAY_ANCHOR: Readonly<TradingDayAnchor>;
43
64
  export declare function isTradingDayAnchor(value: unknown): value is TradingDayAnchor;
44
65
  /**
45
66
  * The trading-day anchor for a symbol's exchange, or undefined for venues
46
67
  * that keep the legacy UTC-midnight day (all of crypto). This is the single
47
- * venue gate both TPO and the session volume profile consume.
68
+ * venue gate both TPO and the session volume profile consume. The CME family
69
+ * answers first by its governed set (the GLOBEX alias included), OPRA by its
70
+ * gate, and every venue the gateway rolls up on a session lattice (forex)
71
+ * answers the lattice's own open, so a venue added to the lattice table
72
+ * gains its anchor here without a new branch.
73
+ *
74
+ * A US stock (market-session.util `isUsEquityMarket`) answers
75
+ * US_EQUITIES_TRADING_DAY_ANCHOR only to a caller that passes its ROW
76
+ * interval, `rowIntervalMs`, finite and strictly between 0 and 12h:
77
+ * - A daily or longer row is a date label at 00:00Z, not an instant (in EST,
78
+ * 00:00Z Monday is 19:00 Sunday New York), so it keeps its UTC date.
79
+ * - A 12h row keeps the UTC date too: in EST the 12h UTC bucket starting
80
+ * 00:00Z spans 19:00 to 07:00 New York, one day's after-hours and the next
81
+ * day's pre-market, which no anchor can split. Every row from 1m to 8h sits
82
+ * inside one trading day under the 20:00 New York boundary.
83
+ * A caller that passes no interval (TPO, DOM, reference lines, session
84
+ * breaks, tape mode, the titan chart-level anchor, calendar weeks and months)
85
+ * keeps the UTC day on stocks, as before.
48
86
  */
49
- export declare function getTradingDayAnchor(exchange: string | undefined | null): TradingDayAnchor | undefined;
87
+ export declare function getTradingDayAnchor(exchange: string | undefined | null, rowIntervalMs?: number): TradingDayAnchor | undefined;
50
88
  export declare function tradingDayStartMs(tsMs: number, anchor: TradingDayAnchor): number;
51
89
  export type TradingDayPeriod = 'Session' | 'Week' | 'Month' | 'Year';
52
90
  /**
@@ -1,6 +1,6 @@
1
1
  /**
2
- * Trading-day anchoring for session venues (the CME family and the OPRA
3
- * options plane).
2
+ * Trading-day anchoring for session venues (the CME family, forex, the OPRA
3
+ * options plane, and US stocks on intraday rows).
4
4
  *
5
5
  * The FE owns all venue knowledge: titan-charts stays venue-agnostic and only
6
6
  * consumes the generic `tradingDayAnchor` descriptor this module produces
@@ -9,10 +9,18 @@
9
9
  * 17:00 America/Chicago
10
10
  * the prior evening, halts 16:00-17:00, so the "day" of Monday runs Sunday
11
11
  * 17:00 CT through Monday 16:00 CT; DST moves the UTC edge (22:00 UTC in
12
- * summer, 23:00 UTC in winter) and Sunday evening belongs to Monday. US
12
+ * summer, 23:00 UTC in winter) and Sunday evening belongs to Monday. Forex
13
+ * (FX_OTC) trades the 17:00 America/New_York day TradingView and MT4 cut on
14
+ * (21:00 UTC in summer, 22:00 UTC in winter), Sunday evening belongs to
15
+ * Monday, and tsdb-gateway serves its daily and weekly bars on it (!2483):
16
+ * the anchor is read off the forex session lattice (session-lattice.util),
17
+ * the same table the live writers key the forming bar with, so the dividers,
18
+ * the VWAP sessions and the daily bars can never roll on different days. US
13
19
  * equity and index options (OPRA) trade one session a day that opens 09:30
14
20
  * America/New_York (us-options-session.util), so their day is labeled by its
15
- * own calendar date.
21
+ * own calendar date. US stocks trade 04:00 to 20:00 America/New_York, so on
22
+ * intraday rows their day opens at the 20:00 after-hours close
23
+ * (US_EQUITIES_TRADING_DAY_ANCHOR, read only with a row interval).
16
24
  *
17
25
  * Consumers of the SAME anchor:
18
26
  * - Session volume profile passes it straight to titan, whose daily session
@@ -33,6 +41,8 @@ import dayjs from 'dayjs';
33
41
  import timezone from 'dayjs/plugin/timezone.js';
34
42
  import utc from 'dayjs/plugin/utc.js';
35
43
  import { isCmeGoverned } from './cme-realtime.util.js';
44
+ import { isUsEquityMarket } from './market-session.util.js';
45
+ import { FOREX_SESSION_LATTICE, sessionLatticeOf } from './session-lattice.util.js';
36
46
  import { isOpraGoverned } from '../v2/opra-governed.util.js';
37
47
  dayjs.extend(utc);
38
48
  dayjs.extend(timezone);
@@ -75,6 +85,51 @@ export const US_OPTIONS_TRADING_DAY_TPO_TIME_RANGE = Object.freeze({
75
85
  end_time: '16:15',
76
86
  timezone: 'America/New_York',
77
87
  });
88
+ /**
89
+ * Forex (FX_OTC): the trading day opens 17:00 America/New_York, read off the
90
+ * forex session lattice so the anchor and the live bar grid share one open.
91
+ * TPO has no wire projection here: the gateway's custom-time-range path takes
92
+ * a 17:00 -> 17:00 window (`detectCrossMidnight`: an end at or before the
93
+ * start is a cross-day session), but TPO is not offered on forex
94
+ * (tradfi.constants FOREX_EXCEPTION_INDICATORS), so the entry waits for it.
95
+ */
96
+ export const FX_TRADING_DAY_ANCHOR = Object.freeze({
97
+ timeZone: FOREX_SESSION_LATTICE.timeZone,
98
+ openMinutes: FOREX_SESSION_LATTICE.openHour * 60,
99
+ });
100
+ /**
101
+ * US stocks on intraday rows: the trading day opens 20:00 America/New_York,
102
+ * at the after-hours close. It is an evening open (openMinutes >= 720), so the
103
+ * day opening 20:00 on X is X+1's trading day and holds X+1's pre-market,
104
+ * regular session and after-hours. In EDT that boundary is 00:00Z, the UTC day
105
+ * exactly; in EST it is 01:00Z, so a winter evening's after-hours (19:00 to
106
+ * 20:00 New York) stays with its own day instead of opening the next one.
107
+ * Answered only through getTradingDayAnchor with a row interval below 12h
108
+ * (its doc says why). TPO has no wire projection for it
109
+ * (getTradingDayTpoTimeRange answers undefined) and passes no interval.
110
+ */
111
+ export const US_EQUITIES_TRADING_DAY_ANCHOR = Object.freeze({
112
+ timeZone: 'America/New_York',
113
+ openMinutes: 20 * 60,
114
+ });
115
+ /** A stock row strictly shorter than this takes the stock anchor; 12h and longer keep the UTC date. */
116
+ const US_EQUITIES_ANCHOR_ROW_CEILING_MS = 12 * 60 * 60 * 1000;
117
+ function isUsEquitiesAnchorRowInterval(rowIntervalMs) {
118
+ return (typeof rowIntervalMs === 'number' &&
119
+ Number.isFinite(rowIntervalMs) &&
120
+ rowIntervalMs > 0 &&
121
+ rowIntervalMs < US_EQUITIES_ANCHOR_ROW_CEILING_MS);
122
+ }
123
+ /** The anchor of a session lattice: the lattice's zone and open hour (session-lattice.util). */
124
+ function sessionLatticeTradingDayAnchor(lattice) {
125
+ if (lattice === FOREX_SESSION_LATTICE)
126
+ return FX_TRADING_DAY_ANCHOR;
127
+ if (lattice.timeZone === CME_TRADING_DAY_ANCHOR.timeZone &&
128
+ lattice.openHour * 60 === CME_TRADING_DAY_ANCHOR.openMinutes) {
129
+ return CME_TRADING_DAY_ANCHOR;
130
+ }
131
+ return Object.freeze({ timeZone: lattice.timeZone, openMinutes: lattice.openHour * 60 });
132
+ }
78
133
  export function isTradingDayAnchor(value) {
79
134
  if (!value || typeof value !== 'object')
80
135
  return false;
@@ -89,14 +144,36 @@ export function isTradingDayAnchor(value) {
89
144
  /**
90
145
  * The trading-day anchor for a symbol's exchange, or undefined for venues
91
146
  * that keep the legacy UTC-midnight day (all of crypto). This is the single
92
- * venue gate both TPO and the session volume profile consume.
147
+ * venue gate both TPO and the session volume profile consume. The CME family
148
+ * answers first by its governed set (the GLOBEX alias included), OPRA by its
149
+ * gate, and every venue the gateway rolls up on a session lattice (forex)
150
+ * answers the lattice's own open, so a venue added to the lattice table
151
+ * gains its anchor here without a new branch.
152
+ *
153
+ * A US stock (market-session.util `isUsEquityMarket`) answers
154
+ * US_EQUITIES_TRADING_DAY_ANCHOR only to a caller that passes its ROW
155
+ * interval, `rowIntervalMs`, finite and strictly between 0 and 12h:
156
+ * - A daily or longer row is a date label at 00:00Z, not an instant (in EST,
157
+ * 00:00Z Monday is 19:00 Sunday New York), so it keeps its UTC date.
158
+ * - A 12h row keeps the UTC date too: in EST the 12h UTC bucket starting
159
+ * 00:00Z spans 19:00 to 07:00 New York, one day's after-hours and the next
160
+ * day's pre-market, which no anchor can split. Every row from 1m to 8h sits
161
+ * inside one trading day under the 20:00 New York boundary.
162
+ * A caller that passes no interval (TPO, DOM, reference lines, session
163
+ * breaks, tape mode, the titan chart-level anchor, calendar weeks and months)
164
+ * keeps the UTC day on stocks, as before.
93
165
  */
94
- export function getTradingDayAnchor(exchange) {
166
+ export function getTradingDayAnchor(exchange, rowIntervalMs) {
95
167
  if (isCmeGoverned(exchange))
96
168
  return CME_TRADING_DAY_ANCHOR;
97
169
  if (isOpraGoverned(exchange))
98
170
  return US_OPTIONS_TRADING_DAY_ANCHOR;
99
- return undefined;
171
+ const lattice = sessionLatticeOf(exchange);
172
+ if (lattice !== null)
173
+ return sessionLatticeTradingDayAnchor(lattice);
174
+ return isUsEquitiesAnchorRowInterval(rowIntervalMs) && isUsEquityMarket(exchange)
175
+ ? US_EQUITIES_TRADING_DAY_ANCHOR
176
+ : undefined;
100
177
  }
101
178
  /** One wall-clock reader per zone (titan src/utils/tradingDay.ts's formatter); null for a zone Intl rejects. */
102
179
  const wallClockFormatters = new Map();