Elffuss BraidHub

kikocis/freqtrade public

develop · 16.3 KiBRenderedRawPermalink
1# Data Downloading
2
3## Getting data for backtesting and hyperopt
4
5To download data (candles / OHLCV) needed for backtesting and hyperoptimization use the `freqtrade download-data` command.
6
7If no additional parameter is specified, freqtrade will download data for `"1m"` and `"5m"` timeframes for the last 30 days.
8Exchange and pairs will come from `config.json` (if specified using `-c/--config`).
9Otherwise `--exchange` becomes mandatory.
10
11You can use a relative timerange (`--days 20`) or an absolute starting point (`--timerange 20200101-`). For incremental downloads, the relative approach should be used.
12
13!!! Tip "Tip: Updating existing data"
14 If you already have backtesting data available in your data-directory and would like to refresh this data up to today, use `--days xx` with a number slightly higher than the missing number of days. Freqtrade will keep the available data and only download the missing data.
15 Be careful though: If the number is too small (which would result in a few missing days), the whole dataset will be removed and only xx days will be downloaded.
16
17### Usage
18
19```
20usage: freqtrade download-data [-h] [-v] [--logfile FILE] [-V] [-c PATH]
21 [-d PATH] [--userdir PATH]
22 [-p PAIRS [PAIRS ...]] [--pairs-file FILE]
23 [--days INT] [--timerange TIMERANGE]
24 [--dl-trades] [--exchange EXCHANGE]
25 [-t {1m,3m,5m,15m,30m,1h,2h,4h,6h,8h,12h,1d,3d,1w,2w,1M,1y} [{1m,3m,5m,15m,30m,1h,2h,4h,6h,8h,12h,1d,3d,1w,2w,1M,1y} ...]]
26 [--erase]
27 [--data-format-ohlcv {json,jsongz,hdf5}]
28 [--data-format-trades {json,jsongz,hdf5}]
29
30optional arguments:
31 -h, --help show this help message and exit
32 -p PAIRS [PAIRS ...], --pairs PAIRS [PAIRS ...]
33 Limit command to these pairs. Pairs are space-
34 separated.
35 --pairs-file FILE File containing a list of pairs to download.
36 --days INT Download data for given number of days.
37 --timerange TIMERANGE
38 Specify what timerange of data to use.
39 --dl-trades Download trades instead of OHLCV data. The bot will
40 resample trades to the desired timeframe as specified
41 as --timeframes/-t.
42 --exchange EXCHANGE Exchange name (default: `bittrex`). Only valid if no
43 config is provided.
44 -t {1m,3m,5m,15m,30m,1h,2h,4h,6h,8h,12h,1d,3d,1w,2w,1M,1y} [{1m,3m,5m,15m,30m,1h,2h,4h,6h,8h,12h,1d,3d,1w,2w,1M,1y} ...], --timeframes {1m,3m,5m,15m,30m,1h,2h,4h,6h,8h,12h,1d,3d,1w,2w,1M,1y} [{1m,3m,5m,15m,30m,1h,2h,4h,6h,8h,12h,1d,3d,1w,2w,1M,1y} ...]
45 Specify which tickers to download. Space-separated
46 list. Default: `1m 5m`.
47 --erase Clean all existing data for the selected
48 exchange/pairs/timeframes.
49 --data-format-ohlcv {json,jsongz,hdf5}
50 Storage format for downloaded candle (OHLCV) data.
51 (default: `None`).
52 --data-format-trades {json,jsongz,hdf5}
53 Storage format for downloaded trades data. (default:
54 `None`).
55
56Common arguments:
57 -v, --verbose Verbose mode (-vv for more, -vvv to get all messages).
58 --logfile FILE Log to the file specified. Special values are:
59 'syslog', 'journald'. See the documentation for more
60 details.
61 -V, --version show program's version number and exit
62 -c PATH, --config PATH
63 Specify configuration file (default:
64 `userdir/config.json` or `config.json` whichever
65 exists). Multiple --config options may be used. Can be
66 set to `-` to read config from stdin.
67 -d PATH, --datadir PATH
68 Path to directory with historical backtesting data.
69 --userdir PATH, --user-data-dir PATH
70 Path to userdata directory.
71
72```
73
74!!! Note "Startup period"
75 `download-data` is a strategy-independent command. The idea is to download a big chunk of data once, and then iteratively increase the amount of data stored.
76
77 For that reason, `download-data` does not care about the "startup-period" defined in a strategy. It's up to the user to download additional days if the backtest should start at a specific point in time (while respecting startup period).
78
79### Data format
80
81Freqtrade currently supports 3 data-formats for both OHLCV and trades data:
82
83* `json` (plain "text" json files)
84* `jsongz` (a gzip-zipped version of json files)
85* `hdf5` (a high performance datastore)
86
87By default, OHLCV data is stored as `json` data, while trades data is stored as `jsongz` data.
88
89This can be changed via the `--data-format-ohlcv` and `--data-format-trades` command line arguments respectively.
90To persist this change, you can should also add the following snippet to your configuration, so you don't have to insert the above arguments each time:
91
92``` jsonc
93 // ...
94 "dataformat_ohlcv": "hdf5",
95 "dataformat_trades": "hdf5",
96 // ...
97```
98
99If the default data-format has been changed during download, then the keys `dataformat_ohlcv` and `dataformat_trades` in the configuration file need to be adjusted to the selected dataformat as well.
100
101!!! Note
102 You can convert between data-formats using the [convert-data](#sub-command-convert-data) and [convert-trade-data](#sub-command-convert-trade-data) methods.
103
104#### Sub-command convert data
105
106```
107usage: freqtrade convert-data [-h] [-v] [--logfile FILE] [-V] [-c PATH]
108 [-d PATH] [--userdir PATH]
109 [-p PAIRS [PAIRS ...]] --format-from
110 {json,jsongz,hdf5} --format-to
111 {json,jsongz,hdf5} [--erase]
112 [-t {1m,3m,5m,15m,30m,1h,2h,4h,6h,8h,12h,1d,3d,1w,2w,1M,1y} [{1m,3m,5m,15m,30m,1h,2h,4h,6h,8h,12h,1d,3d,1w,2w,1M,1y} ...]]
113
114optional arguments:
115 -h, --help show this help message and exit
116 -p PAIRS [PAIRS ...], --pairs PAIRS [PAIRS ...]
117 Show profits for only these pairs. Pairs are space-
118 separated.
119 --format-from {json,jsongz,hdf5}
120 Source format for data conversion.
121 --format-to {json,jsongz,hdf5}
122 Destination format for data conversion.
123 --erase Clean all existing data for the selected
124 exchange/pairs/timeframes.
125 -t {1m,3m,5m,15m,30m,1h,2h,4h,6h,8h,12h,1d,3d,1w,2w,1M,1y} [{1m,3m,5m,15m,30m,1h,2h,4h,6h,8h,12h,1d,3d,1w,2w,1M,1y} ...], --timeframes {1m,3m,5m,15m,30m,1h,2h,4h,6h,8h,12h,1d,3d,1w,2w,1M,1y} [{1m,3m,5m,15m,30m,1h,2h,4h,6h,8h,12h,1d,3d,1w,2w,1M,1y} ...]
126 Specify which tickers to download. Space-separated
127 list. Default: `1m 5m`.
128
129Common arguments:
130 -v, --verbose Verbose mode (-vv for more, -vvv to get all messages).
131 --logfile FILE Log to the file specified. Special values are:
132 'syslog', 'journald'. See the documentation for more
133 details.
134 -V, --version show program's version number and exit
135 -c PATH, --config PATH
136 Specify configuration file (default:
137 `userdir/config.json` or `config.json` whichever
138 exists). Multiple --config options may be used. Can be
139 set to `-` to read config from stdin.
140 -d PATH, --datadir PATH
141 Path to directory with historical backtesting data.
142 --userdir PATH, --user-data-dir PATH
143 Path to userdata directory.
144```
145
146##### Example converting data
147
148The following command will convert all candle (OHLCV) data available in `~/.freqtrade/data/binance` from json to jsongz, saving diskspace in the process.
149It'll also remove original json data files (`--erase` parameter).
150
151``` bash
152freqtrade convert-data --format-from json --format-to jsongz --datadir ~/.freqtrade/data/binance -t 5m 15m --erase
153```
154
155#### Sub-command convert trade data
156
157```
158usage: freqtrade convert-trade-data [-h] [-v] [--logfile FILE] [-V] [-c PATH]
159 [-d PATH] [--userdir PATH]
160 [-p PAIRS [PAIRS ...]] --format-from
161 {json,jsongz,hdf5} --format-to
162 {json,jsongz,hdf5} [--erase]
163
164optional arguments:
165 -h, --help show this help message and exit
166 -p PAIRS [PAIRS ...], --pairs PAIRS [PAIRS ...]
167 Show profits for only these pairs. Pairs are space-
168 separated.
169 --format-from {json,jsongz,hdf5}
170 Source format for data conversion.
171 --format-to {json,jsongz,hdf5}
172 Destination format for data conversion.
173 --erase Clean all existing data for the selected
174 exchange/pairs/timeframes.
175
176Common arguments:
177 -v, --verbose Verbose mode (-vv for more, -vvv to get all messages).
178 --logfile FILE Log to the file specified. Special values are:
179 'syslog', 'journald'. See the documentation for more
180 details.
181 -V, --version show program's version number and exit
182 -c PATH, --config PATH
183 Specify configuration file (default:
184 `userdir/config.json` or `config.json` whichever
185 exists). Multiple --config options may be used. Can be
186 set to `-` to read config from stdin.
187 -d PATH, --datadir PATH
188 Path to directory with historical backtesting data.
189 --userdir PATH, --user-data-dir PATH
190 Path to userdata directory.
191
192```
193
194##### Example converting trades
195
196The following command will convert all available trade-data in `~/.freqtrade/data/kraken` from jsongz to json.
197It'll also remove original jsongz data files (`--erase` parameter).
198
199``` bash
200freqtrade convert-trade-data --format-from jsongz --format-to json --datadir ~/.freqtrade/data/kraken --erase
201```
202
203### Sub-command list-data
204
205You can get a list of downloaded data using the `list-data` sub-command.
206
207```
208usage: freqtrade list-data [-h] [-v] [--logfile FILE] [-V] [-c PATH] [-d PATH]
209 [--userdir PATH] [--exchange EXCHANGE]
210 [--data-format-ohlcv {json,jsongz,hdf5}]
211 [-p PAIRS [PAIRS ...]]
212
213optional arguments:
214 -h, --help show this help message and exit
215 --exchange EXCHANGE Exchange name (default: `bittrex`). Only valid if no
216 config is provided.
217 --data-format-ohlcv {json,jsongz,hdf5}
218 Storage format for downloaded candle (OHLCV) data.
219 (default: `json`).
220 -p PAIRS [PAIRS ...], --pairs PAIRS [PAIRS ...]
221 Show profits for only these pairs. Pairs are space-
222 separated.
223
224Common arguments:
225 -v, --verbose Verbose mode (-vv for more, -vvv to get all messages).
226 --logfile FILE Log to the file specified. Special values are:
227 'syslog', 'journald'. See the documentation for more
228 details.
229 -V, --version show program's version number and exit
230 -c PATH, --config PATH
231 Specify configuration file (default:
232 `userdir/config.json` or `config.json` whichever
233 exists). Multiple --config options may be used. Can be
234 set to `-` to read config from stdin.
235 -d PATH, --datadir PATH
236 Path to directory with historical backtesting data.
237 --userdir PATH, --user-data-dir PATH
238 Path to userdata directory.
239
240```
241
242#### Example list-data
243
244```bash
245> freqtrade list-data --userdir ~/.freqtrade/user_data/
246
247Found 33 pair / timeframe combinations.
248pairs timeframe
249---------- -----------------------------------------
250ADA/BTC 5m, 15m, 30m, 1h, 2h, 4h, 6h, 12h, 1d
251ADA/ETH 5m, 15m, 30m, 1h, 2h, 4h, 6h, 12h, 1d
252ETH/BTC 5m, 15m, 30m, 1h, 2h, 4h, 6h, 12h, 1d
253ETH/USDT 5m, 15m, 30m, 1h, 2h, 4h
254```
255
256### Pairs file
257
258In alternative to the whitelist from `config.json`, a `pairs.json` file can be used.
259
260If you are using Binance for example:
261
262- create a directory `user_data/data/binance` and copy or create the `pairs.json` file in that directory.
263- update the `pairs.json` file to contain the currency pairs you are interested in.
264
265```bash
266mkdir -p user_data/data/binance
267cp tests/testdata/pairs.json user_data/data/binance
268```
269
270If you your configuration directory `user_data` was made by docker, you may get the following error:
271
272```
273cp: cannot create regular file 'user_data/data/binance/pairs.json': Permission denied
274```
275
276You can fix the permissions of your user-data directory as follows:
277
278```
279sudo chown -R $UID:$GID user_data
280```
281
282The format of the `pairs.json` file is a simple json list.
283Mixing different stake-currencies is allowed for this file, since it's only used for downloading.
284
285``` json
286[
287 "ETH/BTC",
288 "ETH/USDT",
289 "BTC/USDT",
290 "XRP/ETH"
291]
292```
293
294### Start download
295
296Then run:
297
298```bash
299freqtrade download-data --exchange binance
300```
301
302This will download historical candle (OHLCV) data for all the currency pairs you defined in `pairs.json`.
303
304### Other Notes
305
306- To use a different directory than the exchange specific default, use `--datadir user_data/data/some_directory`.
307- To change the exchange used to download the historical data from, please use a different configuration file (you'll probably need to adjust rate limits etc.)
308- To use `pairs.json` from some other directory, use `--pairs-file some_other_dir/pairs.json`.
309- To download historical candle (OHLCV) data for only 10 days, use `--days 10` (defaults to 30 days).
310- To download historical candle (OHLCV) data from a fixed starting point, use `--timerange 20200101-` - which will download all data from January 1st, 2020. Eventually set end dates are ignored.
311- Use `--timeframes` to specify what timeframe download the historical candle (OHLCV) data for. Default is `--timeframes 1m 5m` which will download 1-minute and 5-minute data.
312- To use exchange, timeframe and list of pairs as defined in your configuration file, use the `-c/--config` option. With this, the script uses the whitelist defined in the config as the list of currency pairs to download data for and does not require the pairs.json file. You can combine `-c/--config` with most other options.
313
314### Trades (tick) data
315
316By default, `download-data` sub-command downloads Candles (OHLCV) data. Some exchanges also provide historic trade-data via their API.
317This data can be useful if you need many different timeframes, since it is only downloaded once, and then resampled locally to the desired timeframes.
318
319Since this data is large by default, the files use gzip by default. They are stored in your data-directory with the naming convention of `<pair>-trades.json.gz` (`ETH_BTC-trades.json.gz`). Incremental mode is also supported, as for historic OHLCV data, so downloading the data once per week with `--days 8` will create an incremental data-repository.
320
321To use this mode, simply add `--dl-trades` to your call. This will swap the download method to download trades, and resamples the data locally.
322
323!!! Warning "do not use"
324 You should not use this unless you're a kraken user. Most other exchanges provide OHLCV data with sufficient history.
325
326Example call:
327
328```bash
329freqtrade download-data --exchange kraken --pairs XRP/EUR ETH/EUR --days 20 --dl-trades
330```
331
332!!! Note
333 While this method uses async calls, it will be slow, since it requires the result of the previous call to generate the next request to the exchange.
334
335!!! Warning
336 The historic trades are not available during Freqtrade dry-run and live trade modes because all exchanges tested provide this data with a delay of few 100 candles, so it's not suitable for real-time trading.
337
338!!! Note "Kraken user"
339 Kraken users should read [this](exchanges.md#historic-kraken-data) before starting to download data.
340
341## Next step
342
343Great, you now have backtest data downloaded, so you can now start [backtesting](backtesting.md) your strategy.