/** * Positions Component * Handles position display and updates */ export class PositionsComponent { constructor(containerId) { this.container = document.getElementById(containerId); this.positions = []; } async load() { try { const response = await fetch('/api/strategy/positions'); const data = await response.json(); this.positions = data.positions || []; this.render(); } catch (error) { console.error('[Positions] Error loading positions:', error); this.showError('Failed to load positions'); } } render() { if (!this.container) return; if (this.positions.length === 0) { this.container.innerHTML = '
NO OPEN POSITIONS
'; return; } this.container.innerHTML = this.positions.map(pos => { const isProfit = pos.pnl >= 0; return `
${pos.outcome}
${isProfit ? '+' : ''}$${pos.pnl.toFixed(2)}
Size: ${pos.size.toFixed(2)}
Entry: ${(pos.entry_price * 100).toFixed(2)}%
Current: ${(pos.current_price * 100).toFixed(2)}%
P&L: ${pos.pnl_percent.toFixed(2)}%
`; }).join(''); } showError(message) { if (this.container) { this.container.innerHTML = `
${message}
`; } } }