3.5 KiB
3.5 KiB
TradingAgents Frontend
This document describes how to run the TradingAgents web application.
Architecture
The application consists of two parts:
- Backend (
backend/) - FastAPI server that wraps TradingAgentsGraph - Frontend (
frontend/) - Next.js React application
Prerequisites
- Python 3.10+ with uv or pip
- Node.js 18+ and npm
- Environment variables configured (see
.envfile)
Setup
Backend Setup
- Install backend dependencies:
cd backend
pip install -r requirements.txt
# Or if using uv:
uv pip install -r requirements.txt
-
Ensure the main TradingAgents package is installed (it should be in the parent directory)
-
Set environment variables in
.env:
OPENAI_API_KEY=your_key_here
ALPHA_VANTAGE_API_KEY=your_key_here
Frontend Setup
- Install frontend dependencies:
cd frontend
npm install
- Create
.env.localfile:
NEXT_PUBLIC_API_URL=http://localhost:8000
NEXT_PUBLIC_WS_URL=ws://localhost:8000
Running the Application
Start the Backend
From the project root directory:
# Option 1: Using the run script
cd backend
python run.py
# Option 2: Using uvicorn from project root
uvicorn backend.api.main:app --reload --host 0.0.0.0 --port 8000
# Option 3: Using Python module from project root
python -m backend.api.main
The backend will be available at http://localhost:8000
API documentation: http://localhost:8000/docs
Start the Frontend
cd frontend
npm run dev
The frontend will be available at http://localhost:3000
Usage
- Open
http://localhost:3000in your browser - Click "New Analysis" to start a trading analysis
- Fill in the form:
- Ticker symbol (e.g., "SPY")
- Analysis date
- Select analysts
- Configure LLM settings
- Click "Start Analysis"
- View real-time progress and results
Features
- Real-time Analysis: Watch agents work in real-time via WebSocket
- Agent Progress: See status of all agents (Analyst Team, Research Team, etc.)
- Report Viewer: View generated reports with collapsible sections
- History: Browse and view previous analyses
- Configuration: Save and load analysis configurations
API Endpoints
POST /api/analysis/start- Start new analysisGET /api/analysis/{id}/status- Get analysis statusGET /api/analysis/{id}/results- Get analysis resultsWS /ws/analysis/{id}/stream- WebSocket stream for updatesGET /api/history- List historical analysesGET /api/history/{ticker}/{date}- Get specific historical analysisGET /api/config/presets- List configuration presetsPOST /api/config/save- Save configuration preset
Development
Backend Development
The backend uses FastAPI with automatic reload. Changes to Python files will trigger a reload.
Frontend Development
The frontend uses Next.js with hot module replacement. Changes to React components will update automatically.
Troubleshooting
- Backend won't start: Check that all dependencies are installed and environment variables are set
- Frontend can't connect: Verify
NEXT_PUBLIC_API_URLmatches the backend URL - WebSocket connection fails: Ensure the backend is running and CORS is configured correctly
- Analysis fails: Check API keys in
.envfile and verify they're valid
Notes
- The CLI (
cli/main.py) continues to work independently - All existing TradingAgents code remains unchanged
- Results are saved to the
results/directory (same as CLI)