"use client"
import React, { useState, useEffect } from 'react'
export default function AutoTradingPanel() {
const [status, {/* Trading Metrics (Real Data) */}
`etStatus] = useState<'idle'|'running'|'stopped'>('idle')
const [message, setMessage] = useState
('')
const [currentTime, setCurrentTime] = useState('')
// Set current time only on client to avoid hydration mismatch
useEffect(() => {
const updateTime = () => {
setCurrentTime(new Date().toLocaleTimeString())
}
updateTime() // Set initial time
const interval = setInterval(updateTime, 1000) // Update every second
return () => clearInterval(interval)
}, [])
async function handleAction(action: 'start'|'stop') {
setMessage('')
setStatus('idle')
const res = await fetch('/api/auto-trading', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ action })
})
if (res.ok) {
setStatus(action === 'start' ? 'running' : 'stopped')
setMessage(`Auto-trading ${action}ed`)
} else {
setMessage('Error: ' + (await res.text()))
}
}
const getStatusColor = () => {
switch (status) {
case 'running': return 'text-green-400'
case 'stopped': return 'text-red-400'
default: return 'text-gray-400'
}
}
const getStatusIcon = () => {
switch (status) {
case 'running': return '🟢'
case 'stopped': return '🔴'
default: return '⚫'
}
}
return (
⚡
Auto-Trading Control
{getStatusIcon()}
{status}
{/* Status Display */}
Trading Status
{status === 'running' ? 'ACTIVE' : status === 'stopped' ? 'STOPPED' : 'IDLE'}
Last Updated
{currentTime || '--:--:--'}
{message && (
{message}
)}
{/* Action Buttons */}
{/* Trading Metrics (Mock Data) */}
)
}