Intelligence, Advanced Charting & Trading Platform
risk/chartnova-seven-track-safety-2026-10-21
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 | * Non-billable, quota-aware polling planner. Returns advisory scheduling |
| 3 | * constraints only: it never changes Worker Cron or calls a vendor API. |
| 4 | */ |
| 5 | export const VERIFIED_DATED_FREE_BUDGETS=Object.freeze({ |
| 6 | NAVASAN:{calls:120,period:'MONTH',source:'https://www.navasan.tech/en/api',checked:'2026-10-15'}, |
| 7 | GHEYMAT_ONLINE:{calls:250,period:'DAY',source:'https://gheymat.online/price-api',checked:'2026-10-15'} |
| 8 | }); |
| 9 | export function quotaBudget({calls,windowMinutes,callsPerPoll=1,reserveFraction=0.25}){ |
| 10 | for(const x of [calls,windowMinutes,callsPerPoll]){ |
| 11 | if(!Number.isSafeInteger(x)||x<=0)throw new RangeError('positive integers required'); |
| 12 | } |
| 13 | if(!Number.isFinite(reserveFraction)||reserveFraction<0||reserveFraction>=1) |
| 14 | throw new RangeError('reserveFraction must be 0..1 exclusive'); |
| 15 | const usable=Math.floor(calls*(1-reserveFraction)); |
| 16 | const allowed=Math.floor(usable/callsPerPoll); |
| 17 | if(allowed<1)throw new RangeError('No quota available after reserve'); |
| 18 | const mathematicallyMinimalMinutes=windowMinutes*callsPerPoll/calls; |
| 19 | const reservedMinimumMinutes=windowMinutes/allowed; |
| 20 | const suggestedMinutes=Math.ceil(reservedMinimumMinutes); |
| 21 | const scheduledCycles=Math.ceil(windowMinutes/suggestedMinutes); |
| 22 | const spend=scheduledCycles*callsPerPoll; |
| 23 | if(spend>usable)throw new Error('Planner exceeded reserved budget'); |
| 24 | return {quotaLimit:calls,availableCalls:usable,callsPerPoll,windowMinutes, |
| 25 | mathematicallyMinimalMinutes,reservedMinimumMinutes,suggestedMinutes, |
| 26 | plannedCalls:spend,remainingCalls:calls-spend, |
| 27 | guaranteedLatencyMs:null,latencyVerified:false,advisoryOnly:true}; |
| 28 | } |
| 29 | export function officialFreePlanBudget(provider,{daysInMonth=30,callsPerPoll=1,reserveFraction=.25}={}){ |
| 30 | const plan=VERIFIED_DATED_FREE_BUDGETS[provider]; |
| 31 | if(!plan)throw new RangeError('unknown provider'); |
| 32 | if(plan.period==='MONTH'&&![28,29,30,31].includes(daysInMonth)) |
| 33 | throw new RangeError('daysInMonth'); |
| 34 | return quotaBudget({calls:plan.calls,windowMinutes: |
| 35 | plan.period==='DAY'?1440:daysInMonth*1440,callsPerPoll,reserveFraction}); |
| 36 | } |