Start multiple Zenbots at once with screen

Table of Content

Zenbot is wonderful crypto currency bot. You can write own strategy or use existed ones and literally begin to make money while you are sleeping. Of course it’s not so easy to invent profitable strategy, but who wants that always find the path.

Diversification. It’s the main key of the successful investor and it’s obvious that we will run several bots to diversify our assets and minimize losses.

To be able to run several bots simultaneously you should disabling REST API. You can either to disable it or to use random ports. Here is appropriate part of my .env:


Preparing .screenrc config

To run multiple Zenbots at once we’re gonna use screen Linux package. It’s the terminal utility that allow to run any numbers of sessions in one window.
You already imagine how it should work and I’m almost sure you are right, but I want to do a bit more by adding all our bot commands into one file. You can create bash script for this and it will work, but I like to use more right way and will use for it a native configuration file named as .screenrc. The following .screenrc creates a screen session with 2 windows. One window will be running strategy for "DOGE-USDT" pair, the other will be running "SOL-USDT":

chdir /app
sessionname zenbot
screen -t DOGE-USDT 1 zenbot trade binance.DOGE-USDT --period=2m --timeframe_periods=30 ...
screen -t SOL-USDT 2 zenbot trade binance.SOL-USDT --period=2m --timeframe_periods=30 ...

I omitted most of the options of my strategy because it doesn’t matter in this case. Let me explain what means all these options and how to deal with screen.

  • chdir /app – canges the working directory for all subsequent sessions.
  • sessionname zenbot – create a screen window with human readable name "zenbot". You can change the name "zenbot" to whatever you want. The name "zenbot" shows when executing screen -ls and can be used as a parameter for screen -r.
  • screen -t commandName1 1 zenbot ... – the last two commands require more detailed explanation. The minimum command sctructure is:
  • -t commandName1 – the strings "commandNameN" specify the window names within the screen session. In my case it’s the names of crypto coin pairs "DOGE-USDT" and "SOL-USDT".
  • 0...9 – the numbers specifiy which window to run the command in (You don’t have to use subsequent numbers). In my case the numbers are 1 and 2, I omitted 0 window because it’s not handy switching to this screen using the shortcat [Ctrl + a 0] on a keyboard.
  • zenbot ... – the command to use to run the bot. Here you specify any parameters you need.

The .screenrc is ready, now you can read and execute the config with the next command:

screen -c .screenrc

You can also later add another window with a new command to the running screen session, e.g. with:

screen -X screen -S myscreensession -t commandName3 3 zenbot ...

This would create a new window running zenbot in the existing session.

Working with Linux Screen Windows

When you run the command screen -c .screenrc it starts a new screen session and creates two windows (according to out configuration) with a shell in it.
To create a new window with shell type Ctrl+a c, the first available number from the range 0…9 will be assigned to it.

Below are some most common commands for managing Linux Screen windows:

Note: Every screen command begins with Ctrl-a.

  • Ctrl+a c – Create a new window (with shell).
  • Ctrl-a k – Kill the current window.
  • Ctrl+a A – Rename the current window.
  • Ctrl+a Ctrl+a – Toggle between the current and previous windows.
  • Ctrl+a 0-9 – Switch to window 0-9 (by number).
  • Ctrl+a Space or Ctrl+a n – Go to the next in sequence.
  • Ctrl+a ' – (single quote) Display a prompt and let you enter the number or name of a window to switch to.
  • Ctrl+a " – (double quote) Display list of all windows.
  • Ctrl+a d – Detach from Linux Screen session. The program running in the screen session will continue to run after you detach from the session.

You can attach again to the screen and view its output by doing

screen -r zenbot

List active screens (you can use name or PID to attach to it)

screen -ls

Instead of conclusion

On the Internet you can find another approach where you are suggested to run several screen sessions independently. Why is this approach worse? In that case you loss all screen power and switching between sessions become not so simple because you cannot use shortcats and other features.

Useful links

Leave a Reply

Your email address will not be published. Required fields are marked *