'use client' import React, { useState, useEffect } from 'react' // Available timeframes for automation (matching analysis page format) const timeframes = [ { label: '5m', value: '5' }, { label: '15m', value: '15' }, { label: '30m', value: '30' }, { label: '1h', value: '60' }, { label: '2h', value: '120' }, { label: '4h', value: '240' }, { label: '1d', value: 'D' }, ] export default function AutomationPageV2() { const [config, setConfig] = useState({ mode: 'SIMULATION', dexProvider: 'DRIFT', symbol: 'SOLUSD', timeframe: '1h', // Primary timeframe for backwards compatibility selectedTimeframes: ['60'], // Multi-timeframe support tradingAmount: 100, maxLeverage: 20, // Maximum allowed leverage for AI calculations stopLossPercent: 2, takeProfitPercent: 6, riskPercentage: 2 }) const [status, setStatus] = useState(null) const [balance, setBalance] = useState(null) const [positions, setPositions] = useState([]) const [loading, setLoading] = useState(false) useEffect(() => { fetchStatus() fetchBalance() fetchPositions() const interval = setInterval(() => { fetchStatus() fetchBalance() fetchPositions() }, 30000) return () => clearInterval(interval) }, []) const toggleTimeframe = (timeframe) => { setConfig(prev => ({ ...prev, selectedTimeframes: prev.selectedTimeframes.includes(timeframe) ? prev.selectedTimeframes.filter(tf => tf !== timeframe) : [...prev.selectedTimeframes, timeframe] })) } 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 fetchBalance = async () => { try { const response = await fetch('/api/drift/balance') const data = await response.json() if (data.success) { setBalance(data) } } catch (error) { console.error('Failed to fetch balance:', error) } } const fetchPositions = async () => { try { const response = await fetch('/api/drift/positions') const data = await response.json() if (data.success) { setPositions(data.positions || []) } } catch (error) { console.error('Failed to fetch positions:', error) } } const handleStart = async () => { setLoading(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 { setLoading(false) } } const handleStop = async () => { setLoading(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 { setLoading(false) } } return (
Drift Protocol - Multi-Timeframe Analysis
Leverage is now calculated automatically by AI based on account balance, market conditions, and risk assessment. The system optimizes between 1x-20x for maximum profit while maintaining liquidation safety.
Available: ${parseFloat(balance.availableBalance).toFixed(2)} • Using {((config.tradingAmount / balance.availableBalance) * 100).toFixed(1)}% of balance
)}💡 AI will apply optimal leverage automatically based on market conditions
Quick calculation based on ${parseFloat(balance.availableBalance).toFixed(2)} balance
)}Loading bot status...
)}