Files
trading_bot_v3/test-safe-paper-trading-enhancement.js

213 lines
11 KiB
JavaScript

// Test if safe paper trading is getting enhanced AI analysis features
const fs = require('fs').promises;
async function testSafePaperTradingEnhancement() {
try {
console.log('🧪 Testing Safe Paper Trading Enhancement Integration');
console.log('======================================================\n');
// Test the API chain that safe paper trading uses
console.log('🔗 Testing Safe Paper Trading → Enhanced AI Analysis Chain:');
console.log('');
console.log('1. Safe Paper Trading page calls → /api/paper-trading-safe');
console.log('2. Paper Trading Safe API calls → /api/ai-analysis/latest');
console.log('3. AI Analysis Latest calls → /api/enhanced-screenshot (analyze: true)');
console.log('4. Enhanced Screenshot API uses → lib/ai-analysis.ts (NEW ENHANCED VERSION)');
console.log('');
// Check if the Docker environment is running (needed for real test)
const testUrl = 'http://localhost:9001/api/paper-trading-safe';
console.log('🐳 Testing if Docker development environment is running...');
try {
const testResponse = await fetch('http://localhost:9001/api/health', {
signal: AbortSignal.timeout(5000)
});
if (testResponse.ok) {
console.log('✅ Docker environment is running - can test real integration');
// Test the actual safe paper trading API
console.log('\n🧪 Testing Safe Paper Trading API with Enhanced Features...');
const safePaperRequest = {
symbol: 'SOLUSD',
selectedTimeframes: ['60'],
mode: 'PAPER_ONLY',
paperTrading: true,
isolatedMode: true,
isContinuous: false
};
console.log('📊 Request data:', JSON.stringify(safePaperRequest, null, 2));
const apiResponse = await fetch(testUrl, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(safePaperRequest),
signal: AbortSignal.timeout(120000) // 2 minutes for real analysis
});
console.log(`📡 Response status: ${apiResponse.status}`);
if (apiResponse.ok) {
const result = await apiResponse.json();
console.log('✅ Safe Paper Trading API Response Received');
const analysis = result.analysis;
// Check for new professional trading features
console.log('\n🎯 Checking for Enhanced Professional Trading Features:');
console.log('=========================================================');
// Check execution zone
if (analysis.entry?.zone) {
console.log('✅ Execution Zone: Found');
console.log(` Low: $${analysis.entry.zone.low}`);
console.log(` High: $${analysis.entry.zone.high}`);
console.log(` Optimal: $${analysis.entry.zone.optimal}`);
} else {
console.log('❌ Execution Zone: Missing (using old single price format)');
}
// Check slippage buffer
if (analysis.entry?.slippageBuffer) {
console.log(`✅ Slippage Buffer: $${analysis.entry.slippageBuffer}`);
} else {
console.log('❌ Slippage Buffer: Missing');
}
// Check leverage guidance
if (analysis.leverageGuidance) {
console.log('✅ Leverage Guidance: Found');
console.log(` Suggested: ${analysis.leverageGuidance.suggestedLeverage}`);
console.log(` Position Size: ${analysis.leverageGuidance.positionSizePercent}`);
console.log(` Risk Level: ${analysis.leverageGuidance.riskLevel}`);
} else {
console.log('❌ Leverage Guidance: Missing');
}
// Check indicator roadmap
if (analysis.indicatorRoadmap) {
console.log('✅ Indicator Roadmap: Found');
if (analysis.indicatorRoadmap.rsi) {
console.log(` RSI at Entry: ${analysis.indicatorRoadmap.rsi.atEntry}`);
console.log(` RSI Invalidation: ${analysis.indicatorRoadmap.rsi.invalidation}`);
}
if (analysis.indicatorRoadmap.vwap) {
console.log(` VWAP at Entry: ${analysis.indicatorRoadmap.vwap.atEntry}`);
}
} else {
console.log('❌ Indicator Roadmap: Missing');
}
// Check journal template
if (analysis.journalTemplate) {
console.log('✅ Journal Template: Found');
console.log(` Pre-filled Asset: ${analysis.journalTemplate.preFilledData?.asset}`);
console.log(` Setup Type: ${analysis.journalTemplate.preFilledData?.setupType}`);
} else {
console.log('❌ Journal Template: Missing');
}
// Check scenario management
if (analysis.scenarioManagement) {
console.log('✅ Scenario Management: Found');
if (analysis.scenarioManagement.invalidation) {
console.log(` Invalidation Level: $${analysis.scenarioManagement.invalidation.priceLevel}`);
console.log(` Immediate Action: ${analysis.scenarioManagement.invalidation.immediateAction}`);
}
if (analysis.scenarioManagement.alternatives) {
console.log(` Tighter Stop Option: ${analysis.scenarioManagement.alternatives.tighterStopOption || 'N/A'}`);
}
} else {
console.log('❌ Scenario Management: Missing');
}
// Check psychology coaching
if (analysis.psychologyCoaching) {
console.log('✅ Psychology Coaching: Found');
console.log(` Mindset Reminder: ${analysis.psychologyCoaching.mindsetReminder}`);
console.log(` Discipline Note: ${analysis.psychologyCoaching.disciplineNote}`);
} else {
console.log('❌ Psychology Coaching: Missing');
}
// Overall assessment
const enhancedFeatures = [
analysis.entry?.zone,
analysis.entry?.slippageBuffer,
analysis.leverageGuidance,
analysis.indicatorRoadmap,
analysis.journalTemplate,
analysis.scenarioManagement,
analysis.psychologyCoaching
].filter(Boolean).length;
console.log('\n📊 Enhancement Summary:');
console.log('=======================');
console.log(`✅ Enhanced Features Detected: ${enhancedFeatures}/7`);
console.log(`📈 Recommendation: ${analysis.recommendation}`);
console.log(`💪 Confidence: ${analysis.confidence}%`);
console.log(`🎯 Entry Price: $${analysis.entry?.price || 'N/A'}`);
if (enhancedFeatures >= 5) {
console.log('🎉 SUCCESS: Safe Paper Trading is using ENHANCED AI Analysis!');
console.log('🚀 Users will get professional trading desk precision in paper trading.');
} else if (enhancedFeatures >= 3) {
console.log('⚠️ PARTIAL: Some enhanced features detected, but not all.');
console.log('🔧 May need to restart Docker container to pick up latest changes.');
} else {
console.log('❌ ISSUE: Enhanced features not detected in safe paper trading.');
console.log('🔧 Need to investigate API integration.');
}
} else {
const errorText = await apiResponse.text();
console.log(`❌ API Error: ${apiResponse.status} - ${errorText}`);
console.log('🔧 This could indicate Docker container needs restart or API issue.');
}
} else {
console.log('❌ Docker environment not responding');
throw new Error('Docker not running');
}
} catch (fetchError) {
console.log('⚠️ Docker environment not accessible:', fetchError.message);
console.log('');
console.log('🐳 To test the enhanced safe paper trading:');
console.log('1. Start Docker: npm run docker:dev');
console.log('2. Wait for full startup (may take 1-2 minutes)');
console.log('3. Open: http://localhost:9001/safe-paper-trading');
console.log('4. Click "🛡️ Start Safe Paper Analysis"');
console.log('5. Look for enhanced features in the analysis results');
}
console.log('\n🎓 Expected Enhanced Features in Safe Paper Trading:');
console.log('====================================================');
console.log('• Execution zones instead of single entry prices');
console.log('• Slippage buffer calculations');
console.log('• Timeframe-based leverage recommendations');
console.log('• Detailed indicator expectations (RSI, MACD, VWAP, OBV)');
console.log('• Pre-filled journal templates for trade tracking');
console.log('• Scenario management (invalidation rules, alternatives)');
console.log('• Psychology coaching reminders');
console.log('• Professional trading desk language');
console.log('\n📋 User Experience Improvements:');
console.log('=================================');
console.log('• More precise and actionable trade setups');
console.log('• Complete risk management guidance');
console.log('• Professional execution instructions');
console.log('• Educational value for learning trading');
console.log('• Confidence building through detailed analysis');
} catch (error) {
console.error('❌ Test failed:', error.message);
console.error('Full error:', error);
}
}
// Run the test
testSafePaperTradingEnhancement();