'use client' import { useState, useEffect } from 'react' import { TradingChart } from './TradingChart' type TradingTab = 'research' | 'strategies' | 'execution' | 'journal' interface Trader { id: string name: string status: 'learning' | 'active' | 'paused' framesAnalyzed: number patterns: string[] entryRules: string[] exitRules: string[] indicators: string[] riskParams: string[] } interface Trade { id: string trader: string pair: string direction: 'long' | 'short' entryPrice: number exitPrice?: number status: 'open' | 'closed' | 'cancelled' pnl?: number pnlPercent?: number reason: string setup: string timeframe: string openedAt: string closedAt?: string notes: string isDemo: boolean } const defaultTraders: Trader[] = [ { id: 'dopetrades', name: 'DopeTrades', status: 'learning', framesAnalyzed: 922, patterns: ['Accumulation/Distribution', 'Trend Legs', 'Support/Resistance', 'Pop Pattern'], entryRules: ['Identify trend on higher timeframe', 'Find demand/supply zones', 'Wait for retest', '2.5:1 min risk:reward'], exitRules: ['Stop below demand (long)', 'Target recent highs', 'Scale 50% at 1:1'], indicators: ['Price Action Only', 'Horizontal S/R Lines'], riskParams: ['2.5:1 minimum', 'No revenge trading', 'Paper trading first'] }, { id: 'gareth_soloway', name: 'Gareth Soloway', status: 'learning', framesAnalyzed: 768, patterns: ['Institutional Analysis', 'Yield Curve Signals', 'Cycle Top/Bottom', 'Epic Resistance Rejections'], entryRules: ['Track institutional activity', 'Wait for yield curve signals', 'Key level breaks with volume', 'Weekly analysis first'], exitRules: ['Stop below support (long)', 'Target structure highs/lows', '2:1 minimum'], indicators: ['VWAP', 'MACD', 'Volume', '10-Year Yield', 'Support/Resistance'], riskParams: ['No-hype sizing', 'Never average down', 'Respect stops', 'Preservation > profits'] } ] export function TradingPanel() { const [activeTab, setActiveTab] = useState('research') const [traders, setTraders] = useState(defaultTraders) const [selectedTrader, setSelectedTrader] = useState('dopetrades') const [trades, setTrades] = useState([]) const [journalFilter, setJournalFilter] = useState<'all' | 'demo' | 'real'>('all') // Load data useEffect(() => { loadTraders() loadTrades() }, []) const loadTraders = async () => { try { const res = await fetch('/api/trading/traders') if (res.ok) { const data = await res.json() if (data.traders?.length > 0) setTraders(data.traders) } } catch (e) {} } const loadTrades = async () => { try { const res = await fetch('/api/trading/trades') if (res.ok) { const data = await res.json() if (data.trades) setTrades(data.trades) } } catch (e) {} } const tabs = [ { id: 'research', label: '🔬 Deep Research', count: traders.filter(t => t.status === 'learning').length }, { id: 'strategies', label: '🎯 Strategies', count: traders.filter(t => t.status === 'active').length }, { id: 'execution', label: '⚡ Execution', count: trades.filter(t => t.status === 'open').length }, { id: 'journal', label: '📔 Journal', count: trades.length }, ] const filteredTrades = trades.filter(t => { if (journalFilter === 'all') return true if (journalFilter === 'demo') return t.isDemo return !t.isDemo }) const openTrades = trades.filter(t => t.status === 'open') const closedDemoTrades = trades.filter(t => t.status === 'closed' && t.isDemo) const closedRealTrades = trades.filter(t => t.status === 'closed' && !t.isDemo) const totalPnl = closedRealTrades.reduce((sum, t) => sum + (t.pnl || 0), 0) const winRate = closedRealTrades.length > 0 ? Math.round((closedRealTrades.filter(t => (t.pnl || 0) > 0).length / closedRealTrades.length) * 100) : 0 return (
{/* Tab Navigation */}
{tabs.map(tab => ( ))}
{/* Research Tab */} {activeTab === 'research' && (

🔬 Deep Research

Learn trading strategies from experts by analyzing their content.

{traders.map(trader => (
👨‍🏫

{trader.name}

{trader.framesAnalyzed} frames analyzed

{trader.status}
{trader.patterns.length > 0 && (
{trader.patterns.map(p => ( {p} ))}
)}
))}
)} {/* Strategies Tab */} {activeTab === 'strategies' && (

🎯 Trading Strategies

Select a trader style to follow for your next trade.

{traders.filter(t => t.status === 'active').map(trader => ( ))}
{traders.find(t => t.id === selectedTrader) && (

{traders.find(t => t.id === selectedTrader)?.name} Strategy

Entry Rules

    {traders.find(t => t.id === selectedTrader)?.entryRules.map(r => (
  • {r}
  • ))}
{traders.find(t => t.id === selectedTrader)?.entryRules.length === 0 && (

No entry rules defined yet

)}

Exit Rules

    {traders.find(t => t.id === selectedTrader)?.exitRules.map(r => (
  • {r}
  • ))}

Indicators

{traders.find(t => t.id === selectedTrader)?.indicators.map(i => ( {i} ))}

Risk Parameters

    {traders.find(t => t.id === selectedTrader)?.riskParams.map(r => (
  • {r}
  • ))}
)}
)} {/* Execution Tab */} {activeTab === 'execution' && ( )} {/* Journal Tab */} {activeTab === 'journal' && (

📔 Trading Journal

{/* Stats */}

${totalPnl.toFixed(2)}

Real P&L

{winRate}%

Win Rate

{closedRealTrades.length}

Real Trades

{/* Filter */}
{(['all', 'demo', 'real'] as const).map(filter => ( ))}
{/* Trades List */}
{filteredTrades.length === 0 ? (

No trades yet

) : ( filteredTrades.map(trade => (
0 ? 'bg-green-500/10 border-green-500/30' : 'bg-red-500/10 border-red-500/30' }`} >
{trade.pair} {trade.direction.toUpperCase()} {trade.isDemo && (Demo)}
{trade.status === 'closed' && ( = 0 ? 'text-green-400' : 'text-red-400'}`}> {trade.pnl >= 0 ? '+' : ''}{trade.pnl?.toFixed(2)} ({trade.pnlPercent?.toFixed(1)}%) )}

{trade.setup}

{trade.timeframe} {new Date(trade.openedAt).toLocaleDateString()}
)) )}
)}
) }