Repository: freqtrade/freqtrade

Issue:
download-data does not stop downloading at the specified TIMERANGE end date

## Describe your environment

  * Operating system: Microsoft Windows [Version 10.0.19042.804]
  * Python Version: 3.8.6
  * CCXT version: 1.40.99
  * Freqtrade Version: docker-1310a7b5
  
## Describe the problem:

download-data does not stop downloading at the TIMERANGE end date specified on the command line, and continues to download all data until the present.  

### Steps to reproduce:

  1. set up config.json for Kraken with recommended rate limits and download_trades enabled
  2. whitelist DOGE/USD (or any pair with high volume and historical data as far back as 20200101)
  3. run download-data and specify a timerange of a single day, 20200101-20200102: `docker-compose run --rm freqtrade download-data --timerange 20200101-20200102 -t 1m 5m 1h` 
  
### Observed Results:

  * What happened?

Although a timerange with an end date is specified, freqtrade continues to download all trades up to the present, this takes almost two hours with DOGE/USD (once i finally realized what was going on, and let it complete)

  * What did you expect to happen?

I tried this multiple times, and each time concluded that the download had failed or gotten stuck, because downloading the most recent few days takes only minutes, and I was specifying a timerange of a similar length, which I expected to take a similar amount of time.  Often there would be one or more API warning messages, further indicating to me that something about the process had failed.

No indication is given that the end date of the timerange is being ignored.  Indeed, the full timerange is logged by default, including the end date, further leading me to believe it would be honoured: `Parameter --timerange detected: 20200101-20200102`

Only when debug logging is enabled can you see that:
* debug line indicating that the _async_get_trade_history() `until` parameter is None, 
* the logged fetch `since` times continue past the end date, once the logged values are converted to human readable dates.
* (if the process is allowed to complete) debug logged `New End:` is today, and not the requested date

While this doesn't seem to matter much for exchanges that provide OHLCV data and can complete this entire process within seconds, it makes it much less practical to download Kraken data, as it requires downloading the entire history of many hours, instead of a partial history in minutes, which would be useful for either targeted backtesting, or downloading the entire history in stages, by week or month, instead of having a single, many hours or days long, process susceptible to network disconnects or API failures.

### Relevant code exceptions or logs

```
docker-compose run --rm freqtrade download-data --config user_data/config-kraken-download.json --timerange 20200101-20200102 -t 1m 5m 1h -vv
Creating ft_data_freqtrade_run ... done
2021-02-21 10:52:59,162 - freqtrade.configuration.configuration - INFO - Using config: user_data/config-kraken-download.json ...
2021-02-21 10:52:59,164 - freqtrade.loggers - INFO - Verbosity set to 2
2021-02-21 10:52:59,164 - freqtrade.configuration.configuration - INFO - Parameter --timerange detected: 20200101-20200102 ...
2021-02-21 10:52:59,168 - freqtrade.configuration.configuration - INFO - Using user-data directory: /freqtrade/user_data ...
2021-02-21 10:52:59,169 - freqtrade.configuration.configuration - INFO - Using data directory: /freqtrade/user_data/data/kraken ...
2021-02-21 10:52:59,170 - freqtrade.configuration.configuration - INFO - timeframes --timeframes: ['1m', '5m', '1h']
2021-02-21 10:52:59,170 - freqtrade.configuration.check_exchange - INFO - Checking exchange...
2021-02-21 10:52:59,170 - freqtrade.configuration.check_exchange - INFO - Exchange "kraken" is officially supported by the Freqtrade development team.
2021-02-21 10:52:59,170 - freqtrade.configuration.configuration - INFO - Using pairlist from configuration.
2021-02-21 10:52:59,170 - freqtrade.configuration.config_validation - INFO - Validating configuration ...
2021-02-21 10:52:59,174 - freqtrade.exchange.exchange - INFO - Instance is running with dry_run enabled
2021-02-21 10:52:59,174 - freqtrade.exchange.exchange - INFO - Using CCXT 1.40.99
2021-02-21 10:52:59,174 - freqtrade.exchange.exchange - INFO - Applying additional ccxt config: {'enableRateLimit': True}
2021-02-21 10:52:59,176 - freqtrade.exchange.exchange - INFO - Applying additional ccxt config: {'enableRateLimit': True, 'rateLimit': 3100}
2021-02-21 10:52:59,176 - asyncio - DEBUG - Using selector: EpollSelector
2021-02-21 10:52:59,179 - freqtrade.exchange.exchange - INFO - Using Exchange "Kraken"
2021-02-21 10:52:59,179 - freqtrade.resolvers.exchange_resolver - INFO - Using resolved exchange 'Kraken'...
2021-02-21 10:52:59,179 - freqtrade.exchange.exchange - INFO - Markets were not loaded. Loading them now..
2021-02-21 10:52:59,180 - urllib3.connectionpool - DEBUG - Starting new HTTPS connection (1): api.kraken.com:443
2021-02-21 10:52:59,229 - urllib3.connectionpool - DEBUG - https://api.kraken.com:443 "GET /0/public/Assets HTTP/1.1" 200 None
2021-02-21 10:53:02,223 - urllib3.connectionpool - DEBUG - https://api.kraken.com:443 "GET /0/public/AssetPairs HTTP/1.1" 200 None
2021-02-21 10:53:02,401 - freqtrade.commands.data_commands - INFO - About to download pairs: ['DOGE/USD'], intervals: ['1m', '5m', '1h'] to /freqtrade/user_data/data/kraken
2021-02-21 10:53:02,402 - freqtrade.data.history.history_utils - INFO - Downloading trades for pair DOGE/USD.
2021-02-21 10:53:02,404 - freqtrade.data.history.history_utils - DEBUG - Current Start: None
2021-02-21 10:53:02,404 - freqtrade.data.history.history_utils - DEBUG - Current End: None
2021-02-21 10:53:02,405 - freqtrade.data.history.history_utils - INFO - Current Amount of trades: 0
2021-02-21 10:53:02,405 - freqtrade.exchange.exchange - DEBUG - _async_get_trade_history(), pair: DOGE/USD, since: 1577836800000, until: None, from_id: None
2021-02-21 10:53:02,405 - freqtrade.exchange.exchange - DEBUG - Exchange milliseconds: 1613904782405
2021-02-21 10:53:02,405 - freqtrade.exchange.exchange - DEBUG - Fetching trades for pair DOGE/USD, since 1577836800000 (2020-01-01T00:00:00+00:00) ...
2021-02-21 10:53:05,602 - freqtrade.exchange.exchange - DEBUG - Fetching trades for pair DOGE/USD, params: {'since': '1579066744382700000'}
2021-02-21 10:53:08,691 - freqtrade.exchange.exchange - DEBUG - Fetching trades for pair DOGE/USD, params: {'since': '1580264645788800000'}
2021-02-21 10:53:11,832 - freqtrade.exchange.exchange - DEBUG - Fetching trades for pair DOGE/USD, params: {'since': '1581037076332300000'}
2021-02-21 10:53:14,905 - freqtrade.exchange.exchange - DEBUG - Fetching trades for pair DOGE/USD, params: {'since': '1581241002258300000'}
2021-02-21 10:53:18,018 - freqtrade.exchange.exchange - DEBUG - Fetching trades for pair DOGE/USD, params: {'since': '1581533893480400000'}
2021-02-21 10:53:21,108 - freqtrade.exchange.exchange - DEBUG - Fetching trades for pair DOGE/USD, params: {'since': '1581694457906600000'}
2021-02-21 10:53:24,226 - freqtrade.exchange.exchange - DEBUG - Fetching trades for pair DOGE/USD, params: {'since': '1581790760953300000'}
2021-02-21 10:53:27,314 - freqtrade.exchange.exchange - DEBUG - Fetching trades for pair DOGE/USD, params: {'since': '1582285223266800000'}
2021-02-21 10:53:30,412 - freqtrade.exchange.exchange - DEBUG - Fetching trades for pair DOGE/USD, params: {'since': '1583270766319100000'}
2021-02-21 10:53:33,492 - freqtrade.exchange.exchange - DEBUG - Fetching trades for pair DOGE/USD, params: {'since': '1584026721442800000'}
2021-02-21 10:53:36,656 - freqtrade.exchange.exchange - DEBUG - Fetching trades for pair DOGE/USD, params: {'since': '1584353055363500000'}
2021-02-21 10:53:40,327 - freqtrade.exchange.exchange - DEBUG - Fetching trades for pair DOGE/USD, params: {'since': '1584717725924000000'}
2021-02-21 10:53:43,426 - freqtrade.exchange.exchange - DEBUG - Fetching trades for pair DOGE/USD, params: {'since': '1586032024820900000'}
2021-02-21 10:53:45,936 - freqtrade.exchange.exchange - DEBUG - Fetching trades for pair DOGE/USD, params: {'since': '1587682110293100000'}
2021-02-21 10:53:49,506 - freqtrade.exchange.exchange - DEBUG - Fetching trades for pair DOGE/USD, params: {'since': '1587982305851100000'}

[snip]

... by this point, the download has already well passed the timerange end date...

[snip]

2021-02-21 12:27:04,565 - freqtrade.exchange.exchange - DEBUG - Fetching trades for pair DOGE/USD, params: {'since': '1613839961773268166'}
2021-02-21 12:27:07,697 - freqtrade.exchange.exchange - DEBUG - Fetching trades for pair DOGE/USD, params: {'since': '1613844860755625125'}
2021-02-21 12:27:10,777 - freqtrade.exchange.exchange - DEBUG - Fetching trades for pair DOGE/USD, params: {'since': '1613852556363404114'}
2021-02-21 12:27:13,861 - freqtrade.exchange.exchange - DEBUG - Fetching trades for pair DOGE/USD, params: {'since': '1613854822751834520'}
2021-02-21 12:27:16,983 - freqtrade.exchange.exchange - DEBUG - Fetching trades for pair DOGE/USD, params: {'since': '1613858755280910012'}
2021-02-21 12:27:20,547 - freqtrade.exchange.exchange - DEBUG - Fetching trades for pair DOGE/USD, params: {'since': '1613860924089561296'}
2021-02-21 12:27:23,141 - freqtrade.exchange.exchange - DEBUG - Fetching trades for pair DOGE/USD, params: {'since': '1613861918937344013'}
2021-02-21 12:27:26,247 - freqtrade.exchange.exchange - DEBUG - Fetching trades for pair DOGE/USD, params: {'since': '1613866678782574805'}
2021-02-21 12:27:29,411 - freqtrade.exchange.exchange - DEBUG - Fetching trades for pair DOGE/USD, params: {'since': '1613873589042796409'}
2021-02-21 12:27:32,473 - freqtrade.exchange.exchange - DEBUG - Fetching trades for pair DOGE/USD, params: {'since': '1613882246670538565'}
2021-02-21 12:27:35,573 - freqtrade.exchange.exchange - DEBUG - Fetching trades for pair DOGE/USD, params: {'since': '1613899009724676906'}
2021-02-21 12:27:38,659 - freqtrade.exchange.exchange - DEBUG - Stopping because from_id did not change. Reached 1613910446686 > 1613904782405
2021-02-21 12:27:39,131 - freqtrade.misc - INFO - dumping json to "/freqtrade/user_data/data/kraken/DOGE_USD-trades.json.gz"
2021-02-21 12:27:53,229 - freqtrade.misc - DEBUG - done json to "/freqtrade/user_data/data/kraken/DOGE_USD-trades.json.gz"
2021-02-21 12:27:53,229 - freqtrade.data.history.history_utils - DEBUG - New Start: 2020-01-01T00:32:50
2021-02-21 12:27:53,229 - freqtrade.data.history.history_utils - DEBUG - New End: 2021-02-21T12:27:26
2021-02-21 12:27:53,229 - freqtrade.data.history.history_utils - INFO - New Amount of trades: 1824720
2021-02-21 12:27:53,376 - freqtrade.misc - DEBUG - Loading historical data from file /freqtrade/user_data/data/kraken/DOGE_USD-trades.json.gz
2021-02-21 12:28:01,184 - numexpr.utils - INFO - NumExpr defaulting to 4 threads.
2021-02-21 12:28:05,200 - freqtrade.exchange.exchange - DEBUG - Exchange object destroyed, closing async loop
```


Discussion:
Try `--timerange=20200101-20200102`
It's documented in the data-downloading docs:

> 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.

[source](https://www.freqtrade.io/en/latest/data-download/#other-notes)

Specifying an end-date does usually not make sense, and download-data is designed to do incremental downloads - so the "big" chunk of downloading will happen once, and then you do incremental updates every few days (which will then not take a long time).
> It's documented in the data-downloading docs:
> 
> > 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.
> 
> [source](https://www.freqtrade.io/en/latest/data-download/#other-notes)

So it is!  I would still stay that this detail is in a place easy to miss if you don't already know it's there.  I would suggest at a minimum, for ease of use, that if an end date is specified, a warning is printed indicated that it will not be used.

> Specifying an end-date does usually not make sense, and download-data is designed to do incremental downloads - so the "big" chunk of downloading will happen once, and then you do incremental updates every few days (which will then not take a long time).

While I understand you feel it "usually" does not make sense. Is there a problem with implementing the end date for the cases where it does make sense? for example:

> ...it makes it much less practical to download Kraken data, as it requires downloading the entire history of many hours, instead of a partial history in minutes, which would be useful for either targeted backtesting, or downloading the entire history in stages, by week or month, instead of having a single, many hours or days long, process susceptible to network disconnects or API failures.

This isn't a hypothetical situation, it really would be useful to me.  

If you aren't interested in implementing it yourself, would you accept a pull request implementing this functionality?

it's not about interrested, but about time.
This will only benefit a very small % of users (if at all) - so i don't see much point in spending my time on it.

Pull Requests - in general yes - but it'll also depend on what'll be required to make it work (and how it'll be implemented).

Of course.  My impression was that it would be a relatively simple and low risk fix, but perhaps once I look into it I will find out otherwise.  I'll see about setting up a dev environment to take a stab at it.
i honestly can't tell you - I've never really looked at it in too much detail.

The whole `--timerange` support for download-data is also quite new (half a year or so)- previously we used to only support `--days` - which by definition doesn't allow you to specify an end date - and i think only the "from" part is passed to the downloading methods.
FWIW coinbasepro result limit is 300 which is so tight, it is essentially impossible to download data without a tighter control. @brookmiles I will test patches.
@pearcec i'm not sure your comment is related to this issue. 
@xmatthias, It relates since the experience I have is the same.  The `--timerange`  parameter supplied does not match what is sent to the exchange.  For coinbasepro the limits on the number of returned is 300.  So if the range is to larger for a given granularity it will result in an error.  So it is virtually impossible to download data.

So I am highlighting a user experience.

```
docker-compose run --rm freqtrade download-data --pairs XTZ/USD --exchange coinbasepro  --timerange=20210224-20210225  -t 1h -vvv --erase
```

```
2021-02-27 17:51:53,361 - freqtrade.data.history.history_utils - INFO - Downloading pair XTZ/USD, interval 1h.
2021-02-27 17:51:53,361 - freqtrade.data.history.history_utils - INFO - Download history data for pair: "XTZ/USD", timeframe: 1h and store in /freqtrade/user_data/data/coinbasepro.
2021-02-27 17:51:53,365 - freqtrade.data.history.history_utils - DEBUG - Current Start: None
2021-02-27 17:51:53,365 - freqtrade.data.history.history_utils - DEBUG - Current End: None
2021-02-27 17:51:53,365 - freqtrade.exchange.exchange - DEBUG - one_call: 1800000000 msecs (2 weeks)
2021-02-27 17:51:53,365 - freqtrade.exchange.exchange - DEBUG - Fetching pair XTZ/USD, interval 1h, since 1614124800000 (2021-02-24T00:00:00+00:00) ...
2021-02-27 17:51:53,744 - ccxt.base.exchange - DEBUG - GET https://api.pro.coinbase.com/products/XTZ-USD/candles?granularity=3600&start=2021-02-24T00%3A00%3A00.000Z&end=2021-03-16T19%3A00%3A00.000Z, Request: None None
2021-02-27 17:51:53,827 - ccxt.base.exchange - DEBUG - GET https://api.pro.coinbase.com/products/XTZ-USD/candles?granularity=3600&start=2021-02-24T00%3A00%3A00.000Z&end=2021-03-16T19%3A00%3A00.000Z, Response: 400 <CIMultiDictProxy('Date': 'Sat, 27 Feb 2021 17:51:54 GMT', 'Content-Type': 'application/json; charset=utf-8', 'Content-Length': '109', 'Connection': 'keep-alive', 'Access-Control-Allow-Headers': 'Content-Type, Accept, cb-session, cb-fp, cb-form-factor', 'Access-Control-Allow-Methods': 'GET,POST,DELETE,PUT', 'Access-Control-Allow-Origin': '*', 'Access-Control-Expose-Headers': 'cb-before, cb-after, cb-gdpr', 'Access-Control-Max-Age': '7200', 'Cache-Control': 'no-store', 'Etag': 'W/"6d-HnduZAYLI/jEyGyBkryvU+e/oSo"', 'Strict-Transport-Security': 'max-age=15552000; includeSubDomains', 'X-Content-Type-Options': 'nosniff', 'X-Dns-Prefetch-Control': 'off', 'X-Download-Options': 'noopen', 'X-Frame-Options': 'SAMEORIGIN', 'X-Xss-Protection': '1; mode=block', 'CF-Cache-Status': 'MISS', 'cf-request-id': '0886375e5e0000c5f87c879000000001', 'Expect-CT': 'max-age=604800, report-uri="https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct"', 'Vary': 'Accept-Encoding', 'Server': 'cloudflare', 'CF-RAY': '6283c1aa29b1c5f8-EWR')> {"message":"granularity too small for the requested time range. Count of aggregations requested exceeds 300"}
2021-02-27 17:51:53,827 - freqtrade.exchange.common - WARNING - _async_get_candle_history() returned exception: "Could not fetch historical candle (OHLCV) data for pair XTZ/USD due to ExchangeError. Message: coinbasepro granularity too small for the requested time range. Count of aggregations requested exceeds 300"
2021-02-27 17:51:53,827 - freqtrade.exchange.common - WARNING - retrying _async_get_candle_history() still for 4 times
2021-02-27 17:51:53,828 - freqtrade.exchange.exchange - DEBUG - Fetching pair XTZ/USD, interval 1h, since 1614124800000 (2021-02-24T00:00:00+00:00) ...
2021-02-27 17:51:54,243 - ccxt.base.exchange - DEBUG - GET https://api.pro.coinbase.com/products/XTZ-USD/candles?granularity=3600&start=2021-02-24T00%3A00%3A00.000Z&end=2021-03-16T19%3A00%3A00.000Z, Request: None None
2021-02-27 17:51:54,316 - ccxt.base.exchange - DEBUG - GET https://api.pro.coinbase.com/products/XTZ-USD/candles?granularity=3600&start=2021-02-24T00%3A00%3A00.000Z&end=2021-03-16T19%3A00%3A00.000Z, Response: 400 <CIMultiDictProxy('Date': 'Sat, 27 Feb 2021 17:51:54 GMT', 'Content-Type': 'application/json; charset=utf-8', 'Content-Length': '109', 'Connection': 'keep-alive', 'Access-Control-Allow-Headers': 'Content-Type, Accept, cb-session, cb-fp, cb-form-factor', 'Access-Control-Allow-Methods': 'GET,POST,DELETE,PUT', 'Access-Control-Allow-Origin': '*', 'Access-Control-Expose-Headers': 'cb-before, cb-after, cb-gdpr', 'Access-Control-Max-Age': '7200', 'Cache-Control': 'no-store', 'Etag': 'W/"6d-HnduZAYLI/jEyGyBkryvU+e/oSo"', 'Strict-Transport-Security': 'max-age=15552000; includeSubDomains', 'X-Content-Type-Options': 'nosniff', 'X-Dns-Prefetch-Control': 'off', 'X-Download-Options': 'noopen', 'X-Frame-Options': 'SAMEORIGIN', 'X-Xss-Protection': '1; mode=block', 'CF-Cache-Status': 'MISS', 'cf-request-id': '08863760520000c5f84c8c5000000001', 'Expect-CT': 'max-age=604800, report-uri="https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct"', 'Vary': 'Accept-Encoding', 'Server': 'cloudflare', 'CF-RAY': '6283c1ad5c53c5f8-EWR')> {"message":"granularity too small for the requested time range. Count of aggregations requested exceeds 300"}
2021-02-27 17:51:54,316 - freqtrade.exchange.common - WARNING - _async_get_candle_history() returned exception: "Could not fetch historical candle (OHLCV) data for pair XTZ/USD due to ExchangeError. Message: coinbasepro granularity too small for the requested time range. Count of aggregations requested exceeds 300"
2021-02-27 17:51:54,316 - freqtrade.exchange.common - WARNING - retrying _async_get_candle_history() still for 3 times
2021-02-27 17:51:54,316 - freqtrade.exchange.exchange - DEBUG - Fetching pair XTZ/USD, interval 1h, since 1614124800000 (2021-02-24T00:00:00+00:00) ...
2021-02-27 17:51:54,743 - ccxt.base.exchange - DEBUG - GET https://api.pro.coinbase.com/products/XTZ-USD/candles?granularity=3600&start=2021-02-24T00%3A00%3A00.000Z&end=2021-03-16T19%3A00%3A00.000Z, Request: None None
2021-02-27 17:51:54,829 - ccxt.base.exchange - DEBUG - GET https://api.pro.coinbase.com/products/XTZ-USD/candles?granularity=3600&start=2021-02-24T00%3A00%3A00.000Z&end=2021-03-16T19%3A00%3A00.000Z, Response: 400 <CIMultiDictProxy('Date': 'Sat, 27 Feb 2021 17:51:55 GMT', 'Content-Type': 'application/json; charset=utf-8', 'Content-Length': '109', 'Connection': 'keep-alive', 'Access-Control-Allow-Headers': 'Content-Type, Accept, cb-session, cb-fp, cb-form-factor', 'Access-Control-Allow-Methods': 'GET,POST,DELETE,PUT', 'Access-Control-Allow-Origin': '*', 'Access-Control-Expose-Headers': 'cb-before, cb-after, cb-gdpr', 'Access-Control-Max-Age': '7200', 'Cache-Control': 'no-store', 'Etag': 'W/"6d-HnduZAYLI/jEyGyBkryvU+e/oSo"', 'Strict-Transport-Security': 'max-age=15552000; includeSubDomains', 'X-Content-Type-Options': 'nosniff', 'X-Dns-Prefetch-Control': 'off', 'X-Download-Options': 'noopen', 'X-Frame-Options': 'SAMEORIGIN', 'X-Xss-Protection': '1; mode=block', 'CF-Cache-Status': 'MISS', 'cf-request-id': '08863762450000c5f818aab000000001', 'Expect-CT': 'max-age=604800, report-uri="https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct"', 'Vary': 'Accept-Encoding', 'Server': 'cloudflare', 'CF-RAY': '6283c1b06f55c5f8-EWR')> {"message":"granularity too small for the requested time range. Count of aggregations requested exceeds 300"}
2021-02-27 17:51:54,830 - freqtrade.exchange.common - WARNING - _async_get_candle_history() returned exception: "Could not fetch historical candle (OHLCV) data for pair XTZ/USD due to ExchangeError. Message: coinbasepro granularity too small for the requested time range. Count of aggregations requested exceeds 300"
2021-02-27 17:51:54,830 - freqtrade.exchange.common - WARNING - retrying _async_get_candle_history() still for 2 times
2021-02-27 17:51:54,830 - freqtrade.exchange.exchange - DEBUG - Fetching pair XTZ/USD, interval 1h, since 1614124800000 (2021-02-24T00:00:00+00:00) ...
2021-02-27 17:51:55,244 - ccxt.base.exchange - DEBUG - GET https://api.pro.coinbase.com/products/XTZ-USD/candles?granularity=3600&start=2021-02-24T00%3A00%3A00.000Z&end=2021-03-16T19%3A00%3A00.000Z, Request: None None
2021-02-27 17:51:55,288 - ccxt.base.exchange - DEBUG - GET https://api.pro.coinbase.com/products/XTZ-USD/candles?granularity=3600&start=2021-02-24T00%3A00%3A00.000Z&end=2021-03-16T19%3A00%3A00.000Z, Response: 400 <CIMultiDictProxy('Date': 'Sat, 27 Feb 2021 17:51:55 GMT', 'Content-Type': 'application/json; charset=utf-8', 'Content-Length': '109', 'Connection': 'keep-alive', 'Access-Control-Allow-Headers': 'Content-Type, Accept, cb-session, cb-fp, cb-form-factor', 'Access-Control-Allow-Methods': 'GET,POST,DELETE,PUT', 'Access-Control-Allow-Origin': '*', 'Access-Control-Expose-Headers': 'cb-before, cb-after, cb-gdpr', 'Access-Control-Max-Age': '7200', 'Cache-Control': 'no-store', 'Etag': 'W/"6d-HnduZAYLI/jEyGyBkryvU+e/oSo"', 'Strict-Transport-Security': 'max-age=15552000; includeSubDomains', 'X-Content-Type-Options': 'nosniff', 'X-Dns-Prefetch-Control': 'off', 'X-Download-Options': 'noopen', 'X-Frame-Options': 'SAMEORIGIN', 'X-Xss-Protection': '1; mode=block', 'CF-Cache-Status': 'MISS', 'cf-request-id': '088637643b0000c5f87c8bd000000001', 'Expect-CT': 'max-age=604800, report-uri="https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct"', 'Vary': 'Accept-Encoding', 'Server': 'cloudflare', 'CF-RAY': '6283c1b39b21c5f8-EWR')> {"message":"granularity too small for the requested time range. Count of aggregations requested exceeds 300"}
2021-02-27 17:51:55,288 - freqtrade.exchange.common - WARNING - _async_get_candle_history() returned exception: "Could not fetch historical candle (OHLCV) data for pair XTZ/USD due to ExchangeError. Message: coinbasepro granularity too small for the requested time range. Count of aggregations requested exceeds 300"
2021-02-27 17:51:55,288 - freqtrade.exchange.common - WARNING - retrying _async_get_candle_history() still for 1 times
2021-02-27 17:51:55,288 - freqtrade.exchange.exchange - DEBUG - Fetching pair XTZ/USD, interval 1h, since 1614124800000 (2021-02-24T00:00:00+00:00) ...
2021-02-27 17:51:55,743 - ccxt.base.exchange - DEBUG - GET https://api.pro.coinbase.com/products/XTZ-USD/candles?granularity=3600&start=2021-02-24T00%3A00%3A00.000Z&end=2021-03-16T19%3A00%3A00.000Z, Request: None None
2021-02-27 17:51:55,818 - ccxt.base.exchange - DEBUG - GET https://api.pro.coinbase.com/products/XTZ-USD/candles?granularity=3600&start=2021-02-24T00%3A00%3A00.000Z&end=2021-03-16T19%3A00%3A00.000Z, Response: 400 <CIMultiDictProxy('Date': 'Sat, 27 Feb 2021 17:51:56 GMT', 'Content-Type': 'application/json; charset=utf-8', 'Content-Length': '109', 'Connection': 'keep-alive', 'Access-Control-Allow-Headers': 'Content-Type, Accept, cb-session, cb-fp, cb-form-factor', 'Access-Control-Allow-Methods': 'GET,POST,DELETE,PUT', 'Access-Control-Allow-Origin': '*', 'Access-Control-Expose-Headers': 'cb-before, cb-after, cb-gdpr', 'Access-Control-Max-Age': '7200', 'Cache-Control': 'no-store', 'Etag': 'W/"6d-HnduZAYLI/jEyGyBkryvU+e/oSo"', 'Strict-Transport-Security': 'max-age=15552000; includeSubDomains', 'X-Content-Type-Options': 'nosniff', 'X-Dns-Prefetch-Control': 'off', 'X-Download-Options': 'noopen', 'X-Frame-Options': 'SAMEORIGIN', 'X-Xss-Protection': '1; mode=block', 'CF-Cache-Status': 'MISS', 'cf-request-id': '088637662f0000c5f805914000000001', 'Expect-CT': 'max-age=604800, report-uri="https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct"', 'Vary': 'Accept-Encoding', 'Server': 'cloudflare', 'CF-RAY': '6283c1b6ae1bc5f8-EWR')> {"message":"granularity too small for the requested time range. Count of aggregations requested exceeds 300"}
2021-02-27 17:51:55,818 - freqtrade.exchange.common - WARNING - _async_get_candle_history() returned exception: "Could not fetch historical candle (OHLCV) data for pair XTZ/USD due to ExchangeError. Message: coinbasepro granularity too small for the requested time range. Count of aggregations requested exceeds 300"
2021-02-27 17:51:55,818 - freqtrade.exchange.common - WARNING - Giving up retrying: _async_get_candle_history()
2021-02-27 17:51:55,818 - freqtrade.exchange.exchange - WARNING - Async code raised an exception: TemporaryError
2021-02-27 17:51:55,818 - freqtrade.exchange.exchange - INFO - Downloaded data for XTZ/USD with length 0.
2021-02-27 17:51:55,818 - freqtrade.data.converter - DEBUG - Converting candle (OHLCV) data to dataframe for pair XTZ/USD.
2021-02-27 17:51:55,827 - freqtrade.data.converter - DEBUG - Dropping last candle
2021-02-27 17:51:55,827 - freqtrade.data.history.history_utils - DEBUG - New  Start: None
2021-02-27 17:51:55,827 - freqtrade.data.history.history_utils - DEBUG - New End: None
2021-02-27 17:51:55,830 - numexpr.utils - INFO - Note: NumExpr detected 16 cores but "NUMEXPR_MAX_THREADS" not set, so enforcing safe limit of 8.
2021-02-27 17:51:55,830 - numexpr.utils - INFO - NumExpr defaulting to 8 threads.
2021-02-27 17:51:55,836 - freqtrade.exchange.exchange - DEBUG - Exchange object destroyed, closing async loop
```
coinbasepro is not a supported exchange. If the maximum number of candles is 300, there's other ways to approach this to fix this correctly.

As mentioned above, it's got nothing to do with the end-date - as you can't expect to download the data in 300 minute chunks (you can't go below daily granularity, so you'd exclude 1m timeframes automatically.

Resolving patch:
diff --git a/freqtrade/data/history/history_utils.py b/freqtrade/data/history/history_utils.py
--- a/freqtrade/data/history/history_utils.py
+++ b/freqtrade/data/history/history_utils.py
@@ -265,9 +265,13 @@ def _download_trades_history(exchange: Exchange,
     """
     try:
 
-        since = timerange.startts * 1000 if \
-            (timerange and timerange.starttype == 'date') else int(arrow.utcnow().shift(
-                days=-new_pairs_days).float_timestamp) * 1000
+        until = None
+        if (timerange and timerange.starttype == 'date'):
+            since = timerange.startts * 1000
+            if timerange.stoptype == 'date':
+                until = timerange.stopts * 1000
+        else:
+            since = int(arrow.utcnow().shift(days=-new_pairs_days).float_timestamp) * 1000
 
         trades = data_handler.trades_load(pair)
 
@@ -295,6 +299,7 @@ def _download_trades_history(exchange: Exchange,
         # Default since_ms to 30 days if nothing is given
         new_trades = exchange.get_historic_trades(pair=pair,
                                                   since=since,
+                                                  until=until,
                                                   from_id=from_id,
                                                   )
         trades.extend(new_trades[1])


Test patch: