Skip to content
Dan Wallace edited this page Sep 25, 2020 · 13 revisions

Welcome to the East Village Trading Bot Wiki!

Here you will learn how to go from zero to a self-running robot on a web-server. All these steps were done on Windows 10 (version 2004). Most of the steps occur when dealing with the amazon web server. Once you have logged into the server, everything will be in linux commands and will be the same for everyone. If you follow this step by step, exactly, you should be up and running in no time.

To simplify installation, go ahead and register accounts on these four sites. We will be pulling resources from them as we go.

Before we start:

Bookmark these sites and remember your logins as you may need to revisit these sites in the future.

Alright, now for the fun part. You are only 15 minutes away from having your own 24/7 stock trading robot.

Step 1

Step 2

Grab your API keys from Alpaca. Open your editor of choice, place them in config.py and save

###This works with live or paper trading. I recommend using the paper money api keys Alpaca api key Config.py api key entry

Step 3

Login to your AWS account

Sign into aws console

AWS console login

Step 4

Launch virtual machine

Create virtual aws machine

Step 5

Select amazon linux 2 (should be first in the list of results)

Amazon Linux

Step 6

Choose instance: select "t2.micro" -> Press: Review and Launch

Select Instance

Step 7

Review instance -> Press: Launch

Launch Instance

Step 8

Create key pair, download .pem file and press launch instance

Save the downloaded key pair to your user folder: (ex: C:/Users/your pc user name here/example.pem)`

Create Key-Pair

Step 9

Launch and view instance

View Instance

Step 10

Click any blank space in the instance (name field) and the instance summary will appear

Copy the Public IPv4 DNS address and place it in a text document for later

Amazon DNS

Step 11

Login to your ngrok account. After you login you will see see the screen below.

Download the linux (ARM64) file (this is for your linux server). And copy the authentication token into your notepad for later

ngrok authtoken and download

Step 12

Login to your ngrok account. After you login you will see see the screen below.

Download the linux (ARM64) file (this is for your linux server). And copy the authentication token into your notepad for later

ngrok authtoken and download

HALFWAY THERE! You should have a text document for reference that looks like this now:

notepad progress

Step 13 (Microsoft Windows users only)

Install WSL version 2 (windows subsystem for linux). Follow Microsoft's WSL install guide

** SKIP IF: wsl is already installed or you are running macOS or linux **

Step 14 (Microsoft Windows users only)

Open Powershell and type" WSL "

** SKIP IF: you are running macOS or linux **

wsl

Step 15

Once WSL is run in PowerShell (or you are in macOS/linux terminal), copy and paste the text below (replace the path and file name with your own)

  1. cp /mnt/c/Users/YOUR_PC_USER_NAME_HERE/example_REPLACE_with_Your_own.pem ~/example_REPLACE_with_Your_own.pem

Step 16

We need to change the file permissions so copy and paste this chmod command (replace with your linux subsystem username and .pem file name)

  1. chmod 400 /home/YOUR_LINUX_SUBSYSTEM_USERNAME_HERE/example_REPLACE_with_Your_own.pem

Step 17

SSH to server using the following line (remember to place with your own .pem file path and your own amazon DNS

Your PowerShell may ask if you are sure you want to connect. If so, type yes.

  1. ssh -i "/home/YOUR_LINUX_SUBSYSTEM_USERNAME_HERE/example_REPLACE_with_Your_own.pem" ec2-user@COPY_AND_PASTE_THE_SERVER_DNS_FROM_YOUR_NOTEPAD_HERE

Example

ssh to server

Step 18

Now that we have successfully entered our server, copy and paste the following lines into PowerShell:

  1. sudo yum update
  2. sudo amazon-linux-extras install python3.8
  3. sudo yum -y install python3-pip
  4. sudo yum install python-virtualenv

After running all 4 lines my terminal looks like this:

After install

Step 19

Copy and paste the lines below into your terminal:

  1. mkdir myproject
  2. cd myproject
  3. python3 -m venv venv

example directory

Step 20

Create a virtual environment, this is where we will run our bot. (copy and paste the line below into your terminal)

  1. . venv/bin/activate

Step 21

Install flask and requests in the virtual environment (copy and paste the lines below into your terminal)

  1. pip install flask
  2. pip install requests

Step 22

Open FileZilla and go to EDIT -> settings -> SFTP

1. Click on "Add key file" and find your key-pair.pem for your server and click open

2. Click "OK" to exit settings

sftp example

Step 23

Open Site Manager

  1. Locate File on the top bar and click the button directly below it (see screenshot for example)
  2. Click New site
  3. Change protocol to SFTP - SSH Transfer Protocol
  4. Grab your Amazon host DNS from your note pad and paste in the Host: field
  5. Enter ec2-user for the user field (leave password blank)
  6. Click connect
  7. (You may get a window that says "Unknown host key". Press "OK" if you do.

FileZilla Connect

Step 24

Drag config.py, bot.py, and ngrok-stable-linux-amd64.zip over to the server's /home/ec2-user/myproject/ folder

Almost the right place

Place files here

Step 25

Unzip ngrok (copy and paste the command below into your terminal)

  1. unzip /home/ec2-user/myproject/ngrok-stable-linux-amd64.zip

unzip

Step 26

Open a new "screen" (copy and paste the command below into your terminal). This will open a blank terminal screen

  1. screen -S ngrok

new screen

Step 27

You can think of a screen as a window. We will run our programs in screens and detach to leave them running (like minimizing a window)

  1. First, copy and paste the ./ngrok authtoken from your notepad and paste it in the new "screen"
  2. Copy the line below to launch ngrok and press enter ~/myproject/ngrok http 5000

http 5000

Step 28

Your screen should look like the one below. Copy the forwarding url to your notepad. This is your webhook url to use on tradingview.

forwarding url

Press CTRL A+D to detach from screen. Below is a guide on how to operate screens for your future reference:

  1. screen -ls - lists all attached/detached screens
  2. screen -r screen_name_here - Re-attaches to detached screen
  3. screen -S screen_name_here - Starts a new screen with the name screen_name_here (replace with the name you want)
  4. CTRL+A+D = Detach from screen
  5. CTRL+C = Quits the currently attached screen (we generally don't want to do this if we want our bot to stay on).

Step 29

Now we want to run our bot. Copy and paste the following line to do so:

python3 bot.py

start bot

Step 30

Create a alert on trading view for a stock/strategy of your choice

Place your webhook url from your notepad in the url field. Make sure to add "/webhook" on the end of it

Copy the following code into the alert message:

  1. { "symbol": "{{ticker}}", "qty": "{{strategy.order.contracts}}", "side": "{{strategy.order.action}}", "type": "market", "time_in_force": "gtc" }

You are DONE!

You can now watch trades come in from your PowerShell window (only will trade when alerted by trading view)

1. Whenever you are ready, Press CTRL+A+D to detach from your bot window in PowerShell

2. Exit Powershell

3. Your bot will now run 24/7. All you need to do now is set the trading view alerts and strategies!


Have fun!

Disclaimer: I have only done this with paper trading, but it works just as well with live trading. Trade with real money at your own risk!

Clone this wiki locally