import { useState, useEffect } from 'react'; import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card'; import { Badge } from '@/components/ui/badge'; import { trailingStopManager, TrailingStop } from '@/core/trailingStopManager'; import { ShieldCheck, TrendingDown, TrendingUp } from 'lucide-react'; import { cn } from '@/lib/utils'; export const TrailingStopPanel = () => { const [stops, setStops] = useState([]); const [stats, setStats] = useState({ totalStops: 0, activeStops: 0, triggeredCount: 0, avgUnrealizedPnl: 0 }); useEffect(() => { const interval = setInterval(() => { setStops(trailingStopManager.getAllStops()); setStats(trailingStopManager.getStats()); }, 2000); return () => clearInterval(interval); }, []); return ( Trailing Stop Manager
Total
{stats.totalStops}
Active
{stats.activeStops}
Triggered
{stats.triggeredCount}
Avg P&L
= 0 ? "text-success" : "text-destructive")}> {stats.avgUnrealizedPnl.toFixed(2)}%
{stops.length === 0 ? (
No active trailing stops
) : ( stops.slice(0, 5).map((stop, i) => (
{stop.symbol} Stop: ${stop.trailPrice.toFixed(2)}
{stop.unrealizedPnlPct >= 0 ? ( ) : ( )} = 0 ? "text-success" : "text-destructive")}> {stop.unrealizedPnlPct.toFixed(2)}%
)) )}
); };