Compare commits

...

2 Commits

Author SHA1 Message Date
mindesbunister
525da07948 Replace Unicode coin symbols with proper CoinGecko coin icons
- Replace ₿, Ξ, ◎ symbols with actual coin logos from CoinGecko CDN
- Update Bitcoin, Ethereum, and Solana icons across StatusOverview component
- Improve visual appeal and professional appearance of wallet balance, available coins, and market price sections
- Use 24x24px rounded coin images for better UI consistency
2025-07-17 11:46:28 +02:00
mindesbunister
32b1c1a54d Clean up homepage: remove hero section and quick action icons
- Remove 'AI Trading Dashboard' title and description text
- Remove grid of quick action cards (AI Analysis, Trading, etc.)
- Keep only StatusOverview component for cleaner interface
- Update .github/copilot-instructions.md with comprehensive AI agent guidance
2025-07-17 11:33:10 +02:00
3 changed files with 259 additions and 198 deletions

View File

@@ -1,3 +1,104 @@
<!-- Use this file to provide workspace-specific custom instructions to Copilot. For more details, visit https://code.visualstudio.com/docs/copilot/copilot-customization#_use-a-githubcopilotinstructionsmd-file -->
This project is a Next.js 15 App Router application with TypeScript, Tailwind CSS, Prisma, and API routes. It is a trading bot dashboard with AI-powered analysis, auto-trading, trade execution, screenshot capture, and developer settings. Please generate code that is idiomatic for this stack and follows best practices for modern Next.js apps.
# AI-Powered Trading Bot Dashboard
This is a Next.js 15 App Router application with TypeScript, Tailwind CSS, and API routes. It's a production-ready trading bot with AI analysis, automated screenshot capture, and real-time trading execution via Drift Protocol and Jupiter DEX.
## Core Architecture
### Dual-Session Screenshot Automation
- **AI Layout**: `Z1TzpUrf` - RSI (top), EMAs, MACD (bottom)
- **DIY Layout**: `vWVvjLhP` - Stochastic RSI (top), VWAP, OBV (bottom)
- Parallel browser sessions for multi-layout capture in `lib/enhanced-screenshot.ts`
- TradingView automation with session persistence in `lib/tradingview-automation.ts`
### AI Analysis Pipeline
- OpenAI GPT-4o mini for cost-effective chart analysis (~$0.006 per analysis)
- Multi-layout comparison and consensus detection
- Professional trading setups with exact entry/exit levels and risk management
- Layout-specific indicator analysis (RSI vs Stochastic RSI, MACD vs OBV)
### Trading Integration
- **Drift Protocol**: Perpetual futures trading via `@drift-labs/sdk`
- **Jupiter DEX**: Spot trading on Solana
- Position management and P&L tracking
- Real-time account balance and collateral monitoring
## Critical Development Patterns
### Docker Environment
Use Docker for consistency: `npm run docker:dev` (port 9001) or `npm run docker:up` (port 9000)
- Multi-stage builds with browser automation optimizations
- Session persistence via volume mounts
- Chromium path: `/usr/bin/chromium`
### API Route Structure
```typescript
// Enhanced screenshot with progress tracking
POST /api/enhanced-screenshot
{
symbol: "SOLUSD",
timeframe: "240",
layouts: ["ai", "diy"],
analyze: true
}
// Returns: { screenshots, analysis, sessionId }
```
### Progress Tracking System
- `lib/progress-tracker.ts` manages real-time analysis progress
- SessionId-based tracking for multi-step operations
- Steps: init → auth → navigation → loading → capture → analysis
### Timeframe Mapping
Critical: Always use minute values first to avoid TradingView confusion
```typescript
'4h': ['240', '240m', '4h', '4H'] // 240 minutes FIRST, not "4h"
'1h': ['60', '60m', '1h', '1H'] // 60 minutes FIRST
```
### Component Architecture
- `components/AIAnalysisPanel.tsx` - Multi-timeframe analysis interface
- `components/Dashboard.tsx` - Main trading dashboard with real Drift positions
- `components/AdvancedTradingPanel.tsx` - Drift Protocol trading interface
- Layout: `app/layout.js` with gradient styling and navigation
## Environment Variables
```bash
OPENAI_API_KEY= # Required for AI analysis
TRADINGVIEW_EMAIL= # Required for automation
TRADINGVIEW_PASSWORD= # Required for automation
SOLANA_RPC_URL= # Drift trading
DRIFT_PRIVATE_KEY= # Drift trading (base58 encoded)
```
## Build & Development Commands
```bash
# Development (recommended)
npm run docker:dev # Port 9001, hot reload
npm run docker:logs # View container logs
npm run docker:exec # Shell access
# Production deployment
npm run docker:prod:up # Port 9000, optimized build
# Testing automation
node test-enhanced-screenshot.js # Test dual-session capture
./test-docker-comprehensive.sh # Full system test
```
## Code Style Guidelines
- Use `"use client"` for client components with state/effects
- Tailwind with gradient backgrounds and glassmorphism effects
- TypeScript interfaces for all trading parameters and API responses
- Error handling with detailed logging for browser automation
- Session persistence to avoid TradingView captchas
## Key Integration Points
- Session data: `.tradingview-session/` (volume mounted)
- Screenshots: `screenshots/` directory
- Progress tracking: EventEmitter-based real-time updates
- Database: Prisma with SQLite (file:./prisma/dev.db)
Generate code that follows these patterns and integrates seamlessly with the existing trading infrastructure.

View File

@@ -4,66 +4,9 @@ import StatusOverview from '../components/StatusOverview.js'
export default function HomePage() {
return (
<div className="space-y-8">
{/* Hero Section */}
<div className="text-center py-8">
<h1 className="text-4xl font-bold bg-gradient-to-r from-cyan-400 to-blue-600 bg-clip-text text-transparent mb-4">
AI Trading Dashboard
</h1>
<p className="text-gray-400 text-lg max-w-2xl mx-auto">
Advanced cryptocurrency trading with AI-powered analysis, automated execution, and real-time monitoring.
</p>
</div>
<div>
{/* Status Overview */}
<StatusOverview />
{/* Quick Actions */}
<div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 gap-6">
<div className="card card-gradient text-center">
<div className="w-16 h-16 bg-blue-500/20 rounded-full flex items-center justify-center mx-auto mb-4">
<span className="text-blue-400 text-2xl">📊</span>
</div>
<h3 className="text-lg font-semibold text-white mb-2">AI Analysis</h3>
<p className="text-gray-400 text-sm mb-4">Get market insights and TradingView analysis</p>
<a href="/analysis" className="inline-flex items-center px-4 py-2 bg-blue-600/20 text-blue-400 rounded-lg hover:bg-blue-600/30 transition-colors text-sm">
View Analysis
</a>
</div>
<div className="card card-gradient text-center">
<div className="w-16 h-16 bg-green-500/20 rounded-full flex items-center justify-center mx-auto mb-4">
<span className="text-green-400 text-2xl">💰</span>
</div>
<h3 className="text-lg font-semibold text-white mb-2">Manual Trading</h3>
<p className="text-gray-400 text-sm mb-4">Execute trades and view history</p>
<a href="/trading" className="inline-flex items-center px-4 py-2 bg-green-600/20 text-green-400 rounded-lg hover:bg-green-600/30 transition-colors text-sm">
Trade Now
</a>
</div>
<div className="card card-gradient text-center">
<div className="w-16 h-16 bg-purple-500/20 rounded-full flex items-center justify-center mx-auto mb-4">
<span className="text-purple-400 text-2xl">🤖</span>
</div>
<h3 className="text-lg font-semibold text-white mb-2">Auto Trading</h3>
<p className="text-gray-400 text-sm mb-4">Configure automation</p>
<a href="/automation" className="inline-flex items-center px-4 py-2 bg-purple-600/20 text-purple-400 rounded-lg hover:bg-purple-600/30 transition-colors text-sm">
Setup Bot
</a>
</div>
<div className="card card-gradient text-center">
<div className="w-16 h-16 bg-orange-500/20 rounded-full flex items-center justify-center mx-auto mb-4">
<span className="text-orange-400 text-2xl"></span>
</div>
<h3 className="text-lg font-semibold text-white mb-2">Settings</h3>
<p className="text-gray-400 text-sm mb-4">Developer configuration</p>
<a href="/settings" className="inline-flex items-center px-4 py-2 bg-orange-600/20 text-orange-400 rounded-lg hover:bg-orange-600/30 transition-colors text-sm">
Configure
</a>
</div>
</div>
</div>
)
}

View File

@@ -3,17 +3,24 @@ import React, { useEffect, useState } from 'react'
export default function StatusOverview() {
const [status, setStatus] = useState({
driftBalance: 0,
portfolioValue: 0,
activeTrades: 0,
dailyPnL: 0,
systemStatus: 'offline',
bitqueryStatus: 'unknown',
marketPrices: [],
walletBalance: null, // Real wallet balance
availableCoins: [] // Available coins in wallet
walletBalance: null,
availableCoins: []
})
const [loading, setLoading] = useState(true)
// Coin icons mapping - using CoinGecko images
const coinIcons = {
'BTC': 'https://assets.coingecko.com/coins/images/1/large/bitcoin.png',
'ETH': 'https://assets.coingecko.com/coins/images/279/large/ethereum.png',
'SOL': 'https://assets.coingecko.com/coins/images/4128/large/solana.png',
'SOL-USD': 'https://assets.coingecko.com/coins/images/4128/large/solana.png'
}
useEffect(() => {
async function fetchStatus() {
try {
@@ -36,18 +43,18 @@ export default function StatusOverview() {
console.warn('Could not fetch wallet balance:', e)
}
// Get market data from Bitquery
let balance = walletBalance?.totalValue || 0 // Use real wallet balance
let bitqueryStatus = 'error'
// Get market data - only BTC, ETH, SOL
let marketPrices = []
try {
const marketRes = await fetch('/api/market')
if (marketRes.ok) {
const marketData = await marketRes.json()
if (marketData.success) {
marketPrices = marketData.data.prices || []
bitqueryStatus = marketData.data.status?.connected ? 'online' : 'error'
// Filter to only show BTC, ETH, SOL
const targetCoins = ['BTC', 'ETH', 'SOL']
marketPrices = (marketData.data.prices || [])
.filter(price => targetCoins.includes(price.symbol))
.sort((a, b) => targetCoins.indexOf(a.symbol) - targetCoins.indexOf(b.symbol))
}
}
} catch (e) {
@@ -66,11 +73,10 @@ export default function StatusOverview() {
}
setStatus({
driftBalance: balance,
activeTrades: 0, // No fake trades - will show real ones when we have them
dailyPnL: 0, // No fake P&L
portfolioValue: walletBalance?.totalValue || 0,
activeTrades: 0,
dailyPnL: 0,
systemStatus: systemStatus,
bitqueryStatus: bitqueryStatus,
marketPrices: marketPrices,
walletBalance: walletBalance,
availableCoins: availableCoins
@@ -100,154 +106,165 @@ export default function StatusOverview() {
error: '🔴'
}
return (
<div className="card card-gradient">
<div className="flex items-center justify-between mb-6">
<h2 className="text-xl font-bold text-white">System Status</h2>
<div className="flex items-center space-x-2">
<span className="text-lg">{statusIcon[status.systemStatus]}</span>
<span className={`text-sm font-medium ${statusColor[status.systemStatus]}`}>
{status.systemStatus.toUpperCase()}
</span>
if (loading) {
return (
<div className="card card-gradient">
<div className="flex items-center justify-center py-12">
<div className="spinner"></div>
<span className="ml-2 text-gray-400">Loading overview...</span>
</div>
</div>
)
}
{loading ? (
<div className="flex items-center justify-center py-8">
<div className="spinner"></div>
<span className="ml-2 text-gray-400">Loading status...</span>
return (
<div className="space-y-6">
{/* System Status Header */}
<div className="card card-gradient">
<div className="flex items-center justify-between mb-6">
<h2 className="text-xl font-bold text-white">System Status</h2>
<div className="flex items-center space-x-2">
<span className="text-lg">{statusIcon[status.systemStatus]}</span>
<span className={`text-sm font-medium ${statusColor[status.systemStatus]}`}>
Trading Bot {status.systemStatus.toUpperCase()}
</span>
</div>
</div>
) : (
<div className="space-y-6">
{/* Main Status Grid */}
<div className="grid grid-cols-1 sm:grid-cols-3 gap-6">
<div className="text-center">
<div className="w-16 h-16 bg-blue-500/20 rounded-full flex items-center justify-center mx-auto mb-3">
<span className="text-blue-400 text-2xl">💎</span>
</div>
<p className="text-2xl font-bold text-blue-400">
${status.driftBalance.toFixed(2)}
</p>
<p className="text-gray-400 text-sm">Portfolio Value</p>
</div>
{/* Wallet Balance */}
{/* Portfolio Overview - Combined Section */}
<div className="grid grid-cols-2 lg:grid-cols-4 gap-4 mb-6">
<div className="bg-gradient-to-br from-blue-500/10 to-blue-600/10 border border-blue-500/20 rounded-lg p-4">
<div className="flex items-center space-x-3 mb-2">
<div className="w-10 h-10 bg-blue-500/20 rounded-full flex items-center justify-center">
<span className="text-blue-400 text-lg">💎</span>
</div>
<div>
<p className="text-blue-400 text-sm font-medium">Portfolio Value</p>
<p className="text-xl font-bold text-white">${status.portfolioValue.toFixed(2)}</p>
</div>
</div>
</div>
{status.walletBalance && (
<div className="text-center">
<div className="w-16 h-16 bg-emerald-500/20 rounded-full flex items-center justify-center mx-auto mb-3">
<span className="text-emerald-400 text-2xl">🪙</span>
<div className="bg-gradient-to-br from-emerald-500/10 to-emerald-600/10 border border-emerald-500/20 rounded-lg p-4">
<div className="flex items-center space-x-3 mb-2">
<div className="w-10 h-10 bg-emerald-500/20 rounded-full flex items-center justify-center p-1">
<img
src={coinIcons['SOL']}
alt="SOL"
className="w-6 h-6 rounded-full"
/>
</div>
<div>
<p className="text-emerald-400 text-sm font-medium">Wallet Balance</p>
<p className="text-xl font-bold text-white">
{status.walletBalance.positions?.[0]?.amount?.toFixed(4) || '0.0000'} SOL
</p>
</div>
</div>
<p className="text-2xl font-bold text-emerald-400">
{status.walletBalance.positions?.[0]?.amount?.toFixed(4) || '0.0000'} SOL
</p>
<p className="text-gray-400 text-sm">Wallet Balance</p>
</div>
)}
<div className="text-center">
<div className="w-16 h-16 bg-purple-500/20 rounded-full flex items-center justify-center mx-auto mb-3">
<span className="text-purple-400 text-2xl">🔄</span>
<div className="bg-gradient-to-br from-purple-500/10 to-purple-600/10 border border-purple-500/20 rounded-lg p-4">
<div className="flex items-center space-x-3 mb-2">
<div className="w-10 h-10 bg-purple-500/20 rounded-full flex items-center justify-center">
<span className="text-purple-400 text-lg"><EFBFBD></span>
</div>
<p className="text-2xl font-bold text-purple-400">
{status.activeTrades}
</p>
<p className="text-gray-400 text-sm">Active Trades</p>
</div>
<div className="text-center">
<div className="w-16 h-16 bg-green-500/20 rounded-full flex items-center justify-center mx-auto mb-3">
<span className="text-green-400 text-2xl">📈</span>
</div>
<p className={`text-2xl font-bold ${status.dailyPnL >= 0 ? 'text-green-400' : 'text-red-400'}`}>
{status.dailyPnL >= 0 ? '+' : ''}${status.dailyPnL.toFixed(2)}
</p>
<p className="text-gray-400 text-sm">Daily P&L</p>
</div>
</div>
{/* Service Status */}
<div className="border-t border-gray-700 pt-6">
<div className="flex items-center justify-between mb-4">
<h3 className="text-lg font-semibold text-white">Service Status</h3>
</div>
<div className="grid grid-cols-2 gap-4">
<div className="flex items-center justify-between p-3 bg-gray-800 rounded-lg">
<span className="text-gray-300">Trading Bot</span>
<div className="flex items-center space-x-2">
<span className="text-sm">{statusIcon[status.systemStatus]}</span>
<span className={`text-sm font-medium ${statusColor[status.systemStatus]}`}>
{status.systemStatus.toUpperCase()}
</span>
</div>
</div>
<div className="flex items-center justify-between p-3 bg-gray-800 rounded-lg">
<span className="text-gray-300">Bitquery API</span>
<div className="flex items-center space-x-2">
<span className="text-sm">{statusIcon[status.bitqueryStatus]}</span>
<span className={`text-sm font-medium ${statusColor[status.bitqueryStatus]}`}>
{status.bitqueryStatus.toUpperCase()}
</span>
</div>
<div>
<p className="text-purple-400 text-sm font-medium">Active Trades</p>
<p className="text-xl font-bold text-white">{status.activeTrades}</p>
</div>
</div>
</div>
{/* Market Prices */}
{status.marketPrices.length > 0 && (
<div className="border-t border-gray-700 pt-6">
<div className="flex items-center justify-between mb-4">
<h3 className="text-lg font-semibold text-white">Live Market Prices</h3>
<span className="text-xs text-gray-400">Via Bitquery</span>
<div className="bg-gradient-to-br from-green-500/10 to-green-600/10 border border-green-500/20 rounded-lg p-4">
<div className="flex items-center space-x-3 mb-2">
<div className="w-10 h-10 bg-green-500/20 rounded-full flex items-center justify-center">
<span className="text-green-400 text-lg">📈</span>
</div>
<div className="grid grid-cols-1 sm:grid-cols-3 gap-4">
{status.marketPrices.map((price, index) => (
<div key={index} className="p-3 bg-gray-800 rounded-lg">
<div className="flex items-center justify-between">
<span className="text-white font-medium">{price.symbol}</span>
<span className="text-white font-bold">${price.price?.toFixed(4)}</span>
</div>
<div className="flex items-center justify-between mt-1">
<span className="text-xs text-gray-400">24h Change</span>
<span className={`text-xs font-medium ${
price.change24h >= 0 ? 'text-green-400' : 'text-red-400'
}`}>
{price.change24h >= 0 ? '+' : ''}{price.change24h?.toFixed(2)}%
</span>
</div>
</div>
))}
<div>
<p className="text-gray-400 text-sm font-medium">Daily P&L</p>
<p className={`text-xl font-bold ${status.dailyPnL >= 0 ? 'text-green-400' : 'text-red-400'}`}>
{status.dailyPnL >= 0 ? '+' : ''}${status.dailyPnL.toFixed(2)}
</p>
</div>
</div>
)}
</div>
</div>
{/* Available Coins in Wallet */}
{status.availableCoins.length > 0 && (
<div className="border-t border-gray-700 pt-6">
<div className="flex items-center justify-between mb-4">
<h3 className="text-lg font-semibold text-white">Available Wallet Coins</h3>
<span className="text-xs text-gray-400">Ready for Trading</span>
</div>
<div className="grid grid-cols-1 gap-3">
{status.availableCoins.map((coin, index) => (
<div key={index} className="p-3 bg-gray-800 rounded-lg">
<div className="flex items-center justify-between">
<div className="flex items-center space-x-3">
<span className="text-lg">🪙</span>
<div>
<span className="text-white font-medium">{coin.symbol}</span>
<div className="text-xs text-gray-400">${coin.price?.toFixed(2)}</div>
</div>
</div>
<div className="text-right">
<div className="text-white font-bold">{coin.amount?.toFixed(4)}</div>
<div className="text-sm text-gray-400">${coin.usdValue?.toFixed(2)}</div>
{/* Available Wallet Coins */}
{status.availableCoins.length > 0 && (
<div className="border-t border-gray-700 pt-4">
<h3 className="text-lg font-semibold text-white mb-3">Available Coins</h3>
<div className="grid grid-cols-1 md:grid-cols-2 gap-3">
{status.availableCoins.map((coin, index) => (
<div key={index} className="bg-gray-800/50 rounded-lg p-3">
<div className="flex items-center justify-between">
<div className="flex items-center space-x-3">
{coinIcons[coin.symbol] ? (
<img
src={coinIcons[coin.symbol]}
alt={coin.symbol}
className="w-6 h-6 rounded-full"
/>
) : (
<span className="text-xl">🪙</span>
)}
<div>
<span className="text-white font-medium">{coin.symbol}</span>
<div className="text-xs text-gray-400">${coin.price?.toFixed(2)}</div>
</div>
</div>
<div className="text-right">
<div className="text-white font-medium">{coin.amount?.toFixed(4)}</div>
<div className="text-sm text-gray-400">${coin.usdValue?.toFixed(2)}</div>
</div>
</div>
))}
</div>
</div>
))}
</div>
)}
</div>
)}
</div>
{/* Live Market Prices - BTC, ETH, SOL only */}
{status.marketPrices.length > 0 && (
<div className="card card-gradient">
<div className="flex items-center justify-between mb-4">
<h3 className="text-lg font-semibold text-white">Live Market Prices</h3>
<span className="text-xs text-gray-400">Real-time data</span>
</div>
<div className="grid grid-cols-1 md:grid-cols-3 gap-4">
{status.marketPrices.map((price, index) => (
<div key={index} className="bg-gradient-to-br from-gray-800/50 to-gray-700/50 border border-gray-600/30 rounded-lg p-4">
<div className="flex items-center justify-between mb-2">
<div className="flex items-center space-x-2">
{coinIcons[price.symbol] ? (
<img
src={coinIcons[price.symbol]}
alt={price.symbol}
className="w-8 h-8 rounded-full"
/>
) : (
<span className="text-2xl">🪙</span>
)}
<span className="text-white font-bold text-lg">{price.symbol}</span>
</div>
<span className="text-white font-bold text-xl">${price.price?.toFixed(2)}</span>
</div>
<div className="flex items-center justify-between">
<span className="text-xs text-gray-400">24h Change</span>
<span className={`text-sm font-medium px-2 py-1 rounded ${
price.change24h >= 0
? 'text-green-400 bg-green-400/10'
: 'text-red-400 bg-red-400/10'
}`}>
{price.change24h >= 0 ? '+' : ''}{price.change24h?.toFixed(2)}%
</span>
</div>
</div>
))}
</div>
</div>
)}
</div>