Skip to content

gulshandubbani2003/trading-platform-infra

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Trading Platform Infrastructure

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.

Architecture Overview

The platform consists of the following microservices:

  1. Historical Data Loader: Loads historical market data
  2. Price WebSocket Handler: Processes real-time price updates
  3. Indicator Service: Calculates technical indicators
  4. Evaluator Service: Evaluates trading signals
  5. DB Sync Service: Synchronizes data with the database
  6. Alert Sender: Sends trading alerts

Infrastructure Components

  • ECS (Fargate): Container orchestration
  • RDS (PostgreSQL): Database
  • SQS: Message queue for alerts
  • Lambda: Processes SQS messages
  • VPC: Network isolation
  • Security Groups: Network security

Prerequisites

  • AWS CLI installed and configured
  • Docker installed
  • Terraform installed
  • Python 3.9+
  • Git

Setup Instructions

1. Clone the Repository

git clone https://github.com/yourusername/trading-platform-infra.git
cd trading-platform-infra

2. Configure AWS Credentials

aws 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)

3. Create ECR Repositories

# 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

4. Build and Push Docker Images

# 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)

5. Deploy Infrastructure with Terraform

cd terraform

# Initialize Terraform
terraform init

# Review the planned changes
terraform plan

# Apply the infrastructure
terraform apply

6. Verify Deployment

# 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

Service Endpoints

  • 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

Monitoring and Logs

# View CloudWatch logs for a service
aws logs describe-log-groups --log-group-name-prefix /ecs/historical-data-loader --region ap-south-1

Cleanup

To destroy the infrastructure:

cd terraform
terraform destroy

Directory Structure

trading-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

Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Commit your changes
  4. Push to the branch
  5. Create a Pull Request

License

This project is licensed under the MIT License - see the LICENSE file for details.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages