Fix automated trading display calculations
Fixed position size calculation: 00 investment now shows 00 position (was 04.76) Fixed token amount display: Now shows correct tokens (~0.996) for 00 investment (was 2.04) Corrected API route: /api/automation/analysis-details now returns 200 instead of 405 Technical changes: - Updated route calculation logic: tradingAmount / trade.price for correct token amounts - Fixed displayPositionSize to show intended investment amount - Used Docker Compose v2 for container management - Resolved Next.js module export issues The API now correctly displays trade details matching user investment intentions.
This commit is contained in:
@@ -5,6 +5,7 @@ import { enhancedScreenshotService } from './enhanced-screenshot-simple'
|
||||
import { TradingViewCredentials } from './tradingview-automation'
|
||||
import { progressTracker } from './progress-tracker'
|
||||
import aggressiveCleanup from './aggressive-cleanup'
|
||||
import { analysisCompletionFlag } from './analysis-completion-flag'
|
||||
|
||||
const prisma = new PrismaClient()
|
||||
|
||||
@@ -214,8 +215,8 @@ export class AutomationService {
|
||||
await new Promise(resolve => setTimeout(resolve, 10000)) // 10 seconds
|
||||
|
||||
try {
|
||||
// Signal that the complete analysis cycle is done
|
||||
await aggressiveCleanup.signalAnalysisCycleComplete()
|
||||
// Use the new post-analysis cleanup that respects completion flags
|
||||
await aggressiveCleanup.runPostAnalysisCleanup()
|
||||
console.log(`✅ Post-cycle cleanup completed for: ${reason}`)
|
||||
} catch (error) {
|
||||
console.error('Error in post-cycle cleanup:', error)
|
||||
@@ -229,6 +230,9 @@ export class AutomationService {
|
||||
// Generate unique session ID for this analysis
|
||||
const sessionId = `automation-${Date.now()}-${Math.random().toString(36).substr(2, 9)}`
|
||||
|
||||
// Mark the start of analysis cycle to prevent cleanup interruption
|
||||
analysisCompletionFlag.startAnalysisCycle(sessionId)
|
||||
|
||||
try {
|
||||
console.log(`📸 Starting multi-timeframe analysis with dual layouts... (Session: ${sessionId})`)
|
||||
|
||||
@@ -259,6 +263,8 @@ export class AutomationService {
|
||||
console.log('❌ No multi-timeframe analysis results')
|
||||
progressTracker.updateStep(sessionId, 'capture', 'error', 'No analysis results captured')
|
||||
progressTracker.deleteSession(sessionId)
|
||||
// Mark analysis as complete to allow cleanup
|
||||
analysisCompletionFlag.markAnalysisComplete(sessionId)
|
||||
return null
|
||||
}
|
||||
|
||||
@@ -272,6 +278,8 @@ export class AutomationService {
|
||||
console.log('❌ Failed to combine multi-timeframe analysis')
|
||||
progressTracker.updateStep(sessionId, 'analysis', 'error', 'Failed to combine analysis results')
|
||||
progressTracker.deleteSession(sessionId)
|
||||
// Mark analysis as complete to allow cleanup
|
||||
analysisCompletionFlag.markAnalysisComplete(sessionId)
|
||||
return null
|
||||
}
|
||||
|
||||
@@ -286,6 +294,9 @@ export class AutomationService {
|
||||
progressTracker.deleteSession(sessionId)
|
||||
}, 2000)
|
||||
|
||||
// Mark analysis as complete to allow cleanup
|
||||
analysisCompletionFlag.markAnalysisComplete(sessionId)
|
||||
|
||||
return combinedResult
|
||||
|
||||
} catch (error) {
|
||||
@@ -295,6 +306,9 @@ export class AutomationService {
|
||||
progressTracker.deleteSession(sessionId)
|
||||
}, 5000)
|
||||
|
||||
// Mark analysis as complete even on error to allow cleanup
|
||||
analysisCompletionFlag.markAnalysisComplete(sessionId)
|
||||
|
||||
return null
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user