Nhảy tới nội dung

Get started

Auto Trading Bot

Crypto trading bot integrated with Amazon Web Services, Trading Signal Provider and Exchange Platform.

Introduction

Crypto trading is always my passion then today I would like to create a basic workflow of the auto trading bot which receiving webhook consumer and processed by AWS API Gateway and Lambda, then placing the order on an exchange platform together with sending the message notification through your smart phone.

The Auto Trading Bot requires some side services in order to integrate with AWS as below:

Trading Signal Provider

I would like to pick the simple Bollinger Band strategy written in Pine Script and applied in TradingView to receive trading signals through a webhook provider.

AWS API Gateway

REST API Gateway created to process the signal from the webhook integrated with Lambda main function and authorized by Lambda Authorizer.

  • Lambda Authorizer: Authorizing only allowed the white IP list sent from trading signal provider.
  • Lambda Main Function: Process the trading signal such as BUY or SELL and size, then automatically place the order on the exchange platform. In this case, I am going to pick dYdX decentralized trading platform since I got familiar with for a while. Practically, you can select whatever exchange platforms which provide the Trading APIs.

AWS Lambda Main Function

Written in Python 3.12. The function includes codes to implement the followings:

  • Connect to the exchange platform, check the sufficient collateral and place an order.
  • Send the message notification through Discord to your smart devices.

Requirements

Project structure

If configured properly, the project structure will be shown under the working directory \auto-trading-bot as below:

auto-trading-bot
├── auto_trading_bot_api
│ ├── __init__.py
│ └── auto_trading_bot_api_stack.py
├── auto_trading_bot_ecr
│ ├── __init__.py
│ └── auto_trading_bot_ecr_stack.py
├── build-spec
│ └── docker_build_buildspec.yml
├── custom_auth_lambda_function
│ └── customauthlambda.py
├── docker-build
│ ├── app.py
│ ├── Dockerfile
│ ├── send_message.py
│ └── utils.py
├── s3source
│ └── docker-build.zip
├── app.py
├── README.md
└── requirements.txt

Project structure rundown

  • /auto_trading_bot_api/ - 2nd Stack created with REST API Gateway with Lambda integrated.
  • /auto_trading_bot_ecr/ - 1st Stack created with AWS ECR, Docker Image and CodePipeline.
  • /build-spec/ - contains build spec file docker_build_buildspec.yml.
  • /custom_auth_lambda_function/ - Lambda Authorizer.
  • /docker-build/ - all files needed to build the docker image for Lambda main function.
  • /s3source/ - for 1st deployment by CodePipeline.
  • /app.py - main project function.
  • /README.md - Introduction and Instructions.
  • /requirements.txt - for required packages' installation.