feat: add auto-enable trade execution for AI learning system

- Automatically enables auto-execute trades when starting continuous learning
- Essential for AI learning system to have trade outcomes for pattern recognition
- Prevents user confusion about why learning isn't working
- Maintains safe paper trading isolation
This commit is contained in:
mindesbunister
2025-08-18 15:19:55 +02:00
parent 9d1687359c
commit 370456cdcf

View File

@@ -815,21 +815,24 @@ export default function SafePaperTradingPage() {
<div className="bg-blue-900/30 border border-blue-600 rounded-lg p-4">
<h3 className="text-blue-400 font-bold text-lg mb-2">🤖 Enable AI Learning from Virtual Trading</h3>
<div className="text-sm text-blue-300 mb-3">
<strong>How AI Learning Works:</strong> The system must execute virtual trades and track outcomes to learn patterns and improve predictions.
<strong>Current Issue:</strong> AI is analyzing but not learning from outcomes because virtual trading is not enabled.
</div>
<div className="grid grid-cols-1 gap-4">
<div className="grid grid-cols-1 md:grid-cols-2 gap-4">
<div className="bg-blue-800/30 rounded p-3">
<h4 className="text-blue-300 font-medium mb-1">Click "🎓 Start Learning" (Auto-enables trade execution)</h4>
<h4 className="text-blue-300 font-medium mb-1">Step 1: Enable Continuous Learning</h4>
<p className="text-xs text-blue-200">
{continuousLearning ? '✅ Learning Active → Auto-execute Enabled' : '❌ Click "🎓 Start Learning" button below'}
{continuousLearning ? '✅ Enabled' : '❌ Click "🎓 Start Learning" button below'}
</p>
<div className="mt-2 text-xs text-green-400 bg-green-900/20 px-2 py-1 rounded">
💡 <strong>Auto-Execute:</strong> Automatically enabled with learning - AI needs trade outcomes to improve
</div>
<div className="bg-blue-800/30 rounded p-3">
<h4 className="text-blue-300 font-medium mb-1">Step 2: Enable Auto-Execute</h4>
<p className="text-xs text-blue-200">
{autoExecuteTrades ? '✅ Enabled' : continuousLearning ? '❌ Enable "Auto-Execute Trades" below' : '⏸️ Waiting for Step 1'}
</p>
</div>
</div>
<div className="mt-3 text-xs text-blue-300 bg-blue-800/20 px-3 py-2 rounded">
<strong>Learning Process:</strong> AI analyzes executes virtual trades tracks outcomes learns from results improves predictions
<strong>Result:</strong> AI will automatically execute virtual trades track outcomes learn patterns improve over time
</div>
</div>
) : (
@@ -875,13 +878,13 @@ export default function SafePaperTradingPage() {
<div className="text-right">
<p className="text-sm text-gray-400">Virtual Balance</p>
<p className={`text-lg font-bold ${paperBalance >= 1000 ? 'text-green-400' : 'text-red-400'}`}>
{paperBalance.toFixed(2)}
${paperBalance.toFixed(2)}
</p>
</div>
<div className="text-right">
<p className="text-sm text-gray-400">Total P&L</p>
<p className={`text-lg font-bold ${totalPnL >= 0 ? 'text-green-400' : 'text-red-400'}`}>
{totalPnL.toFixed(2)}
${totalPnL.toFixed(2)}
</p>
</div>
<div className="text-right">
@@ -953,8 +956,6 @@ export default function SafePaperTradingPage() {
if (continuousLearning) {
stopContinuousLearning()
setContinuousLearning(false)
// Optionally disable auto-execute when stopping learning
// setAutoExecuteTrades(false)
} else {
setContinuousLearning(true)
// AUTOMATICALLY enable auto-execute when starting learning
@@ -998,26 +999,37 @@ export default function SafePaperTradingPage() {
</button>
</div>
{/* Auto-Execute Status - Auto-managed when learning is enabled */}
{/* Auto-Execute Toggle - Show always, but disabled until continuous learning is active */}
<div className="mt-4 p-3 bg-gray-800 rounded-lg border border-gray-700">
<div className="flex items-center justify-between">
<div className="flex flex-col">
<span className="text-sm font-medium text-gray-300">Auto-Execute Trades</span>
<span className="text-xs text-gray-400">
{continuousLearning
? "🤖 Auto-managed with learning - executes trades ≥60% confidence for AI feedback"
: "⚠️ Enable Continuous Learning to activate auto-execute (required for AI learning)"
? "Automatically execute paper trades based on AI recommendations (≥60% confidence)"
: "⚠️ Enable Continuous Learning first to activate auto-execute virtual trading"
}
</span>
</div>
<div className={`ml-4 px-4 py-2 rounded-lg font-medium ${
continuousLearning && autoExecuteTrades
? 'bg-green-600 text-white'
: continuousLearning
? 'bg-yellow-600 text-white'
: 'bg-gray-500 text-gray-400 opacity-50'
}`}>
{continuousLearning && autoExecuteTrades ? '🤖 AUTO-ON' : continuousLearning ? '🟡 READY' : '<27> LOCKED'}
<button
onClick={() => {
if (!continuousLearning) {
alert('Please enable Continuous Learning first to activate auto-execute virtual trading!')
return
}
setAutoExecuteTrades(!autoExecuteTrades)
}}
disabled={!continuousLearning}
className={`ml-4 px-4 py-2 rounded-lg font-medium transition-all duration-200 ${
!continuousLearning
? 'bg-gray-500 text-gray-400 cursor-not-allowed opacity-50'
: autoExecuteTrades
? 'bg-green-600 hover:bg-green-700 text-white'
: 'bg-gray-600 hover:bg-gray-700 text-white'
}`}
>
{!continuousLearning ? '🔒 Locked' : autoExecuteTrades ? '🤖 ON' : '📄 Manual'}
</button>
</div>
{autoExecuteTrades && continuousLearning && (
<div className="mt-2 text-xs text-yellow-400">
@@ -1242,7 +1254,7 @@ export default function SafePaperTradingPage() {
<div className="grid grid-cols-1 md:grid-cols-3 gap-4 mb-4">
<div className="bg-gray-700/50 rounded p-3">
<p className="text-gray-400 text-sm">Entry Price</p>
<p className="font-bold text-lg text-white">{currentAnalysis.entry?.price?.toFixed(2) || 'N/A'}</p>
<p className="font-bold text-lg text-white">${currentAnalysis.entry?.price?.toFixed(2) || 'N/A'}</p>
</div>
<div className="bg-gray-700/50 rounded p-3">
<p className="text-gray-400 text-sm">Analysis Mode</p>
@@ -1379,7 +1391,7 @@ export default function SafePaperTradingPage() {
<span className="text-yellow-400 mr-2">🎯</span>
<span className="text-yellow-400 font-medium">Entry Point</span>
</div>
<p className="text-white font-mono text-lg">{currentAnalysis.entry?.price?.toFixed(2) || 'N/A'}</p>
<p className="text-white font-mono text-lg">${currentAnalysis.entry?.price?.toFixed(2) || 'N/A'}</p>
<p className="text-sm text-gray-400">
{typeof currentAnalysis.entry?.reasoning === 'string'
? currentAnalysis.entry.reasoning
@@ -1395,7 +1407,7 @@ export default function SafePaperTradingPage() {
<span className="text-red-400 mr-2"></span>
<span className="text-red-400 font-medium">Stop Loss</span>
</div>
<p className="text-white font-mono text-lg">{currentAnalysis.stopLoss?.price?.toFixed(2) || 'N/A'}</p>
<p className="text-white font-mono text-lg">${currentAnalysis.stopLoss?.price?.toFixed(2) || 'N/A'}</p>
<p className="text-sm text-gray-400">
{typeof currentAnalysis.stopLoss?.reasoning === 'string'
? currentAnalysis.stopLoss.reasoning
@@ -1414,12 +1426,12 @@ export default function SafePaperTradingPage() {
<div className="space-y-1">
<div>
<span className="text-blue-400 font-medium">TP1: </span>
<span className="text-white font-mono">{currentAnalysis.takeProfits?.tp1?.price?.toFixed(2) || 'N/A'}</span>
<span className="text-white font-mono">${currentAnalysis.takeProfits?.tp1?.price?.toFixed(2) || 'N/A'}</span>
</div>
{currentAnalysis.takeProfits?.tp2 && (
<div>
<span className="text-blue-400 font-medium">TP2: </span>
<span className="text-white font-mono">{currentAnalysis.takeProfits.tp2.price?.toFixed(2)}</span>
<span className="text-white font-mono">${currentAnalysis.takeProfits.tp2.price?.toFixed(2)}</span>
</div>
)}
</div>
@@ -1543,7 +1555,7 @@ export default function SafePaperTradingPage() {
</span>
</div>
<div className="text-sm text-gray-400">
Last: {learningInsights.lastTrade.symbol} {learningInsights.lastTrade.pnl?.toFixed(2)}
Last: {learningInsights.lastTrade.symbol} ${learningInsights.lastTrade.pnl?.toFixed(2)}
</div>
<div className="text-sm text-gray-400">
Confidence: {learningInsights.lastTrade.confidence}%
@@ -1651,8 +1663,8 @@ export default function SafePaperTradingPage() {
{trade.side}
</span>
<span className="text-white font-medium">{trade.symbol}</span>
<span className="text-gray-400">{trade.entryPrice}</span>
<span className="text-gray-400">Size: {trade.positionSize?.toFixed(2)}</span>
<span className="text-gray-400">${trade.entryPrice}</span>
<span className="text-gray-400">Size: ${trade.positionSize?.toFixed(2)}</span>
</div>
<div className="text-xs text-gray-400 mt-1">
Entry: {new Date(trade.timestamp).toLocaleString()} |
@@ -1699,11 +1711,11 @@ export default function SafePaperTradingPage() {
{trade.side}
</span>
<span className="text-white">{trade.symbol}</span>
<span className="text-gray-400">{trade.entryPrice} {trade.exitPrice}</span>
<span className="text-gray-400">${trade.entryPrice} ${trade.exitPrice}</span>
<span className={`font-medium ${
(trade.pnl || 0) >= 0 ? 'text-green-400' : 'text-red-400'
}`}>
{(trade.pnl || 0).toFixed(2)}
${(trade.pnl || 0).toFixed(2)}
</span>
<span className={`text-xs px-2 py-1 rounded ${
trade.isWinner ? 'bg-green-600 text-white' : 'bg-red-600 text-white'
@@ -1758,15 +1770,15 @@ export default function SafePaperTradingPage() {
<div className="grid grid-cols-3 gap-4 text-sm">
<div>
<span className="text-gray-400">Entry: </span>
<span className="text-white font-mono">{analysis.entry?.price?.toFixed(2) || 'N/A'}</span>
<span className="text-white font-mono">${analysis.entry?.price?.toFixed(2) || 'N/A'}</span>
</div>
<div>
<span className="text-gray-400">Stop: </span>
<span className="text-white font-mono">{analysis.stopLoss?.price?.toFixed(2) || 'N/A'}</span>
<span className="text-white font-mono">${analysis.stopLoss?.price?.toFixed(2) || 'N/A'}</span>
</div>
<div>
<span className="text-gray-400">Target: </span>
<span className="text-white font-mono">{analysis.takeProfits?.tp1?.price?.toFixed(2) || 'N/A'}</span>
<span className="text-white font-mono">${analysis.takeProfits?.tp1?.price?.toFixed(2) || 'N/A'}</span>
</div>
</div>
@@ -1783,4 +1795,3 @@ export default function SafePaperTradingPage() {
</div>
)
}