This project implements a simple trading bot on AWS that uses an SMA20 strategy. It runs in AWS Lambda, stores trades in DynamoDB and can be triggered via an HTTP API (API Gateway). The project is designed to be AWS-native with all infrastructure managed through Terraform.
- Binance Spot Testnet integration
- SMA20 buy/sell trading logic
- Secure API key storage via Secrets Manager
- Trade history in DynamoDB
- Scheduled execution via CloudWatch Events
- Configurable deployment via Terraform
- Local development support
- AWS Lambda - Runs the trading bot code
- AWS API Gateway - Provides HTTP endpoint to trigger bot
- AWS DynamoDB - Stores trading signals and history
- AWS Secrets Manager - Securely stores Binance API credentials
- AWS CloudWatch - Monitors and logs bot execution
- AWS IAM - Manages permissions
- AWS S3 - Stores Lambda deployment packages
- AWS CLI configured with appropriate permissions
- Terraform v1.0.0+
- Python 3.11
- Binance account with API keys
The deployment must be done in multiple phases to handle dependencies correctly:
# Clone the repository
git clone https://github.com/yourusername/aws-crypto-trading-bot.git
cd aws-crypto-trading-bot
# Set up Python virtual environment
python -m venv venv
source venv/bin/activate
pip install -r lambda/requirements.txt
# Create and configure your .env file for local testing
cp .env.example .env
# Edit .env with your Binance API credentials
# Phase 1: Create only the S3 bucket first
cd terraform
terraform init
terraform apply -target=aws_s3_bucket.lambda_bucket
# Phase 2: Package and upload Lambda components
cd ..
# Create the Lambda layer (dependencies)
./scripts/create_layer.sh
# Note the Layer ARN from the output and update it in terraform/lambda.tf
# Package and upload the Lambda function code
./scripts/package_lambda.sh
# Phase 3: Create everything else
cd terraform
terraform apply
To test the bot locally:
source venv/bin/activate
python lambda/bot.py
To trigger the deployed Lambda function:
aws lambda invoke \
--function-name crypto_trading_bot \
--payload '{}' \
response.json
The bot follows a serverless architecture pattern:
- Lambda function runs on schedule or via API Gateway
- Bot fetches price data from Binance
- SMA20 algorithm generates buy/sell signals
- Signals are stored in DynamoDB
- CloudWatch monitors execution and logs results
A dashboard to visualize the trades and configure the strategies (React + Tailwind CSS).
This project follows an iterative development approach:
- CHANGELOG.md tracks all changes
- CLAUDE.md contains build commands and style guidelines
- Security best practices enforced throughout