mirror of
https://github.com/freqtrade/freqtrade.git
synced 2026-01-20 05:50:36 +00:00
tests: update protection tests
This commit is contained in:
@@ -445,7 +445,6 @@ While this strategy is most likely too simple to provide consistent profit, it s
|
|||||||
|
|
||||||
Whether you are using `.range` functionality or the alternatives above, you should try to use space ranges as small as possible since this will improve CPU/RAM usage.
|
Whether you are using `.range` functionality or the alternatives above, you should try to use space ranges as small as possible since this will improve CPU/RAM usage.
|
||||||
|
|
||||||
|
|
||||||
## Optimizing protections
|
## Optimizing protections
|
||||||
|
|
||||||
Freqtrade can also optimize protections. How you optimize protections is up to you, and the following should be considered as example only.
|
Freqtrade can also optimize protections. How you optimize protections is up to you, and the following should be considered as example only.
|
||||||
|
|||||||
@@ -553,7 +553,7 @@ def test_enter_positions_global_pairlock(
|
|||||||
|
|
||||||
@pytest.mark.parametrize("is_short", [False, True])
|
@pytest.mark.parametrize("is_short", [False, True])
|
||||||
def test_handle_protections(mocker, default_conf_usdt, fee, is_short):
|
def test_handle_protections(mocker, default_conf_usdt, fee, is_short):
|
||||||
default_conf_usdt["protections"] = [
|
default_conf_usdt["_strategy_protections"] = [
|
||||||
{"method": "CooldownPeriod", "stop_duration": 60},
|
{"method": "CooldownPeriod", "stop_duration": 60},
|
||||||
{
|
{
|
||||||
"method": "StoplossGuard",
|
"method": "StoplossGuard",
|
||||||
|
|||||||
@@ -1299,7 +1299,7 @@ def test_backtest_pricecontours_protections(default_conf, fee, mocker, testdatad
|
|||||||
# While this test IS a copy of test_backtest_pricecontours, it's needed to ensure
|
# While this test IS a copy of test_backtest_pricecontours, it's needed to ensure
|
||||||
# results do not carry-over to the next run, which is not given by using parametrize.
|
# results do not carry-over to the next run, which is not given by using parametrize.
|
||||||
patch_exchange(mocker)
|
patch_exchange(mocker)
|
||||||
default_conf["protections"] = [
|
default_conf["_strategy_protections"] = [
|
||||||
{
|
{
|
||||||
"method": "CooldownPeriod",
|
"method": "CooldownPeriod",
|
||||||
"stop_duration": 3,
|
"stop_duration": 3,
|
||||||
@@ -1358,7 +1358,7 @@ def test_backtest_pricecontours(
|
|||||||
default_conf, mocker, testdatadir, protections, contour, expected
|
default_conf, mocker, testdatadir, protections, contour, expected
|
||||||
) -> None:
|
) -> None:
|
||||||
if protections:
|
if protections:
|
||||||
default_conf["protections"] = protections
|
default_conf["_strategy_protections"] = protections
|
||||||
default_conf["enable_protections"] = True
|
default_conf["enable_protections"] = True
|
||||||
|
|
||||||
patch_exchange(mocker)
|
patch_exchange(mocker)
|
||||||
|
|||||||
@@ -88,7 +88,7 @@ def generate_mock_trade(
|
|||||||
|
|
||||||
|
|
||||||
def test_protectionmanager(mocker, default_conf):
|
def test_protectionmanager(mocker, default_conf):
|
||||||
default_conf["protections"] = [
|
default_conf["_strategy_protections"] = [
|
||||||
{"method": protection} for protection in constants.AVAILABLE_PROTECTIONS
|
{"method": protection} for protection in constants.AVAILABLE_PROTECTIONS
|
||||||
]
|
]
|
||||||
freqtrade = get_patched_freqtradebot(mocker, default_conf)
|
freqtrade = get_patched_freqtradebot(mocker, default_conf)
|
||||||
@@ -196,7 +196,7 @@ def test_protections_init(default_conf, timeframe, expected_lookback, expected_s
|
|||||||
@pytest.mark.usefixtures("init_persistence")
|
@pytest.mark.usefixtures("init_persistence")
|
||||||
def test_stoploss_guard(mocker, default_conf, fee, caplog, is_short):
|
def test_stoploss_guard(mocker, default_conf, fee, caplog, is_short):
|
||||||
# Active for both sides (long and short)
|
# Active for both sides (long and short)
|
||||||
default_conf["protections"] = [
|
default_conf["_strategy_protections"] = [
|
||||||
{"method": "StoplossGuard", "lookback_period": 60, "stop_duration": 40, "trade_limit": 3}
|
{"method": "StoplossGuard", "lookback_period": 60, "stop_duration": 40, "trade_limit": 3}
|
||||||
]
|
]
|
||||||
freqtrade = get_patched_freqtradebot(mocker, default_conf)
|
freqtrade = get_patched_freqtradebot(mocker, default_conf)
|
||||||
@@ -268,7 +268,7 @@ def test_stoploss_guard(mocker, default_conf, fee, caplog, is_short):
|
|||||||
@pytest.mark.parametrize("only_per_side", [False, True])
|
@pytest.mark.parametrize("only_per_side", [False, True])
|
||||||
@pytest.mark.usefixtures("init_persistence")
|
@pytest.mark.usefixtures("init_persistence")
|
||||||
def test_stoploss_guard_perpair(mocker, default_conf, fee, caplog, only_per_pair, only_per_side):
|
def test_stoploss_guard_perpair(mocker, default_conf, fee, caplog, only_per_pair, only_per_side):
|
||||||
default_conf["protections"] = [
|
default_conf["_strategy_protections"] = [
|
||||||
{
|
{
|
||||||
"method": "StoplossGuard",
|
"method": "StoplossGuard",
|
||||||
"lookback_period": 60,
|
"lookback_period": 60,
|
||||||
@@ -379,7 +379,7 @@ def test_stoploss_guard_perpair(mocker, default_conf, fee, caplog, only_per_pair
|
|||||||
|
|
||||||
@pytest.mark.usefixtures("init_persistence")
|
@pytest.mark.usefixtures("init_persistence")
|
||||||
def test_CooldownPeriod(mocker, default_conf, fee, caplog):
|
def test_CooldownPeriod(mocker, default_conf, fee, caplog):
|
||||||
default_conf["protections"] = [
|
default_conf["_strategy_protections"] = [
|
||||||
{
|
{
|
||||||
"method": "CooldownPeriod",
|
"method": "CooldownPeriod",
|
||||||
"stop_duration": 60,
|
"stop_duration": 60,
|
||||||
@@ -425,7 +425,7 @@ def test_CooldownPeriod(mocker, default_conf, fee, caplog):
|
|||||||
|
|
||||||
@pytest.mark.usefixtures("init_persistence")
|
@pytest.mark.usefixtures("init_persistence")
|
||||||
def test_CooldownPeriod_unlock_at(mocker, default_conf, fee, caplog, time_machine):
|
def test_CooldownPeriod_unlock_at(mocker, default_conf, fee, caplog, time_machine):
|
||||||
default_conf["protections"] = [
|
default_conf["_strategy_protections"] = [
|
||||||
{
|
{
|
||||||
"method": "CooldownPeriod",
|
"method": "CooldownPeriod",
|
||||||
"unlock_at": "05:00",
|
"unlock_at": "05:00",
|
||||||
@@ -509,7 +509,7 @@ def test_CooldownPeriod_unlock_at(mocker, default_conf, fee, caplog, time_machin
|
|||||||
@pytest.mark.parametrize("only_per_side", [False, True])
|
@pytest.mark.parametrize("only_per_side", [False, True])
|
||||||
@pytest.mark.usefixtures("init_persistence")
|
@pytest.mark.usefixtures("init_persistence")
|
||||||
def test_LowProfitPairs(mocker, default_conf, fee, caplog, only_per_side):
|
def test_LowProfitPairs(mocker, default_conf, fee, caplog, only_per_side):
|
||||||
default_conf["protections"] = [
|
default_conf["_strategy_protections"] = [
|
||||||
{
|
{
|
||||||
"method": "LowProfitPairs",
|
"method": "LowProfitPairs",
|
||||||
"lookback_period": 400,
|
"lookback_period": 400,
|
||||||
@@ -599,7 +599,7 @@ def test_LowProfitPairs(mocker, default_conf, fee, caplog, only_per_side):
|
|||||||
|
|
||||||
@pytest.mark.usefixtures("init_persistence")
|
@pytest.mark.usefixtures("init_persistence")
|
||||||
def test_MaxDrawdown(mocker, default_conf, fee, caplog):
|
def test_MaxDrawdown(mocker, default_conf, fee, caplog):
|
||||||
default_conf["protections"] = [
|
default_conf["_strategy_protections"] = [
|
||||||
{
|
{
|
||||||
"method": "MaxDrawdown",
|
"method": "MaxDrawdown",
|
||||||
"lookback_period": 1000,
|
"lookback_period": 1000,
|
||||||
@@ -812,7 +812,7 @@ def test_MaxDrawdown(mocker, default_conf, fee, caplog):
|
|||||||
def test_protection_manager_desc(
|
def test_protection_manager_desc(
|
||||||
mocker, default_conf, protectionconf, desc_expected, exception_expected
|
mocker, default_conf, protectionconf, desc_expected, exception_expected
|
||||||
):
|
):
|
||||||
default_conf["protections"] = [protectionconf]
|
default_conf["_strategy_protections"] = [protectionconf]
|
||||||
freqtrade = get_patched_freqtradebot(mocker, default_conf)
|
freqtrade = get_patched_freqtradebot(mocker, default_conf)
|
||||||
|
|
||||||
short_desc = str(freqtrade.protections.short_desc())
|
short_desc = str(freqtrade.protections.short_desc())
|
||||||
|
|||||||
@@ -173,7 +173,7 @@ def test_startupmessages_telegram_enabled(mocker, default_conf) -> None:
|
|||||||
telegram_mock.reset_mock()
|
telegram_mock.reset_mock()
|
||||||
default_conf["dry_run"] = True
|
default_conf["dry_run"] = True
|
||||||
default_conf["whitelist"] = {"method": "VolumePairList", "config": {"number_assets": 20}}
|
default_conf["whitelist"] = {"method": "VolumePairList", "config": {"number_assets": 20}}
|
||||||
default_conf["protections"] = [
|
default_conf["_strategy_protections"] = [
|
||||||
{"method": "StoplossGuard", "lookback_period": 60, "trade_limit": 2, "stop_duration": 60}
|
{"method": "StoplossGuard", "lookback_period": 60, "trade_limit": 2, "stop_duration": 60}
|
||||||
]
|
]
|
||||||
freqtradebot = get_patched_freqtradebot(mocker, default_conf)
|
freqtradebot = get_patched_freqtradebot(mocker, default_conf)
|
||||||
|
|||||||
@@ -75,15 +75,13 @@ class StrategyTestV3(IStrategy):
|
|||||||
protection_cooldown_lookback = IntParameter([0, 50], default=30)
|
protection_cooldown_lookback = IntParameter([0, 50], default=30)
|
||||||
|
|
||||||
# TODO: Can this work with protection tests? (replace HyperoptableStrategy implicitly ... )
|
# TODO: Can this work with protection tests? (replace HyperoptableStrategy implicitly ... )
|
||||||
# @property
|
@property
|
||||||
# def protections(self):
|
def protections(self):
|
||||||
# prot = []
|
prot = []
|
||||||
# if self.protection_enabled.value:
|
if self.protection_enabled.value:
|
||||||
# prot.append({
|
# Workaround to simplify tests. This will not work in real scenarios.
|
||||||
# "method": "CooldownPeriod",
|
prot = self.config.get("_strategy_protections", {})
|
||||||
# "stop_duration_candles": self.protection_cooldown_lookback.value
|
return prot
|
||||||
# })
|
|
||||||
# return prot
|
|
||||||
|
|
||||||
bot_started = False
|
bot_started = False
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user