Intelligence, Advanced Charting & Trading Platform
phase-1/gold-api-fallback
diagnostics/chartnova-blank-screen-2026-10-15
diagnostics/chartnova-stage2-v27-preview-2026-10-15
docs/chartnova-stage1-reconcile-manifest-2026-10-15
feature/chartnova-ios-widget
feature/chartnova-light-catalog-lazy-series-2026-10-15
feature/chartnova-market-terminal
feature/chartnova-multimarket-chart-ws-foundation
feature/chartnova-neon-direct-history
feature/chartnova-neon-history
feature/paper-trading-risk-controls-2026-10-14
fix/alpha-vantage-live-payload
fix/chartnova-progressive-loading-2026-10-15
fix/live-proof-runner-cwd-2026-10-14
foundation/phase-0
foundation/postgres-core
main
ops/chartnova-emergency-rollback-2026-10-15
phase-1/candle-builder
phase-1/data-proof-artifact
phase-1/data-proof-metrics
phase-1/data-proof-report
phase-1/external-gates-state
phase-1/gold-api-fallback
phase-1/ingestion-pipeline
phase-1/live-proof-runner
phase-1/market-calendar
phase-1/market-domain
phase-1/neon-live-proof
phase-1/persistence-contract
phase-1/postgres-ci
phase-1/provider-adapters
phase-1/provider-recovery
phase-1/quality-propagation
phase-1/spike-detection
phase-1/xau-provider-adapter
risk/chartnova-alert-runtime-atomic-2026-10-22
risk/chartnova-atomic-outbox-2026-10-22
risk/chartnova-seven-track-safety-2026-10-21
safety/p0-triage-2026-10-13
| 1 | const WEEKDAY = Object.freeze({ Sun: 0, Mon: 1, Tue: 2, Wed: 3, Thu: 4, Fri: 5, Sat: 6 }); |
| 2 | |
| 3 | function partsAt(date, timeZone) { |
| 4 | if (!(date instanceof Date) || Number.isNaN(date.valueOf())) throw new TypeError('date must be valid'); |
| 5 | const fmt = new Intl.DateTimeFormat('en-US', { |
| 6 | timeZone, |
| 7 | weekday: 'short', |
| 8 | year: 'numeric', |
| 9 | month: '2-digit', |
| 10 | day: '2-digit', |
| 11 | hour: '2-digit', |
| 12 | minute: '2-digit', |
| 13 | hourCycle: 'h23', |
| 14 | }); |
| 15 | const parts = Object.fromEntries(fmt.formatToParts(date).map(p => [p.type, p.value])); |
| 16 | return { |
| 17 | weekday: WEEKDAY[parts.weekday], |
| 18 | dateKey: `${parts.year}-${parts.month}-${parts.day}`, |
| 19 | minutes: Number(parts.hour) * 60 + Number(parts.minute), |
| 20 | }; |
| 21 | } |
| 22 | |
| 23 | function hhmmToMinutes(value) { |
| 24 | if (!/^\d{2}:\d{2}$/.test(value)) throw new RangeError(`invalid session time: ${value}`); |
| 25 | const [h, m] = value.split(':').map(Number); |
| 26 | if (h > 23 || m > 59) throw new RangeError(`invalid session time: ${value}`); |
| 27 | return h * 60 + m; |
| 28 | } |
| 29 | |
| 30 | export function marketExpectedOpen(date, calendar) { |
| 31 | if (!calendar || typeof calendar !== 'object') throw new TypeError('calendar is required'); |
| 32 | if (calendar.mode === '24x7') return true; |
| 33 | if (calendar.mode !== 'weekly') throw new RangeError(`unsupported calendar mode: ${calendar.mode}`); |
| 34 | if (!calendar.timezone) throw new TypeError('calendar.timezone is required'); |
| 35 | |
| 36 | const local = partsAt(date, calendar.timezone); |
| 37 | if (calendar.holidays?.includes(local.dateKey)) return false; |
| 38 | |
| 39 | const sessions = calendar.sessions?.[local.weekday] ?? []; |
| 40 | return sessions.some(([start, end]) => { |
| 41 | const startMin = hhmmToMinutes(start); |
| 42 | const endMin = hhmmToMinutes(end); |
| 43 | return local.minutes >= startMin && local.minutes < endMin; |
| 44 | }); |
| 45 | } |
| 46 | |
| 47 | export function classifyGap({ from, to, calendar, probeMinutes = 5 }) { |
| 48 | if (!(from instanceof Date) || Number.isNaN(from.valueOf())) throw new TypeError('from must be valid'); |
| 49 | if (!(to instanceof Date) || Number.isNaN(to.valueOf())) throw new TypeError('to must be valid'); |
| 50 | if (to <= from) throw new RangeError('to must be after from'); |
| 51 | if (!Number.isFinite(probeMinutes) || probeMinutes <= 0) throw new RangeError('probeMinutes must be positive'); |
| 52 | |
| 53 | const stepMs = probeMinutes * 60_000; |
| 54 | for (let t = from.valueOf(); t <= to.valueOf(); t += stepMs) { |
| 55 | if (marketExpectedOpen(new Date(t), calendar)) return 'MISSING_DATA'; |
| 56 | } |
| 57 | return 'EXPECTED_CLOSED'; |
| 58 | } |