@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
@@ -1,26 +1,50 @@
1
- import dayjs from 'dayjs';
2
- import isoWeek from 'dayjs/plugin/isoWeek.js';
3
- import timezone from 'dayjs/plugin/timezone.js';
4
- import utc from 'dayjs/plugin/utc.js';
5
- import { zoneWallMsAt, zoneWallToUtcMs } from '../../utility/chart/ny-calendar.util.js';
1
+ import { MARKET_SESSION_SPLIT, marketSessionInstantsOn, marketSessionNamed, sessionClockText, zoneWallEdgeToUtcMs, } from '../../utility/chart/market-sessions.util.js';
2
+ import { marketSessionKind } from '../../utility/chart/market-session.util.js';
3
+ import { NY_TIME_ZONE, zoneOffsetMsAt, zoneWallMsAt } from '../../utility/chart/ny-calendar.util.js';
6
4
  import { getTradingDayAnchor, getTradingDayTpoTimeRange } from '../../utility/chart/trading-day.util.js';
7
- dayjs.extend(utc);
8
- dayjs.extend(isoWeek);
9
- dayjs.extend(timezone);
10
- export const TPO_TRADING_HOUR_TIME_RANGES = {
11
- 'Pre-Market': { start_time: '04:00', end_time: '09:30', timezone: 'ET' },
12
- Regular: { start_time: '09:30', end_time: '16:00', timezone: 'ET' },
13
- 'Post-Market': { start_time: '16:00', end_time: '20:00', timezone: 'ET' },
14
- Asia: { start_time: '00:00', end_time: '06:00', timezone: 'UTC' },
15
- 'Asia Full': { start_time: '00:00', end_time: '09:00', timezone: 'UTC' },
16
- London: { start_time: '06:00', end_time: '12:00', timezone: 'UTC' },
17
- 'London Full': { start_time: '08:00', end_time: '17:00', timezone: 'UTC' },
18
- 'New York': { start_time: '12:00', end_time: '20:00', timezone: 'UTC' },
19
- 'New York Full': { start_time: '08:00', end_time: '17:00', timezone: 'ET' },
20
- 'Pre-Close': { start_time: '20:00', end_time: '00:00', timezone: 'UTC' },
21
- 'All Hours': { start_time: '00:00', end_time: '00:00', timezone: 'UTC' },
22
- Custom: { start_time: '00:00', end_time: '00:00', timezone: 'UTC' },
23
- };
5
+ import { singleStockTapeVenue } from '../../utility/v2/stocks-governed.util.js';
6
+ /** A gateway TradingHour session's row: its hours on the gateway's own clock, its weeks and months on UTC. */
7
+ function gatewaySessionRange(start_time, end_time, timezone) {
8
+ return Object.freeze({ start_time, end_time, timezone, periodCalendar: 'UTC' });
9
+ }
10
+ /** The presets that are market sessions: hours from market-sessions.util, sent as a range, never a fixed-UTC enum. */
11
+ export const TPO_MARKET_SESSION_PRESETS = Object.freeze([
12
+ 'Asia',
13
+ 'Asia Full',
14
+ 'London',
15
+ 'London Full',
16
+ 'New York',
17
+ 'New York Full',
18
+ ]);
19
+ /** The zone a range names on the wire: New York as 'ET' (the gateway keys it apart from 'America/New_York'). */
20
+ function tpoWireTimezone(timeZone) {
21
+ return timeZone === NY_TIME_ZONE ? 'ET' : timeZone;
22
+ }
23
+ /** A market session preset's daily window, read from the shared session table, never written here. */
24
+ function marketSessionRange(name) {
25
+ const session = marketSessionNamed(name);
26
+ if (!session)
27
+ throw new Error(`TPO preset ${name} is not a market session`);
28
+ return Object.freeze({
29
+ start_time: sessionClockText(session.openMinutes),
30
+ end_time: sessionClockText(session.closeMinutes),
31
+ timezone: tpoWireTimezone(session.timeZone),
32
+ });
33
+ }
34
+ /** Every choice's daily window: the gateway's own sessions (BuildWhereTradingHour serves these rows), the markets'. */
35
+ export const TPO_TRADING_HOUR_TIME_RANGES = Object.freeze({
36
+ 'Pre-Market': gatewaySessionRange('04:00', '09:30', 'ET'),
37
+ Regular: gatewaySessionRange('09:30', '16:00', 'ET'),
38
+ 'Post-Market': gatewaySessionRange('16:00', '20:00', 'ET'),
39
+ ...Object.fromEntries(TPO_MARKET_SESSION_PRESETS.map((name) => [name, marketSessionRange(name)])),
40
+ 'Pre-Close': gatewaySessionRange('20:00', '00:00', 'UTC'),
41
+ 'All Hours': Object.freeze({ start_time: '00:00', end_time: '00:00', timezone: 'UTC' }),
42
+ Custom: Object.freeze({ start_time: '00:00', end_time: '00:00', timezone: 'UTC' }),
43
+ });
44
+ /** A range's wall times and clock alone, as the wire and the cache key carry it. */
45
+ export function tpoWireTimeRange(range) {
46
+ return { start_time: range.start_time, end_time: range.end_time, timezone: range.timezone };
47
+ }
24
48
  function parseTpoTimeToMinutes(value) {
25
49
  const match = String(value ?? '').match(/^(\d{1,2}):(\d{2})$/);
26
50
  if (!match)
@@ -42,10 +66,96 @@ function isTpoCrossDay(customTimeRange) {
42
66
  return false;
43
67
  return startMinutes >= endMinutes;
44
68
  }
45
- function getTpoCrossDayOffset(customTimeRange) {
69
+ /** Minutes past local midnight a period's first day opens at: a range crossing midnight keeps its spill-over night. */
70
+ function getTpoCrossDayOffsetMinutes(customTimeRange) {
46
71
  if (!customTimeRange || !isTpoCrossDay(customTimeRange))
47
72
  return 0;
48
- return (parseTpoTimeToMinutes(customTimeRange.end_time) ?? 0) * 60;
73
+ return parseTpoTimeToMinutes(customTimeRange.end_time) ?? 0;
74
+ }
75
+ /** "Chart session", every TPO's default: it names no window until tpoEffectiveTradingHour reads the chart's session. */
76
+ export const TPO_CHART_TRADING_HOUR = 'Chart';
77
+ /** The stamp every writer puts beside a stored choice: an All Hours without it is a row the old mounts filled unasked. */
78
+ export const TPO_TRADING_HOUR_VERSION = 2;
79
+ /** The trading-hour choice the settings hold: no choice (absent, null, empty) is 'Chart'; never a session to build on. */
80
+ export function tpoTradingHourOf(settings) {
81
+ const tradingHour = settings?.tradingHour;
82
+ if (typeof tradingHour !== 'string' || !tradingHour)
83
+ return TPO_CHART_TRADING_HOUR;
84
+ // The one legacy rule: every mount and form before the stamp wrote All Hours whether or not anyone picked it.
85
+ if (tradingHour === 'All Hours' && settings?.tradingHourVersion !== TPO_TRADING_HOUR_VERSION) {
86
+ return TPO_CHART_TRADING_HOUR;
87
+ }
88
+ return tradingHour;
89
+ }
90
+ /** A TPO's choice as its settings store it, 'Chart' as null: a JSON frame or a template keeps null and drops an absent key. */
91
+ export function tpoStoredTradingHour(settings) {
92
+ const name = tpoTradingHourOf(settings);
93
+ // Titan reads `tradingHour || 'All Hours'` for its label and merge key: null draws as the old default did.
94
+ return name === TPO_CHART_TRADING_HOUR ? null : name;
95
+ }
96
+ // Both vocabularies of the two TPO indicators: the registry key (settings.ovType) and the template overlay type.
97
+ const AGGREGATED_TPO_INDICATOR_TYPES = new Set([
98
+ 'AGGREGATED_TIME_PRICE_OPPORTUNITY',
99
+ 'AggregatedTimePriceOpportunity',
100
+ ]);
101
+ const TPO_INDICATOR_TYPES = new Set([
102
+ 'TIME_PRICE_OPPORTUNITY',
103
+ 'TimePriceOpportunity',
104
+ ...AGGREGATED_TPO_INDICATOR_TYPES,
105
+ ]);
106
+ /** Whether an indicator type names one of the two TPO indicators, in either vocabulary. */
107
+ export function isTpoIndicatorType(indicatorType) {
108
+ return typeof indicatorType === 'string' && TPO_INDICATOR_TYPES.has(indicatorType);
109
+ }
110
+ const SINGLE_VENUE_TPO_SESSION_RANGE = Object.freeze({});
111
+ const AGGREGATED_TPO_SESSION_RANGE = Object.freeze({ venueTradingDay: false });
112
+ /**
113
+ * The range options of a TPO type (either vocabulary), the one place its readers take them from: its fetch, its
114
+ * refetch decision, its live merge and its cache key all cut sessions with them, so its live sessions are its
115
+ * history's. The aggregated TPO sums venues whose trading days differ, so its All Hours is the UTC day; the
116
+ * single-venue TPO rides its venue's trading day.
117
+ */
118
+ export function tpoSessionRangeOptions(indicatorType) {
119
+ return typeof indicatorType === 'string' && AGGREGATED_TPO_INDICATOR_TYPES.has(indicatorType)
120
+ ? AGGREGATED_TPO_SESSION_RANGE
121
+ : SINGLE_VENUE_TPO_SESSION_RANGE;
122
+ }
123
+ /** Outside settings over a live TPO (an old template, an old peer): their own unstamped All Hours lands as 'Chart'. */
124
+ export function tpoIncomingTradingHour(indicatorType, incoming) {
125
+ if (!isTpoIndicatorType(indicatorType) || !incoming || typeof incoming !== 'object')
126
+ return incoming;
127
+ const own = incoming;
128
+ // Their own stamp decides, read before a merge hands them the live row's stamp.
129
+ if (own.tradingHour !== 'All Hours' || own.tradingHourVersion != null)
130
+ return incoming;
131
+ return { ...incoming, tradingHour: null, tradingHourVersion: TPO_TRADING_HOUR_VERSION };
132
+ }
133
+ /** An agent's TPO write (an add, a patch) is a deliberate pick, like a form's: the trading hour it names is stamped. */
134
+ export function tpoAgentTradingHour(indicatorType, settings) {
135
+ if (!isTpoIndicatorType(indicatorType) || !settings || typeof settings !== 'object')
136
+ return settings;
137
+ // A write that names no trading hour neither adds nor removes the stamp: the row keeps its choice as it was.
138
+ if (settings.tradingHour === undefined)
139
+ return settings;
140
+ return { ...settings, tradingHourVersion: TPO_TRADING_HOUR_VERSION };
141
+ }
142
+ /** The regular session of the market a TPO reads: an aggregated twin's one stocks tape (a sum has none), else its own. */
143
+ function tpoMarketSessionKind(settings) {
144
+ const venues = settings.meta?.exchanges;
145
+ if (venues !== undefined && venues !== null) {
146
+ const tape = singleStockTapeVenue(venues);
147
+ return tape ? marketSessionKind(tape, settings.symbol) : null;
148
+ }
149
+ return marketSessionKind(settings.exchange, settings.symbol);
150
+ }
151
+ /** THE session every TPO reader builds on: 'Chart' is Regular on a US stock under a US regular-hours chart, else All Hours. */
152
+ export function tpoEffectiveTradingHour(settings, chartRegularKind) {
153
+ const choice = tpoTradingHourOf(settings);
154
+ if (choice !== TPO_CHART_TRADING_HOUR)
155
+ return choice;
156
+ return chartRegularKind === 'us-equity' && settings && tpoMarketSessionKind(settings) === 'us-equity'
157
+ ? 'Regular'
158
+ : 'All Hours';
49
159
  }
50
160
  /**
51
161
  * The venue anchor these settings run on. It is venue knowledge, never
@@ -63,15 +173,18 @@ function resolveTpoTradingDayAnchor(settings) {
63
173
  }
64
174
  /**
65
175
  * The trading-day anchored time range that APPLIES to these settings, or
66
- * undefined. The anchor only shapes the default full-day case: an explicit
67
- * custom range, a non-'All Hours' trading hour, a non-Daily session type, or
68
- * active custom sessions each keep their existing behavior.
176
+ * undefined. The anchor only shapes the full-day case, an effective 'All
177
+ * Hours': any other trading hour, a non-Daily session type, or active custom
178
+ * sessions each keep their existing behavior. A range saved beside All Hours
179
+ * never displaces the venue's day: every save of the old form wrote the time
180
+ * rows it showed (00:00 to 00:00 UTC) beside the choice, so a saved range is
181
+ * no sign of a window anyone picked. 'Custom' is the one choice that carries
182
+ * its own window (a time row no preset matches turns into Custom).
69
183
  */
70
- export function resolveTradingDayTpoTimeRange(settings) {
71
- if (!settings || settings.customTimeRange)
184
+ export function resolveTradingDayTpoTimeRange(settings, chartRegularKind) {
185
+ if (!settings)
72
186
  return undefined;
73
- const tradingHour = typeof settings.tradingHour === 'string' ? settings.tradingHour : undefined;
74
- if (tradingHour && tradingHour !== 'All Hours')
187
+ if (tpoEffectiveTradingHour(settings, chartRegularKind) !== 'All Hours')
75
188
  return undefined;
76
189
  if ((settings.sessionType ?? 'Daily') !== 'Daily')
77
190
  return undefined;
@@ -79,175 +192,180 @@ export function resolveTradingDayTpoTimeRange(settings) {
79
192
  return undefined;
80
193
  return getTradingDayTpoTimeRange(resolveTpoTradingDayAnchor(settings));
81
194
  }
82
- /**
83
- * Precedence: explicit custom range, then the trading-day anchored range
84
- * (which itself yields to non-'All Hours' trading hours and custom
85
- * sessions), then the trading-hour preset table.
86
- */
87
- export function resolveTpoSettingsTimeRange(settings) {
88
- if (settings.customTimeRange)
89
- return settings.customTimeRange;
90
- const anchored = resolveTradingDayTpoTimeRange(settings);
91
- if (anchored)
92
- return anchored;
93
- const tradingHour = typeof settings.tradingHour === 'string' ? settings.tradingHour : undefined;
94
- if (!tradingHour)
95
- return undefined;
96
- return TPO_TRADING_HOUR_TIME_RANGES[tradingHour];
97
- }
98
- function timezoneName(value) {
99
- const raw = String(value || 'UTC');
100
- if (raw.toUpperCase() === 'ET')
101
- return 'America/New_York';
102
- return raw || 'UTC';
103
- }
104
- function unixInTimeZone(timestamp, zone) {
105
- try {
106
- return dayjs.unix(timestamp).tz(zone);
107
- }
108
- catch {
109
- return dayjs.unix(timestamp).utc();
195
+ /** A choice's window, venue day aside: a preset's table row (never the range saved beside it), else the saved range. */
196
+ export function tpoTradingHourTimeRange(tradingHour, savedRange) {
197
+ if (tradingHour !== 'Custom' && Object.prototype.hasOwnProperty.call(TPO_TRADING_HOUR_TIME_RANGES, tradingHour)) {
198
+ return TPO_TRADING_HOUR_TIME_RANGES[tradingHour];
110
199
  }
200
+ return savedRange && typeof savedRange === 'object' ? savedRange : undefined;
111
201
  }
112
- const zonedDayByZone = new Map();
113
- function zonedDayFor(timestamp, zone) {
114
- const cached = zonedDayByZone.get(zone);
115
- if (cached && timestamp >= cached.startUnix && timestamp < cached.endUnix)
116
- return cached;
117
- const dayStart = unixInTimeZone(timestamp, zone).startOf('day');
118
- const fresh = { dayStart, startUnix: dayStart.unix(), endUnix: dayStart.add(1, 'day').unix() };
119
- zonedDayByZone.set(zone, fresh);
120
- return fresh;
121
- }
122
- const WALL_TIME_MEMO_CAP = 512;
123
- const wallTimeUnixMemo = new Map();
124
202
  /**
125
- * The instant whose wall clock in `zone` reads `minutes` past midnight on
126
- * the calendar date `dayKey` ('YYYY-MM-DD'). Parsing the wall string with
127
- * dayjs.tz is DST-exact: `startOf('day').add(minutes, 'minute')` counts REAL
128
- * minutes, which drifts by the offset delta on 23h/25h transition days. For
129
- * UTC zones both agree.
203
+ * The one window a TPO cuts its sessions to, for every reader: All Hours the venue's trading day, a preset its table
204
+ * row, Custom its saved range. A range saved beside All Hours or a preset is the old form's echo of its time rows (a
205
+ * preset's old hours, All Hours' 00:00 to 00:00 UTC) and is never read.
130
206
  */
131
- function wallTimeOnDay(dayKey, minutes, zone) {
132
- const hours = String(Math.floor(minutes / 60)).padStart(2, '0');
133
- const mins = String(minutes % 60).padStart(2, '0');
134
- const wall = `${dayKey} ${hours}:${mins}`;
135
- try {
136
- return dayjs.tz(wall, zone);
137
- }
138
- catch {
139
- return dayjs.utc(wall);
207
+ export function resolveTpoSettingsTimeRange(settings, chartRegularKind, options = {}) {
208
+ const tradingHour = tpoEffectiveTradingHour(settings, chartRegularKind);
209
+ if (tradingHour !== 'All Hours')
210
+ return tpoTradingHourTimeRange(tradingHour, settings.customTimeRange);
211
+ return options.venueTradingDay === false ? undefined : resolveTradingDayTpoTimeRange(settings, chartRegularKind);
212
+ }
213
+ // Every regular session a chart can draw (none, CME's, the US stock market's).
214
+ const TPO_CHART_SESSIONS = [null, 'cme', 'us-equity'];
215
+ /** Whether two saves of one TPO ask another session on some chart: a save never knows its chart, so it asks each. */
216
+ export function tpoSessionAskChanged(next, prev, options = {}) {
217
+ return TPO_CHART_SESSIONS.some((chartRegularKind) => tpoEffectiveTradingHour(next, chartRegularKind) !== tpoEffectiveTradingHour(prev, chartRegularKind) ||
218
+ JSON.stringify(resolveTpoSettingsTimeRange(next, chartRegularKind, options) ?? null) !==
219
+ JSON.stringify(resolveTpoSettingsTimeRange(prev, chartRegularKind, options) ?? null));
220
+ }
221
+ /** The IANA zone a range's clock names: 'ET' is New York, nothing is UTC. */
222
+ export function tpoTimeZone(value) {
223
+ const raw = String(value || 'UTC');
224
+ return raw.toUpperCase() === 'ET' ? NY_TIME_ZONE : raw;
225
+ }
226
+ const servedZones = new Map();
227
+ /** The zone a range is read on: its own where the runtime's zone data knows it, else UTC (a bad saved zone). */
228
+ function servedTimeZone(value) {
229
+ const zone = tpoTimeZone(value);
230
+ let served = servedZones.get(zone);
231
+ if (served === undefined) {
232
+ try {
233
+ zoneOffsetMsAt(zone, 0);
234
+ served = zone;
235
+ }
236
+ catch {
237
+ served = 'UTC';
238
+ }
239
+ if (servedZones.size >= 64)
240
+ servedZones.clear();
241
+ servedZones.set(zone, served);
140
242
  }
243
+ return served;
141
244
  }
142
- /** `wallTimeOnDay(...).unix()`, memoised per (day, minutes, zone): the same few wall times are asked every tick. */
143
- function wallTimeUnixOnDay(dayKey, minutes, zone) {
144
- const key = `${dayKey}|${minutes}|${zone}`;
145
- const hit = wallTimeUnixMemo.get(key);
146
- if (hit !== undefined)
147
- return hit;
148
- const value = wallTimeOnDay(dayKey, minutes, zone).unix();
149
- if (wallTimeUnixMemo.size >= WALL_TIME_MEMO_CAP)
150
- wallTimeUnixMemo.clear();
151
- wallTimeUnixMemo.set(key, value);
152
- return value;
153
- }
245
+ const MINUTE_MS = 60_000;
154
246
  const DAY_MS = 86_400_000;
155
- const pad = (value, width) => String(value).padStart(width, '0');
156
- /**
157
- * The 'YYYY-MM-DD' key of the `zone` calendar date after the one holding
158
- * `timestamp` (unix seconds), as `unixInTimeZone(...).startOf('day').add(1, 'day')`
159
- * formats it, from the zone clock (ny-calendar.util: one Intl reading per UTC
160
- * day). An unknown zone reads UTC, as `unixInTimeZone` does; dayjs reads the
161
- * instants the zone clock does not serve. The day cache is left alone: its
162
- * last-day span is the one `resolveTpoTimeRangeWindow` answers from.
163
- */
164
- function nextZoneDateKey(timestamp, zone) {
247
+ /** A range's hours as a session on its own clock (open, close, zone); undefined for times that do not parse. */
248
+ function tpoRangeSession(range) {
249
+ if (!range)
250
+ return undefined;
251
+ const openMinutes = parseTpoTimeToMinutes(range.start_time);
252
+ const closeMinutes = parseTpoTimeToMinutes(range.end_time);
253
+ if (openMinutes === undefined || closeMinutes === undefined)
254
+ return undefined;
255
+ return { timeZone: servedTimeZone(range.timezone), openMinutes, closeMinutes };
256
+ }
257
+ /** `zone`'s wall clock at `ms` as a UTC-shaped epoch; the instant itself where the zone clock serves none. */
258
+ function zoneWallMsOr(zone, ms) {
259
+ if (zone === 'UTC')
260
+ return ms;
165
261
  let wallMs;
166
262
  try {
167
- wallMs = zoneWallMsAt(zone, timestamp * 1000);
263
+ wallMs = zoneWallMsAt(zone, ms);
168
264
  }
169
265
  catch {
170
- wallMs = timestamp * 1000;
266
+ wallMs = Number.NaN;
171
267
  }
172
- if (Number.isNaN(wallMs))
173
- return unixInTimeZone(timestamp, zone).startOf('day').add(1, 'day').format('YYYY-MM-DD');
174
- const next = new Date(Math.floor(wallMs / DAY_MS) * DAY_MS + DAY_MS);
175
- return `${pad(next.getUTCFullYear(), 4)}-${pad(next.getUTCMonth() + 1, 2)}-${pad(next.getUTCDate(), 2)}`;
268
+ return Number.isNaN(wallMs) ? ms : wallMs;
176
269
  }
177
- export function resolveTpoTimeRangeWindow(timestamp, customTimeRange) {
178
- if (!customTimeRange)
179
- return undefined;
180
- const startMinutes = parseTpoTimeToMinutes(customTimeRange.start_time);
181
- const endMinutes = parseTpoTimeToMinutes(customTimeRange.end_time);
182
- if (startMinutes === undefined || endMinutes === undefined)
183
- return undefined;
184
- const zone = timezoneName(customTimeRange.timezone);
185
- // Cached zoned day plus memoised wall times: the same instants as the
186
- // per-call dayjs chain, compared as unix seconds (`isBefore` on instants).
187
- const { dayStart } = zonedDayFor(timestamp, zone);
188
- const dayKey = dayStart.format('YYYY-MM-DD');
189
- const previousDay = dayStart.subtract(1, 'day');
190
- const nextDay = dayStart.add(1, 'day');
191
- const previousKey = previousDay.format('YYYY-MM-DD');
192
- const nextKey = nextDay.format('YYYY-MM-DD');
193
- const startToday = wallTimeUnixOnDay(dayKey, startMinutes, zone);
194
- const endToday = wallTimeUnixOnDay(dayKey, endMinutes, zone);
195
- if (startMinutes === endMinutes) {
196
- const crossesIntoToday = timestamp < startToday;
197
- const start = crossesIntoToday ? wallTimeUnixOnDay(previousKey, startMinutes, zone) : startToday;
198
- const end = crossesIntoToday ? startToday : wallTimeUnixOnDay(nextKey, startMinutes, zone);
199
- return { startSec: start, endSec: end, fullSession: true };
270
+ /** The session's [open, close) in unix seconds on the local day `dayWallMs`, each edge read on its own date. */
271
+ function sessionInstantsSec(session, dayWallMs) {
272
+ const [openMs, closeMs] = session.timeZone === 'UTC' ? [Number.NaN, Number.NaN] : marketSessionInstantsOn(session, dayWallMs);
273
+ if (Number.isNaN(openMs) || Number.isNaN(closeMs)) {
274
+ const closeDayMs = session.closeMinutes <= session.openMinutes ? dayWallMs + DAY_MS : dayWallMs;
275
+ return [
276
+ Math.floor((dayWallMs + session.openMinutes * MINUTE_MS) / 1000),
277
+ Math.floor((closeDayMs + session.closeMinutes * MINUTE_MS) / 1000),
278
+ ];
279
+ }
280
+ return [Math.floor(openMs / 1000), Math.floor(closeMs / 1000)];
281
+ }
282
+ /** The local calendar day holding `timestamp` (unix seconds) on `zone`'s clock, as its midnight's UTC-shaped epoch. */
283
+ function zoneDayWallMs(zone, timestamp) {
284
+ return Math.floor(zoneWallMsOr(zone, timestamp * 1000) / DAY_MS) * DAY_MS;
285
+ }
286
+ /** The window holding `timestamp` and the local day it opened on. */
287
+ function tpoWindowOn(timestamp, session) {
288
+ const dayWallMs = zoneDayWallMs(session.timeZone, timestamp);
289
+ const [startToday, endToday] = sessionInstantsSec(session, dayWallMs);
290
+ const fullSession = session.openMinutes === session.closeMinutes;
291
+ if (session.openMinutes < session.closeMinutes) {
292
+ return { window: { startSec: startToday, endSec: endToday, fullSession }, openDayWallMs: dayWallMs };
200
293
  }
201
- if (startMinutes < endMinutes) {
202
- return { startSec: startToday, endSec: endToday, fullSession: false };
294
+ // Crossing midnight: before today's open, yesterday's session holds the timestamp while it is still open.
295
+ const [startYesterday, endYesterday] = sessionInstantsSec(session, dayWallMs - DAY_MS);
296
+ if (timestamp < (fullSession ? startToday : endYesterday)) {
297
+ return {
298
+ window: { startSec: startYesterday, endSec: endYesterday, fullSession },
299
+ openDayWallMs: dayWallMs - DAY_MS,
300
+ };
203
301
  }
204
- const isPostMidnightContinuation = timestamp < endToday;
205
- const start = isPostMidnightContinuation ? wallTimeUnixOnDay(previousKey, startMinutes, zone) : startToday;
206
- const end = isPostMidnightContinuation ? endToday : wallTimeUnixOnDay(nextKey, endMinutes, zone);
207
- return { startSec: start, endSec: end, fullSession: false };
302
+ return { window: { startSec: startToday, endSec: endToday, fullSession }, openDayWallMs: dayWallMs };
303
+ }
304
+ /** The daily window `timestamp` reads, on the range's own zone clock: device-independent, daylight saving included. */
305
+ export function resolveTpoTimeRangeWindow(timestamp, customTimeRange) {
306
+ const session = tpoRangeSession(customTimeRange);
307
+ return session ? tpoWindowOn(timestamp, session).window : undefined;
208
308
  }
209
309
  export function containsTpoWindowTime(timestamp, window) {
210
310
  return timestamp >= window.startSec && timestamp < window.endSec;
211
311
  }
312
+ /** The first local day of the day, ISO week (Monday) or month holding the local day `dayWallMs`. */
313
+ function periodFirstDayWallMs(dayWallMs, sessionType) {
314
+ const day = new Date(dayWallMs);
315
+ if (sessionType === 'Weekly')
316
+ return dayWallMs - ((day.getUTCDay() + 6) % 7) * DAY_MS;
317
+ if (sessionType === 'Monthly')
318
+ return Date.UTC(day.getUTCFullYear(), day.getUTCMonth(), 1);
319
+ return dayWallMs;
320
+ }
321
+ /** The first local day of the next day, ISO week or month after the one opening on `firstDayWallMs`. */
322
+ function nextPeriodFirstDayWallMs(firstDayWallMs, sessionType) {
323
+ if (sessionType === 'Weekly')
324
+ return firstDayWallMs + 7 * DAY_MS;
325
+ if (sessionType === 'Monthly') {
326
+ const day = new Date(firstDayWallMs);
327
+ return Date.UTC(day.getUTCFullYear(), day.getUTCMonth() + 1, 1);
328
+ }
329
+ return firstDayWallMs + DAY_MS;
330
+ }
331
+ /**
332
+ * The instant (unix seconds) a window edge `wallMs` means on `zone`'s clock, by the one edge rule
333
+ * (market-sessions.util zoneWallEdgeToUtcMs): a wall time the clock skips opens at the change itself, a repeated one
334
+ * at its first occurrence. The wall time read as UTC where the zone clock serves no reading.
335
+ */
336
+ function zoneWallInstantSec(zone, wallMs) {
337
+ const ms = zoneWallEdgeToUtcMs(zone, wallMs);
338
+ return Math.floor((Number.isNaN(ms) ? wallMs : ms) / 1000);
339
+ }
340
+ /** The day, week or month holding `timestamp` on the range's own calendar, from its close if it crosses midnight. */
341
+ function tpoCalendarPeriodSec(timestamp, sessionType, range) {
342
+ const zone = !range || range.periodCalendar === 'UTC' ? 'UTC' : servedTimeZone(range.timezone);
343
+ const offsetMs = getTpoCrossDayOffsetMinutes(range) * MINUTE_MS;
344
+ const shiftedDayWallMs = Math.floor((zoneWallMsOr(zone, timestamp * 1000) - offsetMs) / DAY_MS) * DAY_MS;
345
+ const firstDayWallMs = periodFirstDayWallMs(shiftedDayWallMs, sessionType);
346
+ return [
347
+ zoneWallInstantSec(zone, firstDayWallMs + offsetMs),
348
+ zoneWallInstantSec(zone, nextPeriodFirstDayWallMs(firstDayWallMs, sessionType) + offsetMs),
349
+ ];
350
+ }
212
351
  export function getTpoSessionStart(timestamp, sessionType, customTimeRange) {
213
- const timeWindow = resolveTpoTimeRangeWindow(timestamp, customTimeRange);
214
- if (sessionType === 'Daily' && timeWindow)
215
- return timeWindow.startSec;
216
- const date = dayjs.unix(timestamp).utc();
217
- const offset = getTpoCrossDayOffset(customTimeRange);
218
- switch (sessionType) {
219
- case 'Weekly':
220
- return date.startOf('isoWeek').unix() + offset;
221
- case 'Monthly':
222
- return date.startOf('month').unix() + offset;
223
- case 'Daily':
224
- default:
225
- return date.startOf('day').unix() + offset;
352
+ if (sessionType === 'Daily' || !(sessionType === 'Weekly' || sessionType === 'Monthly')) {
353
+ const session = tpoRangeSession(customTimeRange);
354
+ if (session)
355
+ return tpoWindowOn(timestamp, session).window.startSec;
356
+ return tpoCalendarPeriodSec(timestamp, 'Daily', customTimeRange)[0];
226
357
  }
358
+ return tpoCalendarPeriodSec(timestamp, sessionType, customTimeRange)[0];
227
359
  }
228
360
  export function getNextTpoSessionStart(timestamp, sessionType, customTimeRange) {
229
- const timeWindow = resolveTpoTimeRangeWindow(timestamp, customTimeRange);
230
- if (sessionType === 'Daily' && timeWindow) {
231
- // The next session opens at the window's start wall time on the next
232
- // wall day, computed wall-exactly: a flat +24h drifts by an hour across
233
- // DST transitions (23h/25h days). The date from the zone clock and the
234
- // instant from the window's own wall-time memo: the TPO folds ask once
235
- // per period, where three dayjs conversions ran each time.
236
- const zone = timezoneName(customTimeRange?.timezone);
237
- const startMinutes = parseTpoTimeToMinutes(customTimeRange?.start_time) ?? 0;
238
- return wallTimeUnixOnDay(nextZoneDateKey(timeWindow.startSec, zone), startMinutes, zone);
239
- }
240
- const date = dayjs.unix(timestamp).utc();
241
- const offset = getTpoCrossDayOffset(customTimeRange);
242
- switch (sessionType) {
243
- case 'Weekly':
244
- return date.add(1, 'week').startOf('isoWeek').unix() + offset;
245
- case 'Monthly':
246
- return date.add(1, 'month').startOf('month').unix() + offset;
247
- case 'Daily':
248
- default:
249
- return date.add(1, 'day').startOf('day').unix() + offset;
361
+ if (sessionType === 'Daily' || !(sessionType === 'Weekly' || sessionType === 'Monthly')) {
362
+ const session = tpoRangeSession(customTimeRange);
363
+ // The next local day's open, read on that date: a flat +24h drifts an hour across a clock change.
364
+ if (session)
365
+ return sessionInstantsSec(session, tpoWindowOn(timestamp, session).openDayWallMs + DAY_MS)[0];
366
+ return tpoCalendarPeriodSec(timestamp, 'Daily', customTimeRange)[1];
250
367
  }
368
+ return tpoCalendarPeriodSec(timestamp, sessionType, customTimeRange)[1];
251
369
  }
252
370
  function formatTpoLetter(index) {
253
371
  if (!Number.isInteger(index) || index < 0) {
@@ -277,14 +395,24 @@ function formatTpoLetter(index) {
277
395
  export function generateTpoLetters(blockIds, _sessionType, _tpoBlockSizeMinutes) {
278
396
  return blockIds.map(formatTpoLetter);
279
397
  }
280
- /** Editable starting template (Asia / London / New York / Close, UTC) — a
281
- * default for the editor, never a hard-coded behavior. */
282
- export const DEFAULT_TPO_CUSTOM_SESSION_SEGMENTS = [
283
- { label: 'Asia', start: '00:00', end: '06:00', color: '#4f8cff' },
284
- { label: 'London', start: '06:00', end: '12:00', color: '#22c39b' },
285
- { label: 'New York', start: '12:00', end: '20:00', color: '#f2a33c' },
286
- { label: 'Close', start: '20:00', end: '00:00', color: '#a06bff' },
287
- ];
398
+ /** Each slice of the day split's colour (Asia, London and New York keep the colours their sessions always had). */
399
+ const SPLIT_SEGMENT_COLORS = Object.freeze({
400
+ asia: '#4f8cff',
401
+ london: '#22c39b',
402
+ newYork: '#f2a33c',
403
+ afterHours: '#a06bff',
404
+ });
405
+ /** The editor's starting set: the day split's slices on its clock, named by `labelOf`; hours from the split only. */
406
+ export function defaultTpoCustomSessionSegments(labelOf) {
407
+ return MARKET_SESSION_SPLIT.slices.map((slice) => ({
408
+ label: labelOf(slice.id),
409
+ start: sessionClockText(slice.startMinutes),
410
+ end: sessionClockText(slice.endMinutes),
411
+ color: SPLIT_SEGMENT_COLORS[slice.id],
412
+ }));
413
+ }
414
+ /** The starting set's clock, the split's own: New York, stored as 'ET'. */
415
+ export const DEFAULT_TPO_CUSTOM_SESSIONS_TIMEZONE = tpoCustomSessionsTimezoneOf(MARKET_SESSION_SPLIT.timeZone);
288
416
  const MINUTES_PER_DAY = 1440;
289
417
  const SECONDS_PER_DAY = 86_400;
290
418
  function parseTpoSegmentEndToMinutes(value) {
@@ -310,7 +438,7 @@ export function normalizeTpoCustomSessionSegments(value, timezone) {
310
438
  if (!Array.isArray(value) || value.length === 0)
311
439
  return null;
312
440
  const clock = tpoCustomSessionsTimezoneOf(timezone);
313
- const zone = timezoneName(clock);
441
+ const zone = tpoTimeZone(clock);
314
442
  const parsed = [];
315
443
  for (const raw of value) {
316
444
  if (!raw || typeof raw !== 'object')
@@ -401,60 +529,10 @@ function toTpoCustomSessionWindow(segment, startDaySec) {
401
529
  color: segment.color,
402
530
  };
403
531
  }
404
- const MS_PER_MINUTE = 60_000;
405
- /** `zone`'s wall clock at `ms` as a UTC-shaped epoch; the instant itself where the zone clock serves none. */
406
- function zoneWallMsOr(zone, ms) {
407
- let wallMs;
408
- try {
409
- wallMs = zoneWallMsAt(zone, ms);
410
- }
411
- catch {
412
- wallMs = Number.NaN;
413
- }
414
- return Number.isNaN(wallMs) ? ms : wallMs;
415
- }
416
- /**
417
- * The instant (unix seconds) `zone`'s wall clock reads `wallMs`; the wall reading itself where the clock serves none.
418
- * A wall time the clock skips (the spring-forward hour) opens at the first instant reading at or after it, the change
419
- * itself: the solver settles a skipped time on an instant reading earlier, and a session start read that way would
420
- * open before the instant asked from (a walk over starts would stall on it).
421
- */
422
- function zoneWallInstantSec(zone, wallMs) {
423
- let ms;
424
- try {
425
- ms = zoneWallToUtcMs(zone, wallMs);
426
- }
427
- catch {
428
- ms = Number.NaN;
429
- }
430
- if (Number.isNaN(ms))
431
- return Math.floor(wallMs / 1000);
432
- const readMs = zoneWallMsOr(zone, ms);
433
- return Math.floor((readMs === wallMs ? ms : firstInstantReadingAtLeast(zone, wallMs, ms, readMs)) / 1000);
434
- }
435
- /**
436
- * The first whole second whose `zone` wall reading is at least `wallMs`, for a skipped wall time: `ms` (reading
437
- * `readMs`) sits on one side of the skipped span and the instant one span away on the other, so a bisection between
438
- * them lands on the change. `ms` itself when the far side reads no later (no skipped span after all).
439
- */
440
- function firstInstantReadingAtLeast(zone, wallMs, ms, readMs) {
441
- let low = readMs < wallMs ? ms : ms - (readMs - wallMs);
442
- let high = readMs < wallMs ? ms + (wallMs - readMs) : ms;
443
- if (!(zoneWallMsOr(zone, high) >= wallMs) || zoneWallMsOr(zone, low) >= wallMs)
444
- return ms;
445
- for (let step = 0; step < 64 && high - low > 1000; step += 1) {
446
- const mid = low + Math.floor((high - low) / 2000) * 1000;
447
- if (zoneWallMsOr(zone, mid) >= wallMs)
448
- high = mid;
449
- else
450
- low = mid;
451
- }
452
- return high;
453
- }
454
532
  function zonedTpoCustomSessionWindow(segment, dayWallMs, zone) {
455
533
  return {
456
- startSec: zoneWallInstantSec(zone, dayWallMs + segment.startMinute * MS_PER_MINUTE),
457
- endSec: zoneWallInstantSec(zone, dayWallMs + segment.endMinute * MS_PER_MINUTE),
534
+ startSec: zoneWallInstantSec(zone, dayWallMs + segment.startMinute * MINUTE_MS),
535
+ endSec: zoneWallInstantSec(zone, dayWallMs + segment.endMinute * MINUTE_MS),
458
536
  index: segment.index,
459
537
  label: segment.label,
460
538
  color: segment.color,
@@ -464,10 +542,10 @@ function zonedTpoCustomSessionWindow(segment, dayWallMs, zone) {
464
542
  * date, each edge converted on its own date, so a session keeps its wall
465
543
  * hours across daylight saving (the 23 and 25 hour days included). */
466
544
  function newYorkTpoCustomSessionDay(timestamp, segments) {
467
- const zone = segments[0].zone || timezoneName('ET');
545
+ const zone = segments[0].zone || tpoTimeZone('ET');
468
546
  const wallMs = zoneWallMsOr(zone, timestamp * 1000);
469
547
  const dayWallMs = Math.floor(wallMs / DAY_MS) * DAY_MS;
470
- return { zone, dayWallMs, minuteOfDay: (wallMs - dayWallMs) / MS_PER_MINUTE };
548
+ return { zone, dayWallMs, minuteOfDay: (wallMs - dayWallMs) / MINUTE_MS };
471
549
  }
472
550
  /** The segment window containing `timestamp` (unix seconds), or null when
473
551
  * the timestamp falls in a gap between segments. Segments read on their
@@ -487,7 +565,7 @@ export function getTpoCustomSessionWindow(timestamp, segments) {
487
565
  }
488
566
  return null;
489
567
  }
490
- const dayStart = dayjs.unix(timestamp).utc().startOf('day').unix();
568
+ const dayStart = Math.floor(timestamp / SECONDS_PER_DAY) * SECONDS_PER_DAY;
491
569
  const minuteOfDay = Math.floor((timestamp - dayStart) / 60);
492
570
  // The post-midnight tail of the wrapping segment (always the last one)
493
571
  // belongs to the session that opened the previous day.
@@ -514,7 +592,7 @@ export function getNextTpoCustomSessionStart(timestamp, segments) {
514
592
  for (const segment of segments) {
515
593
  if (day === 0 && segment.startMinute <= minuteOfDay)
516
594
  continue;
517
- const startSec = zoneWallInstantSec(zone, dayWallMs + day * DAY_MS + segment.startMinute * MS_PER_MINUTE);
595
+ const startSec = zoneWallInstantSec(zone, dayWallMs + day * DAY_MS + segment.startMinute * MINUTE_MS);
518
596
  if (startSec > timestamp)
519
597
  return startSec;
520
598
  }
@@ -522,7 +600,7 @@ export function getNextTpoCustomSessionStart(timestamp, segments) {
522
600
  // Unreachable while the zone clock serves (the next day's first start lies a day ahead); still a step forward.
523
601
  return Math.floor(timestamp) + SECONDS_PER_DAY;
524
602
  }
525
- const dayStart = dayjs.unix(timestamp).utc().startOf('day').unix();
603
+ const dayStart = Math.floor(timestamp / SECONDS_PER_DAY) * SECONDS_PER_DAY;
526
604
  const minuteOfDay = (timestamp - dayStart) / 60;
527
605
  for (const segment of segments) {
528
606
  if (segment.startMinute > minuteOfDay)