@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.
- package/README.md +22 -8
- package/dist/constants/common.constants.d.ts +15 -0
- package/dist/constants/common.constants.js +23 -0
- package/dist/constants/data-source.constants.d.ts +1 -0
- package/dist/constants/data-source.constants.js +1 -0
- package/dist/constants/economic.constants.d.ts +39 -0
- package/dist/constants/economic.constants.js +77 -0
- package/dist/constants/etf-covered-coins.constants.d.ts +1 -0
- package/dist/constants/etf-covered-coins.constants.js +9 -0
- package/dist/constants/feature-flags.constants.d.ts +60 -0
- package/dist/constants/feature-flags.constants.js +308 -0
- package/dist/constants/feature-limits.constants.d.ts +134 -0
- package/dist/constants/feature-limits.constants.js +155 -0
- package/dist/constants/marketCapabilities.constants.d.ts +87 -0
- package/dist/constants/marketCapabilities.constants.js +213 -0
- package/dist/constants/option-venues.constants.d.ts +100 -0
- package/dist/constants/option-venues.constants.js +167 -0
- package/dist/constants/overlay-data.constants.d.ts +53 -0
- package/dist/constants/overlay-data.constants.js +80 -0
- package/dist/constants/pane-grid.constants.d.ts +15 -0
- package/dist/constants/pane-grid.constants.js +17 -0
- package/dist/constants/scriptEditor/builtin-script-snippets.d.ts +133 -0
- package/dist/constants/scriptEditor/builtin-script-snippets.js +451 -0
- package/dist/constants/venue-presets.constants.d.ts +10 -0
- package/dist/constants/venue-presets.constants.js +22 -0
- package/dist/enums/chart.enum.d.ts +68 -0
- package/dist/enums/chart.enum.js +70 -0
- package/dist/helpers/data.helpers.d.ts +2 -0
- package/dist/helpers/data.helpers.js +14 -0
- package/dist/host-env.d.ts +163 -5
- package/dist/host-ports.types.d.ts +431 -0
- package/dist/host-ports.types.js +1 -0
- package/dist/index.d.ts +138 -0
- package/dist/index.js +138 -0
- package/dist/indicators/controls/technical-script/technical-script-input-rendering.d.ts +86 -0
- package/dist/indicators/controls/technical-script/technical-script-input-rendering.js +179 -0
- package/dist/interfaces/asset-venue.interface.d.ts +91 -0
- package/dist/interfaces/asset-venue.interface.js +1 -0
- package/dist/interfaces/cancel-reason.interface.d.ts +24 -0
- package/dist/interfaces/cancel-reason.interface.js +2 -0
- package/dist/interfaces/catalog-display.interface.d.ts +3 -0
- package/dist/interfaces/catalog-display.interface.js +1 -0
- package/dist/interfaces/cme-realtime.interface.d.ts +251 -0
- package/dist/interfaces/cme-realtime.interface.js +46 -0
- package/dist/interfaces/feed.interface.d.ts +80 -0
- package/dist/interfaces/feed.interface.js +7 -0
- package/dist/interfaces/market-kind.interface.d.ts +8 -0
- package/dist/interfaces/market-kind.interface.js +1 -0
- package/dist/interfaces/opra-realtime.interface.d.ts +224 -0
- package/dist/interfaces/opra-realtime.interface.js +105 -0
- package/dist/interfaces/option-instrument.interface.d.ts +32 -0
- package/dist/interfaces/option-instrument.interface.js +1 -0
- package/dist/interfaces/options-chain-scope.interface.d.ts +29 -0
- package/dist/interfaces/options-chain-scope.interface.js +7 -0
- package/dist/interfaces/prediction-market.interface.d.ts +88 -0
- package/dist/interfaces/prediction-market.interface.js +8 -0
- package/dist/interfaces/wrun-runtime.interface.d.ts +5 -0
- package/dist/kscript-data/controls/live-trades-merge.util.d.ts +185 -0
- package/dist/kscript-data/controls/live-trades-merge.util.js +357 -0
- package/dist/settings-templates/frvp-fields.d.ts +27 -0
- package/dist/settings-templates/frvp-fields.js +108 -0
- package/dist/settings-templates/index.d.ts +119 -0
- package/dist/settings-templates/index.js +442 -0
- package/dist/settings-templates/indicator-fields.d.ts +56 -0
- package/dist/settings-templates/indicator-fields.js +793 -0
- package/dist/settings-templates/tool-rules.d.ts +59 -0
- package/dist/settings-templates/tool-rules.js +49 -0
- package/dist/settings-templates/tool-tables.generated.d.ts +2 -0
- package/dist/settings-templates/tool-tables.generated.js +1668 -0
- package/dist/utility/blk-market.util.d.ts +5 -0
- package/dist/utility/blk-market.util.js +12 -0
- package/dist/utility/chart/chart-load-phase.util.d.ts +32 -0
- package/dist/utility/chart/chart-load-phase.util.js +78 -0
- package/dist/utility/chart/cme-cache-context.util.d.ts +108 -0
- package/dist/utility/chart/cme-cache-context.util.js +166 -0
- package/dist/utility/chart/cme-session-bucket.util.d.ts +82 -0
- package/dist/utility/chart/cme-session-bucket.util.js +343 -0
- package/dist/utility/chart/cme-trade-calendar.util.d.ts +26 -0
- package/dist/utility/chart/cme-trade-calendar.util.js +147 -0
- package/dist/utility/chart/continuous-contracts.util.d.ts +138 -0
- package/dist/utility/chart/continuous-contracts.util.js +374 -0
- package/dist/utility/chart/date-labelled-interval.leaf.d.ts +15 -0
- package/dist/utility/chart/date-labelled-interval.leaf.js +19 -0
- package/dist/utility/chart/feed-interval.util.d.ts +119 -0
- package/dist/utility/chart/feed-interval.util.js +321 -0
- package/dist/utility/chart/fetch-dedupe-policy.util.d.ts +110 -0
- package/dist/utility/chart/fetch-dedupe-policy.util.js +407 -0
- package/dist/utility/chart/footprint-band.util.d.ts +76 -0
- package/dist/utility/chart/footprint-band.util.js +205 -0
- package/dist/utility/chart/footprint-cell-identity.util.d.ts +82 -0
- package/dist/utility/chart/footprint-cell-identity.util.js +346 -0
- package/dist/utility/chart/formula-calendar.util.d.ts +27 -0
- package/dist/utility/chart/formula-calendar.util.js +59 -0
- package/dist/utility/chart/history-wall.util.d.ts +67 -0
- package/dist/utility/chart/history-wall.util.js +87 -0
- package/dist/utility/chart/index-mode.util.d.ts +66 -0
- package/dist/utility/chart/index-mode.util.js +360 -0
- package/dist/utility/chart/indicator-coverage-planner.util.d.ts +217 -0
- package/dist/utility/chart/indicator-coverage-planner.util.js +443 -0
- package/dist/utility/chart/indicator-coverage-state.util.d.ts +33 -0
- package/dist/utility/chart/indicator-coverage-state.util.js +110 -0
- package/dist/utility/chart/indicator-gap-detector.util.d.ts +127 -0
- package/dist/utility/chart/indicator-gap-detector.util.js +260 -0
- package/dist/utility/chart/indicator-gap-repair.util.d.ts +88 -0
- package/dist/utility/chart/indicator-gap-repair.util.js +177 -0
- package/dist/utility/chart/indicator-inflight-registry.util.d.ts +26 -0
- package/dist/utility/chart/indicator-inflight-registry.util.js +254 -0
- package/dist/utility/chart/indicator-run-interval.util.d.ts +130 -0
- package/dist/utility/chart/indicator-run-interval.util.js +268 -0
- package/dist/utility/chart/interval-registry.util.d.ts +23 -0
- package/dist/utility/chart/interval-registry.util.js +83 -0
- package/dist/utility/chart/kscript-main-grid-stages.util.d.ts +21 -0
- package/dist/utility/chart/kscript-main-grid-stages.util.js +332 -0
- package/dist/utility/chart/legacy-exchange.leaf.d.ts +11 -0
- package/dist/utility/chart/legacy-exchange.leaf.js +43 -0
- package/dist/utility/chart/live-bucket.util.d.ts +66 -0
- package/dist/utility/chart/live-bucket.util.js +165 -0
- package/dist/utility/chart/market-session-schedule.util.d.ts +91 -0
- package/dist/utility/chart/market-session-schedule.util.js +337 -0
- package/dist/utility/chart/marketKind.util.d.ts +181 -0
- package/dist/utility/chart/marketKind.util.js +371 -0
- package/dist/utility/chart/opra-read-access.leaf.d.ts +26 -0
- package/dist/utility/chart/opra-read-access.leaf.js +25 -0
- package/dist/utility/chart/prediction-identity.util.d.ts +159 -0
- package/dist/utility/chart/prediction-identity.util.js +236 -0
- package/dist/utility/chart/rth-session.util.d.ts +352 -0
- package/dist/utility/chart/rth-session.util.js +926 -0
- package/dist/utility/chart/titan-constants.pin.d.ts +43 -0
- package/dist/utility/chart/titan-constants.pin.js +50 -0
- package/dist/utility/chart/us-equities-session.util.d.ts +127 -0
- package/dist/utility/chart/us-equities-session.util.js +251 -0
- package/dist/utility/chart/window-geometry.leaf.d.ts +119 -0
- package/dist/utility/chart/window-geometry.leaf.js +391 -0
- package/dist/utility/chart/window-owner.leaf.d.ts +19 -0
- package/dist/utility/chart/window-owner.leaf.js +24 -0
- package/dist/utility/chart/wrun-bar-session-facts.util.d.ts +100 -0
- package/dist/utility/chart/wrun-bar-session-facts.util.js +354 -0
- package/dist/utility/chart/wrun-wire-ref.util.d.ts +23 -0
- package/dist/utility/chart/wrun-wire-ref.util.js +16 -0
- package/dist/utility/common/safe-math-eval.d.ts +18 -0
- package/dist/utility/common/safe-math-eval.js +160 -0
- package/dist/utility/common/time.util.d.ts +134 -0
- package/dist/utility/common/time.util.js +428 -0
- package/dist/utility/common/transformations.util.d.ts +126 -0
- package/dist/utility/common/transformations.util.js +711 -0
- package/dist/utility/common/visible-timeout.util.d.ts +17 -0
- package/dist/utility/common/visible-timeout.util.js +75 -0
- package/dist/utility/exchange-normalization.util.d.ts +8 -0
- package/dist/utility/exchange-normalization.util.js +32 -0
- package/dist/utility/html-escape.leaf.d.ts +11 -0
- package/dist/utility/html-escape.leaf.js +20 -0
- package/dist/utility/intl-locale.util.d.ts +2 -0
- package/dist/utility/intl-locale.util.js +28 -0
- package/dist/utility/number-format.util.d.ts +14 -1
- package/dist/utility/number-format.util.js +50 -19
- package/dist/utility/options/option-symbol.util.d.ts +28 -0
- package/dist/utility/options/option-symbol.util.js +176 -0
- package/dist/utility/options/option-trade-units.util.d.ts +190 -0
- package/dist/utility/options/option-trade-units.util.js +283 -0
- package/dist/utility/options/option-venue.util.d.ts +75 -0
- package/dist/utility/options/option-venue.util.js +85 -0
- package/dist/utility/pool-symbol.leaf.d.ts +34 -0
- package/dist/utility/pool-symbol.leaf.js +95 -0
- package/dist/utility/scriptEditor/wrun-runtime-diagnostics.leaf.d.ts +109 -0
- package/dist/utility/scriptEditor/wrun-runtime-diagnostics.leaf.js +302 -0
- package/dist/utility/symbol-selection/contract-expiry.util.d.ts +39 -0
- package/dist/utility/symbol-selection/contract-expiry.util.js +111 -0
- package/dist/utility/v2/gate-plane.util.d.ts +58 -0
- package/dist/utility/v2/gate-plane.util.js +99 -0
- package/dist/utility/v2/gate-session-latch.util.d.ts +22 -0
- package/dist/utility/v2/gate-session-latch.util.js +34 -0
- package/dist/utility/watchlist/import/tradingview-symbols.leaf.d.ts +76 -0
- package/dist/utility/watchlist/import/tradingview-symbols.leaf.js +221 -0
- package/dist/utility/wrun/sources/host-grid-landing.d.ts +15 -0
- package/dist/utility/wrun/sources/host-grid-landing.js +26 -0
- package/dist/utility/wrun/sources/lanes/bitfinex_funding.d.ts +27 -0
- package/dist/utility/wrun/sources/lanes/bitfinex_funding.js +85 -0
- package/dist/utility/wrun/sources/lanes/economic.d.ts +27 -0
- package/dist/utility/wrun/sources/lanes/economic.js +79 -0
- package/dist/utility/wrun/sources/lanes/etf_holdings.d.ts +35 -0
- package/dist/utility/wrun/sources/lanes/etf_holdings.js +165 -0
- package/dist/utility/wrun/sources/lanes/etf_premium.d.ts +19 -0
- package/dist/utility/wrun/sources/lanes/etf_premium.js +114 -0
- package/dist/utility/wrun/sources/lanes/ethena_positions.d.ts +30 -0
- package/dist/utility/wrun/sources/lanes/ethena_positions.js +51 -0
- package/dist/utility/wrun/sources/lanes/index.d.ts +2 -0
- package/dist/utility/wrun/sources/lanes/index.js +32 -0
- package/dist/utility/wrun/sources/lanes/long_short_ratio.d.ts +17 -0
- package/dist/utility/wrun/sources/lanes/long_short_ratio.js +47 -0
- package/dist/utility/wrun/sources/lanes/option_daily.d.ts +58 -0
- package/dist/utility/wrun/sources/lanes/option_daily.js +111 -0
- package/dist/utility/wrun/sources/lanes/option_stats_10m.d.ts +27 -0
- package/dist/utility/wrun/sources/lanes/option_stats_10m.js +21 -0
- package/dist/utility/wrun/sources/lanes/options_flow.d.ts +50 -0
- package/dist/utility/wrun/sources/lanes/options_flow.js +155 -0
- package/dist/utility/wrun/sources/lanes/options_oi.d.ts +29 -0
- package/dist/utility/wrun/sources/lanes/options_oi.js +59 -0
- package/dist/utility/wrun/sources/lanes/options_volume.d.ts +38 -0
- package/dist/utility/wrun/sources/lanes/options_volume.js +63 -0
- package/dist/utility/wrun/sources/lanes/series.d.ts +67 -0
- package/dist/utility/wrun/sources/lanes/series.js +321 -0
- package/dist/utility/wrun/sources/lanes/token_supply.d.ts +30 -0
- package/dist/utility/wrun/sources/lanes/token_supply.js +145 -0
- package/dist/utility/wrun/sources/lanes/treasury_balance.d.ts +25 -0
- package/dist/utility/wrun/sources/lanes/treasury_balance.js +47 -0
- package/dist/utility/wrun/sources/lanes/volatility_index.d.ts +21 -0
- package/dist/utility/wrun/sources/lanes/volatility_index.js +11 -0
- package/dist/utility/wrun/sources/opra-option-lanes.util.d.ts +215 -0
- package/dist/utility/wrun/sources/opra-option-lanes.util.js +477 -0
- package/dist/utility/wrun/sources/registry.d.ts +21 -0
- package/dist/utility/wrun/sources/registry.js +237 -0
- package/dist/utility/wrun/sources/row-lane-registry.d.ts +28 -0
- package/dist/utility/wrun/sources/row-lane-registry.js +230 -0
- package/dist/utility/wrun/sources/row-lanes/index.d.ts +2 -0
- package/dist/utility/wrun/sources/row-lanes/index.js +12 -0
- package/dist/utility/wrun/sources/row-lanes/option_contract_flow.d.ts +2 -0
- package/dist/utility/wrun/sources/row-lanes/option_contract_flow.js +38 -0
- package/dist/utility/wrun/sources/row-lanes/option_contract_state.d.ts +55 -0
- package/dist/utility/wrun/sources/row-lanes/option_contract_state.js +126 -0
- package/dist/utility/wrun/sources/row-lanes/option_prints.d.ts +4 -0
- package/dist/utility/wrun/sources/row-lanes/option_prints.js +191 -0
- package/dist/utility/wrun/sources/row-lanes/option_strikes.d.ts +62 -0
- package/dist/utility/wrun/sources/row-lanes/option_strikes.js +147 -0
- package/dist/utility/wrun/sources/row-lanes/option_surface.d.ts +70 -0
- package/dist/utility/wrun/sources/row-lanes/option_surface.js +144 -0
- package/dist/utility/wrun/sources/wrun-poll-lane.types.d.ts +309 -0
- package/dist/utility/wrun/sources/wrun-poll-lane.types.js +26 -0
- package/dist/utility/wrun/sources/wrun-poll-lanes.util.d.ts +350 -0
- package/dist/utility/wrun/sources/wrun-poll-lanes.util.js +576 -0
- package/dist/utility/wrun/sources/wrun-row-lane.types.d.ts +275 -0
- package/dist/utility/wrun/sources/wrun-row-lane.types.js +16 -0
- package/dist/utility/wrun/sources/wrun-row-lanes.util.d.ts +207 -0
- package/dist/utility/wrun/sources/wrun-row-lanes.util.js +450 -0
- package/dist/utility/wrun/wrun-browser-sources.leaf.d.ts +28 -0
- package/dist/utility/wrun/wrun-browser-sources.leaf.js +66 -0
- package/dist/utility/wrun/wrun-cloud-record.util.d.ts +65 -0
- package/dist/utility/wrun/wrun-cloud-record.util.js +121 -0
- package/dist/utility/wrun/wrun-daily-lane.util.d.ts +95 -0
- package/dist/utility/wrun/wrun-daily-lane.util.js +297 -0
- package/dist/utility/wrun/wrun-deadline.util.d.ts +52 -0
- package/dist/utility/wrun/wrun-deadline.util.js +82 -0
- package/dist/utility/wrun/wrun-etf-flow-lane.util.d.ts +94 -0
- package/dist/utility/wrun/wrun-etf-flow-lane.util.js +224 -0
- package/dist/utility/wrun/wrun-etf-funds.util.d.ts +82 -0
- package/dist/utility/wrun/wrun-etf-funds.util.js +242 -0
- package/dist/utility/wrun/wrun-frames.d.ts +20 -1
- package/dist/utility/wrun/wrun-frames.js +103 -49
- package/dist/utility/wrun/wrun-hosted-wire-caps.d.ts +2 -2
- package/dist/utility/wrun/wrun-hosted-wire-caps.js +27 -0
- package/dist/utility/wrun/wrun-lane-refusal.leaf.d.ts +22 -0
- package/dist/utility/wrun/wrun-lane-refusal.leaf.js +32 -0
- package/dist/utility/wrun/wrun-lane-warmup.util.d.ts +18 -0
- package/dist/utility/wrun/wrun-lane-warmup.util.js +112 -0
- package/dist/utility/wrun/wrun-leg-close.util.d.ts +57 -0
- package/dist/utility/wrun/wrun-leg-close.util.js +187 -0
- package/dist/utility/wrun/wrun-leg-fetch.util.d.ts +144 -0
- package/dist/utility/wrun/wrun-leg-fetch.util.js +212 -0
- package/dist/utility/wrun/wrun-leg-stream-classes.d.ts +73 -0
- package/dist/utility/wrun/wrun-leg-stream-classes.js +86 -0
- package/dist/utility/wrun/wrun-levels-child.util.d.ts +101 -6
- package/dist/utility/wrun/wrun-levels-child.util.js +335 -157
- package/dist/utility/wrun/wrun-memory-clamp.util.d.ts +33 -0
- package/dist/utility/wrun/wrun-memory-clamp.util.js +146 -0
- package/dist/utility/wrun/wrun-odds-template-market.util.d.ts +51 -0
- package/dist/utility/wrun/wrun-odds-template-market.util.js +251 -0
- package/dist/utility/wrun/wrun-opra-flow.leaf.d.ts +65 -0
- package/dist/utility/wrun/wrun-opra-flow.leaf.js +94 -0
- package/dist/utility/wrun/wrun-opra-lane.util.d.ts +47 -0
- package/dist/utility/wrun/wrun-opra-lane.util.js +58 -0
- package/dist/utility/wrun/wrun-opra-stats.leaf.d.ts +49 -0
- package/dist/utility/wrun/wrun-opra-stats.leaf.js +115 -0
- package/dist/utility/wrun/wrun-opra-underlying.util.d.ts +12 -0
- package/dist/utility/wrun/wrun-opra-underlying.util.js +1 -0
- package/dist/utility/wrun/wrun-option-contract-flow.util.d.ts +142 -0
- package/dist/utility/wrun/wrun-option-contract-flow.util.js +451 -0
- package/dist/utility/wrun/wrun-option-knobs.util.d.ts +43 -0
- package/dist/utility/wrun/wrun-option-knobs.util.js +81 -0
- package/dist/utility/wrun/wrun-option-prints.util.d.ts +144 -0
- package/dist/utility/wrun/wrun-option-prints.util.js +356 -0
- package/dist/utility/wrun/wrun-option-summary-lane.util.d.ts +102 -0
- package/dist/utility/wrun/wrun-option-summary-lane.util.js +143 -0
- package/dist/utility/wrun/wrun-options-chain.util.d.ts +308 -0
- package/dist/utility/wrun/wrun-options-chain.util.js +502 -0
- package/dist/utility/wrun/wrun-overlay-identity.util.d.ts +9 -4
- package/dist/utility/wrun/wrun-overlay-identity.util.js +16 -6
- package/dist/utility/wrun/wrun-panel-mount.lazy.d.ts +10 -0
- package/dist/utility/wrun/wrun-panel-mount.lazy.js +68 -0
- package/dist/utility/wrun/wrun-panel-mount.util.d.ts +377 -0
- package/dist/utility/wrun/wrun-panel-mount.util.js +2251 -0
- package/dist/utility/wrun/wrun-param-map.util.d.ts +298 -0
- package/dist/utility/wrun/wrun-param-map.util.js +581 -0
- package/dist/utility/wrun/wrun-pause-dim.util.d.ts +52 -0
- package/dist/utility/wrun/wrun-pause-dim.util.js +153 -0
- package/dist/utility/wrun/wrun-pin-spelling.util.d.ts +149 -0
- package/dist/utility/wrun/wrun-pin-spelling.util.js +523 -0
- package/dist/utility/wrun/wrun-pin-venues.util.d.ts +116 -0
- package/dist/utility/wrun/wrun-pin-venues.util.js +320 -0
- package/dist/utility/wrun/wrun-pinned-interval.util.d.ts +20 -0
- package/dist/utility/wrun/wrun-pinned-interval.util.js +47 -0
- package/dist/utility/wrun/wrun-plot-gate.types.d.ts +23 -0
- package/dist/utility/wrun/wrun-plot-gate.types.js +7 -0
- package/dist/utility/wrun/wrun-present-bits.util.d.ts +37 -0
- package/dist/utility/wrun/wrun-present-bits.util.js +73 -0
- package/dist/utility/wrun/wrun-protocol-pending.util.d.ts +33 -0
- package/dist/utility/wrun/wrun-protocol-pending.util.js +57 -0
- package/dist/utility/wrun/wrun-refusal.util.d.ts +41 -1
- package/dist/utility/wrun/wrun-refusal.util.js +69 -2
- package/dist/utility/wrun/wrun-registry-errors.util.d.ts +1 -14
- package/dist/utility/wrun/wrun-registry-errors.util.js +0 -16
- package/dist/utility/wrun/wrun-row-source.d.ts +158 -0
- package/dist/utility/wrun/wrun-row-source.js +75 -0
- package/dist/utility/wrun/wrun-run-health.util.d.ts +155 -0
- package/dist/utility/wrun/wrun-run-health.util.js +273 -0
- package/dist/utility/wrun/wrun-run-interval-projection.types.d.ts +14 -0
- package/dist/utility/wrun/wrun-run-interval-projection.types.js +1 -0
- package/dist/utility/wrun/wrun-socket-row-source.d.ts +439 -0
- package/dist/utility/wrun/wrun-socket-row-source.js +1689 -0
- package/dist/utility/wrun/wrun-socket-session-losses.util.d.ts +18 -0
- package/dist/utility/wrun/wrun-socket-session-losses.util.js +25 -0
- package/dist/utility/wrun/wrun-source-rows.util.d.ts +911 -0
- package/dist/utility/wrun/wrun-source-rows.util.js +2597 -0
- package/dist/utility/wrun/wrun-tape-source.util.d.ts +82 -0
- package/dist/utility/wrun/wrun-tape-source.util.js +151 -0
- package/dist/utility/wrun/wrun-tier-grid.util.d.ts +137 -0
- package/dist/utility/wrun/wrun-tier-grid.util.js +279 -0
- package/dist/utility/wrun/wrun-trades-lane.util.d.ts +52 -0
- package/dist/utility/wrun/wrun-trades-lane.util.js +58 -0
- package/dist/utility/wrun/wrun-volume-profile-lane.util.d.ts +41 -0
- package/dist/utility/wrun/wrun-volume-profile-lane.util.js +66 -0
- package/dist/utility/wrun-display-name.util.d.ts +33 -0
- package/dist/utility/wrun-display-name.util.js +64 -0
- package/dist/workers/constants/kscript-transport-codes.d.ts +15 -0
- package/dist/workers/constants/kscript-transport-codes.js +15 -0
- package/dist/workers/constants/socket-slots.d.ts +574 -0
- package/dist/workers/constants/socket-slots.js +539 -0
- package/dist/workers/utils/number.worker.util.d.ts +5 -0
- package/dist/workers/utils/number.worker.util.js +10 -0
- package/dist/workers/utils/time.worker.util.d.ts +12 -0
- package/dist/workers/utils/time.worker.util.js +24 -0
- package/dist/workers/utils/volume-profile.worker.util.d.ts +200 -0
- package/dist/workers/utils/volume-profile.worker.util.js +631 -0
- package/package.json +10 -4
|
@@ -0,0 +1,926 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* RTH (regular trading hours) session support for the VOLUME_PROFILE_AGG
|
|
3
|
+
* indicator family on CME-governed futures.
|
|
4
|
+
*
|
|
5
|
+
* The gateway honors `tradingHour = REGULAR` on VOLUME_PROFILE_AGG StreamPoints
|
|
6
|
+
* requests by dropping whole interval buckets whose START lies outside the
|
|
7
|
+
* plan venue's REGULAR window, DST-aware in America/New_York: 09:00-14:30 for
|
|
8
|
+
* an explicit all-NYMEX plan (the energy pit session) and 09:30-16:15 for
|
|
9
|
+
* every other CME-group plan (tsdb-gateway `SessionVenueGroupOf` and
|
|
10
|
+
* `BuildWhereTradingHour`). This module owns everything the frontend needs
|
|
11
|
+
* around that: which symbols have an RTH window and which window
|
|
12
|
+
* (`rthWindowForExchange`, the one place hours are chosen), whether the
|
|
13
|
+
* per-overlay `sessionHours` setting is ACTIVE for a chart interval, the
|
|
14
|
+
* effective fetch interval that keeps profiles boundary-exact at coarse
|
|
15
|
+
* intraday chart intervals, and DST-correct client-side window membership.
|
|
16
|
+
*
|
|
17
|
+
* Worker-safe by design: no Vue / store / i18n imports (workers filter fetched
|
|
18
|
+
* rows through `isWithinRthWindow`, the live-feed service gates merges).
|
|
19
|
+
*
|
|
20
|
+
* The ROOT SET mirrors the engine's venue-sessions module
|
|
21
|
+
* (`@orangecharts/kscript` `dist/kscript/venue-sessions.d.ts`): when a root
|
|
22
|
+
* is added there, add it here in the same wave (and vice versa). The
|
|
23
|
+
* published package ships ONLY the .d.ts for that subpath (the implementation
|
|
24
|
+
* is bundled and mangled inside `dist/kscript-engine.js` and not re-exported
|
|
25
|
+
* from the main entry), so the runtime import cannot resolve; `futuresRootOf`
|
|
26
|
+
* below is a verbatim mirror of the engine source. The WINDOWS follow the
|
|
27
|
+
* wire, not the engine: the engine table (3.0.94) still gives the NYMEX
|
|
28
|
+
* energy roots the uniform 09:30-16:15 window, so `inSession(session="rth")`
|
|
29
|
+
* and `vwap(session="rth")` on those roots disagree with the chart until the
|
|
30
|
+
* engine adopts the energy window; the wrun session facts stay on the
|
|
31
|
+
* engine's table through `engineRthWindowForSymbol` so browser and cloud runs
|
|
32
|
+
* agree. Swap these exports for re-exports of the engine subpath once a
|
|
33
|
+
* release emits the module as importable JS and carries the same windows.
|
|
34
|
+
*/
|
|
35
|
+
import dayjs from 'dayjs';
|
|
36
|
+
import timezone from 'dayjs/plugin/timezone.js';
|
|
37
|
+
import utc from 'dayjs/plugin/utc.js';
|
|
38
|
+
import { Intervals } from '../../constants/interval.constants.js';
|
|
39
|
+
import { isCmeGoverned, normalizeExchangeCode } from './cme-realtime.util.js';
|
|
40
|
+
import { intervalLabelForMs, isSubMinuteInterval, standardIntervalMsAtOrBelow } from './interval-registry.util.js';
|
|
41
|
+
dayjs.extend(utc);
|
|
42
|
+
dayjs.extend(timezone);
|
|
43
|
+
/**
|
|
44
|
+
* CME Group's platform RTH, 09:30-16:15 America/New_York: the REGULAR window
|
|
45
|
+
* the gateway serves every explicit CME, CBOT and COMEX plan
|
|
46
|
+
* (`SessionVenueGroupCMEFutures`, pinned to `cmeRegularSessionAnchor`).
|
|
47
|
+
* TradingView parity: TV applies one family-wide RTH window, 08:30-15:15
|
|
48
|
+
* America/Chicago, rather than per-product pit hours; 15:15 Chicago is the
|
|
49
|
+
* CME equity maintenance halt. The close mirrors the WIRE filter exactly:
|
|
50
|
+
* the gateway widens REGULAR to the 16:15 close for these plans on filtered
|
|
51
|
+
* widths up to 30m (gateway feat/cme-regular-1615). Crypto futures ride the
|
|
52
|
+
* same window as the 2026-08-16 TV-parity decision (the previous 16:00
|
|
53
|
+
* settlement-print close is a one-line revert here AND in the engine if the
|
|
54
|
+
* product ever wants it back). Metals (COMEX) and grains (CBOT) keep it
|
|
55
|
+
* until the gateway can represent their off-grid pit hours (the V3-15 note
|
|
56
|
+
* in tsdb-gateway `pkg/tsdb/selects/builder.go`). Bitcoin Friday Futures
|
|
57
|
+
* fail open on purpose (weekly symbols do not match the contract shape).
|
|
58
|
+
*/
|
|
59
|
+
const CME_PLATFORM_RTH = Object.freeze({
|
|
60
|
+
timeZone: 'America/New_York',
|
|
61
|
+
openMinutes: 570,
|
|
62
|
+
closeMinutes: 975,
|
|
63
|
+
});
|
|
64
|
+
/**
|
|
65
|
+
* The NYMEX energy pit session, 09:00-14:30 America/New_York: the REGULAR
|
|
66
|
+
* window the gateway serves an explicit all-NYMEX plan
|
|
67
|
+
* (`SessionVenueGroupCMEEnergy`, pinned to `cmeEnergySessionAnchor`). Both
|
|
68
|
+
* bounds sit on the 15m grid, so the wire filter is exact at every filtered
|
|
69
|
+
* width (no admit-whole overhang at 30m). The open sits on the UTC hour grid
|
|
70
|
+
* in both DST eras, so the gateway serves 1h REGULAR bars on its plain
|
|
71
|
+
* hourly `time_bucket` and anchors the other widths above 30m on the New
|
|
72
|
+
* York wall clock at 09:00 (4h bars at 09:00 and 13:00); `open + n*tf`
|
|
73
|
+
* (`rthAnchoredBucketStartMs`) lands on the same bars at every width.
|
|
74
|
+
*/
|
|
75
|
+
const NYMEX_ENERGY_RTH = Object.freeze({
|
|
76
|
+
timeZone: 'America/New_York',
|
|
77
|
+
openMinutes: 540,
|
|
78
|
+
closeMinutes: 870,
|
|
79
|
+
});
|
|
80
|
+
/**
|
|
81
|
+
* The exchange each root with an RTH window lists on. Hours never live on a
|
|
82
|
+
* root: `getRthWindowForSymbol` reads the root's exchange through
|
|
83
|
+
* `rthWindowForExchange`, the way the gateway picks the window from the
|
|
84
|
+
* plan's venue.
|
|
85
|
+
*/
|
|
86
|
+
const RTH_ROOT_EXCHANGES = {
|
|
87
|
+
// Equity index
|
|
88
|
+
ES: 'CME',
|
|
89
|
+
NQ: 'CME',
|
|
90
|
+
YM: 'CBOT',
|
|
91
|
+
RTY: 'CME',
|
|
92
|
+
EMD: 'CME',
|
|
93
|
+
MES: 'CME',
|
|
94
|
+
MNQ: 'CME',
|
|
95
|
+
MYM: 'CBOT',
|
|
96
|
+
M2K: 'CME',
|
|
97
|
+
MMC: 'CME',
|
|
98
|
+
SMC: 'CME',
|
|
99
|
+
MSC: 'CME',
|
|
100
|
+
// Crypto
|
|
101
|
+
BTC: 'CME',
|
|
102
|
+
MBT: 'CME',
|
|
103
|
+
ETH: 'CME',
|
|
104
|
+
MET: 'CME',
|
|
105
|
+
SOL: 'CME',
|
|
106
|
+
MSL: 'CME',
|
|
107
|
+
XRP: 'CME',
|
|
108
|
+
MXP: 'CME',
|
|
109
|
+
// Energy
|
|
110
|
+
CL: 'NYMEX',
|
|
111
|
+
MCL: 'NYMEX',
|
|
112
|
+
NG: 'NYMEX',
|
|
113
|
+
RB: 'NYMEX',
|
|
114
|
+
HO: 'NYMEX',
|
|
115
|
+
BZ: 'NYMEX',
|
|
116
|
+
// Metals
|
|
117
|
+
GC: 'COMEX',
|
|
118
|
+
MGC: 'COMEX',
|
|
119
|
+
SI: 'COMEX',
|
|
120
|
+
SIL: 'COMEX',
|
|
121
|
+
HG: 'COMEX',
|
|
122
|
+
MHG: 'COMEX',
|
|
123
|
+
// Treasuries
|
|
124
|
+
ZT: 'CBOT',
|
|
125
|
+
ZF: 'CBOT',
|
|
126
|
+
ZN: 'CBOT',
|
|
127
|
+
TN: 'CBOT',
|
|
128
|
+
ZB: 'CBOT',
|
|
129
|
+
UB: 'CBOT',
|
|
130
|
+
// FX
|
|
131
|
+
'6E': 'CME',
|
|
132
|
+
'6B': 'CME',
|
|
133
|
+
'6J': 'CME',
|
|
134
|
+
'6C': 'CME',
|
|
135
|
+
// Grains
|
|
136
|
+
ZC: 'CBOT',
|
|
137
|
+
ZW: 'CBOT',
|
|
138
|
+
KE: 'CBOT',
|
|
139
|
+
ZS: 'CBOT',
|
|
140
|
+
ZL: 'CBOT',
|
|
141
|
+
};
|
|
142
|
+
/**
|
|
143
|
+
* The RTH window of a CME-group exchange, the client mirror of tsdb-gateway
|
|
144
|
+
* `SessionVenueGroupOf`: NYMEX serves the energy pit session, CME, CBOT and
|
|
145
|
+
* COMEX the platform RTH. Null for every other code, the GLOBEX alias
|
|
146
|
+
* included (a root resolves through the exchange it lists on, never through
|
|
147
|
+
* the alias).
|
|
148
|
+
*/
|
|
149
|
+
export function rthWindowForExchange(exchange) {
|
|
150
|
+
switch (normalizeExchangeCode(exchange)) {
|
|
151
|
+
case 'NYMEX':
|
|
152
|
+
return NYMEX_ENERGY_RTH;
|
|
153
|
+
case 'CME':
|
|
154
|
+
case 'CBOT':
|
|
155
|
+
case 'COMEX':
|
|
156
|
+
return CME_PLATFORM_RTH;
|
|
157
|
+
default:
|
|
158
|
+
return null;
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* Each mapped root's window, resolved once through `rthWindowForExchange`:
|
|
163
|
+
* live-tick gates and the CVD sub-row walk read a symbol's window per call, so
|
|
164
|
+
* the lookup stays one Map read.
|
|
165
|
+
*/
|
|
166
|
+
const RTH_WINDOW_BY_ROOT = new Map(Object.entries(RTH_ROOT_EXCHANGES).flatMap(([root, exchange]) => {
|
|
167
|
+
const window = rthWindowForExchange(exchange);
|
|
168
|
+
return window ? [[root, window]] : [];
|
|
169
|
+
}));
|
|
170
|
+
/**
|
|
171
|
+
* Futures root of a raw contract symbol: leading letters before the
|
|
172
|
+
* month-code + year digits suffix ("ESU6" -> "ES", "MNQZ26" -> "MNQ").
|
|
173
|
+
* Returns null when the symbol does not look like a dated futures contract.
|
|
174
|
+
*/
|
|
175
|
+
export function futuresRootOf(symbol) {
|
|
176
|
+
if (typeof symbol !== 'string')
|
|
177
|
+
return null;
|
|
178
|
+
const match = /^([A-Z0-9]+?)[FGHJKMNQUVXZ]\d{1,2}$/.exec(symbol.toUpperCase());
|
|
179
|
+
return match ? match[1] : null;
|
|
180
|
+
}
|
|
181
|
+
/**
|
|
182
|
+
* The RTH window for a contract symbol: its root's listing exchange through
|
|
183
|
+
* `rthWindowForExchange`, or null for unmapped roots. Continuous symbols
|
|
184
|
+
* (`ES1!`, `BTC1!`) resolve through their root so the toggle works on the
|
|
185
|
+
* primary way CME futures are charted; unmapped roots stay null.
|
|
186
|
+
*/
|
|
187
|
+
export function getRthWindowForSymbol(symbol) {
|
|
188
|
+
const root = futuresRootOf(symbol) ?? continuousRthRootOf(symbol);
|
|
189
|
+
return root ? (RTH_WINDOW_BY_ROOT.get(root) ?? null) : null;
|
|
190
|
+
}
|
|
191
|
+
/**
|
|
192
|
+
* The RTH window the kScript engine's venue-sessions table gives a symbol:
|
|
193
|
+
* the platform window for every mapped root, NYMEX included (engine 3.0.94).
|
|
194
|
+
* Script-facing session facts read this one (wrun `time.session`,
|
|
195
|
+
* wrun-bar-session-facts.util), so a browser run of an indicator agrees with
|
|
196
|
+
* its cloud run and with the engine's `inSession` / `vwap(session="rth")`;
|
|
197
|
+
* every chart gate reads `getRthWindowForSymbol`. It moves to the exchange
|
|
198
|
+
* windows only in a coordinated change of the engine, the WRUN-SESSIONS C3
|
|
199
|
+
* golden and the cloud lanes. Null for an unmapped root.
|
|
200
|
+
*/
|
|
201
|
+
export function engineRthWindowForSymbol(symbol) {
|
|
202
|
+
return getRthWindowForSymbol(symbol) === null ? null : CME_PLATFORM_RTH;
|
|
203
|
+
}
|
|
204
|
+
/** Root of a `<ROOT>1!` continuous symbol, mirroring the engine's fallback. */
|
|
205
|
+
function continuousRthRootOf(symbol) {
|
|
206
|
+
if (typeof symbol !== 'string')
|
|
207
|
+
return null;
|
|
208
|
+
const match = /^([A-Z0-9]+?)1!$/.exec(symbol.trim().toUpperCase());
|
|
209
|
+
return match ? match[1] : null;
|
|
210
|
+
}
|
|
211
|
+
// ─── The sessionHours overlay setting ────────────────────────────────────────
|
|
212
|
+
export const SESSION_HOURS_ETH = 'eth';
|
|
213
|
+
export const SESSION_HOURS_RTH = 'rth';
|
|
214
|
+
/** Follow the chart-level session switch (the per-overlay default). */
|
|
215
|
+
export const SESSION_HOURS_CHART = 'chart';
|
|
216
|
+
/**
|
|
217
|
+
* Normalize a persisted/unknown value. Explicit 'rth'/'eth' are overrides;
|
|
218
|
+
* anything else (unset, legacy junk) follows the chart (the default).
|
|
219
|
+
*/
|
|
220
|
+
export function resolveSessionHoursSetting(value) {
|
|
221
|
+
if (value === SESSION_HOURS_RTH)
|
|
222
|
+
return SESSION_HOURS_RTH;
|
|
223
|
+
if (value === SESSION_HOURS_ETH)
|
|
224
|
+
return SESSION_HOURS_ETH;
|
|
225
|
+
return SESSION_HOURS_CHART;
|
|
226
|
+
}
|
|
227
|
+
/**
|
|
228
|
+
* Collapse an overlay's saved session-hours choice to the EFFECTIVE session:
|
|
229
|
+
* 'chart' (the default) inherits the chart's RTH state, explicit 'eth'/'rth'
|
|
230
|
+
* override it regardless of what the chart is doing.
|
|
231
|
+
*/
|
|
232
|
+
export function resolveEffectiveSessionHours(overlaySessionHours, chartRthActive) {
|
|
233
|
+
const setting = resolveSessionHoursSetting(overlaySessionHours);
|
|
234
|
+
if (setting !== SESSION_HOURS_CHART)
|
|
235
|
+
return setting;
|
|
236
|
+
return chartRthActive ? SESSION_HOURS_RTH : SESSION_HOURS_ETH;
|
|
237
|
+
}
|
|
238
|
+
/**
|
|
239
|
+
* Whether the RTH toggle is offerable at all for this market: a CME-governed
|
|
240
|
+
* venue whose symbol resolves an RTH window. Unmapped roots fail CLOSED here
|
|
241
|
+
* (no toggle), while `isWithinRthWindow` fails OPEN (never drop data the toggle
|
|
242
|
+
* could not have filtered).
|
|
243
|
+
*
|
|
244
|
+
* The venue gate reads `isCmeGoverned` directly rather than the equivalent
|
|
245
|
+
* `isCmeFuturesPolicyActive`, so this module keeps the light worker-safe import
|
|
246
|
+
* graph trading-day.util established instead of pulling marketKind.util's
|
|
247
|
+
* capabilities registry into every worker and spec that touches the VP family.
|
|
248
|
+
*/
|
|
249
|
+
export function hasRthWindow(symbol, exchange) {
|
|
250
|
+
const exchangeCode = typeof exchange === 'string' ? exchange : undefined;
|
|
251
|
+
if (!isCmeGoverned(exchangeCode))
|
|
252
|
+
return false;
|
|
253
|
+
return getRthWindowForSymbol(symbol) !== null;
|
|
254
|
+
}
|
|
255
|
+
export function isIntradayIntervalMs(chartTfMs) {
|
|
256
|
+
return typeof chartTfMs === 'number' && chartTfMs > 0 && chartTfMs < Intervals.map_unit['1d'];
|
|
257
|
+
}
|
|
258
|
+
/**
|
|
259
|
+
* The 30m bucket-grid exactness ceiling shared by every surface that keeps
|
|
260
|
+
* the CHART interval on the wire (main-series candles, the footprint): the
|
|
261
|
+
* gateway keeps/drops WHOLE buckets by their start: both opens (09:30 New
|
|
262
|
+
* York, 09:00 on NYMEX) sit on the 30m grid, while a 1h or 4h bucket
|
|
263
|
+
* straddling the 09:30 open would be dropped whole and silently under-count
|
|
264
|
+
* the cash session. The 16:15 close is exact through 15m; at 30m the 16:00
|
|
265
|
+
* bucket is admitted whole (its start is in-window), matching the engine's
|
|
266
|
+
* pinned admit-whole rule. The NYMEX 14:30 close is exact through 30m.
|
|
267
|
+
*/
|
|
268
|
+
export function isRthBucketExactIntervalMs(chartTfMs) {
|
|
269
|
+
return typeof chartTfMs === 'number' && chartTfMs > 0 && chartTfMs <= Intervals.map_unit['30m'];
|
|
270
|
+
}
|
|
271
|
+
/**
|
|
272
|
+
* The footprint's RTH interval gate: the original consumer of the 30m
|
|
273
|
+
* bucket-grid ceiling (its fetch interval is never overridden). Kept as a
|
|
274
|
+
* named export; the shared predicate above is the one the chart-level
|
|
275
|
+
* session switch reuses.
|
|
276
|
+
*/
|
|
277
|
+
export function isFootprintRthIntervalMs(chartTfMs) {
|
|
278
|
+
return isRthBucketExactIntervalMs(chartTfMs);
|
|
279
|
+
}
|
|
280
|
+
/**
|
|
281
|
+
* The coarse intervals whose RTH candle lattice the gateway serves
|
|
282
|
+
* SESSION-ANCHORED at the 09:30 New York open: every intraday width above the
|
|
283
|
+
* 30m grid (tsdb-gateway `tradingHourNeedsAnchoredBucket`: 1h and 4h, and the
|
|
284
|
+
* rolled-up 45m 2h 6h 8h 12h since !2151). These are the intervals where the
|
|
285
|
+
* footprint's 15m-fetch-and-fold targets the anchored grid, and where regular
|
|
286
|
+
* equities bars and live ticks key onto it. On NYMEX the lattice starts at
|
|
287
|
+
* the 09:00 open; there the 1h grid is the plain UTC hour (the gateway skips
|
|
288
|
+
* anchoring it), which the open-anchored fold reproduces.
|
|
289
|
+
*/
|
|
290
|
+
const FOOTPRINT_RTH_FOLD_TF_MS = new Set(['45m', '1h', '2h', '4h', '6h', '8h', '12h'].map((label) => Intervals.map_unit[label]));
|
|
291
|
+
export function isFootprintRthFoldTfMs(chartTfMs) {
|
|
292
|
+
return typeof chartTfMs === 'number' && FOOTPRINT_RTH_FOLD_TF_MS.has(chartTfMs);
|
|
293
|
+
}
|
|
294
|
+
/**
|
|
295
|
+
* Chart-format interval to milliseconds: numbers pass through, '15m'-style
|
|
296
|
+
* labels resolve via the interval table, anything else is undefined (which
|
|
297
|
+
* every RTH predicate treats as inactive).
|
|
298
|
+
*/
|
|
299
|
+
export function chartIntervalToMs(interval) {
|
|
300
|
+
if (typeof interval === 'number')
|
|
301
|
+
return interval;
|
|
302
|
+
if (typeof interval === 'string') {
|
|
303
|
+
const ms = Intervals.map_unit[interval];
|
|
304
|
+
return typeof ms === 'number' ? ms : undefined;
|
|
305
|
+
}
|
|
306
|
+
return undefined;
|
|
307
|
+
}
|
|
308
|
+
// ─── The chart-level session switch ──────────────────────────────────────────
|
|
309
|
+
/**
|
|
310
|
+
* Whether the CHART itself is in RTH mode: a CME-governed venue whose symbol
|
|
311
|
+
* resolves an RTH window, the persisted chart `sessionType` is 'regular'
|
|
312
|
+
* (unset means ETH on futures; the equities meaning of unset is owned by the
|
|
313
|
+
* Polygon branch of `resolveCandleTradingHour` and never reaches this
|
|
314
|
+
* predicate), AND the chart interval sits on the 30m bucket-exact grid
|
|
315
|
+
* (candles keep the chart interval on the wire, so above 30m the effective
|
|
316
|
+
* mode falls back to ETH while the persisted choice is kept).
|
|
317
|
+
*
|
|
318
|
+
* Ordered cheapest-first on purpose: live-tick gates call this per frame, and
|
|
319
|
+
* the sessionType compare short-circuits everything for non-RTH charts.
|
|
320
|
+
*/
|
|
321
|
+
export function isChartRthActive(exchange, symbol, sessionType, chartTfMs) {
|
|
322
|
+
if (sessionType !== 'regular')
|
|
323
|
+
return false;
|
|
324
|
+
// Any intraday interval: above 30m the gateway's trading-hour path
|
|
325
|
+
// re-aggregates from the 15m base with session-anchored buckets
|
|
326
|
+
// (tsdb-gateway feat/rth-anchored-buckets), so coarse RTH candles are
|
|
327
|
+
// volume-complete and open-anchored. Daily+ stays ETH (a UTC daily bucket
|
|
328
|
+
// already contains the whole session). The footprint keeps its own 30m
|
|
329
|
+
// ceiling: its per-bar ladders ride the drop-semantics filter, not this path.
|
|
330
|
+
if (!isIntradayIntervalMs(chartTfMs))
|
|
331
|
+
return false;
|
|
332
|
+
return hasRthWindow(symbol, exchange);
|
|
333
|
+
}
|
|
334
|
+
/**
|
|
335
|
+
* The default persisted `sessionType` for a chart's market: futures with a
|
|
336
|
+
* governed RTH window default to 'extended' (ETH, the full Globex session)
|
|
337
|
+
* so settings confirms can never silently stamp them into RTH; every other
|
|
338
|
+
* market keeps the historical 'regular' default (for Polygon equities unset
|
|
339
|
+
* and 'regular' both mean the regular session, byte-identical to today).
|
|
340
|
+
*/
|
|
341
|
+
export function defaultChartSessionType(symbol, exchange) {
|
|
342
|
+
return hasRthWindow(symbol, exchange) ? 'extended' : 'regular';
|
|
343
|
+
}
|
|
344
|
+
/**
|
|
345
|
+
* The `sessionType` a chart carries through a symbol switch. The RTH/ETH
|
|
346
|
+
* choice stays only while the chart moves between futures with an RTH window
|
|
347
|
+
* (ES1! in RTH stays RTH on NQ1!); a switch into or out of that family takes
|
|
348
|
+
* the incoming market's default. Carried as-is, the 'regular' a crypto or
|
|
349
|
+
* equities chart stamps by default opened every future it switched to in RTH,
|
|
350
|
+
* frozen on the last cash-session bar while Globex traded.
|
|
351
|
+
*/
|
|
352
|
+
export function sessionTypeAfterSymbolSwitch(previous, next) {
|
|
353
|
+
if (hasRthWindow(previous.symbol, previous.exchange) === hasRthWindow(next.symbol, next.exchange)) {
|
|
354
|
+
return previous.sessionType;
|
|
355
|
+
}
|
|
356
|
+
return defaultChartSessionType(next.symbol, next.exchange);
|
|
357
|
+
}
|
|
358
|
+
/**
|
|
359
|
+
* The single activity decision every RTH consumer shares: the overlay's
|
|
360
|
+
* EFFECTIVE session is RTH (explicit 'rth', or the 'chart' default while the
|
|
361
|
+
* chart-level switch is active; callers that can know the chart state pass
|
|
362
|
+
* `chartRthActive`, everything else fails safe to ETH), the venue+symbol
|
|
363
|
+
* resolve a window, AND the chart interval is intraday (a DAY-interval
|
|
364
|
+
* request under the gateway filter returns zero rows, so daily+ charts
|
|
365
|
+
* always behave as ETH; the settings UI hides the toggle there too).
|
|
366
|
+
*/
|
|
367
|
+
export function isRthSessionHoursActive(settings, chartTfMs, chartRthActive = false) {
|
|
368
|
+
if (!settings)
|
|
369
|
+
return false;
|
|
370
|
+
if (resolveEffectiveSessionHours(settings.sessionHours, chartRthActive) !== SESSION_HOURS_RTH)
|
|
371
|
+
return false;
|
|
372
|
+
if (!isIntradayIntervalMs(chartTfMs))
|
|
373
|
+
return false;
|
|
374
|
+
return hasRthWindow(settings.symbol, settings.exchange);
|
|
375
|
+
}
|
|
376
|
+
// ─── Effective fetch interval ────────────────────────────────────────────────
|
|
377
|
+
const RTH_EFFECTIVE_FETCH_MIN_TF_MS = Intervals.map_unit['1m'];
|
|
378
|
+
const RTH_EFFECTIVE_FETCH_MAX_TF_MS = Intervals.map_unit['15m'];
|
|
379
|
+
/**
|
|
380
|
+
* The wire interval an RTH-filtered profile fetch should use:
|
|
381
|
+
* min(chartTf, 15m), floored at 1m, then snapped to the standard width at or
|
|
382
|
+
* below it. The gateway drops whole buckets whose start lies outside the
|
|
383
|
+
* window, so a coarse bucket straddling the open (e.g. a 1h bucket starting
|
|
384
|
+
* 09:00 ET) would vanish and under-count the profile; capping at 15m keeps
|
|
385
|
+
* every kept/dropped decision boundary-exact (09:30 and 16:15 ET are both on
|
|
386
|
+
* the 15m grid, as are NYMEX's 09:00 and 14:30) while profile aggregation
|
|
387
|
+
* absorbs the finer rows. The snap covers the custom widths under 15m (2m
|
|
388
|
+
* and 3m fetch 1m, 10m fetches 5m): the gateway serves those by rolling up a
|
|
389
|
+
* finer tier and refuses a trading-hour plan at a rolled width ("trading
|
|
390
|
+
* hour sessions are not served at this interval"), and a 2m or 10m bucket
|
|
391
|
+
* would straddle the 16:15 close anyway. Every result is a natively served
|
|
392
|
+
* width (1m / 5m / 15m).
|
|
393
|
+
*/
|
|
394
|
+
export function rthEffectiveFetchTfMs(chartTfMs) {
|
|
395
|
+
if (!Number.isFinite(chartTfMs) || chartTfMs <= 0)
|
|
396
|
+
return RTH_EFFECTIVE_FETCH_MIN_TF_MS;
|
|
397
|
+
return standardIntervalMsAtOrBelow(Math.max(RTH_EFFECTIVE_FETCH_MIN_TF_MS, Math.min(chartTfMs, RTH_EFFECTIVE_FETCH_MAX_TF_MS)));
|
|
398
|
+
}
|
|
399
|
+
/**
|
|
400
|
+
* The wire interval a footprint's RTH fold fetches: the 1s tier under a 5s,
|
|
401
|
+
* 15s or 30s bar (the gateway rolls those from 1s and refuses a trading-hour
|
|
402
|
+
* plan at a rolled width, while 1s is a tier of its own and serves one), else
|
|
403
|
+
* `rthEffectiveFetchTfMs` (1m for 2m and 3m, 5m for 10m, 15m from 45m up).
|
|
404
|
+
* The range profiles keep that 1m floor. Shared by the footprint's request
|
|
405
|
+
* resolver and its worker, so the fetch and the cache key cannot drift.
|
|
406
|
+
*/
|
|
407
|
+
export function footprintRthFoldFetchTfMs(chartTfMs) {
|
|
408
|
+
return isSubMinuteInterval(intervalLabelForMs(chartTfMs))
|
|
409
|
+
? standardIntervalMsAtOrBelow(chartTfMs)
|
|
410
|
+
: rthEffectiveFetchTfMs(chartTfMs);
|
|
411
|
+
}
|
|
412
|
+
/**
|
|
413
|
+
* The timestamp grid live VP rows must land on for an RTH-active overlay so
|
|
414
|
+
* they line up with fetched history: the effective fetch interval for the
|
|
415
|
+
* range profiles, the chart interval for the footprint (per-bar ladders are
|
|
416
|
+
* its identity, its fetch interval is never overridden).
|
|
417
|
+
*/
|
|
418
|
+
export function rthLiveMergeIntervalMs(ovType, chartTfMs) {
|
|
419
|
+
if (ovType === 'VOLUME_FOOTPRINT')
|
|
420
|
+
return chartTfMs;
|
|
421
|
+
return rthEffectiveFetchTfMs(chartTfMs);
|
|
422
|
+
}
|
|
423
|
+
// ─── DST-correct window membership ───────────────────────────────────────────
|
|
424
|
+
// Venue-zone wall-clock arithmetic on Intl.DateTimeFormat, not dayjs: the
|
|
425
|
+
// dayjs timezone plugin resolves `startOf('day')` and `dayjs.tz(wall, zone)`
|
|
426
|
+
// through the HOST zone's offset, which drifts by an hour on the venue's
|
|
427
|
+
// DST days when the host's own DST differs (Phoenix, Honolulu, London around
|
|
428
|
+
// October). Intl parts are host-independent, ~1 us with a cached formatter.
|
|
429
|
+
const zoneFormatters = new Map();
|
|
430
|
+
function zoneFormatter(zone) {
|
|
431
|
+
let formatter = zoneFormatters.get(zone);
|
|
432
|
+
if (!formatter) {
|
|
433
|
+
formatter = new Intl.DateTimeFormat('en-US', {
|
|
434
|
+
timeZone: zone,
|
|
435
|
+
hourCycle: 'h23',
|
|
436
|
+
year: 'numeric',
|
|
437
|
+
month: 'numeric',
|
|
438
|
+
day: 'numeric',
|
|
439
|
+
hour: 'numeric',
|
|
440
|
+
minute: 'numeric',
|
|
441
|
+
second: 'numeric',
|
|
442
|
+
});
|
|
443
|
+
zoneFormatters.set(zone, formatter);
|
|
444
|
+
}
|
|
445
|
+
return formatter;
|
|
446
|
+
}
|
|
447
|
+
/** The wall clock `tsMs` reads in `zone`. Throws (RangeError) on an unknown zone, like the old dayjs path. */
|
|
448
|
+
function zoneWallParts(zone, tsMs) {
|
|
449
|
+
const parts = { year: 0, month: 0, day: 0, hour: 0, minute: 0, second: 0 };
|
|
450
|
+
for (const part of zoneFormatter(zone).formatToParts(tsMs)) {
|
|
451
|
+
switch (part.type) {
|
|
452
|
+
case 'year':
|
|
453
|
+
parts.year = Number(part.value);
|
|
454
|
+
break;
|
|
455
|
+
case 'month':
|
|
456
|
+
parts.month = Number(part.value);
|
|
457
|
+
break;
|
|
458
|
+
case 'day':
|
|
459
|
+
parts.day = Number(part.value);
|
|
460
|
+
break;
|
|
461
|
+
case 'hour':
|
|
462
|
+
parts.hour = Number(part.value) % 24;
|
|
463
|
+
break;
|
|
464
|
+
case 'minute':
|
|
465
|
+
parts.minute = Number(part.value);
|
|
466
|
+
break;
|
|
467
|
+
case 'second':
|
|
468
|
+
parts.second = Number(part.value);
|
|
469
|
+
break;
|
|
470
|
+
default:
|
|
471
|
+
break;
|
|
472
|
+
}
|
|
473
|
+
}
|
|
474
|
+
return parts;
|
|
475
|
+
}
|
|
476
|
+
/** Zone offset at `tsMs` as wall minus UTC, in ms (negative west of Greenwich). */
|
|
477
|
+
function zoneOffsetMs(zone, tsMs) {
|
|
478
|
+
const w = zoneWallParts(zone, tsMs);
|
|
479
|
+
const wallAsUtc = Date.UTC(w.year, w.month - 1, w.day, w.hour, w.minute, w.second);
|
|
480
|
+
return wallAsUtc - Math.floor(tsMs / 1000) * 1000;
|
|
481
|
+
}
|
|
482
|
+
/**
|
|
483
|
+
* The instant whose wall clock in `zone` reads `minutes` past midnight on
|
|
484
|
+
* the calendar date (year, month 1-12, day). Two-pass offset resolution: the
|
|
485
|
+
* offset at the naive guess, re-read at the candidate, so a date on either
|
|
486
|
+
* side of a transition lands on its own offset. DST-exact on 23h/25h days
|
|
487
|
+
* (counting real minutes from midnight would drift by the offset delta); the
|
|
488
|
+
* venue windows' instants (midnight, 09:00, 09:30, 14:30, 16:15 New York)
|
|
489
|
+
* never fall inside a transition hour.
|
|
490
|
+
*/
|
|
491
|
+
function zoneWallToUtcMs(zone, year, month, day, minutes) {
|
|
492
|
+
const guess = Date.UTC(year, month - 1, day) + minutes * 60_000;
|
|
493
|
+
const first = guess - zoneOffsetMs(zone, guess);
|
|
494
|
+
const second = guess - zoneOffsetMs(zone, first);
|
|
495
|
+
return second;
|
|
496
|
+
}
|
|
497
|
+
// Per-venue-local-day memo, resolved by SPAN, not by date string: a lookup
|
|
498
|
+
// compares the timestamp against the cached days' [local midnight, next local
|
|
499
|
+
// midnight) spans (most recently hit first) and only a miss pays the dayjs
|
|
500
|
+
// timezone work, once per venue day per window. The old form ran
|
|
501
|
+
// `dayjs(ts).tz(zone).format()` BEFORE its cache lookup, ~25 us per call, and
|
|
502
|
+
// the CVD sub-bar lane resolves every retained sub-row four times per commit:
|
|
503
|
+
// a 779-candle 1h RTH chart holds ~9,300 sub-rows, 37,000 conversions, the
|
|
504
|
+
// 140-790 ms apply stalls behind the 2026-09-25 zoom stutter.
|
|
505
|
+
//
|
|
506
|
+
// Windows are the frozen module constants (one shared object per venue
|
|
507
|
+
// family), so the WeakMap holds one span list per distinct window object; an
|
|
508
|
+
// ad-hoc window object simply misses (correct, slower). Bounded per window:
|
|
509
|
+
// the oldest span falls off past RTH_DAY_SPANS_PER_WINDOW (the CVD lane
|
|
510
|
+
// rebuilds ~115 sessions per commit and the request-window walks step
|
|
511
|
+
// backward through days, so the bound stays well above a session's reach).
|
|
512
|
+
const rthDaySpansByWindow = new WeakMap();
|
|
513
|
+
const RTH_DAY_SPANS_PER_WINDOW = 1024;
|
|
514
|
+
function rthDayBoundsFor(window, tsMs) {
|
|
515
|
+
let spans = rthDaySpansByWindow.get(window);
|
|
516
|
+
if (!spans) {
|
|
517
|
+
spans = [];
|
|
518
|
+
rthDaySpansByWindow.set(window, spans);
|
|
519
|
+
}
|
|
520
|
+
for (let i = 0; i < spans.length; i += 1) {
|
|
521
|
+
const span = spans[i];
|
|
522
|
+
if (tsMs >= span.dayStartMs && tsMs < span.dayEndMs) {
|
|
523
|
+
if (i > 0) {
|
|
524
|
+
// Move-to-front: sorted scans (the CVD store) hit at index 0 for a whole day.
|
|
525
|
+
spans.splice(i, 1);
|
|
526
|
+
spans.unshift(span);
|
|
527
|
+
}
|
|
528
|
+
return span;
|
|
529
|
+
}
|
|
530
|
+
}
|
|
531
|
+
let bounds;
|
|
532
|
+
try {
|
|
533
|
+
const zone = window.timeZone;
|
|
534
|
+
const wall = zoneWallParts(zone, tsMs);
|
|
535
|
+
// The next calendar date through UTC date arithmetic (month/year rollover included).
|
|
536
|
+
const next = new Date(Date.UTC(wall.year, wall.month - 1, wall.day + 1));
|
|
537
|
+
bounds = {
|
|
538
|
+
openMs: zoneWallToUtcMs(zone, wall.year, wall.month, wall.day, window.openMinutes),
|
|
539
|
+
closeMs: zoneWallToUtcMs(zone, wall.year, wall.month, wall.day, window.closeMinutes),
|
|
540
|
+
dayStartMs: zoneWallToUtcMs(zone, wall.year, wall.month, wall.day, 0),
|
|
541
|
+
dayEndMs: zoneWallToUtcMs(zone, next.getUTCFullYear(), next.getUTCMonth() + 1, next.getUTCDate(), 0),
|
|
542
|
+
};
|
|
543
|
+
}
|
|
544
|
+
catch {
|
|
545
|
+
return null;
|
|
546
|
+
}
|
|
547
|
+
spans.unshift(bounds);
|
|
548
|
+
if (spans.length > RTH_DAY_SPANS_PER_WINDOW)
|
|
549
|
+
spans.length = RTH_DAY_SPANS_PER_WINDOW;
|
|
550
|
+
return bounds;
|
|
551
|
+
}
|
|
552
|
+
/**
|
|
553
|
+
* Every venue-local calendar day's `[open, close)` window that touches
|
|
554
|
+
* `[fromMs, toMs]`, in order: the walk steps one calendar day at a time in
|
|
555
|
+
* the window's zone (`rthDayBoundsFor`, so it is DST-exact on 23h/25h days)
|
|
556
|
+
* and keeps a day whose close is after `fromMs` and whose open is before
|
|
557
|
+
* `toMs`. Calendar-based like the other walks: Saturday, Sunday and holidays
|
|
558
|
+
* have mathematical bounds too, which is harmless for consumers that shade
|
|
559
|
+
* or gate BARS (no bar trades 09:30-16:15 New York on a weekend) and wrong
|
|
560
|
+
* for anyone who would count the windows as trading days. Empty for an
|
|
561
|
+
* inverted or non-finite span. Ad-hoc window objects miss the per-window
|
|
562
|
+
* memo (correct, slower); pass the frozen module constants.
|
|
563
|
+
*/
|
|
564
|
+
export function sessionWindowsInRange(window, fromMs, toMs) {
|
|
565
|
+
const windows = [];
|
|
566
|
+
if (!Number.isFinite(fromMs) || !Number.isFinite(toMs) || fromMs > toMs)
|
|
567
|
+
return windows;
|
|
568
|
+
let cursor = fromMs;
|
|
569
|
+
while (cursor <= toMs) {
|
|
570
|
+
const bounds = rthDayBoundsFor(window, cursor);
|
|
571
|
+
// A non-advancing day would loop forever: unreachable with valid zone math, kept as the loop's guard.
|
|
572
|
+
if (!bounds || bounds.dayEndMs <= cursor)
|
|
573
|
+
break;
|
|
574
|
+
if (bounds.closeMs > fromMs && bounds.openMs < toMs)
|
|
575
|
+
windows.push({ openMs: bounds.openMs, closeMs: bounds.closeMs });
|
|
576
|
+
cursor = bounds.dayEndMs;
|
|
577
|
+
}
|
|
578
|
+
return windows;
|
|
579
|
+
}
|
|
580
|
+
/**
|
|
581
|
+
* `sessionWindowsInRange` for a symbol's mapped RTH window; empty for an
|
|
582
|
+
* unmapped root (callers gate on `hasRthWindow` first, like every other
|
|
583
|
+
* session-reset consumer).
|
|
584
|
+
*/
|
|
585
|
+
export function rthWindowsInRange(symbol, fromMs, toMs) {
|
|
586
|
+
const window = getRthWindowForSymbol(symbol);
|
|
587
|
+
if (!window)
|
|
588
|
+
return [];
|
|
589
|
+
return sessionWindowsInRange(window, fromMs, toMs);
|
|
590
|
+
}
|
|
591
|
+
/**
|
|
592
|
+
* Whether `tsMs` falls inside the symbol's RTH window `[open, close)` on its
|
|
593
|
+
* own venue-local calendar day, DST-correct in the window's IANA zone. This
|
|
594
|
+
* matches the gateway's bucket rule (a bucket is kept when its START is
|
|
595
|
+
* inside the window), so gating bucket-start timestamps with it agrees with
|
|
596
|
+
* the server filter.
|
|
597
|
+
*
|
|
598
|
+
* Fails OPEN (returns true) when the symbol has no window: consumers only
|
|
599
|
+
* call this while RTH is active, and dropping data the toggle predicate
|
|
600
|
+
* could not vouch for would blank overlays on a mapping gap.
|
|
601
|
+
*/
|
|
602
|
+
export function isWithinRthWindow(symbol, tsMs) {
|
|
603
|
+
const window = getRthWindowForSymbol(symbol);
|
|
604
|
+
if (!window)
|
|
605
|
+
return true;
|
|
606
|
+
if (!Number.isFinite(tsMs))
|
|
607
|
+
return false;
|
|
608
|
+
const bounds = rthDayBoundsFor(window, tsMs);
|
|
609
|
+
if (!bounds)
|
|
610
|
+
return true;
|
|
611
|
+
return tsMs >= bounds.openMs && tsMs < bounds.closeMs;
|
|
612
|
+
}
|
|
613
|
+
/**
|
|
614
|
+
* The session OPEN instant for an in-session timestamp, or null when the
|
|
615
|
+
* symbol resolves no window or `tsMs` lies outside `[open, close)` on its
|
|
616
|
+
* venue-local day. One value serves two roles for session-reset consumers
|
|
617
|
+
* (CVD reset-at-open): it is a window-membership predicate (null = out of
|
|
618
|
+
* session) AND the session identity (two timestamps share a trading session
|
|
619
|
+
* exactly when their opens are equal), so reset boundaries can never disagree
|
|
620
|
+
* with the filter that admitted the rows. Unmapped symbols return null for
|
|
621
|
+
* EVERY timestamp, so callers must gate on a mapped window first (every
|
|
622
|
+
* session-reset activity predicate requires `hasRthWindow`); only then does
|
|
623
|
+
* null strictly mean "outside the session". DST-correct via the same
|
|
624
|
+
* memoized per-day bounds.
|
|
625
|
+
*/
|
|
626
|
+
export function rthSessionOpenMs(symbol, tsMs) {
|
|
627
|
+
const window = getRthWindowForSymbol(symbol);
|
|
628
|
+
if (!window)
|
|
629
|
+
return null;
|
|
630
|
+
if (!Number.isFinite(tsMs))
|
|
631
|
+
return null;
|
|
632
|
+
const bounds = rthDayBoundsFor(window, tsMs);
|
|
633
|
+
if (!bounds)
|
|
634
|
+
return null;
|
|
635
|
+
if (tsMs < bounds.openMs || tsMs >= bounds.closeMs)
|
|
636
|
+
return null;
|
|
637
|
+
return bounds.openMs;
|
|
638
|
+
}
|
|
639
|
+
/**
|
|
640
|
+
* The EXCLUSIVE close of the trading session containing `tsMs`: the twin of
|
|
641
|
+
* `rthSessionOpenMs` (same null contract: no mapped window, or `tsMs` outside
|
|
642
|
+
* `[open, close)`), for "did the held row reach the session close" checks.
|
|
643
|
+
*/
|
|
644
|
+
export function rthSessionCloseMs(symbol, tsMs) {
|
|
645
|
+
const window = getRthWindowForSymbol(symbol);
|
|
646
|
+
if (!window)
|
|
647
|
+
return null;
|
|
648
|
+
if (!Number.isFinite(tsMs))
|
|
649
|
+
return null;
|
|
650
|
+
const bounds = rthDayBoundsFor(window, tsMs);
|
|
651
|
+
if (!bounds)
|
|
652
|
+
return null;
|
|
653
|
+
if (tsMs < bounds.openMs || tsMs >= bounds.closeMs)
|
|
654
|
+
return null;
|
|
655
|
+
return bounds.closeMs;
|
|
656
|
+
}
|
|
657
|
+
/**
|
|
658
|
+
* The instant a FOLDED footprint bucket stops changing, on either fold grid:
|
|
659
|
+
* anchored buckets end at `min(start + tf, session close)`
|
|
660
|
+
* (`rthAnchoredBucketEndMs`); utc-grid buckets nominally end at `start + tf`
|
|
661
|
+
* but the RTH filter stops feeding them at the session close, so the bucket
|
|
662
|
+
* holding the close is complete at 20:15Z, not at the top of the next hour.
|
|
663
|
+
* Forming/closed classification (the poll-apply gate) must use this end or a
|
|
664
|
+
* closed stub/close-straddling row would count as forming long after it froze.
|
|
665
|
+
*/
|
|
666
|
+
export function footprintFoldBucketEndMs(symbol, bucketStartMs, tfMs, bucketMode) {
|
|
667
|
+
if (bucketMode === 'anchored')
|
|
668
|
+
return rthAnchoredBucketEndMs(symbol, bucketStartMs, tfMs);
|
|
669
|
+
if (!Number.isFinite(bucketStartMs) || !Number.isFinite(tfMs) || tfMs <= 0)
|
|
670
|
+
return null;
|
|
671
|
+
const nominalEnd = bucketStartMs + tfMs;
|
|
672
|
+
const close = rthSessionCloseMs(symbol, bucketStartMs) ?? rthSessionCloseMs(symbol, nominalEnd - 1);
|
|
673
|
+
return close !== null ? Math.min(nominalEnd, close) : nominalEnd;
|
|
674
|
+
}
|
|
675
|
+
/**
|
|
676
|
+
* Does the bucket `[bucketStartMs, bucketStartMs + tfMs)` overlap its venue
|
|
677
|
+
* day's RTH session at all? The live gate for FOLDED footprints on the utc
|
|
678
|
+
* grid: the bucket holding the open (13:00Z for a 13:30Z open) and the one
|
|
679
|
+
* holding the close legitimately carry in-session sub-rows even though their
|
|
680
|
+
* starts sit outside `[open, close)`; the worker already rejected every
|
|
681
|
+
* out-of-session SOURCE frame, so the bucket-start test would wrongly drop
|
|
682
|
+
* them. Anchored buckets start in-session by construction and pass trivially.
|
|
683
|
+
*/
|
|
684
|
+
export function rthBucketOverlapsSessionMs(symbol, bucketStartMs, tfMs) {
|
|
685
|
+
if (!Number.isFinite(bucketStartMs) || !Number.isFinite(tfMs) || tfMs <= 0)
|
|
686
|
+
return false;
|
|
687
|
+
const window = getRthWindowForSymbol(symbol);
|
|
688
|
+
if (!window)
|
|
689
|
+
return false;
|
|
690
|
+
const bucketEndMs = bucketStartMs + tfMs;
|
|
691
|
+
for (const probe of [bucketStartMs, bucketEndMs - 1]) {
|
|
692
|
+
const bounds = rthDayBoundsFor(window, probe);
|
|
693
|
+
if (bounds && bucketStartMs < bounds.closeMs && bucketEndMs > bounds.openMs)
|
|
694
|
+
return true;
|
|
695
|
+
}
|
|
696
|
+
return false;
|
|
697
|
+
}
|
|
698
|
+
/**
|
|
699
|
+
* Session-anchored bucket start for an RTH-mode bar at coarse (>30m)
|
|
700
|
+
* intervals. Above the 30m bucket-exact ceiling the gateway's trading-hour
|
|
701
|
+
* path re-aggregates from the 15m base with buckets anchored at the session
|
|
702
|
+
* OPEN (09:30 America/New_York, 09:00 on NYMEX), stepping `tfMs` within the
|
|
703
|
+
* day; the session's last bucket is a natural partial (nominal width, fewer
|
|
704
|
+
* contributing rows). This is the client-side mirror of that grid, and the
|
|
705
|
+
* ONE boundary source for both live writers: the live-feed forming-bar gate
|
|
706
|
+
* (cme-rth-main-frame-drop) and titan's main-series merger
|
|
707
|
+
* (`buildMergeLiveDataPoint`) derive their bucket keys here, so a live frame
|
|
708
|
+
* merges into the bucket the fetched history actually has and the two paths
|
|
709
|
+
* can never disagree (a UTC-grid floor at 1h keys 13:00Z/14:00Z while EDT
|
|
710
|
+
* session bars sit at 13:30Z/14:30Z).
|
|
711
|
+
*
|
|
712
|
+
* Returns null when the inputs are invalid, the symbol resolves no window,
|
|
713
|
+
* or `tsMs` sits outside `[open, close)` on its venue-local day: out of
|
|
714
|
+
* session there is no anchored bucket the frame could belong to, so live
|
|
715
|
+
* callers treat null as "drop the frame". DST-correct via the same memoized
|
|
716
|
+
* per-day bounds `isWithinRthWindow` rides.
|
|
717
|
+
*/
|
|
718
|
+
export function rthAnchoredBucketStartMs(symbol, tsMs, tfMs) {
|
|
719
|
+
if (!Number.isFinite(tsMs) || !Number.isFinite(tfMs) || tfMs <= 0)
|
|
720
|
+
return null;
|
|
721
|
+
const window = getRthWindowForSymbol(symbol);
|
|
722
|
+
if (!window)
|
|
723
|
+
return null;
|
|
724
|
+
const bounds = rthDayBoundsFor(window, tsMs);
|
|
725
|
+
if (!bounds)
|
|
726
|
+
return null;
|
|
727
|
+
if (tsMs < bounds.openMs || tsMs >= bounds.closeMs)
|
|
728
|
+
return null;
|
|
729
|
+
return bounds.openMs + Math.floor((tsMs - bounds.openMs) / tfMs) * tfMs;
|
|
730
|
+
}
|
|
731
|
+
/**
|
|
732
|
+
* The EXCLUSIVE end of the anchored bucket that starts at `bucketStartMs`:
|
|
733
|
+
* `min(start + tf, session close)`. The session's last bucket is a stub (the
|
|
734
|
+
* 19:30 hourly bar closes at the 20:15 session close), and forming/closed
|
|
735
|
+
* classification must use this end, not `start + tf`. Null mirrors
|
|
736
|
+
* `rthAnchoredBucketStartMs` (no window, or the start is outside its session).
|
|
737
|
+
*/
|
|
738
|
+
export function rthAnchoredBucketEndMs(symbol, bucketStartMs, tfMs) {
|
|
739
|
+
if (!Number.isFinite(bucketStartMs) || !Number.isFinite(tfMs) || tfMs <= 0)
|
|
740
|
+
return null;
|
|
741
|
+
const window = getRthWindowForSymbol(symbol);
|
|
742
|
+
if (!window)
|
|
743
|
+
return null;
|
|
744
|
+
const bounds = rthDayBoundsFor(window, bucketStartMs);
|
|
745
|
+
if (!bounds)
|
|
746
|
+
return null;
|
|
747
|
+
if (bucketStartMs < bounds.openMs || bucketStartMs >= bounds.closeMs)
|
|
748
|
+
return null;
|
|
749
|
+
return Math.min(bucketStartMs + tfMs, bounds.closeMs);
|
|
750
|
+
}
|
|
751
|
+
/**
|
|
752
|
+
* The most recent RTH session bounds whose OPEN is at or before `tsMs`,
|
|
753
|
+
* whether or not `tsMs` is inside the session. `rthSessionOpenMs` answers
|
|
754
|
+
* "which session am I in" (null out of session); this answers "which session
|
|
755
|
+
* did I most recently enter" — the primitive a session-anchored profile needs
|
|
756
|
+
* to show the last completed session outside trading hours. Walks venue-local
|
|
757
|
+
* calendar days backward (bounded) so a post-close Friday timestamp or a
|
|
758
|
+
* weekend one resolves Friday's window. NOTE: the walk is calendar-based; a
|
|
759
|
+
* calendar day with no trading (Saturday, holidays) still has mathematical
|
|
760
|
+
* bounds, so DATA-aware callers must fall back a day when the returned window
|
|
761
|
+
* turns out empty (dsp-session-window.util's deriveDspWindow is that guard).
|
|
762
|
+
* Additive to the kscript venue-sessions mirror; not part of the mirrored
|
|
763
|
+
* surface.
|
|
764
|
+
*/
|
|
765
|
+
const LATEST_RTH_LOOKBACK_DAYS = 7;
|
|
766
|
+
export function latestRthSessionBoundsAtOrBefore(symbol, tsMs) {
|
|
767
|
+
const window = getRthWindowForSymbol(symbol);
|
|
768
|
+
if (!window)
|
|
769
|
+
return null;
|
|
770
|
+
if (!Number.isFinite(tsMs))
|
|
771
|
+
return null;
|
|
772
|
+
for (let daysBack = 0; daysBack <= LATEST_RTH_LOOKBACK_DAYS; daysBack++) {
|
|
773
|
+
const bounds = rthDayBoundsFor(window, tsMs - daysBack * 24 * 60 * 60 * 1000);
|
|
774
|
+
if (!bounds)
|
|
775
|
+
return null;
|
|
776
|
+
if (bounds.openMs <= tsMs)
|
|
777
|
+
return { openMs: bounds.openMs, closeMs: bounds.closeMs };
|
|
778
|
+
}
|
|
779
|
+
return null;
|
|
780
|
+
}
|
|
781
|
+
/**
|
|
782
|
+
* The next RTH open strictly AFTER `tsMs` on the same memoized window: inside
|
|
783
|
+
* a session it is tomorrow's open, after the close it is the next calendar
|
|
784
|
+
* day's, before the open it is today's. NON-AUTHORITATIVE, a HINT only
|
|
785
|
+
* (data-loading S6, the poll cadence's probe hint): the RthWindow is a
|
|
786
|
+
* chart-side filter (a timezone plus open and close minutes), not a venue
|
|
787
|
+
* schedule. It admits Saturday and holiday sessions exactly like
|
|
788
|
+
* `latestRthSessionBoundsAtOrBefore` (every calendar day has mathematical
|
|
789
|
+
* bounds), the RTH window (09:30 to 16:15 New York, 09:00 to 14:30 on NYMEX)
|
|
790
|
+
* is not the Globex cycle, and it can neither prove a venue still closed nor
|
|
791
|
+
* name the 17:00 CT
|
|
792
|
+
* reopen. A caller may shorten a timer to it (one extra probe on a
|
|
793
|
+
* non-trading day at worst); it must never skip a request, derive 'closed'
|
|
794
|
+
* or resume a cadence from it. Null for an unmapped symbol or a non-finite
|
|
795
|
+
* instant.
|
|
796
|
+
*/
|
|
797
|
+
export function nextRthSessionOpenMs(symbol, tsMs) {
|
|
798
|
+
const window = getRthWindowForSymbol(symbol);
|
|
799
|
+
if (!window)
|
|
800
|
+
return null;
|
|
801
|
+
if (!Number.isFinite(tsMs))
|
|
802
|
+
return null;
|
|
803
|
+
for (let daysAhead = 0; daysAhead <= LATEST_RTH_LOOKBACK_DAYS; daysAhead++) {
|
|
804
|
+
const bounds = rthDayBoundsFor(window, tsMs + daysAhead * 24 * 60 * 60 * 1000);
|
|
805
|
+
if (!bounds)
|
|
806
|
+
return null;
|
|
807
|
+
if (bounds.openMs > tsMs)
|
|
808
|
+
return bounds.openMs;
|
|
809
|
+
}
|
|
810
|
+
return null;
|
|
811
|
+
}
|
|
812
|
+
/**
|
|
813
|
+
* Slack a CALLER should add to a bar count before asking for its session span.
|
|
814
|
+
* Session slots are an upper bound on rows (holidays, early closes, and thin
|
|
815
|
+
* back-month contracts under-fill them), so a window sized to exact capacity
|
|
816
|
+
* systematically delivers short. Lives here next to the walk it corrects; the
|
|
817
|
+
* walk itself stays exact so it remains a testable "span holding N bars".
|
|
818
|
+
*/
|
|
819
|
+
export const RTH_SPAN_DENSITY_MARGIN = 1.15;
|
|
820
|
+
/**
|
|
821
|
+
* Session-anchored buckets one full RTH trading day contributes at `tfMs`:
|
|
822
|
+
* ceil(sessionSpan / tfMs), the last bucket a natural partial (mirrors the
|
|
823
|
+
* gateway's session-anchored re-aggregation above the 30m grid and the
|
|
824
|
+
* admit-whole rule at/below it). At 1h: 7 on the CME platform window, 6 on
|
|
825
|
+
* the NYMEX energy window.
|
|
826
|
+
*/
|
|
827
|
+
export function rthSessionBucketsPerDay(window, tfMs) {
|
|
828
|
+
const sessionMs = (window.closeMinutes - window.openMinutes) * 60_000;
|
|
829
|
+
return Math.max(1, Math.ceil(sessionMs / tfMs));
|
|
830
|
+
}
|
|
831
|
+
/**
|
|
832
|
+
* Wall-clock span that contains `barCount` RTH session bars walking BACKWARD
|
|
833
|
+
* from `endMs`, for sizing lazy-load windows on session-filtered series. The
|
|
834
|
+
* lazy pipeline's `bars * intervalMs` translation assumes contiguous bars; an
|
|
835
|
+
* RTH series carries only `rthSessionBucketsPerDay` bars per trading day and
|
|
836
|
+
* none on weekends (~3.4-4.9x sparser at 1h), so windows sized that way
|
|
837
|
+
* under-deliver every round and the loader re-frames once per round until the
|
|
838
|
+
* shortfall closes (the 2026-08-20 ES1! reload-flap).
|
|
839
|
+
*
|
|
840
|
+
* Walks venue-local calendar days on a NOON-anchored cursor (24h steps from
|
|
841
|
+
* noon are DST-safe: US transitions run at 02:00 and the two yearly shifts
|
|
842
|
+
* cancel, so the cursor stays inside 11:00-13:00 local), skips Saturday and
|
|
843
|
+
* Sunday, and accumulates per-day bucket counts until `barCount` is covered;
|
|
844
|
+
* the span then reaches that day's terminal bucket. The count is treated as
|
|
845
|
+
* session CAPACITY, which is an upper bound on rows actually present, so
|
|
846
|
+
* callers sizing a fetch window should pad with `RTH_SPAN_DENSITY_MARGIN`
|
|
847
|
+
* (holidays, early closes and thin contracts under-fill their slots, which
|
|
848
|
+
* would otherwise make every window land short). Returns null when the
|
|
849
|
+
* symbol resolves no RTH window or inputs are invalid (callers keep the
|
|
850
|
+
* naive translation).
|
|
851
|
+
*/
|
|
852
|
+
export function rthSessionWallSpanForBarsMs(symbol, tfMs, barCount, endMs) {
|
|
853
|
+
const window = getRthWindowForSymbol(symbol);
|
|
854
|
+
if (!window)
|
|
855
|
+
return null;
|
|
856
|
+
if (!Number.isFinite(tfMs) || tfMs <= 0)
|
|
857
|
+
return null;
|
|
858
|
+
if (!Number.isFinite(endMs))
|
|
859
|
+
return null;
|
|
860
|
+
if (!Number.isFinite(barCount) || barCount <= 0)
|
|
861
|
+
return null;
|
|
862
|
+
const perDay = rthSessionBucketsPerDay(window, tfMs);
|
|
863
|
+
let zonedEnd;
|
|
864
|
+
try {
|
|
865
|
+
zonedEnd = dayjs(endMs).tz(window.timeZone);
|
|
866
|
+
}
|
|
867
|
+
catch {
|
|
868
|
+
return null;
|
|
869
|
+
}
|
|
870
|
+
let cursorMs = zonedEnd.startOf('day').add(12, 'hour').valueOf();
|
|
871
|
+
let remaining = Math.ceil(barCount);
|
|
872
|
+
// Trading days needed, inflated for weekends (7/5) plus holiday margin;
|
|
873
|
+
// hard-bounds the walk for any degenerate input.
|
|
874
|
+
const maxDays = Math.min(1000, Math.ceil((remaining / perDay) * 1.4) + 14);
|
|
875
|
+
let terminalStartMs = null;
|
|
876
|
+
for (let i = 0; i < maxDays; i++) {
|
|
877
|
+
let day;
|
|
878
|
+
try {
|
|
879
|
+
day = dayjs(cursorMs).tz(window.timeZone);
|
|
880
|
+
}
|
|
881
|
+
catch {
|
|
882
|
+
break;
|
|
883
|
+
}
|
|
884
|
+
const dow = day.day();
|
|
885
|
+
if (dow !== 0 && dow !== 6) {
|
|
886
|
+
const bounds = rthDayBoundsFor(window, cursorMs);
|
|
887
|
+
if (bounds && bounds.openMs < endMs) {
|
|
888
|
+
const dayBars = endMs >= bounds.closeMs ? perDay : Math.max(0, Math.min(perDay, Math.ceil((endMs - bounds.openMs) / tfMs)));
|
|
889
|
+
if (dayBars > 0) {
|
|
890
|
+
remaining -= dayBars;
|
|
891
|
+
if (remaining <= 0) {
|
|
892
|
+
// Land on the exact TERMINAL BUCKET inside this day, not the
|
|
893
|
+
// day's open: at fine intervals (405*60 1s bars per day) a
|
|
894
|
+
// day-open span over-asks by up to a whole session plus the
|
|
895
|
+
// overnight gap (~72h from a Monday open) for a sub-day demand.
|
|
896
|
+
const overshootBars = -remaining;
|
|
897
|
+
terminalStartMs = bounds.openMs + overshootBars * tfMs;
|
|
898
|
+
break;
|
|
899
|
+
}
|
|
900
|
+
terminalStartMs = bounds.openMs;
|
|
901
|
+
}
|
|
902
|
+
}
|
|
903
|
+
}
|
|
904
|
+
cursorMs -= 24 * 60 * 60 * 1000;
|
|
905
|
+
}
|
|
906
|
+
if (terminalStartMs === null)
|
|
907
|
+
return null;
|
|
908
|
+
return Math.max(tfMs, endMs - terminalStartMs);
|
|
909
|
+
}
|
|
910
|
+
/**
|
|
911
|
+
* Roughly how many RTH bars a wall-clock span of `spanMs` holds at `tfMs`:
|
|
912
|
+
* the per-day bucket count scaled by the span's trading days (5 of every 7
|
|
913
|
+
* calendar days). The inverse of `rthSessionWallSpanForBarsMs`, for callers
|
|
914
|
+
* sizing a BUDGET rather than a window (how many bars a plain bucket-sized
|
|
915
|
+
* round can be expected to yield on an RTH pane). Null when the symbol
|
|
916
|
+
* resolves no RTH window.
|
|
917
|
+
*/
|
|
918
|
+
export function rthSessionBarsInWallSpanMs(symbol, tfMs, spanMs) {
|
|
919
|
+
const window = getRthWindowForSymbol(symbol);
|
|
920
|
+
if (!window)
|
|
921
|
+
return null;
|
|
922
|
+
if (!Number.isFinite(tfMs) || tfMs <= 0 || !Number.isFinite(spanMs) || spanMs <= 0)
|
|
923
|
+
return null;
|
|
924
|
+
const tradingDays = (spanMs / 86_400_000) * (5 / 7);
|
|
925
|
+
return Math.max(1, Math.round(rthSessionBucketsPerDay(window, tfMs) * tradingDays));
|
|
926
|
+
}
|