@orangecharts/wrun-chart-host 0.6.0 → 0.7.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 +13 -5
- package/dist/constants/marketCapabilities.constants.d.ts +5 -0
- package/dist/constants/marketCapabilities.constants.js +16 -0
- package/dist/host-ports.types.d.ts +35 -3
- package/dist/index.d.ts +11 -1
- package/dist/index.js +11 -1
- package/dist/indicators/controls/tpo-session.util.js +42 -18
- package/dist/market-data/billing.interface.d.ts +2 -1
- package/dist/settings-templates/indicator-fields.js +10 -0
- package/dist/utility/chart/crypto-index.leaf.d.ts +16 -0
- package/dist/utility/chart/crypto-index.leaf.js +19 -0
- package/dist/utility/chart/index-mode-admission.util.js +9 -1
- package/dist/utility/chart/index-mode.util.d.ts +11 -5
- package/dist/utility/chart/index-mode.util.js +22 -10
- package/dist/utility/chart/kscript-source-answer-budget.leaf.d.ts +36 -0
- package/dist/utility/chart/kscript-source-answer-budget.leaf.js +39 -0
- package/dist/utility/chart/kscript-source-degrade.leaf.d.ts +38 -1
- package/dist/utility/chart/kscript-source-degrade.leaf.js +39 -1
- package/dist/utility/chart/live-bucket.util.d.ts +2 -1
- package/dist/utility/chart/live-bucket.util.js +47 -15
- package/dist/utility/chart/local-kscript-warmup-depth.util.d.ts +15 -1
- package/dist/utility/chart/local-kscript-warmup-depth.util.js +9 -0
- package/dist/utility/chart/market-session-schedule.util.d.ts +3 -1
- package/dist/utility/chart/market-session-schedule.util.js +24 -2
- package/dist/utility/chart/marketKind.util.d.ts +12 -7
- package/dist/utility/chart/marketKind.util.js +15 -5
- package/dist/utility/chart/ny-calendar.util.d.ts +104 -0
- package/dist/utility/chart/ny-calendar.util.js +346 -0
- package/dist/utility/chart/om-panel.util.d.ts +14 -2
- package/dist/utility/chart/om-panel.util.js +108 -40
- package/dist/utility/chart/rth-session.util.d.ts +10 -7
- package/dist/utility/chart/rth-session.util.js +17 -22
- package/dist/utility/chart/trading-day.util.js +90 -18
- package/dist/utility/chart/us-equities-session.util.js +20 -67
- package/dist/utility/chart/wrun-bar-session-facts.util.js +14 -1
- package/dist/utility/common/time.util.d.ts +7 -1
- package/dist/utility/common/time.util.js +11 -41
- package/dist/utility/number-format.util.d.ts +17 -7
- package/dist/utility/number-format.util.js +18 -8
- package/dist/utility/options/option-symbol.util.js +13 -2
- package/dist/utility/symbol-selection/contract-expiry.util.js +9 -1
- package/dist/utility/watchlist/import/import-request.leaf.d.ts +4 -1
- package/dist/utility/watchlist/import/import-request.leaf.js +5 -2
- package/dist/utility/watchlist/import/tradingview-symbols.leaf.d.ts +25 -4
- package/dist/utility/watchlist/import/tradingview-symbols.leaf.js +62 -4
- package/dist/utility/wrun/run-schedule/wrun-chart-gate-reader.util.d.ts +19 -0
- package/dist/utility/wrun/run-schedule/wrun-chart-gate-reader.util.js +57 -0
- package/dist/utility/wrun/run-schedule/wrun-gate-reader-warm.util.d.ts +23 -0
- package/dist/utility/wrun/run-schedule/wrun-gate-reader-warm.util.js +90 -0
- package/dist/utility/wrun/run-schedule/wrun-lane-groups.util.d.ts +39 -0
- package/dist/utility/wrun/run-schedule/wrun-lane-groups.util.js +60 -0
- package/dist/utility/wrun/run-schedule/wrun-late-reads.util.d.ts +77 -0
- package/dist/utility/wrun/run-schedule/wrun-late-reads.util.js +195 -0
- package/dist/utility/wrun/run-schedule/wrun-own-candles.util.d.ts +56 -0
- package/dist/utility/wrun/run-schedule/wrun-own-candles.util.js +70 -0
- package/dist/utility/wrun/run-schedule/wrun-prefix-feeds.util.d.ts +53 -0
- package/dist/utility/wrun/run-schedule/wrun-prefix-feeds.util.js +239 -0
- package/dist/utility/wrun/sources/lanes/option_stats_10m.d.ts +16 -0
- package/dist/utility/wrun/sources/lanes/option_stats_10m.js +14 -0
- package/dist/utility/wrun/sources/lanes/options_flow.d.ts +43 -18
- package/dist/utility/wrun/sources/lanes/options_flow.js +209 -72
- package/dist/utility/wrun/sources/lanes/token_supply.js +5 -31
- package/dist/utility/wrun/sources/opra-option-lanes.util.d.ts +3 -18
- package/dist/utility/wrun/sources/opra-option-lanes.util.js +12 -57
- package/dist/utility/wrun/sources/row-lane-registry.d.ts +1 -1
- package/dist/utility/wrun/sources/row-lane-registry.js +22 -8
- package/dist/utility/wrun/sources/row-lanes/option_contract_flow.d.ts +61 -0
- package/dist/utility/wrun/sources/row-lanes/option_contract_flow.js +103 -8
- package/dist/utility/wrun/sources/row-lanes/option_contract_state.d.ts +5 -0
- package/dist/utility/wrun/sources/row-lanes/option_contract_state.js +24 -12
- package/dist/utility/wrun/sources/row-lanes/option_prints.d.ts +55 -0
- package/dist/utility/wrun/sources/row-lanes/option_prints.js +95 -18
- package/dist/utility/wrun/sources/row-lanes/option_strikes.d.ts +15 -1
- package/dist/utility/wrun/sources/row-lanes/option_strikes.js +23 -8
- package/dist/utility/wrun/sources/row-lanes/option_surface.js +11 -11
- package/dist/utility/wrun/sources/wrun-poll-lane.types.d.ts +14 -2
- package/dist/utility/wrun/sources/wrun-poll-lane.types.js +6 -3
- package/dist/utility/wrun/sources/wrun-poll-lanes.util.d.ts +43 -8
- package/dist/utility/wrun/sources/wrun-poll-lanes.util.js +77 -11
- package/dist/utility/wrun/sources/wrun-row-lane.types.d.ts +31 -16
- package/dist/utility/wrun/sources/wrun-row-lane.types.js +2 -0
- package/dist/utility/wrun/sources/wrun-row-lanes.util.d.ts +52 -12
- package/dist/utility/wrun/sources/wrun-row-lanes.util.js +110 -46
- package/dist/utility/wrun/wrun-browser-sources.leaf.d.ts +10 -0
- package/dist/utility/wrun/wrun-browser-sources.leaf.js +12 -0
- package/dist/utility/wrun/wrun-coin-lane-live.util.d.ts +3 -3
- package/dist/utility/wrun/wrun-coin-lane-live.util.js +53 -18
- package/dist/utility/wrun/wrun-color-settings.util.d.ts +6 -0
- package/dist/utility/wrun/wrun-color-settings.util.js +45 -0
- package/dist/utility/wrun/wrun-draft-overlay.util.js +14 -8
- package/dist/utility/wrun/wrun-failure-cause.d.ts +1 -1
- package/dist/utility/wrun/wrun-failure-cause.js +14 -0
- package/dist/utility/wrun/wrun-frames.js +6 -2
- package/dist/utility/wrun/wrun-host.service.d.ts +26 -18
- package/dist/utility/wrun/wrun-host.service.js +49 -52
- package/dist/utility/wrun/wrun-hosted-wire-caps.d.ts +1 -1
- package/dist/utility/wrun/wrun-hosted-wire-caps.js +2 -0
- package/dist/utility/wrun/wrun-input-requirements.leaf.js +7 -4
- package/dist/utility/wrun/wrun-kit-run-tables.util.d.ts +24 -0
- package/dist/utility/wrun/wrun-kit-run-tables.util.js +87 -0
- package/dist/utility/wrun/wrun-lifecycle.contract.d.ts +2 -1
- package/dist/utility/wrun/wrun-live-tick.util.d.ts +8 -2
- package/dist/utility/wrun/wrun-live-tick.util.js +35 -16
- package/dist/utility/wrun/wrun-opra-flow.leaf.d.ts +40 -13
- package/dist/utility/wrun/wrun-opra-flow.leaf.js +39 -12
- package/dist/utility/wrun/wrun-option-contract-flow.util.d.ts +70 -21
- package/dist/utility/wrun/wrun-option-contract-flow.util.js +257 -112
- package/dist/utility/wrun/wrun-option-prints.util.d.ts +62 -22
- package/dist/utility/wrun/wrun-option-prints.util.js +148 -46
- package/dist/utility/wrun/wrun-option-views.util.d.ts +262 -0
- package/dist/utility/wrun/wrun-option-views.util.js +356 -0
- package/dist/utility/wrun/wrun-options-chain.util.d.ts +23 -2
- package/dist/utility/wrun/wrun-options-chain.util.js +37 -3
- package/dist/utility/wrun/wrun-overlay-drivers.util.d.ts +18 -3
- package/dist/utility/wrun/wrun-overlay-drivers.util.js +32 -7
- package/dist/utility/wrun/wrun-overlay-recovery.util.d.ts +9 -3
- package/dist/utility/wrun/wrun-overlay-recovery.util.js +146 -18
- package/dist/utility/wrun/wrun-overlay-run.util.d.ts +50 -6
- package/dist/utility/wrun/wrun-overlay-run.util.js +816 -243
- package/dist/utility/wrun/wrun-pin-spelling.util.d.ts +5 -0
- package/dist/utility/wrun/wrun-pin-spelling.util.js +28 -12
- package/dist/utility/wrun/wrun-pin-venues.util.js +4 -6
- package/dist/utility/wrun/wrun-present-bits.util.d.ts +9 -0
- package/dist/utility/wrun/wrun-present-bits.util.js +39 -0
- package/dist/utility/wrun/wrun-refusal-surface.util.d.ts +3 -2
- package/dist/utility/wrun/wrun-refusal-surface.util.js +5 -4
- package/dist/utility/wrun/wrun-refusal.util.d.ts +66 -6
- package/dist/utility/wrun/wrun-refusal.util.js +335 -40
- package/dist/utility/wrun/wrun-source-rows.util.js +11 -0
- package/dist/utility/wrun/wrun-tier-grid.util.d.ts +28 -3
- package/dist/utility/wrun/wrun-tier-grid.util.js +79 -19
- package/dist/utility/wrun/wrun-transient-rerun.util.d.ts +14 -3
- package/dist/utility/wrun/wrun-transient-rerun.util.js +33 -8
- package/package.json +5 -5
- package/dist/utility/wrun/wrun-opra-underlying.util.d.ts +0 -12
- package/dist/utility/wrun/wrun-opra-underlying.util.js +0 -1
|
@@ -38,6 +38,7 @@ import utc from 'dayjs/plugin/utc.js';
|
|
|
38
38
|
import { Intervals } from '../../constants/interval.constants.js';
|
|
39
39
|
import { isCmeGoverned, normalizeExchangeCode } from './cme-realtime.util.js';
|
|
40
40
|
import { intervalLabelForMs, isSubMinuteInterval, standardIntervalMsAtOrBelow } from './interval-registry.util.js';
|
|
41
|
+
// No reading here goes through dayjs any more; the plugins stay registered for importers that rely on it.
|
|
41
42
|
dayjs.extend(utc);
|
|
42
43
|
dayjs.extend(timezone);
|
|
43
44
|
/**
|
|
@@ -539,6 +540,7 @@ function rthDayBoundsFor(window, tsMs) {
|
|
|
539
540
|
closeMs: zoneWallToUtcMs(zone, wall.year, wall.month, wall.day, window.closeMinutes),
|
|
540
541
|
dayStartMs: zoneWallToUtcMs(zone, wall.year, wall.month, wall.day, 0),
|
|
541
542
|
dayEndMs: zoneWallToUtcMs(zone, next.getUTCFullYear(), next.getUTCMonth() + 1, next.getUTCDate(), 0),
|
|
543
|
+
weekday: (next.getUTCDay() + 6) % 7,
|
|
542
544
|
};
|
|
543
545
|
}
|
|
544
546
|
catch {
|
|
@@ -841,13 +843,16 @@ export function rthSessionBucketsPerDay(window, tfMs) {
|
|
|
841
843
|
* noon are DST-safe: US transitions run at 02:00 and the two yearly shifts
|
|
842
844
|
* cancel, so the cursor stays inside 11:00-13:00 local), skips Saturday and
|
|
843
845
|
* Sunday, and accumulates per-day bucket counts until `barCount` is covered;
|
|
844
|
-
* the span then reaches that day's terminal bucket. The
|
|
845
|
-
*
|
|
846
|
-
*
|
|
847
|
-
* (
|
|
848
|
-
*
|
|
849
|
-
*
|
|
850
|
-
*
|
|
846
|
+
* the span then reaches that day's terminal bucket. The cursor's days are
|
|
847
|
+
* consecutive, so their weekdays follow from the end day's by arithmetic and
|
|
848
|
+
* the walk reads only the per-day memo, never a timezone conversion per day
|
|
849
|
+
* (each lazy-load round asks it again). The count is treated as session
|
|
850
|
+
* CAPACITY, which is an upper bound on rows actually present, so callers
|
|
851
|
+
* sizing a fetch window should pad with `RTH_SPAN_DENSITY_MARGIN` (holidays,
|
|
852
|
+
* early closes and thin contracts under-fill their slots, which would
|
|
853
|
+
* otherwise make every window land short). Returns null when the symbol
|
|
854
|
+
* resolves no RTH window or inputs are invalid (callers keep the naive
|
|
855
|
+
* translation).
|
|
851
856
|
*/
|
|
852
857
|
export function rthSessionWallSpanForBarsMs(symbol, tfMs, barCount, endMs) {
|
|
853
858
|
const window = getRthWindowForSymbol(symbol);
|
|
@@ -860,28 +865,18 @@ export function rthSessionWallSpanForBarsMs(symbol, tfMs, barCount, endMs) {
|
|
|
860
865
|
if (!Number.isFinite(barCount) || barCount <= 0)
|
|
861
866
|
return null;
|
|
862
867
|
const perDay = rthSessionBucketsPerDay(window, tfMs);
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
}
|
|
867
|
-
catch {
|
|
868
|
+
// The venue-local day holding `endMs` (null on a zone failure, or an instant that is not a date).
|
|
869
|
+
const endDay = rthDayBoundsFor(window, endMs);
|
|
870
|
+
if (!endDay)
|
|
868
871
|
return null;
|
|
869
|
-
|
|
870
|
-
let cursorMs = zonedEnd.startOf('day').add(12, 'hour').valueOf();
|
|
872
|
+
let cursorMs = endDay.dayStartMs + 12 * 60 * 60 * 1000;
|
|
871
873
|
let remaining = Math.ceil(barCount);
|
|
872
874
|
// Trading days needed, inflated for weekends (7/5) plus holiday margin;
|
|
873
875
|
// hard-bounds the walk for any degenerate input.
|
|
874
876
|
const maxDays = Math.min(1000, Math.ceil((remaining / perDay) * 1.4) + 14);
|
|
875
877
|
let terminalStartMs = null;
|
|
876
878
|
for (let i = 0; i < maxDays; i++) {
|
|
877
|
-
|
|
878
|
-
try {
|
|
879
|
-
day = dayjs(cursorMs).tz(window.timeZone);
|
|
880
|
-
}
|
|
881
|
-
catch {
|
|
882
|
-
break;
|
|
883
|
-
}
|
|
884
|
-
const dow = day.day();
|
|
879
|
+
const dow = (endDay.weekday + 7 - (i % 7)) % 7;
|
|
885
880
|
if (dow !== 0 && dow !== 6) {
|
|
886
881
|
const bounds = rthDayBoundsFor(window, cursorMs);
|
|
887
882
|
if (bounds && bounds.openMs < endMs) {
|
|
@@ -98,13 +98,82 @@ export function getTradingDayAnchor(exchange) {
|
|
|
98
98
|
return US_OPTIONS_TRADING_DAY_ANCHOR;
|
|
99
99
|
return undefined;
|
|
100
100
|
}
|
|
101
|
-
|
|
102
|
-
const
|
|
101
|
+
/** One wall-clock reader per zone (titan src/utils/tradingDay.ts's formatter); null for a zone Intl rejects. */
|
|
102
|
+
const wallClockFormatters = new Map();
|
|
103
|
+
function wallClockFormatter(timeZone) {
|
|
104
|
+
let formatter = wallClockFormatters.get(timeZone);
|
|
105
|
+
if (formatter === undefined) {
|
|
106
|
+
try {
|
|
107
|
+
formatter = new Intl.DateTimeFormat('en-US', {
|
|
108
|
+
timeZone,
|
|
109
|
+
year: 'numeric',
|
|
110
|
+
month: '2-digit',
|
|
111
|
+
day: '2-digit',
|
|
112
|
+
hour: '2-digit',
|
|
113
|
+
minute: '2-digit',
|
|
114
|
+
second: '2-digit',
|
|
115
|
+
// h23 avoids the hour-24 midnight some engines emit for h24.
|
|
116
|
+
hourCycle: 'h23',
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
catch {
|
|
120
|
+
formatter = null;
|
|
121
|
+
}
|
|
122
|
+
wallClockFormatters.set(timeZone, formatter);
|
|
123
|
+
}
|
|
124
|
+
return formatter;
|
|
125
|
+
}
|
|
126
|
+
/** The wall clock at `tsMs` in the formatter's zone, as ms since the epoch read as if UTC (titan's wallClockMs). */
|
|
127
|
+
function wallClockMs(formatter, tsMs) {
|
|
128
|
+
let year = 0;
|
|
129
|
+
let month = 1;
|
|
130
|
+
let day = 1;
|
|
131
|
+
let hour = 0;
|
|
132
|
+
let minute = 0;
|
|
133
|
+
let second = 0;
|
|
134
|
+
for (const part of formatter.formatToParts(tsMs)) {
|
|
135
|
+
if (part.type === 'year')
|
|
136
|
+
year = Number(part.value);
|
|
137
|
+
else if (part.type === 'month')
|
|
138
|
+
month = Number(part.value);
|
|
139
|
+
else if (part.type === 'day')
|
|
140
|
+
day = Number(part.value);
|
|
141
|
+
else if (part.type === 'hour')
|
|
142
|
+
hour = Number(part.value);
|
|
143
|
+
else if (part.type === 'minute')
|
|
144
|
+
minute = Number(part.value);
|
|
145
|
+
else if (part.type === 'second')
|
|
146
|
+
second = Number(part.value);
|
|
147
|
+
}
|
|
148
|
+
return Date.UTC(year, month - 1, day, hour, minute, second) + (((tsMs % 1000) + 1000) % 1000);
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* The instant whose wall clock reads `targetWallMs` (ms read as if UTC): titan's
|
|
152
|
+
* own fixed-point solve (tradingDay.ts instantForWall), started from the zone's
|
|
153
|
+
* offset at the wall reading itself and corrected twice. Every wall time that
|
|
154
|
+
* exists converges; a wall time the zone repeats (the fall-back hour) or skips
|
|
155
|
+
* (the spring-forward gap) lands on the neighbor titan's buckets open at.
|
|
156
|
+
* dayjs.tz, which this replaced, guessed from the zone's offset at the device's
|
|
157
|
+
* NOW: a custom window opening 01:30 America/New_York on 2026-11-01 opened at
|
|
158
|
+
* 05:30Z in summer and 06:30Z in winter, while titan opens it at 05:30Z, so a
|
|
159
|
+
* winter tab's fetch head and history trim skipped that hour.
|
|
160
|
+
*/
|
|
161
|
+
function instantForWall(formatter, targetWallMs) {
|
|
162
|
+
let instant = targetWallMs - (wallClockMs(formatter, targetWallMs) - targetWallMs);
|
|
163
|
+
for (let pass = 0; pass < 2; pass++) {
|
|
164
|
+
const wall = wallClockMs(formatter, instant);
|
|
165
|
+
if (wall === targetWallMs)
|
|
166
|
+
break;
|
|
167
|
+
instant += targetWallMs - wall;
|
|
168
|
+
}
|
|
169
|
+
return instant;
|
|
170
|
+
}
|
|
103
171
|
/**
|
|
104
172
|
* The instant whose wall clock in `timeZone` reads `minutes` past midnight on
|
|
105
|
-
* the y-m-d calendar date
|
|
106
|
-
*
|
|
107
|
-
* midnight
|
|
173
|
+
* the y-m-d calendar date, solved as titan solves it (instantForWall), so the
|
|
174
|
+
* FE mirror opens every day where titan does, DST edges included: counting real
|
|
175
|
+
* minutes from midnight would drift by the offset delta on 23h/25h transition
|
|
176
|
+
* days. A zone this runtime's Intl rejects reads the wall time as UTC. Memoized
|
|
108
177
|
* because period-floor consumers walk thousands of bar timestamps while the
|
|
109
178
|
* instant only changes once per calendar date; bounded, cleared wholesale on
|
|
110
179
|
* overflow (recomputation is cheap).
|
|
@@ -115,13 +184,9 @@ function wallInstantMs(timeZone, date, minutes) {
|
|
|
115
184
|
const key = `${timeZone}|${minutes}|${date.y}-${date.m}-${date.d}`;
|
|
116
185
|
let ms = wallInstantCache.get(key);
|
|
117
186
|
if (ms === undefined) {
|
|
118
|
-
const
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
}
|
|
122
|
-
catch {
|
|
123
|
-
ms = dayjs.utc(wall).valueOf();
|
|
124
|
-
}
|
|
187
|
+
const targetWallMs = Date.UTC(date.y, date.m - 1, date.d, Math.floor(minutes / 60), minutes % 60);
|
|
188
|
+
const formatter = wallClockFormatter(timeZone);
|
|
189
|
+
ms = formatter ? instantForWall(formatter, targetWallMs) : targetWallMs;
|
|
125
190
|
if (wallInstantCache.size >= WALL_INSTANT_CACHE_MAX)
|
|
126
191
|
wallInstantCache.clear();
|
|
127
192
|
wallInstantCache.set(key, ms);
|
|
@@ -167,12 +232,19 @@ export function tradingDayStartMs(tsMs, anchor) {
|
|
|
167
232
|
return cached.openMs;
|
|
168
233
|
const date = venueDateOf(tsMs, anchor.timeZone);
|
|
169
234
|
const todayOpen = wallInstantMs(anchor.timeZone, date, anchor.openMinutes);
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
// Opens are strictly increasing, exactly one per calendar date
|
|
173
|
-
//
|
|
174
|
-
//
|
|
175
|
-
|
|
235
|
+
let openDate = tsMs >= todayOpen ? date : shiftCalendarDate(date, -1);
|
|
236
|
+
let openMs = tsMs >= todayOpen ? todayOpen : wallInstantMs(anchor.timeZone, openDate, anchor.openMinutes);
|
|
237
|
+
// Opens are strictly increasing, exactly one per calendar date, so the span
|
|
238
|
+
// [openMs, nextOpenMs) maps every contained instant to openMs. Titan's own
|
|
239
|
+
// defensive step: an open inside a transition gap can solve to its pre-gap
|
|
240
|
+
// neighbor, early enough that the NEXT calendar date's open precedes tsMs,
|
|
241
|
+
// and then that open is the day holding tsMs.
|
|
242
|
+
let nextOpenMs = wallInstantMs(anchor.timeZone, shiftCalendarDate(openDate, 1), anchor.openMinutes);
|
|
243
|
+
if (tsMs >= todayOpen && nextOpenMs <= tsMs) {
|
|
244
|
+
openDate = shiftCalendarDate(openDate, 1);
|
|
245
|
+
openMs = nextOpenMs;
|
|
246
|
+
nextOpenMs = wallInstantMs(anchor.timeZone, shiftCalendarDate(openDate, 1), anchor.openMinutes);
|
|
247
|
+
}
|
|
176
248
|
tradingDayWindowByAnchor.set(anchorKey, { openMs, nextOpenMs });
|
|
177
249
|
return openMs;
|
|
178
250
|
}
|
|
@@ -19,20 +19,18 @@
|
|
|
19
19
|
* regular 09:30 -> 16:00
|
|
20
20
|
* after 16:00 -> 20:00
|
|
21
21
|
* closed everything else, and weekends
|
|
22
|
+
* Every per-row answer here reads the New York calendar (ny-calendar.util):
|
|
23
|
+
* one timezone lookup per date, integer compares per row.
|
|
22
24
|
*
|
|
23
25
|
* Worker-safe: no Vue / store / i18n imports (the bars cache and the workers
|
|
24
26
|
* import the row filter).
|
|
25
27
|
*/
|
|
26
|
-
import dayjs from 'dayjs';
|
|
27
|
-
import timezone from 'dayjs/plugin/timezone.js';
|
|
28
|
-
import utc from 'dayjs/plugin/utc.js';
|
|
29
28
|
import { checkIsPolygon } from './marketKind.util.js';
|
|
29
|
+
import { NY_REGULAR_CLOSE_MINUTES, NY_REGULAR_OPEN_MINUTES, NY_TIME_ZONE, nyCalendarDay, nyCalendarDayAt, nyNextRegularOpenAfterMs, nyRegularSessionOpenMs, } from './ny-calendar.util.js';
|
|
30
30
|
import { isFootprintRthFoldTfMs, isRthBucketExactIntervalMs, sessionWindowsInRange, } from './rth-session.util.js';
|
|
31
31
|
import { sessionGridStartMs } from './cme-session-bucket.util.js';
|
|
32
32
|
import { checkUSMarketHours } from '../common/time.util.js';
|
|
33
|
-
|
|
34
|
-
dayjs.extend(timezone);
|
|
35
|
-
export const US_EQUITIES_TIME_ZONE = 'America/New_York';
|
|
33
|
+
export const US_EQUITIES_TIME_ZONE = NY_TIME_ZONE;
|
|
36
34
|
/**
|
|
37
35
|
* Switch for the equities extended-hours session. On (since 2026-10-02):
|
|
38
36
|
* Polygon's consolidated minute bars are back on exchange 92 and carry the
|
|
@@ -50,9 +48,10 @@ export const usEquitiesSessionConfig = { extendedHoursEnabled: true };
|
|
|
50
48
|
export function isEquityExtendedSession(sessionType) {
|
|
51
49
|
return usEquitiesSessionConfig.extendedHoursEnabled && sessionType === 'extended';
|
|
52
50
|
}
|
|
53
|
-
/** Minutes after local midnight, matching `checkUSMarketHours
|
|
54
|
-
const REGULAR_OPEN_MINUTES =
|
|
55
|
-
const REGULAR_CLOSE_MINUTES =
|
|
51
|
+
/** Minutes after local midnight, matching `checkUSMarketHours` (both read the New York calendar's edges). */
|
|
52
|
+
const REGULAR_OPEN_MINUTES = NY_REGULAR_OPEN_MINUTES;
|
|
53
|
+
const REGULAR_CLOSE_MINUTES = NY_REGULAR_CLOSE_MINUTES;
|
|
54
|
+
const DAY_MS = 86_400_000;
|
|
56
55
|
/**
|
|
57
56
|
* The regular cash session as a window object, for the shared zone-day walks
|
|
58
57
|
* in rth-session.util (one frozen constant so their per-window memo holds).
|
|
@@ -123,19 +122,9 @@ export function filterUsEquityRegularSessionBars(bars, intervalMs) {
|
|
|
123
122
|
export function usEquityAnchoredBucketStartMs(tsMs, intervalMs) {
|
|
124
123
|
if (!Number.isFinite(tsMs) || !Number.isFinite(intervalMs) || intervalMs <= 0)
|
|
125
124
|
return null;
|
|
126
|
-
|
|
125
|
+
const openMs = nyRegularSessionOpenMs(tsMs);
|
|
126
|
+
if (openMs === null)
|
|
127
127
|
return null;
|
|
128
|
-
let date;
|
|
129
|
-
try {
|
|
130
|
-
date = dayjs(tsMs).tz(US_EQUITIES_TIME_ZONE).format('YYYY-MM-DD');
|
|
131
|
-
}
|
|
132
|
-
catch {
|
|
133
|
-
return null;
|
|
134
|
-
}
|
|
135
|
-
const open = nyWallInstant(date, REGULAR_OPEN_MINUTES);
|
|
136
|
-
if (open === null)
|
|
137
|
-
return null;
|
|
138
|
-
const openMs = open.valueOf();
|
|
139
128
|
return openMs + Math.floor((tsMs - openMs) / intervalMs) * intervalMs;
|
|
140
129
|
}
|
|
141
130
|
/**
|
|
@@ -182,10 +171,11 @@ export function usEquityChangeReferenceClose(sessionBars, price, regularGated) {
|
|
|
182
171
|
const latest = bars[bars.length - 1];
|
|
183
172
|
if (!latest)
|
|
184
173
|
return null;
|
|
185
|
-
|
|
186
|
-
|
|
174
|
+
// The 16:00 New York close on the bar's UTC date.
|
|
175
|
+
const latestDay = nyCalendarDay(Math.floor(Math.trunc(latest[0]) / DAY_MS));
|
|
176
|
+
if (latestDay === null)
|
|
187
177
|
return null;
|
|
188
|
-
const latestCloseMs =
|
|
178
|
+
const latestCloseMs = latestDay.regularCloseMs;
|
|
189
179
|
let priceIsLater = price.atMs > latestCloseMs;
|
|
190
180
|
if (regularGated) {
|
|
191
181
|
const nextOpenMs = getUsEquitiesScheduleStatus(latestCloseMs).nextOpenMs;
|
|
@@ -197,25 +187,6 @@ export function usEquityChangeReferenceClose(sessionBars, price, regularGated) {
|
|
|
197
187
|
return bars.length >= 2 ? bars[bars.length - 2][4] : null;
|
|
198
188
|
}
|
|
199
189
|
// ─── Weekly schedule ─────────────────────────────────────────────────────────
|
|
200
|
-
/** New York wall-clock instant on `date` ('YYYY-MM-DD'); null on tz failure. */
|
|
201
|
-
function nyWallInstant(date, minutes) {
|
|
202
|
-
const hours = String(Math.floor(minutes / 60)).padStart(2, '0');
|
|
203
|
-
const mins = String(minutes % 60).padStart(2, '0');
|
|
204
|
-
try {
|
|
205
|
-
return dayjs.tz(`${date} ${hours}:${mins}`, US_EQUITIES_TIME_ZONE);
|
|
206
|
-
}
|
|
207
|
-
catch {
|
|
208
|
-
return null;
|
|
209
|
-
}
|
|
210
|
-
}
|
|
211
|
-
/** Calendar-date arithmetic on the date string only: no DST involvement. */
|
|
212
|
-
function nextDate(date) {
|
|
213
|
-
return dayjs.utc(date).add(1, 'day').format('YYYY-MM-DD');
|
|
214
|
-
}
|
|
215
|
-
function isWeekday(date) {
|
|
216
|
-
const day = dayjs.utc(date).day();
|
|
217
|
-
return day >= 1 && day <= 5;
|
|
218
|
-
}
|
|
219
190
|
/**
|
|
220
191
|
* The static weekly cycle, evaluated at `nowMs`. Like the governed-futures
|
|
221
192
|
* schedule this is deliberately NOT a holiday calendar: on an exchange
|
|
@@ -223,29 +194,11 @@ function isWeekday(date) {
|
|
|
223
194
|
*/
|
|
224
195
|
export function getUsEquitiesScheduleStatus(nowMs) {
|
|
225
196
|
const phase = resolveUsEquitySessionPhase(nowMs);
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
date = dayjs(nowMs).tz(US_EQUITIES_TIME_ZONE).format('YYYY-MM-DD');
|
|
229
|
-
}
|
|
230
|
-
catch {
|
|
197
|
+
const day = nyCalendarDayAt(nowMs);
|
|
198
|
+
if (day === null)
|
|
231
199
|
return { open: phase === 'regular', phase, nextOpenMs: null, nextCloseMs: null };
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
}
|
|
237
|
-
// Next weekday open strictly after now: today (pre-market) or the next
|
|
238
|
-
// trading day. Eight days covers any weekend from either side.
|
|
239
|
-
let candidate = date;
|
|
240
|
-
for (let i = 0; i < 8; i += 1) {
|
|
241
|
-
if (isWeekday(candidate)) {
|
|
242
|
-
const open = nyWallInstant(candidate, REGULAR_OPEN_MINUTES);
|
|
243
|
-
if (open === null)
|
|
244
|
-
return { open: false, phase, nextOpenMs: null, nextCloseMs: null };
|
|
245
|
-
if (open.valueOf() > nowMs)
|
|
246
|
-
return { open: false, phase, nextOpenMs: open.valueOf(), nextCloseMs: null };
|
|
247
|
-
}
|
|
248
|
-
candidate = nextDate(candidate);
|
|
249
|
-
}
|
|
250
|
-
return { open: false, phase, nextOpenMs: null, nextCloseMs: null };
|
|
200
|
+
if (phase === 'regular')
|
|
201
|
+
return { open: true, phase, nextOpenMs: null, nextCloseMs: day.regularCloseMs };
|
|
202
|
+
// Next weekday open strictly after now: today (pre-market) or the next trading day.
|
|
203
|
+
return { open: false, phase, nextOpenMs: nyNextRegularOpenAfterMs(nowMs), nextCloseMs: null };
|
|
251
204
|
}
|
|
@@ -63,6 +63,7 @@ import { cmeSessionBucketMs } from './cme-session-bucket.util.js';
|
|
|
63
63
|
import { isCmeGoverned } from './cme-realtime.util.js';
|
|
64
64
|
import { liveBucketVenueOf } from './live-bucket.util.js';
|
|
65
65
|
import { getMarketKind } from './marketKind.util.js';
|
|
66
|
+
import { zoneOffsetMsAt } from './ny-calendar.util.js';
|
|
66
67
|
import { getGovernedFuturesScheduleStatusForSymbol, GOVERNED_FUTURES_TIME_ZONE, isCmeAlwaysOnSymbol, } from './market-session-schedule.util.js';
|
|
67
68
|
import { engineRthWindowForSymbol, sessionWindowsInRange, } from './rth-session.util.js';
|
|
68
69
|
import { resolveUsEquitySessionPhase, US_EQUITIES_TIME_ZONE, } from './us-equities-session.util.js';
|
|
@@ -118,6 +119,7 @@ const floorTo = (value, step) => value - (((value % step) + step) % step);
|
|
|
118
119
|
const ZONE_DAYS_MAX = 4096;
|
|
119
120
|
function zoneClock(zone) {
|
|
120
121
|
return {
|
|
122
|
+
zone,
|
|
121
123
|
formatter: new Intl.DateTimeFormat('en-US', {
|
|
122
124
|
timeZone: zone,
|
|
123
125
|
hourCycle: 'h23',
|
|
@@ -134,8 +136,19 @@ function zoneClock(zone) {
|
|
|
134
136
|
}
|
|
135
137
|
const newYorkClock = zoneClock(US_EQUITIES_TIME_ZONE);
|
|
136
138
|
const chicagoClock = zoneClock(GOVERNED_FUTURES_TIME_ZONE);
|
|
137
|
-
/**
|
|
139
|
+
/**
|
|
140
|
+
* The wall clock `tMs` reads in the zone, as if it were UTC (whole seconds): one Intl reading per
|
|
141
|
+
* UTC day (the zone clock in ny-calendar.util), so a day-lookup miss and a DST day's per-bar offset
|
|
142
|
+
* cost no Intl call.
|
|
143
|
+
*/
|
|
138
144
|
function wallAsUtcMs(clock, tMs) {
|
|
145
|
+
const offsetMs = zoneOffsetMsAt(clock.zone, tMs);
|
|
146
|
+
if (Number.isNaN(offsetMs))
|
|
147
|
+
return readWallAsUtcMs(clock, tMs);
|
|
148
|
+
return Math.floor(Math.trunc(tMs) / 1000) * 1000 + offsetMs;
|
|
149
|
+
}
|
|
150
|
+
/** The wall clock read from Intl: for the instants the zone clock does not serve (it throws for a non-date). */
|
|
151
|
+
function readWallAsUtcMs(clock, tMs) {
|
|
139
152
|
let year = 1970;
|
|
140
153
|
let month = 1;
|
|
141
154
|
let day = 1;
|
|
@@ -85,7 +85,13 @@ export declare const isPollingFetchPayload: (payload: {
|
|
|
85
85
|
tf?: string;
|
|
86
86
|
} | null | undefined) => boolean;
|
|
87
87
|
/**
|
|
88
|
-
* Check if a given timestamp is within regular US market hours (9:30 AM - 4:00 PM ET)
|
|
88
|
+
* Check if a given timestamp is within regular US market hours (9:30 AM - 4:00 PM ET), on the
|
|
89
|
+
* weekday cycle in New York time: pre-market 4:00 AM - 9:30 AM, after-hours 4:00 PM - 8:00 PM,
|
|
90
|
+
* closed otherwise and all weekend (holidays are not modelled).
|
|
91
|
+
*
|
|
92
|
+
* Per-row callers (every landed stock bar) pay integer compares: the New York calendar
|
|
93
|
+
* (ny-calendar.util) resolves each date's session edges once. A non-number input keeps its old
|
|
94
|
+
* dayjs reading (`undefined` is now, a Date or a date string is its instant).
|
|
89
95
|
* @param timestampMs - Timestamp in milliseconds
|
|
90
96
|
* @returns Object containing:
|
|
91
97
|
* - isRegularHours: true if within regular hours (9:30 AM - 4:00 PM ET)
|
|
@@ -5,6 +5,7 @@ import Timezone from 'dayjs/plugin/timezone.js';
|
|
|
5
5
|
import IsoWeek from 'dayjs/plugin/isoWeek.js';
|
|
6
6
|
import QuarterOfYear from 'dayjs/plugin/quarterOfYear.js';
|
|
7
7
|
import { Intervals } from '../../constants/interval.constants.js';
|
|
8
|
+
import { nyMarketPhaseAt } from '../chart/ny-calendar.util.js';
|
|
8
9
|
dayjs.extend(Utc);
|
|
9
10
|
dayjs.extend(Timezone);
|
|
10
11
|
dayjs.extend(IsoWeek);
|
|
@@ -260,53 +261,22 @@ export const calculatePollingPeriod = (interval, numberOfCandles = 2) => {
|
|
|
260
261
|
export const isPollingFetchPayload = (payload) => payload?.isPolling === true ||
|
|
261
262
|
(payload?.from === 0 && payload?.period === calculatePollingPeriod(payload?.interval ?? payload?.tf ?? ''));
|
|
262
263
|
/**
|
|
263
|
-
* US
|
|
264
|
-
*
|
|
265
|
-
*
|
|
266
|
-
*
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
REGULAR_START: { hour: 9, minute: 30 }, // 9:30 AM ET
|
|
271
|
-
REGULAR_END: { hour: 16, minute: 0 }, // 4:00 PM ET
|
|
272
|
-
AFTER_HOURS_END: { hour: 20, minute: 0 }, // 8:00 PM ET
|
|
273
|
-
};
|
|
274
|
-
/**
|
|
275
|
-
* Check if a given timestamp is within regular US market hours (9:30 AM - 4:00 PM ET)
|
|
264
|
+
* Check if a given timestamp is within regular US market hours (9:30 AM - 4:00 PM ET), on the
|
|
265
|
+
* weekday cycle in New York time: pre-market 4:00 AM - 9:30 AM, after-hours 4:00 PM - 8:00 PM,
|
|
266
|
+
* closed otherwise and all weekend (holidays are not modelled).
|
|
267
|
+
*
|
|
268
|
+
* Per-row callers (every landed stock bar) pay integer compares: the New York calendar
|
|
269
|
+
* (ny-calendar.util) resolves each date's session edges once. A non-number input keeps its old
|
|
270
|
+
* dayjs reading (`undefined` is now, a Date or a date string is its instant).
|
|
276
271
|
* @param timestampMs - Timestamp in milliseconds
|
|
277
272
|
* @returns Object containing:
|
|
278
273
|
* - isRegularHours: true if within regular hours (9:30 AM - 4:00 PM ET)
|
|
279
274
|
* - sessionType: 'pre' | 'regular' | 'after' | 'closed'
|
|
280
275
|
*/
|
|
281
276
|
export function checkUSMarketHours(timestampMs) {
|
|
282
|
-
|
|
283
|
-
const
|
|
284
|
-
|
|
285
|
-
// Check if it's a weekend
|
|
286
|
-
if (dayOfWeek === 0 || dayOfWeek === 6) {
|
|
287
|
-
return { isRegularHours: false, sessionType: 'closed' };
|
|
288
|
-
}
|
|
289
|
-
const hour = etTime.hour();
|
|
290
|
-
const minute = etTime.minute();
|
|
291
|
-
const timeInMinutes = hour * 60 + minute;
|
|
292
|
-
// Calculate time boundaries in minutes since midnight
|
|
293
|
-
const preMarketStart = US_MARKET_HOURS.PRE_MARKET_START.hour * 60 + US_MARKET_HOURS.PRE_MARKET_START.minute;
|
|
294
|
-
const regularStart = US_MARKET_HOURS.REGULAR_START.hour * 60 + US_MARKET_HOURS.REGULAR_START.minute;
|
|
295
|
-
const regularEnd = US_MARKET_HOURS.REGULAR_END.hour * 60 + US_MARKET_HOURS.REGULAR_END.minute;
|
|
296
|
-
const afterHoursEnd = US_MARKET_HOURS.AFTER_HOURS_END.hour * 60 + US_MARKET_HOURS.AFTER_HOURS_END.minute;
|
|
297
|
-
// Determine session type
|
|
298
|
-
if (timeInMinutes >= regularStart && timeInMinutes < regularEnd) {
|
|
299
|
-
return { isRegularHours: true, sessionType: 'regular' };
|
|
300
|
-
}
|
|
301
|
-
else if (timeInMinutes >= preMarketStart && timeInMinutes < regularStart) {
|
|
302
|
-
return { isRegularHours: false, sessionType: 'pre' };
|
|
303
|
-
}
|
|
304
|
-
else if (timeInMinutes >= regularEnd && timeInMinutes < afterHoursEnd) {
|
|
305
|
-
return { isRegularHours: false, sessionType: 'after' };
|
|
306
|
-
}
|
|
307
|
-
else {
|
|
308
|
-
return { isRegularHours: false, sessionType: 'closed' };
|
|
309
|
-
}
|
|
277
|
+
const tsMs = typeof timestampMs === 'number' ? timestampMs : dayjs(timestampMs).valueOf();
|
|
278
|
+
const sessionType = nyMarketPhaseAt(tsMs);
|
|
279
|
+
return { isRegularHours: sessionType === 'regular', sessionType };
|
|
310
280
|
}
|
|
311
281
|
// ─── ET calendar helpers ─────────────────────────────────────────────────
|
|
312
282
|
// Used for anything that needs to reason about "the current ET calendar day"
|
|
@@ -57,12 +57,17 @@ export declare function changeNumberFormat(value: number, precision: number): st
|
|
|
57
57
|
export declare function formatAdaptiveVolume(value: number): string;
|
|
58
58
|
export declare function safeDivide(a: number, b: number): number;
|
|
59
59
|
/**
|
|
60
|
-
* The
|
|
61
|
-
*
|
|
62
|
-
*
|
|
63
|
-
*
|
|
64
|
-
*
|
|
65
|
-
*
|
|
60
|
+
* The ticker's digits for a trade price, so one symbol reads the same number on
|
|
61
|
+
* every ticker surface. The decimals come from the price's own magnitude,
|
|
62
|
+
* because the FE holds no per-symbol tick size and the chart's axis precision
|
|
63
|
+
* moves with every zoom. `reference` is the price a difference belongs to: a
|
|
64
|
+
* 24h change prints at its price's resolution.
|
|
65
|
+
*
|
|
66
|
+
* Venue-blind: every value reads as a trade price. A surface that prints a
|
|
67
|
+
* market's figure asks the web's market-aware text
|
|
68
|
+
* (`src/utility/chart/market-price-text.util.ts`), which falls back to this for
|
|
69
|
+
* a plain price; through this ladder a crypto index market cap printed all
|
|
70
|
+
* thirteen digits.
|
|
66
71
|
*/
|
|
67
72
|
export declare function formatPriceByMagnitude(value: number, reference?: number): string;
|
|
68
73
|
export declare function titlePriceDirection(curr: unknown, prev: unknown, lastGlyph?: string): string;
|
|
@@ -74,8 +79,13 @@ export declare function titlePriceDirection(curr: unknown, prev: unknown, lastGl
|
|
|
74
79
|
* ratio to "1.00". Negative values (spread formulas) keep the magnitude rule.
|
|
75
80
|
*/
|
|
76
81
|
export declare function formatTitlePrice(price: number): string;
|
|
82
|
+
/**
|
|
83
|
+
* The tab title's price and its direction glyph, kept per chart and per market. `formatPrice` prints the price
|
|
84
|
+
* (default `formatTitlePrice`, venue-blind): the web passes its market-aware text
|
|
85
|
+
* (`src/utility/chart/market-price-text.util.ts`), so a crypto index reads in its own unit (`$1.08T ▲`).
|
|
86
|
+
*/
|
|
77
87
|
export declare function formatChartTitlePrice(price: number, tc: TitleChart, context: {
|
|
78
88
|
symbolKey: string;
|
|
79
89
|
previousPrice?: number;
|
|
80
|
-
}): string;
|
|
90
|
+
}, formatPrice?: (price: number) => string): string;
|
|
81
91
|
export {};
|
|
@@ -164,12 +164,17 @@ export function safeDivide(a, b) {
|
|
|
164
164
|
const TICKER_MIN_SIGNIFICANT_DIGITS = 3;
|
|
165
165
|
const MAX_TICKER_DECIMALS = 20;
|
|
166
166
|
/**
|
|
167
|
-
* The
|
|
168
|
-
*
|
|
169
|
-
*
|
|
170
|
-
*
|
|
171
|
-
*
|
|
172
|
-
*
|
|
167
|
+
* The ticker's digits for a trade price, so one symbol reads the same number on
|
|
168
|
+
* every ticker surface. The decimals come from the price's own magnitude,
|
|
169
|
+
* because the FE holds no per-symbol tick size and the chart's axis precision
|
|
170
|
+
* moves with every zoom. `reference` is the price a difference belongs to: a
|
|
171
|
+
* 24h change prints at its price's resolution.
|
|
172
|
+
*
|
|
173
|
+
* Venue-blind: every value reads as a trade price. A surface that prints a
|
|
174
|
+
* market's figure asks the web's market-aware text
|
|
175
|
+
* (`src/utility/chart/market-price-text.util.ts`), which falls back to this for
|
|
176
|
+
* a plain price; through this ladder a crypto index market cap printed all
|
|
177
|
+
* thirteen digits.
|
|
173
178
|
*/
|
|
174
179
|
export function formatPriceByMagnitude(value, reference = value) {
|
|
175
180
|
const ladder = value >= 10000 ? 1 : value >= 1000 ? 2 : value >= 100 ? 3 : value >= 10 ? 4 : 5;
|
|
@@ -209,11 +214,16 @@ export function formatTitlePrice(price) {
|
|
|
209
214
|
}
|
|
210
215
|
// Keyed by the chart instance so a destroyed chart takes its entry with it (no retainer).
|
|
211
216
|
const titlePricesByChart = new WeakMap();
|
|
212
|
-
|
|
217
|
+
/**
|
|
218
|
+
* The tab title's price and its direction glyph, kept per chart and per market. `formatPrice` prints the price
|
|
219
|
+
* (default `formatTitlePrice`, venue-blind): the web passes its market-aware text
|
|
220
|
+
* (`src/utility/chart/market-price-text.util.ts`), so a crypto index reads in its own unit (`$1.08T ▲`).
|
|
221
|
+
*/
|
|
222
|
+
export function formatChartTitlePrice(price, tc, context, formatPrice = formatTitlePrice) {
|
|
213
223
|
const stored = titlePricesByChart.get(tc);
|
|
214
224
|
const previous = stored?.symbolKey === context.symbolKey ? stored : undefined;
|
|
215
225
|
const glyph = titlePriceDirection(price, previous ? previous.price : context.previousPrice, previous?.glyph);
|
|
216
226
|
titlePricesByChart.set(tc, { symbolKey: context.symbolKey, price, glyph });
|
|
217
|
-
const formattedPrice =
|
|
227
|
+
const formattedPrice = formatPrice(price);
|
|
218
228
|
return glyph ? `${formattedPrice} ${glyph}` : formattedPrice;
|
|
219
229
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { zoneWallMsAt } from '../chart/ny-calendar.util.js';
|
|
1
2
|
import { contractExpiryEndMs, parseCmeContractExpiry } from '../symbol-selection/contract-expiry.util.js';
|
|
2
3
|
const MONTHS = ['JAN', 'FEB', 'MAR', 'APR', 'MAY', 'JUN', 'JUL', 'AUG', 'SEP', 'OCT', 'NOV', 'DEC'];
|
|
3
4
|
// Same contract pattern `OptionChainService.resolveOptionContractSelection` reads, e.g. `ESU6 C5400`.
|
|
@@ -80,8 +81,8 @@ const NEW_YORK_PARTS = new Intl.DateTimeFormat('en-US', {
|
|
|
80
81
|
hour: '2-digit',
|
|
81
82
|
minute: '2-digit',
|
|
82
83
|
});
|
|
83
|
-
/** The New York wall clock
|
|
84
|
-
function
|
|
84
|
+
/** The New York wall clock read from Intl: for the instants the zone clock does not serve (it throws for a non-date). */
|
|
85
|
+
function readNewYorkWallClockMs(instantMs) {
|
|
85
86
|
const read = {};
|
|
86
87
|
for (const part of NEW_YORK_PARTS.formatToParts(new Date(instantMs))) {
|
|
87
88
|
if (part.type !== 'literal')
|
|
@@ -89,6 +90,16 @@ function newYorkWallClockMs(instantMs) {
|
|
|
89
90
|
}
|
|
90
91
|
return Date.UTC(read.year, read.month - 1, read.day, read.hour, read.minute);
|
|
91
92
|
}
|
|
93
|
+
const MINUTE_MS = 60_000;
|
|
94
|
+
/**
|
|
95
|
+
* The New York wall clock of an instant, as a UTC-shaped epoch (minutes precision) for offset
|
|
96
|
+
* arithmetic: one Intl reading per UTC day (the zone clock in ny-calendar.util), since the 0DTE
|
|
97
|
+
* filter asks it for every flow row.
|
|
98
|
+
*/
|
|
99
|
+
function newYorkWallClockMs(instantMs) {
|
|
100
|
+
const wallMs = zoneWallMsAt(OSI_NEW_YORK, instantMs);
|
|
101
|
+
return Number.isNaN(wallMs) ? readNewYorkWallClockMs(instantMs) : Math.floor(wallMs / MINUTE_MS) * MINUTE_MS;
|
|
102
|
+
}
|
|
92
103
|
/** The New York calendar day an instant falls on, in days since the epoch: the US options trade date. */
|
|
93
104
|
export function newYorkDayNumber(instantMs) {
|
|
94
105
|
return Math.floor(newYorkWallClockMs(instantMs) / 86_400_000);
|
|
@@ -51,13 +51,21 @@ export function isContractExpired(rawSymbol, now = new Date()) {
|
|
|
51
51
|
return false;
|
|
52
52
|
return contractExpiryEndMs(expiry) < now.getTime();
|
|
53
53
|
}
|
|
54
|
+
/** One delivery-label formatter per date locale: the venue list labels every contract row with it. */
|
|
55
|
+
const deliveryFormatters = new Map();
|
|
54
56
|
/** Localized delivery label, e.g. "Jul 2026" / "2026年7月". '' when undecodable. */
|
|
55
57
|
export function formatContractExpiry(rawSymbol, locale, now = new Date()) {
|
|
56
58
|
const expiry = parseCmeContractExpiry(rawSymbol, now);
|
|
57
59
|
if (!expiry)
|
|
58
60
|
return '';
|
|
59
61
|
try {
|
|
60
|
-
|
|
62
|
+
const dateLocale = getDateLocale(locale);
|
|
63
|
+
let formatter = deliveryFormatters.get(dateLocale);
|
|
64
|
+
if (formatter === undefined) {
|
|
65
|
+
formatter = new Intl.DateTimeFormat(dateLocale, { month: 'short', year: 'numeric', timeZone: 'UTC' });
|
|
66
|
+
deliveryFormatters.set(dateLocale, formatter);
|
|
67
|
+
}
|
|
68
|
+
return formatter.format(new Date(Date.UTC(expiry.year, expiry.monthIndex, 15)));
|
|
61
69
|
}
|
|
62
70
|
catch {
|
|
63
71
|
return '';
|
|
@@ -6,5 +6,8 @@
|
|
|
6
6
|
* over a literal, never written (the phase 2 leaf-state guard's immutable form).
|
|
7
7
|
*/
|
|
8
8
|
export declare const IMPORT_REQUEST_TIMEOUT_MS = 20000;
|
|
9
|
-
/**
|
|
9
|
+
/**
|
|
10
|
+
* The types the poll asks for: a priced row of any venue answers on one of them. A crypto index (CRYPTOCAP: BTC.D,
|
|
11
|
+
* TOTAL2) answers only on its candle type, so a `CRYPTOCAP:` entry and a pin on one are found by name too.
|
|
12
|
+
*/
|
|
10
13
|
export declare const IMPORT_MARKET_TYPES: readonly string[];
|
|
@@ -6,5 +6,8 @@
|
|
|
6
6
|
* over a literal, never written (the phase 2 leaf-state guard's immutable form).
|
|
7
7
|
*/
|
|
8
8
|
export const IMPORT_REQUEST_TIMEOUT_MS = 20_000;
|
|
9
|
-
/**
|
|
10
|
-
|
|
9
|
+
/**
|
|
10
|
+
* The types the poll asks for: a priced row of any venue answers on one of them. A crypto index (CRYPTOCAP: BTC.D,
|
|
11
|
+
* TOTAL2) answers only on its candle type, so a `CRYPTOCAP:` entry and a pin on one are found by name too.
|
|
12
|
+
*/
|
|
13
|
+
export const IMPORT_MARKET_TYPES = ['TICKER_AGG', 'TRADE', 'CRYPTO_DOMINANCE_AGG'];
|