Intelligence, Advanced Charting & Trading Platform
phase-1/market-domain
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 | export const TROY_OUNCE_GRAMS = 31.1034768; |
| 2 | export const GOLD_18K_PURITY = 0.75; |
| 3 | |
| 4 | function positiveFinite(value, name) { |
| 5 | if (!Number.isFinite(value) || value <= 0) throw new RangeError(`${name} must be positive and finite`); |
| 6 | } |
| 7 | |
| 8 | export function theoreticalGold18Irt({ xauUsdPerTroyOunce, usdIrt }) { |
| 9 | positiveFinite(xauUsdPerTroyOunce, 'xauUsdPerTroyOunce'); |
| 10 | positiveFinite(usdIrt, 'usdIrt'); |
| 11 | return (xauUsdPerTroyOunce / TROY_OUNCE_GRAMS) * GOLD_18K_PURITY * usdIrt; |
| 12 | } |
| 13 | |
| 14 | export function goldPremium({ marketIrtPerGram, theoreticalIrtPerGram }) { |
| 15 | positiveFinite(marketIrtPerGram, 'marketIrtPerGram'); |
| 16 | positiveFinite(theoreticalIrtPerGram, 'theoreticalIrtPerGram'); |
| 17 | return { |
| 18 | absoluteIrt: marketIrtPerGram - theoreticalIrtPerGram, |
| 19 | percent: (marketIrtPerGram / theoreticalIrtPerGram - 1) * 100, |
| 20 | }; |
| 21 | } |
| 22 | |
| 23 | export function alignSources({ target, xau, usdIrt, maxAgeMs }) { |
| 24 | if (!(target instanceof Date) || Number.isNaN(target.valueOf())) throw new TypeError('target must be a valid Date'); |
| 25 | if (!Number.isFinite(maxAgeMs) || maxAgeMs < 0) throw new RangeError('maxAgeMs must be non-negative and finite'); |
| 26 | positiveFinite(xau.value, 'xau.value'); |
| 27 | positiveFinite(usdIrt.value, 'usdIrt.value'); |
| 28 | |
| 29 | const targetMs = target.valueOf(); |
| 30 | const xauMs = xau.timestamp?.valueOf(); |
| 31 | const usdMs = usdIrt.timestamp?.valueOf(); |
| 32 | if (!Number.isFinite(xauMs) || !Number.isFinite(usdMs)) throw new TypeError('source timestamps must be valid Dates'); |
| 33 | if (xauMs > targetMs || usdMs > targetMs) throw new RangeError('source timestamp cannot be after target'); |
| 34 | |
| 35 | const xauAgeMs = targetMs - xauMs; |
| 36 | const usdIrtAgeMs = targetMs - usdMs; |
| 37 | return { |
| 38 | targetTimestamp: target.toISOString(), |
| 39 | xau: { value: xau.value, timestamp: xau.timestamp.toISOString() }, |
| 40 | usdIrt: { value: usdIrt.value, timestamp: usdIrt.timestamp.toISOString() }, |
| 41 | xauAgeMs, |
| 42 | usdIrtAgeMs, |
| 43 | quality: xauAgeMs <= maxAgeMs && usdIrtAgeMs <= maxAgeMs ? 'GOOD' : 'STALE', |
| 44 | }; |
| 45 | } |