diff --git a/tests/test_utils.py b/tests/test_utils.py index 55672c4c9..bc641af34 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -8,7 +8,7 @@ from freqtrade import OperationalException from freqtrade.state import RunMode from freqtrade.utils import (setup_utils_configuration, start_create_userdir, start_download_data, start_list_exchanges, - start_list_timeframes) + start_list_pairs, start_list_timeframes) from tests.conftest import get_args, log_has, patch_exchange @@ -164,6 +164,163 @@ def test_list_timeframes(mocker, capsys): assert re.search(r"^1d$", captured.out, re.MULTILINE) +def test_list_markets(mocker, markets, capsys): + + api_mock = MagicMock() + api_mock.markets = markets + patch_exchange(mocker, api_mock=api_mock) + + # Test with no --config + args = [ + "list-markets", + ] + with pytest.raises(OperationalException, + match=r"This command requires a configured exchange.*"): + start_list_pairs(get_args(args), False) + + # Test with --config config.json.example + args = [ + '--config', 'config.json.example', + "list-markets", + ] + start_list_pairs(get_args(args), False) + captured = capsys.readouterr() + assert re.match("Exchange Bittrex has 8 active markets:\n", + captured.out) + +# # Test with --exchange +# args = [ +# "list-markets", +# "--exchange", "binance" +# ] +# start_list_pairs(get_args(args), False) +# captured = capsys.readouterr() +# assert re.match("Exchange Binance has 8 active markets:\n", +# captured.out) + + # Test with --all: all markets + args = [ + '--config', 'config.json.example', + "list-markets", "--all" + ] + start_list_pairs(get_args(args), False) + captured = capsys.readouterr() + assert re.match("Exchange Bittrex has 11 markets:\n", + captured.out) + + # Test list-pairs subcommand: active pairs + args = [ + '--config', 'config.json.example', + "list-pairs", + ] + start_list_pairs(get_args(args), True) + captured = capsys.readouterr() + assert re.match("Exchange Bittrex has 7 active pairs:\n", + captured.out) + + # Test list-pairs subcommand with --all: all pairs + args = [ + '--config', 'config.json.example', + "list-pairs", "--all" + ] + start_list_pairs(get_args(args), True) + captured = capsys.readouterr() + assert re.match("Exchange Bittrex has 10 pairs:\n", + captured.out) + + # active markets, base=ETH, LTC + args = [ + '--config', 'config.json.example', + "list-markets", + "--base", "ETH", "LTC" + ] + start_list_pairs(get_args(args), False) + captured = capsys.readouterr() + assert re.match("Exchange Bittrex has 5 active markets with ETH, LTC as base currencies:\n", + captured.out) + + # active markets, base=LTC + args = [ + '--config', 'config.json.example', + "list-markets", + "--base", "LTC" + ] + start_list_pairs(get_args(args), False) + captured = capsys.readouterr() + assert re.match("Exchange Bittrex has 3 active markets with LTC as base currency:\n", + captured.out) + + # active markets, quote=USDT, USD + args = [ + '--config', 'config.json.example', + "list-markets", + "--quote", "USDT", "USD" + ] + start_list_pairs(get_args(args), False) + captured = capsys.readouterr() + assert re.match("Exchange Bittrex has 4 active markets with USDT, USD as quote currencies:\n", + captured.out) + + # active markets, quote=USDT + args = [ + '--config', 'config.json.example', + "list-markets", + "--quote", "USDT" + ] + start_list_pairs(get_args(args), False) + captured = capsys.readouterr() + assert re.match("Exchange Bittrex has 3 active markets with USDT as quote currency:\n", + captured.out) + + # active markets, base=LTC, quote=USDT + args = [ + '--config', 'config.json.example', + "list-markets", + "--base", "LTC", "--quote", "USDT" + ] + start_list_pairs(get_args(args), False) + captured = capsys.readouterr() + assert re.match("Exchange Bittrex has 2 active markets with LTC as base currency and " + "with USDT as quote currency:\n", + captured.out) + + # active pairs, base=LTC, quote=USDT + args = [ + '--config', 'config.json.example', + "list-pairs", + "--base", "LTC", "--quote", "USDT" + ] + start_list_pairs(get_args(args), True) + captured = capsys.readouterr() + assert re.match("Exchange Bittrex has 1 active pair with LTC as base currency and " + "with USDT as quote currency:\n", + captured.out) + + # active markets, base=LTC, quote=USDT, NONEXISTENT + args = [ + '--config', 'config.json.example', + "list-markets", + "--base", "LTC", "--quote", "USDT", "NONEXISTENT" + ] + start_list_pairs(get_args(args), False) + captured = capsys.readouterr() + assert re.match("Exchange Bittrex has 2 active markets with LTC as base currency and " + "with USDT, NONEXISTENT as quote currencies:\n", + captured.out) + + # active markets, base=LTC, quote=NONEXISTENT + args = [ + '--config', 'config.json.example', + "list-markets", + "--base", "LTC", "--quote", "NONEXISTENT" + ] + start_list_pairs(get_args(args), False) + captured = capsys.readouterr() + assert re.match("Exchange Bittrex has 0 active markets with LTC as base currency and " + "with NONEXISTENT as quote currency.\n", + captured.out) + + def test_create_datadir_failed(caplog): args = [