mirror of
https://github.com/freqtrade/freqtrade.git
synced 2024-11-14 20:23:57 +00:00
tests: move protection-validation test to protection test file
This commit is contained in:
parent
8736728478
commit
39c582dac2
|
@ -5,6 +5,7 @@ import pytest
|
||||||
|
|
||||||
from freqtrade import constants
|
from freqtrade import constants
|
||||||
from freqtrade.enums import ExitType
|
from freqtrade.enums import ExitType
|
||||||
|
from freqtrade.exceptions import OperationalException
|
||||||
from freqtrade.persistence import PairLocks, Trade
|
from freqtrade.persistence import PairLocks, Trade
|
||||||
from freqtrade.persistence.trade_model import Order
|
from freqtrade.persistence.trade_model import Order
|
||||||
from freqtrade.plugins.protectionmanager import ProtectionManager
|
from freqtrade.plugins.protectionmanager import ProtectionManager
|
||||||
|
@ -101,6 +102,63 @@ def test_protectionmanager(mocker, default_conf):
|
||||||
assert handler.stop_per_pair("XRP/BTC", datetime.now(timezone.utc), "*") is None
|
assert handler.stop_per_pair("XRP/BTC", datetime.now(timezone.utc), "*") is None
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize(
|
||||||
|
"protconf,expected",
|
||||||
|
[
|
||||||
|
([], None),
|
||||||
|
([{"method": "StoplossGuard", "lookback_period": 2000, "stop_duration_candles": 10}], None),
|
||||||
|
([{"method": "StoplossGuard", "lookback_period_candles": 20, "stop_duration": 10}], None),
|
||||||
|
(
|
||||||
|
[
|
||||||
|
{
|
||||||
|
"method": "StoplossGuard",
|
||||||
|
"lookback_period_candles": 20,
|
||||||
|
"lookback_period": 2000,
|
||||||
|
"stop_duration": 10,
|
||||||
|
}
|
||||||
|
],
|
||||||
|
r"Protections must specify either `lookback_period`.*",
|
||||||
|
),
|
||||||
|
(
|
||||||
|
[
|
||||||
|
{
|
||||||
|
"method": "StoplossGuard",
|
||||||
|
"lookback_period": 20,
|
||||||
|
"stop_duration": 10,
|
||||||
|
"stop_duration_candles": 10,
|
||||||
|
}
|
||||||
|
],
|
||||||
|
r"Protections must specify either `stop_duration`.*",
|
||||||
|
),
|
||||||
|
(
|
||||||
|
[
|
||||||
|
{
|
||||||
|
"method": "StoplossGuard",
|
||||||
|
"lookback_period": 20,
|
||||||
|
"stop_duration": 10,
|
||||||
|
"unlock_at": "20:02",
|
||||||
|
}
|
||||||
|
],
|
||||||
|
r"Protections must specify either `unlock_at`, `stop_duration` or.*",
|
||||||
|
),
|
||||||
|
(
|
||||||
|
[{"method": "StoplossGuard", "lookback_period_candles": 20, "unlock_at": "20:02"}],
|
||||||
|
None,
|
||||||
|
),
|
||||||
|
(
|
||||||
|
[{"method": "StoplossGuard", "lookback_period_candles": 20, "unlock_at": "55:102"}],
|
||||||
|
"Invalid date format for unlock_at: 55:102.",
|
||||||
|
),
|
||||||
|
],
|
||||||
|
)
|
||||||
|
def test_validate_protections(protconf, expected):
|
||||||
|
if expected:
|
||||||
|
with pytest.raises(OperationalException, match=expected):
|
||||||
|
ProtectionManager.validate_protections(protconf)
|
||||||
|
else:
|
||||||
|
ProtectionManager.validate_protections(protconf)
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
"timeframe,expected_lookback,expected_stop,protconf",
|
"timeframe,expected_lookback,expected_stop,protconf",
|
||||||
[
|
[
|
||||||
|
|
|
@ -812,65 +812,6 @@ def test_validate_whitelist(default_conf):
|
||||||
validate_config_consistency(conf)
|
validate_config_consistency(conf)
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize(
|
|
||||||
"protconf,expected",
|
|
||||||
[
|
|
||||||
([], None),
|
|
||||||
([{"method": "StoplossGuard", "lookback_period": 2000, "stop_duration_candles": 10}], None),
|
|
||||||
([{"method": "StoplossGuard", "lookback_period_candles": 20, "stop_duration": 10}], None),
|
|
||||||
(
|
|
||||||
[
|
|
||||||
{
|
|
||||||
"method": "StoplossGuard",
|
|
||||||
"lookback_period_candles": 20,
|
|
||||||
"lookback_period": 2000,
|
|
||||||
"stop_duration": 10,
|
|
||||||
}
|
|
||||||
],
|
|
||||||
r"Protections must specify either `lookback_period`.*",
|
|
||||||
),
|
|
||||||
(
|
|
||||||
[
|
|
||||||
{
|
|
||||||
"method": "StoplossGuard",
|
|
||||||
"lookback_period": 20,
|
|
||||||
"stop_duration": 10,
|
|
||||||
"stop_duration_candles": 10,
|
|
||||||
}
|
|
||||||
],
|
|
||||||
r"Protections must specify either `stop_duration`.*",
|
|
||||||
),
|
|
||||||
(
|
|
||||||
[
|
|
||||||
{
|
|
||||||
"method": "StoplossGuard",
|
|
||||||
"lookback_period": 20,
|
|
||||||
"stop_duration": 10,
|
|
||||||
"unlock_at": "20:02",
|
|
||||||
}
|
|
||||||
],
|
|
||||||
r"Protections must specify either `unlock_at`, `stop_duration` or.*",
|
|
||||||
),
|
|
||||||
(
|
|
||||||
[{"method": "StoplossGuard", "lookback_period_candles": 20, "unlock_at": "20:02"}],
|
|
||||||
None,
|
|
||||||
),
|
|
||||||
(
|
|
||||||
[{"method": "StoplossGuard", "lookback_period_candles": 20, "unlock_at": "55:102"}],
|
|
||||||
"Invalid date format for unlock_at: 55:102.",
|
|
||||||
),
|
|
||||||
],
|
|
||||||
)
|
|
||||||
def test_validate_protections(default_conf, protconf, expected):
|
|
||||||
conf = deepcopy(default_conf)
|
|
||||||
conf["protections"] = protconf
|
|
||||||
if expected:
|
|
||||||
with pytest.raises(OperationalException, match=expected):
|
|
||||||
validate_config_consistency(conf)
|
|
||||||
else:
|
|
||||||
validate_config_consistency(conf)
|
|
||||||
|
|
||||||
|
|
||||||
def test_validate_ask_orderbook(default_conf, caplog) -> None:
|
def test_validate_ask_orderbook(default_conf, caplog) -> None:
|
||||||
conf = deepcopy(default_conf)
|
conf = deepcopy(default_conf)
|
||||||
conf["exit_pricing"]["use_order_book"] = True
|
conf["exit_pricing"]["use_order_book"] = True
|
||||||
|
|
Loading…
Reference in New Issue
Block a user