This is a trigger management system for cryptocurrencies/stocks/commodities, built using Django, PostgreSQL, and several additional technologies. It allows users to create triggers for trackable entities' prices, receive alerts via email, and view price charts live.
- Docker
- Docker Compose
- Clone the Repository
git clone https://github.com/subh-chaturvedi/BookMyTrigger
cd BookMyTrigger
- Build and Start Docker Containers
docker-compose up --build
This command builds the Docker images and starts the containers for your Django application, Redis, RabbitMQ, and PostgreSQL.
- Run Migrations After the containers are up, you need to apply the database migrations:
docker-compose exec web python manage.py migrate
- Create a Superuser (Optional) To access the Django admin interface, create a superuser:
docker-compose exec web python manage.py createsuperuser
- Access the Application
-
Django Application :
http://localhost:8000
-
RabbitMQ Management Interface :
http://localhost:15672
(username:guest
, password:guest
) -
PgAdmin :
http://localhost:8080
(email:[email protected]
, password:abc
)
-
Django : Web framework for building the application.
-
PostgreSQL : Database for storing user data and triggers.
-
Binance WebSocket API : For real-time price updates.
-
Celery : For handling asynchronous tasks.
-
RabbitMQ : Message broker for Celery.
-
TradingView : For embeddable financial charts.
-
Redis : Caching layer for API responses.
-
Docker : Containerization of the application and services.
- Django Application :
-
Handles user authentication using JWT, trigger management, and API endpoints.
-
Uses Django REST framework for building API endpoints.
- PostgreSQL :
- Stores user information, triggers, and other persistent data.
- Binance WebSocket :
-
Streams real-time cryptocurrency prices to the Django application.
-
Listens for price updates and triggers alerts when conditions are met.
- Celery :
-
Manages asynchronous tasks such as sending email notifications.
-
Workers execute tasks from the queue and store results in Redis.
- RabbitMQ :
-
Acts as the message broker for Celery.
-
Manages task queues and ensures reliable delivery of tasks to Celery workers.
- Redis :
-
Configured as the Result Backend for celery.
-
Also used for caching API responses to reduce database load and improve performance.
-
Stores task results for quick access and real-time monitoring of task statuses.
- Docker :
-
Containerizes the application and its dependencies for consistency across different environments.
-
Simplifies the setup and deployment process.
- Docker Compose :
-
Defines and runs multi-container Docker applications.
-
Orchestrates the various services (Django, PostgreSQL, RabbitMQ, Redis) required by the application.
- Frontend Interface :
-
Allows users to log in, view, create, and delete triggers.
-
Displays a BTC price chart using TradingView or Matplotlib-generated images.
This API provides endpoints for managing user accounts, setting and deleting alerts, and retrieving alert information. It includes endpoints for user authentication, alert management, and fetching alert statuses with pagination and filtering.
All endpoints except those for registration and login require authentication via JWT (JSON Web Token). Include the token in the Authorization
header as Bearer <jwt-token>
.
- Register User
-
Endpoint :
POST /api/register/
-
Description : Registers a new user in the system.
-
Request Body :
{
"username": "string",
"password": "string",
"email": "string"
}
- Response :
-
Status Code :
201 Created
-
Body :
-
{
"id": 1,
"username": "string",
"email": "string"
}
- Errors :
400 Bad Request
: Validation errors or missing required fields.
- Login User
-
Endpoint :
POST /api/login/
-
Description : Authenticates a user and returns a JWT for subsequent requests.
-
Request Body :
{
"username": "string",
"password": "string"
}
- Response :
-
Status Code :
200 OK
-
Body :
-
{
"access": "jwt-token",
"refresh": "refresh-token"
}
- Errors :
401 Unauthorized
: Invalid credentials.
- Create Alert Trigger
-
Endpoint :
POST /api/alerts/create/
-
Description : Creates a new alert trigger for the authenticated user.
-
Headers :
Authorization: Bearer <jwt-token>
-
Request Body :
{
"trigger_value": "integer"
}
- Response :
-
Status Code :
201 Created
-
Body :
-
{
"id": 1,
"trigger_value": 50000,
"status": "created"
}
- Errors :
-
400 Bad Request
: Invalid trigger value or other validation errors. -
401 Unauthorized
: Invalid or missing JWT token.
-
- Delete Alert Trigger
-
Endpoint :
DELETE /api/alerts/delete/{id}/
-
Description : Deletes an existing alert trigger for the authenticated user.
-
Headers :
Authorization: Bearer <jwt-token>
-
URL Parameters :
id
: ID of the alert trigger to delete.
-
Response :
-
Status Code :
200 OK
-
Body :
-
{
"message": "Alert deleted successfully"
}
- Errors :
-
404 Not Found
: Alert trigger with the specified ID does not exist. -
401 Unauthorized
: Invalid or missing JWT token.
-
- Fetch Alerts
-
Endpoint :
GET /api/alerts/
-
Description : Retrieves all alert triggers for the authenticated user with optional filtering and pagination.
-
Headers :
Authorization: Bearer <jwt-token>
-
Query Parameters :
-
status
(optional): Filter alerts by status (e.g.,created
,triggered
). -
page
(optional): Page number for pagination (default is 1). -
page_size
(optional): Number of alerts per page (default is 10).
-
-
Response :
-
Status Code :
200 OK
-
Body :
-
{
"count": 10,
"results": [
{
"id": 1,
"trigger_value": 50000,
"status": "triggered"
}
]
}
- Errors :
401 Unauthorized
: Invalid or missing JWT token.
Currently, I have only added functionality to track BTC prices.
The system monitors Bitcoin (BTC) price in real-time using Binance WebSocket. Alerts are generated when the price crosses user-defined trigger values. Alerts are then printed to the command line and sent via email.
-
WebSocket Connection : Establishes a connection to the Binance WebSocket API to receive real-time BTC price updates.
-
Trigger Comparison : Compares incoming price updates with stored user triggers.
-
Alert Generation :
-
Console Output : Prints alerts to the terminal when price triggers are met.
-
Email Notification : Sends email notifications to users using Celery and RabbitMQ.
-
Celery Worker : Handles background tasks, such as sending email notifications, asynchronously.
-
RabbitMQ : Acts as the message broker for Celery tasks.
-
Email Sending :
-
The
send_email
task is enqueued by Celery when a price trigger is activated. -
Emails are sent using the SMTP backend configured in Django settings.
-
Triggers Management : Users can view, create, and delete triggers through the front-end.
-
BTC Price Chart : Displays real-time BTC price data using TradingView widgets.