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