Price alert application that triggers an email when the user’s target price is achieved.
- Features
- Get Started
- Life Cycle
- Reproducibility Tips
- Folder Structure
- Routes
- Setting Up Postgre DB
- Checking Routes
- CRUD Alerts
- JWT Auth
- Email Notifications
- Celery Scheduler
- Multiple Coins
- Clone the repo
- Update the
.docker.env
file.- Create a env using
.docker.env.example
- Create a env using
- Start Server
- Docker Compose
docker-compose up
- Clone the repo
- Create a virtual env
python3 -m venv venv source ./venv/bin/activate
- Update the
.env
file.- 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
- Install Dependeince
- pip
pip install -r requirements.txt
- Make Migrations
- shell
python manage.py makemigrations python manage.py migrate
- Start Server
- Django Server
python manage.py runserver
- start Celery
celery -A KryptoAPI worker --loglevel=info
- start Scheduler
celery -A KryptoAPI beat --loglevel=info
pip install celery
sudo apt-get install rabbitmq-server
- 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.
- 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/46a548c84c21fc0c2f78
.dockerignore
.gitignore
|____launch.json
Dockerfile
KryptoAPI.http
|____.docker.env
|____.env
| |______init__.py
| |____admin.py
| |____apps.py
| | |______init__.py
| | |____requests_manager.py
| | |____routine_manager.py
| | |____task_manager.py
| |____mail.py
| | |______init__.py
| |____models.py
| |____serializers.py
| |____tasks.py
| |____tests.py
| |____urls.py
| |____views.py
| |______init__.py
| |____admin.py
| |____apps.py
| | |______init__.py
| |____models.py
| |____tests.py
| |____views.py
| |______init__.py
| |____asgi.py
| |____celery.py
| |____settings.py
| |____urls.py
| |____wsgi.py
|____manage.py
README.md
docker-compose.yml
requirements.txt
- Create
- List
```localhost:8000/api/alert/pro-listview/```
- Paginate ()
- Filter
- Triggered
- Sleep
- Active (Listen)
- Delete
- Activate/Deactivate
- 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.)
CREATE DATABASE krypto2;
CREATE USER krypto2 WITH PASSWORD 'Swarag';
GRANT ALL PRIVILEGES ON DATABASE krypto TO krypto;
- Headers are configured as Authorization: JWT <access_token> header:
curl --location --request POST 'http://localhost:8000/auth/jwt/create' \
--header 'Content-Type: application/json' \
--data-raw '{
"email": "[email protected]",
"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"
}