feat: add retroactive position analysis functionality
New Features: - 🔍 ANALYZE button to generate AI reasoning for existing positions - Retroactive AI analysis API endpoint for positions opened outside automation - Enhanced reasoning display with RETROACTIVE indicator - Smart position analysis that handles missing stop loss data - /api/automation/analyze-position endpoint for retroactive analysis - analyzeExistingPosition() function in automation-v2 UI - Automatic estimation of stop loss when not visible in position data - Enhanced AI reasoning panel with retroactive analysis support - Analyzes entry strategy, risk management, and leverage calculations - Generates detailed AI reasoning for existing positions - Shows estimated vs actual stop loss levels - Calculates risk/reward ratios and leverage estimates - Displays position status (profitable/underwater) with safety metrics - RETROACTIVE badge for analyzed existing positions - Blue 🔍 ANALYZE button in automation controls - Enhanced reasoning display with position-specific insights - Comprehensive execution details with estimated vs actual data Now users can see AI reasoning for any existing position, not just new automation trades!
This commit is contained in:
@@ -260,6 +260,44 @@ export default function AutomationPageV2() {
|
||||
}
|
||||
}
|
||||
|
||||
const analyzeExistingPosition = async () => {
|
||||
console.log('🔍 Analyzing existing position...')
|
||||
setLoading(true)
|
||||
try {
|
||||
// First get the current position data
|
||||
const positionResponse = await fetch('/api/automation/position-monitor')
|
||||
const positionData = await positionResponse.json()
|
||||
|
||||
if (positionData.success && positionData.monitor.hasPosition) {
|
||||
// Analyze the existing position
|
||||
const response = await fetch('/api/automation/analyze-position', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({
|
||||
action: 'analyze_existing_position',
|
||||
positionData: positionData.monitor.position
|
||||
})
|
||||
})
|
||||
|
||||
const data = await response.json()
|
||||
|
||||
if (data.success) {
|
||||
console.log('✅ Position analysis generated successfully')
|
||||
fetchStatus() // Refresh to show the analysis
|
||||
} else {
|
||||
console.error('Failed to analyze position:', data.error)
|
||||
}
|
||||
} else {
|
||||
console.log('ℹ️ No position found to analyze')
|
||||
alert('No active position found to analyze')
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Position analysis error:', error)
|
||||
} finally {
|
||||
setLoading(false)
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="space-y-6">
|
||||
<div className="grid grid-cols-1 xl:grid-cols-3 gap-6">
|
||||
@@ -296,6 +334,14 @@ export default function AutomationPageV2() {
|
||||
>
|
||||
🧪 TEST AI
|
||||
</button>
|
||||
<button
|
||||
onClick={analyzeExistingPosition}
|
||||
disabled={loading}
|
||||
className="px-4 py-3 bg-blue-600 text-white rounded-lg hover:bg-blue-700 transition-colors disabled:opacity-50 font-semibold border-2 border-blue-500"
|
||||
title="Analyze Current Position - Generate AI reasoning for existing position"
|
||||
>
|
||||
🔍 ANALYZE
|
||||
</button>
|
||||
</>
|
||||
) : (
|
||||
<button
|
||||
@@ -572,6 +618,11 @@ export default function AutomationPageV2() {
|
||||
}`}>
|
||||
{status.lastDecision.recommendation || 'HOLD'}
|
||||
</div>
|
||||
{status.lastDecision.isRetrospective && (
|
||||
<div className="px-2 py-1 rounded-full text-xs font-bold bg-orange-500/20 text-orange-300 border border-orange-500/30">
|
||||
📊 RETROACTIVE
|
||||
</div>
|
||||
)}
|
||||
<div className="flex items-center space-x-2">
|
||||
<span className="text-gray-400 text-sm">Confidence:</span>
|
||||
<div className={`px-2 py-1 rounded text-sm font-bold ${
|
||||
|
||||
Reference in New Issue
Block a user