/* Chan web API client helpers */ window.ChanApi = { analyze: function(params) { const q = new URLSearchParams(params); return fetch('/api/analyze?' + q.toString()).then(r => r.json()); }, chartMetadata: function() { return fetch('/api/chart_metadata').then(r => r.json()); }, symbols: function() { return fetch('/api/symbols').then(r => r.json()); }, derivatives: function(params) { const q = new URLSearchParams(params || {}); return fetch('/api/derivatives?' + q.toString()).then(function(r) { return r.json().then(function(body) { if (!r.ok) throw new Error((body && body.error) || r.statusText); return body; }); }); }, sentimentLatest: function(params) { const q = new URLSearchParams(params || {}); return fetch('/api/sentiment/latest?' + q.toString()).then(function(r) { return r.json().then(function(body) { if (!r.ok) throw new Error((body && body.error) || r.statusText); return body; }); }); }, sentimentMetrics: function(params) { const q = new URLSearchParams(params || {}); return fetch('/api/sentiment/metrics?' + q.toString()).then(function(r) { return r.json().then(function(body) { if (!r.ok) throw new Error((body && body.error) || r.statusText); return body; }); }); }, macdConfig: function(body) { if (body === undefined) return fetch('/api/macd_config').then(r => r.json()); return fetch('/api/macd_config', { method: 'POST', headers: {'Content-Type': 'application/json'}, body: JSON.stringify(body) }).then(r => r.json()); } };