@orangecharts/wrun-chart-host 0.6.0 → 0.7.1
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 +14 -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/index.d.ts +2 -0
- package/dist/settings-templates/index.js +19 -5
- package/dist/settings-templates/indicator-fields.d.ts +2 -0
- package/dist/settings-templates/indicator-fields.js +10 -0
- package/dist/settings-templates/tool-rules.d.ts +12 -2
- package/dist/settings-templates/tool-rules.js +9 -2
- package/dist/settings-templates/tool-tables.generated.js +9 -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
|
@@ -16,12 +16,15 @@
|
|
|
16
16
|
* until the data latch corrects it. Known-coarse by design (v1).
|
|
17
17
|
*
|
|
18
18
|
* All math is done in exchange wall-clock parts obtained through Intl with an
|
|
19
|
-
* explicit timeZone
|
|
19
|
+
* explicit timeZone (the zone clock in ny-calendar.util: one Intl reading per
|
|
20
|
+
* UTC day, so the 1 Hz status tick does date arithmetic, not ~20 Intl calls),
|
|
21
|
+
* then converted back to UTC instants with the dual-offset
|
|
20
22
|
* probe (try CST/CDT, keep the one that renders back to the intended wall
|
|
21
23
|
* time). The session boundaries (16:00/17:00) are never inside a DST jump
|
|
22
24
|
* (those happen at 02:00 local), so the probe is always unambiguous.
|
|
23
25
|
*/
|
|
24
26
|
import { cmeServedAccessForExchange } from './cme-cache-context.util.js';
|
|
27
|
+
import { zoneWallMsAt } from './ny-calendar.util.js';
|
|
25
28
|
import { getRthWindowForSymbol, rthSessionOpenMs } from './rth-session.util.js';
|
|
26
29
|
import { delayedDefaultSecondsFor, gateProviderForExchange } from '../v2/gate-plane.util.js';
|
|
27
30
|
export const GOVERNED_FUTURES_TIME_ZONE = 'America/Chicago';
|
|
@@ -40,7 +43,8 @@ const partsFormatter = new Intl.DateTimeFormat('en-US', {
|
|
|
40
43
|
minute: 'numeric',
|
|
41
44
|
hourCycle: 'h23',
|
|
42
45
|
});
|
|
43
|
-
|
|
46
|
+
/** The Chicago wall clock read from Intl: for the instants the zone clock does not serve (it throws for a non-date). */
|
|
47
|
+
function readWallClockParts(utcMs) {
|
|
44
48
|
const parts = {};
|
|
45
49
|
for (const p of partsFormatter.formatToParts(new Date(utcMs)))
|
|
46
50
|
parts[p.type] = p.value;
|
|
@@ -54,6 +58,24 @@ function wallClockPartsAt(utcMs) {
|
|
|
54
58
|
minute: Number(parts.minute),
|
|
55
59
|
};
|
|
56
60
|
}
|
|
61
|
+
/**
|
|
62
|
+
* The Chicago wall clock at `utcMs`: one Intl reading per UTC day (the zone clock in
|
|
63
|
+
* ny-calendar.util), then date arithmetic. A status reads it about 20 times, every second.
|
|
64
|
+
*/
|
|
65
|
+
function wallClockPartsAt(utcMs) {
|
|
66
|
+
const wallMs = zoneWallMsAt(GOVERNED_FUTURES_TIME_ZONE, utcMs);
|
|
67
|
+
if (Number.isNaN(wallMs))
|
|
68
|
+
return readWallClockParts(utcMs);
|
|
69
|
+
const wall = new Date(wallMs);
|
|
70
|
+
return {
|
|
71
|
+
year: wall.getUTCFullYear(),
|
|
72
|
+
month: wall.getUTCMonth() + 1,
|
|
73
|
+
day: wall.getUTCDate(),
|
|
74
|
+
weekday: wall.getUTCDay(),
|
|
75
|
+
hour: wall.getUTCHours(),
|
|
76
|
+
minute: wall.getUTCMinutes(),
|
|
77
|
+
};
|
|
78
|
+
}
|
|
57
79
|
/**
|
|
58
80
|
* UTC instant for a Chicago wall-clock time on the calendar day of `dayAnchorUtcMs`
|
|
59
81
|
* (anchored at noon UTC so day arithmetic never straddles a DST jump). Probes the
|
|
@@ -4,12 +4,13 @@ import { type OmTargetMetadata } from './om-target.util.js';
|
|
|
4
4
|
/**
|
|
5
5
|
* The frontend's market-kind vocabulary: TitanCharts' `MarketKind` union plus
|
|
6
6
|
* FE-owned kinds for governed CME venues (`'futures'`), HyperLiquid
|
|
7
|
-
* prediction markets (`'hip4'`)
|
|
8
|
-
* the ECONOMICS catalog publishers, which the engine still knows as `'fred'`)
|
|
7
|
+
* prediction markets (`'hip4'`), economic series (`'economic'`: FRED and
|
|
8
|
+
* the ECONOMICS catalog publishers, which the engine still knows as `'fred'`)
|
|
9
|
+
* and the crypto-wide indices (`'cryptoIndex'`: CRYPTOCAP's BTC.D, TOTAL, ...).
|
|
9
10
|
* TitanCharts does not know these kinds; anything handed into the engine
|
|
10
11
|
* narrows through `toTitanMarketKind`.
|
|
11
12
|
*/
|
|
12
|
-
export type VenueMarketKind = Exclude<MarketKind, 'fred'> | 'economic' | 'futures' | 'hip4' | 'options';
|
|
13
|
+
export type VenueMarketKind = Exclude<MarketKind, 'fred'> | 'economic' | 'futures' | 'hip4' | 'options' | 'cryptoIndex';
|
|
13
14
|
/** Which wire path serves an economic series (see `economicSource`). */
|
|
14
15
|
export type EconomicSource = 'fred' | 'observation';
|
|
15
16
|
/**
|
|
@@ -123,14 +124,18 @@ export declare function checkIsForexCommodityOrFutures(exchange: string | undefi
|
|
|
123
124
|
* Narrow the FE kind to TitanCharts' `MarketKind` union at the engine
|
|
124
125
|
* boundary. `'futures'` maps to `'commodity'` for session handling; `'hip4'`
|
|
125
126
|
* maps to `'polymarket'` for the prediction renderer; `'economic'` maps to
|
|
126
|
-
* the engine's `'fred'` (single-value series treatment)
|
|
127
|
-
*
|
|
127
|
+
* the engine's `'fred'` (single-value series treatment); `'cryptoIndex'`
|
|
128
|
+
* maps to `'crypto'`: the indices print 24/7 (about every 250 ms after a
|
|
129
|
+
* price move, every 5 s per coin) onto uniform bars from 1m up, the crypto
|
|
130
|
+
* treatment's own shape, gap policy included. FE-internal code always sees
|
|
131
|
+
* the honest venue kind.
|
|
128
132
|
*/
|
|
129
133
|
export declare function toTitanMarketKind(kind: VenueMarketKind): MarketKind;
|
|
130
134
|
/**
|
|
131
135
|
* True when TitanCharts must omit the dedicated 'volume' legend overlay:
|
|
132
|
-
* economic series
|
|
133
|
-
* CME futures DO ship contracts volume on TRADE_AGG
|
|
136
|
+
* economic series, forex/commodity venues and the crypto indices ship no
|
|
137
|
+
* per-bar volume. Governed CME futures DO ship contracts volume on TRADE_AGG
|
|
138
|
+
* bars, so they keep it.
|
|
134
139
|
*/
|
|
135
140
|
export declare function venueOmitsVolumeOverlay(exchange: string | undefined | null): boolean;
|
|
136
141
|
export declare function checkIsDex(exchange: string | undefined | null): boolean;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { MARKET_CAPABILITIES, ONCHAIN_POOL_CAPABILITIES, } from '../../constants/marketCapabilities.constants.js';
|
|
2
2
|
import { isBlkExchange } from '../blk-market.util.js';
|
|
3
3
|
import { ECONOMIC_EXCHANGES, FRED_EXCHANGE } from '../../constants/economic.constants.js';
|
|
4
|
+
import { CRYPTO_INDEX_EXCHANGES } from './crypto-index.leaf.js';
|
|
4
5
|
import { isCmeGoverned, normalizeExchangeCode } from './cme-realtime.util.js';
|
|
5
6
|
import { isGovernedPlaneExchange } from '../v2/gate-plane.util.js';
|
|
6
7
|
import { isOmTargetPane } from './om-target.util.js';
|
|
@@ -76,6 +77,9 @@ const EXCHANGE_TO_KIND = {
|
|
|
76
77
|
// Economic series: FRED plus the ECONOMICS catalog venue and the observation
|
|
77
78
|
// publishers (economic.constants.ts owns the list).
|
|
78
79
|
...Object.fromEntries(ECONOMIC_EXCHANGES.map((code) => [code, 'economic'])),
|
|
80
|
+
// Crypto-wide indices (CRYPTOCAP): value prints 24/7 with no trades,
|
|
81
|
+
// volume or book behind them (crypto-index.leaf owns the list).
|
|
82
|
+
...Object.fromEntries(CRYPTO_INDEX_EXCHANGES.map((code) => [code, 'cryptoIndex'])),
|
|
79
83
|
// Polymarket
|
|
80
84
|
POLYMARKET: 'polymarket',
|
|
81
85
|
// Hip3 (Hyperliquid synthetic derivatives)
|
|
@@ -278,8 +282,11 @@ export function checkIsForexCommodityOrFutures(exchange) {
|
|
|
278
282
|
* Narrow the FE kind to TitanCharts' `MarketKind` union at the engine
|
|
279
283
|
* boundary. `'futures'` maps to `'commodity'` for session handling; `'hip4'`
|
|
280
284
|
* maps to `'polymarket'` for the prediction renderer; `'economic'` maps to
|
|
281
|
-
* the engine's `'fred'` (single-value series treatment)
|
|
282
|
-
*
|
|
285
|
+
* the engine's `'fred'` (single-value series treatment); `'cryptoIndex'`
|
|
286
|
+
* maps to `'crypto'`: the indices print 24/7 (about every 250 ms after a
|
|
287
|
+
* price move, every 5 s per coin) onto uniform bars from 1m up, the crypto
|
|
288
|
+
* treatment's own shape, gap policy included. FE-internal code always sees
|
|
289
|
+
* the honest venue kind.
|
|
283
290
|
*/
|
|
284
291
|
export function toTitanMarketKind(kind) {
|
|
285
292
|
if (kind === 'futures' || kind === 'options')
|
|
@@ -288,15 +295,18 @@ export function toTitanMarketKind(kind) {
|
|
|
288
295
|
return 'polymarket';
|
|
289
296
|
if (kind === 'economic')
|
|
290
297
|
return 'fred';
|
|
298
|
+
if (kind === 'cryptoIndex')
|
|
299
|
+
return 'crypto';
|
|
291
300
|
return kind;
|
|
292
301
|
}
|
|
293
302
|
/**
|
|
294
303
|
* True when TitanCharts must omit the dedicated 'volume' legend overlay:
|
|
295
|
-
* economic series
|
|
296
|
-
* CME futures DO ship contracts volume on TRADE_AGG
|
|
304
|
+
* economic series, forex/commodity venues and the crypto indices ship no
|
|
305
|
+
* per-bar volume. Governed CME futures DO ship contracts volume on TRADE_AGG
|
|
306
|
+
* bars, so they keep it.
|
|
297
307
|
*/
|
|
298
308
|
export function venueOmitsVolumeOverlay(exchange) {
|
|
299
|
-
return checkIsEconomic(exchange) || checkIsForexOrCommodity(exchange);
|
|
309
|
+
return checkIsEconomic(exchange) || checkIsForexOrCommodity(exchange) || getMarketKind(exchange) === 'cryptoIndex';
|
|
300
310
|
}
|
|
301
311
|
export function checkIsDex(exchange) {
|
|
302
312
|
return getMarketKind(exchange) === 'dex';
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The shared point for per-row timezone math: a zone clock for any IANA zone (one Intl reading per
|
|
3
|
+
* UTC day), and on it the New York calendar behind every US equities session question (the pre /
|
|
4
|
+
* regular / after phase, the 09:30 anchored bucket, the next regular open), resolved once per date.
|
|
5
|
+
*
|
|
6
|
+
* Why this exists (CPU profiles 2026-10-20, UW-PARITY reports/INDICATOR-LOAD-BUDGET.md): on 45m
|
|
7
|
+
* to 12h stock bars every landed row re-derived the New York wall clock through dayjs
|
|
8
|
+
* (`checkUSMarketHours`, plus a format and a parse for the anchored bucket), about 24 us per
|
|
9
|
+
* conversion. One 1h Flow Marks add spent 8.9 s in dayjs `.tz`, and the host-bar walk
|
|
10
|
+
* (`liveBucketStartsInRange`) probed every quarter hour through nights and weekends at three
|
|
11
|
+
* conversions a probe. The same mistake sat in the Chicago schedule (about 20 Intl readings per
|
|
12
|
+
* status, every second), the regional session windows, the option symbol dates and the bar facts.
|
|
13
|
+
* An offset changes twice a year, so each zone reads it once per UTC day into a bounded memo and
|
|
14
|
+
* every row does integer math against it.
|
|
15
|
+
*
|
|
16
|
+
* The zone clock (`zoneOffsetMsAt`, `zoneWallMsAt`, `zoneWallToUtcMs`) reads Intl at a UTC day's
|
|
17
|
+
* first and last second; a day whose two readings differ is bisected to the second the offset
|
|
18
|
+
* changes on. Exact for any zone that changes its offset at most once per UTC day (every zone the
|
|
19
|
+
* app reads); a second change inside one day is detected and read per instant. It serves the
|
|
20
|
+
* instants from the year 100 to the Date range edge: a caller keeps its own reading outside them.
|
|
21
|
+
*
|
|
22
|
+
* The New York calendar, per date (DST-exact on the 23h and 25h days): its span [00:00, next 00:00)
|
|
23
|
+
* and its session edges in UTC ms, on the weekday cycle `checkUSMarketHours` has always read:
|
|
24
|
+
* pre 04:00 -> 09:30
|
|
25
|
+
* regular 09:30 -> 16:00
|
|
26
|
+
* after 16:00 -> 20:00
|
|
27
|
+
* closed everything else, and all of Saturday and Sunday
|
|
28
|
+
* Holidays and half days are NOT modelled (the v1 scope of us-equities-session.util): an
|
|
29
|
+
* exchange holiday reads as a normal weekday.
|
|
30
|
+
*
|
|
31
|
+
* Host-independent (dayjs re-parsed the zone's wall string in the host zone, which misreads an
|
|
32
|
+
* hour on the host's own DST days). Pure and worker-safe: Intl only, no dayjs.
|
|
33
|
+
*/
|
|
34
|
+
export declare const NY_TIME_ZONE = "America/New_York";
|
|
35
|
+
/** Session edges as wall-clock minutes after New York midnight. */
|
|
36
|
+
export declare const NY_PRE_MARKET_OPEN_MINUTES: number;
|
|
37
|
+
export declare const NY_REGULAR_OPEN_MINUTES: number;
|
|
38
|
+
export declare const NY_REGULAR_CLOSE_MINUTES: number;
|
|
39
|
+
export declare const NY_POST_MARKET_CLOSE_MINUTES: number;
|
|
40
|
+
export type NyMarketPhase = 'pre' | 'regular' | 'after' | 'closed';
|
|
41
|
+
/** One New York calendar date, resolved once: its span and its session edges in UTC ms. */
|
|
42
|
+
export interface NyCalendarDay {
|
|
43
|
+
/** The date as whole days since 1970-01-01 (its 00:00Z over 86,400,000). */
|
|
44
|
+
readonly dayNumber: number;
|
|
45
|
+
/** 0 Sunday to 6 Saturday. */
|
|
46
|
+
readonly weekday: number;
|
|
47
|
+
/** Monday to Friday: a date with sessions (holidays are not modelled). */
|
|
48
|
+
readonly isTradeDate: boolean;
|
|
49
|
+
/** New York midnight that starts the date, and the next one: the date is [dayStartMs, dayEndMs). */
|
|
50
|
+
readonly dayStartMs: number;
|
|
51
|
+
readonly dayEndMs: number;
|
|
52
|
+
/** Wall clock minus UTC at the regular open, in ms (-4h in EDT, -5h in EST). */
|
|
53
|
+
readonly utcOffsetMs: number;
|
|
54
|
+
readonly preMarketOpenMs: number;
|
|
55
|
+
readonly regularOpenMs: number;
|
|
56
|
+
/** The regular close, which is also the after-hours open. */
|
|
57
|
+
readonly regularCloseMs: number;
|
|
58
|
+
readonly postMarketCloseMs: number;
|
|
59
|
+
}
|
|
60
|
+
/** Test oracle: New York dates resolved (`computed`), instants looked up (`lookups`), zone UTC days read (`zoneDays`). */
|
|
61
|
+
export declare const __nyCalendarStats: {
|
|
62
|
+
computed: number;
|
|
63
|
+
lookups: number;
|
|
64
|
+
zoneDays: number;
|
|
65
|
+
};
|
|
66
|
+
/**
|
|
67
|
+
* `zone`'s offset at `tMs` (wall clock minus UTC, ms; a fractional ms truncates, as a Date's does).
|
|
68
|
+
* NaN outside the instants the clock serves (from the year 100 to the Date range edge): the caller
|
|
69
|
+
* keeps its own reading there. Throws Intl's RangeError for a zone it does not know.
|
|
70
|
+
*/
|
|
71
|
+
export declare function zoneOffsetMsAt(zone: string, tMs: number): number;
|
|
72
|
+
/** The wall clock `tMs` reads in `zone`, as a UTC-shaped epoch at ms precision; NaN outside the span served. */
|
|
73
|
+
export declare function zoneWallMsAt(zone: string, tMs: number): number;
|
|
74
|
+
/**
|
|
75
|
+
* The instant `zone`'s wall clock reads `wallMs` (a UTC-shaped epoch), by fixed-point iteration from
|
|
76
|
+
* `seedOffsetMs` (the offset at `wallMs` read as an instant, when absent): an instant whose own offset
|
|
77
|
+
* is the one it was solved with is the answer, so a wall time on either side of a change settles on
|
|
78
|
+
* its own offset in one or two reads. A wall time a change skips or repeats settles on one of its
|
|
79
|
+
* readings: callers keep their edges off the change. NaN outside the span served.
|
|
80
|
+
*/
|
|
81
|
+
export declare function zoneWallToUtcMs(zone: string, wallMs: number, seedOffsetMs?: number): number;
|
|
82
|
+
/** Test hook: empty memos (the New York dates and every zone's UTC days) and zeroed counters. */
|
|
83
|
+
export declare function __resetNyCalendarMemo(): void;
|
|
84
|
+
/**
|
|
85
|
+
* The New York calendar date `dayNumber` (days since 1970-01-01), resolved once; null outside the
|
|
86
|
+
* span the zone clock serves, and where the runtime has no New York zone data.
|
|
87
|
+
*/
|
|
88
|
+
export declare function nyCalendarDay(dayNumber: number): NyCalendarDay | null;
|
|
89
|
+
/**
|
|
90
|
+
* The New York calendar date holding the instant `tsMs`; a fractional ms truncates, as a Date's
|
|
91
|
+
* does. Null for a non-finite instant or one outside the span the zone clock serves.
|
|
92
|
+
*/
|
|
93
|
+
export declare function nyCalendarDayAt(tsMs: number): NyCalendarDay | null;
|
|
94
|
+
/** The session phase at `tsMs`: 'closed' on Saturday and Sunday, and for an instant that is not a date. */
|
|
95
|
+
export declare function nyMarketPhaseAt(tsMs: number): NyMarketPhase;
|
|
96
|
+
/** The regular open of the cash session holding `tsMs`; null outside [09:30, 16:00) on a trade date. */
|
|
97
|
+
export declare function nyRegularSessionOpenMs(tsMs: number): number | null;
|
|
98
|
+
/**
|
|
99
|
+
* The first regular open strictly after `tsMs`: the same date's while before it, else the next
|
|
100
|
+
* Monday-to-Friday date's (weekend dates are skipped by arithmetic, never resolved). Null when
|
|
101
|
+
* there is none at or before `notAfterMs`, or outside the span served: a walk bounded by
|
|
102
|
+
* `notAfterMs` never resolves a date it will not reach (a date's open is after its own 00:00Z).
|
|
103
|
+
*/
|
|
104
|
+
export declare function nyNextRegularOpenAfterMs(tsMs: number, notAfterMs?: number): number | null;
|
|
@@ -0,0 +1,346 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The shared point for per-row timezone math: a zone clock for any IANA zone (one Intl reading per
|
|
3
|
+
* UTC day), and on it the New York calendar behind every US equities session question (the pre /
|
|
4
|
+
* regular / after phase, the 09:30 anchored bucket, the next regular open), resolved once per date.
|
|
5
|
+
*
|
|
6
|
+
* Why this exists (CPU profiles 2026-10-20, UW-PARITY reports/INDICATOR-LOAD-BUDGET.md): on 45m
|
|
7
|
+
* to 12h stock bars every landed row re-derived the New York wall clock through dayjs
|
|
8
|
+
* (`checkUSMarketHours`, plus a format and a parse for the anchored bucket), about 24 us per
|
|
9
|
+
* conversion. One 1h Flow Marks add spent 8.9 s in dayjs `.tz`, and the host-bar walk
|
|
10
|
+
* (`liveBucketStartsInRange`) probed every quarter hour through nights and weekends at three
|
|
11
|
+
* conversions a probe. The same mistake sat in the Chicago schedule (about 20 Intl readings per
|
|
12
|
+
* status, every second), the regional session windows, the option symbol dates and the bar facts.
|
|
13
|
+
* An offset changes twice a year, so each zone reads it once per UTC day into a bounded memo and
|
|
14
|
+
* every row does integer math against it.
|
|
15
|
+
*
|
|
16
|
+
* The zone clock (`zoneOffsetMsAt`, `zoneWallMsAt`, `zoneWallToUtcMs`) reads Intl at a UTC day's
|
|
17
|
+
* first and last second; a day whose two readings differ is bisected to the second the offset
|
|
18
|
+
* changes on. Exact for any zone that changes its offset at most once per UTC day (every zone the
|
|
19
|
+
* app reads); a second change inside one day is detected and read per instant. It serves the
|
|
20
|
+
* instants from the year 100 to the Date range edge: a caller keeps its own reading outside them.
|
|
21
|
+
*
|
|
22
|
+
* The New York calendar, per date (DST-exact on the 23h and 25h days): its span [00:00, next 00:00)
|
|
23
|
+
* and its session edges in UTC ms, on the weekday cycle `checkUSMarketHours` has always read:
|
|
24
|
+
* pre 04:00 -> 09:30
|
|
25
|
+
* regular 09:30 -> 16:00
|
|
26
|
+
* after 16:00 -> 20:00
|
|
27
|
+
* closed everything else, and all of Saturday and Sunday
|
|
28
|
+
* Holidays and half days are NOT modelled (the v1 scope of us-equities-session.util): an
|
|
29
|
+
* exchange holiday reads as a normal weekday.
|
|
30
|
+
*
|
|
31
|
+
* Host-independent (dayjs re-parsed the zone's wall string in the host zone, which misreads an
|
|
32
|
+
* hour on the host's own DST days). Pure and worker-safe: Intl only, no dayjs.
|
|
33
|
+
*/
|
|
34
|
+
export const NY_TIME_ZONE = 'America/New_York';
|
|
35
|
+
/** Session edges as wall-clock minutes after New York midnight. */
|
|
36
|
+
export const NY_PRE_MARKET_OPEN_MINUTES = 4 * 60;
|
|
37
|
+
export const NY_REGULAR_OPEN_MINUTES = 9 * 60 + 30;
|
|
38
|
+
export const NY_REGULAR_CLOSE_MINUTES = 16 * 60;
|
|
39
|
+
export const NY_POST_MARKET_CLOSE_MINUTES = 20 * 60;
|
|
40
|
+
const SECOND_MS = 1_000;
|
|
41
|
+
const MINUTE_MS = 60_000;
|
|
42
|
+
const HOUR_MS = 3_600_000;
|
|
43
|
+
const DAY_MS = 86_400_000;
|
|
44
|
+
const DAY_S = 86_400;
|
|
45
|
+
const EST_OFFSET_MS = -5 * HOUR_MS;
|
|
46
|
+
/** Test oracle: New York dates resolved (`computed`), instants looked up (`lookups`), zone UTC days read (`zoneDays`). */
|
|
47
|
+
export const __nyCalendarStats = { computed: 0, lookups: 0, zoneDays: 0 };
|
|
48
|
+
// ─── The zone clock: any IANA zone, one Intl reading per UTC day ────────────
|
|
49
|
+
/** The Date range edge (ECMA-262 TimeClip): an instant past it is not a date. */
|
|
50
|
+
const MAX_TIME_MS = 8.64e15;
|
|
51
|
+
/**
|
|
52
|
+
* The instants the zone clock serves: from the year 100 (Intl and `Date.UTC` agree on the year from
|
|
53
|
+
* there) to two days inside the Date range edge (a UTC day's readings stay inside it).
|
|
54
|
+
*/
|
|
55
|
+
const ZONE_CLOCK_MIN_MS = Date.UTC(100, 0, 2);
|
|
56
|
+
const ZONE_CLOCK_MAX_MS = MAX_TIME_MS - 2 * DAY_MS;
|
|
57
|
+
/** UTC days kept per zone, oldest out first: eleven years. */
|
|
58
|
+
const ZONE_DAYS_MAX = 4096;
|
|
59
|
+
const zoneClocks = new Map();
|
|
60
|
+
/** The zone's clock; throws the RangeError Intl throws for a zone it does not know. */
|
|
61
|
+
function zoneClockOf(zone) {
|
|
62
|
+
let clock = zoneClocks.get(zone);
|
|
63
|
+
if (clock === undefined) {
|
|
64
|
+
clock = {
|
|
65
|
+
formatter: new Intl.DateTimeFormat('en-US', {
|
|
66
|
+
timeZone: zone,
|
|
67
|
+
hourCycle: 'h23',
|
|
68
|
+
year: 'numeric',
|
|
69
|
+
month: 'numeric',
|
|
70
|
+
day: 'numeric',
|
|
71
|
+
hour: 'numeric',
|
|
72
|
+
minute: 'numeric',
|
|
73
|
+
second: 'numeric',
|
|
74
|
+
}),
|
|
75
|
+
days: new Map(),
|
|
76
|
+
last: null,
|
|
77
|
+
};
|
|
78
|
+
zoneClocks.set(zone, clock);
|
|
79
|
+
}
|
|
80
|
+
return clock;
|
|
81
|
+
}
|
|
82
|
+
/** The zone's offset at the whole ms `tMs` as Intl renders it: wall clock minus UTC, whole seconds. */
|
|
83
|
+
function readOffsetMs(formatter, tMs) {
|
|
84
|
+
let year = 1970;
|
|
85
|
+
let month = 1;
|
|
86
|
+
let day = 1;
|
|
87
|
+
let hour = 0;
|
|
88
|
+
let minute = 0;
|
|
89
|
+
let second = 0;
|
|
90
|
+
for (const part of formatter.formatToParts(tMs)) {
|
|
91
|
+
switch (part.type) {
|
|
92
|
+
case 'year':
|
|
93
|
+
year = Number(part.value);
|
|
94
|
+
break;
|
|
95
|
+
case 'month':
|
|
96
|
+
month = Number(part.value);
|
|
97
|
+
break;
|
|
98
|
+
case 'day':
|
|
99
|
+
day = Number(part.value);
|
|
100
|
+
break;
|
|
101
|
+
case 'hour':
|
|
102
|
+
// Some ICU builds render midnight as 24 even under h23.
|
|
103
|
+
hour = Number(part.value) % 24;
|
|
104
|
+
break;
|
|
105
|
+
case 'minute':
|
|
106
|
+
minute = Number(part.value);
|
|
107
|
+
break;
|
|
108
|
+
case 'second':
|
|
109
|
+
second = Number(part.value);
|
|
110
|
+
break;
|
|
111
|
+
default:
|
|
112
|
+
break;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
return Date.UTC(year, month - 1, day, hour, minute, second) - Math.floor(tMs / SECOND_MS) * SECOND_MS;
|
|
116
|
+
}
|
|
117
|
+
function resolveZoneUtcDay(formatter, dayNumber) {
|
|
118
|
+
const startMs = dayNumber * DAY_MS;
|
|
119
|
+
const offsetMs = readOffsetMs(formatter, startMs);
|
|
120
|
+
const endOffsetMs = readOffsetMs(formatter, startMs + DAY_MS - SECOND_MS);
|
|
121
|
+
if (endOffsetMs === offsetMs) {
|
|
122
|
+
return Object.freeze({
|
|
123
|
+
dayNumber,
|
|
124
|
+
offsetMs,
|
|
125
|
+
transitionMs: Number.POSITIVE_INFINITY,
|
|
126
|
+
laterOffsetMs: offsetMs,
|
|
127
|
+
irregular: false,
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
// An offset changes on a whole second: bisect the day's seconds for the first one off `offsetMs`.
|
|
131
|
+
let lo = 0;
|
|
132
|
+
let hi = DAY_S - 1;
|
|
133
|
+
let hiOffsetMs = endOffsetMs;
|
|
134
|
+
while (hi - lo > 1) {
|
|
135
|
+
const mid = (lo + hi) >>> 1;
|
|
136
|
+
const midOffsetMs = readOffsetMs(formatter, startMs + mid * SECOND_MS);
|
|
137
|
+
if (midOffsetMs === offsetMs) {
|
|
138
|
+
lo = mid;
|
|
139
|
+
}
|
|
140
|
+
else {
|
|
141
|
+
hi = mid;
|
|
142
|
+
hiOffsetMs = midOffsetMs;
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
return Object.freeze({
|
|
146
|
+
dayNumber,
|
|
147
|
+
offsetMs,
|
|
148
|
+
transitionMs: startMs + hi * SECOND_MS,
|
|
149
|
+
laterOffsetMs: hiOffsetMs,
|
|
150
|
+
irregular: hiOffsetMs !== endOffsetMs,
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
function zoneUtcDayOf(clock, dayNumber) {
|
|
154
|
+
const last = clock.last;
|
|
155
|
+
if (last !== null && last.dayNumber === dayNumber)
|
|
156
|
+
return last;
|
|
157
|
+
let day = clock.days.get(dayNumber);
|
|
158
|
+
if (day === undefined) {
|
|
159
|
+
day = resolveZoneUtcDay(clock.formatter, dayNumber);
|
|
160
|
+
__nyCalendarStats.zoneDays += 1;
|
|
161
|
+
if (clock.days.size >= ZONE_DAYS_MAX) {
|
|
162
|
+
const oldest = clock.days.keys().next();
|
|
163
|
+
if (!oldest.done)
|
|
164
|
+
clock.days.delete(oldest.value);
|
|
165
|
+
}
|
|
166
|
+
clock.days.set(dayNumber, day);
|
|
167
|
+
}
|
|
168
|
+
clock.last = day;
|
|
169
|
+
return day;
|
|
170
|
+
}
|
|
171
|
+
/**
|
|
172
|
+
* `zone`'s offset at `tMs` (wall clock minus UTC, ms; a fractional ms truncates, as a Date's does).
|
|
173
|
+
* NaN outside the instants the clock serves (from the year 100 to the Date range edge): the caller
|
|
174
|
+
* keeps its own reading there. Throws Intl's RangeError for a zone it does not know.
|
|
175
|
+
*/
|
|
176
|
+
export function zoneOffsetMsAt(zone, tMs) {
|
|
177
|
+
if (!(tMs >= ZONE_CLOCK_MIN_MS && tMs <= ZONE_CLOCK_MAX_MS))
|
|
178
|
+
return Number.NaN;
|
|
179
|
+
const clock = zoneClockOf(zone);
|
|
180
|
+
const t = Math.trunc(tMs);
|
|
181
|
+
const day = zoneUtcDayOf(clock, Math.floor(t / DAY_MS));
|
|
182
|
+
if (day.irregular)
|
|
183
|
+
return readOffsetMs(clock.formatter, t);
|
|
184
|
+
return t < day.transitionMs ? day.offsetMs : day.laterOffsetMs;
|
|
185
|
+
}
|
|
186
|
+
/** The wall clock `tMs` reads in `zone`, as a UTC-shaped epoch at ms precision; NaN outside the span served. */
|
|
187
|
+
export function zoneWallMsAt(zone, tMs) {
|
|
188
|
+
const offsetMs = zoneOffsetMsAt(zone, tMs);
|
|
189
|
+
return Number.isNaN(offsetMs) ? offsetMs : Math.trunc(tMs) + offsetMs;
|
|
190
|
+
}
|
|
191
|
+
/**
|
|
192
|
+
* The instant `zone`'s wall clock reads `wallMs` (a UTC-shaped epoch), by fixed-point iteration from
|
|
193
|
+
* `seedOffsetMs` (the offset at `wallMs` read as an instant, when absent): an instant whose own offset
|
|
194
|
+
* is the one it was solved with is the answer, so a wall time on either side of a change settles on
|
|
195
|
+
* its own offset in one or two reads. A wall time a change skips or repeats settles on one of its
|
|
196
|
+
* readings: callers keep their edges off the change. NaN outside the span served.
|
|
197
|
+
*/
|
|
198
|
+
export function zoneWallToUtcMs(zone, wallMs, seedOffsetMs = zoneOffsetMsAt(zone, wallMs)) {
|
|
199
|
+
let offsetMs = seedOffsetMs;
|
|
200
|
+
for (let read = 0; read < 3; read += 1) {
|
|
201
|
+
const candidateMs = wallMs - offsetMs;
|
|
202
|
+
const actualMs = zoneOffsetMsAt(zone, candidateMs);
|
|
203
|
+
if (actualMs === offsetMs || Number.isNaN(actualMs))
|
|
204
|
+
return Number.isNaN(actualMs) ? actualMs : candidateMs;
|
|
205
|
+
offsetMs = actualMs;
|
|
206
|
+
}
|
|
207
|
+
return wallMs - offsetMs;
|
|
208
|
+
}
|
|
209
|
+
// ─── The New York calendar ───────────────────────────────────────────────────
|
|
210
|
+
/** The dates whose span and session edges stay inside the instants the zone clock serves. */
|
|
211
|
+
const MIN_DAY_NUMBER = Math.ceil(ZONE_CLOCK_MIN_MS / DAY_MS) + 1;
|
|
212
|
+
const MAX_DAY_NUMBER = Math.floor(ZONE_CLOCK_MAX_MS / DAY_MS) - 2;
|
|
213
|
+
/** New York dates kept, oldest out first: eight years of trade dates; a sorted scan never revisits an evicted one. */
|
|
214
|
+
const NY_CALENDAR_MEMO_MAX = 2048;
|
|
215
|
+
/** 1970-01-01 was a Thursday. */
|
|
216
|
+
const weekdayOf = (dayNumber) => (((dayNumber + 4) % 7) + 7) % 7;
|
|
217
|
+
const isTradeDateNumber = (dayNumber) => {
|
|
218
|
+
const weekday = weekdayOf(dayNumber);
|
|
219
|
+
return weekday >= 1 && weekday <= 5;
|
|
220
|
+
};
|
|
221
|
+
function resolveDay(dayNumber) {
|
|
222
|
+
// The offset after the 02:00 transition hour, read at 12:00Z (07:00 or 08:00 New York), seeds every edge.
|
|
223
|
+
const seedOffsetMs = zoneOffsetMsAt(NY_TIME_ZONE, dayNumber * DAY_MS + 12 * HOUR_MS);
|
|
224
|
+
const at = (day, minutes) => zoneWallToUtcMs(NY_TIME_ZONE, day * DAY_MS + minutes * MINUTE_MS, seedOffsetMs);
|
|
225
|
+
const regularOpenMs = at(dayNumber, NY_REGULAR_OPEN_MINUTES);
|
|
226
|
+
const weekday = weekdayOf(dayNumber);
|
|
227
|
+
return Object.freeze({
|
|
228
|
+
dayNumber,
|
|
229
|
+
weekday,
|
|
230
|
+
isTradeDate: weekday >= 1 && weekday <= 5,
|
|
231
|
+
dayStartMs: at(dayNumber, 0),
|
|
232
|
+
dayEndMs: at(dayNumber + 1, 0),
|
|
233
|
+
utcOffsetMs: dayNumber * DAY_MS + NY_REGULAR_OPEN_MINUTES * MINUTE_MS - regularOpenMs,
|
|
234
|
+
preMarketOpenMs: at(dayNumber, NY_PRE_MARKET_OPEN_MINUTES),
|
|
235
|
+
regularOpenMs,
|
|
236
|
+
regularCloseMs: at(dayNumber, NY_REGULAR_CLOSE_MINUTES),
|
|
237
|
+
postMarketCloseMs: at(dayNumber, NY_POST_MARKET_CLOSE_MINUTES),
|
|
238
|
+
});
|
|
239
|
+
}
|
|
240
|
+
const daysByNumber = new Map();
|
|
241
|
+
/** The date the last instant fell on: a sorted scan hits it for a whole day without a Map read. */
|
|
242
|
+
let lastDay = null;
|
|
243
|
+
/** Test hook: empty memos (the New York dates and every zone's UTC days) and zeroed counters. */
|
|
244
|
+
export function __resetNyCalendarMemo() {
|
|
245
|
+
daysByNumber.clear();
|
|
246
|
+
lastDay = null;
|
|
247
|
+
for (const clock of zoneClocks.values()) {
|
|
248
|
+
clock.days.clear();
|
|
249
|
+
clock.last = null;
|
|
250
|
+
}
|
|
251
|
+
__nyCalendarStats.computed = 0;
|
|
252
|
+
__nyCalendarStats.lookups = 0;
|
|
253
|
+
__nyCalendarStats.zoneDays = 0;
|
|
254
|
+
}
|
|
255
|
+
/**
|
|
256
|
+
* The New York calendar date `dayNumber` (days since 1970-01-01), resolved once; null outside the
|
|
257
|
+
* span the zone clock serves, and where the runtime has no New York zone data.
|
|
258
|
+
*/
|
|
259
|
+
export function nyCalendarDay(dayNumber) {
|
|
260
|
+
if (!Number.isInteger(dayNumber) || dayNumber < MIN_DAY_NUMBER || dayNumber > MAX_DAY_NUMBER)
|
|
261
|
+
return null;
|
|
262
|
+
const cached = daysByNumber.get(dayNumber);
|
|
263
|
+
if (cached !== undefined)
|
|
264
|
+
return cached;
|
|
265
|
+
let day;
|
|
266
|
+
try {
|
|
267
|
+
day = resolveDay(dayNumber);
|
|
268
|
+
}
|
|
269
|
+
catch {
|
|
270
|
+
return null;
|
|
271
|
+
}
|
|
272
|
+
__nyCalendarStats.computed += 1;
|
|
273
|
+
if (daysByNumber.size >= NY_CALENDAR_MEMO_MAX) {
|
|
274
|
+
const oldest = daysByNumber.keys().next();
|
|
275
|
+
if (!oldest.done)
|
|
276
|
+
daysByNumber.delete(oldest.value);
|
|
277
|
+
}
|
|
278
|
+
daysByNumber.set(dayNumber, day);
|
|
279
|
+
return day;
|
|
280
|
+
}
|
|
281
|
+
/**
|
|
282
|
+
* The New York calendar date holding the instant `tsMs`; a fractional ms truncates, as a Date's
|
|
283
|
+
* does. Null for a non-finite instant or one outside the span the zone clock serves.
|
|
284
|
+
*/
|
|
285
|
+
export function nyCalendarDayAt(tsMs) {
|
|
286
|
+
__nyCalendarStats.lookups += 1;
|
|
287
|
+
if (!(tsMs >= -MAX_TIME_MS && tsMs <= MAX_TIME_MS))
|
|
288
|
+
return null;
|
|
289
|
+
const t = Math.trunc(tsMs);
|
|
290
|
+
const hit = lastDay;
|
|
291
|
+
if (hit !== null && t >= hit.dayStartMs && t < hit.dayEndMs)
|
|
292
|
+
return hit;
|
|
293
|
+
// The last offset seen (EST before any) names the date, except within an hour of midnight across a DST change.
|
|
294
|
+
let day = nyCalendarDay(Math.floor((t + (hit?.utcOffsetMs ?? EST_OFFSET_MS)) / DAY_MS));
|
|
295
|
+
while (day !== null && t < day.dayStartMs)
|
|
296
|
+
day = nyCalendarDay(day.dayNumber - 1);
|
|
297
|
+
while (day !== null && t >= day.dayEndMs)
|
|
298
|
+
day = nyCalendarDay(day.dayNumber + 1);
|
|
299
|
+
if (day !== null)
|
|
300
|
+
lastDay = day;
|
|
301
|
+
return day;
|
|
302
|
+
}
|
|
303
|
+
/** The phase of the instant `tsMs` on its own date `day`. */
|
|
304
|
+
function phaseOn(day, tsMs) {
|
|
305
|
+
if (!day.isTradeDate)
|
|
306
|
+
return 'closed';
|
|
307
|
+
const t = Math.trunc(tsMs);
|
|
308
|
+
if (t < day.preMarketOpenMs)
|
|
309
|
+
return 'closed';
|
|
310
|
+
if (t < day.regularOpenMs)
|
|
311
|
+
return 'pre';
|
|
312
|
+
if (t < day.regularCloseMs)
|
|
313
|
+
return 'regular';
|
|
314
|
+
return t < day.postMarketCloseMs ? 'after' : 'closed';
|
|
315
|
+
}
|
|
316
|
+
/** The session phase at `tsMs`: 'closed' on Saturday and Sunday, and for an instant that is not a date. */
|
|
317
|
+
export function nyMarketPhaseAt(tsMs) {
|
|
318
|
+
const day = nyCalendarDayAt(tsMs);
|
|
319
|
+
return day === null ? 'closed' : phaseOn(day, tsMs);
|
|
320
|
+
}
|
|
321
|
+
/** The regular open of the cash session holding `tsMs`; null outside [09:30, 16:00) on a trade date. */
|
|
322
|
+
export function nyRegularSessionOpenMs(tsMs) {
|
|
323
|
+
const day = nyCalendarDayAt(tsMs);
|
|
324
|
+
return day !== null && phaseOn(day, tsMs) === 'regular' ? day.regularOpenMs : null;
|
|
325
|
+
}
|
|
326
|
+
/**
|
|
327
|
+
* The first regular open strictly after `tsMs`: the same date's while before it, else the next
|
|
328
|
+
* Monday-to-Friday date's (weekend dates are skipped by arithmetic, never resolved). Null when
|
|
329
|
+
* there is none at or before `notAfterMs`, or outside the span served: a walk bounded by
|
|
330
|
+
* `notAfterMs` never resolves a date it will not reach (a date's open is after its own 00:00Z).
|
|
331
|
+
*/
|
|
332
|
+
export function nyNextRegularOpenAfterMs(tsMs, notAfterMs = Number.POSITIVE_INFINITY) {
|
|
333
|
+
const day = nyCalendarDayAt(tsMs);
|
|
334
|
+
if (day === null)
|
|
335
|
+
return null;
|
|
336
|
+
let openMs = day.regularOpenMs;
|
|
337
|
+
if (!day.isTradeDate || Math.trunc(tsMs) >= openMs) {
|
|
338
|
+
let next = day.dayNumber + 1;
|
|
339
|
+
while (!isTradeDateNumber(next))
|
|
340
|
+
next += 1;
|
|
341
|
+
if (next * DAY_MS > notAfterMs)
|
|
342
|
+
return null;
|
|
343
|
+
openMs = nyCalendarDay(next)?.regularOpenMs ?? null;
|
|
344
|
+
}
|
|
345
|
+
return openMs !== null && openMs <= notAfterMs ? openMs : null;
|
|
346
|
+
}
|
|
@@ -47,12 +47,19 @@ export interface ParsedPanelClear {
|
|
|
47
47
|
}
|
|
48
48
|
export type ParsedPanelFrame = ParsedPanel | ParsedPanelClear;
|
|
49
49
|
export type PanelRejectReason = 'payload is not an object' | 'unknown payload key' | 'invalid chartIndex' | 'invalid payloadId' | 'payloadId does not match chartIndex' | 'invalid revision stamp' | 'invalid clear flag (only true is wire-legal)' | 'clear payload carries baggage' | 'invalid panel' | 'unknown panel key' | 'payloadId does not match panel.id' | `invalid panel.${'id' | 'title' | 'kind' | 'x' | 'place' | 'orientation' | 'series' | 'stacked' | 'labels' | 'bins' | 'hole'}` | `invalid panel.${PanelStyleWord}` | `invalid panel.series.${PanelSeriesStyleWord}` | 'unknown panel.series key' | 'heatmap panels use x: category' | 'histogram panels use x: category' | 'rows is not an array' | 'too many rows' | 'invalid panel row' | 'invalid source' | 'unknown source key' | `invalid source.${'kind' | 'ref' | 'computedAtMs'}`;
|
|
50
|
+
/** The row an `invalid panel row` refusal broke the grammar at: its index in `rows` and why, for diagnostics (a
|
|
51
|
+
* ring event, a log line), never for the viewer's copy. */
|
|
52
|
+
export interface PanelRowRefusal {
|
|
53
|
+
index: number;
|
|
54
|
+
reason: string;
|
|
55
|
+
}
|
|
50
56
|
export type SetPanelParseResult = {
|
|
51
57
|
ok: true;
|
|
52
58
|
data: ParsedPanelFrame;
|
|
53
59
|
} | {
|
|
54
60
|
ok: false;
|
|
55
61
|
rejectReason: PanelRejectReason;
|
|
62
|
+
row?: PanelRowRefusal;
|
|
56
63
|
};
|
|
57
64
|
export declare function isPanelClearFrame(frame: ParsedPanelFrame): frame is ParsedPanelClear;
|
|
58
65
|
/** Reject an entire frame before it can advance any session revision floor.
|
|
@@ -60,7 +67,11 @@ export declare function isPanelClearFrame(frame: ParsedPanelFrame): frame is Par
|
|
|
60
67
|
* frame's style words are checked here (value, kind, `#rrggbb[aa]` colours)
|
|
61
68
|
* and a bad one is refused by name (`invalid panel.<word>`); a wrun
|
|
62
69
|
* declaration's were checked by the kit, except the app's own bar words. A
|
|
63
|
-
* word outside the list is refused on both lanes.
|
|
70
|
+
* word outside the list is refused on both lanes. A row that breaks the row
|
|
71
|
+
* grammar refuses the frame, never a truncation (the frozen wrun-4 rule, alike
|
|
72
|
+
* on every host), and the refusal names the row's index and why (`row`); a
|
|
73
|
+
* missing reading in a cell that only shows a number is that cell's gap,
|
|
74
|
+
* never a break (`missingReading`). */
|
|
64
75
|
export declare function parseSetPanelData(value: unknown, options?: ParseSetPanelOptions): SetPanelParseResult;
|
|
65
76
|
/** The meta-level hooks a translated panel asks the engine to call (SC08):
|
|
66
77
|
* `formatDomainValue` prints every number the pane shows by role,
|
|
@@ -104,7 +115,8 @@ export interface PanelTableCellContext {
|
|
|
104
115
|
* A number, or a styled cell's `value`, prints through the column's format,
|
|
105
116
|
* else the table's (SC40); no format keeps the raw print. A styled cell's
|
|
106
117
|
* own background, text look, alignment and spans map onto the T2 table keys
|
|
107
|
-
* (SC14 SC22 SC35); a cell without an alignment takes its column's.
|
|
118
|
+
* (SC14 SC22 SC35); a cell without an alignment takes its column's. A missing
|
|
119
|
+
* reading (`null`) is an empty cell. */
|
|
108
120
|
export declare function engineTableCell(cell: ParsedPanel['rows'][number][number], column?: PanelTableColumn, ctx?: PanelTableCellContext): unknown;
|
|
109
121
|
/** Labels for a time-keyed curve or bars panel, as short as the key set
|
|
110
122
|
* allows: clock times inside one day, dates for day-aligned keys, a year
|