fix: Remove all hardcoded timeframe references in automation service
- Replace hardcoded timeframes array ['15', '1h', '2h', '4h'] with dynamic selectedTimeframes - Fix hardcoded '1h' references in primary timeframe selection - Update recommendation messages to use dynamic primaryTimeframe - Ensure scalping selection (5,15,30m) is properly respected by automation service - All timeframe logic now uses selectedTimeframes from UI configuration
This commit is contained in:
@@ -15,6 +15,7 @@ export interface AutomationConfig {
|
||||
mode: 'SIMULATION' | 'LIVE'
|
||||
symbol: string
|
||||
timeframe: string
|
||||
selectedTimeframes?: string[] // Multi-timeframe support from UI
|
||||
tradingAmount: number
|
||||
maxLeverage: number
|
||||
// stopLossPercent and takeProfitPercent removed - AI calculates these automatically
|
||||
@@ -271,8 +272,8 @@ export class AutomationService {
|
||||
progressTracker.createSession(sessionId, progressSteps)
|
||||
progressTracker.updateStep(sessionId, 'init', 'active', 'Starting multi-timeframe analysis...')
|
||||
|
||||
// Multi-timeframe analysis: 15m, 1h, 2h, 4h
|
||||
const timeframes = ['15', '1h', '2h', '4h']
|
||||
// Use selected timeframes from UI, fallback to default if not provided
|
||||
const timeframes = this.config!.selectedTimeframes || ['1h']
|
||||
const symbol = this.config!.symbol
|
||||
|
||||
console.log(`🔍 Analyzing ${symbol} across timeframes: ${timeframes.join(', ')} with AI + DIY layouts`)
|
||||
@@ -404,8 +405,10 @@ export class AutomationService {
|
||||
return { screenshots: [], analysis: null }
|
||||
}
|
||||
|
||||
// Get the primary timeframe (1h) as base
|
||||
const primaryResult = validResults.find(r => r.timeframe === '1h') || validResults[0]
|
||||
// Get the primary timeframe (first selected or default) as base
|
||||
const selectedTimeframes = this.config!.selectedTimeframes || ['1h']
|
||||
const primaryTimeframe = selectedTimeframes[0] || '1h'
|
||||
const primaryResult = validResults.find(r => r.timeframe === primaryTimeframe) || validResults[0]
|
||||
const screenshots = validResults.length > 0 ? [primaryResult.timeframe] : []
|
||||
|
||||
// Calculate weighted confidence based on timeframe alignment
|
||||
@@ -478,8 +481,10 @@ ${validResults.map(r => `• ${r.timeframe}: ${r.analysis?.recommendation} (${r.
|
||||
const allLevels = results.map(r => r.analysis?.keyLevels).filter(Boolean)
|
||||
if (allLevels.length === 0) return {}
|
||||
|
||||
// Use the 1h timeframe levels as primary, or first available
|
||||
const primaryLevels = results.find(r => r.timeframe === '1h')?.analysis?.keyLevels || allLevels[0]
|
||||
// Use the primary timeframe levels (first selected) as primary, or first available
|
||||
const selectedTimeframes = this.config!.selectedTimeframes || ['1h']
|
||||
const primaryTimeframe = selectedTimeframes[0] || '1h'
|
||||
const primaryLevels = results.find(r => r.timeframe === primaryTimeframe)?.analysis?.keyLevels || allLevels[0]
|
||||
|
||||
return {
|
||||
...primaryLevels,
|
||||
@@ -491,8 +496,10 @@ ${validResults.map(r => `• ${r.timeframe}: ${r.analysis?.recommendation} (${r.
|
||||
const sentiments = results.map(r => r.analysis?.marketSentiment).filter(Boolean)
|
||||
if (sentiments.length === 0) return 'NEUTRAL'
|
||||
|
||||
// Use the 1h timeframe sentiment as primary, or first available
|
||||
const primarySentiment = results.find(r => r.timeframe === '1h')?.analysis?.marketSentiment || sentiments[0]
|
||||
// Use the primary timeframe sentiment (first selected) as primary, or first available
|
||||
const selectedTimeframes = this.config!.selectedTimeframes || ['1h']
|
||||
const primaryTimeframe = selectedTimeframes[0] || '1h'
|
||||
const primarySentiment = results.find(r => r.timeframe === primaryTimeframe)?.analysis?.marketSentiment || sentiments[0]
|
||||
|
||||
return primarySentiment || 'NEUTRAL'
|
||||
}
|
||||
@@ -1191,11 +1198,14 @@ ${validResults.map(r => `• ${r.timeframe}: ${r.analysis?.recommendation} (${r.
|
||||
recommendations: string[]
|
||||
}> {
|
||||
try {
|
||||
// For now, return mock data
|
||||
// For now, return mock data with dynamic timeframe
|
||||
const selectedTimeframes = this.config?.selectedTimeframes || ['1h']
|
||||
const primaryTimeframe = selectedTimeframes[0] || '1h'
|
||||
|
||||
return {
|
||||
totalAnalyses: 150,
|
||||
avgAccuracy: 0.72,
|
||||
bestTimeframe: '1h',
|
||||
bestTimeframe: primaryTimeframe,
|
||||
worstTimeframe: '15m',
|
||||
commonFailures: [
|
||||
'Low confidence predictions',
|
||||
@@ -1203,7 +1213,7 @@ ${validResults.map(r => `• ${r.timeframe}: ${r.analysis?.recommendation} (${r.
|
||||
'Timeframe misalignment'
|
||||
],
|
||||
recommendations: [
|
||||
'Focus on 1h timeframe for better accuracy',
|
||||
`Focus on ${primaryTimeframe} timeframe for better accuracy`,
|
||||
'Wait for higher confidence signals (>75%)',
|
||||
'Use multiple timeframe confirmation'
|
||||
]
|
||||
|
||||
Reference in New Issue
Block a user