Skip to content

Instantly share code, notes, and snippets.

@djmeph
Last active September 28, 2018 19:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save djmeph/e26d7eb2634799c6bb32701e28cd7816 to your computer and use it in GitHub Desktop.
Save djmeph/e26d7eb2634799c6bb32701e28cd7816 to your computer and use it in GitHub Desktop.
Radically Self-Reliant Crypto Bot Workshop

Radically Self-Reliant Crypto Bot Workshop

Launch Ubuntu 16.04 EC2 Instance

  1. Select Ubuntu Server 16.04 LTS 64-bit
  2. Recommend General Purpose - t2.small instance type. (1 CPU core, 2GB RAM)
  3. Select a subnet. us-east-1x, us-east-2x, us-west-2x are $0.023/hr for t2.small
  4. Select 8GB GP2 SSD ($0.80/month)
  5. Tags are optional
  6. Create a new security group and call it crypto-bot. For now, leave port 22 open to Anywhere
  7. Review and Launch
  8. Select Create a new key pair, name it cryptobot and download the private key file. (cryptobot.pem)

At this point, view your new VPS in EC2 Instances and give it a unique name. Find the public domain for your instance and save it for later, we'll need it to establish an SSH connection.

looks like ec2-XXX-XXX-XXX-XXX.compute-1.amazonaws.com

Setup SSH Connection

Linux and Mac

Copy private key file to ~/.ssh

mv ~/Downloads/cryptobot.pem ~/.ssh/

Set permissions on private key file to owner can read and write

chmod 600 ~/.ssh/cryptobot.pem

Secure private key file with a password

ssh-keygen -p -f ~/.ssh/cryptobot.pem

Add alias to ssh config

nano ~/.ssh/config

Add the following entry at the end of the file.

Host cryptobot
        IdentityFile ~/.ssh/cryptobot.pem
        HostName ec2-XXX-XXX-XXX-XXX.compute-1.amazonaws.com
        User ubuntu

Save and exit.

Connect to server

ssh cryptobot

Type in your password and you will be logged into your remote instance. The first time you log in it will ask you to verify the ECDSA key fingerprint, type yes to bypass this prompt in the future.

Initial setup

First, let's bring the entire server up to date and reboot.

sudo apt-get update && sudo apt-get dist-upgrade -y && sudo shutdown now -r

Upon completion you will be disconnected from the server as it reboots. Wait 2 minutes and reconnect with ssh cryptobot

Install Profit Trailer Dependencies

Add apt repository for certbot, which will be used later.

sudo add-apt-repository ppa:certbot/certbot

These commands install Node.js, npm, essential build tools, Java Development Kit, nginx, and certbot for nginx. Should run with no prompts.

curl -sL https://deb.nodesource.com/setup_8.x | sudo -E bash -
sudo apt-get install -y nodejs build-essential openjdk-8-jre nginx python-certbot-nginx unzip
sudo npm i -g pm2

Now, set pm2 to launch at startup with systemd.

pm2 startup

Copy and paste the command, which should look something like this:

sudo env PATH=$PATH:/usr/bin /usr/lib/node_modules/pm2/bin/pm2 startup systemd -u ubuntu --hp /home/ubuntu

And create a pm2 config file.

pm2 save

Install Profit Trailer

Download latest release https://github.com/taniman/profit-trailer/releases

wget https://github.com/taniman/profit-trailer/releases/download/X.X.X/ProfitTrailer-X.X.X.zip
unzip ProfitTrailer-X.X.X.zip
mv ProfitTrailer-X.X.X ProfitTrailer

Edit application properties and set to test mode

cd ProfitTrailer/
nano application.properties

Fill in your license key, api token, exchange info, exchange API keys, time zone, and any other settings you want to change here. Make sure server.test_mode is set to true. Profit Trailer will intialize your settings and then you can tweak them through the interface later before taking it out of testing mode.

Your application.properties file should look like this:

license = xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
server.port = 8081
server.api_token =

server.sitename = My BTC Bot
trading.exchange = BINANCE
trading.log_history = 8

server.timezone_offset = -04:00
server.language = enus
server.skin = dark
server.currency = USD

server.disable_password = false
server.disable_config = false
server.disable_online_config = false
server.enable_shutdown = true
server.disable_notification = false
server.disable_browser = false

telegram.bot_token_1 =
telegram.chat_1 =
telegram.disable_notification = true

discord.bot_token_1 =
discord.chat_1 =

default_api_key     = xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
default_api_secret  = xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
trading_api_key     = xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
trading_api_secret  = xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

telegram.startup_notification = false
discord.startup_notification = false
telegram.shutdown_notification = false
discord.shutdown_notification = false

server.start_trading_delay = 0

#testmode does paper trading so you will see buy and sell activity.
server.test_mode = true

#timeout in seconds
connection.timeout = 30

#enabling debug modes when support asks you
#logging.level.nl.komtek = DEBUG
#logging.level.nl.komtek.pt.services = TRACE

Save the configuration and start the bot

pm2 start pm2-ProfitTrailer.json
pm2 save

View the logs to ensure a successful start

pm2 logs profit-trailer

The output should like this:

0|profit-t | 2018-05-19 03:13 +00:00: 
0|profit-t | 2018-05-19 03:13 +00:00:   .   ____          _            __ _ _2018-05-19 03:13 +00:00: 
0|profit-t | 2018-05-19 03:13 +00:00:  /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \2018-05-19 03:13 +00:00: 
0|profit-t | 2018-05-19 03:13 +00:00: ( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \2018-05-19 03:13 +00:00: 
0|profit-t |  \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
0|profit-t |   '  |____| .__|_| |_|_| |_\__, | / / / /
0|profit-t |  =========|_|==============|___/=/_/_/_/
0|profit-t | 2018-05-19 03:13 +00:00:  :: Spring Boot ::        (v1.5.9.RELEASE)2018-05-19 03:13 +00:00: 
0|profit-t | 2018-05-19 03:13 +00:00: 

0|profit-t | 2018-05-19 03:13 +00:00: 2018-05-19 03:13:22 INFO Application - PT Version: 2.0.3
0|profit-t | 2018-05-19 03:13 +00:00: 2018-05-19 03:13:22 INFO Application - Java Version: 1.8.0_171
0|profit-t | 2018-05-19 03:13 +00:00: 2018-05-19 03:13:24 INFO ConfigApi - Please finish the setup process in your browser

PressCTRL+C to quit. If you have any trouble getting Profit Trailer to start, consult the wiki or the #Support channel on Discord.

NGINX/SSL Setup

For this step I recommend using a subdomain of a domain you already own. Create a CNAME record in your DNS settings for the subdomain (ie. cryptobot.yourdomain.com) and point it to the address we used to connect to SSH earlier. (ec2-XXX-XXX-XXX-XXX.compute-1.amazonaws.com) Don't move on to NGINX setup until you've selected a domain and setup your DNS. We will need this domain later to encrypt the connection to the browser dashboard.

Open HTTP/HTTPS ports

In the EC2 Dashboard on AWS, select Security Groups in the list and select the Security Group you specified when you created the instance. Give it a unique name if it doesn't already have one. Edit the inbound rules and add HTTP and HTTPS (Ports 80 and 443) to the list, and make them accessible Anywhere.

Setup NGINX

sudo nano /etc/nginx/sites-available/cryptobot

Add the following settings to this file. Replace cryptobot.yourdomain.com with your chosen and configured domain name.

server {

    server_name cryptobot.yourdomain.com;

    location / {
        proxy_pass http://localhost:8081;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection 'upgrade';
        proxy_set_header Host $host;
        proxy_cache_bypass $http_upgrade;
    }

}

Save and exit. Now create a symlink to enable it.

cd /etc/nginx/sites-enabled/
sudo ln -s ../sites-available/cryptobot

Check to make sure the settings are OK before enabling them.

sudo nginx -t

If your configuration is suitable, you will see the following output:

nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

Restart NGINX

sudo systemctl restart nginx

SETUP SSL with Certbot

sudo certbot --nginx -d cryptobot.yourdomain.com

The first time you use Certbot it will ask for an email address, and it will ask you to agree to the terms of service. You must agree to the terms to use this feature. It will also ask you if you're willing to share your email address, and that is optional.

Each time you setup an HTTPS instance with certbot, it will ask if you want to automatically redirect unsecure traffic to your secure HTTPS server. I recommend enabling the redirect, just in case you forget to use https. (Option 2)

Finish Profit Trailer Setup

Visit your profit trailer site in a web browser using the secure HTTPS link. (ie. https://cryptobot.yourdomain.com)

The first thing you will be instructed to do is create a password. Make sure it's strong and stored in a safe, encrypted place. Personally, I use LastPass to generate random, secure passwords and to save them. In order to create a password you will need to verify the API key that is linked to your account.

After creating a password, you will be asked to select a name for your cryptobot settings profile. Name it whatever you want.

Once you have created your settings profile, you will see your dashboard, with your current balances, and it should say Test Mode in the top right corner.

Disclaimer:

This is a technical guide on how to setup a secure VPS for use with Profit Trailer. I offer no advice on which trading settings to use. Please, for your sake, do your research and test your settings before taking your bot out of test mode. It's very easy to lose money with the wrong settings. Consider yourself warned, and enjoy.

Lubuntu and vncserver setup

Install dependencies

sudo apt-get install -y lubuntu-core tightvncserver

Initialize VNC Server

vncserver

On the first run, Tight VNC will ask you to create a password that is used to connect to the server. You can also create a view-only password, but it is optional, and usually not necessary.

Stop the server

vncserver -kill :1

Edit your xstartup file and replace the last line

nano ~/.vnc/xstartup

#!/bin/sh

xrdb $HOME/.Xresources
xsetroot -solid grey
#x-terminal-emulator -geometry 80x24+10+10 -ls -title "$VNCDESKTOP Desktop" &
#x-window-manager &
# Fix to make GNOME work
export XKL_XMODMAP_DISABLE=1
/usr/bin/startlxde

Automatically start Tight VNC with systemd

Create systemd bash script:

sudo nano /etc/systemd/system/vncserver@.service

[Unit]
Description=Start TightVNC server at startup
After=syslog.target network.target

[Service]
Type=forking
User=ubuntu
PAMName=login
PIDFile=/home/ubuntu/.vnc/%H:%i.pid
ExecStartPre=-/usr/bin/vncserver -kill :%i > /dev/null     2>&1
ExecStart=/usr/bin/vncserver -depth 24 -geometry     1280x800 :%i
ExecStop=/usr/bin/vncserver -kill :%i

[Install]
WantedBy=multi-user.target

Enable and start new service

sudo systemctl daemon-reload
sudo systemctl enable vncserver@1.service
sudo systemctl start vncserver@1.service

Install Chromium Browser

sudo apt-get install -y chromium-browser

Setup VNC Client (Mac OS X)

Create a persistent SOCKS connection

ssh -L 1202:127.0.0.1:5901 -N -f -l ubuntu ec2-XXX-XXX-XXX-XXX.compute-1.amazonaws.com -i ~/.ssh/cryptobot.pem

Now, open Screen Sharing, which can be found via Spotlight search. Connect to 127.0.0.1:1202 and type in the password you created earlier. You should be able to open Chromium Browser now and the rest is up to you.

Resources used to write this tutorial

Installing node.js via package manager

https://nodejs.org/en/download/package-manager/#debian-and-ubuntu-based-linux-distributions

How To Set Up a Node.js Application for Production on Ubuntu 16.04

https://www.digitalocean.com/community/tutorials/how-to-set-up-a-node-js-application-for-production-on-ubuntu-16-04

How To Secure Nginx with Let's Encrypt on Ubuntu 16.04

https://www.digitalocean.com/community/tutorials/how-to-secure-nginx-with-let-s-encrypt-on-ubuntu-16-04

Profit Trailer Wiki

https://wiki.profittrailer.com/doku.php

How to Install and Configure VNC on Ubuntu 16.04

Note that I opted to use lubuntu instead of xfce. This is because lubuntu does a better job of emulating the graphical user interface when there is no OpenGL compliant GPU installed in the system.

https://www.digitalocean.com/community/tutorials/how-to-install-and-configure-vnc-on-ubuntu-16-04

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment