This repository contains the infrastructure code for a real-time trading platform built using AWS services. The platform processes market data, calculates technical indicators, evaluates trading signals, and sends alerts.
The platform consists of the following microservices:
- Historical Data Loader: Loads historical market data
- Price WebSocket Handler: Processes real-time price updates
- Indicator Service: Calculates technical indicators
- Evaluator Service: Evaluates trading signals
- DB Sync Service: Synchronizes data with the database
- Alert Sender: Sends trading alerts
- ECS (Fargate): Container orchestration
- RDS (PostgreSQL): Database
- SQS: Message queue for alerts
- Lambda: Processes SQS messages
- VPC: Network isolation
- Security Groups: Network security
- AWS CLI installed and configured
- Docker installed
- Terraform installed
- Python 3.9+
- Git
git clone https://github.com/yourusername/trading-platform-infra.git
cd trading-platform-infraaws configure
# Enter your AWS Access Key ID
# Enter your AWS Secret Access Key
# Enter your default region (ap-south-1)
# Enter your output format (json)# Create ECR repositories for each service
aws ecr create-repository --repository-name historical-data-loader --region ap-south-1
aws ecr create-repository --repository-name price-websocket-handler --region ap-south-1
aws ecr create-repository --repository-name indicator-service --region ap-south-1
aws ecr create-repository --repository-name evaluator-service --region ap-south-1
aws ecr create-repository --repository-name db-sync-service --region ap-south-1
aws ecr create-repository --repository-name alert-sender --region ap-south-1# Authenticate Docker with ECR
aws ecr get-login-password --region ap-south-1 | docker login --username AWS --password-stdin 941860342175.dkr.ecr.ap-south-1.amazonaws.com
# Build and push each service
cd docker/historical-data-loader
docker build -t historical-data-loader .
docker tag historical-data-loader:latest 941860342175.dkr.ecr.ap-south-1.amazonaws.com/historical-data-loader:latest
docker push 941860342175.dkr.ecr.ap-south-1.amazonaws.com/historical-data-loader:latest
# Repeat for other services
cd ../price-websocket-handler
docker build -t price-websocket-handler .
docker tag price-websocket-handler:latest 941860342175.dkr.ecr.ap-south-1.amazonaws.com/price-websocket-handler:latest
docker push 941860342175.dkr.ecr.ap-south-1.amazonaws.com/price-websocket-handler:latest
# ... (repeat for other services)cd terraform
# Initialize Terraform
terraform init
# Review the planned changes
terraform plan
# Apply the infrastructure
terraform apply# Check ECS cluster status
aws ecs describe-clusters --clusters trading-cluster --region ap-south-1
# List running services
aws ecs list-services --cluster trading-cluster --region ap-south-1
# Check service status
aws ecs describe-services --cluster trading-cluster --services historical-data-loader-service --region ap-south-1
# Get task details
aws ecs list-tasks --cluster trading-cluster --service-name historical-data-loader-service --region ap-south-1
aws ecs describe-tasks --cluster trading-cluster --tasks <task-id> --region ap-south-1- Historical Data Loader:
http://<service-ip>/load-historical-data - Price WebSocket Handler:
ws://<service-ip>/ws - Indicator Service:
http://<service-ip>/calculate-indicators - Evaluator Service:
http://<service-ip>/evaluate-signals - DB Sync Service:
http://<service-ip>/sync - Alert Sender:
http://<service-ip>/send-alert
# View CloudWatch logs for a service
aws logs describe-log-groups --log-group-name-prefix /ecs/historical-data-loader --region ap-south-1To destroy the infrastructure:
cd terraform
terraform destroytrading-platform-infra/
├── docker/
│ ├── historical-data-loader/
│ ├── price-websocket-handler/
│ ├── indicator-service/
│ ├── evaluator-service/
│ ├── db-sync-service/
│ └── alert-sender/
├── lambda_function/
│ ├── lambda_function.py
│ └── requirements.txt
├── terraform/
│ ├── main.tf
│ ├── variables.tf
│ └── outputs.tf
└── README.md
- Fork the repository
- Create a feature branch
- Commit your changes
- Push to the branch
- Create a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.