2018-01-13 02:36:12 +00:00
# Installation
2018-01-09 04:27:41 +00:00
This page explains how to prepare your environment for running the bot.
2018-01-13 02:36:12 +00:00
2018-12-31 10:04:22 +00:00
## Prerequisite
Before running your bot in production you will need to setup few
external API. In production mode, the bot required valid Bittrex API
credentials and a Telegram bot (optional but recommended).
2018-01-13 02:36:12 +00:00
2018-12-31 10:04:22 +00:00
- [Setup your exchange account ](#setup-your-exchange-account )
- [Backtesting commands ](#setup-your-telegram-bot )
2018-01-13 02:36:12 +00:00
2018-12-31 10:04:22 +00:00
### Setup your exchange account
*To be completed, please feel free to complete this section.*
2018-01-13 05:32:09 +00:00
2018-12-31 10:04:22 +00:00
### Setup your Telegram bot
The only things you need is a working Telegram bot and its API token.
Below we explain how to create your Telegram Bot, and how to get your
Telegram user id.
2018-01-29 04:53:55 +00:00
2018-12-31 10:04:22 +00:00
### 1. Create your Telegram bot
**1.1. Start a chat with https://telegram.me/BotFather**
**1.2. Send the message `/newbot` . ** *BotFather response:*
```
Alright, a new bot. How are we going to call it? Please choose a name for your bot.
```
**1.3. Choose the public name of your bot (e.x. `Freqtrade bot` )**
*BotFather response:*
```
Good. Now let's choose a username for your bot. It must end in `bot` . Like this, for example: TetrisBot or tetris_bot.
```
**1.4. Choose the name id of your bot (e.x "`My_own_freqtrade_bot`")**
**1.5. Father bot will return you the token (API key)**< br / >
Copy it and keep it you will use it for the config parameter `token` .
*BotFather response:*
```hl_lines="4"
Done! Congratulations on your new bot. You will find it at t.me/My_own_freqtrade_bot. You can now add a description, about section and profile picture for your bot, see /help for a list of commands. By the way, when you've finished creating your cool bot, ping our Bot Support if you want a better username for it. Just make sure the bot is fully operational before you do this.
Use this token to access the HTTP API:
521095879:AAEcEZEL7ADJ56FtG_qD0bQJSKETbXCBCi0
2018-01-29 04:53:55 +00:00
2018-12-31 10:04:22 +00:00
For a description of the Bot API, see this page: https://core.telegram.org/bots/api
```
**1.6. Don't forget to start the conversation with your bot, by clicking /START button**
### 2. Get your user id
**2.1. Talk to https://telegram.me/userinfobot**
**2.2. Get your "Id", you will use it for the config parameter
`chat_id` .**
< hr / >
## Quick start
Freqtrade provides a Linux/MacOS script to install all dependencies and help you to configure the bot.
```bash
git clone git@github.com:freqtrade/freqtrade.git
cd freqtrade
git checkout develop
./setup.sh --install
```
!!! Note
2018-12-31 13:00:36 +00:00
Windows installation is explained [here ](#windows ).
2018-12-31 10:04:22 +00:00
< hr / >
2018-01-29 04:53:55 +00:00
## Easy Installation - Linux Script
If you are on Debian, Ubuntu or MacOS a freqtrade provides a script to Install, Update, Configure, and Reset your bot.
```bash
$ ./setup.sh
usage:
-i,--install Install freqtrade from scratch
-u,--update Command git pull to update.
-r,--reset Hard reset your develop/master branch.
-c,--config Easy config generator (Will override your existing file).
```
2018-12-31 10:04:22 +00:00
** --install **
2018-06-08 09:23:00 +00:00
2018-01-29 04:53:55 +00:00
This script will install everything you need to run the bot:
2018-06-08 09:23:00 +00:00
2018-01-29 04:53:55 +00:00
* Mandatory software as: `Python3` , `ta-lib` , `wget`
* Setup your virtualenv
* Configure your `config.json` file
This script is a combination of `install script` `--reset` , `--config`
2018-12-31 10:04:22 +00:00
** --update **
2018-06-08 09:23:00 +00:00
2018-01-29 04:53:55 +00:00
Update parameter will pull the last version of your current branch and update your virtualenv.
2018-12-31 10:04:22 +00:00
** --reset **
2018-06-08 09:23:00 +00:00
2018-01-29 04:53:55 +00:00
Reset parameter will hard reset your branch (only if you are on `master` or `develop` ) and recreate your virtualenv.
2018-12-31 10:04:22 +00:00
** --config **
2018-06-08 09:23:00 +00:00
2018-01-29 04:53:55 +00:00
Config parameter is a `config.json` configurator. This script will ask you questions to setup your bot and create your `config.json` .
2018-01-13 02:36:12 +00:00
------
## Automatic Installation - Docker
2018-01-02 02:17:10 +00:00
Start by downloading Docker for your platform:
2018-01-13 02:36:12 +00:00
* [Mac ](https://www.docker.com/products/docker#/mac )
* [Windows ](https://www.docker.com/products/docker#/windows )
* [Linux ](https://www.docker.com/products/docker#/linux )
Once you have Docker installed, simply create the config file (e.g. `config.json` ) and then create a Docker image for `freqtrade` using the Dockerfile in this repo.
### 1. Prepare the Bot
2018-12-31 10:04:22 +00:00
**1.1. Clone the git repository**
2018-01-02 02:17:10 +00:00
2019-02-20 17:09:26 +00:00
Linux/Mac/Windows with WSL
2018-01-02 02:17:10 +00:00
```bash
2018-06-03 21:07:00 +00:00
git clone https://github.com/freqtrade/freqtrade.git
2018-01-02 02:17:10 +00:00
```
2018-01-13 02:36:12 +00:00
2019-02-20 17:09:26 +00:00
Windows with docker
2019-02-18 16:16:27 +00:00
```bash
git clone --config core.autocrlf=input https://github.com/freqtrade/freqtrade.git
```
2018-12-31 10:04:22 +00:00
**1.2. (Optional) Checkout the develop branch**
2018-01-13 02:36:12 +00:00
2018-01-02 02:17:10 +00:00
```bash
git checkout develop
```
2018-01-13 02:36:12 +00:00
2018-12-31 10:04:22 +00:00
**1.3. Go into the new directory**
2018-01-13 02:36:12 +00:00
2018-01-02 02:17:10 +00:00
```bash
cd freqtrade
```
2018-01-13 02:36:12 +00:00
2018-12-31 10:04:22 +00:00
**1.4. Copy `config.json.example` to `config.json` **
2018-01-13 02:36:12 +00:00
2018-01-02 02:17:10 +00:00
```bash
2018-01-14 17:25:30 +00:00
cp -n config.json.example config.json
2018-01-02 02:17:10 +00:00
```
2018-01-13 02:36:12 +00:00
2018-12-31 13:00:36 +00:00
> To edit the config please refer to the [Bot Configuration](configuration.md) page.
2018-01-13 02:36:12 +00:00
2018-12-31 10:04:22 +00:00
**1.5. Create your database file *(optional - the bot will create it if it is missing)* *
2018-01-13 02:36:12 +00:00
2018-01-13 05:32:09 +00:00
Production
2018-06-08 09:23:00 +00:00
2018-01-02 02:17:10 +00:00
```bash
touch tradesv3.sqlite
2018-01-13 05:32:09 +00:00
````
2018-01-02 02:17:10 +00:00
2018-01-13 05:32:09 +00:00
Dry-Run
2018-06-08 09:23:00 +00:00
2018-01-13 05:32:09 +00:00
```bash
2018-01-02 02:17:10 +00:00
touch tradesv3.dryrun.sqlite
```
2018-10-21 11:33:23 +00:00
### 2. Download or build the docker image
Either use the prebuilt image from docker hub - or build the image yourself if you would like more control on which version is used.
Branches / tags available can be checked out on [Dockerhub ](https://hub.docker.com/r/freqtradeorg/freqtrade/tags/ ).
2018-12-31 10:04:22 +00:00
**2.1. Download the docker image**
2018-10-21 11:33:23 +00:00
Pull the image from docker hub and (optionally) change the name of the image
```bash
docker pull freqtradeorg/freqtrade:develop
# Optionally tag the repository so the run-commands remain shorter
docker tag freqtradeorg/freqtrade:develop freqtrade
```
To update the image, simply run the above commands again and restart your running container.
2018-12-31 10:04:22 +00:00
**2.2. Build the Docker image**
2018-01-13 02:36:12 +00:00
2018-01-02 02:17:10 +00:00
```bash
cd freqtrade
docker build -t freqtrade .
```
2018-12-17 15:54:28 +00:00
If you are developing using Docker, use `Dockerfile.develop` to build a dev Docker image, which will also set up develop dependencies:
2018-12-02 13:08:00 +00:00
```bash
2018-12-17 15:54:28 +00:00
docker build -f ./Dockerfile.develop -t freqtrade-dev .
2018-12-02 13:08:00 +00:00
```
2018-01-13 02:36:12 +00:00
For security reasons, your configuration file will not be included in the image, you will need to bind mount it. It is also advised to bind mount an SQLite database file (see the "5. Run a restartable docker image" section) to keep it between updates.
2018-01-02 02:17:10 +00:00
2018-01-13 02:36:12 +00:00
### 3. Verify the Docker image
After the build process you can verify that the image was created with:
```bash
2018-01-02 02:17:10 +00:00
docker images
```
2018-01-13 02:36:12 +00:00
### 4. Run the Docker image
You can run a one-off container that is immediately deleted upon exiting with the following command (`config.json` must be in the current working directory):
```bash
2018-03-10 08:53:38 +00:00
docker run --rm -v /etc/localtime:/etc/localtime:ro -v `pwd` /config.json:/freqtrade/config.json -it freqtrade
2018-01-02 02:17:10 +00:00
```
2018-06-08 09:23:00 +00:00
There is known issue in OSX Docker versions after 17.09.1, whereby /etc/localtime cannot be shared causing Docker to not start. A work-around for this is to start with the following cmd.
2018-05-23 10:17:35 +00:00
```bash
docker run --rm -e TZ=`ls -la /etc/localtime | cut -d/ -f8-9` -v `pwd` /config.json:/freqtrade/config.json -it freqtrade
```
2018-12-31 10:04:22 +00:00
More information on this docker issue and work-around can be read [here ](https://github.com/docker/for-mac/issues/2396 ).
2018-01-13 02:36:12 +00:00
2018-06-08 09:23:00 +00:00
In this example, the database will be created inside the docker instance and will be lost when you will refresh your image.
2018-01-02 02:17:10 +00:00
### 5. Run a restartable docker image
2018-01-13 02:36:12 +00:00
To run a restartable instance in the background (feel free to place your configuration and database files wherever it feels comfortable on your filesystem).
2018-12-31 10:04:22 +00:00
**5.1. Move your config file and database**
2018-01-13 02:36:12 +00:00
2018-01-02 02:17:10 +00:00
```bash
mkdir ~/.freqtrade
mv config.json ~/.freqtrade
mv tradesv3.sqlite ~/.freqtrade
```
2018-12-31 10:04:22 +00:00
**5.2. Run the docker image**
2018-01-13 02:36:12 +00:00
2018-01-02 02:17:10 +00:00
```bash
docker run -d \
--name freqtrade \
2018-03-09 19:51:28 +00:00
-v /etc/localtime:/etc/localtime:ro \
2018-01-02 02:17:10 +00:00
-v ~/.freqtrade/config.json:/freqtrade/config.json \
-v ~/.freqtrade/tradesv3.sqlite:/freqtrade/tradesv3.sqlite \
2018-06-07 03:47:14 +00:00
freqtrade --db-url sqlite:///tradesv3.sqlite
2018-01-02 02:17:10 +00:00
```
2018-06-08 09:23:00 +00:00
2018-12-31 10:04:22 +00:00
!!! Note
db-url defaults to `sqlite:///tradesv3.sqlite` but it defaults to `sqlite://` if `dry_run=True` is being used.
To override this behaviour use a custom db-url value: i.e.: `--db-url sqlite:///tradesv3.dryrun.sqlite`
2018-01-02 02:17:10 +00:00
### 6. Monitor your Docker instance
2018-01-13 02:36:12 +00:00
2018-01-02 02:17:10 +00:00
You can then use the following commands to monitor and manage your container:
```bash
docker logs freqtrade
docker logs -f freqtrade
docker restart freqtrade
docker stop freqtrade
docker start freqtrade
```
2018-08-26 18:09:12 +00:00
For more information on how to operate Docker, please refer to the [official Docker documentation ](https://docs.docker.com/ ).
2018-12-31 10:04:22 +00:00
!!! Note
You do not need to rebuild the image for configuration changes, it will suffice to edit `config.json` and restart the container.
2018-01-13 02:36:12 +00:00
2018-06-18 20:42:14 +00:00
### 7. Backtest with docker
The following assumes that the above steps (1-4) have been completed successfully.
Also, backtest-data should be available at `~/.freqtrade/user_data/` .
2018-12-31 10:04:22 +00:00
```bash
2018-06-18 20:42:14 +00:00
docker run -d \
--name freqtrade \
-v /etc/localtime:/etc/localtime:ro \
-v ~/.freqtrade/config.json:/freqtrade/config.json \
-v ~/.freqtrade/tradesv3.sqlite:/freqtrade/tradesv3.sqlite \
-v ~/.freqtrade/user_data/:/freqtrade/user_data/ \
freqtrade --strategy AwsomelyProfitableStrategy backtesting
```
2018-12-31 13:00:36 +00:00
Head over to the [Backtesting Documentation ](backtesting.md ) for more details.
2018-06-18 20:42:14 +00:00
2018-12-31 10:04:22 +00:00
!!! Note
Additional parameters can be appended after the image name (`freqtrade` in the above example).
2018-06-18 20:42:14 +00:00
2018-01-13 02:36:12 +00:00
------
## Custom Installation
We've included/collected install instructions for Ubuntu 16.04, MacOS, and Windows. These are guidelines and your success may vary with other distros.
2018-12-31 10:04:22 +00:00
OS Specific steps are listed first, the [Common ](#common ) section below is necessary for all systems.
2018-01-13 02:36:12 +00:00
### Requirements
2018-01-02 02:17:10 +00:00
Click each one for install guide:
2018-06-08 09:23:00 +00:00
2018-08-26 18:09:12 +00:00
* [Python >= 3.6.x ](http://docs.python-guide.org/en/latest/starting/installation/ )
2018-01-13 02:36:12 +00:00
* [pip ](https://pip.pypa.io/en/stable/installing/ )
* [git ](https://git-scm.com/book/en/v2/Getting-Started-Installing-Git )
* [virtualenv ](https://virtualenv.pypa.io/en/stable/installation/ ) (Recommended)
* [TA-Lib ](https://mrjbq7.github.io/ta-lib/install.html )
2018-01-02 02:17:10 +00:00
2018-01-13 02:36:12 +00:00
### Linux - Ubuntu 16.04
2018-08-26 18:09:12 +00:00
#### Install Python 3.6, Git, and wget
2018-01-13 02:36:12 +00:00
2018-01-02 02:17:10 +00:00
```bash
sudo add-apt-repository ppa:jonathonf/python-3.6
sudo apt-get update
2018-01-09 05:24:00 +00:00
sudo apt-get install python3.6 python3.6-venv python3.6-dev build-essential autoconf libtool pkg-config make wget git
2018-01-02 02:17:10 +00:00
```
2018-08-28 20:06:46 +00:00
#### Raspberry Pi / Raspbian
Before installing FreqTrade on a Raspberry Pi running the official Raspbian Image, make sure you have at least Python 3.6 installed. The default image only provides Python 3.5. Probably the easiest way to get a recent version of python is [miniconda ](https://repo.continuum.io/miniconda/ ).
2018-12-27 06:56:35 +00:00
The following assumes that miniconda3 is installed and available in your environment. Last miniconda3 installation file use python 3.4, we will update to python 3.6 on this installation.
It's recommended to use (mini)conda for this as installation/compilation of `numpy` , `scipy` and `pandas` takes a long time.
Additional package to install on your Raspbian, `libffi-dev` required by cryptography (from python-telegram-bot).
2018-08-28 20:06:46 +00:00
``` bash
conda config --add channels rpi
conda install python=3.6
conda create -n freqtrade python=3.6
2018-12-27 06:56:35 +00:00
conda activate freqtrade
conda install scipy pandas numpy
2018-08-28 20:06:46 +00:00
2018-12-27 06:56:35 +00:00
sudo apt install libffi-dev
2019-04-26 17:57:09 +00:00
python3 -m pip install -r requirements-common.txt
2018-10-03 17:32:14 +00:00
python3 -m pip install -e .
2018-08-28 20:06:46 +00:00
```
2018-08-26 18:09:12 +00:00
### MacOS
2018-10-11 17:26:19 +00:00
#### Install Python 3.6, git and wget
2018-08-26 18:09:12 +00:00
```bash
brew install python3 git wget
```
2018-12-31 10:04:22 +00:00
### Common
2018-08-26 18:09:12 +00:00
#### 1. Install TA-Lib
2018-01-13 02:36:12 +00:00
2018-01-02 02:17:10 +00:00
Official webpage: https://mrjbq7.github.io/ta-lib/install.html
2018-01-13 02:36:12 +00:00
```bash
2018-01-02 02:17:10 +00:00
wget http://prdownloads.sourceforge.net/ta-lib/ta-lib-0.4.0-src.tar.gz
tar xvzf ta-lib-0.4.0-src.tar.gz
cd ta-lib
2018-09-16 09:24:49 +00:00
sed -i.bak "s|0.00000001|0.000000000000000001 |g" src/ta_func/ta_utility.h
2018-10-11 17:26:19 +00:00
./configure --prefix=/usr/local
2018-01-02 02:17:10 +00:00
make
2018-10-11 17:26:19 +00:00
sudo make install
2018-01-02 02:17:10 +00:00
cd ..
rm -rf ./ta-lib*
```
2018-12-31 10:04:22 +00:00
!!! Note
An already downloaded version of ta-lib is included in the repository, as the sourceforge.net source seems to have problems frequently.
2018-01-13 02:36:12 +00:00
2018-08-26 18:09:12 +00:00
#### 2. Setup your Python virtual environment (virtualenv)
2018-01-13 02:36:12 +00:00
2018-12-31 10:04:22 +00:00
!!! Note
This step is optional but strongly recommended to keep your system organized
2018-01-13 02:36:12 +00:00
```bash
2018-08-26 18:09:12 +00:00
python3 -m venv .env
source .env/bin/activate
2018-01-13 02:36:12 +00:00
```
2018-08-26 18:09:12 +00:00
#### 3. Install FreqTrade
2018-01-02 02:17:10 +00:00
2018-01-13 02:36:12 +00:00
Clone the git repository:
2018-01-02 02:17:10 +00:00
```bash
2018-06-03 21:07:00 +00:00
git clone https://github.com/freqtrade/freqtrade.git
2018-08-26 18:09:12 +00:00
2018-01-02 02:17:10 +00:00
```
2018-08-26 18:09:12 +00:00
Optionally checkout the stable/master branch:
2018-01-02 02:17:10 +00:00
```bash
2018-08-26 18:09:12 +00:00
git checkout master
2018-01-02 02:17:10 +00:00
```
2018-08-26 18:09:12 +00:00
#### 4. Initialize the configuration
2018-01-13 02:36:12 +00:00
```bash
cd freqtrade
cp config.json.example config.json
```
2018-12-31 13:00:36 +00:00
> *To edit the config please refer to [Bot Configuration](configuration.md).*
2018-01-13 02:36:12 +00:00
2018-08-26 18:09:12 +00:00
#### 5. Install python dependencies
2018-01-13 05:32:09 +00:00
2018-08-26 18:09:12 +00:00
``` bash
2018-08-26 10:49:39 +00:00
pip3 install --upgrade pip
pip3 install -r requirements.txt
pip3 install -e .
2018-01-13 02:36:12 +00:00
```
2018-08-26 18:09:12 +00:00
#### 6. Run the Bot
2018-01-13 05:32:09 +00:00
If this is the first time you run the bot, ensure you are running it in Dry-run `"dry_run": true,` otherwise it will start to buy and sell coins.
2018-01-13 02:36:12 +00:00
```bash
2019-03-24 14:13:17 +00:00
python3.6 freqtrade -c config.json
2018-01-13 02:36:12 +00:00
```
2018-08-26 18:09:12 +00:00
*Note*: If you run the bot on a server, you should consider using [Docker ](#automatic-installation---docker ) a terminal multiplexer like `screen` or [`tmux` ](https://en.wikipedia.org/wiki/Tmux ) to avoid that the bot is stopped on logout.
#### 7. [Optional] Configure `freqtrade` as a `systemd` service
From the freqtrade repo... copy `freqtrade.service` to your systemd user directory (usually `~/.config/systemd/user` ) and update `WorkingDirectory` and `ExecStart` to match your setup.
After that you can start the daemon with:
```bash
systemctl --user start freqtrade
```
For this to be persistent (run when user is logged out) you'll need to enable `linger` for your freqtrade user.
```bash
sudo loginctl enable-linger "$USER"
```
2019-03-10 17:05:33 +00:00
If you run the bot as a service, you can use systemd service manager as a software watchdog monitoring freqtrade bot
state and restarting it in the case of failures. If the `internals.sd_notify` parameter is set to true in the
configuration or the `--sd-notify` command line option is used, the bot will send keep-alive ping messages to systemd
using the sd_notify (systemd notifications) protocol and will also tell systemd its current state (Running or Stopped)
when it changes.
The `freqtrade.service.watchdog` file contains an example of the service unit configuration file which uses systemd
as the watchdog.
2019-03-23 18:43:23 +00:00
!!! Note
The sd_notify communication between the bot and the systemd service manager will not work if the bot runs in a
Docker container.
2019-03-10 17:05:33 +00:00
2018-01-29 04:53:55 +00:00
------
## Windows
2018-06-08 09:23:00 +00:00
We recommend that Windows users use [Docker ](#docker ) as this will work much easier and smoother (also more secure).
If that is not possible, try using the Windows Linux subsystem (WSL) - for which the Ubuntu instructions should work.
If that is not available on your system, feel free to try the instructions below, which led to success for some.
2018-01-29 04:53:55 +00:00
2018-06-08 09:23:00 +00:00
### Install freqtrade manually
#### Clone the git repository
```bash
git clone https://github.com/freqtrade/freqtrade.git
```
2018-01-29 04:53:55 +00:00
copy paste `config.json` to ``\path\freqtrade-develop\freqtrade`
2018-08-28 17:30:26 +00:00
#### Install ta-lib
2018-06-08 09:23:00 +00:00
Install ta-lib according to the [ta-lib documentation ](https://github.com/mrjbq7/ta-lib#windows ).
2018-12-31 10:12:56 +00:00
As compiling from source on windows has heavy dependencies (requires a partial visual studio installation), there is also a repository of unofficial precompiled windows Wheels [here ](https://www.lfd.uci.edu/~gohlke/pythonlibs/#ta-lib ), which needs to be downloaded and installed using `pip install TA_Lib‑ 0.4.17‑ cp36‑ cp36m‑ win32.whl` (make sure to use the version matching your python version)
2018-06-08 09:23:00 +00:00
2018-01-29 04:53:55 +00:00
```cmd
>cd \path\freqtrade-develop
>python -m venv .env
>cd .env\Scripts
>activate.bat
>cd \path\freqtrade-develop
2018-06-08 09:23:00 +00:00
REM optionally install ta-lib from wheel
REM >pip install TA_Lib‑ 0.4.17‑ cp36‑ cp36m‑ win32.whl
2018-01-29 04:53:55 +00:00
>pip install -r requirements.txt
>pip install -e .
2018-06-08 09:23:00 +00:00
>python freqtrade\main.py
2018-01-29 04:53:55 +00:00
```
2018-06-03 21:07:00 +00:00
> Thanks [Owdr](https://github.com/Owdr) for the commands. Source: [Issue #222](https://github.com/freqtrade/freqtrade/issues/222)
2018-01-29 04:53:55 +00:00
2018-08-28 17:30:26 +00:00
#### Error during installation under Windows
``` bash
error: Microsoft Visual C++ 14.0 is required. Get it with "Microsoft Visual C++ Build Tools": http://landinghub.visualstudio.com/visual-cpp-build-tools
```
Unfortunately, many packages requiring compilation don't provide a pre-build wheel. It is therefore mandatory to have a C/C++ compiler installed and available for your python environment to use.
The easiest way is to download install Microsoft Visual Studio Community [here ](https://visualstudio.microsoft.com/downloads/ ) and make sure to install "Common Tools for Visual C++" to enable building c code on Windows. Unfortunately, this is a heavy download / dependency (~4Gb) so you might want to consider WSL or docker first.
---
2018-01-13 02:36:12 +00:00
Now you have an environment ready, the next step is
2018-12-31 12:39:18 +00:00
[Bot Configuration ](configuration.md ).