Skip to the content.

Krypto Price Tracker

Price alert application that triggers an email when the user’s target price is achieved.

Features

Get Started

  1. Clone the repo
  2. Create a virtual env
     python3 -m venv venv
     source ./venv/bin/activate 
    
  3. Update the .env file.
    • Create a env using env.example
  4. Have Postgre and RebitMQ running
    • postgre
       pgrep -u postgres -fa -- -D
      
    • rabitmq
       sudo systemctl enable rabbitmq-server
       sudo systemctl status  rabbitmq-server
       sudo systemctl start rabbitmq-server
      
  5. Install Dependeince
    • pip
       pip install -r requirements.txt
      
  6. Make Migrations
    • shell
       python manage.py makemigrations
       python manage.py migrate
      
  7. Start Server
    • Django Server
       python manage.py runserver
      
    • start Celery
       celery -A KryptoAPI worker --loglevel=info
      
    • start Scheduler
       celery -A KryptoAPI beat --loglevel=info
      

Install celery

pip install celery

Install RabbitMQ (Ubuntu Linux 20.04LTS)

sudo apt-get install rabbitmq-server

Life Cycle

  1. Admin Starts the server instance and add few coins to the database
  2. User Creates an account and start creating alerts for registred coins
  3. Service Actively fetches, the latest prices of Coins (30 Sec)(Can be modified)
  4. Once the latest prices are fetched, start querying the alerts such that
    • alert is active
    • the alert target is crossed, both reaching an upper limit and lower limit
  5. Found Alerts are turned to sleep,
    • since once an email is sent, the notification is reached. Not to spam user
    • if the user, want to have the notification still running, he/she needs to activate the alert.

Reproducibility Tips

  1. Use Pro list view to add alerts for users, without much Hassel (added for testing)
    • http://localhost:8000/api/alert/pro-listview/
  2. Auth Header is set to JWT, not Bearer
  3. Once Scheduler is called, alerts are set to sleep, so activate the alert again in Django Admin Panel
  4. Access and Refresh Token
    1. http://localhost:8000/auth/jwt/create/
    2. http://localhost:8000/auth/jwt/refresh/
  5. End Points
    1. KryptoAPI.http
    2. POSTMAN collection https://www.getpostman.com/collections/46a548c84c21fc0c2f78

      Folder Structure

      manage.py
      KryptoAPI/asgi.py
      KryptoAPI/__init__.py
      KryptoAPI/celery.py
      KryptoAPI/urls.py
      KryptoAPI/wsgi.py
      KryptoAPI/settings.py
      Alerts/__init__.py
      Alerts/serializers.py
      Alerts/mail.py
      Alerts/views.py
      Alerts/tests.py
      Alerts/tasks.py
      Alerts/apps.py
      Alerts/admin.py
      Alerts/urls.py
      Alerts/models.py
      Authentication/__init__.py
      Authentication/views.py
      Authentication/tests.py
      Authentication/apps.py
      Authentication/admin.py
      Authentication/models.py
      Alerts/helpers/__init__.py
      Alerts/helpers/task_manager.py
      Alerts/helpers/requests_manager.py
      Alerts/helpers/routine_manager.py
      Alerts/migrations/__init__.py
      Authentication/migrations/__init__.py
      

      Routes

      • Create
      • List
        localhost:8000/api/alert/pro-listview/
      • Paginate ()
      • Filter
        • Triggered
        • Sleep
        • Active (Listen)
          • Delete
          • Activate/Deactivate

Features

Setting Up Postgre DB

CREATE DATABASE krypto2;
CREATE USER krypto2  WITH PASSWORD 'Swarag';
GRANT ALL PRIVILEGES ON DATABASE krypto TO krypto;

Checking Routes

  1. Headers are configured as **Authorization: JWT header:**

Login

curl --location --request POST 'http://localhost:8000/auth/jwt/create' \
--header 'Content-Type: application/json' \
--data-raw '{
    "email": "apple@a.cm",
    "password": "qwe"
}'
POST /auth/jwt/create

HTTP 200 OK
Allow: POST, OPTIONS
Content-Type: application/json
Vary: Accept

{
    "refresh": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ0b2tlbl90eXBlIjoicmVmcmVzaCIsImV4cCI6MTYzMTM3NTMwOCwianRpIjoiMmNmYzg5MjdiZWMxNDEyYWE2Y2Q5OTc4ZTg5N2ZkMzciLCJ1c2VyX2lkIjoyfQ.DK_sTu-Qd-ZI-utAysylokIV2H0HJ3abTlSW8I4ojNc",
    "access": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ0b2tlbl90eXBlIjoiYWNjZXNzIiwiZXhwIjoxNjMxMjg5MjA4LCJqdGkiOiI1NDA5OGI0ZTdkNmM0ODgyOTM2MDc1OGNjNDc5YmFiOSIsInVzZXJfaWQiOjJ9.FvBp001LT1ChJlZllZ6u4jkhcc3FXeicr03NmsCY_9E"
}