feat: implement complete automation system with real trading connection
This commit is contained in:
20
app/api/automation/learning-insights/route.js
Normal file
20
app/api/automation/learning-insights/route.js
Normal file
@@ -0,0 +1,20 @@
|
||||
import { NextResponse } from 'next/server'
|
||||
import { automationService } from '@/lib/automation-service-simple'
|
||||
|
||||
export async function GET() {
|
||||
try {
|
||||
const insights = await automationService.getLearningInsights('default-user')
|
||||
|
||||
return NextResponse.json({
|
||||
success: true,
|
||||
insights
|
||||
})
|
||||
} catch (error) {
|
||||
console.error('Get learning insights error:', error)
|
||||
return NextResponse.json({
|
||||
success: false,
|
||||
error: 'Internal server error',
|
||||
message: error.message
|
||||
}, { status: 500 })
|
||||
}
|
||||
}
|
||||
21
app/api/automation/pause/route.js
Normal file
21
app/api/automation/pause/route.js
Normal file
@@ -0,0 +1,21 @@
|
||||
import { NextResponse } from 'next/server'
|
||||
import { automationService } from '@/lib/automation-service-simple'
|
||||
|
||||
export async function POST() {
|
||||
try {
|
||||
const success = await automationService.pauseAutomation()
|
||||
|
||||
if (success) {
|
||||
return NextResponse.json({ success: true, message: 'Automation paused successfully' })
|
||||
} else {
|
||||
return NextResponse.json({ success: false, error: 'Failed to pause automation' }, { status: 500 })
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Pause automation error:', error)
|
||||
return NextResponse.json({
|
||||
success: false,
|
||||
error: 'Internal server error',
|
||||
message: error.message
|
||||
}, { status: 500 })
|
||||
}
|
||||
}
|
||||
31
app/api/automation/recent-trades/route.js
Normal file
31
app/api/automation/recent-trades/route.js
Normal file
@@ -0,0 +1,31 @@
|
||||
import { NextResponse } from 'next/server'
|
||||
import { PrismaClient } from '@prisma/client'
|
||||
|
||||
const prisma = new PrismaClient()
|
||||
|
||||
export async function GET() {
|
||||
try {
|
||||
const trades = await prisma.trade.findMany({
|
||||
where: {
|
||||
userId: 'default-user',
|
||||
isAutomated: true
|
||||
},
|
||||
orderBy: {
|
||||
createdAt: 'desc'
|
||||
},
|
||||
take: 10
|
||||
})
|
||||
|
||||
return NextResponse.json({
|
||||
success: true,
|
||||
trades
|
||||
})
|
||||
} catch (error) {
|
||||
console.error('Get recent trades error:', error)
|
||||
return NextResponse.json({
|
||||
success: false,
|
||||
error: 'Internal server error',
|
||||
message: error.message
|
||||
}, { status: 500 })
|
||||
}
|
||||
}
|
||||
21
app/api/automation/resume/route.js
Normal file
21
app/api/automation/resume/route.js
Normal file
@@ -0,0 +1,21 @@
|
||||
import { NextResponse } from 'next/server'
|
||||
import { automationService } from '@/lib/automation-service-simple'
|
||||
|
||||
export async function POST() {
|
||||
try {
|
||||
const success = await automationService.resumeAutomation()
|
||||
|
||||
if (success) {
|
||||
return NextResponse.json({ success: true, message: 'Automation resumed successfully' })
|
||||
} else {
|
||||
return NextResponse.json({ success: false, error: 'Failed to resume automation' }, { status: 500 })
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Resume automation error:', error)
|
||||
return NextResponse.json({
|
||||
success: false,
|
||||
error: 'Internal server error',
|
||||
message: error.message
|
||||
}, { status: 500 })
|
||||
}
|
||||
}
|
||||
29
app/api/automation/start/route.js
Normal file
29
app/api/automation/start/route.js
Normal file
@@ -0,0 +1,29 @@
|
||||
import { NextResponse } from 'next/server'
|
||||
import { automationService } from '@/lib/automation-service-simple'
|
||||
|
||||
export async function POST(request) {
|
||||
try {
|
||||
const config = await request.json()
|
||||
|
||||
// Add a default userId for now (in production, get from auth)
|
||||
const automationConfig = {
|
||||
userId: 'default-user',
|
||||
...config
|
||||
}
|
||||
|
||||
const success = await automationService.startAutomation(automationConfig)
|
||||
|
||||
if (success) {
|
||||
return NextResponse.json({ success: true, message: 'Automation started successfully' })
|
||||
} else {
|
||||
return NextResponse.json({ success: false, error: 'Failed to start automation' }, { status: 500 })
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Start automation error:', error)
|
||||
return NextResponse.json({
|
||||
success: false,
|
||||
error: 'Internal server error',
|
||||
message: error.message
|
||||
}, { status: 500 })
|
||||
}
|
||||
}
|
||||
20
app/api/automation/status/route.js
Normal file
20
app/api/automation/status/route.js
Normal file
@@ -0,0 +1,20 @@
|
||||
import { NextResponse } from 'next/server'
|
||||
import { automationService } from '@/lib/automation-service-simple'
|
||||
|
||||
export async function GET() {
|
||||
try {
|
||||
const status = await automationService.getStatus()
|
||||
|
||||
return NextResponse.json({
|
||||
success: true,
|
||||
status: status || null
|
||||
})
|
||||
} catch (error) {
|
||||
console.error('Get status error:', error)
|
||||
return NextResponse.json({
|
||||
success: false,
|
||||
error: 'Internal server error',
|
||||
message: error.message
|
||||
}, { status: 500 })
|
||||
}
|
||||
}
|
||||
21
app/api/automation/stop/route.js
Normal file
21
app/api/automation/stop/route.js
Normal file
@@ -0,0 +1,21 @@
|
||||
import { NextResponse } from 'next/server'
|
||||
import { automationService } from '@/lib/automation-service-simple'
|
||||
|
||||
export async function POST() {
|
||||
try {
|
||||
const success = await automationService.stopAutomation()
|
||||
|
||||
if (success) {
|
||||
return NextResponse.json({ success: true, message: 'Automation stopped successfully' })
|
||||
} else {
|
||||
return NextResponse.json({ success: false, error: 'Failed to stop automation' }, { status: 500 })
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Stop automation error:', error)
|
||||
return NextResponse.json({
|
||||
success: false,
|
||||
error: 'Internal server error',
|
||||
message: error.message
|
||||
}, { status: 500 })
|
||||
}
|
||||
}
|
||||
64
app/api/automation/test/route.ts
Normal file
64
app/api/automation/test/route.ts
Normal file
@@ -0,0 +1,64 @@
|
||||
import { NextRequest, NextResponse } from 'next/server'
|
||||
import { automationService } from '../../../../lib/automation-service-simple'
|
||||
|
||||
export async function GET(request: NextRequest) {
|
||||
try {
|
||||
console.log('🧪 Testing Automation Service Connection...')
|
||||
|
||||
// Test configuration
|
||||
const testConfig = {
|
||||
userId: 'test-user-123',
|
||||
mode: 'SIMULATION' as const,
|
||||
symbol: 'SOLUSD',
|
||||
timeframe: '1h',
|
||||
tradingAmount: 10, // $10 for simulation
|
||||
maxLeverage: 2,
|
||||
stopLossPercent: 2,
|
||||
takeProfitPercent: 6,
|
||||
maxDailyTrades: 5,
|
||||
riskPercentage: 1
|
||||
}
|
||||
|
||||
console.log('📋 Config:', testConfig)
|
||||
|
||||
// Test starting automation
|
||||
console.log('\n🚀 Starting automation...')
|
||||
const startResult = await automationService.startAutomation(testConfig)
|
||||
console.log('✅ Start result:', startResult)
|
||||
|
||||
// Test getting status
|
||||
console.log('\n📊 Getting status...')
|
||||
const status = await automationService.getStatus()
|
||||
console.log('✅ Status:', status)
|
||||
|
||||
// Test getting learning insights
|
||||
console.log('\n🧠 Getting learning insights...')
|
||||
const insights = await automationService.getLearningInsights(testConfig.userId)
|
||||
console.log('✅ Learning insights:', insights)
|
||||
|
||||
// Test stopping
|
||||
console.log('\n🛑 Stopping automation...')
|
||||
const stopResult = await automationService.stopAutomation()
|
||||
console.log('✅ Stop result:', stopResult)
|
||||
|
||||
console.log('\n🎉 All automation tests passed!')
|
||||
|
||||
return NextResponse.json({
|
||||
success: true,
|
||||
message: 'Automation service connection test passed!',
|
||||
results: {
|
||||
startResult,
|
||||
status,
|
||||
insights,
|
||||
stopResult
|
||||
}
|
||||
})
|
||||
|
||||
} catch (error) {
|
||||
console.error('❌ Test failed:', error)
|
||||
return NextResponse.json({
|
||||
success: false,
|
||||
error: error instanceof Error ? error.message : 'Unknown error'
|
||||
}, { status: 500 })
|
||||
}
|
||||
}
|
||||
@@ -1,28 +1,475 @@
|
||||
'use client'
|
||||
import React from 'react'
|
||||
import React, { useState, useEffect } from 'react'
|
||||
|
||||
export default function AutomationPage() {
|
||||
const [config, setConfig] = useState({
|
||||
mode: 'SIMULATION',
|
||||
symbol: 'SOLUSD',
|
||||
timeframe: '1h',
|
||||
tradingAmount: 100,
|
||||
maxLeverage: 3,
|
||||
stopLossPercent: 2,
|
||||
takeProfitPercent: 6,
|
||||
maxDailyTrades: 5,
|
||||
riskPercentage: 2
|
||||
})
|
||||
|
||||
const [status, setStatus] = useState(null)
|
||||
const [isLoading, setIsLoading] = useState(false)
|
||||
const [learningInsights, setLearningInsights] = useState(null)
|
||||
const [recentTrades, setRecentTrades] = useState([])
|
||||
|
||||
useEffect(() => {
|
||||
fetchStatus()
|
||||
fetchLearningInsights()
|
||||
fetchRecentTrades()
|
||||
}, [])
|
||||
|
||||
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 fetchLearningInsights = async () => {
|
||||
try {
|
||||
const response = await fetch('/api/automation/learning-insights')
|
||||
const data = await response.json()
|
||||
if (data.success) {
|
||||
setLearningInsights(data.insights)
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Failed to fetch learning insights:', error)
|
||||
}
|
||||
}
|
||||
|
||||
const fetchRecentTrades = async () => {
|
||||
try {
|
||||
const response = await fetch('/api/automation/recent-trades')
|
||||
const data = await response.json()
|
||||
if (data.success) {
|
||||
setRecentTrades(data.trades)
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Failed to fetch recent trades:', 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)
|
||||
}
|
||||
}
|
||||
|
||||
const handlePause = async () => {
|
||||
setIsLoading(true)
|
||||
try {
|
||||
const response = await fetch('/api/automation/pause', {
|
||||
method: 'POST'
|
||||
})
|
||||
const data = await response.json()
|
||||
if (data.success) {
|
||||
fetchStatus()
|
||||
} else {
|
||||
alert('Failed to pause automation: ' + data.error)
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Failed to pause automation:', error)
|
||||
alert('Failed to pause automation')
|
||||
} finally {
|
||||
setIsLoading(false)
|
||||
}
|
||||
}
|
||||
|
||||
const handleResume = async () => {
|
||||
setIsLoading(true)
|
||||
try {
|
||||
const response = await fetch('/api/automation/resume', {
|
||||
method: 'POST'
|
||||
})
|
||||
const data = await response.json()
|
||||
if (data.success) {
|
||||
fetchStatus()
|
||||
} else {
|
||||
alert('Failed to resume automation: ' + data.error)
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Failed to resume automation:', error)
|
||||
alert('Failed to resume automation')
|
||||
} finally {
|
||||
setIsLoading(false)
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="space-y-8">
|
||||
<div className="flex items-center justify-between">
|
||||
<div>
|
||||
<h1 className="text-3xl font-bold text-white">Automation</h1>
|
||||
<p className="text-gray-400 mt-2">Configure automated trading settings and monitor session status</p>
|
||||
<h1 className="text-3xl font-bold text-white">Automation Mode</h1>
|
||||
<p className="text-gray-400 mt-2">
|
||||
AI-powered automated trading on 1H timeframe with learning capabilities
|
||||
</p>
|
||||
</div>
|
||||
<div className="flex space-x-4">
|
||||
{status?.isActive ? (
|
||||
<>
|
||||
<button
|
||||
onClick={handlePause}
|
||||
disabled={isLoading}
|
||||
className="px-4 py-2 bg-yellow-600 text-white rounded-lg hover:bg-yellow-700 transition-colors disabled:opacity-50"
|
||||
>
|
||||
{isLoading ? 'Pausing...' : 'Pause'}
|
||||
</button>
|
||||
<button
|
||||
onClick={handleStop}
|
||||
disabled={isLoading}
|
||||
className="px-4 py-2 bg-red-600 text-white rounded-lg hover:bg-red-700 transition-colors disabled:opacity-50"
|
||||
>
|
||||
{isLoading ? 'Stopping...' : 'Stop'}
|
||||
</button>
|
||||
</>
|
||||
) : (
|
||||
<>
|
||||
{status?.status === 'PAUSED' && (
|
||||
<button
|
||||
onClick={handleResume}
|
||||
disabled={isLoading}
|
||||
className="px-4 py-2 bg-green-600 text-white rounded-lg hover:bg-green-700 transition-colors disabled:opacity-50"
|
||||
>
|
||||
{isLoading ? 'Resuming...' : 'Resume'}
|
||||
</button>
|
||||
)}
|
||||
<button
|
||||
onClick={handleStart}
|
||||
disabled={isLoading}
|
||||
className="px-4 py-2 bg-blue-600 text-white rounded-lg hover:bg-blue-700 transition-colors disabled:opacity-50"
|
||||
>
|
||||
{isLoading ? 'Starting...' : 'Start Automation'}
|
||||
</button>
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="grid grid-cols-1 xl:grid-cols-2 gap-8">
|
||||
{/* Configuration Panel */}
|
||||
<div className="space-y-6">
|
||||
<div className="card card-gradient p-6">
|
||||
<h2 className="text-xl font-bold text-white mb-4">Auto Trading Settings</h2>
|
||||
<p className="text-gray-400">Automation configuration will be available here.</p>
|
||||
<h2 className="text-xl font-bold text-white mb-4">Configuration</h2>
|
||||
|
||||
<div className="space-y-4">
|
||||
<div>
|
||||
<label className="block text-sm font-medium text-gray-300 mb-2">
|
||||
Trading Mode
|
||||
</label>
|
||||
<select
|
||||
value={config.mode}
|
||||
onChange={(e) => setConfig({...config, mode: e.target.value})}
|
||||
className="w-full p-3 bg-gray-800 border border-gray-700 rounded-lg text-white focus:outline-none focus:ring-2 focus:ring-blue-500"
|
||||
disabled={status?.isActive}
|
||||
>
|
||||
<option value="SIMULATION">Simulation (Paper Trading)</option>
|
||||
<option value="LIVE">Live Trading (Jupiter DEX)</option>
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<div className="grid grid-cols-2 gap-4">
|
||||
<div>
|
||||
<label className="block text-sm font-medium text-gray-300 mb-2">
|
||||
Symbol
|
||||
</label>
|
||||
<select
|
||||
value={config.symbol}
|
||||
onChange={(e) => setConfig({...config, symbol: e.target.value})}
|
||||
className="w-full p-3 bg-gray-800 border border-gray-700 rounded-lg text-white focus:outline-none focus:ring-2 focus:ring-blue-500"
|
||||
disabled={status?.isActive}
|
||||
>
|
||||
<option value="SOLUSD">SOL/USD</option>
|
||||
<option value="BTCUSD">BTC/USD</option>
|
||||
<option value="ETHUSD">ETH/USD</option>
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<label className="block text-sm font-medium text-gray-300 mb-2">
|
||||
Timeframe
|
||||
</label>
|
||||
<select
|
||||
value={config.timeframe}
|
||||
onChange={(e) => setConfig({...config, timeframe: e.target.value})}
|
||||
className="w-full p-3 bg-gray-800 border border-gray-700 rounded-lg text-white focus:outline-none focus:ring-2 focus:ring-blue-500"
|
||||
disabled={status?.isActive}
|
||||
>
|
||||
<option value="1h">1 Hour (Recommended)</option>
|
||||
<option value="4h">4 Hours</option>
|
||||
<option value="1d">1 Day</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="grid grid-cols-2 gap-4">
|
||||
<div>
|
||||
<label className="block text-sm font-medium text-gray-300 mb-2">
|
||||
Trading Amount ($)
|
||||
</label>
|
||||
<input
|
||||
type="number"
|
||||
value={config.tradingAmount}
|
||||
onChange={(e) => setConfig({...config, tradingAmount: parseFloat(e.target.value)})}
|
||||
className="w-full p-3 bg-gray-800 border border-gray-700 rounded-lg text-white focus:outline-none focus:ring-2 focus:ring-blue-500"
|
||||
disabled={status?.isActive}
|
||||
min="10"
|
||||
step="10"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<label className="block text-sm font-medium text-gray-300 mb-2">
|
||||
Max Leverage
|
||||
</label>
|
||||
<select
|
||||
value={config.maxLeverage}
|
||||
onChange={(e) => setConfig({...config, maxLeverage: parseFloat(e.target.value)})}
|
||||
className="w-full p-3 bg-gray-800 border border-gray-700 rounded-lg text-white focus:outline-none focus:ring-2 focus:ring-blue-500"
|
||||
disabled={status?.isActive}
|
||||
>
|
||||
<option value="1">1x (Spot)</option>
|
||||
<option value="2">2x</option>
|
||||
<option value="3">3x</option>
|
||||
<option value="5">5x</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="grid grid-cols-3 gap-4">
|
||||
<div>
|
||||
<label className="block text-sm font-medium text-gray-300 mb-2">
|
||||
Stop Loss (%)
|
||||
</label>
|
||||
<input
|
||||
type="number"
|
||||
value={config.stopLossPercent}
|
||||
onChange={(e) => setConfig({...config, stopLossPercent: parseFloat(e.target.value)})}
|
||||
className="w-full p-3 bg-gray-800 border border-gray-700 rounded-lg text-white focus:outline-none focus:ring-2 focus:ring-blue-500"
|
||||
disabled={status?.isActive}
|
||||
min="1"
|
||||
max="10"
|
||||
step="0.5"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<label className="block text-sm font-medium text-gray-300 mb-2">
|
||||
Take Profit (%)
|
||||
</label>
|
||||
<input
|
||||
type="number"
|
||||
value={config.takeProfitPercent}
|
||||
onChange={(e) => setConfig({...config, takeProfitPercent: parseFloat(e.target.value)})}
|
||||
className="w-full p-3 bg-gray-800 border border-gray-700 rounded-lg text-white focus:outline-none focus:ring-2 focus:ring-blue-500"
|
||||
disabled={status?.isActive}
|
||||
min="2"
|
||||
max="20"
|
||||
step="1"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<label className="block text-sm font-medium text-gray-300 mb-2">
|
||||
Max Daily Trades
|
||||
</label>
|
||||
<input
|
||||
type="number"
|
||||
value={config.maxDailyTrades}
|
||||
onChange={(e) => setConfig({...config, maxDailyTrades: parseInt(e.target.value)})}
|
||||
className="w-full p-3 bg-gray-800 border border-gray-700 rounded-lg text-white focus:outline-none focus:ring-2 focus:ring-blue-500"
|
||||
disabled={status?.isActive}
|
||||
min="1"
|
||||
max="20"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Learning Insights */}
|
||||
{learningInsights && (
|
||||
<div className="card card-gradient p-6">
|
||||
<h2 className="text-xl font-bold text-white mb-4">AI Learning Insights</h2>
|
||||
<div className="space-y-3">
|
||||
<div className="flex justify-between">
|
||||
<span className="text-gray-300">Total Analyses:</span>
|
||||
<span className="text-white font-semibold">{learningInsights.totalAnalyses}</span>
|
||||
</div>
|
||||
<div className="flex justify-between">
|
||||
<span className="text-gray-300">Avg Accuracy:</span>
|
||||
<span className="text-white font-semibold">{(learningInsights.avgAccuracy * 100).toFixed(1)}%</span>
|
||||
</div>
|
||||
<div className="flex justify-between">
|
||||
<span className="text-gray-300">Best Timeframe:</span>
|
||||
<span className="text-green-400 font-semibold">{learningInsights.bestTimeframe}</span>
|
||||
</div>
|
||||
<div className="flex justify-between">
|
||||
<span className="text-gray-300">Worst Timeframe:</span>
|
||||
<span className="text-red-400 font-semibold">{learningInsights.worstTimeframe}</span>
|
||||
</div>
|
||||
|
||||
<div className="mt-4">
|
||||
<h3 className="text-lg font-semibold text-white mb-2">Recommendations</h3>
|
||||
<ul className="space-y-1">
|
||||
{learningInsights.recommendations.map((rec, idx) => (
|
||||
<li key={idx} className="text-sm text-gray-300">• {rec}</li>
|
||||
))}
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{/* Status and Performance */}
|
||||
<div className="space-y-6">
|
||||
{/* Status Panel */}
|
||||
<div className="card card-gradient p-6">
|
||||
<h2 className="text-xl font-bold text-white mb-4">Session Status</h2>
|
||||
<p className="text-gray-400">Session monitoring will be shown here.</p>
|
||||
<h2 className="text-xl font-bold text-white mb-4">Status</h2>
|
||||
{status ? (
|
||||
<div className="space-y-3">
|
||||
<div className="flex items-center justify-between">
|
||||
<span className="text-gray-300">Status:</span>
|
||||
<span className={`font-semibold px-2 py-1 rounded ${
|
||||
status.isActive ? 'bg-green-600 text-white' : 'bg-red-600 text-white'
|
||||
}`}>
|
||||
{status.isActive ? 'ACTIVE' : 'STOPPED'}
|
||||
</span>
|
||||
</div>
|
||||
<div className="flex justify-between">
|
||||
<span className="text-gray-300">Mode:</span>
|
||||
<span className={`font-semibold ${
|
||||
status.mode === 'LIVE' ? 'text-red-400' : 'text-blue-400'
|
||||
}`}>
|
||||
{status.mode}
|
||||
</span>
|
||||
</div>
|
||||
<div className="flex justify-between">
|
||||
<span className="text-gray-300">Symbol:</span>
|
||||
<span className="text-white font-semibold">{status.symbol}</span>
|
||||
</div>
|
||||
<div className="flex justify-between">
|
||||
<span className="text-gray-300">Timeframe:</span>
|
||||
<span className="text-white font-semibold">{status.timeframe}</span>
|
||||
</div>
|
||||
<div className="flex justify-between">
|
||||
<span className="text-gray-300">Total Trades:</span>
|
||||
<span className="text-white font-semibold">{status.totalTrades}</span>
|
||||
</div>
|
||||
<div className="flex justify-between">
|
||||
<span className="text-gray-300">Win Rate:</span>
|
||||
<span className={`font-semibold ${
|
||||
status.winRate > 0.6 ? 'text-green-400' :
|
||||
status.winRate > 0.4 ? 'text-yellow-400' : 'text-red-400'
|
||||
}`}>
|
||||
{(status.winRate * 100).toFixed(1)}%
|
||||
</span>
|
||||
</div>
|
||||
<div className="flex justify-between">
|
||||
<span className="text-gray-300">Total P&L:</span>
|
||||
<span className={`font-semibold ${
|
||||
status.totalPnL > 0 ? 'text-green-400' :
|
||||
status.totalPnL < 0 ? 'text-red-400' : 'text-gray-300'
|
||||
}`}>
|
||||
${status.totalPnL.toFixed(2)}
|
||||
</span>
|
||||
</div>
|
||||
{status.lastAnalysis && (
|
||||
<div className="flex justify-between">
|
||||
<span className="text-gray-300">Last Analysis:</span>
|
||||
<span className="text-white font-semibold">
|
||||
{new Date(status.lastAnalysis).toLocaleTimeString()}
|
||||
</span>
|
||||
</div>
|
||||
)}
|
||||
{status.errorCount > 0 && (
|
||||
<div className="flex justify-between">
|
||||
<span className="text-gray-300">Errors:</span>
|
||||
<span className="text-red-400 font-semibold">{status.errorCount}</span>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
) : (
|
||||
<p className="text-gray-400">No active automation session</p>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{/* Recent Trades */}
|
||||
<div className="card card-gradient p-6">
|
||||
<h2 className="text-xl font-bold text-white mb-4">Recent Automated Trades</h2>
|
||||
{recentTrades.length > 0 ? (
|
||||
<div className="space-y-3">
|
||||
{recentTrades.slice(0, 5).map((trade, idx) => (
|
||||
<div key={idx} className="flex items-center justify-between p-3 bg-gray-800 rounded-lg">
|
||||
<div>
|
||||
<span className={`font-semibold ${
|
||||
trade.side === 'BUY' ? 'text-green-400' : 'text-red-400'
|
||||
}`}>
|
||||
{trade.side}
|
||||
</span>
|
||||
<span className="text-white ml-2">{trade.symbol}</span>
|
||||
<span className="text-gray-400 ml-2">{trade.timeframe}</span>
|
||||
</div>
|
||||
<div className="text-right">
|
||||
<div className="text-white font-semibold">${trade.amount}</div>
|
||||
<div className="text-sm text-gray-400">{trade.confidence}% confidence</div>
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
) : (
|
||||
<p className="text-gray-400">No recent trades</p>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user