Remove demo data fallbacks - use only real Drift account data
- Updated Dashboard.tsx to remove demo data fallbacks - Updated TradingHistory.tsx to use new Drift trading history endpoint - Added getTradingHistory method to DriftTradingService - Created new /api/drift/trading-history endpoint - Removed fallback demo positions from getPositions method - All UI components now show only real Drift account data or empty states - No more hardcoded mock trades or positions
This commit is contained in:
@@ -695,7 +695,7 @@ export class TradingViewAutomation {
|
||||
const text = await button.textContent() || ''
|
||||
const trimmedText = text.trim().toLowerCase()
|
||||
|
||||
console.log(`📝 Button ${i + 1}: "${trimmedText}"`)
|
||||
console.log(`📝
|
||||
|
||||
if (trimmedText.includes('email') ||
|
||||
trimmedText.includes('continue with email') ||
|
||||
@@ -877,21 +877,30 @@ export class TradingViewAutomation {
|
||||
// Handle potential captcha
|
||||
console.log('🤖 Checking for captcha...')
|
||||
try {
|
||||
// Look for different types of captcha
|
||||
// Look for different types of captcha and robot confirmation
|
||||
const captchaSelectors = [
|
||||
'iframe[src*="recaptcha"]',
|
||||
'iframe[src*="captcha"]',
|
||||
'.recaptcha-checkbox',
|
||||
'[data-testid="captcha"]',
|
||||
'.captcha-container'
|
||||
'.captcha-container',
|
||||
'text="Please confirm that you are not a robot"',
|
||||
'text="Are you human?"',
|
||||
'text="Please verify you are human"',
|
||||
'text="Security check"',
|
||||
'.tv-dialog__error:has-text("robot")',
|
||||
'.alert:has-text("robot")',
|
||||
'.error:has-text("robot")'
|
||||
]
|
||||
|
||||
let captchaFound = false
|
||||
let captchaType = ''
|
||||
for (const selector of captchaSelectors) {
|
||||
try {
|
||||
if (await this.page.locator(selector).isVisible({ timeout: 2000 })) {
|
||||
console.log(`🤖 Captcha detected: ${selector}`)
|
||||
console.log(`🤖 Captcha/Robot check detected: ${selector}`)
|
||||
captchaFound = true
|
||||
captchaType = selector
|
||||
break
|
||||
}
|
||||
} catch (e) {
|
||||
@@ -900,15 +909,32 @@ export class TradingViewAutomation {
|
||||
}
|
||||
|
||||
if (captchaFound) {
|
||||
console.log('⚠️ Captcha detected - this requires manual intervention')
|
||||
console.log('🖱️ Please solve the captcha manually within 30 seconds...')
|
||||
console.log('⚠️ CAPTCHA/Robot verification detected!')
|
||||
console.log('🚫 This indicates TradingView has flagged this as automated behavior.')
|
||||
console.log('<27> In a Docker environment, automated captcha solving is not feasible.')
|
||||
|
||||
// Wait for captcha to be solved
|
||||
await this.page.waitForTimeout(30000)
|
||||
console.log('⏳ Proceeding after captcha wait period')
|
||||
// Take a screenshot for debugging
|
||||
await this.takeDebugScreenshot('captcha_detected')
|
||||
|
||||
// Instead of waiting, we should fail fast and suggest alternatives
|
||||
console.log('❌ Cannot proceed with automated login due to captcha protection.')
|
||||
console.log('🔧 Possible solutions:')
|
||||
console.log(' 1. Use a different IP address or VPN')
|
||||
console.log(' 2. Wait some time before retrying (rate limiting)')
|
||||
console.log(' 3. Use session persistence from a manually authenticated browser')
|
||||
console.log(' 4. Contact TradingView support if this persists')
|
||||
|
||||
// Mark captcha detection for future reference
|
||||
await this.markCaptchaDetected()
|
||||
|
||||
// Return false immediately instead of waiting
|
||||
throw new Error(`Captcha detected (${captchaType}) - automated login blocked`)
|
||||
}
|
||||
|
||||
} catch (captchaError: any) {
|
||||
if (captchaError.message.includes('Captcha detected')) {
|
||||
throw captchaError
|
||||
}
|
||||
console.log('⚠️ Captcha check failed:', captchaError?.message)
|
||||
}
|
||||
|
||||
@@ -1106,17 +1132,64 @@ export class TradingViewAutomation {
|
||||
return true
|
||||
}
|
||||
|
||||
console.log('🔐 Not logged in, starting automated login process...')
|
||||
console.log('🔐 Not logged in, checking session persistence options...')
|
||||
|
||||
// Try automated login first
|
||||
// Before attempting login, check if we have any saved session data
|
||||
const sessionInfo = await this.testSessionPersistence()
|
||||
console.log('📊 Session persistence check:', sessionInfo)
|
||||
|
||||
if (sessionInfo.cookiesCount > 0) {
|
||||
console.log('🍪 Found saved session data, attempting to restore...')
|
||||
|
||||
// Try navigating to TradingView with saved session first
|
||||
try {
|
||||
await this.page.goto('https://www.tradingview.com/', {
|
||||
waitUntil: 'domcontentloaded',
|
||||
timeout: 30000
|
||||
})
|
||||
|
||||
// Restore session storage after navigation
|
||||
await this.restoreSessionStorage()
|
||||
|
||||
// Wait for page to settle and check login status
|
||||
await this.page.waitForTimeout(5000)
|
||||
|
||||
const nowLoggedIn = await this.checkLoginStatus()
|
||||
if (nowLoggedIn) {
|
||||
console.log('✅ Session restoration successful! Login confirmed.')
|
||||
this.isAuthenticated = true
|
||||
await this.saveSession()
|
||||
return true
|
||||
} else {
|
||||
console.log('⚠️ Session restoration failed, saved session may be expired')
|
||||
}
|
||||
} catch (e) {
|
||||
console.log('❌ Session restoration attempt failed:', e)
|
||||
}
|
||||
}
|
||||
|
||||
// Only attempt automated login if we don't have valid session data
|
||||
console.log('🤖 Attempting automated login...')
|
||||
const autoLoginSuccess = await this.login(credentials)
|
||||
|
||||
if (autoLoginSuccess) {
|
||||
console.log('✅ Automated login successful! Saving session for future use.')
|
||||
this.isAuthenticated = true
|
||||
await this.saveSession()
|
||||
return true
|
||||
try {
|
||||
const autoLoginSuccess = await this.login(credentials)
|
||||
|
||||
if (autoLoginSuccess) {
|
||||
console.log('✅ Automated login successful! Saving session for future use.')
|
||||
this.isAuthenticated = true
|
||||
await this.saveSession()
|
||||
return true
|
||||
}
|
||||
} catch (loginError: any) {
|
||||
if (loginError.message.includes('Captcha detected')) {
|
||||
console.log('🚫 Captcha protection encountered during automated login.')
|
||||
console.log('💡 To resolve this issue:')
|
||||
console.log(' 1. Clear any existing session data: docker-compose exec app rm -f /app/session_*.json')
|
||||
console.log(' 2. Wait 1-2 hours before retrying (to clear rate limiting)')
|
||||
console.log(' 3. Consider using a different IP address or VPN')
|
||||
console.log(' 4. Manually log in to TradingView in a browser to establish a valid session')
|
||||
return false
|
||||
}
|
||||
throw loginError
|
||||
}
|
||||
|
||||
console.log('❌ Automated login failed, this is likely due to captcha protection.')
|
||||
@@ -2193,6 +2266,34 @@ export class TradingViewAutomation {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Mark that a captcha was detected (to implement cooldown)
|
||||
*/
|
||||
private async markCaptchaDetected(): Promise<void> {
|
||||
try {
|
||||
const captchaMarkerFile = path.join(process.cwd(), 'captcha_detected.json')
|
||||
const markerData = {
|
||||
timestamp: new Date().toISOString(),
|
||||
count: 1
|
||||
}
|
||||
|
||||
// If marker already exists, increment count
|
||||
if (await this.fileExists(captchaMarkerFile)) {
|
||||
try {
|
||||
const existing = JSON.parse(await fs.readFile(captchaMarkerFile, 'utf8'))
|
||||
markerData.count = (existing.count || 0) + 1
|
||||
} catch (e) {
|
||||
// Use defaults if can't read existing file
|
||||
}
|
||||
}
|
||||
|
||||
await fs.writeFile(captchaMarkerFile, JSON.stringify(markerData, null, 2))
|
||||
console.log(`📝 Marked captcha detection #${markerData.count} at ${markerData.timestamp}`)
|
||||
} catch (error) {
|
||||
console.log('⚠️ Error marking captcha detection:', error)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if file exists
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user