A sophisticated FastAPI-based REST API that combines traditional stock analysis with AI-powered insights using AutoGen agents. This system provides comprehensive stock analysis, technical indicators, and market sentiment analysis.
-
Advanced Stock Analysis
- Year-to-date (YTD) performance tracking
- Technical indicators (RSI, MACD, Moving Averages)
- Interactive price visualizations
- Historical data analysis
-
AI-Powered Insights
- Market sentiment analysis
- Automated technical analysis
- Trend predictions
- News sentiment integration
-
Modern Architecture
- FastAPI for high-performance async operations
- AutoGen agents for intelligent analysis
- Pydantic for robust data validation
- Swagger/OpenAPI documentation
- Type hints and modern Python practices
- Python 3.9+
- OpenAI API key
- Git
- Clone the repository:
git clone https://github.com/yourusername/stock-analysis-api.git
cd stock-analysis-api
- Create and activate virtual environment:
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
- Install dependencies:
pip install -r backend/requirements.txt
- Set up environment variables:
cp backend/.env.example backend/.env
# Edit .env and add your OpenAI API key
- Run the application:
cd backend
uvicorn app.main:app --reload
The API will be available at:
- API Endpoint:
http://localhost:8000
- Interactive Docs:
http://localhost:8000/docs
- ReDoc:
http://localhost:8000/redoc
POST /api/v1/stocks/analysis
Performs comprehensive stock analysis with AI insights.
Request body:
{
"symbols": ["AAPL", "MSFT"]
}
POST /api/v1/stocks/sentiment
Analyzes market sentiment using AI agents.
Request body:
{
"symbols": ["AAPL", "TSLA"]
}
GET /api/v1/stocks/plot/{filename}
Retrieves generated stock visualizations.
backend/
├── app/
│ ├── agents/ # AutoGen agents
│ ├── api/ # API routes
│ ├── models/ # Pydantic models
│ ├── services/ # Business logic
│ ├── utils/ # Utility functions
│ ├── config.py # Configuration
│ └── main.py # Application entry
├── static/ # Static files
├── tests/ # Test suite
├── .env # Environment variables
└── requirements.txt # Dependencies
pytest
# Format code
black .
# Check types
mypy .
# Lint code
flake8
import httpx
import asyncio
async def analyze_stocks():
async with httpx.AsyncClient() as client:
response = await client.post(
'http://localhost:8000/api/v1/stocks/analysis',
json={'symbols': ['AAPL', 'MSFT']}
)
return response.json()
# Run analysis
result = asyncio.run(analyze_stocks())
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature
) - Commit your changes (
git commit -m 'Add amazing feature'
) - Push to the branch (
git push origin feature/amazing-feature
) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
- FastAPI for the amazing web framework
- AutoGen for AI agent capabilities
- yfinance for stock data
- OpenAI for AI capabilities
Aman - @LinkedIN - aman1024soni@gmail.com