A comprehensive FastAPI backend for a mobile stock and cryptocurrency tracking application with technical analysis capabilities.
- Authentication: JWT-based user authentication and authorization
- Stock Data: Real-time and historical stock data from Alpha Vantage API
- Cryptocurrency Data: Real-time crypto exchange rates and historical data
- Technical Indicators: RSI, MACD, Bollinger Bands, and Stochastic oscillators
- Market Analysis: Automated overbought/oversold analysis with configurable thresholds
- Favorites Management: User watchlists for stocks and cryptocurrencies
- Chart Data: Formatted data for mobile app charts with technical indicator overlays
- Caching: Redis-based caching with 15-minute TTL for optimal performance
- Rate Limiting: Built-in rate limiting for Alpha Vantage API calls
- FastAPI: Modern, fast web framework for building APIs
- PostgreSQL: Robust relational database for user data and favorites
- Redis: In-memory caching for API responses
- SQLAlchemy: Python SQL toolkit and ORM
- Alembic: Database migration tool
- Alpha Vantage API: Financial data provider
- Python 3.11+
- Poetry (recommended) or pip
- PostgreSQL
- Redis
- Alpha Vantage API key (premium subscription recommended)
Quick Setup:
git clone <repository-url>
cd StellarIQ_backend
# Linux/macOS
chmod +x scripts/setup-dev.sh
./scripts/setup-dev.sh
# Windows
scripts\setup-dev.bat
Manual Setup:
- Clone the repository:
git clone <repository-url>
cd StellarIQ_backend
- Install Poetry if you haven't already:
# Linux/macOS/WSL
curl -sSL https://install.python-poetry.org | python3 -
# Windows PowerShell
(Invoke-WebRequest -Uri https://install.python-poetry.org -UseBasicParsing).Content | python -
- Install dependencies:
poetry install
- Set up pre-commit hooks:
poetry run pre-commit install
- Set up environment variables:
cp .env.example .env
# Edit .env with your configuration
- Start services with Docker Compose:
make docker-up
# or: docker-compose up -d postgres redis
- Run database migrations:
make upgrade
# or: poetry run alembic upgrade head
- Start the application:
make run
# or: poetry run uvicorn main:app --reload
- Clone the repository:
git clone <repository-url>
cd StellarIQ_backend
- Create and activate virtual environment:
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
- Install dependencies:
pip install -r requirements.txt
- Set up environment variables:
cp .env.example .env
# Edit .env with your configuration
- Start services with Docker Compose:
docker-compose up -d postgres redis
- Run database migrations:
alembic upgrade head
- Start the application:
uvicorn main:app --reload
The API will be available at http://localhost:8000
Interactive API documentation is available at:
- Swagger UI:
http://localhost:8000/docs
- ReDoc:
http://localhost:8000/redoc
POST /auth/register
- Register a new userPOST /auth/login
- Login and get access tokenGET /auth/me
- Get current user informationGET /auth/verify-token
- Verify token validity
GET /stocks/search
- Search for stock symbolsGET /stocks/quote/{symbol}
- Get current stock quoteGET /stocks/daily/{symbol}
- Get daily stock dataGET /stocks/intraday/{symbol}
- Get intraday stock data
GET /crypto/popular
- Get popular cryptocurrency symbolsGET /crypto/rate/{from_currency}
- Get crypto exchange rateGET /crypto/daily/{symbol}
- Get daily crypto dataGET /crypto/rates/multiple
- Get multiple crypto rates
GET /indicators/rsi/{symbol}
- Get RSI indicatorGET /indicators/macd/{symbol}
- Get MACD indicatorGET /indicators/stoch/{symbol}
- Get Stochastic indicatorGET /indicators/bbands/{symbol}
- Get Bollinger BandsGET /indicators/analysis/{symbol}
- Get comprehensive technical analysis
POST /favorites/
- Add symbol to favoritesDELETE /favorites/{symbol}
- Remove symbol from favoritesGET /favorites/
- Get user's favorites with quotesGET /favorites/check/{symbol}
- Check if symbol is favoritedGET /favorites/stats
- Get favorites statistics
GET /charts/candlestick/{symbol}
- Get candlestick chart dataGET /charts/comparison
- Get comparison chart for multiple symbolsGET /charts/multi/{symbols}
- Get multi-symbol chart data
GET /analysis/symbol/{symbol}
- Analyze single symbolPOST /analysis/bulk
- Bulk analysis of multiple symbolsGET /analysis/watchlist
- Analyze user's watchlistGET /analysis/screener
- Market screener with conditions
Key configuration options in .env
:
# Database
DATABASE_URL=postgresql://stellariq:password@localhost:5432/stellariq_db
# Redis
REDIS_URL=redis://localhost:6379/0
# Alpha Vantage API
ALPHA_VANTAGE_API_KEY=your_api_key_here
# JWT
SECRET_KEY=your-secret-key
ACCESS_TOKEN_EXPIRE_MINUTES=30
# Cache
CACHE_TTL_SECONDS=900 # 15 minutes
The API provides sophisticated technical analysis with configurable thresholds:
- RSI (Relative Strength Index): Default thresholds 70/30
- MACD (Moving Average Convergence Divergence): Signal line crossovers
- Stochastic Oscillator: Default thresholds 80/20
- Bollinger Bands: Price position relative to bands
- Overbought: Multiple indicators suggest selling opportunity
- Oversold: Multiple indicators suggest buying opportunity
- Neutral: Mixed or inconclusive signals
- All Alpha Vantage API responses are cached for 15 minutes
- Cache keys include all relevant parameters for accurate retrieval
- Automatic cache invalidation and cleanup
- Redis-based for high performance
- Default: 5 requests per minute to Alpha Vantage API
- Configurable rate limiting with automatic queuing
- Request timing optimization for premium API limits
- Comprehensive error responses with detailed messages
- Graceful degradation when external APIs are unavailable
- Proper HTTP status codes for all scenarios
- JWT-based authentication with configurable expiration
- Password hashing with bcrypt
- CORS configuration for mobile app integration
- Input validation and sanitization
# Run tests
make test
# or: poetry run pytest
# Run tests with coverage
make test-cov
# or: poetry run pytest --cov=app --cov-report=html
# Run linting
make lint
# or: poetry run flake8 app tests && poetry run mypy app
# Format code
make format
# or: poetry run black app tests && poetry run isort app tests
# Run all checks
make check
pytest
With Poetry and the included Makefile, you have access to convenient development commands:
make help # Show all available commands
make install-dev # Install all dependencies including dev tools
make run # Start development server
make test # Run tests
make test-cov # Run tests with coverage
make lint # Run linting (flake8, mypy)
make format # Format code (black, isort)
make format-check # Check code formatting
make migrate msg="description" # Create new migration
make upgrade # Apply database migrations
make docker-up # Start Docker services
make docker-down # Stop Docker services
make clean # Clean cache and temp files
The application is containerized and ready for deployment:
docker-compose up --build
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests for new functionality
- Submit a pull request
This project is licensed under the MIT License.