|
|
||
|---|---|---|
| .. | ||
| cli | ||
| tradingagents | ||
| DEPLOYMENT_GUIDE.md | ||
| FIXES_AND_IMPROVEMENTS_SUMMARY.md | ||
| ISSUE_ANALYSIS_AND_FIX_PLAN.md | ||
| Procfile | ||
| README.md | ||
| SERPAPI_SETUP.md | ||
| STREAMING_USAGE_EXAMPLES.md | ||
| TEST_DOCUMENTATION.md | ||
| TEST_SUMMARY.md | ||
| TOOL_CALL_FIX_SUMMARY.md | ||
| api.py | ||
| check_setup.py | ||
| deploy-to-railway.sh | ||
| main.py | ||
| production.env.example | ||
| pyproject.toml | ||
| railway.json | ||
| requirements.txt | ||
| restart_api.sh | ||
| run_all_tests.py | ||
| run_api.py | ||
| setup.py | ||
| test_analysis_full_output.json | ||
| test_analysis_output.json | ||
| test_analysis_with_timing.py | ||
| test_api.md | ||
| test_api.py | ||
| test_api_comprehensive.py | ||
| test_api_comprehensive_final.py | ||
| test_comprehensive_fixes.py | ||
| test_extended_fix.py | ||
| test_main_comprehensive.py | ||
| test_main_simple.py | ||
| test_output.json | ||
| test_parallel_execution.py | ||
| test_risk_management_flow.py | ||
| test_risk_manager_isolated.py | ||
| test_simple_fix.py | ||
| test_simple_risk_manager.py | ||
| test_tool_call_fix.py | ||
| test_with_mock.py | ||
| validate_fixes.py | ||
| verify_api.sh | ||
README.md
Trading Agents Backend
This directory contains the Python backend for the Trading Agents system.
Structure
api.py- FastAPI server that exposes trading analysis endpointsrun_api.py- Script to run the FastAPI servermain.py- Main entry point for the trading systemtradingagents/- Core trading logic and agentsagents/- Various AI agents (analysts, researchers, traders, risk managers)dataflows/- Data fetching and processing utilitiesgraph/- Trading decision graph and workflow
cli/- Command-line interface for the trading systemresults/- Output directory for analysis resultsrequirements.txt- Python dependenciessetup.py- Package setup configurationpyproject.toml- Modern Python project configuration
Quick Start
-
Install dependencies:
pip install -r requirements.txt -
Run the FastAPI server:
python run_api.py -
Or use the CLI:
python -m cli.main
API Endpoints
GET /- Root endpoint (API status)GET /health- Health checkPOST /analyze- Analyze a stock ticker- Request:
{"ticker": "AAPL"} - Response: Comprehensive analysis including market, sentiment, news, and trading decisions
- Request:
GET /docs- Interactive API documentation (Swagger UI)
Testing the API
Quick Test
# Run the test script
python test_api.py
Manual Testing
- Using Browser: Navigate to http://localhost:8000/docs for interactive testing
- Using curl: See
test_api.mdfor detailed curl commands - Using Python: Use the provided
test_api.pyscript
For detailed testing instructions, see test_api.md.
Environment Variables
Create a .env file in the project root with:
Required
OPENAI_API_KEY- Your OpenAI API key for AI agentsFINNHUB_API_KEY- For market data (free tier available)
Optional
REDDIT_CLIENT_ID- For Reddit sentiment analysisREDDIT_CLIENT_SECRET- For Reddit sentiment analysisTRADINGAGENTS_RESULTS_DIR- Custom results directory (default:backend/results)TRADINGAGENTS_DATA_DIR- Custom data directory (default:backend/data)TRADINGAGENTS_API_HOST- API host (default:localhost)TRADINGAGENTS_API_PORT- API port (default:8000)
Example .env file:
# API Keys
OPENAI_API_KEY=sk-your-key-here
FINNHUB_API_KEY=your-finnhub-key
# Optional Reddit API
REDDIT_CLIENT_ID=your-client-id
REDDIT_CLIENT_SECRET=your-client-secret
# Optional custom directories
# TRADINGAGENTS_RESULTS_DIR=/custom/path/to/results
# TRADINGAGENTS_API_PORT=3000
Features
Streaming Analysis (NEW!)
The TradingAgents CLI now supports real-time streaming of analysis reports as they're being generated by the AI agents. Instead of waiting for complete sections to be delivered, you can see the analysis content flowing in real-time.
Usage Options
-
Dedicated Streaming Command:
python -m cli.main stream python -m cli.main stream --advanced # With advanced configuration -
Streaming Flag with Analyze Command:
python -m cli.main analyze --streaming python -m cli.main analyze --streaming --advanced -
Default Command with Streaming:
python -m cli.main --streaming python -m cli.main --streaming --advanced
Streaming vs. Regular Analysis
- Regular Analysis: Shows progress updates and agent statuses, but reports are delivered only when complete sections are finished
- Streaming Analysis: Shows the same progress updates PLUS real-time streaming of report content as agents generate it
What You'll See in Streaming Mode
- 🔄 Agent Progress: Same as regular mode - shows which agents are working
- 📡 Live Streaming Panel: Real-time content from the currently active agent
- 🔴 Live Indicator: Shows which agent is currently generating content
- ⚡ Higher Refresh Rate: Updates 8 times per second for smooth streaming
Benefits
- Real-time Insights: See analysis developing as it happens
- Better Understanding: Watch the thought process of each agent
- Immediate Feedback: Know immediately when agents start working on different aspects
- Enhanced Experience: More engaging and informative than batch delivery
Technical Details
The streaming implementation:
- Uses a
StreamingMessageBufferthat extends the regularMessageBuffer - Detects agent transitions and content generation in real-time
- Maintains the same final report quality while providing streaming experience
- Automatically saves all content to report files as in regular mode