"use client" import React, { useEffect, useState } from 'react' interface Trade { id: string symbol: string side: string amount: number price: number status: string executedAt: string pnl?: number } export default function TradingHistory() { const [trades, setTrades] = useState([]) const [loading, setLoading] = useState(true) useEffect(() => { async function fetchTrades() { try { const res = await fetch('/api/trading-history') if (res.ok) { const data = await res.json() setTrades(data) } else { // Mock data for demonstration setTrades([ { id: '1', symbol: 'BTCUSD', side: 'BUY', amount: 0.1, price: 45230.50, status: 'FILLED', executedAt: new Date().toISOString(), pnl: 125.50 }, { id: '2', symbol: 'ETHUSD', side: 'SELL', amount: 2.5, price: 2856.75, status: 'FILLED', executedAt: new Date(Date.now() - 3600000).toISOString(), pnl: -67.25 }, { id: '3', symbol: 'SOLUSD', side: 'BUY', amount: 10, price: 95.80, status: 'FILLED', executedAt: new Date(Date.now() - 7200000).toISOString(), pnl: 89.75 } ]) } } catch (error) { console.error('Failed to fetch trades:', error) setTrades([]) } setLoading(false) } fetchTrades() }, []) const getSideColor = (side: string) => { return side.toLowerCase() === 'buy' ? 'text-green-400' : 'text-red-400' } const getStatusColor = (status: string) => { switch (status.toLowerCase()) { case 'filled': return 'text-green-400' case 'pending': return 'text-yellow-400' case 'cancelled': return 'text-red-400' default: return 'text-gray-400' } } const getPnLColor = (pnl?: number) => { if (!pnl) return 'text-gray-400' return pnl >= 0 ? 'text-green-400' : 'text-red-400' } return (

📊 Trading History

Latest {trades.length} trades
{loading ? (
Loading trades...
) : trades.length === 0 ? (
📈

No trading history

Your completed trades will appear here

) : (
{trades.map((trade, index) => ( ))}
Asset Side Amount Price Status P&L Time
{trade.symbol.slice(0, 2)}
{trade.symbol}
{trade.side} {trade.amount} ${trade.price.toLocaleString()} {trade.status} {trade.pnl ? `${trade.pnl >= 0 ? '+' : ''}$${trade.pnl.toFixed(2)}` : '--'} {new Date(trade.executedAt).toLocaleTimeString()}
)}
) }