Elffuss BraidHub

kikocis/freqtrade public

develop · 8.6 KiBRenderedRawPermalink
1# Using Freqtrade with Docker
2
3This page explains how to run the bot with Docker. It is not meant to work out of the box. You'll still need to read through the documentation and understand how to properly configure it.
4
5## Install Docker
6
7Start by downloading and installing Docker CE for your platform:
8
9* [Mac](https://docs.docker.com/docker-for-mac/install/)
10* [Windows](https://docs.docker.com/docker-for-windows/install/)
11* [Linux](https://docs.docker.com/install/)
12
13To simplify running freqtrade, please install [`docker-compose`](https://docs.docker.com/compose/install/) should be installed and available to follow the below [docker quick start guide](#docker-quick-start).
14
15## Freqtrade with docker-compose
16
17Freqtrade provides an official Docker image on [Dockerhub](https://hub.docker.com/r/freqtradeorg/freqtrade/), as well as a [docker-compose file](https://github.com/freqtrade/freqtrade/blob/stable/docker-compose.yml) ready for usage.
18
19!!! Note
20 - The following section assumes that `docker` and `docker-compose` are installed and available to the logged in user.
21 - All below commands use relative directories and will have to be executed from the directory containing the `docker-compose.yml` file.
22
23### Docker quick start
24
25Create a new directory and place the [docker-compose file](https://raw.githubusercontent.com/freqtrade/freqtrade/stable/docker-compose.yml) in this directory.
26
27=== "PC/MAC/Linux"
28 ``` bash
29 mkdir ft_userdata
30 cd ft_userdata/
31 # Download the docker-compose file from the repository
32 curl https://raw.githubusercontent.com/freqtrade/freqtrade/stable/docker-compose.yml -o docker-compose.yml
33
34 # Pull the freqtrade image
35 docker-compose pull
36
37 # Create user directory structure
38 docker-compose run --rm freqtrade create-userdir --userdir user_data
39
40 # Create configuration - Requires answering interactive questions
41 docker-compose run --rm freqtrade new-config --config user_data/config.json
42 ```
43
44=== "RaspberryPi"
45 ``` bash
46 mkdir ft_userdata
47 cd ft_userdata/
48 # Download the docker-compose file from the repository
49 curl https://raw.githubusercontent.com/freqtrade/freqtrade/stable/docker-compose.yml -o docker-compose.yml
50
51 # Pull the freqtrade image
52 docker-compose pull
53
54 # Create user directory structure
55 docker-compose run --rm freqtrade create-userdir --userdir user_data
56
57 # Create configuration - Requires answering interactive questions
58 docker-compose run --rm freqtrade new-config --config user_data/config.json
59 ```
60
61 !!! Note "Change your docker Image"
62 You have to change the docker image in the docker-compose file for your Raspberry build to work properly.
63 ``` yml
64 image: freqtradeorg/freqtrade:stable_pi
65 # image: freqtradeorg/freqtrade:develop_pi
66 ```
67
68The above snippet creates a new directory called `ft_userdata`, downloads the latest compose file and pulls the freqtrade image.
69The last 2 steps in the snippet create the directory with `user_data`, as well as (interactively) the default configuration based on your selections.
70
71!!! Question "How to edit the bot configuration?"
72 You can edit the configuration at any time, which is available as `user_data/config.json` (within the directory `ft_userdata`) when using the above configuration.
73
74 You can also change the both Strategy and commands by editing the command section of your `docker-compose.yml` file.
75
76#### Adding a custom strategy
77
781. The configuration is now available as `user_data/config.json`
792. Copy a custom strategy to the directory `user_data/strategies/`
803. Add the Strategy' class name to the `docker-compose.yml` file
81
82The `SampleStrategy` is run by default.
83
84!!! Warning "`SampleStrategy` is just a demo!"
85 The `SampleStrategy` is there for your reference and give you ideas for your own strategy.
86 Please always backtest your strategy and use dry-run for some time before risking real money!
87 You will find more information about Strategy development in the [Strategy documentation](strategy-customization.md).
88
89Once this is done, you're ready to launch the bot in trading mode (Dry-run or Live-trading, depending on your answer to the corresponding question you made above).
90
91``` bash
92docker-compose up -d
93```
94
95!!! Warning "Default configuration"
96 While the configuration generated will be mostly functional, you will still need to verify that all options correspond to what you want (like Pricing, pairlist, ...) before starting the bot.
97
98#### Monitoring the bot
99
100You can check for running instances with `docker-compose ps`.
101This should list the service `freqtrade` as `running`. If that's not the case, best check the logs (see next point).
102
103#### Docker-compose logs
104
105Logs will be written to: `user_data/logs/freqtrade.log`.
106You can also check the latest log with the command `docker-compose logs -f`.
107
108#### Database
109
110The database will be located at: `user_data/tradesv3.sqlite`
111
112#### Updating freqtrade with docker-compose
113
114Updating freqtrade when using `docker-compose` is as simple as running the following 2 commands:
115
116``` bash
117# Download the latest image
118docker-compose pull
119# Restart the image
120docker-compose up -d
121```
122
123This will first pull the latest image, and will then restart the container with the just pulled version.
124
125!!! Warning "Check the Changelog"
126 You should always check the changelog for breaking changes / manual interventions required and make sure the bot starts correctly after the update.
127
128### Editing the docker-compose file
129
130Advanced users may edit the docker-compose file further to include all possible options or arguments.
131
132All freqtrade arguments will be available by running `docker-compose run --rm freqtrade <command> <optional arguments>`.
133
134!!! Note "`docker-compose run --rm`"
135 Including `--rm` will remove the container after completion, and is highly recommended for all modes except trading mode (running with `freqtrade trade` command).
136
137#### Example: Download data with docker-compose
138
139Download backtesting data for 5 days for the pair ETH/BTC and 1h timeframe from Binance. The data will be stored in the directory `user_data/data/` on the host.
140
141``` bash
142docker-compose run --rm freqtrade download-data --pairs ETH/BTC --exchange binance --days 5 -t 1h
143```
144
145Head over to the [Data Downloading Documentation](data-download.md) for more details on downloading data.
146
147#### Example: Backtest with docker-compose
148
149Run backtesting in docker-containers for SampleStrategy and specified timerange of historical data, on 5m timeframe:
150
151``` bash
152docker-compose run --rm freqtrade backtesting --config user_data/config.json --strategy SampleStrategy --timerange 20190801-20191001 -i 5m
153```
154
155Head over to the [Backtesting Documentation](backtesting.md) to learn more.
156
157### Additional dependencies with docker-compose
158
159If your strategy requires dependencies not included in the default image - it will be necessary to build the image on your host.
160For this, please create a Dockerfile containing installation steps for the additional dependencies (have a look at [docker/Dockerfile.custom](https://github.com/freqtrade/freqtrade/blob/develop/docker/Dockerfile.custom) for an example).
161
162You'll then also need to modify the `docker-compose.yml` file and uncomment the build step, as well as rename the image to avoid naming collisions.
163
164``` yaml
165 image: freqtrade_custom
166 build:
167 context: .
168 dockerfile: "./Dockerfile.<yourextension>"
169```
170
171You can then run `docker-compose build` to build the docker image, and run it using the commands described above.
172
173## Plotting with docker-compose
174
175Commands `freqtrade plot-profit` and `freqtrade plot-dataframe` ([Documentation](plotting.md)) are available by changing the image to `*_plot` in your docker-compose.yml file.
176You can then use these commands as follows:
177
178``` bash
179docker-compose run --rm freqtrade plot-dataframe --strategy AwesomeStrategy -p BTC/ETH --timerange=20180801-20180805
180```
181
182The output will be stored in the `user_data/plot` directory, and can be opened with any modern browser.
183
184## Data analysis using docker compose
185
186Freqtrade provides a docker-compose file which starts up a jupyter lab server.
187You can run this server using the following command:
188
189``` bash
190docker-compose -f docker/docker-compose-jupyter.yml up
191```
192
193This will create a docker-container running jupyter lab, which will be accessible using `https://127.0.0.1:8888/lab`.
194Please use the link that's printed in the console after startup for simplified login.
195
196Since part of this image is built on your machine, it is recommended to rebuild the image from time to time to keep freqtrade (and dependencies) up-to-date.
197
198``` bash
199docker-compose -f docker/docker-compose-jupyter.yml build --no-cache
200```