, pub-7590763259720133, DIRECT, f08c47fec0942fa0
top of page

Crypto Automated Trading Bot (ETF) with Trailing Stop Loss

Updated: Jan 24, 2022

Setup a trading bot that will auto-rebalance your portfolio just like an ETF.
Balanced and Automated Cryptocurrency Portfolio

This tutorial will set up an open-source automated cryptocurrency trading bot on an Ubuntu virtual private server (VPS). You can host the bot on a small, low-performance server.

I take no credit for the creation of this bot; I'm only providing expanded implementation documentation. I was inspired by this Reddit post by u/Travalgard. He is the creator and maintainer of this bot. All praise or donations should be directed towards him. The bot's Github can be found here.



  • Auto-rebalances your portfolio like an Exchange Traded Fund (ETF)

  • If the portfolio retracts by 20%, an integrated trailing stop liquidates the portfolio to USDT

  • Automatically excludes stablecoins

  • It's possible to include or exclude any coin

  • Auto-invests in the top 50-100+ coins by market cap

  • Integrated dollar-cost-averaging (DCA)




Virtual Private Server Recommendations

A VPS with the following specifications should be sufficient:

Virtual CPUs: 1 Core

Memory Size: 0.5 GB

Disk Space: 10 GB

Bandwidth: 0.5 TB

Virtual CPUs: 1 Core

Memory Size: 0.5 GB

Disk Space: 10 GB

Bandwidth: Unlimited @ 400mbps

Price: $2.00 USD Monthly

Virtual CPUs: 1 Core

Memory Size: 0.5 GB

Disk Space: 10 GB

Bandwidth: 0.5 TB

Price: $2.50 USD Monthly

Virtual CPUs: 1 Core

Memory Size: 1 GB

Disk Space: 15 GB

Bandwidth: 1 TB @ 1000mbps

Price: $3.20 USD Monthly

Virtual CPUs: 4 Cores

Memory Size: 6 GB

Disk Space: 80 GB

Bandwidth: Unlimited @ 100mbps

Price: $7.00 USD Monthly



You should complete the following guides in their entirety to secure your server.

You will need to sign up for a Exchange account and create an API key.

  1. Signup for a Exchange account

  2. Once logged in, go to settings API Keys

  3. Create a new API key

  4. Make sure you select Enable Trading

  5. Save the Secret Key somewhere safe

You must create a account and generate a new API key API Keys



Depending on your VPS provider, the server could be ready instantly or take up to 24 hours.

Once the VPS has been created successfully, your provider will send you a confirmation email that contains the server IP address and password.

Establish an SSH connection with your server. Make sure your server is fully updated using the following command:

sudo apt update -y && sudo apt full-upgrade -y && sudo apt autoremove -y && sudo apt clean -y && sudo apt autoclean -y

This command will perform the following:

  • update - updates the list of packages but do not install

  • upgrade - install new versions of packages if new versions are available

  • full-upgrade - performs the function of an upgrade but will remove currently installed packages if this is needed to upgrade the system as a whole (fixing bad dependencies)

  • autoremove, autoclean and clean - clean old packages which are not needed anymore

  • option -y does not request permission on every step

  • && states that it runs the next command if the previous was successfully executed



The bot is running on NodeJS, and it is presumed you will want to run it with a process manager such as PM2 to automatically restart it in case of failure and keep it running when you detach from the terminal session. The following steps will make sure you have all prerequisites installed, and the repository downloaded.

Install NodeJS

Both the bot itself and the process manager will be run on NodeJS. You can install NodeJS with:

 sudo apt-get install nodejs

After NodeJS is installed, check the version with:

sudo node -v

The required minimum version is 14. If the version shown is lower than that, you can upgrade it by executing the following command:

sudo curl -sL | sudo bash -

After you have done that, you can install the new NodeJS version by executing:

sudo apt-get install nodejs

Install NPM

The Node Package Manager (NPM) is required to install package requirements for the bot and can be installed with:

 sudo apt-get install npm

If it has not been installed already.

Install PM2

PM2 is a process manager that will keep your bot running as well as restart it after failure. It can be installed with:

sudo npm install pm2 -g

Install Logrotate

The log file generated by the process manager will grow indefinitely. To prevent that, we will install logrotate, which will neatly split up our log file into several log files (one for each day) and delete files older than 30 days. It can be installed with:

sudo pm2 install pm2-logrotate

Install Git

Git will be used to clone the repository and keep the bot up to date. You can install it with:

sudo apt-get install git



We now need to download and compile the source code and install the package requirements. The following steps will lead you through that process.

Clone the Bot

Navigate to the folder you want MCRBot to be located in, .i.e.,

sudo cd MCRBot 

Then run:

sudo git clone

To clone the repository.

Compile the Bot

Navigate into the bot folder, i.e,

sudo cd MCRBot

And run:

sudo sh 

To download all package requirements and compile the source code. You will be asked to name your bot to your liking (You can leave it MCRBot, too).



To configure the bot:

sudo cd MCRBot

And then,

sudo nano config.ts 

You should see the following list of configuration options:

Modify the configuration option of the trading bot for a custom configuration
Automated Trading Bot Configuration Options


  • Enter the APIKEY you received from the Exchange API

  • Enter the SECRET you received from the Exchange API

  • QUOTE is best left in USDT as this has the most trading pairs on the Exchange

  • INVESTMENT defines the dollar-cost-average (DCA) amount. Whatever number you set here will be invested once a day, i.e., $25 once per day spread amongst 50-100+ coins

  • TRAILING STOP > ACTIVE should be set to true if you want the bot to liquidate your portfolio if it suffers a loss of 20%

If you need more detailed explanations of what each option does, read the comments in the configuration file. They should explain things well enough. When you are done, save the file:

Hit Ctrl+X, Y for Yes, and then Enter to confirm the File Name to Write (Save).


Starting, Restarting, and Stopping

You can easily start, restart and stop the bot by executing the corresponding scripts, either with:



Monitoring and Logs

To monitor your currently running bot, enter:

pm2 monit 

And select it with the arrow keys in the list on the left. If you would like to check the log files, you can usually find them under:


Or you can check the latest log lines with:

pm2 logs MCRBot

For more PM2 commands, visit the Quick Start Page.


Updating the Bot

To update the bot to the newest version, execute:


This will also automatically restart your bot after the update. Your current configuration will remain the same.


In this tutorial, you have learned how to install, modify, and build an automated cryptocurrency trading bot.

You are welcome to comment below with any questions or comments.

If you found this article informative, please support my efforts by donating to my Ethereum ENS address: geekbyte.eth

308 views2 comments
bottom of page