freqtrade_origin/tests/commands/test_commands.py

1907 lines
55 KiB
Python
Raw Normal View History

import json
2019-06-16 08:13:24 +00:00
import re
2023-05-14 16:31:09 +00:00
from datetime import datetime, timedelta
from io import BytesIO
from pathlib import Path
2019-08-16 13:28:11 +00:00
from unittest.mock import MagicMock, PropertyMock
2021-01-10 13:06:06 +00:00
from zipfile import ZipFile
import pytest
2024-05-12 13:08:40 +00:00
from freqtrade.commands import (
start_backtesting_show,
start_convert_data,
2024-10-21 17:11:56 +00:00
start_convert_db,
2024-05-12 13:08:40 +00:00
start_convert_trades,
start_create_userdir,
start_download_data,
start_hyperopt_list,
start_hyperopt_show,
start_install_ui,
start_list_data,
start_list_exchanges,
2024-10-21 17:11:56 +00:00
start_list_freqAI_models,
2024-10-22 04:32:11 +00:00
start_list_hyperopt_loss_functions,
2024-05-12 13:08:40 +00:00
start_list_markets,
start_list_strategies,
start_list_timeframes,
start_new_strategy,
start_show_config,
start_show_trades,
start_strategy_update,
start_test_pairlist,
start_trading,
start_webserver,
)
from freqtrade.commands.deploy_ui import (
2024-05-12 13:08:40 +00:00
clean_ui_subdir,
download_and_install_ui,
get_ui_download_url,
read_ui_version,
)
from freqtrade.configuration import setup_utils_configuration
2021-06-08 19:20:35 +00:00
from freqtrade.enums import RunMode
from freqtrade.exceptions import OperationalException
2022-05-09 17:59:15 +00:00
from freqtrade.persistence.models import init_db
2022-05-10 17:17:12 +00:00
from freqtrade.persistence.pairlock_middleware import PairLocks
2023-05-14 16:31:09 +00:00
from freqtrade.util import dt_floor_day, dt_now, dt_utc
2024-05-12 13:08:40 +00:00
from tests.conftest import (
CURRENT_TEST_STRATEGY,
EXMS,
create_mock_trades,
get_args,
log_has,
log_has_re,
patch_exchange,
patched_configuration_load_config_file,
)
from tests.conftest_hyperopt import hyperopt_test_result
2020-09-10 05:40:19 +00:00
from tests.conftest_trades import MOCK_TRADE_COUNT
2019-06-16 08:13:24 +00:00
2019-06-16 18:37:59 +00:00
def test_setup_utils_configuration():
2019-06-16 08:13:24 +00:00
args = [
2024-05-12 13:47:54 +00:00
"list-exchanges",
"--config",
"tests/testdata/testconfigs/main_test_config.json",
2019-06-16 08:13:24 +00:00
]
2019-06-16 18:37:59 +00:00
config = setup_utils_configuration(get_args(args), RunMode.OTHER)
2019-06-16 08:13:24 +00:00
assert "exchange" in config
2024-05-12 13:47:54 +00:00
assert config["dry_run"] is True
2019-06-16 08:13:24 +00:00
args = [
2024-05-12 13:47:54 +00:00
"list-exchanges",
"--config",
"tests/testdata/testconfigs/testconfig.json",
]
config = setup_utils_configuration(get_args(args), RunMode.OTHER, set_dry=False)
assert "exchange" in config
2024-05-12 13:47:54 +00:00
assert config["dry_run"] is False
2019-06-16 08:13:24 +00:00
def test_start_trading_fail(mocker, caplog):
2019-11-16 08:56:16 +00:00
mocker.patch("freqtrade.worker.Worker.run", MagicMock(side_effect=OperationalException))
mocker.patch("freqtrade.worker.Worker.__init__", MagicMock(return_value=None))
exitmock = mocker.patch("freqtrade.worker.Worker.exit", MagicMock())
2024-05-12 13:47:54 +00:00
args = ["trade", "-c", "tests/testdata/testconfigs/main_test_config.json"]
with pytest.raises(OperationalException):
start_trading(get_args(args))
2019-11-16 08:56:16 +00:00
assert exitmock.call_count == 1
exitmock.reset_mock()
caplog.clear()
2019-11-16 08:56:16 +00:00
mocker.patch("freqtrade.worker.Worker.__init__", MagicMock(side_effect=OperationalException))
with pytest.raises(OperationalException):
start_trading(get_args(args))
2019-11-16 08:56:16 +00:00
assert exitmock.call_count == 0
2021-04-01 05:49:54 +00:00
def test_start_webserver(mocker, caplog):
2024-05-12 13:47:54 +00:00
api_server_mock = mocker.patch(
"freqtrade.rpc.api_server.ApiServer",
)
2021-04-01 05:49:54 +00:00
2024-05-12 13:47:54 +00:00
args = ["webserver", "-c", "tests/testdata/testconfigs/main_test_config.json"]
2021-04-01 05:49:54 +00:00
start_webserver(get_args(args))
assert api_server_mock.call_count == 1
2019-06-16 08:13:24 +00:00
def test_list_exchanges(capsys):
args = [
"list-exchanges",
]
start_list_exchanges(get_args(args))
captured = capsys.readouterr()
assert re.search(r".*Exchanges available for Freqtrade.*", captured.out)
assert re.search(r".*binance.*", captured.out)
2023-12-18 06:08:19 +00:00
assert re.search(r".*bybit.*", captured.out)
2019-06-16 08:13:24 +00:00
# Test with --one-column
args = [
"list-exchanges",
"--one-column",
]
start_list_exchanges(get_args(args))
captured = capsys.readouterr()
assert re.search(r"^binance$", captured.out, re.MULTILINE)
2023-12-18 06:08:19 +00:00
assert re.search(r"^bybit$", captured.out, re.MULTILINE)
2019-09-30 21:33:54 +00:00
# Test with --all
args = [
"list-exchanges",
"--all",
]
start_list_exchanges(get_args(args))
captured = capsys.readouterr()
assert re.search(r"All exchanges supported by the ccxt library.*", captured.out)
assert re.search(r".*binance.*", captured.out)
2023-12-18 06:08:19 +00:00
assert re.search(r".*bingx.*", captured.out)
assert re.search(r".*bitmex.*", captured.out)
2019-09-30 21:33:54 +00:00
# Test with --one-column --all
args = [
"list-exchanges",
"--one-column",
"--all",
]
start_list_exchanges(get_args(args))
captured = capsys.readouterr()
assert re.search(r"^binance$", captured.out, re.MULTILINE)
2023-12-18 06:08:19 +00:00
assert re.search(r"^bingx$", captured.out, re.MULTILINE)
2019-09-30 21:33:54 +00:00
assert re.search(r"^bitmex$", captured.out, re.MULTILINE)
2019-10-06 08:32:19 +00:00
def test_list_timeframes(mocker, capsys):
api_mock = MagicMock()
2024-05-12 13:47:54 +00:00
api_mock.timeframes = {
"1m": "oneMin",
"5m": "fiveMin",
"30m": "thirtyMin",
"1h": "hour",
"1d": "day",
}
patch_exchange(mocker, api_mock=api_mock, exchange="bybit")
2019-10-03 23:01:44 +00:00
args = [
"list-timeframes",
]
pargs = get_args(args)
2024-05-12 13:47:54 +00:00
pargs["config"] = None
with pytest.raises(
OperationalException, match=r"This command requires a configured exchange.*"
):
2019-10-03 23:01:44 +00:00
start_list_timeframes(pargs)
2023-12-18 06:08:19 +00:00
# Test with --config tests/testdata/testconfigs/main_test_config.json
2019-10-03 23:01:44 +00:00
args = [
"list-timeframes",
2024-05-12 13:47:54 +00:00
"--config",
"tests/testdata/testconfigs/main_test_config.json",
2019-10-03 23:01:44 +00:00
]
start_list_timeframes(get_args(args))
captured = capsys.readouterr()
2024-05-12 13:47:54 +00:00
assert re.match(
2024-05-12 15:51:21 +00:00
"Timeframes available for the exchange `Bybit`: 1m, 5m, 30m, 1h, 1d", captured.out
2024-05-12 13:47:54 +00:00
)
2019-10-03 23:01:44 +00:00
2023-12-18 06:08:19 +00:00
# Test with --exchange bybit
2019-10-03 23:01:44 +00:00
args = [
"list-timeframes",
2024-05-12 13:47:54 +00:00
"--exchange",
"bybit",
2019-10-03 23:01:44 +00:00
]
start_list_timeframes(get_args(args))
captured = capsys.readouterr()
2024-05-12 13:47:54 +00:00
assert re.match(
2024-05-12 15:51:21 +00:00
"Timeframes available for the exchange `Bybit`: 1m, 5m, 30m, 1h, 1d", captured.out
2024-05-12 13:47:54 +00:00
)
api_mock.timeframes = {
"1m": "1m",
"5m": "5m",
"15m": "15m",
"30m": "30m",
"1h": "1h",
"6h": "6h",
"12h": "12h",
"1d": "1d",
"3d": "3d",
}
patch_exchange(mocker, api_mock=api_mock, exchange="binance")
2019-10-03 23:01:44 +00:00
# Test with --exchange binance
args = [
"list-timeframes",
2024-05-12 13:47:54 +00:00
"--exchange",
"binance",
2019-10-03 23:01:44 +00:00
]
start_list_timeframes(get_args(args))
captured = capsys.readouterr()
2024-05-12 13:47:54 +00:00
assert re.match(
2024-05-12 15:51:21 +00:00
"Timeframes available for the exchange `Binance`: 1m, 5m, 15m, 30m, 1h, 6h, 12h, 1d, 3d",
2024-05-12 13:47:54 +00:00
captured.out,
)
2019-10-03 23:01:44 +00:00
# Test with --one-column
args = [
"list-timeframes",
2024-05-12 13:47:54 +00:00
"--config",
"tests/testdata/testconfigs/main_test_config.json",
2019-10-03 23:01:44 +00:00
"--one-column",
]
start_list_timeframes(get_args(args))
captured = capsys.readouterr()
assert re.search(r"^1m$", captured.out, re.MULTILINE)
assert re.search(r"^5m$", captured.out, re.MULTILINE)
assert re.search(r"^1h$", captured.out, re.MULTILINE)
assert re.search(r"^1d$", captured.out, re.MULTILINE)
# Test with --exchange binance --one-column
args = [
"list-timeframes",
2024-05-12 13:47:54 +00:00
"--exchange",
"binance",
2019-10-03 23:01:44 +00:00
"--one-column",
]
start_list_timeframes(get_args(args))
captured = capsys.readouterr()
assert re.search(r"^1m$", captured.out, re.MULTILINE)
assert re.search(r"^5m$", captured.out, re.MULTILINE)
assert re.search(r"^1h$", captured.out, re.MULTILINE)
assert re.search(r"^1d$", captured.out, re.MULTILINE)
def test_list_markets(mocker, markets_static, capsys):
2019-10-17 21:48:40 +00:00
api_mock = MagicMock()
patch_exchange(mocker, api_mock=api_mock, exchange="binance", mock_markets=markets_static)
2019-10-17 21:48:40 +00:00
# Test with no --config
args = [
"list-markets",
]
2019-10-20 19:43:00 +00:00
pargs = get_args(args)
2024-05-12 13:47:54 +00:00
pargs["config"] = None
with pytest.raises(
OperationalException, match=r"This command requires a configured exchange.*"
):
2019-10-20 19:43:00 +00:00
start_list_markets(pargs, False)
2019-10-17 21:48:40 +00:00
2023-12-18 06:08:19 +00:00
# Test with --config tests/testdata/testconfigs/main_test_config.json
2019-10-17 21:48:40 +00:00
args = [
"list-markets",
2024-05-12 13:47:54 +00:00
"--config",
"tests/testdata/testconfigs/main_test_config.json",
2019-10-18 11:25:43 +00:00
"--print-list",
2019-10-17 21:48:40 +00:00
]
start_list_markets(get_args(args), False)
2019-10-17 21:48:40 +00:00
captured = capsys.readouterr()
2024-05-12 13:47:54 +00:00
assert (
"Exchange Binance has 12 active markets: "
"ADA/USDT:USDT, BLK/BTC, ETH/BTC, ETH/USDT, ETH/USDT:USDT, LTC/BTC, "
"LTC/ETH, LTC/USD, NEO/BTC, TKN/BTC, XLTCUSDT, XRP/BTC.\n" in captured.out
)
2019-10-17 21:48:40 +00:00
patch_exchange(mocker, api_mock=api_mock, exchange="binance", mock_markets=markets_static)
2019-10-20 23:15:37 +00:00
# Test with --exchange
2024-05-12 13:47:54 +00:00
args = ["list-markets", "--exchange", "binance"]
2019-10-20 23:15:37 +00:00
pargs = get_args(args)
2024-05-12 13:47:54 +00:00
pargs["config"] = None
2019-10-20 23:15:37 +00:00
start_list_markets(pargs, False)
captured = capsys.readouterr()
2024-07-06 11:09:37 +00:00
assert re.search(r".*Exchange Binance has 12 active markets.*", captured.out)
2019-10-17 21:48:40 +00:00
patch_exchange(mocker, api_mock=api_mock, exchange="binance", mock_markets=markets_static)
2019-10-17 21:48:40 +00:00
# Test with --all: all markets
args = [
2024-05-12 13:47:54 +00:00
"list-markets",
"--all",
"--config",
"tests/testdata/testconfigs/main_test_config.json",
2019-10-18 11:25:43 +00:00
"--print-list",
2019-10-17 21:48:40 +00:00
]
start_list_markets(get_args(args), False)
2019-10-17 21:48:40 +00:00
captured = capsys.readouterr()
2024-05-12 13:47:54 +00:00
assert (
"Exchange Binance has 14 markets: "
"ADA/USDT:USDT, BLK/BTC, BTT/BTC, ETH/BTC, ETH/USDT, ETH/USDT:USDT, "
"LTC/BTC, LTC/ETH, LTC/USD, LTC/USDT, NEO/BTC, TKN/BTC, XLTCUSDT, XRP/BTC.\n"
in captured.out
)
2019-10-17 21:48:40 +00:00
# Test list-pairs subcommand: active pairs
args = [
"list-pairs",
2024-05-12 13:47:54 +00:00
"--config",
"tests/testdata/testconfigs/main_test_config.json",
2019-10-18 11:25:43 +00:00
"--print-list",
2019-10-17 21:48:40 +00:00
]
start_list_markets(get_args(args), True)
2019-10-17 21:48:40 +00:00
captured = capsys.readouterr()
2024-05-12 13:47:54 +00:00
assert (
"Exchange Binance has 9 active pairs: "
"BLK/BTC, ETH/BTC, ETH/USDT, LTC/BTC, LTC/ETH, LTC/USD, NEO/BTC, TKN/BTC, XRP/BTC.\n"
in captured.out
)
2019-10-17 21:48:40 +00:00
# Test list-pairs subcommand with --all: all pairs
args = [
2024-05-12 13:47:54 +00:00
"list-pairs",
"--all",
"--config",
"tests/testdata/testconfigs/main_test_config.json",
2019-10-18 11:25:43 +00:00
"--print-list",
2019-10-17 21:48:40 +00:00
]
start_list_markets(get_args(args), True)
2019-10-17 21:48:40 +00:00
captured = capsys.readouterr()
2024-05-12 13:47:54 +00:00
assert (
"Exchange Binance has 11 pairs: "
"BLK/BTC, BTT/BTC, ETH/BTC, ETH/USDT, LTC/BTC, LTC/ETH, LTC/USD, LTC/USDT, NEO/BTC, "
"TKN/BTC, XRP/BTC.\n" in captured.out
)
2019-10-17 21:48:40 +00:00
# active markets, base=ETH, LTC
args = [
"list-markets",
2024-05-12 13:47:54 +00:00
"--config",
"tests/testdata/testconfigs/main_test_config.json",
"--base",
"ETH",
"LTC",
2019-10-18 11:25:43 +00:00
"--print-list",
2019-10-17 21:48:40 +00:00
]
start_list_markets(get_args(args), False)
2019-10-17 21:48:40 +00:00
captured = capsys.readouterr()
2024-05-12 13:47:54 +00:00
assert (
"Exchange Binance has 7 active markets with ETH, LTC as base currencies: "
"ETH/BTC, ETH/USDT, ETH/USDT:USDT, LTC/BTC, LTC/ETH, LTC/USD, XLTCUSDT.\n" in captured.out
)
2019-10-17 21:48:40 +00:00
# active markets, base=LTC
args = [
"list-markets",
2024-05-12 13:47:54 +00:00
"--config",
"tests/testdata/testconfigs/main_test_config.json",
"--base",
"LTC",
2019-10-18 11:25:43 +00:00
"--print-list",
2019-10-17 21:48:40 +00:00
]
start_list_markets(get_args(args), False)
2019-10-17 21:48:40 +00:00
captured = capsys.readouterr()
2024-05-12 13:47:54 +00:00
assert (
"Exchange Binance has 4 active markets with LTC as base currency: "
"LTC/BTC, LTC/ETH, LTC/USD, XLTCUSDT.\n" in captured.out
)
2019-10-17 21:48:40 +00:00
# active markets, quote=USDT, USD
args = [
"list-markets",
2024-05-12 13:47:54 +00:00
"--config",
"tests/testdata/testconfigs/main_test_config.json",
"--quote",
"USDT",
"USD",
2019-10-18 11:25:43 +00:00
"--print-list",
2019-10-17 21:48:40 +00:00
]
start_list_markets(get_args(args), False)
2019-10-17 21:48:40 +00:00
captured = capsys.readouterr()
2024-05-12 13:47:54 +00:00
assert (
"Exchange Binance has 5 active markets with USDT, USD as quote currencies: "
"ADA/USDT:USDT, ETH/USDT, ETH/USDT:USDT, LTC/USD, XLTCUSDT.\n" in captured.out
)
2019-10-17 21:48:40 +00:00
# active markets, quote=USDT
args = [
"list-markets",
2024-05-12 13:47:54 +00:00
"--config",
"tests/testdata/testconfigs/main_test_config.json",
"--quote",
"USDT",
2019-10-18 11:25:43 +00:00
"--print-list",
2019-10-17 21:48:40 +00:00
]
start_list_markets(get_args(args), False)
2019-10-17 21:48:40 +00:00
captured = capsys.readouterr()
2024-05-12 13:47:54 +00:00
assert (
"Exchange Binance has 4 active markets with USDT as quote currency: "
"ADA/USDT:USDT, ETH/USDT, ETH/USDT:USDT, XLTCUSDT.\n" in captured.out
)
2019-10-17 21:48:40 +00:00
# active markets, base=LTC, quote=USDT
args = [
"list-markets",
2024-05-12 13:47:54 +00:00
"--config",
"tests/testdata/testconfigs/main_test_config.json",
"--base",
"LTC",
"--quote",
"USDT",
2019-10-18 11:25:43 +00:00
"--print-list",
2019-10-17 21:48:40 +00:00
]
start_list_markets(get_args(args), False)
2019-10-17 21:48:40 +00:00
captured = capsys.readouterr()
2024-05-12 13:47:54 +00:00
assert (
"Exchange Binance has 1 active market with LTC as base currency and "
"with USDT as quote currency: XLTCUSDT.\n" in captured.out
)
2019-10-17 21:48:40 +00:00
# active pairs, base=LTC, quote=USDT
args = [
"list-pairs",
2024-05-12 13:47:54 +00:00
"--config",
"tests/testdata/testconfigs/main_test_config.json",
"--base",
"LTC",
"--quote",
"USD",
2019-10-18 11:25:43 +00:00
"--print-list",
2019-10-17 21:48:40 +00:00
]
start_list_markets(get_args(args), True)
2019-10-17 21:48:40 +00:00
captured = capsys.readouterr()
2024-05-12 13:47:54 +00:00
assert (
"Exchange Binance has 1 active pair with LTC as base currency and "
"with USD as quote currency: LTC/USD.\n" in captured.out
)
2019-10-17 21:48:40 +00:00
# active markets, base=LTC, quote=USDT, NONEXISTENT
args = [
"list-markets",
2024-05-12 13:47:54 +00:00
"--config",
"tests/testdata/testconfigs/main_test_config.json",
"--base",
"LTC",
"--quote",
"USDT",
"NONEXISTENT",
2019-10-18 11:25:43 +00:00
"--print-list",
2019-10-17 21:48:40 +00:00
]
start_list_markets(get_args(args), False)
2019-10-17 21:48:40 +00:00
captured = capsys.readouterr()
2024-05-12 13:47:54 +00:00
assert (
"Exchange Binance has 1 active market with LTC as base currency and "
"with USDT, NONEXISTENT as quote currencies: XLTCUSDT.\n" in captured.out
)
2019-10-17 21:48:40 +00:00
# active markets, base=LTC, quote=NONEXISTENT
args = [
"list-markets",
2024-05-12 13:47:54 +00:00
"--config",
"tests/testdata/testconfigs/main_test_config.json",
"--base",
"LTC",
"--quote",
"NONEXISTENT",
2019-10-18 11:25:43 +00:00
"--print-list",
2019-10-17 21:48:40 +00:00
]
start_list_markets(get_args(args), False)
2019-10-17 21:48:40 +00:00
captured = capsys.readouterr()
2024-05-12 13:47:54 +00:00
assert (
"Exchange Binance has 0 active markets with LTC as base currency and "
"with NONEXISTENT as quote currency.\n" in captured.out
)
2019-10-18 11:25:43 +00:00
# Test tabular output
args = [
"list-markets",
2024-05-12 13:47:54 +00:00
"--config",
"tests/testdata/testconfigs/main_test_config.json",
2019-10-18 11:25:43 +00:00
]
start_list_markets(get_args(args), False)
captured = capsys.readouterr()
2024-07-06 11:09:37 +00:00
assert "Exchange Binance has 12 active markets" in captured.out
2019-10-18 11:25:43 +00:00
# Test tabular output, no markets found
args = [
"list-markets",
2024-05-12 13:47:54 +00:00
"--config",
"tests/testdata/testconfigs/main_test_config.json",
"--base",
"LTC",
"--quote",
"NONEXISTENT",
2019-10-18 11:25:43 +00:00
]
start_list_markets(get_args(args), False)
captured = capsys.readouterr()
2024-05-12 13:47:54 +00:00
assert (
"Exchange Binance has 0 active markets with LTC as base currency and "
"with NONEXISTENT as quote currency.\n" in captured.out
)
2019-10-18 11:25:43 +00:00
# Test --print-json
args = [
"list-markets",
2024-05-12 13:47:54 +00:00
"--config",
"tests/testdata/testconfigs/main_test_config.json",
"--print-json",
2019-10-18 11:25:43 +00:00
]
start_list_markets(get_args(args), False)
captured = capsys.readouterr()
2024-05-12 13:47:54 +00:00
assert (
'["ADA/USDT:USDT","BLK/BTC","ETH/BTC","ETH/USDT","ETH/USDT:USDT",'
'"LTC/BTC","LTC/ETH","LTC/USD","NEO/BTC","TKN/BTC","XLTCUSDT","XRP/BTC"]' in captured.out
)
2019-10-18 11:25:43 +00:00
# Test --print-csv
args = [
"list-markets",
2024-05-12 13:47:54 +00:00
"--config",
"tests/testdata/testconfigs/main_test_config.json",
"--print-csv",
2019-10-18 11:25:43 +00:00
]
start_list_markets(get_args(args), False)
captured = capsys.readouterr()
2024-05-12 13:47:54 +00:00
assert "Id,Symbol,Base,Quote,Active,Spot,Margin,Future,Leverage" in captured.out
assert "blkbtc,BLK/BTC,BLK,BTC,True,Spot" in captured.out
assert "USD-LTC,LTC/USD,LTC,USD,True,Spot" in captured.out
2019-10-18 11:25:43 +00:00
# Test --one-column
args = [
"list-markets",
2024-05-12 13:47:54 +00:00
"--config",
"tests/testdata/testconfigs/main_test_config.json",
"--one-column",
2019-10-18 11:25:43 +00:00
]
start_list_markets(get_args(args), False)
captured = capsys.readouterr()
assert re.search(r"^BLK/BTC$", captured.out, re.MULTILINE)
2019-10-26 11:24:26 +00:00
assert re.search(r"^LTC/USD$", captured.out, re.MULTILINE)
2019-10-17 21:48:40 +00:00
2024-05-12 13:47:54 +00:00
mocker.patch(f"{EXMS}.markets", PropertyMock(side_effect=ValueError))
2020-10-29 06:54:42 +00:00
# Test --one-column
args = [
"list-markets",
2024-05-12 13:47:54 +00:00
"--config",
"tests/testdata/testconfigs/main_test_config.json",
"--one-column",
2020-10-29 06:54:42 +00:00
]
with pytest.raises(OperationalException, match=r"Cannot get markets.*"):
start_list_markets(get_args(args), False)
2019-10-17 21:48:40 +00:00
def test_create_datadir_failed(caplog):
args = [
"create-userdir",
]
with pytest.raises(SystemExit):
start_create_userdir(get_args(args))
2019-08-18 13:09:44 +00:00
assert log_has("`create-userdir` requires --userdir to be set.", caplog)
def test_create_datadir(caplog, mocker):
2024-10-03 03:33:52 +00:00
cud = mocker.patch(
"freqtrade.configuration.directory_operations.create_userdata_dir", MagicMock()
)
csf = mocker.patch(
"freqtrade.configuration.directory_operations.copy_sample_files", MagicMock()
)
2024-05-12 13:47:54 +00:00
args = ["create-userdir", "--userdir", "/temp/freqtrade/test"]
start_create_userdir(get_args(args))
assert cud.call_count == 1
assert csf.call_count == 1
2019-11-12 12:31:07 +00:00
def test_start_new_strategy(mocker, caplog):
wt_mock = mocker.patch.object(Path, "write_text", MagicMock())
2019-11-16 13:47:44 +00:00
mocker.patch.object(Path, "exists", MagicMock(return_value=False))
2024-05-12 13:47:54 +00:00
args = ["new-strategy", "--strategy", "CoolNewStrategy"]
2019-11-12 12:31:07 +00:00
start_new_strategy(get_args(args))
assert wt_mock.call_count == 1
assert "CoolNewStrategy" in wt_mock.call_args_list[0][0][0]
assert log_has_re("Writing strategy to .*", caplog)
2024-10-03 03:33:52 +00:00
mocker.patch("freqtrade.configuration.setup_utils_configuration")
mocker.patch.object(Path, "exists", MagicMock(return_value=True))
2024-05-12 13:47:54 +00:00
with pytest.raises(
OperationalException, match=r".* already exists. Please choose another Strategy Name\."
):
start_new_strategy(get_args(args))
2019-11-12 12:31:07 +00:00
2019-11-12 12:33:37 +00:00
def test_start_new_strategy_no_arg(mocker, caplog):
args = [
"new-strategy",
]
2024-05-12 13:47:54 +00:00
with pytest.raises(OperationalException, match="`new-strategy` requires --strategy to be set."):
2019-11-12 12:33:37 +00:00
start_new_strategy(get_args(args))
2021-01-10 13:06:06 +00:00
def test_start_install_ui(mocker):
clean_mock = mocker.patch("freqtrade.commands.deploy_ui.clean_ui_subdir")
2024-05-12 13:47:54 +00:00
get_url_mock = mocker.patch(
"freqtrade.commands.deploy_ui.get_ui_download_url",
2024-05-12 13:47:54 +00:00
return_value=("https://example.com/whatever", "0.0.1"),
)
download_mock = mocker.patch("freqtrade.commands.deploy_ui.download_and_install_ui")
mocker.patch("freqtrade.commands.deploy_ui.read_ui_version", return_value=None)
2021-01-10 13:06:06 +00:00
args = [
"install-ui",
]
2021-01-16 09:15:27 +00:00
start_install_ui(get_args(args))
2021-01-10 13:06:06 +00:00
assert clean_mock.call_count == 1
2021-01-10 13:46:59 +00:00
assert get_url_mock.call_count == 1
2021-01-10 13:06:06 +00:00
assert download_mock.call_count == 1
2021-01-16 09:15:27 +00:00
clean_mock.reset_mock()
get_url_mock.reset_mock()
download_mock.reset_mock()
args = [
"install-ui",
"--erase",
]
start_install_ui(get_args(args))
assert clean_mock.call_count == 1
2021-01-31 13:43:16 +00:00
assert get_url_mock.call_count == 1
2021-01-16 09:15:27 +00:00
assert download_mock.call_count == 0
2021-01-10 13:06:06 +00:00
2023-11-05 15:25:23 +00:00
def test_clean_ui_subdir(mocker, tmp_path, caplog):
mocker.patch("freqtrade.commands.deploy_ui.Path.is_dir", side_effect=[True, True])
mocker.patch("freqtrade.commands.deploy_ui.Path.is_file", side_effect=[False, True])
rd_mock = mocker.patch("freqtrade.commands.deploy_ui.Path.rmdir")
ul_mock = mocker.patch("freqtrade.commands.deploy_ui.Path.unlink")
2021-01-10 13:06:06 +00:00
2024-05-12 13:47:54 +00:00
mocker.patch(
"freqtrade.commands.deploy_ui.Path.glob",
2024-05-12 13:47:54 +00:00
return_value=[Path("test1"), Path("test2"), Path(".gitkeep")],
)
2023-11-05 15:25:23 +00:00
folder = tmp_path / "uitests"
2021-01-10 13:06:06 +00:00
clean_ui_subdir(folder)
assert log_has("Removing UI directory content.", caplog)
assert rd_mock.call_count == 1
assert ul_mock.call_count == 1
2023-11-05 15:25:23 +00:00
def test_download_and_install_ui(mocker, tmp_path):
2021-01-10 13:46:59 +00:00
# Create zipfile
2021-01-10 13:06:06 +00:00
requests_mock = MagicMock()
file_like_object = BytesIO()
2024-05-12 13:47:54 +00:00
with ZipFile(file_like_object, mode="w") as zipfile:
for file in ("test1.txt", "hello/", "test2.txt"):
2021-01-10 13:06:06 +00:00
zipfile.writestr(file, file)
file_like_object.seek(0)
requests_mock.content = file_like_object.read()
2021-01-10 13:46:59 +00:00
mocker.patch("freqtrade.commands.deploy_ui.requests.get", return_value=requests_mock)
2021-01-10 13:46:59 +00:00
mocker.patch("freqtrade.commands.deploy_ui.Path.is_dir", side_effect=[True, False])
wb_mock = mocker.patch("freqtrade.commands.deploy_ui.Path.write_bytes")
2021-01-10 13:46:59 +00:00
2023-11-05 15:25:23 +00:00
folder = tmp_path / "uitests_dl"
2021-01-31 13:39:46 +00:00
folder.mkdir(exist_ok=True)
2021-01-31 14:37:57 +00:00
assert read_ui_version(folder) is None
2024-05-12 13:47:54 +00:00
download_and_install_ui(folder, "http://whatever.xxx/download/file.zip", "22")
2021-01-10 13:06:06 +00:00
assert wb_mock.call_count == 2
2024-05-12 13:47:54 +00:00
assert read_ui_version(folder) == "22"
2021-01-31 13:39:46 +00:00
2021-01-10 13:06:06 +00:00
2021-01-10 13:52:51 +00:00
def test_get_ui_download_url(mocker):
response = MagicMock()
response.json = MagicMock(
2024-05-12 13:47:54 +00:00
side_effect=[
[{"assets_url": "http://whatever.json", "name": "0.0.1"}],
[{"browser_download_url": "http://download.zip"}],
]
)
get_mock = mocker.patch("freqtrade.commands.deploy_ui.requests.get", return_value=response)
x, last_version = get_ui_download_url()
2021-01-10 13:52:51 +00:00
assert get_mock.call_count == 2
2024-05-12 13:47:54 +00:00
assert last_version == "0.0.1"
assert x == "http://download.zip"
2021-01-10 13:52:51 +00:00
def test_get_ui_download_url_direct(mocker):
response = MagicMock()
response.json = MagicMock(
return_value=[
{
2024-05-12 13:47:54 +00:00
"assets_url": "http://whatever.json",
"name": "0.0.2",
"assets": [{"browser_download_url": "http://download22.zip"}],
},
{
2024-05-12 13:47:54 +00:00
"assets_url": "http://whatever.json",
"name": "0.0.1",
"assets": [{"browser_download_url": "http://download1.zip"}],
},
2024-05-12 13:47:54 +00:00
]
)
get_mock = mocker.patch("freqtrade.commands.deploy_ui.requests.get", return_value=response)
x, last_version = get_ui_download_url()
assert get_mock.call_count == 1
2024-05-12 13:47:54 +00:00
assert last_version == "0.0.2"
assert x == "http://download22.zip"
get_mock.reset_mock()
response.json.reset_mock()
2024-05-12 13:47:54 +00:00
x, last_version = get_ui_download_url("0.0.1")
assert last_version == "0.0.1"
assert x == "http://download1.zip"
with pytest.raises(ValueError, match="UI-Version not found."):
2024-05-12 13:47:54 +00:00
x, last_version = get_ui_download_url("0.0.3")
def test_download_data_keyboardInterrupt(mocker, markets):
2024-05-12 13:47:54 +00:00
dl_mock = mocker.patch(
2024-10-03 03:33:52 +00:00
"freqtrade.data.history.download_data_main",
2024-05-12 13:47:54 +00:00
MagicMock(side_effect=KeyboardInterrupt),
)
2019-08-17 04:58:38 +00:00
patch_exchange(mocker)
2024-05-12 13:47:54 +00:00
mocker.patch(f"{EXMS}.markets", PropertyMock(return_value=markets))
2019-08-17 04:58:38 +00:00
args = [
"download-data",
2024-05-12 13:47:54 +00:00
"--exchange",
"binance",
"--pairs",
"ETH/BTC",
"XRP/BTC",
2019-08-17 04:58:38 +00:00
]
2019-08-25 13:02:40 +00:00
with pytest.raises(SystemExit):
pargs = get_args(args)
2024-05-12 13:47:54 +00:00
pargs["config"] = None
start_download_data(pargs)
2019-08-17 04:58:38 +00:00
2019-08-25 13:02:40 +00:00
assert dl_mock.call_count == 1
2019-08-17 04:58:38 +00:00
def test_download_data_timerange(mocker, markets):
2024-05-12 13:47:54 +00:00
dl_mock = mocker.patch(
"freqtrade.data.history.history_utils.refresh_backtest_ohlcv_data",
MagicMock(return_value=["ETH/BTC", "XRP/BTC"]),
)
patch_exchange(mocker)
2024-05-12 13:47:54 +00:00
mocker.patch(f"{EXMS}.markets", PropertyMock(return_value=markets))
args = [
"download-data",
2024-05-12 13:47:54 +00:00
"--exchange",
"binance",
"--pairs",
"ETH/BTC",
"XRP/BTC",
"--days",
"20",
"--timerange",
"20200101-",
]
with pytest.raises(OperationalException, match=r"--days and --timerange are mutually.*"):
pargs = get_args(args)
2024-05-12 13:47:54 +00:00
pargs["config"] = None
start_download_data(pargs)
assert dl_mock.call_count == 0
args = [
"download-data",
2024-05-12 13:47:54 +00:00
"--exchange",
"binance",
"--pairs",
"ETH/BTC",
"XRP/BTC",
"--days",
"20",
]
pargs = get_args(args)
2024-05-12 13:47:54 +00:00
pargs["config"] = None
start_download_data(pargs)
assert dl_mock.call_count == 1
# 20days ago
2023-05-14 16:31:09 +00:00
days_ago = dt_floor_day(dt_now() - timedelta(days=20)).timestamp()
2024-05-12 13:47:54 +00:00
assert dl_mock.call_args_list[0][1]["timerange"].startts == days_ago
dl_mock.reset_mock()
args = [
"download-data",
2024-05-12 13:47:54 +00:00
"--exchange",
"binance",
"--pairs",
"ETH/BTC",
"XRP/BTC",
"--timerange",
"20200101-",
]
pargs = get_args(args)
2024-05-12 13:47:54 +00:00
pargs["config"] = None
start_download_data(pargs)
assert dl_mock.call_count == 1
2024-05-12 13:47:54 +00:00
assert dl_mock.call_args_list[0][1]["timerange"].startts == int(dt_utc(2020, 1, 1).timestamp())
2019-08-16 13:28:11 +00:00
def test_download_data_no_markets(mocker, caplog):
2024-05-12 13:47:54 +00:00
dl_mock = mocker.patch(
"freqtrade.data.history.history_utils.refresh_backtest_ohlcv_data",
MagicMock(return_value=["ETH/BTC", "XRP/BTC"]),
)
patch_exchange(mocker, exchange="binance")
2024-05-12 13:47:54 +00:00
mocker.patch(f"{EXMS}.get_markets", return_value={})
2019-08-16 13:28:11 +00:00
args = [
"download-data",
2024-05-12 13:47:54 +00:00
"--exchange",
"binance",
"--pairs",
"ETH/BTC",
"XRP/BTC",
"--days",
"20",
2019-08-16 13:28:11 +00:00
]
start_download_data(get_args(args))
2024-05-12 13:47:54 +00:00
assert dl_mock.call_args[1]["timerange"].starttype == "date"
assert log_has("Pairs [ETH/BTC,XRP/BTC] not available on exchange Binance.", caplog)
2023-06-17 16:22:47 +00:00
def test_download_data_no_exchange(mocker):
2024-05-12 13:47:54 +00:00
mocker.patch(
"freqtrade.data.history.history_utils.refresh_backtest_ohlcv_data",
MagicMock(return_value=["ETH/BTC", "XRP/BTC"]),
)
patch_exchange(mocker)
2024-05-12 13:47:54 +00:00
mocker.patch(f"{EXMS}.get_markets", return_value={})
args = [
"download-data",
2019-12-03 14:10:27 +00:00
]
pargs = get_args(args)
2024-05-12 13:47:54 +00:00
pargs["config"] = None
with pytest.raises(
OperationalException, match=r"This command requires a configured exchange.*"
):
start_download_data(pargs)
2023-01-05 08:12:09 +00:00
def test_download_data_no_pairs(mocker):
2024-05-12 13:47:54 +00:00
mocker.patch(
"freqtrade.data.history.history_utils.refresh_backtest_ohlcv_data",
MagicMock(return_value=["ETH/BTC", "XRP/BTC"]),
)
patch_exchange(mocker)
2024-05-12 13:47:54 +00:00
mocker.patch(f"{EXMS}.markets", PropertyMock(return_value={}))
args = [
"download-data",
"--exchange",
"binance",
]
pargs = get_args(args)
2024-05-12 13:47:54 +00:00
pargs["config"] = None
with pytest.raises(
OperationalException, match=r"Downloading data requires a list of pairs\..*"
):
start_download_data(pargs)
2019-10-08 18:31:14 +00:00
def test_download_data_all_pairs(mocker, markets):
2024-05-12 13:47:54 +00:00
dl_mock = mocker.patch(
"freqtrade.data.history.history_utils.refresh_backtest_ohlcv_data",
MagicMock(return_value=["ETH/BTC", "XRP/BTC"]),
)
patch_exchange(mocker)
2024-05-12 13:47:54 +00:00
mocker.patch(f"{EXMS}.markets", PropertyMock(return_value=markets))
args = ["download-data", "--exchange", "binance", "--pairs", ".*/USDT"]
pargs = get_args(args)
2024-05-12 13:47:54 +00:00
pargs["config"] = None
start_download_data(pargs)
2024-05-12 13:47:54 +00:00
expected = set(["BTC/USDT", "ETH/USDT", "XRP/USDT", "NEO/USDT", "TKN/USDT"])
assert set(dl_mock.call_args_list[0][1]["pairs"]) == expected
assert dl_mock.call_count == 1
dl_mock.reset_mock()
args = [
"download-data",
"--exchange",
"binance",
"--pairs",
".*/USDT",
"--include-inactive-pairs",
]
pargs = get_args(args)
2024-05-12 13:47:54 +00:00
pargs["config"] = None
start_download_data(pargs)
2024-05-12 13:47:54 +00:00
expected = set(["BTC/USDT", "ETH/USDT", "LTC/USDT", "XRP/USDT", "NEO/USDT", "TKN/USDT"])
assert set(dl_mock.call_args_list[0][1]["pairs"]) == expected
2023-06-17 16:22:47 +00:00
def test_download_data_trades(mocker):
2024-05-12 13:47:54 +00:00
dl_mock = mocker.patch(
"freqtrade.data.history.history_utils.refresh_backtest_trades_data",
MagicMock(return_value=[]),
)
convert_mock = mocker.patch(
"freqtrade.data.history.history_utils.convert_trades_to_ohlcv", MagicMock(return_value=[])
)
2019-10-08 18:31:14 +00:00
patch_exchange(mocker)
2024-05-12 13:47:54 +00:00
mocker.patch(f"{EXMS}.get_markets", return_value={})
2019-10-08 18:31:14 +00:00
args = [
"download-data",
2024-05-12 13:47:54 +00:00
"--exchange",
"kraken",
"--pairs",
"ETH/BTC",
"XRP/BTC",
"--days",
"20",
"--dl-trades",
2019-10-08 18:31:14 +00:00
]
pargs = get_args(args)
2024-05-12 13:47:54 +00:00
pargs["config"] = None
start_download_data(pargs)
2024-05-12 13:47:54 +00:00
assert dl_mock.call_args[1]["timerange"].starttype == "date"
2019-10-08 18:31:14 +00:00
assert dl_mock.call_count == 1
assert convert_mock.call_count == 1
args = [
"download-data",
2024-05-12 13:47:54 +00:00
"--exchange",
"kraken",
"--pairs",
"ETH/BTC",
"XRP/BTC",
"--days",
"20",
"--trading-mode",
"futures",
"--dl-trades",
]
2019-12-03 14:10:27 +00:00
def test_download_data_data_invalid(mocker):
patch_exchange(mocker, exchange="kraken")
2024-05-12 13:47:54 +00:00
mocker.patch(f"{EXMS}.get_markets", return_value={})
args = [
"download-data",
2024-05-12 13:47:54 +00:00
"--exchange",
"kraken",
"--pairs",
"ETH/BTC",
"XRP/BTC",
"--days",
"20",
]
pargs = get_args(args)
2024-05-12 13:47:54 +00:00
pargs["config"] = None
with pytest.raises(OperationalException, match=r"Historic klines not available for .*"):
start_download_data(pargs)
def test_start_convert_trades(mocker):
2024-05-12 13:47:54 +00:00
convert_mock = mocker.patch(
2024-10-03 03:33:52 +00:00
"freqtrade.data.converter.convert_trades_to_ohlcv", MagicMock(return_value=[])
2024-05-12 13:47:54 +00:00
)
2021-09-29 17:39:29 +00:00
patch_exchange(mocker)
2024-05-12 13:47:54 +00:00
mocker.patch(f"{EXMS}.get_markets")
mocker.patch(f"{EXMS}.markets", PropertyMock(return_value={}))
2021-09-29 17:39:29 +00:00
args = [
"trades-to-ohlcv",
2024-05-12 13:47:54 +00:00
"--exchange",
"kraken",
"--pairs",
"ETH/BTC",
"XRP/BTC",
2021-09-29 17:39:29 +00:00
]
start_convert_trades(get_args(args))
assert convert_mock.call_count == 1
2022-04-23 08:44:11 +00:00
def test_start_list_strategies(capsys):
2019-12-24 14:35:38 +00:00
args = [
"list-strategies",
"--strategy-path",
2020-02-18 19:12:10 +00:00
str(Path(__file__).parent.parent / "strategy" / "strats"),
2024-05-12 13:47:54 +00:00
"-1",
2019-12-24 14:35:38 +00:00
]
pargs = get_args(args)
# pargs['config'] = None
start_list_strategies(pargs)
captured = capsys.readouterr()
assert "StrategyTestV2" in captured.out
assert "strategy_test_v2.py" not in captured.out
assert CURRENT_TEST_STRATEGY in captured.out
2019-12-24 14:35:38 +00:00
# Test regular output
args = [
"list-strategies",
"--strategy-path",
2020-02-18 19:12:10 +00:00
str(Path(__file__).parent.parent / "strategy" / "strats"),
2024-05-12 13:47:54 +00:00
"--no-color",
2019-12-24 14:35:38 +00:00
]
pargs = get_args(args)
# pargs['config'] = None
start_list_strategies(pargs)
captured = capsys.readouterr()
assert "StrategyTestV2" in captured.out
assert "strategy_test_v2.py" in captured.out
assert CURRENT_TEST_STRATEGY in captured.out
2019-12-24 14:35:38 +00:00
# Test color output
2020-02-02 16:13:17 +00:00
args = [
"list-strategies",
"--strategy-path",
str(Path(__file__).parent.parent / "strategy" / "strats"),
2020-02-02 16:13:17 +00:00
]
pargs = get_args(args)
# pargs['config'] = None
start_list_strategies(pargs)
2020-02-02 16:13:17 +00:00
captured = capsys.readouterr()
assert "StrategyTestV2" in captured.out
assert "strategy_test_v2.py" in captured.out
assert CURRENT_TEST_STRATEGY in captured.out
assert "LOAD FAILED" in captured.out
2022-04-23 07:19:18 +00:00
# Recursive
assert "TestStrategyNoImplements" not in captured.out
# Test recursive
args = [
"list-strategies",
"--strategy-path",
str(Path(__file__).parent.parent / "strategy" / "strats"),
2024-05-12 13:47:54 +00:00
"--no-color",
"--recursive-strategy-search",
2022-04-23 07:19:18 +00:00
]
pargs = get_args(args)
# pargs['config'] = None
start_list_strategies(pargs)
captured = capsys.readouterr()
assert "StrategyTestV2" in captured.out
assert "strategy_test_v2.py" in captured.out
2022-04-23 07:19:18 +00:00
assert "StrategyTestV2" in captured.out
assert "TestStrategyNoImplements" in captured.out
2022-04-23 08:44:11 +00:00
assert str(Path("broken_strats/broken_futures_strategies.py")) in captured.out
2020-02-02 16:13:17 +00:00
2024-10-22 04:32:11 +00:00
def test_start_list_hyperopt_loss_functions(capsys):
args = ["list-hyperoptloss", "-1"]
pargs = get_args(args)
pargs["config"] = None
start_list_hyperopt_loss_functions(pargs)
captured = capsys.readouterr()
assert "CalmarHyperOptLoss" in captured.out
assert "MaxDrawDownHyperOptLoss" in captured.out
assert "SortinoHyperOptLossDaily" in captured.out
assert "<builtin>/hyperopt_loss_sortino_daily.py" not in captured.out
args = ["list-hyperoptloss"]
pargs = get_args(args)
pargs["config"] = None
start_list_hyperopt_loss_functions(pargs)
captured = capsys.readouterr()
assert "CalmarHyperOptLoss" in captured.out
assert "MaxDrawDownHyperOptLoss" in captured.out
assert "SortinoHyperOptLossDaily" in captured.out
assert "<builtin>/hyperopt_loss_sortino_daily.py" in captured.out
2022-10-15 06:20:06 +00:00
def test_start_list_freqAI_models(capsys):
2024-05-12 13:47:54 +00:00
args = ["list-freqaimodels", "-1"]
2022-10-15 06:20:06 +00:00
pargs = get_args(args)
2024-05-12 13:47:54 +00:00
pargs["config"] = None
2022-10-15 06:20:06 +00:00
start_list_freqAI_models(pargs)
captured = capsys.readouterr()
assert "LightGBMClassifier" in captured.out
assert "LightGBMRegressor" in captured.out
assert "XGBoostRegressor" in captured.out
assert "<builtin>/LightGBMRegressor.py" not in captured.out
args = [
"list-freqaimodels",
]
pargs = get_args(args)
2024-05-12 13:47:54 +00:00
pargs["config"] = None
2022-10-15 06:20:06 +00:00
start_list_freqAI_models(pargs)
captured = capsys.readouterr()
assert "LightGBMClassifier" in captured.out
assert "LightGBMRegressor" in captured.out
assert "XGBoostRegressor" in captured.out
assert "<builtin>/LightGBMRegressor.py" in captured.out
2020-01-25 12:38:13 +00:00
def test_start_test_pairlist(mocker, caplog, tickers, default_conf, capsys):
patch_exchange(mocker, mock_markets=True)
2024-05-12 13:47:54 +00:00
mocker.patch.multiple(
EXMS,
exchange_has=MagicMock(return_value=True),
get_tickers=tickers,
)
2019-12-03 14:10:27 +00:00
2024-05-12 13:47:54 +00:00
default_conf["pairlists"] = [
2019-12-03 14:10:27 +00:00
{
"method": "VolumePairList",
"number_assets": 5,
"sort_key": "quoteVolume",
},
{"method": "PrecisionFilter"},
{"method": "PriceFilter", "low_price_ratio": 0.02},
]
patched_configuration_load_config_file(mocker, default_conf)
2024-05-12 13:47:54 +00:00
args = ["test-pairlist", "-c", "tests/testdata/testconfigs/main_test_config.json"]
2019-12-03 14:10:27 +00:00
start_test_pairlist(get_args(args))
assert log_has_re(r"^Using resolved pairlist VolumePairList.*", caplog)
assert log_has_re(r"^Using resolved pairlist PrecisionFilter.*", caplog)
assert log_has_re(r"^Using resolved pairlist PriceFilter.*", caplog)
captured = capsys.readouterr()
assert re.match(r"Pairs for .*", captured.out)
assert re.match("['ETH/BTC', 'TKN/BTC', 'BLK/BTC', 'LTC/BTC', 'XRP/BTC']", captured.out)
2020-10-29 07:09:50 +00:00
args = [
2024-05-12 13:47:54 +00:00
"test-pairlist",
"-c",
"tests/testdata/testconfigs/main_test_config.json",
"--one-column",
2020-10-29 07:09:50 +00:00
]
start_test_pairlist(get_args(args))
captured = capsys.readouterr()
assert re.match(r"ETH/BTC\nTKN/BTC\nBLK/BTC\nLTC/BTC\nXRP/BTC\n", captured.out)
args = [
2024-05-12 13:47:54 +00:00
"test-pairlist",
"-c",
"tests/testdata/testconfigs/main_test_config.json",
"--print-json",
2020-10-29 07:09:50 +00:00
]
start_test_pairlist(get_args(args))
captured = capsys.readouterr()
try:
json_pairs = json.loads(captured.out)
2024-05-12 13:47:54 +00:00
assert "ETH/BTC" in json_pairs
assert "TKN/BTC" in json_pairs
assert "BLK/BTC" in json_pairs
assert "LTC/BTC" in json_pairs
assert "XRP/BTC" in json_pairs
except json.decoder.JSONDecodeError:
2024-05-12 13:47:54 +00:00
pytest.fail(f"Expected well formed JSON, but failed to parse: {captured.out}")
2020-10-29 07:09:50 +00:00
def test_hyperopt_list(mocker, capsys, caplog, tmp_path):
saved_hyperopt_results = hyperopt_test_result()
2023-11-05 15:25:23 +00:00
csv_file = tmp_path / "test.csv"
2021-08-08 08:22:45 +00:00
mocker.patch(
2024-05-12 13:47:54 +00:00
"freqtrade.optimize.hyperopt_tools.HyperoptTools._test_hyperopt_results_exist",
return_value=True,
2021-09-20 02:24:22 +00:00
)
def fake_iterator(*args, **kwargs):
yield from [saved_hyperopt_results]
mocker.patch(
2024-05-12 13:47:54 +00:00
"freqtrade.optimize.hyperopt_tools.HyperoptTools._read_results", side_effect=fake_iterator
2021-08-08 08:22:45 +00:00
)
args = [
"hyperopt-list",
"--no-details",
"--no-color",
]
pargs = get_args(args)
2024-05-12 13:47:54 +00:00
pargs["config"] = None
2021-08-08 08:22:45 +00:00
start_hyperopt_list(pargs)
captured = capsys.readouterr()
2024-05-12 13:47:54 +00:00
assert all(
x in captured.out
for x in [
" 1/12",
" 2/12",
" 3/12",
" 4/12",
" 5/12",
" 6/12",
" 7/12",
" 8/12",
" 9/12",
" 10/12",
" 11/12",
" 12/12",
]
)
2021-08-08 08:22:45 +00:00
args = [
"hyperopt-list",
"--best",
"--no-details",
"--no-color",
]
pargs = get_args(args)
2024-05-12 13:47:54 +00:00
pargs["config"] = None
2021-08-08 08:22:45 +00:00
start_hyperopt_list(pargs)
captured = capsys.readouterr()
2024-05-12 13:47:54 +00:00
assert all(x in captured.out for x in [" 1/12", " 5/12", " 10/12"])
assert all(
x not in captured.out
for x in [" 2/12", " 3/12", " 4/12", " 6/12", " 7/12", " 8/12", " 9/12", " 11/12", " 12/12"]
)
2021-08-08 08:22:45 +00:00
args = [
"hyperopt-list",
"--profitable",
"--no-details",
"--no-color",
]
pargs = get_args(args)
2024-05-12 13:47:54 +00:00
pargs["config"] = None
2021-08-08 08:22:45 +00:00
start_hyperopt_list(pargs)
captured = capsys.readouterr()
2024-05-12 13:47:54 +00:00
assert all(x in captured.out for x in [" 2/12", " 10/12"])
assert all(
x not in captured.out
for x in [
" 1/12",
" 3/12",
" 4/12",
" 5/12",
" 6/12",
" 7/12",
" 8/12",
" 9/12",
" 11/12",
" 12/12",
]
)
2021-08-08 08:22:45 +00:00
args = [
"hyperopt-list",
"--profitable",
"--no-color",
]
pargs = get_args(args)
2024-05-12 13:47:54 +00:00
pargs["config"] = None
2021-08-08 08:22:45 +00:00
start_hyperopt_list(pargs)
captured = capsys.readouterr()
2024-05-12 13:47:54 +00:00
assert all(
x in captured.out
for x in [
" 2/12",
" 10/12",
"Best result:",
"Buy hyperspace params",
"Sell hyperspace params",
"ROI table",
"Stoploss",
]
)
assert all(
x not in captured.out
for x in [
" 1/12",
" 3/12",
" 4/12",
" 5/12",
" 6/12",
" 7/12",
" 8/12",
" 9/12",
" 11/12",
" 12/12",
]
)
2021-08-08 08:22:45 +00:00
args = [
"hyperopt-list",
"--no-details",
"--no-color",
2024-05-12 13:47:54 +00:00
"--min-trades",
"20",
2021-08-08 08:22:45 +00:00
]
pargs = get_args(args)
2024-05-12 13:47:54 +00:00
pargs["config"] = None
2021-08-08 08:22:45 +00:00
start_hyperopt_list(pargs)
captured = capsys.readouterr()
2024-05-12 13:47:54 +00:00
assert all(x in captured.out for x in [" 3/12", " 6/12", " 7/12", " 9/12", " 11/12"])
assert all(
x not in captured.out
for x in [" 1/12", " 2/12", " 4/12", " 5/12", " 8/12", " 10/12", " 12/12"]
)
2021-08-08 08:22:45 +00:00
args = [
"hyperopt-list",
"--profitable",
"--no-details",
"--no-color",
2024-05-12 13:47:54 +00:00
"--max-trades",
"20",
2021-08-08 08:22:45 +00:00
]
pargs = get_args(args)
2024-05-12 13:47:54 +00:00
pargs["config"] = None
2021-08-08 08:22:45 +00:00
start_hyperopt_list(pargs)
captured = capsys.readouterr()
2024-05-12 13:47:54 +00:00
assert all(x in captured.out for x in [" 2/12", " 10/12"])
assert all(
x not in captured.out
for x in [
" 1/12",
" 3/12",
" 4/12",
" 5/12",
" 6/12",
" 7/12",
" 8/12",
" 9/12",
" 11/12",
" 12/12",
]
)
2021-08-08 08:22:45 +00:00
args = [
"hyperopt-list",
"--profitable",
"--no-details",
"--no-color",
2024-05-12 13:47:54 +00:00
"--min-avg-profit",
"0.11",
2021-08-08 08:22:45 +00:00
]
pargs = get_args(args)
2024-05-12 13:47:54 +00:00
pargs["config"] = None
2021-08-08 08:22:45 +00:00
start_hyperopt_list(pargs)
captured = capsys.readouterr()
2024-05-12 13:47:54 +00:00
assert all(x in captured.out for x in [" 2/12"])
assert all(
x not in captured.out
for x in [
" 1/12",
" 3/12",
" 4/12",
" 5/12",
" 6/12",
" 7/12",
" 8/12",
" 9/12",
" 10/12",
" 11/12",
" 12/12",
]
)
2021-08-08 08:22:45 +00:00
args = [
"hyperopt-list",
"--no-details",
"--no-color",
2024-05-12 13:47:54 +00:00
"--max-avg-profit",
"0.10",
2021-08-08 08:22:45 +00:00
]
pargs = get_args(args)
2024-05-12 13:47:54 +00:00
pargs["config"] = None
2021-08-08 08:22:45 +00:00
start_hyperopt_list(pargs)
captured = capsys.readouterr()
2024-05-12 13:47:54 +00:00
assert all(
x in captured.out
for x in [" 1/12", " 3/12", " 5/12", " 6/12", " 7/12", " 8/12", " 9/12", " 11/12"]
)
assert all(x not in captured.out for x in [" 2/12", " 4/12", " 10/12", " 12/12"])
2021-08-08 08:22:45 +00:00
args = [
"hyperopt-list",
"--no-details",
"--no-color",
2024-05-12 13:47:54 +00:00
"--min-total-profit",
"0.4",
2021-08-08 08:22:45 +00:00
]
pargs = get_args(args)
2024-05-12 13:47:54 +00:00
pargs["config"] = None
2021-08-08 08:22:45 +00:00
start_hyperopt_list(pargs)
captured = capsys.readouterr()
2024-05-12 13:47:54 +00:00
assert all(x in captured.out for x in [" 10/12"])
assert all(
x not in captured.out
for x in [
" 1/12",
" 2/12",
" 3/12",
" 4/12",
" 5/12",
" 6/12",
" 7/12",
" 8/12",
" 9/12",
" 11/12",
" 12/12",
]
)
2021-08-08 08:22:45 +00:00
args = [
"hyperopt-list",
"--no-details",
"--no-color",
2024-05-12 13:47:54 +00:00
"--max-total-profit",
"0.4",
2021-08-08 08:22:45 +00:00
]
pargs = get_args(args)
2024-05-12 13:47:54 +00:00
pargs["config"] = None
2021-08-08 08:22:45 +00:00
start_hyperopt_list(pargs)
captured = capsys.readouterr()
2024-05-12 13:47:54 +00:00
assert all(
x in captured.out
for x in [" 1/12", " 2/12", " 3/12", " 5/12", " 6/12", " 7/12", " 8/12", " 9/12", " 11/12"]
)
assert all(x not in captured.out for x in [" 4/12", " 10/12", " 12/12"])
2021-08-08 08:22:45 +00:00
args = [
"hyperopt-list",
"--no-details",
"--no-color",
2024-05-12 13:47:54 +00:00
"--min-objective",
"0.1",
2021-08-08 08:22:45 +00:00
]
pargs = get_args(args)
2024-05-12 13:47:54 +00:00
pargs["config"] = None
2021-08-08 08:22:45 +00:00
start_hyperopt_list(pargs)
captured = capsys.readouterr()
2024-05-12 13:47:54 +00:00
assert all(x in captured.out for x in [" 10/12"])
assert all(
x not in captured.out
for x in [
" 1/12",
" 2/12",
" 3/12",
" 4/12",
" 5/12",
" 6/12",
" 7/12",
" 8/12",
" 9/12",
" 11/12",
" 12/12",
]
)
2021-08-08 08:22:45 +00:00
args = [
"hyperopt-list",
"--no-details",
2024-05-12 13:47:54 +00:00
"--max-objective",
"0.1",
2021-08-08 08:22:45 +00:00
]
pargs = get_args(args)
2024-05-12 13:47:54 +00:00
pargs["config"] = None
2021-08-08 08:22:45 +00:00
start_hyperopt_list(pargs)
captured = capsys.readouterr()
2024-05-12 13:47:54 +00:00
assert all(
x in captured.out
for x in [" 1/12", " 2/12", " 3/12", " 5/12", " 6/12", " 7/12", " 8/12", " 9/12", " 11/12"]
)
assert all(x not in captured.out for x in [" 4/12", " 10/12", " 12/12"])
2021-08-08 08:22:45 +00:00
args = [
"hyperopt-list",
"--profitable",
"--no-details",
"--no-color",
2024-05-12 13:47:54 +00:00
"--min-avg-time",
"2000",
2021-08-08 08:22:45 +00:00
]
pargs = get_args(args)
2024-05-12 13:47:54 +00:00
pargs["config"] = None
2021-08-08 08:22:45 +00:00
start_hyperopt_list(pargs)
captured = capsys.readouterr()
2024-05-12 13:47:54 +00:00
assert all(x in captured.out for x in [" 10/12"])
assert all(
x not in captured.out
for x in [
" 1/12",
" 2/12",
" 3/12",
" 4/12",
" 5/12",
" 6/12",
" 7/12",
" 8/12",
" 9/12",
" 11/12",
" 12/12",
]
)
2021-08-08 08:22:45 +00:00
args = [
"hyperopt-list",
"--no-details",
"--no-color",
2024-05-12 13:47:54 +00:00
"--max-avg-time",
"1500",
2021-08-08 08:22:45 +00:00
]
pargs = get_args(args)
2024-05-12 13:47:54 +00:00
pargs["config"] = None
2021-08-08 08:22:45 +00:00
start_hyperopt_list(pargs)
captured = capsys.readouterr()
2024-05-12 13:47:54 +00:00
assert all(x in captured.out for x in [" 2/12", " 6/12"])
assert all(
x not in captured.out
for x in [
" 1/12",
" 3/12",
" 4/12",
" 5/12",
" 7/12",
" 8/12",
" 9/12",
" 10/12",
" 11/12",
" 12/12",
]
)
2021-08-08 08:22:45 +00:00
args = [
"hyperopt-list",
"--no-details",
"--no-color",
"--export-csv",
str(csv_file),
]
pargs = get_args(args)
2024-05-12 13:47:54 +00:00
pargs["config"] = None
2021-08-08 08:22:45 +00:00
start_hyperopt_list(pargs)
captured = capsys.readouterr()
log_has("CSV file created: test_file.csv", caplog)
assert csv_file.is_file()
line = csv_file.read_text()
2024-05-12 13:47:54 +00:00
assert (
'Best,1,2,-1.25%,-1.2222,-0.00125625,,-2.51,"3,930.0 m",0.43662' in line
or "Best,1,2,-1.25%,-1.2222,-0.00125625,,-2.51,2 days 17:30:00,2,0,0.43662" in line
)
2021-08-08 08:22:45 +00:00
csv_file.unlink()
2020-03-05 18:58:01 +00:00
def test_hyperopt_show(mocker, capsys):
saved_hyperopt_results = hyperopt_test_result()
mocker.patch(
2024-05-12 13:47:54 +00:00
"freqtrade.optimize.hyperopt_tools.HyperoptTools._test_hyperopt_results_exist",
return_value=True,
)
def fake_iterator(*args, **kwargs):
yield from [saved_hyperopt_results]
mocker.patch(
2024-05-12 13:47:54 +00:00
"freqtrade.optimize.hyperopt_tools.HyperoptTools._read_results", side_effect=fake_iterator
)
2024-10-03 03:33:52 +00:00
mocker.patch("freqtrade.optimize.optimize_reports.show_backtest_result")
args = [
"hyperopt-show",
]
2019-12-09 09:49:04 +00:00
pargs = get_args(args)
2024-05-12 13:47:54 +00:00
pargs["config"] = None
2019-12-09 09:49:04 +00:00
start_hyperopt_show(pargs)
captured = capsys.readouterr()
assert " 12/12" in captured.out
2024-05-12 13:47:54 +00:00
args = ["hyperopt-show", "--best"]
2019-12-09 09:49:04 +00:00
pargs = get_args(args)
2024-05-12 13:47:54 +00:00
pargs["config"] = None
2019-12-09 09:49:04 +00:00
start_hyperopt_show(pargs)
captured = capsys.readouterr()
assert " 10/12" in captured.out
2024-05-12 13:47:54 +00:00
args = ["hyperopt-show", "-n", "1"]
2019-12-09 09:49:04 +00:00
pargs = get_args(args)
2024-05-12 13:47:54 +00:00
pargs["config"] = None
2019-12-09 09:49:04 +00:00
start_hyperopt_show(pargs)
captured = capsys.readouterr()
assert " 1/12" in captured.out
2024-05-12 13:47:54 +00:00
args = ["hyperopt-show", "--best", "-n", "2"]
2019-12-09 09:49:04 +00:00
pargs = get_args(args)
2024-05-12 13:47:54 +00:00
pargs["config"] = None
2019-12-09 09:49:04 +00:00
start_hyperopt_show(pargs)
captured = capsys.readouterr()
assert " 5/12" in captured.out
2024-05-12 13:47:54 +00:00
args = ["hyperopt-show", "--best", "-n", "-1"]
2019-12-09 09:49:04 +00:00
pargs = get_args(args)
2024-05-12 13:47:54 +00:00
pargs["config"] = None
2019-12-09 09:49:04 +00:00
start_hyperopt_show(pargs)
captured = capsys.readouterr()
assert " 10/12" in captured.out
2019-12-09 21:22:11 +00:00
2024-05-12 13:47:54 +00:00
args = ["hyperopt-show", "--best", "-n", "-4"]
2019-12-09 21:22:11 +00:00
pargs = get_args(args)
2024-05-12 13:47:54 +00:00
pargs["config"] = None
with pytest.raises(
OperationalException, match="The index of the epoch to show should be greater than -4."
):
2019-12-09 21:22:11 +00:00
start_hyperopt_show(pargs)
2024-05-12 13:47:54 +00:00
args = ["hyperopt-show", "--best", "-n", "4"]
2019-12-09 21:22:11 +00:00
pargs = get_args(args)
2024-05-12 13:47:54 +00:00
pargs["config"] = None
with pytest.raises(
OperationalException, match="The index of the epoch to show should be less than 4."
):
2019-12-09 21:22:11 +00:00
start_hyperopt_show(pargs)
2019-12-28 09:37:34 +00:00
def test_convert_data(mocker, testdatadir):
2024-10-03 03:33:52 +00:00
ohlcv_mock = mocker.patch("freqtrade.data.converter.convert_ohlcv_format")
trades_mock = mocker.patch("freqtrade.data.converter.convert_trades_format")
2019-12-28 09:37:34 +00:00
args = [
"convert-data",
"--format-from",
"json",
"--format-to",
"jsongz",
"--datadir",
str(testdatadir),
]
pargs = get_args(args)
2024-05-12 13:47:54 +00:00
pargs["config"] = None
2019-12-28 09:37:34 +00:00
start_convert_data(pargs, True)
assert trades_mock.call_count == 0
assert ohlcv_mock.call_count == 1
2024-05-12 13:47:54 +00:00
assert ohlcv_mock.call_args[1]["convert_from"] == "json"
assert ohlcv_mock.call_args[1]["convert_to"] == "jsongz"
assert ohlcv_mock.call_args[1]["erase"] is False
2019-12-28 09:37:34 +00:00
def test_convert_data_trades(mocker, testdatadir):
2024-10-03 03:33:52 +00:00
ohlcv_mock = mocker.patch("freqtrade.data.converter.convert_ohlcv_format")
trades_mock = mocker.patch("freqtrade.data.converter.convert_trades_format")
2019-12-28 09:37:34 +00:00
args = [
"convert-trade-data",
"--format-from",
"jsongz",
"--format-to",
"json",
"--datadir",
str(testdatadir),
]
pargs = get_args(args)
2024-05-12 13:47:54 +00:00
pargs["config"] = None
2019-12-28 09:37:34 +00:00
start_convert_data(pargs, False)
assert ohlcv_mock.call_count == 0
assert trades_mock.call_count == 1
2024-05-12 13:47:54 +00:00
assert trades_mock.call_args[1]["convert_from"] == "jsongz"
assert trades_mock.call_args[1]["convert_to"] == "json"
assert trades_mock.call_args[1]["erase"] is False
2020-05-02 09:44:18 +00:00
2020-07-12 08:01:37 +00:00
def test_start_list_data(testdatadir, capsys):
args = [
"list-data",
"--datadir",
str(testdatadir),
]
pargs = get_args(args)
2024-05-12 13:47:54 +00:00
pargs["config"] = None
2020-07-12 08:01:37 +00:00
start_list_data(pargs)
captured = capsys.readouterr()
2023-07-09 17:44:33 +00:00
assert "Found 16 pair / timeframe combinations." in captured.out
assert re.search(r".*Pair.*Timeframe.*Type.*\n", captured.out)
assert re.search(r"\n.* UNITTEST/BTC .* 1m, 5m, 8m, 30m .* spot |\n", captured.out)
2020-07-14 04:55:34 +00:00
args = [
"list-data",
"--data-format-ohlcv",
2023-07-09 15:06:11 +00:00
"feather",
2024-05-12 13:47:54 +00:00
"--pairs",
"XRP/ETH",
2020-07-14 04:55:34 +00:00
"--datadir",
str(testdatadir),
]
pargs = get_args(args)
2024-05-12 13:47:54 +00:00
pargs["config"] = None
2020-07-14 04:55:34 +00:00
start_list_data(pargs)
captured = capsys.readouterr()
assert "Found 2 pair / timeframe combinations." in captured.out
assert re.search(r".*Pair.*Timeframe.*Type.*\n", captured.out)
2020-07-14 04:55:34 +00:00
assert "UNITTEST/BTC" not in captured.out
assert re.search(r"\n.* XRP/ETH .* 1m, 5m .* spot |\n", captured.out)
2020-07-12 08:01:37 +00:00
args = [
"list-data",
2024-05-12 13:47:54 +00:00
"--trading-mode",
"futures",
"--datadir",
str(testdatadir),
]
pargs = get_args(args)
2024-05-12 13:47:54 +00:00
pargs["config"] = None
start_list_data(pargs)
captured = capsys.readouterr()
assert "Found 6 pair / timeframe combinations." in captured.out
assert re.search(r".*Pair.*Timeframe.*Type.*\n", captured.out)
assert re.search(r"\n.* XRP/USDT:USDT .* 5m, 1h .* futures |\n", captured.out)
assert re.search(r"\n.* XRP/USDT:USDT .* 1h, 8h .* mark |\n", captured.out)
2022-08-19 11:44:31 +00:00
args = [
"list-data",
2024-05-12 13:47:54 +00:00
"--pairs",
"XRP/ETH",
2022-08-19 11:44:31 +00:00
"--datadir",
str(testdatadir),
"--show-timerange",
]
pargs = get_args(args)
2024-05-12 13:47:54 +00:00
pargs["config"] = None
2022-08-19 11:44:31 +00:00
start_list_data(pargs)
captured = capsys.readouterr()
assert "Found 2 pair / timeframe combinations." in captured.out
assert re.search(r".*Pair.*Timeframe.*Type.*From .* To .* Candles .*\n", captured.out)
2022-08-19 11:44:31 +00:00
assert "UNITTEST/BTC" not in captured.out
assert re.search(
r"\n.* XRP/USDT .* 1m .* spot .* 2019-10-11 00:00:00 .* 2019-10-13 11:19:00 .* 2469 |\n",
captured.out,
)
2022-08-19 11:44:31 +00:00
2020-07-12 08:01:37 +00:00
def test_start_list_trades_data(testdatadir, capsys):
args = [
"list-data",
"--datadir",
str(testdatadir),
"--trades",
]
pargs = get_args(args)
pargs["config"] = None
start_list_data(pargs)
captured = capsys.readouterr()
assert "Found trades data for 1 pair." in captured.out
assert re.search(r".*Pair.*Type.*\n", captured.out)
assert re.search(r"\n.* XRP/ETH .* spot |\n", captured.out)
args = [
"list-data",
"--datadir",
str(testdatadir),
"--trades",
"--show-timerange",
]
pargs = get_args(args)
pargs["config"] = None
start_list_data(pargs)
captured = capsys.readouterr()
assert "Found trades data for 1 pair." in captured.out
assert re.search(r".*Pair.*Type.*From.*To.*Trades.*\n", captured.out)
assert re.search(
r"\n.* XRP/ETH .* spot .* 2019-10-11 00:00:01 .* 2019-10-13 11:19:28 .* 12477 .*|\n",
captured.out,
)
args = [
"list-data",
"--datadir",
str(testdatadir),
"--trades",
2024-08-13 05:33:13 +00:00
"--trading-mode",
"futures",
]
pargs = get_args(args)
pargs["config"] = None
start_list_data(pargs)
captured = capsys.readouterr()
2024-08-13 05:33:13 +00:00
assert "Found trades data for 0 pairs." in captured.out
2020-05-02 09:44:18 +00:00
@pytest.mark.usefixtures("init_persistence")
def test_show_trades(mocker, fee, capsys, caplog):
2020-10-16 05:39:12 +00:00
mocker.patch("freqtrade.persistence.init_db")
2021-09-20 02:24:22 +00:00
create_mock_trades(fee, False)
2024-05-12 13:47:54 +00:00
args = ["show-trades", "--db-url", "sqlite:///"]
2020-05-02 09:44:18 +00:00
pargs = get_args(args)
2024-05-12 13:47:54 +00:00
pargs["config"] = None
2020-05-02 09:44:18 +00:00
start_show_trades(pargs)
2020-09-10 05:40:19 +00:00
assert log_has(f"Printing {MOCK_TRADE_COUNT} Trades: ", caplog)
2020-05-02 09:44:18 +00:00
captured = capsys.readouterr()
assert "Trade(id=1" in captured.out
assert "Trade(id=2" in captured.out
assert "Trade(id=3" in captured.out
2024-05-12 13:47:54 +00:00
args = ["show-trades", "--db-url", "sqlite:///", "--print-json", "--trade-ids", "1", "2"]
2020-05-02 09:44:18 +00:00
pargs = get_args(args)
2024-05-12 13:47:54 +00:00
pargs["config"] = None
2020-05-02 09:44:18 +00:00
start_show_trades(pargs)
captured = capsys.readouterr()
assert log_has("Printing 2 Trades: ", caplog)
assert '"trade_id": 1' in captured.out
assert '"trade_id": 2' in captured.out
assert '"trade_id": 3' not in captured.out
args = [
"show-trades",
]
pargs = get_args(args)
2024-05-12 13:47:54 +00:00
pargs["config"] = None
with pytest.raises(OperationalException, match=r"--db-url is required for this command."):
start_show_trades(pargs)
2021-10-30 15:05:12 +00:00
2021-10-31 08:55:19 +00:00
def test_backtesting_show(mocker, testdatadir, capsys):
2024-05-12 13:47:54 +00:00
sbr = mocker.patch("freqtrade.optimize.optimize_reports.show_backtest_results")
2021-10-30 15:05:12 +00:00
args = [
2021-10-31 08:55:19 +00:00
"backtesting-show",
2021-10-30 15:05:12 +00:00
"--export-filename",
f"{testdatadir / 'backtest_results/backtest-result.json'}",
2024-05-12 13:47:54 +00:00
"--show-pair-list",
2021-10-30 15:05:12 +00:00
]
pargs = get_args(args)
2024-05-12 13:47:54 +00:00
pargs["config"] = None
2021-10-31 08:55:19 +00:00
start_backtesting_show(pargs)
2021-10-30 15:05:12 +00:00
assert sbr.call_count == 1
2024-01-24 19:31:38 +00:00
out, _err = capsys.readouterr()
2021-10-30 15:05:12 +00:00
assert "Pairs for Strategy" in out
2022-05-09 17:59:15 +00:00
2023-11-05 15:25:36 +00:00
def test_start_convert_db(fee, tmp_path):
db_src_file = tmp_path / "db.sqlite"
2022-05-09 17:59:15 +00:00
db_from = f"sqlite:///{db_src_file}"
2023-11-05 15:35:49 +00:00
db_target_file = tmp_path / "db_target.sqlite"
2022-05-09 17:59:15 +00:00
db_to = f"sqlite:///{db_target_file}"
args = [
"convert-db",
2022-05-09 17:59:15 +00:00
"--db-url-from",
db_from,
"--db-url",
db_to,
]
assert not db_src_file.is_file()
2022-05-19 04:45:20 +00:00
init_db(db_from)
2022-05-09 17:59:15 +00:00
create_mock_trades(fee)
2022-05-10 17:17:12 +00:00
2024-05-12 13:47:54 +00:00
PairLocks.timeframe = "5m"
PairLocks.lock_pair("XRP/USDT", datetime.now(), "Random reason 125", side="long")
2022-05-09 17:59:15 +00:00
assert db_src_file.is_file()
assert not db_target_file.is_file()
2022-05-10 17:17:12 +00:00
2022-05-09 17:59:15 +00:00
pargs = get_args(args)
2024-05-12 13:47:54 +00:00
pargs["config"] = None
start_convert_db(pargs)
2022-05-10 17:17:12 +00:00
2022-05-09 17:59:15 +00:00
assert db_target_file.is_file()
2023-11-05 15:25:36 +00:00
def test_start_strategy_updater(mocker, tmp_path):
2024-05-12 13:47:54 +00:00
sc_mock = mocker.patch("freqtrade.commands.strategy_utils_commands.start_conversion")
teststrats = Path(__file__).parent.parent / "strategy/strats"
args = [
"strategy-updater",
"--userdir",
2023-11-05 15:25:36 +00:00
str(tmp_path),
"--strategy-path",
str(teststrats),
]
pargs = get_args(args)
2024-05-12 13:47:54 +00:00
pargs["config"] = None
start_strategy_update(pargs)
# Number of strategies in the test directory
2023-09-21 11:19:39 +00:00
assert sc_mock.call_count == 12
sc_mock.reset_mock()
args = [
"strategy-updater",
"--userdir",
2023-11-05 15:25:36 +00:00
str(tmp_path),
"--strategy-path",
str(teststrats),
"--strategy-list",
"StrategyTestV3",
2024-05-12 13:47:54 +00:00
"StrategyTestV2",
]
pargs = get_args(args)
2024-05-12 13:47:54 +00:00
pargs["config"] = None
start_strategy_update(pargs)
# Number of strategies in the test directory
assert sc_mock.call_count == 2
2024-03-19 19:23:51 +00:00
def test_start_show_config(capsys, caplog):
2024-03-19 19:23:51 +00:00
args = [
"show-config",
"--config",
"tests/testdata/testconfigs/main_test_config.json",
]
pargs = get_args(args)
start_show_config(pargs)
captured = capsys.readouterr()
assert "Your combined configuration is:" in captured.out
assert '"max_open_trades":' in captured.out
assert '"secret": "REDACTED"' in captured.out
2024-03-20 06:07:00 +00:00
args = [
"show-config",
"--config",
"tests/testdata/testconfigs/main_test_config.json",
2024-05-12 13:47:54 +00:00
"--show-sensitive",
2024-03-20 06:07:00 +00:00
]
pargs = get_args(args)
start_show_config(pargs)
captured = capsys.readouterr()
assert "Your combined configuration is:" in captured.out
assert '"max_open_trades":' in captured.out
assert '"secret": "REDACTED"' not in captured.out
2024-05-12 13:47:54 +00:00
assert log_has_re(r"Sensitive information will be shown in the upcoming output.*", caplog)