Elffuss BraidHub

kikocis/freqtrade public

develop · 8.2 KiBRenderedRawPermalink
1# Advanced Post-installation Tasks
2
3This page explains some advanced tasks and configuration options that can be performed after the bot installation and may be uselful in some environments.
4
5If you do not know what things mentioned here mean, you probably do not need it.
6
7## Running multiple instances of Freqtrade
8
9This section will show you how to run multiple bots at the same time, on the same machine.
10
11### Things to consider
12
13* Use different database files.
14* Use different Telegram bots (requires multiple different configuration files; applies only when Telegram is enabled).
15* Use different ports (applies only when Freqtrade REST API webserver is enabled).
16
17### Different database files
18
19In order to keep track of your trades, profits, etc., freqtrade is using a SQLite database where it stores various types of information such as the trades you performed in the past and the current position(s) you are holding at any time. This allows you to keep track of your profits, but most importantly, keep track of ongoing activity if the bot process would be restarted or would be terminated unexpectedly.
20
21Freqtrade will, by default, use separate database files for dry-run and live bots (this assumes no database-url is given in either configuration nor via command line argument).
22For live trading mode, the default database will be `tradesv3.sqlite` and for dry-run it will be `tradesv3.dryrun.sqlite`.
23
24The optional argument to the trade command used to specify the path of these files is `--db-url`, which requires a valid SQLAlchemy url.
25So when you are starting a bot with only the config and strategy arguments in dry-run mode, the following 2 commands would have the same outcome.
26
27``` bash
28freqtrade trade -c MyConfig.json -s MyStrategy
29# is equivalent to
30freqtrade trade -c MyConfig.json -s MyStrategy --db-url sqlite:///tradesv3.dryrun.sqlite
31```
32
33It means that if you are running the trade command in two different terminals, for example to test your strategy both for trades in USDT and in another instance for trades in BTC, you will have to run them with different databases.
34
35If you specify the URL of a database which does not exist, freqtrade will create one with the name you specified. So to test your custom strategy with BTC and USDT stake currencies, you could use the following commands (in 2 separate terminals):
36
37``` bash
38# Terminal 1:
39freqtrade trade -c MyConfigBTC.json -s MyCustomStrategy --db-url sqlite:///user_data/tradesBTC.dryrun.sqlite
40# Terminal 2:
41freqtrade trade -c MyConfigUSDT.json -s MyCustomStrategy --db-url sqlite:///user_data/tradesUSDT.dryrun.sqlite
42```
43
44Conversely, if you wish to do the same thing in production mode, you will also have to create at least one new database (in addition to the default one) and specify the path to the "live" databases, for example:
45
46``` bash
47# Terminal 1:
48freqtrade trade -c MyConfigBTC.json -s MyCustomStrategy --db-url sqlite:///user_data/tradesBTC.live.sqlite
49# Terminal 2:
50freqtrade trade -c MyConfigUSDT.json -s MyCustomStrategy --db-url sqlite:///user_data/tradesUSDT.live.sqlite
51```
52
53For more information regarding usage of the sqlite databases, for example to manually enter or remove trades, please refer to the [SQL Cheatsheet](sql_cheatsheet.md).
54
55## Configure the bot running as a systemd service
56
57Copy the `freqtrade.service` file to your systemd user directory (usually `~/.config/systemd/user`) and update `WorkingDirectory` and `ExecStart` to match your setup.
58
59!!! Note
60 Certain systems (like Raspbian) don't load service unit files from the user directory. In this case, copy `freqtrade.service` into `/etc/systemd/user/` (requires superuser permissions).
61
62After that you can start the daemon with:
63
64```bash
65systemctl --user start freqtrade
66```
67
68For this to be persistent (run when user is logged out) you'll need to enable `linger` for your freqtrade user.
69
70```bash
71sudo loginctl enable-linger "$USER"
72```
73
74If you run the bot as a service, you can use systemd service manager as a software watchdog monitoring freqtrade bot
75state and restarting it in the case of failures. If the `internals.sd_notify` parameter is set to true in the
76configuration or the `--sd-notify` command line option is used, the bot will send keep-alive ping messages to systemd
77using the sd_notify (systemd notifications) protocol and will also tell systemd its current state (Running or Stopped)
78when it changes.
79
80The `freqtrade.service.watchdog` file contains an example of the service unit configuration file which uses systemd
81as the watchdog.
82
83!!! Note
84 The sd_notify communication between the bot and the systemd service manager will not work if the bot runs in a Docker container.
85
86## Advanced Logging
87
88On many Linux systems the bot can be configured to send its log messages to `syslog` or `journald` system services. Logging to a remote `syslog` server is also available on Windows. The special values for the `--logfile` command line option can be used for this.
89
90### Logging to syslog
91
92To send Freqtrade log messages to a local or remote `syslog` service use the `--logfile` command line option with the value in the following format:
93
94* `--logfile syslog:<syslog_address>` -- send log messages to `syslog` service using the `<syslog_address>` as the syslog address.
95
96The syslog address can be either a Unix domain socket (socket filename) or a UDP socket specification, consisting of IP address and UDP port, separated by the `:` character.
97
98So, the following are the examples of possible usages:
99
100* `--logfile syslog:/dev/log` -- log to syslog (rsyslog) using the `/dev/log` socket, suitable for most systems.
101* `--logfile syslog` -- same as above, the shortcut for `/dev/log`.
102* `--logfile syslog:/var/run/syslog` -- log to syslog (rsyslog) using the `/var/run/syslog` socket. Use this on MacOS.
103* `--logfile syslog:localhost:514` -- log to local syslog using UDP socket, if it listens on port 514.
104* `--logfile syslog:<ip>:514` -- log to remote syslog at IP address and port 514. This may be used on Windows for remote logging to an external syslog server.
105
106Log messages are send to `syslog` with the `user` facility. So you can see them with the following commands:
107
108* `tail -f /var/log/user`, or
109* install a comprehensive graphical viewer (for instance, 'Log File Viewer' for Ubuntu).
110
111On many systems `syslog` (`rsyslog`) fetches data from `journald` (and vice versa), so both `--logfile syslog` or `--logfile journald` can be used and the messages be viewed with both `journalctl` and a syslog viewer utility. You can combine this in any way which suites you better.
112
113For `rsyslog` the messages from the bot can be redirected into a separate dedicated log file. To achieve this, add
114```
115if $programname startswith "freqtrade" then -/var/log/freqtrade.log
116```
117to one of the rsyslog configuration files, for example at the end of the `/etc/rsyslog.d/50-default.conf`.
118
119For `syslog` (`rsyslog`), the reduction mode can be switched on. This will reduce the number of repeating messages. For instance, multiple bot Heartbeat messages will be reduced to a single message when nothing else happens with the bot. To achieve this, set in `/etc/rsyslog.conf`:
120```
121# Filter duplicated messages
122$RepeatedMsgReduction on
123```
124
125### Logging to journald
126
127This needs the `systemd` python package installed as the dependency, which is not available on Windows. Hence, the whole journald logging functionality is not available for a bot running on Windows.
128
129To send Freqtrade log messages to `journald` system service use the `--logfile` command line option with the value in the following format:
130
131* `--logfile journald` -- send log messages to `journald`.
132
133Log messages are send to `journald` with the `user` facility. So you can see them with the following commands:
134
135* `journalctl -f` -- shows Freqtrade log messages sent to `journald` along with other log messages fetched by `journald`.
136* `journalctl -f -u freqtrade.service` -- this command can be used when the bot is run as a `systemd` service.
137
138There are many other options in the `journalctl` utility to filter the messages, see manual pages for this utility.
139
140On many systems `syslog` (`rsyslog`) fetches data from `journald` (and vice versa), so both `--logfile syslog` or `--logfile journald` can be used and the messages be viewed with both `journalctl` and a syslog viewer utility. You can combine this in any way which suites you better.