Intelligence, Advanced Charting & Trading Platform
feature/paper-trading-risk-controls-2026-10-14
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 | * Future-paper-feed boundary only: does NOT contact a provider or execute orders. |
| 3 | * An operator must separately verify authenticity, entitlement, signature, and transport. |
| 4 | */ |
| 5 | const timestamp=(s,name)=>{ |
| 6 | if(typeof s!=='string'||!/^\d{4}-\d\d-\d\dT\d\d:\d\d:\d\d(?:\.\d+)?(?:Z|[+-]\d\d:\d\d)$/.test(s)|| |
| 7 | !Number.isFinite(Date.parse(s)))throw new TypeError(name+' needs ISO timezone'); |
| 8 | return Date.parse(s); |
| 9 | }; |
| 10 | const goodPrice=(value,name)=>{ |
| 11 | const n=Number(value); |
| 12 | if(!Number.isFinite(n)||n<=0)throw new TypeError(name+' must be positive and finite'); |
| 13 | return n; |
| 14 | }; |
| 15 | export function validatePaperQuote(quote,{ |
| 16 | symbol, side, now, maxAgeMs=15000, lastSequence=0, |
| 17 | approvedSources=[] |
| 18 | }={}){ |
| 19 | if(!quote||typeof quote!=='object'||Array.isArray(quote)) |
| 20 | throw new TypeError('invalid quote'); |
| 21 | if(!/^[A-Z0-9_]{3,48}$/.test(symbol??'')||quote.symbol!==symbol) |
| 22 | throw new TypeError('symbol mismatch'); |
| 23 | if(side!=='LONG'&&side!=='SHORT')throw new TypeError('unsupported side'); |
| 24 | if(!Array.isArray(approvedSources)||!approvedSources.includes(quote.source)|| |
| 25 | !/^[a-z][a-z0-9_]{2,48}$/.test(quote.source??'')) |
| 26 | throw new TypeError('source not approved for paper quotes'); |
| 27 | if(quote.usage!=='PAPER_ONLY_BID_ASK'||quote.entitlement!=='reviewed_simulation_display'|| |
| 28 | quote.dataKind!=='bid_ask_quote') |
| 29 | throw new TypeError('quote type/usage not authorized'); |
| 30 | if(quote.quality!=='GOOD'||quote.isMarketOpen!==true) |
| 31 | throw new TypeError('quote not healthy or market not open'); |
| 32 | if(typeof quote.unit!=='string'||!/^[A-Z0-9_]{3,40}$/.test(quote.unit)) |
| 33 | throw new TypeError('missing canonical quote unit'); |
| 34 | if(!Number.isSafeInteger(quote.sequence)||quote.sequence<=lastSequence) |
| 35 | throw new RangeError('replayed or invalid quote sequence'); |
| 36 | if(!Number.isInteger(maxAgeMs)||maxAgeMs<1000||maxAgeMs>60000) |
| 37 | throw new RangeError('unsupported freshness tolerance'); |
| 38 | const receivedAt=timestamp(quote.receivedAt,'receivedAt'); |
| 39 | const sourceAt=timestamp(quote.sourceTimestamp,'sourceTimestamp'); |
| 40 | const currentAt=timestamp(now,'now'); |
| 41 | if(sourceAt>receivedAt+1000||receivedAt>currentAt+1000|| |
| 42 | sourceAt>currentAt+1000||currentAt-receivedAt>maxAgeMs|| |
| 43 | currentAt-sourceAt>maxAgeMs) |
| 44 | throw new RangeError('stale or future quote'); |
| 45 | const bid=goodPrice(quote.bid,'bid'),ask=goodPrice(quote.ask,'ask'); |
| 46 | if(bid>ask)throw new RangeError('crossed bid/ask quote'); |
| 47 | if((ask-bid)/ask>0.05)throw new RangeError('spread greater than 5% safety cap'); |
| 48 | return Object.freeze({ |
| 49 | symbol,source:quote.source,unit:quote.unit,sequence:quote.sequence, |
| 50 | // LONG exits against bid, SHORT exits against ask; NOT a guaranteed fill. |
| 51 | hypotheticalExitMark:side==='LONG'?bid:ask, |
| 52 | bid,ask,sourceTimestamp:new Date(sourceAt).toISOString(), |
| 53 | receivedAt:new Date(receivedAt).toISOString(),kind:'PAPER_QUOTE_ELIGIBLE' |
| 54 | }); |
| 55 | } |