Skip to content

Commit

Permalink
Fail download-data gracefully if no pairs-file exists
Browse files Browse the repository at this point in the history
  • Loading branch information
xmatthias committed Sep 21, 2019
1 parent 3245ebc commit 7aa42f8
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
6 changes: 6 additions & 0 deletions freqtrade/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import arrow

from freqtrade import OperationalException
from freqtrade.configuration import Configuration, TimeRange
from freqtrade.configuration.directory_operations import create_userdata_dir
from freqtrade.data.history import refresh_backtest_ohlcv_data
Expand Down Expand Up @@ -70,6 +71,11 @@ def start_download_data(args: Dict[str, Any]) -> None:
time_since = arrow.utcnow().shift(days=-config['days']).strftime("%Y%m%d")
timerange = TimeRange.parse_timerange(f'{time_since}-')

if 'pairs' not in config:
raise OperationalException(
"Downloading data requires a list of pairs."
"Please check the documentation on how to configure this.")

dl_path = Path(config['datadir'])
logger.info(f'About to download pairs: {config["pairs"]}, '
f'intervals: {config["timeframes"]} to {dl_path}')
Expand Down
24 changes: 22 additions & 2 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import re
from pathlib import Path
from unittest.mock import MagicMock, PropertyMock

import pytest
Expand All @@ -7,7 +8,7 @@
from freqtrade.state import RunMode
from freqtrade.utils import (setup_utils_configuration, start_create_userdir,
start_download_data, start_list_exchanges)
from tests.conftest import get_args, log_has, log_has_re, patch_exchange
from tests.conftest import get_args, log_has, patch_exchange


def test_setup_utils_configuration():
Expand Down Expand Up @@ -114,8 +115,27 @@ def test_download_data_no_exchange(mocker, caplog):
'freqtrade.exchange.Exchange.markets', PropertyMock(return_value={})
)
args = [
"download-data"
"download-data",
]
with pytest.raises(OperationalException,
match=r"This command requires a configured exchange.*"):
start_download_data(get_args(args))


def test_download_data_no_pairs(mocker, caplog):
mocker.patch.object(Path, "exists", MagicMock(return_value=False))

mocker.patch('freqtrade.utils.refresh_backtest_ohlcv_data',
MagicMock(return_value=["ETH/BTC", "XRP/BTC"]))
patch_exchange(mocker)
mocker.patch(
'freqtrade.exchange.Exchange.markets', PropertyMock(return_value={})
)
args = [
"download-data",
"--exchange",
"binance",
]
with pytest.raises(OperationalException,
match=r"Downloading data requires a list of pairs\..*"):
start_download_data(get_args(args))

0 comments on commit 7aa42f8

Please sign in to comment.