Integrate superior parallel screenshot system into main automation
BREAKING CHANGES: - Replace enhancedScreenshotService with superiorScreenshotService throughout system - Update trading presets to match actual strategy definitions: * Scalp: 5m, 15m (was 7 timeframes) * Day Trading: 1h, 4h (NEW) * Swing Trading: 4h, 1D (NEW) * Extended: All timeframes for comprehensive analysis - Auto-trading service now uses intelligent parallel capture - Enhanced-screenshot API restored with superior backend - AI analysis service updated for compatibility - Superior screenshot API supports all presets PERFORMANCE IMPROVEMENTS: - Parallel capture for ALL timeframes regardless of count - Intelligent preset detection based on timeframe patterns - No more hardcoded 7-timeframe limitation - Backwards compatibility maintained The system now uses the superior parallel approach for ANY timeframe selection, whether it's 2 timeframes (scalp/day/swing) or 8+ timeframes (extended). No more sequential delays - everything is parallel!
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { enhancedScreenshotService } from './enhanced-screenshot-robust'
|
||||
import { superiorScreenshotService } from './superior-screenshot-service'
|
||||
import { aiAnalysisService } from './ai-analysis'
|
||||
import { automatedCleanupService } from './automated-cleanup-service'
|
||||
import aggressiveCleanup from './aggressive-cleanup'
|
||||
@@ -69,7 +69,7 @@ export class AutoTradingService {
|
||||
|
||||
// Force cleanup all browser sessions
|
||||
try {
|
||||
await enhancedScreenshotService.cleanup()
|
||||
await superiorScreenshotService.cleanup()
|
||||
await aggressiveCleanup.forceCleanup()
|
||||
console.log('✅ Trading service stopped and cleaned up')
|
||||
} catch (cleanupError) {
|
||||
@@ -80,60 +80,103 @@ export class AutoTradingService {
|
||||
private async runTradingCycle(config: TradingConfig): Promise<void> {
|
||||
console.log(`🔄 Running trading cycle ${this.currentCycle}...`)
|
||||
|
||||
// Process each timeframe sequentially to avoid resource conflicts
|
||||
for (const timeframe of config.timeframes) {
|
||||
if (!this.isRunning) break // Check if service was stopped
|
||||
try {
|
||||
console.log(`\n📊 Processing ${config.symbol} with ${config.timeframes.length} timeframes...`)
|
||||
|
||||
try {
|
||||
console.log(`\n📊 Processing ${config.symbol} ${timeframe}...`)
|
||||
|
||||
// Capture screenshots with robust cleanup
|
||||
const screenshots = await enhancedScreenshotService.captureWithLogin({
|
||||
symbol: config.symbol,
|
||||
timeframe: timeframe,
|
||||
layouts: config.layouts,
|
||||
analyze: false // We'll analyze separately
|
||||
})
|
||||
// Determine trading strategy based on timeframes for intelligent parallel capture
|
||||
const timeframeSet = new Set(config.timeframes)
|
||||
let preset: 'scalp' | 'day-trading' | 'swing-trading' | 'custom' = 'custom'
|
||||
|
||||
// Detect strategy based on timeframe patterns
|
||||
if (timeframeSet.has('5') && timeframeSet.has('15') && config.timeframes.length === 2) {
|
||||
preset = 'scalp'
|
||||
console.log('🎯 Detected: SCALP trading strategy')
|
||||
} else if (timeframeSet.has('60') && timeframeSet.has('240') && config.timeframes.length === 2) {
|
||||
preset = 'day-trading'
|
||||
console.log('🎯 Detected: DAY TRADING strategy')
|
||||
} else if (timeframeSet.has('240') && timeframeSet.has('1D') && config.timeframes.length === 2) {
|
||||
preset = 'swing-trading'
|
||||
console.log('🎯 Detected: SWING TRADING strategy')
|
||||
} else {
|
||||
preset = 'custom'
|
||||
console.log('🎯 Using: CUSTOM timeframe configuration')
|
||||
}
|
||||
|
||||
if (screenshots.length > 0) {
|
||||
console.log(`✅ Captured ${screenshots.length} screenshots for ${timeframe}`)
|
||||
// Capture screenshots using superior parallel technique
|
||||
let screenshots: any[] = []
|
||||
let allResults: any[] = []
|
||||
|
||||
if (preset === 'custom') {
|
||||
// Custom timeframes - use parallel capture with custom preset
|
||||
console.log('🚀 Using superior parallel capture with custom timeframes...')
|
||||
allResults = await superiorScreenshotService.captureParallel({
|
||||
symbol: config.symbol,
|
||||
preset: 'custom',
|
||||
timeframes: config.timeframes,
|
||||
layouts: config.layouts,
|
||||
analyze: false
|
||||
})
|
||||
} else {
|
||||
// Standard preset - use optimized preset method
|
||||
console.log(`🚀 Using superior parallel capture with ${preset} preset...`)
|
||||
allResults = await superiorScreenshotService.captureParallel({
|
||||
symbol: config.symbol,
|
||||
preset: preset,
|
||||
layouts: config.layouts,
|
||||
analyze: false
|
||||
})
|
||||
}
|
||||
|
||||
// Extract successful screenshots for analysis
|
||||
screenshots = allResults
|
||||
.filter(result => result.success && result.screenshots)
|
||||
.flatMap(result => result.screenshots || [])
|
||||
|
||||
if (screenshots.length > 0) {
|
||||
console.log(`✅ Superior parallel capture completed: ${screenshots.length} screenshots`)
|
||||
|
||||
// Process results by timeframe for detailed analysis
|
||||
for (const result of allResults) {
|
||||
if (!result.success) {
|
||||
console.error(`❌ Failed to capture ${result.timeframeName}: ${result.error}`)
|
||||
continue
|
||||
}
|
||||
|
||||
// Analyze screenshots
|
||||
if (!result.screenshots || result.screenshots.length === 0) {
|
||||
console.warn(`⚠️ No screenshots for ${result.timeframeName}`)
|
||||
continue
|
||||
}
|
||||
|
||||
try {
|
||||
console.log(`\n🤖 Analyzing ${result.timeframeName} (${result.screenshots.length} screenshots)...`)
|
||||
|
||||
let analysis = null
|
||||
if (screenshots.length === 1) {
|
||||
analysis = await aiAnalysisService.analyzeScreenshot(screenshots[0])
|
||||
} else if (screenshots.length > 1) {
|
||||
analysis = await aiAnalysisService.analyzeMultipleScreenshots(screenshots)
|
||||
if (result.screenshots.length === 1) {
|
||||
analysis = await aiAnalysisService.analyzeScreenshot(result.screenshots[0])
|
||||
} else if (result.screenshots.length > 1) {
|
||||
analysis = await aiAnalysisService.analyzeMultipleScreenshots(result.screenshots)
|
||||
}
|
||||
|
||||
if (analysis) {
|
||||
console.log(`✅ Analysis completed for ${timeframe}`)
|
||||
console.log(`✅ Analysis completed for ${result.timeframeName}`)
|
||||
console.log(`📈 Sentiment: ${analysis.marketSentiment || 'Unknown'}`)
|
||||
console.log(`🎯 Recommendation: ${analysis.recommendation}, Confidence: ${analysis.confidence}%`)
|
||||
|
||||
// Here you would implement your trading logic based on analysis
|
||||
await this.processAnalysisForTrading(analysis, config.symbol, timeframe)
|
||||
// Process trading logic based on analysis
|
||||
await this.processAnalysisForTrading(analysis, config.symbol, result.timeframeName)
|
||||
} else {
|
||||
console.warn(`⚠️ No analysis returned for ${timeframe}`)
|
||||
console.warn(`⚠️ No analysis returned for ${result.timeframeName}`)
|
||||
}
|
||||
} catch (analysisError) {
|
||||
console.error(`❌ Analysis failed for ${timeframe}:`, analysisError)
|
||||
console.error(`❌ Analysis failed for ${result.timeframeName}:`, analysisError)
|
||||
}
|
||||
} else {
|
||||
console.error(`❌ No screenshots captured for ${timeframe}`)
|
||||
}
|
||||
|
||||
// Small delay between timeframes to prevent overwhelming the system
|
||||
if (config.timeframes.indexOf(timeframe) < config.timeframes.length - 1) {
|
||||
console.log('⏳ Brief pause before next timeframe...')
|
||||
await new Promise(resolve => setTimeout(resolve, 5000))
|
||||
}
|
||||
|
||||
} catch (error) {
|
||||
console.error(`❌ Error processing ${timeframe}:`, error)
|
||||
// Continue with next timeframe even if one fails
|
||||
} else {
|
||||
console.error(`❌ No screenshots captured using superior parallel technique`)
|
||||
}
|
||||
|
||||
} catch (error) {
|
||||
console.error(`❌ Error in trading cycle:`, error)
|
||||
}
|
||||
|
||||
console.log(`✅ Trading cycle ${this.currentCycle} completed`)
|
||||
|
||||
Reference in New Issue
Block a user