diff --git a/lib/ai-analysis.ts b/lib/ai-analysis.ts index 2acc651..ad35a77 100644 --- a/lib/ai-analysis.ts +++ b/lib/ai-analysis.ts @@ -184,16 +184,22 @@ Be concise but thorough. Only return valid JSON.` throw new Error('No content received from OpenAI') } + console.log('AI response content:', content) + // Parse the JSON response const jsonMatch = content.match(/\{[\s\S]*\}/) if (!jsonMatch) { + console.error('No JSON found in response. Full content:', content) throw new Error('No JSON found in response') } + console.log('Extracted JSON:', jsonMatch[0]) + const analysis = JSON.parse(jsonMatch[0]) // Validate the structure if (!analysis.summary || !analysis.marketSentiment || !analysis.recommendation || !analysis.confidence) { + console.error('Invalid analysis structure:', analysis) throw new Error('Invalid analysis structure') } diff --git a/lib/tradingview.ts b/lib/tradingview.ts index fe6624f..96c84e8 100644 --- a/lib/tradingview.ts +++ b/lib/tradingview.ts @@ -260,6 +260,8 @@ export class TradingViewCapture { if (!loggedInCheck) { console.log('Not properly logged in, re-authenticating...') + // Reset login state and force re-authentication + this.loggedIn = false await this.login() // Try navigating to the layout URL again @@ -283,6 +285,15 @@ export class TradingViewCapture { } await page.goto(baseUrl, { waitUntil: 'networkidle2', timeout: 60000 }) } + } else { + console.log('User menu found but still getting restriction - layout may be private') + // Even though we're logged in, the layout is restricted, use base chart + console.log(`Layout "${layout}" is private or not accessible, falling back to base chart`) + let baseUrl = `https://www.tradingview.com/chart/?symbol=${finalSymbol}` + if (finalTimeframe) { + baseUrl += `&interval=${encodeURIComponent(finalTimeframe)}` + } + await page.goto(baseUrl, { waitUntil: 'networkidle2', timeout: 60000 }) } }