Configure And Run Freqtrade On Digitalocean Droplet + Supervisor + Nginx

Sait Maraşlıoğlu
6 min readMay 12, 2021

In this article, I will try to explain how to set up Freqtrade on an Ubuntu, running multiple instances and remote frequi accesss.

Create a droplet

Head towards digitalocean.com and create a droplet .

(This link contains my referral, you get 100 $ to spend in 6 months, if you spend 25 $, I get 25$ to spend)

Creating droplet is simple and most of your preferences not relevant to our article, but I want to give you a minimal setup which will cost you about 5 $ a month, to my experience you can run up to 3 bots at once with this system. When changing this preferences, only make sure you keep Ubuntu 20.04 as your distribution.

Distribution must be Ubuntu to follow this article
I preferred here 5 $ plan, which is cheapest. to my experience you can run up to 3 bots together with this.
Doesn’t matter which one you choose, preferably choose something close to your exchange.
Set your password
Give your droplet a name and make sure you are creating only 1 droplet

If you don’t have anything missing, you should be able to create your droplet.

After creating your droplet, it should be up and running in seconds.

Under droplets menu, you will see your newly created droplet and you can obtain its IP.

Connecting to our Droplet

Since my system is also Ubuntu I will use a terminal to connect to my droplet but If you are on a windows, you can use Putty to connect to your droplet.

On Ubuntu open a terminal and type ‘ssh root@YOUR_DROPLET_IP’, it should ask you for your password, type the password you set when creating your droplet.

Now you know how to connect to your droplet.

Install required packages

sudo apt update
sudo apt upgrade
sudo apt install python3-pip
sudo apt install python3-venv

Install Freqtrade

cd /home/
mkdir workspace
cd workspace/
git clone https://github.com/freqtrade/freqtrade.git
cd freqtrade
git checkout develop
./setup.sh -i

Above commands are self explanatory, first we created a folder called “workspace” to hold everything related this setup, later we pulled git repository from freqtrade public library and install.

During installation process, you will be asked a few questions, these are how I answered.

Reset git branch? (This will remove all changes you made!) [y/N]? y

Do you want to install dependencies for dev [y/N]? yDo you want to install plotting dependencies (plotly) [y/N]? yDo you want to install hyperopt dependencies [y/N]? y

Remember, every time you want to use some Freqtrade commands (trade, backtest etc.) you have to activate your virtualenv.

cd /home/workspace/freqtrade/
source .env/bin/activate

Initialize the configuration

freqtrade create-userdir --userdir user_data
freqtrade new-config --config config.json

When creating our new config, you will be asked a few questions.

? Do you want to enable Dry-run (simulated trades)? Yes
? Please insert your stake currency: BTC
? Please insert your stake amount: 0.01
? Please insert max_open_trades (Integer or 'unlimited'): 3
? Please insert your desired timeframe (e.g. 5m): 5m
? Please insert your display Currency (for reporting): USD
? Select exchange binance
? Do you want to enable Telegram? No
? Do you want to enable the Rest API (includes FreqUI)? No

We didn’t activate Telegram or Rest API on purpose, to make things simple for now. It’s a dry run, so free free to check if your bot actually starts.

freqtrade trade --config config.json --strategy SampleStrategy

Activate Telegram

In your config.json file, telegram part looks something like this.

"telegram": {
"enabled": false,
"token": "",
"chat_id": ""
}

We will need a token and chat_id.

Token :

1 - Find BotFather on telegram

2 - Send “/newbot” to BotFather

3 - Choose a name and username for your bot, BotFather should send you the token we need. Also there will be a link to your bot, click that link to find your bot and start it.

Chat Id :

1- Find userinfobot on telegram.

2 - Send “/startbot”, userinfobot should give you your id.

It’s all set, now you can put token and chat_id in place and enable telegram integration. Your final code block should be looking something like this.

"telegram": {
"enabled": true,
"token": "YOUR_TOKEN",
"chat_id": "YOUR_CHAT_ID"
}

Activate FreqUI

Install frequi

freqtrade install-ui

In your config.json file, your frequi code block will be similar to this.

"api_server": {
"enabled": false,
"listen_ip_address": "127.0.0.1",
"listen_port": 8080,
"verbosity": "error",
"enable_openapi": false,
"jwt_secret_key": "80d23ec6ec0ed760497a69ewrvwrw50f69ff6c69b2a27e0f668783266b8fff09d648c7",
"CORS_origins": [],
"username": "",
"password": ""
},

If we set it to enabled and set our username and password, it should work.

"api_server": {
"enabled": true,
"listen_ip_address": "127.0.0.1",
"listen_port": 8080,
"verbosity": "error",
"enable_openapi": false,
"jwt_secret_key": "80d23ec6ec0eewrtwerewwwwwwwd760497a69e50f69ff6c69b2a27e0f668783266b8fff09d648c7",
"CORS_origins": [],
"username": "SET_YOUR_USERNAME_HERE",
"password": "SET_YOUR_PASSWORD_HERE"
},

Install Supervisor

Problem with our installation is , we cannot run and control more than one bot, I find supervisor super simple and effective to use.

sudo apt install supervisor

Supervisor is located at /etc/supervisor/ and “conf.d” folder will contain our supervisor configuration files. Freqtrade configuration file may look like this.

filename = /etc/supervisor/conf.d/freqtrade1.conf

[program:freqtrade1]
command=/home/workspace/supervisor/freqtrade1/freqtrade1.sh
autostart=false
autorestart=true
stderr_logfile=/home/workspace/supervisor/freqtrade1/err.log
stdout_logfile=/home/workspace/supervisor/freqtrade1/out.log
stopasgroup=true
stopsignal=QUIT

This basically tells supervisor that we have a program called freqtrade1, once we want to start it it should run a script at “/home/workspace/supervisor/freqtrade1/freqtrade1.sh”, and put related log files into specified locations.

Now we have to create this sh file.

cd /home/workspace/
mkdir supervisor
cd supervisor/
mkdir freqtrade1

In freqtrade1 folder we will put following file.

filename = /home/workspace/supervisor/freqtrade1/freqtrade1.sh

#!/bin/bash

cd /home/workspace/freqtrade/
source .env/bin/activate
freqtrade trade --config config_freqtrade1.json --strategy SampleStrategy

This script basically does what we do when we want to start our bot. We told him to go to freqtrade folder, activate virtualenv and run “freqtrade trade” command.

You may have notices we used “config_freqtrade1.json” for our new bot. So you have to create your config file under freqtrade folder with this name.

Since we add a new program to supervisor

supervisorctl update

Start Bot

supervisorctl start freqtrade1

Your bot should be started, if you wonder whats with logs

cd /home/workspace/supervisor/freqtrade1/tail err.log -f

Files used to create your bot are located at,

/etc/supervisor/conf.d/freqtrade1.conf

/home/workspace/supervisor/freqtrade1/freqtrade1.sh

With supervisor succesfully installed and configured, you can basically reproduce files with different names and create new bots for supervisor to take care of.

Supervisor commands:

supervisorctl start all (This starts all configured bots)
supervisorctl stop all (Stops all bots)
supervisorctl start freqtrade1 (Starts only freqtrade1)
supervisorctl stop freqtrade1 (Stops only freqtrade1)
supervisorctl reread (whenever your supervisor conf files changes, use this to update your process)
supervisorctl update (adds new configurations files to its known processes)

Activate FreqUI Remote Access

Frequi is active in our installation but we need to access it from anywhere.

To do that, we will use nginx.

sudo apt install nginx

We will create our site in sites-available folder and create a symbolink to sites-enabled folder.

File name : /etc/nginx/sites-available/freqtrader1_nginx

server {
listen 9000;
server_name YOUR_DROPLET_IP;

location / {
proxy_pass http://127.0.0.1:8080;
}
}

And create symbolink

ln -s /etc/nginx/sites-available/freqtrader1_nginx /etc/nginx/sites-enabled/

Restart nginx , if you need to

sudo service restart nginx

Assuming that our config files rest api port 8080, we made it avaiable at SERVEIP:9000

If everything everything worked fine, you should be able to visit your frequi at YOUR_DROPLET_IP:9000.

If you have more than one bot running, you can create multiple sites, using different ports.

Final words

As I mentioned earlier, this system was enough for 3 bot running simultaneously.

Hope this will be useful for somebody, Freqtrade documentation is very clear about installation, with supervisor and nginx, you should be all set.

--

--