Fix timeframe selection bug and syntax errors

- Fixed critical timeframe mapping bug where '4h' was interpreted as '4 minutes'
- Now prioritizes minute values: '4h' -> ['240', '240m', '4h', '4H']
- Added fallback mechanism to enter exact minutes (240) in custom interval input
- Fixed multiple syntax errors in tradingview-automation.ts:
  * Missing closing parentheses in console.log statements
  * Missing parentheses in writeFile and JSON.parse calls
  * Fixed import statements for fs and path modules
  * Added missing utility methods (fileExists, markCaptchaDetected, etc.)
- Enhanced timeframe selection with comprehensive hour mappings (1h, 2h, 4h, 6h, 12h)
- Added detailed logging for debugging timeframe selection
- Application now builds successfully without syntax errors
- Interval selection should work correctly for all common timeframes

Key improvements:
 4h chart selection now works correctly (240 minutes, not 4 minutes)
 All TypeScript compilation errors resolved
 Enhanced debugging output for timeframe mapping
 Robust fallback mechanisms for interval selection
 Docker integration and manual CAPTCHA handling maintained
This commit is contained in:
mindesbunister
2025-07-13 13:57:35 +02:00
parent 19d4020622
commit b91d35ad60
17 changed files with 1218 additions and 143 deletions

View File

@@ -28,9 +28,6 @@ export class EnhancedScreenshotService {
console.log('Initializing TradingView automation for Docker container...')
// Ensure browser is healthy before operations
await tradingViewAutomation.ensureBrowserReady()
// Initialize automation with Docker-optimized settings
await tradingViewAutomation.init()
@@ -74,7 +71,61 @@ export class EnhancedScreenshotService {
}
console.log(`Navigating to ${config.symbol} chart...`)
const navSuccess = await tradingViewAutomation.navigateToChart(navOptions)
// Add retry logic for navigation in case of browser state issues
let navSuccess = false
let retryCount = 0
const maxRetries = 2
while (!navSuccess && retryCount < maxRetries) {
try {
navSuccess = await tradingViewAutomation.navigateToChart(navOptions)
if (!navSuccess) {
console.log(`Navigation attempt ${retryCount + 1} failed, retrying...`)
retryCount++
if (retryCount < maxRetries) {
// Wait before retry
await new Promise(resolve => setTimeout(resolve, 3000))
// Reinitialize if needed
await tradingViewAutomation.init()
// Check if we need to re-authenticate after reinitialization
const stillLoggedIn = await tradingViewAutomation.isLoggedIn()
if (!stillLoggedIn) {
console.log('🔐 Re-authentication required after browser reinitialization...')
const reAuthSuccess = await tradingViewAutomation.smartLogin(config.credentials)
if (!reAuthSuccess) {
throw new Error('Re-authentication failed after browser reinitialization')
}
}
}
}
} catch (error: any) {
console.log(`Navigation error on attempt ${retryCount + 1}:`, error.message)
retryCount++
if (retryCount < maxRetries) {
console.log('Reinitializing browser and retrying...')
await new Promise(resolve => setTimeout(resolve, 3000))
await tradingViewAutomation.init()
// Check if we need to re-authenticate after reinitialization
const stillLoggedIn = await tradingViewAutomation.isLoggedIn()
if (!stillLoggedIn) {
console.log('🔐 Re-authentication required after browser reinitialization...')
const reAuthSuccess = await tradingViewAutomation.smartLogin(config.credentials)
if (!reAuthSuccess) {
throw new Error('Re-authentication failed after browser reinitialization')
}
}
} else {
throw error
}
}
}
if (!navSuccess) {
throw new Error('Chart navigation failed')