mirror of
https://github.com/freqtrade/freqtrade.git
synced 2025-12-02 10:03:05 +00:00
Added unlock_at field for protection config
This commit is contained in:
@@ -102,56 +102,94 @@ def test_protectionmanager(mocker, default_conf):
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"timeframe,expected,protconf",
|
||||
"timeframe,expected_lookback,expected_stop,protconf",
|
||||
[
|
||||
(
|
||||
"1m",
|
||||
[20, 10],
|
||||
20,
|
||||
10,
|
||||
[{"method": "StoplossGuard", "lookback_period_candles": 20, "stop_duration": 10}],
|
||||
),
|
||||
(
|
||||
"5m",
|
||||
[100, 15],
|
||||
100,
|
||||
15,
|
||||
[{"method": "StoplossGuard", "lookback_period_candles": 20, "stop_duration": 15}],
|
||||
),
|
||||
(
|
||||
"1h",
|
||||
[1200, 40],
|
||||
1200,
|
||||
40,
|
||||
[{"method": "StoplossGuard", "lookback_period_candles": 20, "stop_duration": 40}],
|
||||
),
|
||||
(
|
||||
"1d",
|
||||
[1440, 5],
|
||||
1440,
|
||||
5,
|
||||
[{"method": "StoplossGuard", "lookback_period_candles": 1, "stop_duration": 5}],
|
||||
),
|
||||
(
|
||||
"1m",
|
||||
[20, 5],
|
||||
20,
|
||||
5,
|
||||
[{"method": "StoplossGuard", "lookback_period": 20, "stop_duration_candles": 5}],
|
||||
),
|
||||
(
|
||||
"5m",
|
||||
[15, 25],
|
||||
15,
|
||||
25,
|
||||
[{"method": "StoplossGuard", "lookback_period": 15, "stop_duration_candles": 5}],
|
||||
),
|
||||
(
|
||||
"1h",
|
||||
[50, 600],
|
||||
50,
|
||||
600,
|
||||
[{"method": "StoplossGuard", "lookback_period": 50, "stop_duration_candles": 10}],
|
||||
),
|
||||
(
|
||||
"1h",
|
||||
[60, 540],
|
||||
60,
|
||||
540,
|
||||
[{"method": "StoplossGuard", "lookback_period_candles": 1, "stop_duration_candles": 9}],
|
||||
),
|
||||
(
|
||||
"1m",
|
||||
20,
|
||||
"01:00",
|
||||
[{"method": "StoplossGuard", "lookback_period_candles": 20, "unlock_at": "01:00"}],
|
||||
),
|
||||
(
|
||||
"5m",
|
||||
100,
|
||||
"02:00",
|
||||
[{"method": "StoplossGuard", "lookback_period_candles": 20, "unlock_at": "02:00"}],
|
||||
),
|
||||
(
|
||||
"1h",
|
||||
1200,
|
||||
"03:00",
|
||||
[{"method": "StoplossGuard", "lookback_period_candles": 20, "unlock_at": "03:00"}],
|
||||
),
|
||||
(
|
||||
"1d",
|
||||
1440,
|
||||
"04:00",
|
||||
[{"method": "StoplossGuard", "lookback_period_candles": 1, "unlock_at": "04:00"}],
|
||||
),
|
||||
],
|
||||
)
|
||||
def test_protections_init(default_conf, timeframe, expected, protconf):
|
||||
def test_protections_init(default_conf, timeframe, expected_lookback, expected_stop, protconf):
|
||||
"""
|
||||
Test the initialization of protections with different configurations, including unlock_at.
|
||||
"""
|
||||
default_conf["timeframe"] = timeframe
|
||||
man = ProtectionManager(default_conf, protconf)
|
||||
assert len(man._protection_handlers) == len(protconf)
|
||||
assert man._protection_handlers[0]._lookback_period == expected[0]
|
||||
assert man._protection_handlers[0]._stop_duration == expected[1]
|
||||
assert man._protection_handlers[0]._lookback_period == expected_lookback
|
||||
if isinstance(expected_stop, int):
|
||||
assert man._protection_handlers[0]._stop_duration == expected_stop
|
||||
else:
|
||||
assert man._protection_handlers[0].unlock_at.strftime("%H:%M") == expected_stop
|
||||
|
||||
|
||||
@pytest.mark.parametrize("is_short", [False, True])
|
||||
@@ -654,6 +692,30 @@ def test_MaxDrawdown(mocker, default_conf, fee, caplog):
|
||||
"if drawdown is > 0.0 within 20 candles.'}]",
|
||||
None,
|
||||
),
|
||||
(
|
||||
{
|
||||
"method": "StoplossGuard",
|
||||
"lookback_period_candles": 12,
|
||||
"trade_limit": 2,
|
||||
"required_profit": -0.05,
|
||||
"unlock_at": "01:00",
|
||||
},
|
||||
"[{'StoplossGuard': 'StoplossGuard - Frequent Stoploss Guard, "
|
||||
"2 stoplosses with profit < -5.00% within 12 candles. Unlocking trading at 01:00.'}]",
|
||||
None,
|
||||
),
|
||||
(
|
||||
{"method": "LowProfitPairs", "lookback_period_candles": 11, "unlock_at": "03:00"},
|
||||
"[{'LowProfitPairs': 'LowProfitPairs - Low Profit Protection, locks pairs with "
|
||||
"profit < 0.0 within 11 candles. Unlocking trading at 03:00.'}]",
|
||||
None,
|
||||
),
|
||||
(
|
||||
{"method": "MaxDrawdown", "lookback_period_candles": 20, "unlock_at": "04:00"},
|
||||
"[{'MaxDrawdown': 'MaxDrawdown - Max drawdown protection, stop trading "
|
||||
"if drawdown is > 0.0 within 20 candles. Unlocking trading at 04:00.'}]",
|
||||
None,
|
||||
),
|
||||
],
|
||||
)
|
||||
def test_protection_manager_desc(
|
||||
|
||||
Reference in New Issue
Block a user