- Python 3.x
- pip
- RabbitMQ (message broker)
- Redis (caching tool)
- Celery (API task queuer)
git clone https://github.com/thebigjoe29/BTC_tracker_email.git
cd BTC_tracker_email
pip install -r requirements.txt
redis-server
rabbitmq-server
mysql server
celery -A myproject worker --pool=solo -l info
python manage.py migrate && python manage.py runserver
- LOGIN THE USER
method: POST
body: { "email": "[email protected]", "password": "yourpassword" }
http://127.0.0.1:8000/api/login/
- REGISTER THE USER
method: POST
body: { "email": "[email protected]", "password": "yourpassword" }
http://127.0.0.1:8000/api/register/
- CREATE AN ALERT
method: POST
body: { "price": 51000 }
http://127.0.0.1:8000/api/alerts/create
- DELETE ALERT WITH GIVEN ID
method: POST
http://127.0.0.1:8000/api/delete/<replace_with_alert_id>
5. FETCH ALL ALERTS
method: GET
http://127.0.0.1:8000/api/alerts/
- FETCH ALERTS FILTERED BY STATUS
method: GET
http://127.0.0.1:8000/api/alerts/<replace_with_alert_status>
https://api.binance.com/api/v3/ticker/price?symbol=BTCUSDT
- A user registers themselves using the /register API using a valid email and password.
- The user logs in using the /login the same credentials.
- On successul login, a JWT (JSON Web Token) is returned, with user_email embedded in it.
- All subsequent APIs will require Bearer authentication using these tokens. (30 min validity).
- The user can create an alert with his desired price in the price parameter of the request body.
- A celery worker is instantiated as soon as the request is received by the server that checks for changes every 10s.
- If the current BTC price is greater than or equal to the request_price, the Email job will be triggered and Celery will send an email to the user immediately.
- If the condition fails, Celery will infinitely keep a watch on the BTC price and send the Email as soon as the condition is met.
- Only alerts with status="created" are kept in task queues and rest are only stored in the MySql database.
- Once an alert has been triggered, its status is changed to "triggered" and it is dequeued.
- Using Django-Redis, all GET alert responses will be cached locally for a fixed period of time.
- This will increase retrieval speed and avoid unnecessary API calls.
- However Celery will continue fetching current BTC prices even if cached data is available to ensure data consistency.
- Using status as a parameter, the user can fetch alerts filtered by the status, eg. created, triggered, deleted etc.
- All GET responses are paginated for easy access with count, next page url and number of entries per page provided with each response.
id(int)
email(String)
password (String)
id(int)
email(String)
status(String)
price (int)