An autonomous AI trading system combining a CANSLIM Scanner Dashboard (Flask web UI) with the Wilson AI agent for 24/7 market analysis and trade execution. The system uses real-time market data from Alpaca and Finnhub, cloud persistence via Supabase, and autonomous decision-making powered by Google ADK and OpenRouter LLM.
DeepDiver is not just a dashboard—it's an autonomous trading system where the Wilson AI agent performs market analysis, generates CANSLIM scans, monitors positions, and makes trading decisions independently. The dashboard provides human oversight and discretionary trading capabilities.
- 🤖 Wilson AI Agent: Autonomous trader using Google ADK + OpenRouter LLM
- 📊 CANSLIM Scanner: Real-time stock analysis based on CANSLIM methodology
- 📈 Market Data: Live data from Alpaca and Finnhub APIs
- ☁️ Cloud Persistence: Supabase for all data storage with real-time WebSocket updates
- ⏰ Scheduled Tasks: APScheduler for automated morning briefings and market monitoring
- 🎨 Web Dashboard: Flask-based UI for human oversight and manual trading
- Autonomous Market Analysis: Wilson performs CANSLIM scans every morning at 8:30 AM ET
- Position Monitoring: Checks open positions every 15 minutes during market hours
- Alert Management: Monitors price alerts and triggers notifications
- Trade Journaling: Logs all decisions and actions to Supabase
- 9 Specialized Tools: Market data fetching, position management, watchlist updates, and more
- Real-time Updates: WebSocket subscriptions for instant data refresh
- Position Sizing Calculator: Automatic share calculation based on risk parameters
- Historical Scans: Browse past CANSLIM scan results
- Trade Journal: Track stock positions and covered calls with P&L
- Price Alerts: Set and monitor price alerts
- Earnings Calendar: Track upcoming earnings dates
- Daily Routines: Pre-market and post-close trading checklists
- Dark Mode UI: Professional interface optimized for extended use
- Market Regime Tracking: Confirmed, Rally Attempt, Under Pressure, Correction
- Risk Management: Configure account size, risk per trade, max positions
- CSV Export: Export scan results for further analysis
- Live Filtering: Search and filter stocks in real-time
- Color-Coded Signals: Visual indicators for buy/sell signals, RS ratings
- Backend: Python 3.12+ with Flask (application factory pattern)
- Frontend: Vanilla JavaScript with Supabase Realtime client
- AI Agent: Google ADK (Agent Development Kit) + OpenRouter LLM
- Market Data: Alpaca API (real-time quotes) + Finnhub API (fundamentals)
- Database: Supabase (PostgreSQL with real-time subscriptions)
- Task Scheduler: APScheduler for automated market monitoring
- Package Manager: uv (modern Python package installer)
- Python 3.12+
- uv package manager - Install uv
- API Keys (free tiers available):
- Alpaca API (real-time market data)
- Finnhub API (market fundamentals)
- Supabase account (cloud database)
- OpenRouter API (LLM access)
git clone https://github.com/yourusername/deepdiver.git
cd deepdiver# macOS/Linux
curl -LsSf https://astral.sh/uv/install.sh | sh
# Or via pip
pip install uvCreate a .env file in the project root:
cp .env.example .envEdit .env and set your API keys:
# --- Market Data APIs ---
ALPACA_API_KEY=your_alpaca_api_key_here
ALPACA_SECRET_KEY=your_alpaca_secret_key_here
FINNHUB_API_KEY=your_finnhub_api_key_here
# --- Supabase (Cloud Database) ---
SUPABASE_URL=your_supabase_url_here
SUPABASE_KEY=your_supabase_service_role_key_here
SUPABASE_ANON_KEY=your_supabase_anon_key_here
# --- AI Agent (Wilson) ---
OPENROUTER_API_KEY=your_openrouter_api_key_here
# GEMINI_API_KEY=your_gemini_api_key_here (Optional fallback)
# --- App Config ---
FLASK_ENV=development
PORT=8080- Create a free Supabase account at supabase.com
- Create a new project
- Copy your project URL and keys to
.env - Run the schema setup:
- Open Supabase SQL Editor
- Copy contents of
docs/supabase-schema.sql - Execute the SQL to create all tables
- Enable Realtime:
- Go to Database → Replication
- Enable replication for:
scans,scan_stocks,positions,alerts,journal
# Quick start (recommended)
chmod +x run.sh
./run.sh
# Or manually
uv sync # Install dependencies
uv run run.py # Start Flask serverOpen your browser to:
http://localhost:8080
On first launch, Wilson will:
- Check market status
- Wait for the morning briefing (8:30 AM ET on weekdays)
- Perform CANSLIM scan and populate the dashboard
- Monitor positions every 15 minutes during market hours
You can manually trigger a scan:
uv run python -c "from app.tasks import task_morning_briefing; task_morning_briefing()"- Home: Main CANSLIM scanner dashboard
- Calendar: View and log daily trading routines
- Calls: Track covered call positions
- History: Browse historical scan results
- Settings: Configure account equity, risk %, max positions
Wilson operates autonomously with 9 specialized tools:
- log_journal: Logs all decisions and actions
- check_market_status: Determines if market is open/closed
- fetch_market_data: Gets real-time price data from Alpaca/Finnhub
- write_scan_results: Saves CANSLIM scan results to Supabase
- get_current_positions: Retrieves open positions
- get_watchlist: Gets monitored stocks
- update_position: Updates position stops, targets, or closes trades
- check_alerts: Monitors price alerts
- add_to_watchlist: Adds stocks to monitoring list
View Wilson's activity in the Supabase journal table.
- Morning Briefing: 8:30 AM ET (Mon-Fri) - CANSLIM scan
- Market Monitor: Every 15 min during market hours (9 AM - 4 PM ET, Mon-Fri)
deepdiver/
├── app/
│ ├── __init__.py # Flask application factory
│ ├── extensions.py # Supabase client, APScheduler
│ ├── tasks.py # Scheduled jobs (morning briefing, market monitor)
│ ├── agents/ # AI Agent Logic
│ │ ├── wilson.py # Wilson AI agent (Google ADK)
│ │ ├── tools.py # 9 agent tools
│ │ └── prompts.py # Wilson's system prompt
│ ├── dashboard/ # Web UI Blueprint
│ │ ├── __init__.py # Blueprint registration
│ │ ├── routes.py # API endpoints and page routes
│ │ └── utils.py # Data access layer (Supabase queries)
│ └── templates/ # Jinja2 HTML templates
│ ├── index.html # Main dashboard
│ ├── calendar.html # Trading calendar
│ ├── calls.html # Covered calls tracker
│ ├── routine.html # Daily routine viewer
│ └── routine_form.html # Routine entry form
├── docs/
│ ├── supabase-schema.sql # Database schema
│ └── ... # Additional documentation
├── run.py # Application entry point
├── run.sh # Launch script with env validation
├── pyproject.toml # Python dependencies (uv format)
├── .env.example # Example environment variables
├── Dockerfile # Docker container config
├── docker-compose.yml # Docker Compose setup
└── README.md # This file
Configure via the web UI or directly in Supabase settings table:
- account_equity: Total account value (default: $100,000)
- risk_pct: Risk per trade as decimal (default: 0.01 = 1%)
- max_positions: Maximum concurrent positions (default: 6)
risk_per_trade = account_equity * risk_pct
risk_per_share = pivot - stop
shares = int(risk_per_trade / risk_per_share)
cost = shares * pivotGET /api/data- Latest scan with position sizingGET /api/refresh- Force refreshGET /api/export?filter=- Export CSVGET /api/history- List all scansGET /api/history/<scan_id>- Get specific scan
GET /api/positions- List positions + summaryPOST /api/positions- Add positionPATCH /api/positions/<id>- Update/close positionDELETE /api/positions/<id>- Delete position
GET /api/alerts- List alertsPOST /api/alerts- Add alertDELETE /api/alerts/<id>- Delete alert
GET /api/settings- Get account settingsPOST /api/settings- Update settings
See app/dashboard/routes.py for complete API documentation.
# Build and start
docker-compose up -d
# View logs
docker-compose logs -f
# Stop
docker-compose downFor production deployment, see CLAUDE.md for detailed instructions.
- Define function in
app/agents/tools.py - Add
@tooldecorator fromgoogle.adk.tools - Register in
app/agents/wilson.pytools list
Example:
from google.adk.tools import tool
@tool
def my_new_tool(param: str) -> str:
"""Description of what this tool does.
Args:
param: Description of parameter
Returns:
Description of return value
"""
return "result"# Add runtime dependency
uv add package-name
# Add dev dependency
uv add --dev package-nameuv run pytest- Verify Supabase credentials in
.env - Run database schema:
docs/supabase-schema.sql - Manually trigger scan:
uv run python -c "from app.tasks import task_morning_briefing; task_morning_briefing()" - Check Supabase dashboard → Tables →
scansfor data
- Enable Realtime in Supabase → Database → Replication
- Verify
SUPABASE_ANON_KEYis set correctly - Check browser console for WebSocket errors
- Look for green dot indicator in dashboard top-right
- Verify
OPENROUTER_API_KEYis valid - Check Supabase
journaltable for Wilson's logs - Test manually:
uv run python -c "from app.agents.wilson import wilson; print(wilson.run('test'))"
# Change port in .env
PORT=8081
# Or kill existing process
lsof -ti:8080 | xargs killFor more troubleshooting, see CLAUDE.md.
- CLAUDE.md: Comprehensive developer guide for AI assistants
- docs/supabase-schema.sql: Database schema
- docs/QUICKSTART.md: Quick start guide
- docs/TESTING.md: Testing documentation
Contributions welcome! Please:
- Fork the repository
- Create a feature branch
- Make your changes with tests
- Submit a pull request
MIT License - see LICENSE file for details.
Built with AI-powered development tools.
Disclaimer: This tool is for educational and research purposes. Always do your own due diligence before making investment decisions. Past performance does not guarantee future results. Autonomous trading carries significant risk.
