Intelligence, Advanced Charting & Trading Platform
feature/chartnova-light-catalog-lazy-series-2026-10-15
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 | /** |
| 2 | * Project a provider-verified cached market catalog to a lightweight read-only |
| 3 | * snapshot. It never synthesizes prices, converts units or fabricates OHLC. |
| 4 | * |
| 5 | * Self-contained by design: this function is embedded unchanged into the |
| 6 | * Cloudflare Worker by the source-gated deployment patcher. |
| 7 | */ |
| 8 | export function marketCatalogSummary(catalog, nowMs = Date.now()) { |
| 9 | const unavailable = {ok:false,error:'market_data_not_collected'}; |
| 10 | if (!catalog || catalog.ok!==true || catalog.source!=='gheymat.online' || |
| 11 | !Array.isArray(catalog.markets) || catalog.markets.length<1 || |
| 12 | catalog.markets.length>200 || !Number.isFinite(nowMs)) return unavailable; |
| 13 | const ms=Date.parse(catalog.fetchedAt); |
| 14 | if (!Number.isFinite(ms) || ms>nowMs+300000) return unavailable; |
| 15 | const seen=new Set(), rows=[]; |
| 16 | for(const m of catalog.markets) { |
| 17 | if(!m || typeof m.symbol!=='string' || |
| 18 | !/^[A-Z0-9]{1,20}-[A-Z0-9]{2,10}$/.test(m.symbol) || |
| 19 | seen.has(m.symbol) || typeof m.name!=='string' || |
| 20 | !m.name.trim() || m.name.length>160 || |
| 21 | typeof m.base!=='string' || m.base!==m.symbol.split('-')[0] || |
| 22 | typeof m.quote!=='string' || m.quote!==m.symbol.split('-')[1] || |
| 23 | typeof m.category!=='string' || !/^[A-Z_]{3,30}$/.test(m.category) || |
| 24 | !Number.isFinite(m.sellPrice) || m.sellPrice<=0 || |
| 25 | !(m.buyPrice===null || m.buyPrice===undefined || (Number.isFinite(m.buyPrice)&&m.buyPrice>0)) || |
| 26 | !(m.change===null || m.change===undefined || Number.isFinite(m.change)) || |
| 27 | typeof m.updatedAt!=='string' || !Number.isFinite(Date.parse(m.updatedAt)) || |
| 28 | Date.parse(m.updatedAt)>nowMs+300000 || |
| 29 | typeof m.isUpToDate!=='boolean' || !Array.isArray(m.history) || |
| 30 | m.history.length>168 || !m.history.every(v=>Number.isFinite(v)&&v>0))return unavailable; |
| 31 | seen.add(m.symbol); |
| 32 | // Explicit allowlist: do not leak 168-point arrays to the initial screen. |
| 33 | rows.push({ |
| 34 | symbol:m.symbol,name:m.name,base:m.base,quote:m.quote,category:m.category, |
| 35 | sellPrice:m.sellPrice,buyPrice:m.buyPrice??null,change:m.change??null, |
| 36 | updatedAt:m.updatedAt,isUpToDate:m.isUpToDate, |
| 37 | historyCount:m.history.length, |
| 38 | historyKind:'provider_price_points_not_ohlc' |
| 39 | }); |
| 40 | } |
| 41 | return { |
| 42 | ok:true,source:catalog.source,fetchedAt:catalog.fetchedAt, |
| 43 | stale:nowMs-ms>45*60000, |
| 44 | quoteSide:'sell', |
| 45 | dataKind:'provider_market_snapshots_not_executable_quotes', |
| 46 | markets:rows |
| 47 | }; |
| 48 | } |