'use client' import React, { useState, useEffect } from 'react' export default function AutomationPage() { const [config, setConfig] = useState({ mode: 'SIMULATION', dexProvider: 'DRIFT', symbol: 'SOLUSD', timeframe: '1h', tradingAmount: 100, maxLeverage: 5, stopLossPercent: 2, takeProfitPercent: 6, maxDailyTrades: 5, riskPercentage: 2 }) const [status, setStatus] = useState(null) const [isLoading, setIsLoading] = useState(false) useEffect(() => { fetchStatus() const interval = setInterval(fetchStatus, 30000) return () => clearInterval(interval) }, []) const fetchStatus = async () => { try { const response = await fetch('/api/automation/status') const data = await response.json() if (data.success) { setStatus(data.status) } } catch (error) { console.error('Failed to fetch status:', error) } } const handleStart = async () => { setIsLoading(true) try { const response = await fetch('/api/automation/start', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(config) }) const data = await response.json() if (data.success) { fetchStatus() } else { alert('Failed to start automation: ' + data.error) } } catch (error) { console.error('Failed to start automation:', error) alert('Failed to start automation') } finally { setIsLoading(false) } } const handleStop = async () => { setIsLoading(true) try { const response = await fetch('/api/automation/stop', { method: 'POST' }) const data = await response.json() if (data.success) { fetchStatus() } else { alert('Failed to stop automation: ' + data.error) } } catch (error) { console.error('Failed to stop automation:', error) alert('Failed to stop automation') } finally { setIsLoading(false) } } return (
Drift Protocol
Loading...
)}