Use Enum values within bot code
This commit is contained in:
parent
b90303c9a3
commit
2b3e7eeb21
@ -5,6 +5,7 @@ import logging
|
|||||||
import random
|
import random
|
||||||
from typing import Any, Dict, List
|
from typing import Any, Dict, List
|
||||||
|
|
||||||
|
from freqtrade.enums.runmode import RunMode
|
||||||
from freqtrade.plugins.pairlist.IPairList import IPairList
|
from freqtrade.plugins.pairlist.IPairList import IPairList
|
||||||
|
|
||||||
|
|
||||||
@ -20,12 +21,12 @@ class ShuffleFilter(IPairList):
|
|||||||
|
|
||||||
# Apply seed in backtesting mode to get comparable results,
|
# Apply seed in backtesting mode to get comparable results,
|
||||||
# but not in live modes to get a non-repeating order of pairs during live modes.
|
# but not in live modes to get a non-repeating order of pairs during live modes.
|
||||||
if config['runmode'].value in ('live', 'dry_run'):
|
if config.get('runmode') in (RunMode.LIVE, RunMode.DRY_RUN):
|
||||||
self._seed = None
|
self._seed = None
|
||||||
logger.info("live mode detected, not applying seed.")
|
logger.info("Live mode detected, not applying seed.")
|
||||||
else:
|
else:
|
||||||
self._seed = pairlistconfig.get('seed')
|
self._seed = pairlistconfig.get('seed')
|
||||||
logger.info("Backtesting mode detected, applying seed value: " + str(self._seed))
|
logger.info(f"Backtesting mode detected, applying seed value: {self._seed}")
|
||||||
|
|
||||||
# deprecated since 3.9
|
# deprecated since 3.9
|
||||||
#self._random = random.Random(self._seed)
|
#self._random = random.Random(self._seed)
|
||||||
|
@ -7,6 +7,7 @@ import pytest
|
|||||||
import time_machine
|
import time_machine
|
||||||
|
|
||||||
from freqtrade.constants import AVAILABLE_PAIRLISTS
|
from freqtrade.constants import AVAILABLE_PAIRLISTS
|
||||||
|
from freqtrade.enums.runmode import RunMode
|
||||||
from freqtrade.exceptions import OperationalException
|
from freqtrade.exceptions import OperationalException
|
||||||
from freqtrade.persistence import Trade
|
from freqtrade.persistence import Trade
|
||||||
from freqtrade.plugins.pairlist.pairlist_helpers import expand_pairlist
|
from freqtrade.plugins.pairlist.pairlist_helpers import expand_pairlist
|
||||||
@ -657,6 +658,22 @@ def test_PerformanceFilter_error(mocker, whitelist_conf, caplog) -> None:
|
|||||||
assert log_has("PerformanceFilter is not available in this mode.", caplog)
|
assert log_has("PerformanceFilter is not available in this mode.", caplog)
|
||||||
|
|
||||||
|
|
||||||
|
def test_ShuffleFilter_init(mocker, whitelist_conf, caplog) -> None:
|
||||||
|
whitelist_conf['pairlists'] = [
|
||||||
|
{"method": "StaticPairList"},
|
||||||
|
{"method": "ShuffleFilter", "seed": 42}
|
||||||
|
]
|
||||||
|
|
||||||
|
exchange = get_patched_exchange(mocker, whitelist_conf)
|
||||||
|
PairListManager(exchange, whitelist_conf)
|
||||||
|
assert log_has("Backtesting mode detected, applying seed value: 42", caplog)
|
||||||
|
caplog.clear()
|
||||||
|
whitelist_conf['runmode'] = RunMode.DRY_RUN
|
||||||
|
PairListManager(exchange, whitelist_conf)
|
||||||
|
assert not log_has("Backtesting mode detected, applying seed value: 42", caplog)
|
||||||
|
assert log_has("Live mode detected, not applying seed.", caplog)
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.usefixtures("init_persistence")
|
@pytest.mark.usefixtures("init_persistence")
|
||||||
def test_PerformanceFilter_lookback(mocker, whitelist_conf, fee, caplog) -> None:
|
def test_PerformanceFilter_lookback(mocker, whitelist_conf, fee, caplog) -> None:
|
||||||
whitelist_conf['exchange']['pair_whitelist'].append('XRP/BTC')
|
whitelist_conf['exchange']['pair_whitelist'].append('XRP/BTC')
|
||||||
|
Loading…
Reference in New Issue
Block a user