Skip to content

A high-performance alert system that monitors live market data and pushes instant notifications to users via WebSockets when price thresholds are triggered.

Notifications You must be signed in to change notification settings

Py-God/crypto-alert

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

13 Commits
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Stock/Crypto Alert System

A real-time price alert system for stocks and cryptocurrencies. Get notified when your favorite assets hit target prices through email and WebSocket notifications.

πŸš€ Features

  • User Authentication: Secure JWT-based authentication with refresh tokens
  • Price Alerts: Create, manage, and monitor price alerts for stocks and cryptocurrencies
  • Real-time Updates: WebSocket connections for live price updates and alert triggers
  • Multi-Asset Support: Support for both stocks (via Yahoo Finance) and cryptocurrencies (via Binance API)
  • Email Notifications: Email alerts when price targets are reached
  • Market Data API: Fetch current prices, validate symbols, and get bulk price data
  • Redis Caching: Optimized performance with Redis caching for market data
  • Background Monitoring: Automated scheduler for checking and triggering alerts
  • Modern UI: Beautiful, responsive React frontend with Tailwind CSS

πŸ› οΈ Tech Stack

Backend

  • FastAPI - Modern Python web framework
  • PostgreSQL - Relational database with asyncpg
  • Redis - Caching and session management
  • SQLAlchemy - ORM with async support
  • Alembic - Database migrations
  • WebSockets - Real-time communication
  • JWT - Authentication tokens
  • Python Binance & yfinance - Market data providers

Frontend

  • React 19 - UI library
  • Vite - Build tool and dev server
  • React Router - Client-side routing
  • Axios - HTTP client
  • Tailwind CSS - Utility-first CSS framework
  • Lucide React - Icon library

Infrastructure

  • Docker & Docker Compose - Containerization
  • Nginx - Web server for frontend
  • Uvicorn - ASGI server

πŸ“‹ Prerequisites

  • Docker and Docker Compose installed
  • Git
  • (Optional) Node.js 20+ and Python 3.10+ for local development

🚦 Getting Started

Using Docker Compose (Recommended)

  1. Clone the repository

    git clone <your-repo-url>
    cd crypto-alert
  2. Create environment file (optional)

    # Create .env file in project root
    POSTGRES_USER=postgres
    POSTGRES_PASSWORD=postgres
    POSTGRES_DB=crypto_alerts
    SECRET_KEY=your-secret-key-here
    JWT_SECRET_KEY=your-jwt-secret-key-here
    
    # Optional: API Keys
    BINANCE_API_KEY=your-binance-api-key
    BINANCE_API_SECRET=your-binance-api-secret
    
    # Optional: Email configuration
    SMTP_HOST=smtp.gmail.com
    SMTP_PORT=587
    SMTP_USERNAME=your-email@gmail.com
    SMTP_PASSWORD=your-app-password
    SMTP_FROM_EMAIL=your-email@gmail.com
  3. Start all services

    docker-compose up -d
  4. Access the application

  5. View logs

    # All services
    docker-compose logs -f
    
    # Specific service
    docker-compose logs -f backend
    docker-compose logs -f frontend

Stop Services

docker-compose down

Reset Database (⚠️ Deletes all data)

docker-compose down -v
docker-compose up -d

πŸ”§ Configuration

Environment Variables

The application uses environment variables for configuration. You can set them in a .env file or as environment variables in docker-compose.yml.

Required Variables

  • DATABASE_URL - PostgreSQL connection string (auto-generated in docker-compose)
  • SECRET_KEY - Secret key for encryption
  • REDIS_URL - Redis connection string (auto-generated in docker-compose)

Optional Variables

  • POSTGRES_USER - PostgreSQL username (default: postgres)
  • POSTGRES_PASSWORD - PostgreSQL password (default: postgres)
  • POSTGRES_DB - Database name (default: crypto_alerts)
  • CORS_ORIGINS - Comma-separated list of allowed origins
  • SMTP_* - Email configuration for notifications

API Endpoints

All API endpoints are prefixed with /api/v1/.

Authentication (/api/v1/auth)

  • POST /register - Register a new user
  • POST /login - Login and get JWT tokens
  • POST /refresh - Refresh access token
  • GET /me - Get current user info
  • POST /logout - Logout user

Alerts (/api/v1/alerts)

  • POST / - Create a new alert
  • GET / - Get all user alerts
  • GET /{alert_id} - Get specific alert
  • PUT /{alert_id} - Update alert
  • DELETE /{alert_id} - Delete alert

Market Data (/api/v1/market)

  • GET /price/{symbol} - Get current price
  • POST /prices - Get multiple prices
  • GET /validate/{symbol} - Validate symbol exists

WebSocket (/api/v1/ws)

  • WS /connect - Connect for real-time updates

Notifications (/api/v1/notifications)

  • POST /test-email - Send test email

πŸ’» Local Development

Backend Development

cd backend

# Install dependencies using uv (recommended)
curl -LsSf https://astral.sh/uv/install.sh | sh
uv sync

# Or using pip
pip install -r requirements.txt

# Set up environment variables
export DATABASE_URL="postgresql+asyncpg://postgres:postgres@localhost:5432/crypto_alerts"
export REDIS_URL="redis://localhost:6379/0"
export SECRET_KEY="your-secret-key"

# Run migrations
alembic upgrade head

# Start development server
uvicorn src.main:app --reload --host 0.0.0.0 --port 8000

Frontend Development

cd frontend

# Install dependencies
npm install

# Start development server
npm run dev

The frontend will run on http://localhost:5173 (or another port if 5173 is busy).

πŸ“ Project Structure

crypto-alert/
β”œβ”€β”€ backend/
β”‚   β”œβ”€β”€ src/
β”‚   β”‚   β”œβ”€β”€ auth/          # Authentication logic
β”‚   β”‚   β”œβ”€β”€ alerts/        # Alert management
β”‚   β”‚   β”œβ”€β”€ market_data/   # Market data fetching
β”‚   β”‚   β”œβ”€β”€ notifications/ # Email notifications
β”‚   β”‚   β”œβ”€β”€ websocket/     # WebSocket handlers
β”‚   β”‚   β”œβ”€β”€ cache/         # Redis client
β”‚   β”‚   β”œβ”€β”€ database.py    # Database setup
β”‚   β”‚   β”œβ”€β”€ config.py      # Configuration
β”‚   β”‚   └── main.py        # FastAPI app
β”‚   β”œβ”€β”€ alembic/           # Database migrations
β”‚   β”œβ”€β”€ Dockerfile
β”‚   └── pyproject.toml
β”œβ”€β”€ frontend/
β”‚   β”œβ”€β”€ src/
β”‚   β”‚   β”œβ”€β”€ api/           # API client
β”‚   β”‚   β”œβ”€β”€ contexts/      # React contexts
β”‚   β”‚   β”œβ”€β”€ pages/         # Page components
β”‚   β”‚   └── App.jsx
β”‚   β”œβ”€β”€ Dockerfile
β”‚   └── package.json
└── docker-compose.yml

πŸ› Troubleshooting

Backend can't connect to database

  • Check that PostgreSQL container is running: docker-compose ps
  • Verify database credentials in environment variables
  • Check logs: docker-compose logs postgres

CORS errors

  • Ensure your frontend URL is in CORS_ORIGINS
  • Check backend logs for CORS-related errors
  • Verify frontend is accessing from allowed origin

Redis connection issues

  • Check Redis container is running: docker-compose logs redis
  • Application will work without Redis (caching disabled)

Frontend shows network errors

  • Verify backend is running and accessible
  • Check browser console for detailed error messages
  • Ensure API base URL is correct in src/api/client.js

πŸ§ͺ Testing

API documentation and testing interface available at:

πŸ“ Database Migrations

# Create a new migration
docker exec -it crypto-alert-backend alembic revision --autogenerate -m "description"

# Apply migrations
docker exec -it crypto-alert-backend alembic upgrade head

# Rollback migration
docker exec -it crypto-alert-backend alembic downgrade -1

πŸ” Security Notes

  • Change default passwords and secrets in production
  • Use strong SECRET_KEY values
  • Enable HTTPS in production
  • Configure proper CORS origins
  • Keep dependencies updated

🀝 Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

πŸ‘€ Author

Boluwatife Leke-Oduoye

πŸ™ Acknowledgments

  • Binance API for cryptocurrency data
  • Yahoo Finance for stock market data

About

A high-performance alert system that monitors live market data and pushes instant notifications to users via WebSockets when price thresholds are triggered.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published