Skip to content

Secure Bitcoin price tracker with automated email updates

Notifications You must be signed in to change notification settings

thebigjoe29/Crypto-Alert

Repository files navigation

Project Overview and Documentation

Image description WhatsApp Image 2024-07-29 at 03 50 30_29b5ffbe WhatsApp Image 2024-07-29 at 03 37 44_5893e671 WhatsApp Image 2024-07-29 at 03 39 52_53189760

Prerequisites

  • Python 3.x
  • pip
  • RabbitMQ (message broker)
  • Redis (caching tool)
  • Celery (API task queuer)

Steps

1. Clone the Repository

git clone https://github.com/thebigjoe29/BTC_tracker_email.git
cd BTC_tracker_email

2. Install requirements

pip install -r requirements.txt

3. Ensure servers are up and running

redis-server
rabbitmq-server
mysql server

4. Start the celery worker

celery -A myproject worker --pool=solo -l info

5. Start the Django server and migrations

python manage.py migrate && python manage.py runserver

API Endpoints

  1. LOGIN THE USER
    method: POST
    body: { "email": "[email protected]", "password": "yourpassword" }
http://127.0.0.1:8000/api/login/
  1. REGISTER THE USER
    method: POST
    body: { "email": "[email protected]", "password": "yourpassword" }
http://127.0.0.1:8000/api/register/
  1. CREATE AN ALERT
    method: POST
    body: { "price": 51000 }
http://127.0.0.1:8000/api/alerts/create
  1. 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/
  1. FETCH ALERTS FILTERED BY STATUS
    method: GET
http://127.0.0.1:8000/api/alerts/<replace_with_alert_status>

Alert logic and User auth

Current price of BTC (USD) is fetched from Binance's live price API endpoint

https://api.binance.com/api/v3/ticker/price?symbol=BTCUSDT
  1. A user registers themselves using the /register API using a valid email and password.
  2. The user logs in using the /login the same credentials.
  3. On successul login, a JWT (JSON Web Token) is returned, with user_email embedded in it.
  4. All subsequent APIs will require Bearer authentication using these tokens. (30 min validity).
  5. The user can create an alert with his desired price in the price parameter of the request body.
  6. A celery worker is instantiated as soon as the request is received by the server that checks for changes every 10s.
  7. 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.
  8. 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.
  9. Only alerts with status="created" are kept in task queues and rest are only stored in the MySql database.
  10. Once an alert has been triggered, its status is changed to "triggered" and it is dequeued.

Caching, Pagination and GET APIs

  1. Using Django-Redis, all GET alert responses will be cached locally for a fixed period of time.
  2. This will increase retrieval speed and avoid unnecessary API calls.
  3. However Celery will continue fetching current BTC prices even if cached data is available to ensure data consistency.
  4. Using status as a parameter, the user can fetch alerts filtered by the status, eg. created, triggered, deleted etc.
  5. All GET responses are paginated for easy access with count, next page url and number of entries per page provided with each response.

Models

1. User model:

id(int)
email(String)
password (String)

2. Alert model:

id(int)
email(String)
status(String)
price (int)

About

Secure Bitcoin price tracker with automated email updates

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published