@orangecharts/wrun-chart-host 0.2.0 → 0.4.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 (342) hide show
  1. package/README.md +22 -8
  2. package/dist/constants/common.constants.d.ts +15 -0
  3. package/dist/constants/common.constants.js +23 -0
  4. package/dist/constants/data-source.constants.d.ts +1 -0
  5. package/dist/constants/data-source.constants.js +1 -0
  6. package/dist/constants/economic.constants.d.ts +39 -0
  7. package/dist/constants/economic.constants.js +77 -0
  8. package/dist/constants/etf-covered-coins.constants.d.ts +1 -0
  9. package/dist/constants/etf-covered-coins.constants.js +9 -0
  10. package/dist/constants/feature-flags.constants.d.ts +60 -0
  11. package/dist/constants/feature-flags.constants.js +308 -0
  12. package/dist/constants/feature-limits.constants.d.ts +134 -0
  13. package/dist/constants/feature-limits.constants.js +155 -0
  14. package/dist/constants/marketCapabilities.constants.d.ts +87 -0
  15. package/dist/constants/marketCapabilities.constants.js +213 -0
  16. package/dist/constants/option-venues.constants.d.ts +100 -0
  17. package/dist/constants/option-venues.constants.js +167 -0
  18. package/dist/constants/overlay-data.constants.d.ts +53 -0
  19. package/dist/constants/overlay-data.constants.js +80 -0
  20. package/dist/constants/pane-grid.constants.d.ts +15 -0
  21. package/dist/constants/pane-grid.constants.js +17 -0
  22. package/dist/constants/scriptEditor/builtin-script-snippets.d.ts +133 -0
  23. package/dist/constants/scriptEditor/builtin-script-snippets.js +451 -0
  24. package/dist/constants/venue-presets.constants.d.ts +10 -0
  25. package/dist/constants/venue-presets.constants.js +22 -0
  26. package/dist/enums/chart.enum.d.ts +68 -0
  27. package/dist/enums/chart.enum.js +70 -0
  28. package/dist/helpers/data.helpers.d.ts +2 -0
  29. package/dist/helpers/data.helpers.js +14 -0
  30. package/dist/host-env.d.ts +163 -5
  31. package/dist/host-ports.types.d.ts +431 -0
  32. package/dist/host-ports.types.js +1 -0
  33. package/dist/index.d.ts +138 -0
  34. package/dist/index.js +138 -0
  35. package/dist/indicators/controls/technical-script/technical-script-input-rendering.d.ts +86 -0
  36. package/dist/indicators/controls/technical-script/technical-script-input-rendering.js +179 -0
  37. package/dist/interfaces/asset-venue.interface.d.ts +91 -0
  38. package/dist/interfaces/asset-venue.interface.js +1 -0
  39. package/dist/interfaces/cancel-reason.interface.d.ts +24 -0
  40. package/dist/interfaces/cancel-reason.interface.js +2 -0
  41. package/dist/interfaces/catalog-display.interface.d.ts +3 -0
  42. package/dist/interfaces/catalog-display.interface.js +1 -0
  43. package/dist/interfaces/cme-realtime.interface.d.ts +251 -0
  44. package/dist/interfaces/cme-realtime.interface.js +46 -0
  45. package/dist/interfaces/feed.interface.d.ts +80 -0
  46. package/dist/interfaces/feed.interface.js +7 -0
  47. package/dist/interfaces/market-kind.interface.d.ts +8 -0
  48. package/dist/interfaces/market-kind.interface.js +1 -0
  49. package/dist/interfaces/opra-realtime.interface.d.ts +224 -0
  50. package/dist/interfaces/opra-realtime.interface.js +105 -0
  51. package/dist/interfaces/option-instrument.interface.d.ts +32 -0
  52. package/dist/interfaces/option-instrument.interface.js +1 -0
  53. package/dist/interfaces/options-chain-scope.interface.d.ts +29 -0
  54. package/dist/interfaces/options-chain-scope.interface.js +7 -0
  55. package/dist/interfaces/prediction-market.interface.d.ts +88 -0
  56. package/dist/interfaces/prediction-market.interface.js +8 -0
  57. package/dist/interfaces/wrun-runtime.interface.d.ts +5 -0
  58. package/dist/kscript-data/controls/live-trades-merge.util.d.ts +185 -0
  59. package/dist/kscript-data/controls/live-trades-merge.util.js +357 -0
  60. package/dist/settings-templates/frvp-fields.d.ts +27 -0
  61. package/dist/settings-templates/frvp-fields.js +108 -0
  62. package/dist/settings-templates/index.d.ts +119 -0
  63. package/dist/settings-templates/index.js +442 -0
  64. package/dist/settings-templates/indicator-fields.d.ts +56 -0
  65. package/dist/settings-templates/indicator-fields.js +793 -0
  66. package/dist/settings-templates/tool-rules.d.ts +59 -0
  67. package/dist/settings-templates/tool-rules.js +49 -0
  68. package/dist/settings-templates/tool-tables.generated.d.ts +2 -0
  69. package/dist/settings-templates/tool-tables.generated.js +1668 -0
  70. package/dist/utility/blk-market.util.d.ts +5 -0
  71. package/dist/utility/blk-market.util.js +12 -0
  72. package/dist/utility/chart/chart-load-phase.util.d.ts +32 -0
  73. package/dist/utility/chart/chart-load-phase.util.js +78 -0
  74. package/dist/utility/chart/cme-cache-context.util.d.ts +108 -0
  75. package/dist/utility/chart/cme-cache-context.util.js +166 -0
  76. package/dist/utility/chart/cme-session-bucket.util.d.ts +82 -0
  77. package/dist/utility/chart/cme-session-bucket.util.js +343 -0
  78. package/dist/utility/chart/cme-trade-calendar.util.d.ts +26 -0
  79. package/dist/utility/chart/cme-trade-calendar.util.js +147 -0
  80. package/dist/utility/chart/continuous-contracts.util.d.ts +138 -0
  81. package/dist/utility/chart/continuous-contracts.util.js +374 -0
  82. package/dist/utility/chart/date-labelled-interval.leaf.d.ts +15 -0
  83. package/dist/utility/chart/date-labelled-interval.leaf.js +19 -0
  84. package/dist/utility/chart/feed-interval.util.d.ts +119 -0
  85. package/dist/utility/chart/feed-interval.util.js +321 -0
  86. package/dist/utility/chart/fetch-dedupe-policy.util.d.ts +110 -0
  87. package/dist/utility/chart/fetch-dedupe-policy.util.js +407 -0
  88. package/dist/utility/chart/footprint-band.util.d.ts +76 -0
  89. package/dist/utility/chart/footprint-band.util.js +205 -0
  90. package/dist/utility/chart/footprint-cell-identity.util.d.ts +82 -0
  91. package/dist/utility/chart/footprint-cell-identity.util.js +346 -0
  92. package/dist/utility/chart/formula-calendar.util.d.ts +27 -0
  93. package/dist/utility/chart/formula-calendar.util.js +59 -0
  94. package/dist/utility/chart/history-wall.util.d.ts +67 -0
  95. package/dist/utility/chart/history-wall.util.js +87 -0
  96. package/dist/utility/chart/index-mode.util.d.ts +66 -0
  97. package/dist/utility/chart/index-mode.util.js +360 -0
  98. package/dist/utility/chart/indicator-coverage-planner.util.d.ts +217 -0
  99. package/dist/utility/chart/indicator-coverage-planner.util.js +443 -0
  100. package/dist/utility/chart/indicator-coverage-state.util.d.ts +33 -0
  101. package/dist/utility/chart/indicator-coverage-state.util.js +110 -0
  102. package/dist/utility/chart/indicator-gap-detector.util.d.ts +127 -0
  103. package/dist/utility/chart/indicator-gap-detector.util.js +260 -0
  104. package/dist/utility/chart/indicator-gap-repair.util.d.ts +88 -0
  105. package/dist/utility/chart/indicator-gap-repair.util.js +177 -0
  106. package/dist/utility/chart/indicator-inflight-registry.util.d.ts +26 -0
  107. package/dist/utility/chart/indicator-inflight-registry.util.js +254 -0
  108. package/dist/utility/chart/indicator-run-interval.util.d.ts +130 -0
  109. package/dist/utility/chart/indicator-run-interval.util.js +268 -0
  110. package/dist/utility/chart/interval-registry.util.d.ts +23 -0
  111. package/dist/utility/chart/interval-registry.util.js +83 -0
  112. package/dist/utility/chart/kscript-main-grid-stages.util.d.ts +21 -0
  113. package/dist/utility/chart/kscript-main-grid-stages.util.js +332 -0
  114. package/dist/utility/chart/legacy-exchange.leaf.d.ts +11 -0
  115. package/dist/utility/chart/legacy-exchange.leaf.js +43 -0
  116. package/dist/utility/chart/live-bucket.util.d.ts +66 -0
  117. package/dist/utility/chart/live-bucket.util.js +165 -0
  118. package/dist/utility/chart/market-session-schedule.util.d.ts +91 -0
  119. package/dist/utility/chart/market-session-schedule.util.js +337 -0
  120. package/dist/utility/chart/marketKind.util.d.ts +181 -0
  121. package/dist/utility/chart/marketKind.util.js +371 -0
  122. package/dist/utility/chart/opra-read-access.leaf.d.ts +26 -0
  123. package/dist/utility/chart/opra-read-access.leaf.js +25 -0
  124. package/dist/utility/chart/prediction-identity.util.d.ts +159 -0
  125. package/dist/utility/chart/prediction-identity.util.js +236 -0
  126. package/dist/utility/chart/rth-session.util.d.ts +352 -0
  127. package/dist/utility/chart/rth-session.util.js +926 -0
  128. package/dist/utility/chart/titan-constants.pin.d.ts +43 -0
  129. package/dist/utility/chart/titan-constants.pin.js +50 -0
  130. package/dist/utility/chart/us-equities-session.util.d.ts +127 -0
  131. package/dist/utility/chart/us-equities-session.util.js +251 -0
  132. package/dist/utility/chart/window-geometry.leaf.d.ts +119 -0
  133. package/dist/utility/chart/window-geometry.leaf.js +391 -0
  134. package/dist/utility/chart/window-owner.leaf.d.ts +19 -0
  135. package/dist/utility/chart/window-owner.leaf.js +24 -0
  136. package/dist/utility/chart/wrun-bar-session-facts.util.d.ts +100 -0
  137. package/dist/utility/chart/wrun-bar-session-facts.util.js +354 -0
  138. package/dist/utility/chart/wrun-wire-ref.util.d.ts +23 -0
  139. package/dist/utility/chart/wrun-wire-ref.util.js +16 -0
  140. package/dist/utility/common/safe-math-eval.d.ts +18 -0
  141. package/dist/utility/common/safe-math-eval.js +160 -0
  142. package/dist/utility/common/time.util.d.ts +134 -0
  143. package/dist/utility/common/time.util.js +428 -0
  144. package/dist/utility/common/transformations.util.d.ts +126 -0
  145. package/dist/utility/common/transformations.util.js +711 -0
  146. package/dist/utility/common/visible-timeout.util.d.ts +17 -0
  147. package/dist/utility/common/visible-timeout.util.js +75 -0
  148. package/dist/utility/exchange-normalization.util.d.ts +8 -0
  149. package/dist/utility/exchange-normalization.util.js +32 -0
  150. package/dist/utility/html-escape.leaf.d.ts +11 -0
  151. package/dist/utility/html-escape.leaf.js +20 -0
  152. package/dist/utility/intl-locale.util.d.ts +2 -0
  153. package/dist/utility/intl-locale.util.js +28 -0
  154. package/dist/utility/number-format.util.d.ts +14 -1
  155. package/dist/utility/number-format.util.js +50 -19
  156. package/dist/utility/options/option-symbol.util.d.ts +28 -0
  157. package/dist/utility/options/option-symbol.util.js +176 -0
  158. package/dist/utility/options/option-trade-units.util.d.ts +190 -0
  159. package/dist/utility/options/option-trade-units.util.js +283 -0
  160. package/dist/utility/options/option-venue.util.d.ts +75 -0
  161. package/dist/utility/options/option-venue.util.js +85 -0
  162. package/dist/utility/pool-symbol.leaf.d.ts +34 -0
  163. package/dist/utility/pool-symbol.leaf.js +95 -0
  164. package/dist/utility/scriptEditor/wrun-runtime-diagnostics.leaf.d.ts +109 -0
  165. package/dist/utility/scriptEditor/wrun-runtime-diagnostics.leaf.js +302 -0
  166. package/dist/utility/symbol-selection/contract-expiry.util.d.ts +39 -0
  167. package/dist/utility/symbol-selection/contract-expiry.util.js +111 -0
  168. package/dist/utility/v2/gate-plane.util.d.ts +58 -0
  169. package/dist/utility/v2/gate-plane.util.js +99 -0
  170. package/dist/utility/v2/gate-session-latch.util.d.ts +22 -0
  171. package/dist/utility/v2/gate-session-latch.util.js +34 -0
  172. package/dist/utility/watchlist/import/tradingview-symbols.leaf.d.ts +76 -0
  173. package/dist/utility/watchlist/import/tradingview-symbols.leaf.js +221 -0
  174. package/dist/utility/wrun/sources/host-grid-landing.d.ts +15 -0
  175. package/dist/utility/wrun/sources/host-grid-landing.js +26 -0
  176. package/dist/utility/wrun/sources/lanes/bitfinex_funding.d.ts +27 -0
  177. package/dist/utility/wrun/sources/lanes/bitfinex_funding.js +85 -0
  178. package/dist/utility/wrun/sources/lanes/economic.d.ts +27 -0
  179. package/dist/utility/wrun/sources/lanes/economic.js +79 -0
  180. package/dist/utility/wrun/sources/lanes/etf_holdings.d.ts +35 -0
  181. package/dist/utility/wrun/sources/lanes/etf_holdings.js +165 -0
  182. package/dist/utility/wrun/sources/lanes/etf_premium.d.ts +19 -0
  183. package/dist/utility/wrun/sources/lanes/etf_premium.js +114 -0
  184. package/dist/utility/wrun/sources/lanes/ethena_positions.d.ts +30 -0
  185. package/dist/utility/wrun/sources/lanes/ethena_positions.js +51 -0
  186. package/dist/utility/wrun/sources/lanes/index.d.ts +2 -0
  187. package/dist/utility/wrun/sources/lanes/index.js +32 -0
  188. package/dist/utility/wrun/sources/lanes/long_short_ratio.d.ts +17 -0
  189. package/dist/utility/wrun/sources/lanes/long_short_ratio.js +47 -0
  190. package/dist/utility/wrun/sources/lanes/option_daily.d.ts +58 -0
  191. package/dist/utility/wrun/sources/lanes/option_daily.js +111 -0
  192. package/dist/utility/wrun/sources/lanes/option_stats_10m.d.ts +27 -0
  193. package/dist/utility/wrun/sources/lanes/option_stats_10m.js +21 -0
  194. package/dist/utility/wrun/sources/lanes/options_flow.d.ts +50 -0
  195. package/dist/utility/wrun/sources/lanes/options_flow.js +155 -0
  196. package/dist/utility/wrun/sources/lanes/options_oi.d.ts +29 -0
  197. package/dist/utility/wrun/sources/lanes/options_oi.js +59 -0
  198. package/dist/utility/wrun/sources/lanes/options_volume.d.ts +38 -0
  199. package/dist/utility/wrun/sources/lanes/options_volume.js +63 -0
  200. package/dist/utility/wrun/sources/lanes/series.d.ts +67 -0
  201. package/dist/utility/wrun/sources/lanes/series.js +321 -0
  202. package/dist/utility/wrun/sources/lanes/token_supply.d.ts +30 -0
  203. package/dist/utility/wrun/sources/lanes/token_supply.js +145 -0
  204. package/dist/utility/wrun/sources/lanes/treasury_balance.d.ts +25 -0
  205. package/dist/utility/wrun/sources/lanes/treasury_balance.js +47 -0
  206. package/dist/utility/wrun/sources/lanes/volatility_index.d.ts +21 -0
  207. package/dist/utility/wrun/sources/lanes/volatility_index.js +11 -0
  208. package/dist/utility/wrun/sources/opra-option-lanes.util.d.ts +215 -0
  209. package/dist/utility/wrun/sources/opra-option-lanes.util.js +477 -0
  210. package/dist/utility/wrun/sources/registry.d.ts +21 -0
  211. package/dist/utility/wrun/sources/registry.js +237 -0
  212. package/dist/utility/wrun/sources/row-lane-registry.d.ts +28 -0
  213. package/dist/utility/wrun/sources/row-lane-registry.js +230 -0
  214. package/dist/utility/wrun/sources/row-lanes/index.d.ts +2 -0
  215. package/dist/utility/wrun/sources/row-lanes/index.js +12 -0
  216. package/dist/utility/wrun/sources/row-lanes/option_contract_flow.d.ts +2 -0
  217. package/dist/utility/wrun/sources/row-lanes/option_contract_flow.js +38 -0
  218. package/dist/utility/wrun/sources/row-lanes/option_contract_state.d.ts +55 -0
  219. package/dist/utility/wrun/sources/row-lanes/option_contract_state.js +126 -0
  220. package/dist/utility/wrun/sources/row-lanes/option_prints.d.ts +4 -0
  221. package/dist/utility/wrun/sources/row-lanes/option_prints.js +191 -0
  222. package/dist/utility/wrun/sources/row-lanes/option_strikes.d.ts +62 -0
  223. package/dist/utility/wrun/sources/row-lanes/option_strikes.js +147 -0
  224. package/dist/utility/wrun/sources/row-lanes/option_surface.d.ts +70 -0
  225. package/dist/utility/wrun/sources/row-lanes/option_surface.js +144 -0
  226. package/dist/utility/wrun/sources/wrun-poll-lane.types.d.ts +309 -0
  227. package/dist/utility/wrun/sources/wrun-poll-lane.types.js +26 -0
  228. package/dist/utility/wrun/sources/wrun-poll-lanes.util.d.ts +350 -0
  229. package/dist/utility/wrun/sources/wrun-poll-lanes.util.js +576 -0
  230. package/dist/utility/wrun/sources/wrun-row-lane.types.d.ts +275 -0
  231. package/dist/utility/wrun/sources/wrun-row-lane.types.js +16 -0
  232. package/dist/utility/wrun/sources/wrun-row-lanes.util.d.ts +207 -0
  233. package/dist/utility/wrun/sources/wrun-row-lanes.util.js +450 -0
  234. package/dist/utility/wrun/wrun-browser-sources.leaf.d.ts +28 -0
  235. package/dist/utility/wrun/wrun-browser-sources.leaf.js +66 -0
  236. package/dist/utility/wrun/wrun-cloud-record.util.d.ts +65 -0
  237. package/dist/utility/wrun/wrun-cloud-record.util.js +121 -0
  238. package/dist/utility/wrun/wrun-daily-lane.util.d.ts +95 -0
  239. package/dist/utility/wrun/wrun-daily-lane.util.js +297 -0
  240. package/dist/utility/wrun/wrun-deadline.util.d.ts +52 -0
  241. package/dist/utility/wrun/wrun-deadline.util.js +82 -0
  242. package/dist/utility/wrun/wrun-etf-flow-lane.util.d.ts +94 -0
  243. package/dist/utility/wrun/wrun-etf-flow-lane.util.js +224 -0
  244. package/dist/utility/wrun/wrun-etf-funds.util.d.ts +82 -0
  245. package/dist/utility/wrun/wrun-etf-funds.util.js +242 -0
  246. package/dist/utility/wrun/wrun-frames.d.ts +20 -1
  247. package/dist/utility/wrun/wrun-frames.js +103 -49
  248. package/dist/utility/wrun/wrun-hosted-wire-caps.d.ts +2 -2
  249. package/dist/utility/wrun/wrun-hosted-wire-caps.js +27 -0
  250. package/dist/utility/wrun/wrun-lane-refusal.leaf.d.ts +22 -0
  251. package/dist/utility/wrun/wrun-lane-refusal.leaf.js +32 -0
  252. package/dist/utility/wrun/wrun-lane-warmup.util.d.ts +18 -0
  253. package/dist/utility/wrun/wrun-lane-warmup.util.js +112 -0
  254. package/dist/utility/wrun/wrun-leg-close.util.d.ts +57 -0
  255. package/dist/utility/wrun/wrun-leg-close.util.js +187 -0
  256. package/dist/utility/wrun/wrun-leg-fetch.util.d.ts +144 -0
  257. package/dist/utility/wrun/wrun-leg-fetch.util.js +212 -0
  258. package/dist/utility/wrun/wrun-leg-stream-classes.d.ts +73 -0
  259. package/dist/utility/wrun/wrun-leg-stream-classes.js +86 -0
  260. package/dist/utility/wrun/wrun-levels-child.util.d.ts +101 -6
  261. package/dist/utility/wrun/wrun-levels-child.util.js +335 -157
  262. package/dist/utility/wrun/wrun-memory-clamp.util.d.ts +33 -0
  263. package/dist/utility/wrun/wrun-memory-clamp.util.js +146 -0
  264. package/dist/utility/wrun/wrun-odds-template-market.util.d.ts +51 -0
  265. package/dist/utility/wrun/wrun-odds-template-market.util.js +251 -0
  266. package/dist/utility/wrun/wrun-opra-flow.leaf.d.ts +65 -0
  267. package/dist/utility/wrun/wrun-opra-flow.leaf.js +94 -0
  268. package/dist/utility/wrun/wrun-opra-lane.util.d.ts +47 -0
  269. package/dist/utility/wrun/wrun-opra-lane.util.js +58 -0
  270. package/dist/utility/wrun/wrun-opra-stats.leaf.d.ts +49 -0
  271. package/dist/utility/wrun/wrun-opra-stats.leaf.js +115 -0
  272. package/dist/utility/wrun/wrun-opra-underlying.util.d.ts +12 -0
  273. package/dist/utility/wrun/wrun-opra-underlying.util.js +1 -0
  274. package/dist/utility/wrun/wrun-option-contract-flow.util.d.ts +142 -0
  275. package/dist/utility/wrun/wrun-option-contract-flow.util.js +451 -0
  276. package/dist/utility/wrun/wrun-option-knobs.util.d.ts +43 -0
  277. package/dist/utility/wrun/wrun-option-knobs.util.js +81 -0
  278. package/dist/utility/wrun/wrun-option-prints.util.d.ts +144 -0
  279. package/dist/utility/wrun/wrun-option-prints.util.js +356 -0
  280. package/dist/utility/wrun/wrun-option-summary-lane.util.d.ts +102 -0
  281. package/dist/utility/wrun/wrun-option-summary-lane.util.js +143 -0
  282. package/dist/utility/wrun/wrun-options-chain.util.d.ts +308 -0
  283. package/dist/utility/wrun/wrun-options-chain.util.js +502 -0
  284. package/dist/utility/wrun/wrun-overlay-identity.util.d.ts +9 -4
  285. package/dist/utility/wrun/wrun-overlay-identity.util.js +16 -6
  286. package/dist/utility/wrun/wrun-panel-mount.lazy.d.ts +10 -0
  287. package/dist/utility/wrun/wrun-panel-mount.lazy.js +68 -0
  288. package/dist/utility/wrun/wrun-panel-mount.util.d.ts +377 -0
  289. package/dist/utility/wrun/wrun-panel-mount.util.js +2251 -0
  290. package/dist/utility/wrun/wrun-param-map.util.d.ts +298 -0
  291. package/dist/utility/wrun/wrun-param-map.util.js +581 -0
  292. package/dist/utility/wrun/wrun-pause-dim.util.d.ts +52 -0
  293. package/dist/utility/wrun/wrun-pause-dim.util.js +153 -0
  294. package/dist/utility/wrun/wrun-pin-spelling.util.d.ts +149 -0
  295. package/dist/utility/wrun/wrun-pin-spelling.util.js +523 -0
  296. package/dist/utility/wrun/wrun-pin-venues.util.d.ts +116 -0
  297. package/dist/utility/wrun/wrun-pin-venues.util.js +320 -0
  298. package/dist/utility/wrun/wrun-pinned-interval.util.d.ts +20 -0
  299. package/dist/utility/wrun/wrun-pinned-interval.util.js +47 -0
  300. package/dist/utility/wrun/wrun-plot-gate.types.d.ts +23 -0
  301. package/dist/utility/wrun/wrun-plot-gate.types.js +7 -0
  302. package/dist/utility/wrun/wrun-present-bits.util.d.ts +37 -0
  303. package/dist/utility/wrun/wrun-present-bits.util.js +73 -0
  304. package/dist/utility/wrun/wrun-protocol-pending.util.d.ts +33 -0
  305. package/dist/utility/wrun/wrun-protocol-pending.util.js +57 -0
  306. package/dist/utility/wrun/wrun-refusal.util.d.ts +41 -1
  307. package/dist/utility/wrun/wrun-refusal.util.js +69 -2
  308. package/dist/utility/wrun/wrun-registry-errors.util.d.ts +1 -14
  309. package/dist/utility/wrun/wrun-registry-errors.util.js +0 -16
  310. package/dist/utility/wrun/wrun-row-source.d.ts +158 -0
  311. package/dist/utility/wrun/wrun-row-source.js +75 -0
  312. package/dist/utility/wrun/wrun-run-health.util.d.ts +155 -0
  313. package/dist/utility/wrun/wrun-run-health.util.js +273 -0
  314. package/dist/utility/wrun/wrun-run-interval-projection.types.d.ts +14 -0
  315. package/dist/utility/wrun/wrun-run-interval-projection.types.js +1 -0
  316. package/dist/utility/wrun/wrun-socket-row-source.d.ts +439 -0
  317. package/dist/utility/wrun/wrun-socket-row-source.js +1689 -0
  318. package/dist/utility/wrun/wrun-socket-session-losses.util.d.ts +18 -0
  319. package/dist/utility/wrun/wrun-socket-session-losses.util.js +25 -0
  320. package/dist/utility/wrun/wrun-source-rows.util.d.ts +911 -0
  321. package/dist/utility/wrun/wrun-source-rows.util.js +2597 -0
  322. package/dist/utility/wrun/wrun-tape-source.util.d.ts +82 -0
  323. package/dist/utility/wrun/wrun-tape-source.util.js +151 -0
  324. package/dist/utility/wrun/wrun-tier-grid.util.d.ts +137 -0
  325. package/dist/utility/wrun/wrun-tier-grid.util.js +279 -0
  326. package/dist/utility/wrun/wrun-trades-lane.util.d.ts +52 -0
  327. package/dist/utility/wrun/wrun-trades-lane.util.js +58 -0
  328. package/dist/utility/wrun/wrun-volume-profile-lane.util.d.ts +41 -0
  329. package/dist/utility/wrun/wrun-volume-profile-lane.util.js +66 -0
  330. package/dist/utility/wrun-display-name.util.d.ts +33 -0
  331. package/dist/utility/wrun-display-name.util.js +64 -0
  332. package/dist/workers/constants/kscript-transport-codes.d.ts +15 -0
  333. package/dist/workers/constants/kscript-transport-codes.js +15 -0
  334. package/dist/workers/constants/socket-slots.d.ts +574 -0
  335. package/dist/workers/constants/socket-slots.js +539 -0
  336. package/dist/workers/utils/number.worker.util.d.ts +5 -0
  337. package/dist/workers/utils/number.worker.util.js +10 -0
  338. package/dist/workers/utils/time.worker.util.d.ts +12 -0
  339. package/dist/workers/utils/time.worker.util.js +24 -0
  340. package/dist/workers/utils/volume-profile.worker.util.d.ts +200 -0
  341. package/dist/workers/utils/volume-profile.worker.util.js +631 -0
  342. package/package.json +10 -4
@@ -0,0 +1,343 @@
1
+ /**
2
+ * The CME session lattice: the client mirror of how tsdb-gateway labels CME
3
+ * Group history at 4h, 1d, 1w and every rolled-up preset (pkg/tsdb/selects/
4
+ * cme.go, usesCMESessionRollup + cmeSessionBucketExpression, since c645fd6;
5
+ * the presets since !2151). The gateway re-groups source-tier rows on the
6
+ * Chicago wall clock:
7
+ *
8
+ * - intraday (2m 3m 10m 45m 2h 4h 6h 8h 12h): `time_bucket(width, ts,
9
+ * timezone => 'America/Chicago', offset => 17:00 modulo the width)`, so the
10
+ * 17:00 open starts a bar. 4h: local 01/05/09/13/17/21 (22/02/06/10/14/18Z
11
+ * in CDT, 23/03/07/11/15/19Z in CST); 2h and 8h offset 1h, 6h and 12h 5h,
12
+ * 45m 30m, 2m 3m 10m none. The source tier is the coarsest of 1h/15m/5m/1m
13
+ * dividing both the width and that offset (`sessionTier`);
14
+ * - 1d: the trade date (the date flips at the 17:00 open), stamped at 00:00Z
15
+ * of that date, so an evening print belongs to TOMORROW's bar. A weekday
16
+ * holiday's session belongs to the next trade date on the CME calendar
17
+ * (cme-trade-calendar.util, !2154): Labor Day trades are 9/8's;
18
+ * - 3d: a year's trade dates in threes from its first (`DayGroupStart`), the
19
+ * way TradingView groups them, labeled by the first, so Thu-Fri-Mon is one
20
+ * bar and a holiday never leaves one short;
21
+ * - 1w: the Monday of the trade-date week, 00:00Z (Sunday's open starts it);
22
+ * - 1M 3M 6M 1Y: the months of the trade dates, stamped on the first month's
23
+ * 1st at 00:00Z (29dda19, intervals part 4); a weekend day joins the Friday
24
+ * before, so a month opens at the 17:00 Chicago open before its first trade
25
+ * date.
26
+ *
27
+ * The rollup covers explicit CME-group plans only (every exchange CME, CBOT,
28
+ * NYMEX or COMEX) for TRADE_AGG, TRADE_SIDE_AGNOSTIC_AGG, and the per-symbol
29
+ * VOLUME_PROFILE_AGG / BLOCK_BOOK_SNAPSHOT_AGG; open interest, settlement and
30
+ * coin-aggregated series stay on UTC buckets. A live writer that floored CME
31
+ * frames on the UTC grid instead split the forming bar (a 04:00 ET candle
32
+ * beside the 02:00 ET one) and titan dropped the frames keyed before it.
33
+ *
34
+ * Pure and worker-safe: Intl only, no dayjs.
35
+ */
36
+ import { Intervals } from '../../constants/interval.constants.js';
37
+ import { barEndMs, calendarBarStartMs, calendarMonthsOfMs } from './calendar-interval.util.js';
38
+ import { cmeDayGroupStartMs, cmeTradeDateOnOrAfter, cmeTradeDateOnOrBefore, isCmeTradeDate, } from './cme-trade-calendar.util.js';
39
+ const MINUTE_MS = 60_000;
40
+ const HOUR_MS = 3_600_000;
41
+ const DAY_MS = 86_400_000;
42
+ const ONE_DAY_MS = Intervals.map_unit['1d'];
43
+ const THREE_DAYS_MS = Intervals.map_unit['3d'];
44
+ const ONE_WEEK_MS = Intervals.map_unit['1w'];
45
+ /** The intraday widths the gateway buckets on the lattice. */
46
+ const INTRADAY_LATTICE_MS = new Set(['2m', '3m', '10m', '45m', '2h', '4h', '6h', '8h', '12h'].map((label) => Intervals.map_unit[label]));
47
+ const CME_SESSION_TIME_ZONE = 'America/Chicago';
48
+ /** The session open on the Chicago wall clock (gateway `cmeSessionOpenHour`). */
49
+ const CME_SESSION_OPEN_HOUR = 17;
50
+ /** The session open's offset into a width: 17:00 sits on the lattice (4h: 01:00, 05:00, ... 21:00). */
51
+ const openOffsetMs = (widthMs) => (CME_SESSION_OPEN_HOUR * HOUR_MS) % widthMs;
52
+ /** The source tier the gateway re-buckets for a width (`sessionTier`): the coarsest dividing width and offset. */
53
+ function sourceStepMs(widthMs) {
54
+ const offsetMs = openOffsetMs(widthMs);
55
+ for (const stepMs of [HOUR_MS, 15 * MINUTE_MS, 5 * MINUTE_MS]) {
56
+ if (widthMs % stepMs === 0 && offsetMs % stepMs === 0)
57
+ return stepMs;
58
+ }
59
+ return MINUTE_MS;
60
+ }
61
+ /** Central Standard Time. Postgres reads a Chicago wall time that occurs twice or never as standard time. */
62
+ const CHICAGO_STANDARD_OFFSET_MS = -6 * HOUR_MS;
63
+ const CHICAGO_DAYLIGHT_OFFSET_MS = -5 * HOUR_MS;
64
+ /** The venues the gateway rolls up (`isCMEGroupExchange`); GLOBEX is a metadata alias with no gate mapping. */
65
+ const CME_SESSION_LATTICE_EXCHANGES = new Set(['CME', 'CBOT', 'NYMEX', 'COMEX']);
66
+ export function isCmeSessionLatticeExchange(exchange) {
67
+ return typeof exchange === 'string' && CME_SESSION_LATTICE_EXCHANGES.has(exchange.toUpperCase());
68
+ }
69
+ /** The intervals the gateway serves on the session lattice: the intraday widths, 1d, 3d, 1w and the calendar rungs. */
70
+ export function isCmeSessionLatticeIntervalMs(intervalMs) {
71
+ return (typeof intervalMs === 'number' &&
72
+ (INTRADAY_LATTICE_MS.has(intervalMs) ||
73
+ intervalMs === ONE_DAY_MS ||
74
+ intervalMs === THREE_DAYS_MS ||
75
+ intervalMs === ONE_WEEK_MS ||
76
+ calendarMonthsOfMs(intervalMs) !== null));
77
+ }
78
+ const floorTo = (value, step) => value - (((value % step) + step) % step);
79
+ let chicagoFormatter = null;
80
+ function getChicagoFormatter() {
81
+ if (!chicagoFormatter) {
82
+ chicagoFormatter = new Intl.DateTimeFormat('en-US', {
83
+ timeZone: CME_SESSION_TIME_ZONE,
84
+ year: 'numeric',
85
+ month: '2-digit',
86
+ day: '2-digit',
87
+ hour: '2-digit',
88
+ minute: '2-digit',
89
+ second: '2-digit',
90
+ hourCycle: 'h23',
91
+ });
92
+ }
93
+ return chicagoFormatter;
94
+ }
95
+ function intlChicagoOffsetMs(utcMs) {
96
+ const wall = { year: 0, month: 1, day: 1, hour: 0, minute: 0, second: 0 };
97
+ for (const part of getChicagoFormatter().formatToParts(utcMs)) {
98
+ if (part.type in wall)
99
+ wall[part.type] = Number(part.value);
100
+ }
101
+ return Date.UTC(wall.year, wall.month - 1, wall.day, wall.hour % 24, wall.minute, wall.second) - utcMs;
102
+ }
103
+ /**
104
+ * Chicago's UTC offset at `utcMs`. US transitions happen at 02:00 local, a
105
+ * whole UTC hour, at most once per UTC day, so a day whose first and last
106
+ * hours agree holds one offset throughout: it caches per day (a CVD candle
107
+ * commit buckets years of rows, the live path one frame at a time), and only
108
+ * a transition day falls back to per-hour reads. NaN marks a transition day.
109
+ */
110
+ const offsetByUtcDay = new Map();
111
+ const offsetByUtcHour = new Map();
112
+ const OFFSET_CACHE_MAX = 8192;
113
+ function cacheOffset(cache, key, offset) {
114
+ if (cache.size >= OFFSET_CACHE_MAX)
115
+ cache.clear();
116
+ cache.set(key, offset);
117
+ }
118
+ function chicagoOffsetMs(utcMs) {
119
+ const dayMs = floorTo(utcMs, DAY_MS);
120
+ let dayOffset = offsetByUtcDay.get(dayMs);
121
+ if (dayOffset === undefined) {
122
+ const first = intlChicagoOffsetMs(dayMs);
123
+ dayOffset = first === intlChicagoOffsetMs(dayMs + 23 * HOUR_MS) ? first : Number.NaN;
124
+ cacheOffset(offsetByUtcDay, dayMs, dayOffset);
125
+ }
126
+ if (!Number.isNaN(dayOffset))
127
+ return dayOffset;
128
+ const hourMs = floorTo(utcMs, HOUR_MS);
129
+ let hourOffset = offsetByUtcHour.get(hourMs);
130
+ if (hourOffset === undefined) {
131
+ hourOffset = intlChicagoOffsetMs(hourMs);
132
+ cacheOffset(offsetByUtcHour, hourMs, hourOffset);
133
+ }
134
+ return hourOffset;
135
+ }
136
+ /**
137
+ * The instant a Chicago wall time (expressed as if it were UTC) names, read
138
+ * the way Postgres does (DetermineTimeZoneOffset): a wall time that occurs
139
+ * twice (fall back) or never (spring forward) reads as standard time.
140
+ */
141
+ function chicagoWallToUtcMs(wallAsUtcMs) {
142
+ const standard = wallAsUtcMs - CHICAGO_STANDARD_OFFSET_MS;
143
+ if (chicagoOffsetMs(standard) === CHICAGO_STANDARD_OFFSET_MS)
144
+ return standard;
145
+ const daylight = wallAsUtcMs - CHICAGO_DAYLIGHT_OFFSET_MS;
146
+ if (chicagoOffsetMs(daylight) === CHICAGO_DAYLIGHT_OFFSET_MS)
147
+ return daylight;
148
+ return standard;
149
+ }
150
+ /** The Chicago wall clock (as if it were UTC) of the gateway's source row: the 1h bucket holding `tsMs`. */
151
+ function chicagoWallOfSourceRow(tsMs) {
152
+ const rowMs = floorTo(tsMs, HOUR_MS);
153
+ return rowMs + chicagoOffsetMs(rowMs);
154
+ }
155
+ /** The calendar date of the session close `tsMs` trades toward (gateway `cmeSessionDay`): it flips at the 17:00 open. */
156
+ function sessionDayMs(tsMs) {
157
+ return floorTo(chicagoWallOfSourceRow(tsMs) + (24 - CME_SESSION_OPEN_HOUR) * HOUR_MS, DAY_MS);
158
+ }
159
+ const isWeekendDay = (dayMs) => {
160
+ const weekday = new Date(dayMs).getUTCDay();
161
+ return weekday === 0 || weekday === 6;
162
+ };
163
+ /**
164
+ * The trade date holding `tsMs`, stamped at 00:00Z (gateway
165
+ * `cmeCurrentSessionLabel`): a weekday holiday's session moves to the next
166
+ * trade date, a weekend day keeps its own date.
167
+ */
168
+ function tradeDateLabelMs(tsMs) {
169
+ const day = sessionDayMs(tsMs);
170
+ return isWeekendDay(day) ? day : cmeTradeDateOnOrAfter(day);
171
+ }
172
+ /** The 3d bar's first trade date: a weekend day joins the previous trade date's bar. */
173
+ function threeDayLabelMs(tsMs) {
174
+ const day = sessionDayMs(tsMs);
175
+ return cmeDayGroupStartMs(isWeekendDay(day) ? cmeTradeDateOnOrBefore(day) : cmeTradeDateOnOrAfter(day), 3);
176
+ }
177
+ /** The first session day booked to the trade date `labelMs`: a weekday holiday just before it opens with it. */
178
+ function firstSessionDayMs(labelMs) {
179
+ let day = labelMs;
180
+ for (let prev = day - DAY_MS; !isWeekendDay(prev) && !isCmeTradeDate(prev); prev -= DAY_MS)
181
+ day = prev;
182
+ return day;
183
+ }
184
+ /**
185
+ * The calendar bar holding `tsMs` (gateway `cmeSessionBucketExpression`): the months of its trade
186
+ * date, a weekend day counted on the Friday before it, so a stale weekend book never opens a month.
187
+ */
188
+ function calendarLabelMs(tsMs, months) {
189
+ const day = sessionDayMs(tsMs);
190
+ const weekday = new Date(day).getUTCDay();
191
+ const tradeDateMs = weekday === 6 ? day - DAY_MS : weekday === 0 ? day - 2 * DAY_MS : cmeTradeDateOnOrAfter(day);
192
+ return calendarBarStartMs(tradeDateMs, months);
193
+ }
194
+ /** The first session day booked to the calendar bar stamped `labelMs`: the first weekday after the last trade date
195
+ * before it (a holiday just before the month opens with it, as New Year's Day opens January). */
196
+ function firstCalendarSessionDayMs(labelMs) {
197
+ let day = cmeTradeDateOnOrBefore(labelMs - DAY_MS) + DAY_MS;
198
+ while (isWeekendDay(day))
199
+ day += DAY_MS;
200
+ return day;
201
+ }
202
+ /** The 17:00 Chicago open that starts the session day `dayMs`, on the calendar day before it. */
203
+ const sessionOpenMs = (dayMs) => chicagoWallToUtcMs(dayMs - DAY_MS + CME_SESSION_OPEN_HOUR * HOUR_MS);
204
+ /**
205
+ * The gateway's intraday bucket start for the source row holding `tsMs`, in
206
+ * the order TimescaleDB runs `time_bucket` with a timezone and an offset
207
+ * (src/time_bucket.c `ts_timestamptz_timezone_bucket`, 2.25+ #9129): take
208
+ * the offset off in UTC, bucket the Chicago wall clock from local midnight,
209
+ * read the start back, step back while it lands after the shifted instant
210
+ * (the fall-back guard), put the offset back in UTC. On the fall-back
211
+ * Sunday the 01:00 4h bar spans five real hours from 06:00Z; only CME's 24/7
212
+ * crypto products trade then. Every lattice width divides a day, so flooring
213
+ * the wall clock from the epoch is flooring it from local midnight.
214
+ */
215
+ function intradayBucketStartMs(tsMs, widthMs) {
216
+ const offsetMs = openOffsetMs(widthMs);
217
+ const shifted = floorTo(tsMs, sourceStepMs(widthMs)) - offsetMs;
218
+ let start = chicagoWallToUtcMs(floorTo(shifted + chicagoOffsetMs(shifted), widthMs));
219
+ while (start > shifted)
220
+ start -= widthMs;
221
+ return start + offsetMs;
222
+ }
223
+ const SESSION_GRID_ORIGIN_MS = Date.UTC(2000, 0, 3);
224
+ const SESSION_GRID_DAYS = 3;
225
+ /**
226
+ * The first trade date (00:00Z) of the 3d session bar holding the trade date
227
+ * `dayMs` (gateway `sessionGridStart`, session_grid.go): trade dates are
228
+ * counted in weekdays from 2000-01-03, a Monday, three to a bar; a weekend
229
+ * date counts as the Friday before it. The regular US equities session only
230
+ * (the gateway's NYSE calendar is not wired yet); CME rides the trade
231
+ * calendar, every other market's 3d is the calendar floor.
232
+ */
233
+ export function sessionGridStartMs(dayMs) {
234
+ const days = Math.floor((dayMs - SESSION_GRID_ORIGIN_MS) / DAY_MS);
235
+ const weeks = Math.floor(days / 7);
236
+ const weekday = 5 * weeks + Math.min(days - 7 * weeks, 4);
237
+ const start = SESSION_GRID_DAYS * Math.floor(weekday / SESSION_GRID_DAYS);
238
+ const startWeeks = Math.floor(start / 5);
239
+ return SESSION_GRID_ORIGIN_MS + (7 * startWeeks + start - 5 * startWeeks) * DAY_MS;
240
+ }
241
+ /**
242
+ * The bar key the gateway stamps for the CME session bar holding `tsMs`: the
243
+ * intraday bucket start, or the trade-date label (00:00Z of the trade date,
244
+ * not the 17:00 open instant) at 1d, the first trade date of its 3d group,
245
+ * the Monday of its week at 1w, and the 1st of its trade date's month,
246
+ * quarter, half or year at a calendar length. Null when the interval is not a
247
+ * session-lattice interval or the input is not a number.
248
+ */
249
+ export function cmeSessionBucketMs(tsMs, intervalMs) {
250
+ if (!Number.isFinite(tsMs))
251
+ return null;
252
+ if (INTRADAY_LATTICE_MS.has(intervalMs))
253
+ return intradayBucketStartMs(tsMs, intervalMs);
254
+ if (intervalMs === ONE_DAY_MS)
255
+ return tradeDateLabelMs(tsMs);
256
+ if (intervalMs === THREE_DAYS_MS)
257
+ return threeDayLabelMs(tsMs);
258
+ if (intervalMs === ONE_WEEK_MS) {
259
+ const dayMs = tradeDateLabelMs(tsMs);
260
+ // date_trunc('week'): ISO weeks start Monday; 1970-01-01 was a Thursday (ISO index 3).
261
+ const isoWeekday = (((Math.floor(dayMs / DAY_MS) + 3) % 7) + 7) % 7;
262
+ return dayMs - isoWeekday * DAY_MS;
263
+ }
264
+ const months = calendarMonthsOfMs(intervalMs);
265
+ return months === null ? null : calendarLabelMs(tsMs, months);
266
+ }
267
+ /** Bar ends already read (at most a few thousand legs' candles; cleared when full). */
268
+ const barEndCache = new Map();
269
+ const BAR_END_CACHE_MAX = 8192;
270
+ /** The longest a daily-class bar can run past its stamp: a week and the holidays around it. */
271
+ const DAILY_BAR_SCAN_MS = 21 * DAY_MS;
272
+ /**
273
+ * The instant the CME session bar stamped `barMs` (a key `cmeSessionBucketMs` stamps) stops
274
+ * taking source rows: the end of the last source row the lattice books to it, for a reader that
275
+ * must never take a bar before it closes (a pinned wrun leg). At 1d, 3d and 1w the key only
276
+ * advances with the session day, so the bar ends at the first source row booked elsewhere: a 3d
277
+ * bar runs to the 17:00 Chicago open of the next group's first session, a weekend or a weekday
278
+ * holiday inside it (Thursday, Friday and Monday close at Monday's 17:00), and a 1d bar to the
279
+ * 17:00 open that starts the next session day. An intraday bar ends at its stamp plus its width,
280
+ * except across a DST change: on the fall-back Sunday a bucket reaching the repeated hour holds
281
+ * its rows an hour longer (the 01:00 4h bar runs five real hours), and the 45m lattice books
282
+ * rows of the repeated hour back to an earlier stamp, so the end is the end of the LAST row
283
+ * booked to it within its width and an hour. A calendar bar runs to the next one's open (July 2026
284
+ * to Sunday 8/2 at 17:00 CDT). Null off the lattice intervals, or for a stamp the lattice books no
285
+ * row to.
286
+ */
287
+ export function cmeSessionBarEndMs(barMs, intervalMs) {
288
+ if (!Number.isFinite(barMs) || !isCmeSessionLatticeIntervalMs(intervalMs))
289
+ return null;
290
+ const cacheKey = `${intervalMs}:${barMs}`;
291
+ const cached = barEndCache.get(cacheKey);
292
+ if (cached !== undefined)
293
+ return cached;
294
+ let end = null;
295
+ const months = calendarMonthsOfMs(intervalMs);
296
+ if (months !== null) {
297
+ if (calendarBarStartMs(barMs, months) === barMs) {
298
+ end = sessionOpenMs(firstCalendarSessionDayMs(barEndMs(barMs, intervalMs)));
299
+ }
300
+ }
301
+ else if (INTRADAY_LATTICE_MS.has(intervalMs)) {
302
+ const windowEndMs = barMs + intervalMs + HOUR_MS;
303
+ if (chicagoOffsetMs(barMs - intervalMs - HOUR_MS) === chicagoOffsetMs(windowEndMs)) {
304
+ // No DST change within reach: the lattice is a plain run of widths here. (A spring-forward
305
+ // change just before the stamp shortens the bar, so the window reaches back a width too.)
306
+ end = cmeSessionBucketMs(barMs, intervalMs) === barMs ? barMs + intervalMs : null;
307
+ }
308
+ else {
309
+ const stepMs = sourceStepMs(intervalMs);
310
+ for (let rowMs = barMs; rowMs < windowEndMs; rowMs += stepMs) {
311
+ if (cmeSessionBucketMs(rowMs, intervalMs) === barMs)
312
+ end = rowMs + stepMs;
313
+ }
314
+ }
315
+ }
316
+ else if (cmeSessionBucketMs(barMs, intervalMs) === barMs) {
317
+ let rowMs = barMs + HOUR_MS;
318
+ while (rowMs < barMs + DAILY_BAR_SCAN_MS && cmeSessionBucketMs(rowMs, intervalMs) === barMs)
319
+ rowMs += HOUR_MS;
320
+ end = rowMs < barMs + DAILY_BAR_SCAN_MS ? rowMs : null;
321
+ }
322
+ if (barEndCache.size >= BAR_END_CACHE_MAX)
323
+ barEndCache.clear();
324
+ barEndCache.set(cacheKey, end);
325
+ return end;
326
+ }
327
+ /**
328
+ * The instant the CME session bar holding `tsMs` opens, for a fetch window
329
+ * that must cover the whole bar: the intraday bucket start, or the 17:00
330
+ * Chicago open before the trade date (1d), the 3d group's first trade date
331
+ * and the week's Monday (1w), where the bar key is a 00:00Z label that runs
332
+ * ahead of the open, and a calendar bar's first trade date (August 2026 opens
333
+ * Sunday 8/2). A 1d or 3d bar after a weekday holiday opens with the holiday's
334
+ * session (9/8 opens Sunday 9/6). Null off the lattice intervals.
335
+ */
336
+ export function cmeSessionBarOpenMs(tsMs, intervalMs) {
337
+ const bucketMs = cmeSessionBucketMs(tsMs, intervalMs);
338
+ if (bucketMs === null || INTRADAY_LATTICE_MS.has(intervalMs))
339
+ return bucketMs;
340
+ if (calendarMonthsOfMs(intervalMs) !== null)
341
+ return sessionOpenMs(firstCalendarSessionDayMs(bucketMs));
342
+ return sessionOpenMs(intervalMs === ONE_WEEK_MS ? bucketMs : firstSessionDayMs(bucketMs));
343
+ }
@@ -0,0 +1,26 @@
1
+ /**
2
+ * The CME Globex trade calendar: the client mirror of tsdb-gateway
3
+ * `pkg/tsdb/tradecalendar` with the `cme_globex` rows of its migration
4
+ * 1790786667_market_holidays (!2154). A rule holiday is not a trade date: a
5
+ * session trading on one (an early-halt Monday, Thanksgiving) belongs to the
6
+ * next trade date. An exception with `trading` true keeps a holiday as a
7
+ * trade date of its own (a jobs-report Good Friday, and the holidays
8
+ * TradingView's 2018-2020 history counts as sessions), one with `trading`
9
+ * false closes a weekday. Pinned to TradingView's ES1! 3D bar starts
10
+ * (`__fixtures__/cme-trade-calendar`). Edit the rows here in lockstep with
11
+ * the gateway's migrations, or live bars split from history.
12
+ *
13
+ * Days are UTC-midnight milliseconds. Pure and worker-safe.
14
+ */
15
+ export declare function isCmeTradeDate(dayMs: number): boolean;
16
+ /** The trade date a session whose calendar date is `dayMs` belongs to: that day, else the next trade date. */
17
+ export declare function cmeTradeDateOnOrAfter(dayMs: number): number;
18
+ /** The last trade date on or before `dayMs`. */
19
+ export declare function cmeTradeDateOnOrBefore(dayMs: number): number;
20
+ /**
21
+ * The first trade date of the `days`-session bar holding the trade date
22
+ * `tradeDateMs` (gateway `DayGroupStart`): a year's trade dates grouped in
23
+ * runs from its first, as TradingView does, so the count restarts every
24
+ * January and a year's last bar may hold fewer.
25
+ */
26
+ export declare function cmeDayGroupStartMs(tradeDateMs: number, days: number): number;
@@ -0,0 +1,147 @@
1
+ /**
2
+ * The CME Globex trade calendar: the client mirror of tsdb-gateway
3
+ * `pkg/tsdb/tradecalendar` with the `cme_globex` rows of its migration
4
+ * 1790786667_market_holidays (!2154). A rule holiday is not a trade date: a
5
+ * session trading on one (an early-halt Monday, Thanksgiving) belongs to the
6
+ * next trade date. An exception with `trading` true keeps a holiday as a
7
+ * trade date of its own (a jobs-report Good Friday, and the holidays
8
+ * TradingView's 2018-2020 history counts as sessions), one with `trading`
9
+ * false closes a weekday. Pinned to TradingView's ES1! 3D bar starts
10
+ * (`__fixtures__/cme-trade-calendar`). Edit the rows here in lockstep with
11
+ * the gateway's migrations, or live bars split from history.
12
+ *
13
+ * Days are UTC-midnight milliseconds. Pure and worker-safe.
14
+ */
15
+ const DAY_MS = 86_400_000;
16
+ /** Months are 1-12, weekdays 0 (Sunday) to 6, as in the gateway's rows. */
17
+ const CME_RULES = [
18
+ { kind: 'fixed', month: 1, day: 1, weekendRule: 'monday_if_sunday' }, // New Year's Day
19
+ { kind: 'nth_weekday', month: 1, weekday: 1, nth: 3 }, // Martin Luther King Jr. Day
20
+ { kind: 'nth_weekday', month: 2, weekday: 1, nth: 3 }, // Presidents Day
21
+ { kind: 'easter', offsetDays: -2 }, // Good Friday
22
+ { kind: 'last_weekday', month: 5, weekday: 1 }, // Memorial Day
23
+ { kind: 'fixed', month: 6, day: 19, weekendRule: 'nearest_weekday', fromYear: 2022 }, // Juneteenth
24
+ { kind: 'fixed', month: 7, day: 4, weekendRule: 'nearest_weekday' }, // Independence Day
25
+ { kind: 'nth_weekday', month: 9, weekday: 1, nth: 1 }, // Labor Day
26
+ { kind: 'nth_weekday', month: 11, weekday: 4, nth: 4 }, // Thanksgiving
27
+ { kind: 'fixed', month: 12, day: 25, weekendRule: 'nearest_weekday' }, // Christmas Day
28
+ ];
29
+ /** [day, trading]: jobs-report Good Fridays and TradingView's 2018-2020 sessions trade. */
30
+ const CME_EXCEPTIONS = [
31
+ ['2012-04-06', true],
32
+ ['2015-04-03', true],
33
+ ['2018-03-30', true],
34
+ ['2019-04-19', true],
35
+ ['2019-12-25', true],
36
+ ['2020-01-01', true],
37
+ ['2020-04-10', true],
38
+ ['2021-04-02', true],
39
+ ['2023-04-07', true],
40
+ ['2026-04-03', true],
41
+ ];
42
+ const utcDay = (year, month, day) => Date.UTC(year, month - 1, day);
43
+ const weekdayOf = (dayMs) => new Date(dayMs).getUTCDay();
44
+ const isWeekend = (dayMs) => weekdayOf(dayMs) === 0 || weekdayOf(dayMs) === 6;
45
+ /** Easter Sunday (Gregorian, anonymous algorithm). */
46
+ function easterMs(year) {
47
+ const a = year % 19;
48
+ const b = Math.floor(year / 100);
49
+ const c = year % 100;
50
+ const d = Math.floor(b / 4);
51
+ const e = b % 4;
52
+ const f = Math.floor((b + 8) / 25);
53
+ const g = Math.floor((b - f + 1) / 3);
54
+ const h = (19 * a + b - d - g + 15) % 30;
55
+ const i = Math.floor(c / 4);
56
+ const k = c % 4;
57
+ const l = (32 + 2 * e + 2 * i - h - k) % 7;
58
+ const m = Math.floor((a + 11 * h + 22 * l) / 451);
59
+ const month = Math.floor((h + l - 7 * m + 114) / 31);
60
+ return utcDay(year, month, ((h + l - 7 * m + 114) % 31) + 1);
61
+ }
62
+ /** The weekday a rule observes in `year`, or null when it is not observed (New Year's on a Saturday). */
63
+ function ruleDayMs(rule, year) {
64
+ switch (rule.kind) {
65
+ case 'fixed': {
66
+ if (rule.fromYear !== undefined && year < rule.fromYear)
67
+ return null;
68
+ const dayMs = utcDay(year, rule.month, rule.day);
69
+ const weekday = weekdayOf(dayMs);
70
+ if (weekday === 0)
71
+ return dayMs + DAY_MS;
72
+ if (weekday !== 6)
73
+ return dayMs;
74
+ return rule.weekendRule === 'nearest_weekday' ? dayMs - DAY_MS : null;
75
+ }
76
+ case 'nth_weekday': {
77
+ const first = utcDay(year, rule.month, 1);
78
+ const dayMs = first + (((rule.weekday - weekdayOf(first) + 7) % 7) + 7 * (rule.nth - 1)) * DAY_MS;
79
+ return new Date(dayMs).getUTCMonth() + 1 === rule.month ? dayMs : null;
80
+ }
81
+ case 'last_weekday': {
82
+ const last = utcDay(year, rule.month + 1, 1) - DAY_MS;
83
+ return last - ((weekdayOf(last) - rule.weekday + 7) % 7) * DAY_MS;
84
+ }
85
+ case 'easter':
86
+ return easterMs(year) + rule.offsetDays * DAY_MS;
87
+ }
88
+ }
89
+ const exceptionByDay = new Map(CME_EXCEPTIONS.map(([day, trading]) => [Date.parse(`${day}T00:00:00Z`), trading]));
90
+ const tradeDatesByYear = new Map();
91
+ /** A year's trade dates in order: weekdays the rules leave open, exceptions applied last. */
92
+ function yearTradeDates(year) {
93
+ const cached = tradeDatesByYear.get(year);
94
+ if (cached)
95
+ return cached;
96
+ const closed = new Set();
97
+ for (const rule of CME_RULES) {
98
+ const dayMs = ruleDayMs(rule, year);
99
+ if (dayMs !== null)
100
+ closed.add(dayMs);
101
+ }
102
+ const dates = [];
103
+ const index = new Map();
104
+ for (let dayMs = utcDay(year, 1, 1); new Date(dayMs).getUTCFullYear() === year; dayMs += DAY_MS) {
105
+ if (isWeekend(dayMs))
106
+ continue;
107
+ const trading = exceptionByDay.get(dayMs);
108
+ if (trading === false || (trading === undefined && closed.has(dayMs)))
109
+ continue;
110
+ index.set(dayMs, dates.length);
111
+ dates.push(dayMs);
112
+ }
113
+ const entry = { dates, index };
114
+ tradeDatesByYear.set(year, entry);
115
+ return entry;
116
+ }
117
+ const floorDay = (ms) => ms - (((ms % DAY_MS) + DAY_MS) % DAY_MS);
118
+ export function isCmeTradeDate(dayMs) {
119
+ const day = floorDay(dayMs);
120
+ return yearTradeDates(new Date(day).getUTCFullYear()).index.has(day);
121
+ }
122
+ /** The trade date a session whose calendar date is `dayMs` belongs to: that day, else the next trade date. */
123
+ export function cmeTradeDateOnOrAfter(dayMs) {
124
+ let day = floorDay(dayMs);
125
+ while (!isCmeTradeDate(day))
126
+ day += DAY_MS;
127
+ return day;
128
+ }
129
+ /** The last trade date on or before `dayMs`. */
130
+ export function cmeTradeDateOnOrBefore(dayMs) {
131
+ let day = floorDay(dayMs);
132
+ while (!isCmeTradeDate(day))
133
+ day -= DAY_MS;
134
+ return day;
135
+ }
136
+ /**
137
+ * The first trade date of the `days`-session bar holding the trade date
138
+ * `tradeDateMs` (gateway `DayGroupStart`): a year's trade dates grouped in
139
+ * runs from its first, as TradingView does, so the count restarts every
140
+ * January and a year's last bar may hold fewer.
141
+ */
142
+ export function cmeDayGroupStartMs(tradeDateMs, days) {
143
+ const tradeDate = cmeTradeDateOnOrAfter(tradeDateMs);
144
+ const { dates, index } = yearTradeDates(new Date(tradeDate).getUTCFullYear());
145
+ const position = index.get(tradeDate) ?? 0;
146
+ return dates[days * Math.floor(position / days)];
147
+ }
@@ -0,0 +1,138 @@
1
+ export declare const CONTINUOUS_RULE_VERSION = 1;
2
+ export declare const CONTINUOUS_BOUNDARY_LOCAL_TIME = "17:00";
3
+ export declare const CONTINUOUS_BOUNDARY_TIMEZONE = "America/Chicago";
4
+ export interface ContinuousFamilyRule {
5
+ nBusinessDays: number;
6
+ /** Shared month cycle for every root of the family (mutually exclusive with cycleByRoot). */
7
+ cycle?: string[];
8
+ /** Roots sharing `cycle` (mutually exclusive with cycleByRoot). */
9
+ roots?: string[];
10
+ /** Per-root month cycles; the key set IS the family's root set. */
11
+ cycleByRoot?: Record<string, string[]>;
12
+ }
13
+ /**
14
+ * Per-family roll constants. EXACT mirror of the golden fixture's `families`
15
+ * object (and therefore of the gateway config); the parity spec deep-equals
16
+ * this against the fixture.
17
+ */
18
+ export declare const CONTINUOUS_FAMILIES: Record<string, ContinuousFamilyRule>;
19
+ /** Root of a continuous symbol ("ES1!" -> "ES"), or null when not one. */
20
+ export declare function continuousRootOf(symbol: string | undefined | null): string | null;
21
+ /** True for `<ROOT>1!` where ROOT is a configured continuous root. */
22
+ export declare function isContinuousSymbol(symbol: string | undefined | null): boolean;
23
+ /** One concrete contract instance. Year-digit recycling (ESU6 2016 vs 2026) is disambiguated by expiryMs. */
24
+ export interface ContinuousContractInstance {
25
+ symbol: string;
26
+ /** Expiry instant (ms UTC); its America/Chicago calendar date is the rule's expiry date. */
27
+ expiryMs: number;
28
+ /** How expiryMs was obtained. Alert creates carry this provenance to the server. */
29
+ expirySource?: 'catalog' | 'delivery_month_fallback';
30
+ /** 24h volume from the catalog row; dying contracts omit it on the wire. */
31
+ volume24h?: number;
32
+ }
33
+ export interface ContinuousEra {
34
+ symbol: string;
35
+ expiryMs: number;
36
+ /** Previous era's end; 0 for the first known era. */
37
+ eraStartMs: number;
38
+ /** Roll boundary: 17:00 America/Chicago, N business days before expiry (ms UTC). */
39
+ eraEndMs: number;
40
+ }
41
+ export interface ResolvedContinuousLead {
42
+ symbol: string;
43
+ expiryMs: number;
44
+ eraStartMs: number;
45
+ /** The next roll boundary (revalidate the lead at this instant). */
46
+ eraEndMs: number;
47
+ }
48
+ /**
49
+ * Eras for a root, given its contract instances: filter to the root's active
50
+ * month cycle, order by expiry, and end each era N business days before that
51
+ * contract's expiry at 17:00 America/Chicago. Contracts outside the cycle
52
+ * (serial months like ESF7) never lead.
53
+ */
54
+ export declare function computeContinuousEras(root: string, contracts: ContinuousContractInstance[]): ContinuousEra[];
55
+ /**
56
+ * The contract leading the continuous series at `nowMs`: the era containing
57
+ * now (era = [prevBoundary, boundary); at the boundary instant the NEXT
58
+ * contract already leads). Null when no known contract's era covers now
59
+ * (empty/expired registry list); callers treat that as "unresolved".
60
+ *
61
+ * `exchange` is carried for symmetry with the resolver cache identity; the
62
+ * math itself is venue-independent (roots are globally unique across the
63
+ * governed venues).
64
+ */
65
+ export declare function resolveContinuousLead(root: string, exchange: string, contracts: ContinuousContractInstance[], nowMs: number): ResolvedContinuousLead | null;
66
+ export type ContinuousLeadPeek = (exchange: string, symbol: string) => ResolvedContinuousLead | null;
67
+ /** Called once by continuous-contracts.service at construction. */
68
+ export declare function registerContinuousLeadPeek(peek: ContinuousLeadPeek | null): void;
69
+ /** Last-known lead via the registered resolver; null when unregistered/unresolved. */
70
+ export declare function peekRegisteredContinuousLead(exchange: string, symbol: string): ResolvedContinuousLead | null;
71
+ /**
72
+ * Lead applier slot. The applier retracts the affected charts' live channels
73
+ * BEFORE a lead flip commits (channels rebuild from settings at call time, so
74
+ * they must be torn down while the old lead is still peekable) and restamps +
75
+ * resubscribes after. It lives in the live-feed service, which imports the
76
+ * resolver service; registering through this leaf module (no imports back into
77
+ * either) keeps the wiring independent of which side of that import cycle the
78
+ * module graph is entered from, and of whether the cycle evaluates
79
+ * synchronously.
80
+ */
81
+ export interface ContinuousLeadApplier {
82
+ /** Retract affected charts' live channels; runs while the OLD lead is still peekable. */
83
+ beforeLeadChange(root: string): void;
84
+ /** Stamp metadata + resubscribe; runs once the NEW lead is peekable. */
85
+ afterLeadChange(root: string, lead: ResolvedContinuousLead): void;
86
+ }
87
+ /** Answers "does any chart still reference this continuous root". */
88
+ export type ContinuousRootUsageProbe = (root: string) => boolean;
89
+ /** Called at module scope by the live-feed service. */
90
+ export declare function registerContinuousLeadApplier(applier: ContinuousLeadApplier | null): void;
91
+ /** The registered applier; null (workers, isolated specs) means a lead flip re-homes nothing. */
92
+ export declare function registeredContinuousLeadApplier(): ContinuousLeadApplier | null;
93
+ /**
94
+ * Register the "does any chart still reference this root" probe. Resolver
95
+ * timer fires (failure retry and boundary revalidation alike) consult it and
96
+ * drop the root instead of refetching when the answer is no. Search-warmed
97
+ * roots ride the same lifecycle: warm freely, expire when no chart picked the
98
+ * symbol up.
99
+ */
100
+ export declare function registerContinuousRootUsageProbe(probe: ContinuousRootUsageProbe | null): void;
101
+ /** The registered probe; null (workers, isolated specs) means "assume referenced". */
102
+ export declare function registeredContinuousRootUsageProbe(): ContinuousRootUsageProbe | null;
103
+ /**
104
+ * Chart-metadata accessor slot, same shape as the lead peek above: the
105
+ * live-feed STORE asserts the resolvedContract stamp at subscribe time but
106
+ * must stay dependency-light (importing the chart store would drag the whole
107
+ * chart graph into every node spec touching the live-feed store), so
108
+ * live-feed.util registers the real accessor at module load. Unregistered
109
+ * (isolated specs, pre-chart boot) the accessor answers undefined and the
110
+ * stamp assertion no-ops.
111
+ */
112
+ export interface ContinuousChartMetadataView {
113
+ exchange?: string;
114
+ symbol?: string;
115
+ resolvedContract?: string;
116
+ }
117
+ export type ContinuousChartMetadataAccessor = (chartIndex: number) => ContinuousChartMetadataView | undefined;
118
+ export declare function registerContinuousChartMetadataAccessor(accessor: ContinuousChartMetadataAccessor | null): void;
119
+ export declare function continuousChartMetadataByIndex(chartIndex: number): ContinuousChartMetadataView | undefined;
120
+ /**
121
+ * Chart-side identity a live frame is matched against. For continuous symbols
122
+ * the live channels subscribe with the RESOLVED contract (the gate only
123
+ * streams concrete contracts), so frames arrive labeled e.g. ESU6 while the
124
+ * chart's symbol stays ES1!; `resolvedContract` bridges the two.
125
+ */
126
+ export interface LiveFeedSymbolTarget {
127
+ symbol?: unknown;
128
+ normalizedSymbol?: unknown;
129
+ resolvedContract?: unknown;
130
+ }
131
+ /**
132
+ * True when a live frame's symbol belongs to the target's stream: exact
133
+ * symbol/normalizedSymbol match, or, for a continuous target, the resolved
134
+ * lead contract. The alias only applies when the resolved contract's parsed
135
+ * root matches the continuous root, so a stale resolvedContract from another
136
+ * market can never claim foreign frames.
137
+ */
138
+ export declare function symbolsMatchForLiveFeed(target: LiveFeedSymbolTarget | undefined | null, frameSymbol: unknown): boolean;