In this tutorial, I will show you step by step, how to deploy your Jesse project from your local into a VPS for production.
I highly recommend using a VPS for production instead of running the bot on your local machine. The reason being that your local machine is not as reliable as a server. It has a better Internet connection, and there's less chance of accidents such as power outages.
Installation and configuration of a Linux VPS seem scary to some users. But don't worry, because I have made a script that makes the installation super easy.
Here are a list of providers that I recommend based on my experience:
I'll be using an Ubuntu 18.04 VPS which is offered by almost all cloud providers.
I've been using Hetzner for past years because not only it has the cheapest price, but also it has the highest quality among providers that I tried. Its starting plan which comes with 1 core CPU and 2GBs of RAM is what I've been using for running Jesse and it costs only €2.96 per month. You can use my referral link which gives you €20 free credits at the time of sign up. That is months of the server for free!
After logging into your Hetzner account, choose the default project, or create a new one. Then click on the red "Add server" button. You can choose the location of the server as whatever you want it to be.
As for the "Image", I'll be choosing
Leave the rest be. The beginning €2.96 is more than enough.
Next, you need to add/choose an SSH key and give your server a name. The name could be anything you want it to be. As for the SSH key, if you have one, just copy it from your local system and add it. If you haven't created one already, go you Gitlab's guide and follow the instruction to create one. It'll only take a minute. And then, add it into the SSH key section:
Now go ahead and click on "CREATE & BUY NOW".
Connect to the server we just created on Hezner, by opening a terminal and typing:
# "servers_ip" should be the IP address of your server ssh [email protected]_ip
Now execute below command which is from my "stack installer repository:
source <(curl -fsSL https://raw.githubusercontent.com/jesse-ai/stack-installer/master/ubuntu-18.04.sh)
It'll take a few minutes for the installation to go through. After that, your server has all that it needs to run Jesse.
Let's create a new Jesse project on our local machine. I'm on a macOS machine. After going into your desired location, run:
# bot1 is the name of my project. It could be anything you want jesse make-project bot1
And next I cd into it:
Let's copy a strategy called "SMACrossover" from the "[example strategies](https://github.com/jesse-ai/example-strategies" repository which contains a few strategies submitted by the community members.
Next, I create a new strategy and name it
SMACrossover by executing:
jesse make-strategy SMACrossover
Next, I paste the contents of SMACrossover into
strategies/SMACrossover/__init__.py in my project.
If you are reading this, I assume you already have a valid license for the live trade plugin. If you don't, please head over to Jesse's website, register, and purchase a license.
Next, go to the "releases" page and download the latest version for (in this case)
Linux - x86_64:
Now move the download package into your project files.
I'll be using Gitlab to host my project privately, and then of course to retrieve it from my server.
If you're not familiar with Git, I highly recommend checking out this YouTube video to get started with it. Git is a very useful version manager and services such as Gitlab or Github are real-life savers for development.
First, I create a new private project on Gitlab and give it a name. In my case, I entered
bot1. Make sure that the "Visibility Level" is set to
Now I need to push my project files into the repository. I do that by opening the terminal, and going into the project, and running:
cd bot1 git init git remote add origin [email protected]:saleh-mir/bot1.git git add . git commit -m "Initial commit" git push -u origin master
Now I need to retrieve the files from the server. The first thing I need to do is to give my VPS access to this private repository. For that, I need to create an SSH key, and add it to my Gitlab account's SSH:
It'll ask for the location to store my keys, and I just choose the default one by pressing
Enter. Next, it'll ask for a passphrase, which I skip by pressing
Enter. And of course, one more time for confirmation.
After that, my keys are generated and I can see it by executing:
I now copy my SSH key and paste it into my Gitlab accounts SSH keys page:
And finally, click on "Add key".
Now I open the terminal tab that has the VPS open in it, and clone this repository by typing:
git clone [email protected]:saleh-mir/bot1.git
yes for confirmation. Now open the project by typing
cd bot1. Notice that our project is missing the
routes.py files. That's because they are added into the
.gitignore files of projects created by Jesse. This is to make sure that your sensitive API keys and such, are not accidentally pushed to the repository.
So I create them back by just copying the content of each from my local, and paste it in the server:
# after pasting, press CTRL + C, and then Y to confirm and save the file. nano config.py
Now I do the same for
# after pasting, press CTRL + C, and then Y to confirm and save the file. nano routes.py
Here is the content of
routes.py that I copied. You can modify it as you need:
# trading routes routes = [ # notice that the exchange should be either "Binance Futures" or "Testnet Binance Futures" and NOT "Binance" ('Testnet Binance Futures', 'BTC-USDT', '1m', 'SMACrossover'), ] # in case your strategy requires extra candles, timeframes, ... extra_candles = [ # ('Binance', 'BTC-USDT', anchor_timeframe('4h')), ]
Of course, we also need a database. PostgreSQL has already been installed using the script we just used. So let's create one by below commands:
# switch to postgres user sudo su - postgres # open PostgreSQL CLI psql # create database CREATE DATABASE jesse_db; # create new user CREATE USER jesse_user WITH PASSWORD 'password'; # set privileges of the created user GRANT ALL PRIVILEGES ON DATABASE jesse_db to jesse_user; # exit PostgreSQL CLI \q # exit postgres user (back to root) exit
Since I am already inside my project which has the live trade plugin's package in it, I can easily install it with pip:
pip install jesse_live-0.0.2-cp38-cp38-manylinux2010_x86_64.whl
Now I should see the successful installation message:
Successfully built starkbank-ecdsa Installing collected packages: starkbank-ecdsa, jesse-live Successfully installed jesse-live-0.0.2 starkbank-ecdsa-1.1.0 WARNING: Running pip as root will break packages and permissions. You should install packages reliably by using venv: https://pip.pypa.io/warnings/venv
Now I need to log in by typing:
This will ask for my email and password which I entered at the time of registration on Jesse's website. If it goes well you should see:
Now let's confirm that the live trade plugin is installed correctly by typing:
The output should have the
paper modes in it:
➜ bot1 git:(master) ✗ jesse Usage: jesse [OPTIONS] COMMAND [ARGS]... Options: --version Show the version and exit. --help Show this message and exit. Commands: backtest backtest mode. import-candles imports historical candles from exchange live trades in real-time on exchange with REAL money login (Initially) Logins to the website. make-project generates a new strategy folder from... make-strategy generates a new strategy folder from... optimize tunes the hyper-parameters of your strategy paper trades in real-time on exchange with PAPER money routes lists all routes
In order for Jesse to be able to connect to the server, I have to enter my API keys, and for it to be able to send me notifications I have to enter my keys for either Telegram or Discord (or both!).
I can do that by modifying the
live-config.py file which contains this info:
Now everything is in place. I can start a live session by typing:
Or a paper trading session by:
It is often useful to have the debug mode enabled. For that, enter the same commands but this time add the
debug flag at the end.
But there's a problem here. If I close my terminal, the live session will stop. But I want the bot to continue trading for days even if I shut down my computer. That was the whole point of running it on a VPS.
For that, I use a tool called "screen". Screen creates a virtual terminal screen that I can attach and detach from whenever I need to. screen gets installed by that installer script that I just used. So I can go ahead and create my first screen:
screen -S bot
Now inside this screen I can run the live session again, but this time it won't be terminated if I close my terminal. Next time that I connect back to the server, I can reattach to that screen by:
screen -r bot