const BASE = 'https://allocait.app/api/v1'
const headers = { 'x-api-key': process.env.ALLOCAIT_API_KEY, 'Content-Type': 'application/json' }
const prices = { ALFA: 181.5, BRAV: 94.2, GOLF: 62.3 } // from your own source: every held and every changed symbol
const trades = [{ symbol: 'ALFA', side: 'BUY', shares: 40 }]
const res = await fetch(`${BASE}/trades/check`, { method: 'POST', headers,
body: JSON.stringify({ portfolio_id: process.env.ALLOCAIT_PORTFOLIO_ID, trades, prices }) })
const result = await res.json()
if (!res.ok) throw new Error(result.missing_symbols ? `Add prices for: ${result.missing_symbols.join(', ')}` : `No result: ${result.error_code ?? res.status}`) // a failed call is no result
console.log('rules this change adds or deepens:', result.newly_or_further_outside_count)
for (const r of result.rules) {
console.log(r.change, r.kind, r.asset_class, r.symbol ?? '(class)', `${r.before_pct} -> ${r.after_pct}`)
}
console.log('whole book inside every rule afterward:', result.within_rules)
console.log('positions last updated:', result.positions_updated_at)