mirror of
https://github.com/freqtrade/freqtrade.git
synced 2025-11-29 08:33:07 +00:00
Add startup test case
This commit is contained in:
@@ -6,7 +6,6 @@ from freqtrade.configuration import setup_utils_configuration
|
|||||||
from freqtrade.enums import RunMode
|
from freqtrade.enums import RunMode
|
||||||
from freqtrade.exceptions import OperationalException
|
from freqtrade.exceptions import OperationalException
|
||||||
from freqtrade.misc import round_coin_value
|
from freqtrade.misc import round_coin_value
|
||||||
from freqtrade.optimize.lookahead_analysis import LookaheadAnalysisSubFunctions
|
|
||||||
from freqtrade.resolvers import StrategyResolver
|
from freqtrade.resolvers import StrategyResolver
|
||||||
|
|
||||||
|
|
||||||
@@ -142,12 +141,16 @@ def start_lookahead_analysis(args: Dict[str, Any]) -> None:
|
|||||||
:param args: Cli args from Arguments()
|
:param args: Cli args from Arguments()
|
||||||
:return: None
|
:return: None
|
||||||
"""
|
"""
|
||||||
|
from freqtrade.optimize.lookahead_analysis import LookaheadAnalysisSubFunctions
|
||||||
|
|
||||||
config = setup_utils_configuration(args, RunMode.UTIL_NO_EXCHANGE)
|
config = setup_utils_configuration(args, RunMode.UTIL_NO_EXCHANGE)
|
||||||
|
|
||||||
if config['targeted_trade_amount'] < config['minimum_trade_amount']:
|
if config['targeted_trade_amount'] < config['minimum_trade_amount']:
|
||||||
# add logic that tells the user to check the configuration
|
# add logic that tells the user to check the configuration
|
||||||
# since this combo doesn't make any sense.
|
# since this combo doesn't make any sense.
|
||||||
pass
|
raise OperationalException(
|
||||||
|
"targeted trade amount can't be smaller than minimum trade amount."
|
||||||
|
)
|
||||||
|
|
||||||
strategy_objs = StrategyResolver.search_all_objects(
|
strategy_objs = StrategyResolver.search_all_objects(
|
||||||
config, enum_failed=False, recursive=config.get('recursive_strategy_search', False))
|
config, enum_failed=False, recursive=config.get('recursive_strategy_search', False))
|
||||||
|
|||||||
@@ -1,17 +1,16 @@
|
|||||||
# pragma pylint: disable=missing-docstring, W0212, line-too-long, C0103, unused-argument
|
# pragma pylint: disable=missing-docstring, W0212, line-too-long, C0103, unused-argument
|
||||||
|
|
||||||
from unittest.mock import PropertyMock
|
from pathlib import Path
|
||||||
|
from unittest.mock import MagicMock, PropertyMock
|
||||||
|
|
||||||
import numpy as np
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
import freqtrade.commands.arguments
|
import freqtrade.commands.arguments
|
||||||
import freqtrade.optimize.lookahead_analysis
|
import freqtrade.optimize.lookahead_analysis
|
||||||
from freqtrade.configuration import TimeRange
|
from freqtrade.commands.optimize_commands import start_lookahead_analysis
|
||||||
from freqtrade.data import history
|
|
||||||
from freqtrade.data.converter import clean_ohlcv_dataframe
|
|
||||||
from freqtrade.data.history import get_timerange
|
from freqtrade.data.history import get_timerange
|
||||||
from tests.conftest import generate_test_data, patch_exchange
|
from freqtrade.exceptions import OperationalException
|
||||||
|
from tests.conftest import CURRENT_TEST_STRATEGY, get_args, patch_exchange
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
@@ -22,11 +21,46 @@ def lookahead_conf(default_conf_usdt):
|
|||||||
return default_conf_usdt
|
return default_conf_usdt
|
||||||
|
|
||||||
|
|
||||||
def trim_dictlist(dict_list, num):
|
def test_start_start_lookahead_analysis(mocker):
|
||||||
new = {}
|
single_mock = MagicMock()
|
||||||
for pair, pair_data in dict_list.items():
|
mocker.patch.multiple(
|
||||||
new[pair] = pair_data[num:].reset_index()
|
'freqtrade.optimize.lookahead_analysis.LookaheadAnalysisSubFunctions',
|
||||||
return new
|
initialize_single_lookahead_analysis=single_mock,
|
||||||
|
text_table_lookahead_analysis_instances=MagicMock(),
|
||||||
|
)
|
||||||
|
args = [
|
||||||
|
"lookahead-analysis",
|
||||||
|
"--strategy",
|
||||||
|
CURRENT_TEST_STRATEGY,
|
||||||
|
"--strategy-path",
|
||||||
|
str(Path(__file__).parent.parent / "strategy" / "strats"),
|
||||||
|
]
|
||||||
|
pargs = get_args(args)
|
||||||
|
pargs['config'] = None
|
||||||
|
|
||||||
|
start_lookahead_analysis(pargs)
|
||||||
|
assert single_mock.call_count == 1
|
||||||
|
|
||||||
|
single_mock.reset_mock()
|
||||||
|
|
||||||
|
# Test invalid config
|
||||||
|
args = [
|
||||||
|
"lookahead-analysis",
|
||||||
|
"--strategy",
|
||||||
|
CURRENT_TEST_STRATEGY,
|
||||||
|
"--strategy-path",
|
||||||
|
str(Path(__file__).parent.parent / "strategy" / "strats"),
|
||||||
|
"--targeted-trade-amount",
|
||||||
|
"10",
|
||||||
|
"--minimum-trade-amount",
|
||||||
|
"20",
|
||||||
|
]
|
||||||
|
pargs = get_args(args)
|
||||||
|
pargs['config'] = None
|
||||||
|
with pytest.raises(OperationalException,
|
||||||
|
match=r"targeted trade amount can't be smaller than .*"):
|
||||||
|
start_lookahead_analysis(pargs)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def test_biased_strategy(lookahead_conf, mocker, caplog) -> None:
|
def test_biased_strategy(lookahead_conf, mocker, caplog) -> None:
|
||||||
|
|||||||
Reference in New Issue
Block a user