Skip to content

Installation on PythonAnywhere

Ron Klinkien edited this page Aug 1, 2022 · 1 revision

Security

Because you store your 3Commas API keys in the cloud, make sure to use a unique and difficult password to protect your PythonAnywhere account. Also enable 2-Factor authentication for extra protection. (Look under account/security)

Install

Go to PythonAnywhere at (for EU) https://eu.pythonanywhere.com/ and create free account, view your Dashboard and click on 'Bash' button under New Console: Console

Check if the time is correct, if not set your Timezone like so: (example for the Netherlands)

20:22 ~ $ echo 'export TZ="/usr/share/zoneinfo/Europe/Amsterdam"' >>~/.bashrc

Then stop and restart the Bash console.

Then download software, run: (you can copy and paste with Ctrl-c/Ctrl-v)

$ git clone https://github.com/cyberjunky/3commas-cyber-bots.git
$ cd 3commas-cyber-bots
$ pip3 install -r requirements.txt

It will look like this:

14:45 ~ $ git clone https://github.com/cyberjunky/3commas-cyber-bots.git
Cloning into '3commas-cyber-bots'...
remote: Enumerating objects: 1174, done.
remote: Counting objects: 100% (377/377), done.
remote: Compressing objects: 100% (98/98), done.
remote: Total 1174 (delta 347), reused 290 (delta 279), pack-reused 797
Receiving objects: 100% (1174/1174), 1.47 MiB | 4.44 MiB/s, done.
Resolving deltas: 100% (748/748), done.
14:45 ~ $ cd 3commas-cyber-bots
14:46 ~/3commas-cyber-bots (main)$ pip3 install -r requirements.txt
Defaulting to user installation because normal site-packages is not writeable
Looking in links: /usr/share/pip-wheels
Collecting py3cw==0.0.33
  Downloading py3cw-0.0.33-py3-none-any.whl (6.5 kB)
Collecting apprise==0.9.6
  Downloading apprise-0.9.6-py2.py3-none-any.whl (1.0 MB)
     |████████████████████████████████| 1.0 MB 14.5 MB/s 
Collecting telethon==1.24.0
  Downloading Telethon-1.24.0-py3-none-any.whl (528 kB)
     |████████████████████████████████| 528 kB 15.4 MB/s 
Collecting beautifulsoup4==4.10.0
  Downloading beautifulsoup4-4.10.0-py3-none-any.whl (97 kB)
     |████████████████████████████████| 97 kB 1.2 MB/s 
Requirement already satisfied: requests in /usr/local/lib/python3.9/site-packages (from py3cw==0.0.33->-r requirements.txt (line 1)) (2.25.1)
Requirement already satisfied: markdown in /usr/local/lib/python3.9/site-packages (from apprise==0.9.6->-r requirements.txt (line 2)) (3.3.3)
Requirement already satisfied: click>=5.0 in /usr/local/lib/python3.9/site-packages (from apprise==0.9.6->-r requirements.txt (line 2)) (7.1.2)
Requirement already satisfied: PyYAML in /usr/local/lib/python3.9/site-packages (from apprise==0.9.6->-r requirements.txt (line 2)) (5.3.1)
Requirement already satisfied: requests-oauthlib in /usr/local/lib/python3.9/site-packages (from apprise==0.9.6->-r requirements.txt (line 2)) (1.3.0)
Requirement already satisfied: six in /usr/local/lib/python3.9/site-packages (from apprise==0.9.6->-r requirements.txt (line 2)) (1.16.0)
Requirement already satisfied: rsa in /usr/local/lib/python3.9/site-packages (from telethon==1.24.0->-r requirements.txt (line 3)) (4.7)
Requirement already satisfied: pyaes in /home/cyberjunky/.local/lib/python3.9/site-packages (from telethon==1.24.0->-r requirements.txt (line 3)) (1.6.1)
Requirement already satisfied: soupsieve>1.2 in /usr/local/lib/python3.9/site-packages (from beautifulsoup4==4.10.0->-r requirements.txt (line 4)) (2.1)
Requirement already satisfied: chardet<5,>=3.0.2 in /usr/local/lib/python3.9/site-packages (from requests->py3cw==0.0.33->-r requirements.txt (line 1)) (4.0.0)
Requirement already satisfied: urllib3<1.27,>=1.21.1 in /usr/local/lib/python3.9/site-packages (from requests->py3cw==0.0.33->-r requirements.txt (line 1)) (1.26.2)
Requirement already satisfied: idna<3,>=2.5 in /usr/local/lib/python3.9/site-packages (from requests->py3cw==0.0.33->-r requirements.txt (line 1)) (2.10)
Requirement already satisfied: certifi>=2017.4.17 in /usr/local/lib/python3.9/site-packages (from requests->py3cw==0.0.33->-r requirements.txt (line 1)) (2020.12.5)
Requirement already satisfied: oauthlib>=3.0.0 in /usr/local/lib/python3.9/site-packages (from requests-oauthlib->apprise==0.9.6->-r requirements.txt (line 2)) (3.1.0)
Requirement already satisfied: pyasn1>=0.1.3 in /usr/local/lib/python3.9/site-packages (from rsa->telethon==1.24.0->-r requirements.txt (line 3)) (0.4.8)
Installing collected packages: telethon, py3cw, beautifulsoup4, apprise
  Attempting uninstall: telethon
    Found existing installation: Telethon 1.23.0
    Uninstalling Telethon-1.23.0:
      Successfully uninstalled Telethon-1.23.0
  Attempting uninstall: py3cw
    Found existing installation: py3cw 0.0.31
    Uninstalling py3cw-0.0.31:
      Successfully uninstalled py3cw-0.0.31
  Attempting uninstall: apprise
    Found existing installation: apprise 0.9.5.1
    Uninstalling apprise-0.9.5.1:
      Successfully uninstalled apprise-0.9.5.1
Successfully installed apprise-0.9.6 beautifulsoup4-4.10.0 py3cw-0.0.33 telethon-1.24.0
14:47 ~/3commas-cyber-bots (main)$ 

Then you can run any of the scripts. If you want to run multiple bot helpers, create another Bash console by clicking on the 'Bash' button again, cd to the 3commas-cyber-bots folder and start the next.

For example compound:

14:47 ~/3commas-cyber-bots (main)$ ./compound.py 
2022-01-24 14:49:02 - compound - INFO - 3C Cyber Bot-Helper compound
2022-01-24 14:49:02 - compound - INFO - Started on Monday 14:49:02 2022-01-24
2022-01-24 14:49:02 - compound - INFO - Notifications are disabled
2022-01-24 14:49:02 - compound - INFO - Created example config file '/home/cyberjunky/3commas-cyber-bots/compound.ini', edit it and restart the program
14:49 ~/3commas-cyber-bots (main)$ 

Edit compound.ini, enter your 3Commas your API keys, edit 'id' behind [bot_] to the id of your bot (123456 as example):

14:52 ~/3commas-cyber-bots (main)$ nano compound.ini

[settings]
timezone = Europe/Amsterdam
timeinterval = 3600
debug = False
logrotate = 7
default-profittocompound = 1.0
3c-apikey = Your 3Commas API Key
3c-apisecret = Your 3Commas API Secret
notifications = False
notify-urls = ['notify-url1', 'notify-url2']

[bot_123456]
compoundmode = boso
profittocompound = 1.0
usermaxactivedeals = 5
usermaxsafetyorders = 5
comment = put here the name of the bot

Add more sections if you want to run more bots. After editing start the script again to test if it works.

Always-On

To run python scripts in PythonAnywhere you can use the Bash consoles. Sometimes servers experience a refresh or have downtime due to maintenance.

To make sure that the scripts are always up and running, you can set-up an "Always-on" Task. This requires a paid PythonAnywhere subscription (5 euros a month) and you can enable 1 "always-on" task only per account.

First you need to create a startup script with the bot helper(s) you want to run. This script executes the required python scripts that otherwise would need a separate command in a separate console.

14:55 ~/3commas-cyber-bots (main)$ cd
14:55 ~ $ nano startup.sh

And put this as content:

#!/bin/bash
cd ~/3commas-cyber-bots
python3 compound.py &
python3 coinmarketcap.py &

Add desired python script(s) to run.

Make script executable:

15:11 $ chmod +x startup.sh 

Once you are ready to run an always-on task, go to Tasks page. In the Always-on section find the task bar and enter the following entry.

Create

After a few seconds the status will go from starting to running.
In the Actions (View Task Log - Icon with lines) you can view the status/output of the python scripts.
It will look something like this (for compound.py)

Jan 24 20:27:23 2022-01-24 21:27:23 - compound - INFO - 3C Cyber Bot-Helper compound
Jan 24 20:27:23 2022-01-24 21:27:23 - compound - INFO - Started on Monday 21:27:23 2022-01-24
Jan 24 20:27:23 2022-01-24 21:27:23 - compound - INFO - Notifications are enabled
Jan 24 20:27:23 2022-01-24 21:27:23 - compound - INFO - Loaded configuration from '/home/cyberjunky/3commas-cyber-bots/compound.ini'
Jan 24 20:27:23 2022-01-24 21:27:23 - compound - INFO - Database '/home/cyberjunky/3commas-cyber-bots/compound.sqlite3' opened successfully
Jan 24 20:27:23 2022-01-24 21:27:23 - compound - INFO - Reloaded configuration from '/home/cyberjunky/3commas-cyber-bots/compound.ini'
Jan 24 20:27:29 2022-01-24 21:27:29 - compound - INFO - Fetched the deals for bot OK (0 deals)
Jan 24 20:27:29 2022-01-24 21:27:29 - compound - INFO - Binance BUSD Multi Long Bot Heinrich Bakkus - 648 BUSD AR20 30 min
Jan 24 20:27:29 No (new) deals found for this bot!
Jan 24 20:27:29 2022-01-24 21:27:29 - compound - INFO - Next update in 3600 Seconds at 22:27:29
Jan 24 20:27:29 2022-01-24 21:27:29 - compound - INFO - Notifying 1 service(s) asynchronously.
Jan 24 20:27:30 2022-01-24 21:27:30 - compound - INFO - Sent Telegram notification.

You can click on 'Fetch process list' button to see the running processes: (for compound.py)

Tasks

You can find more information about Always-on here: https://help.pythonanywhere.com/pages/AlwaysOnTasks/