'use client' import React, { useState, useEffect } from 'react' import TradingChart from '../../components/TradingChart' import CompactTradingPanel from '../../components/CompactTradingPanel' import PositionsPanel from '../../components/PositionsPanel' export default function ChartTradingPage() { const [currentPrice, setCurrentPrice] = useState(166.21) const [positions, setPositions] = useState([]) const [selectedSymbol, setSelectedSymbol] = useState('SOL') useEffect(() => { fetchPositions() const interval = setInterval(fetchPositions, 10000) // Update every 10 seconds return () => clearInterval(interval) }, []) const fetchPositions = async () => { try { const response = await fetch('/api/trading/positions') const data = await response.json() if (data.success) { setPositions(data.positions || []) } } catch (error) { console.error('Failed to fetch positions:', error) } } const handleTrade = async (tradeData: any) => { try { console.log('Executing trade:', tradeData) // For perpetual trades, use the execute-perp endpoint const response = await fetch('/api/trading/execute-perp', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(tradeData) }) const result = await response.json() if (result.success) { alert(`Trade executed successfully! ${result.message}`) fetchPositions() // Refresh positions } else { alert(`Trade failed: ${result.error || result.message}`) } } catch (error) { console.error('Trade execution error:', error) alert('Trade execution failed. Please try again.') } } const handlePriceUpdate = (price: number) => { setCurrentPrice(price) } return (
{/* Top Bar */}

Trading Terminal

{/* Symbol Selector */}
{['SOL', 'BTC', 'ETH'].map(symbol => ( ))}
{/* Market Status */}
Market Open
Server Time: {new Date().toLocaleTimeString()}
{/* Main Trading Interface */}
{/* Chart Area (70% width) */}
{/* Trading Panel (30% width) */}
{/* Bottom Panel - Positions */}
{positions.length > 0 && (
Total P&L: +$0.00
)}
{/* Positions Table */}
{positions.length === 0 ? (
No open positions
) : (
{positions.map((position: any) => (
{position.symbol} • {position.side}
Size: {position.amount} • Entry: ${position.entryPrice?.toFixed(2)}
${position.totalValue?.toFixed(2) || '0.00'}
= 0 ? 'text-green-400' : 'text-red-400' }`}> {(position.unrealizedPnl || 0) >= 0 ? '+' : ''}${(position.unrealizedPnl || 0).toFixed(2)}
))}
)}
) }