Krypto Price Tracker
Price alert application that triggers an email when the user’s target price is achieved.
Features
- CRUD Alerts
 - JWT Auth
 - Email Notifications
 - Celery Scheduler
 - Multiple Coins
 
Get Started
- Clone the repo
 - Create a virtual env
    
python3 -m venv venv source ./venv/bin/activate - Update the 
.envfile.- Create a env using 
env.example 
 - Create a env using 
 - 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 
 - postgre
        
 - Install Dependeince
    
- pip
        
pip install -r requirements.txt 
 - pip
        
 - Make Migrations
    
- shell
        
python manage.py makemigrations python manage.py migrate 
 - shell
        
 - Start Server
    
- Django Server
        
python manage.py runserver - start Celery
        
celery -A KryptoAPI worker --loglevel=info - start Scheduler
        
celery -A KryptoAPI beat --loglevel=info 
 - Django Server
        
 
Install celery
pip install celery
Install RabbitMQ (Ubuntu Linux 20.04LTS)
sudo apt-get install rabbitmq-server
Life Cycle
- Admin Starts the server instance and add few coins to the database
 - User Creates an account and start creating alerts for registred coins
 - Service Actively fetches, the latest prices of Coins (30 Sec)(Can be modified)
 - 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
 
 - 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
- Use Pro list view to add alerts for users, without much Hassel (added for testing)
    
http://localhost:8000/api/alert/pro-listview/
 - Auth Header is set to JWT, not Bearer
 - Once Scheduler is called, alerts are set to sleep, so activate the alert again in Django Admin Panel
 - Access and Refresh Token
    
http://localhost:8000/auth/jwt/create/http://localhost:8000/auth/jwt/refresh/
 - End Points
    
- KryptoAPI.http
 - POSTMAN collection 
https://www.getpostman.com/collections/46a548c84c21fc0c2f78Folder 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__.pyRoutes
- Create
 - List
localhost:8000/api/alert/pro-listview/ 
- Paginate ()
 - Filter
            
- Triggered
 - Sleep
 - Active (Listen)
                
- Delete
 - Activate/Deactivate
 
 
 
 
 
Features
- Create a rest API endpoint for the user’s to create an alert 
alerts/create/ - Create a rest API endpoint for the user’s to delete an alert 
alerts/delete/ - Create a rest API endpoint to fetch all the alerts that the user has created.
 - The response should also include the status of the alerts (created/deleted/triggered/.. or any other status you feel needs to be included)
 - Paginate the response.
 - Include filter options based on the status of the alerts. Eg: if the user wanted only the alerts that were triggered, then the endpoint should provide just that)
 - Add user authentication to the endpoints. Use JWT tokens.
 - Write a script that monitors the price of the cryptocurrency
 - You can use this endpoint to fetch the latest price of the cryptocurrency:
'https://api.coingecko.com/api/v3/simple/price?ids={coin}&vs_currencies={curr}' - When the price of the coin reaches the price specified by the users, send an email to all the users that set the alert at that price. (send mail using Gmail SMTP, SendGrid, etc)
 - You should set up a background worker(eg: celery/python-script/go-script) to send the email. Use Rabbit MQ/Redis as a message broker.)
 
Setting Up Postgre DB
CREATE DATABASE krypto2;
CREATE USER krypto2  WITH PASSWORD 'Swarag';
GRANT ALL PRIVILEGES ON DATABASE krypto TO krypto;
Checking Routes
- 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"
}