/crypto_alert

Cryptocurrency Price Alert Application

Primary LanguagePython


Crypto Alert App

This project consists of a web application that allows users to set alerts for cryptocurrency prices. The application uses Streamlit for the frontend and Flask for the backend. It also integrates with the CoinGecko API to fetch real-time cryptocurrency prices and Redis for storing alerts.

Features

  • Streamlit App: A user interface to set alerts for cryptocurrency prices and view price charts. Streamlit App

  • Flask API: A RESTful API to manage alerts and fetch cryptocurrency prices. Flask API

  • CoinGecko Integration: Fetch real-time cryptocurrency prices. CoinGecko Integration

  • Redis: Store and manage alert data. Redis

Getting Started

Prerequisites

image

  • Docker
  • Docker Compose

Installation

  1. Clone the repository:

    git clone https://github.com/paritosh921/crypto-alert-app.git
    cd crypto-alert-app
  2. Create the requirements.txt file:

    flask
    streamlit
    requests
    redis
    pandas
    numpy
    matplotlib
  3. Create the Dockerfile:

    # Use an official Python image as the base
    FROM python:3.9-slim
    
    # Set the working directory in the container
    WORKDIR /app
    
    # Copy the requirements file
    COPY requirements.txt .
    
    # Install the dependencies
    RUN pip install --no-cache-dir -r requirements.txt
    
    # Copy the app code
    COPY app.py .
    COPY api.py .
    
    # Make ports available to the world outside this container
    EXPOSE 8501
    EXPOSE 5000
    
    # Run the Flask API and Streamlit app when the container launches
    CMD ["sh", "-c", "python api.py & streamlit run app.py"]
  4. Create the docker-compose.yml file:

    version: '3.7'
    
    services:
      redis:
        image: "redis:alpine"
        container_name: "redis"
        ports:
          - "6379:6379"
    
      app:
        build: .
        container_name: "crypto-alert-app"
        ports:
          - "8501:8501"
          - "5000:5000"
        depends_on:
          - redis
        environment:
          - REDIS_HOST=redis
          - REDIS_PORT=6379

Running the Application

  1. Build and run the Docker containers:

    docker-compose up --build
  2. Access the Streamlit app:

    Open your browser and go to http://localhost:8501.

  3. Access the Flask API:

    The API will be running at http://localhost:5000.

Usage

Streamlit App

  1. Select a cryptocurrency (Bitcoin, Ethereum, Ripple).
  2. View the current price fetched from the CoinGecko API.
  3. Enter the price at which you want to receive an alert.
  4. Enter your email address.
  5. Click on "Set Alert" to save the alert.

Flask API

  • Create Alert:

    curl -X POST http://localhost:5000/alerts/create/ -H "Content-Type: application/json" -d '{"coin": "bitcoin", "price": 30000, "email": "user@example.com", "status": "created"}'
  • Get Alerts:

    curl -X GET http://localhost:5000/alerts/
  • Delete Alert:

    curl -X DELETE http://localhost:5000/alerts/delete/ -H "Content-Type: application/json" -d '{"coin": "bitcoin", "price": 30000, "email": "user@example.com"}'
  • Get Price:

    curl -X GET http://localhost:5000/price/bitcoin/

Project Structure

crypto-alert-app/
│
├── app.py                # Streamlit app code
├── api.py                # Flask API code
├── requirements.txt      # Python dependencies
├── Dockerfile            # Dockerfile for building the image
└── docker-compose.yml    # Docker Compose configuration

Contributing

If you would like to contribute, please open a pull request or issue on GitHub.