diff --git a/app/automation-v2/page.js b/app/automation-v2/page.js index b573b5d..430ae5f 100644 --- a/app/automation-v2/page.js +++ b/app/automation-v2/page.js @@ -380,12 +380,13 @@ Based on comprehensive technical analysis across multiple timeframes:
- {status?.isActive ? ( + {(status?.isActive || positions.length > 0) ? ( <> @@ -403,7 +404,7 @@ Based on comprehensive technical analysis across multiple timeframes: onClick={handleEmergencyStop} disabled={loading} className="px-6 py-4 bg-gradient-to-r from-red-800 to-red-900 text-white rounded-xl hover:from-red-900 hover:to-red-950 transition-all duration-200 disabled:opacity-50 font-semibold border-2 border-red-600/50 shadow-lg shadow-red-900/50 transform hover:scale-105" - title="Emergency Stop - Closes all positions immediately" + title={status?.isActive ? "Emergency Stop - Closes all positions immediately" : "Emergency disable - Prevents any automation triggers"} >
🚨 diff --git a/immediate-stop.js b/immediate-stop.js new file mode 100644 index 0000000..e28d2ff --- /dev/null +++ b/immediate-stop.js @@ -0,0 +1,67 @@ +#!/usr/bin/env node + +/** + * Immediate Stop Script - Disable automation to prevent triggers on position close + */ + +const baseUrl = 'http://localhost:9001'; + +async function immediateStop() { + console.log('🚨 IMMEDIATE AUTOMATION STOP\n'); + + try { + // 1. Check current position + console.log('šŸ“ˆ Checking Active Position:'); + const positionsResponse = await fetch(`${baseUrl}/api/drift/positions`); + const positionsData = await positionsResponse.json(); + + if (positionsData.success && positionsData.positions?.length > 0) { + console.log(` āš ļø ACTIVE POSITION DETECTED: ${positionsData.positions.length} position(s)`); + positionsData.positions.forEach((pos, i) => { + console.log(` - Position ${i+1}: ${pos.symbol} ${pos.side.toUpperCase()}`); + console.log(` Size: ${pos.size}, PnL: $${pos.unrealizedPnl?.toFixed(2)}`); + }); + console.log(' 🚨 Position close could trigger automation - STOPPING NOW!\n'); + } + + // 2. Stop automation immediately + console.log('šŸ›‘ Stopping Automation:'); + const stopResponse = await fetch(`${baseUrl}/api/automation/stop`, { + method: 'POST' + }); + const stopResult = await stopResponse.json(); + console.log(` - Regular Stop: ${stopResult.success ? 'āœ… SUCCESS' : 'āŒ FAILED'}`); + console.log(` - Message: ${stopResult.message}`); + + // 3. Emergency stop for extra safety + console.log('\n🚨 Emergency Stop (Extra Safety):'); + const emergencyResponse = await fetch(`${baseUrl}/api/automation/emergency-stop`, { + method: 'POST' + }); + const emergencyResult = await emergencyResponse.json(); + console.log(` - Emergency Stop: ${emergencyResult.success ? 'āœ… SUCCESS' : 'āŒ FAILED'}`); + + // 4. Verify automation is stopped + console.log('\nāœ… Verification:'); + const statusResponse = await fetch(`${baseUrl}/api/automation/status`); + const statusData = await statusResponse.json(); + console.log(` - Automation Active: ${statusData.isActive ? 'āš ļø STILL ACTIVE' : 'āœ… STOPPED'}`); + + console.log('\nšŸŽÆ RESULT:'); + if (!statusData.isActive) { + console.log(' āœ… AUTOMATION DISABLED - Safe to close position manually'); + console.log(' āœ… No automation will trigger when position closes'); + console.log(' šŸ’” You can now close your position safely in Drift'); + } else { + console.log(' āš ļø AUTOMATION STILL ACTIVE - May need manual intervention'); + } + + } catch (error) { + console.error('āŒ Stop script failed:', error.message); + console.log('\nšŸ†˜ MANUAL STOP COMMANDS:'); + console.log(' curl -X POST http://localhost:9001/api/automation/stop'); + console.log(' curl -X POST http://localhost:9001/api/automation/emergency-stop'); + } +} + +immediateStop().catch(console.error); diff --git a/live-component-test.js b/live-component-test.js new file mode 100644 index 0000000..b03cc32 --- /dev/null +++ b/live-component-test.js @@ -0,0 +1,83 @@ +#!/usr/bin/env node + +/** + * Live Component Data Test - Check what the frontend component is actually receiving + */ + +const baseUrl = 'http://localhost:9001'; + +async function testComponentData() { + console.log('šŸ” Testing what the EnhancedAILearningPanel component receives...\n'); + + try { + // Test the three API endpoints the component calls + console.log('1ļøāƒ£ Testing /api/automation/learning-status:'); + const learningResponse = await fetch(`${baseUrl}/api/automation/learning-status`); + const learningData = await learningResponse.json(); + console.log(` - Success: ${learningData.success}`); + console.log(` - Learning Enabled: ${learningData.learningSystem?.enabled}`); + console.log(` - Message: ${learningData.learningSystem?.message}`); + + console.log('\n2ļøāƒ£ Testing /api/automation/status:'); + const statusResponse = await fetch(`${baseUrl}/api/automation/status`); + const statusData = await statusResponse.json(); + console.log(` - Is Active: ${statusData.isActive}`); + console.log(` - Mode: ${statusData.mode}`); + console.log(` - Symbol: ${statusData.symbol}`); + + console.log('\n3ļøāƒ£ Testing /api/ai-learning-status:'); + const aiLearningResponse = await fetch(`${baseUrl}/api/ai-learning-status`); + const aiLearningData = await aiLearningResponse.json(); + console.log(` - Success: ${aiLearningData.success}`); + console.log(` - Total Analyses: ${aiLearningData.data?.totalAnalyses}`); + console.log(` - Phase: ${aiLearningData.data?.phase}`); + console.log(` - Statistics Object:`, JSON.stringify(aiLearningData.data?.statistics, null, 2)); + + // Check what the component logic would do + console.log('\n🧠 Component Logic Analysis:'); + const aiData = aiLearningData.success ? aiLearningData.data : { + totalAnalyses: 0, + totalDecisions: 0, + // ... fallback data + }; + + console.log(` - Component would use: ${aiLearningData.success ? 'REAL API DATA' : 'FALLBACK DATA'}`); + console.log(` - Total Analyses: ${aiData.totalAnalyses}`); + console.log(` - Has Learning Data: ${(aiData.totalAnalyses || 0) > 0}`); + console.log(` - Should Show Active: ${(aiData.totalAnalyses || 0) > 0 || (aiData.totalDecisions || 0) > 0}`); + + // Check browser cache issues + console.log('\n🌐 Browser Cache Check:'); + const headers = { + 'Cache-Control': 'no-cache', + 'Pragma': 'no-cache' + }; + const pageResponse = await fetch(`${baseUrl}/automation-v2`, { headers }); + console.log(` - Page loads: ${pageResponse.ok ? 'YES' : 'NO'}`); + console.log(` - Content-Type: ${pageResponse.headers.get('content-type')}`); + + // Check if it's a Next.js page + const pageText = await pageResponse.text(); + const hasLearningComponent = pageText.includes('AI Learning System'); + const hasReactHydration = pageText.includes('__NEXT_DATA__'); + + console.log(` - Has AI Learning Component: ${hasLearningComponent ? 'YES' : 'NO'}`); + console.log(` - Has React Hydration: ${hasReactHydration ? 'YES' : 'NO'}`); + + console.log('\nšŸŽÆ Diagnosis:'); + if (!statusData.isActive) { + console.log(' āš ļø STOP BUTTON: Hidden because automation is not active'); + console.log(' šŸ’” To see stop button: Start automation first'); + } + + if (aiLearningData.success && aiData.totalAnalyses > 9000) { + console.log(' āœ… AI DATA: Component should show real learning data'); + console.log(' šŸ’” If still showing old data: Clear browser cache (Ctrl+F5)'); + } + + } catch (error) { + console.error('āŒ Test failed:', error.message); + } +} + +testComponentData().catch(console.error);