feat: Always show stop buttons when positions exist to prevent automation triggers
Modified Stop Button Logic:
- Stop buttons now visible when positions exist (not just when automation active)
- Prevents automation from triggering when positions close
- Added helpful tooltips explaining button purpose in different states
Enhanced Button Behavior:
- When automation active: 'STOP' button stops running automation
- When positions exist but automation inactive: 'DISABLE' button prevents triggers
- Emergency button always available for immediate safety
Safety Scripts Added:
- immediate-stop.js: Quick script to disable automation before position close
- Verifies position status and ensures no automation triggers
Position Safety: CONFIRMED
- Current position: SOL-PERP LONG .41 PnL
- Automation: DISABLED ✅
- Safe to close position manually without triggering new automation
Critical for position management - stops automation from auto-triggering on position close.
This commit is contained in:
@@ -380,12 +380,13 @@ Based on comprehensive technical analysis across multiple timeframes:
|
||||
</div>
|
||||
|
||||
<div className="flex space-x-4">
|
||||
{status?.isActive ? (
|
||||
{(status?.isActive || positions.length > 0) ? (
|
||||
<>
|
||||
<button
|
||||
onClick={handleStop}
|
||||
disabled={loading}
|
||||
className="px-8 py-4 bg-gradient-to-r from-red-600 to-red-700 text-white rounded-xl hover:from-red-700 hover:to-red-800 transition-all duration-200 disabled:opacity-50 font-semibold shadow-lg shadow-red-500/25 transform hover:scale-105"
|
||||
title={status?.isActive ? "Stop active automation" : "Prevent automation from triggering on position close"}
|
||||
>
|
||||
{loading ? (
|
||||
<div className="flex items-center space-x-2">
|
||||
@@ -395,7 +396,7 @@ Based on comprehensive technical analysis across multiple timeframes:
|
||||
) : (
|
||||
<div className="flex items-center space-x-2">
|
||||
<span>🛑</span>
|
||||
<span>STOP</span>
|
||||
<span>{status?.isActive ? 'STOP' : 'DISABLE'}</span>
|
||||
</div>
|
||||
)}
|
||||
</button>
|
||||
@@ -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"}
|
||||
>
|
||||
<div className="flex items-center space-x-2">
|
||||
<span>🚨</span>
|
||||
|
||||
67
immediate-stop.js
Normal file
67
immediate-stop.js
Normal file
@@ -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);
|
||||
83
live-component-test.js
Normal file
83
live-component-test.js
Normal file
@@ -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);
|
||||
Reference in New Issue
Block a user