Merge branch 'develop' into align_userdata
This commit is contained in:
@@ -49,12 +49,12 @@ def test_returns_latest_sell_signal(mocker, default_conf, ticker_history):
|
||||
def test_get_signal_empty(default_conf, mocker, caplog):
|
||||
assert (False, False) == _STRATEGY.get_signal('foo', default_conf['ticker_interval'],
|
||||
DataFrame())
|
||||
assert log_has('Empty ticker history for pair foo', caplog.record_tuples)
|
||||
assert log_has('Empty ticker history for pair foo', caplog)
|
||||
caplog.clear()
|
||||
|
||||
assert (False, False) == _STRATEGY.get_signal('bar', default_conf['ticker_interval'],
|
||||
[])
|
||||
assert log_has('Empty ticker history for pair bar', caplog.record_tuples)
|
||||
assert log_has('Empty ticker history for pair bar', caplog)
|
||||
|
||||
|
||||
def test_get_signal_exception_valueerror(default_conf, mocker, caplog, ticker_history):
|
||||
@@ -65,7 +65,7 @@ def test_get_signal_exception_valueerror(default_conf, mocker, caplog, ticker_hi
|
||||
)
|
||||
assert (False, False) == _STRATEGY.get_signal('foo', default_conf['ticker_interval'],
|
||||
ticker_history)
|
||||
assert log_has('Unable to analyze ticker for pair foo: xyz', caplog.record_tuples)
|
||||
assert log_has('Unable to analyze ticker for pair foo: xyz', caplog)
|
||||
|
||||
|
||||
def test_get_signal_empty_dataframe(default_conf, mocker, caplog, ticker_history):
|
||||
@@ -76,7 +76,7 @@ def test_get_signal_empty_dataframe(default_conf, mocker, caplog, ticker_history
|
||||
)
|
||||
assert (False, False) == _STRATEGY.get_signal('xyz', default_conf['ticker_interval'],
|
||||
ticker_history)
|
||||
assert log_has('Empty dataframe for pair xyz', caplog.record_tuples)
|
||||
assert log_has('Empty dataframe for pair xyz', caplog)
|
||||
|
||||
|
||||
def test_get_signal_old_dataframe(default_conf, mocker, caplog, ticker_history):
|
||||
@@ -91,10 +91,7 @@ def test_get_signal_old_dataframe(default_conf, mocker, caplog, ticker_history):
|
||||
)
|
||||
assert (False, False) == _STRATEGY.get_signal('xyz', default_conf['ticker_interval'],
|
||||
ticker_history)
|
||||
assert log_has(
|
||||
'Outdated history for pair xyz. Last tick is 16 minutes old',
|
||||
caplog.record_tuples
|
||||
)
|
||||
assert log_has('Outdated history for pair xyz. Last tick is 16 minutes old', caplog)
|
||||
|
||||
|
||||
def test_get_signal_handles_exceptions(mocker, default_conf):
|
||||
@@ -237,9 +234,8 @@ def test_analyze_ticker_default(ticker_history, mocker, caplog) -> None:
|
||||
assert buy_mock.call_count == 1
|
||||
assert buy_mock.call_count == 1
|
||||
|
||||
assert log_has('TA Analysis Launched', caplog.record_tuples)
|
||||
assert not log_has('Skipping TA Analysis for already analyzed candle',
|
||||
caplog.record_tuples)
|
||||
assert log_has('TA Analysis Launched', caplog)
|
||||
assert not log_has('Skipping TA Analysis for already analyzed candle', caplog)
|
||||
caplog.clear()
|
||||
|
||||
strategy.analyze_ticker(ticker_history, {'pair': 'ETH/BTC'})
|
||||
@@ -247,9 +243,8 @@ def test_analyze_ticker_default(ticker_history, mocker, caplog) -> None:
|
||||
assert ind_mock.call_count == 2
|
||||
assert buy_mock.call_count == 2
|
||||
assert buy_mock.call_count == 2
|
||||
assert log_has('TA Analysis Launched', caplog.record_tuples)
|
||||
assert not log_has('Skipping TA Analysis for already analyzed candle',
|
||||
caplog.record_tuples)
|
||||
assert log_has('TA Analysis Launched', caplog)
|
||||
assert not log_has('Skipping TA Analysis for already analyzed candle', caplog)
|
||||
|
||||
|
||||
def test__analyze_ticker_internal_skip_analyze(ticker_history, mocker, caplog) -> None:
|
||||
@@ -275,9 +270,8 @@ def test__analyze_ticker_internal_skip_analyze(ticker_history, mocker, caplog) -
|
||||
assert ind_mock.call_count == 1
|
||||
assert buy_mock.call_count == 1
|
||||
assert buy_mock.call_count == 1
|
||||
assert log_has('TA Analysis Launched', caplog.record_tuples)
|
||||
assert not log_has('Skipping TA Analysis for already analyzed candle',
|
||||
caplog.record_tuples)
|
||||
assert log_has('TA Analysis Launched', caplog)
|
||||
assert not log_has('Skipping TA Analysis for already analyzed candle', caplog)
|
||||
caplog.clear()
|
||||
|
||||
ret = strategy._analyze_ticker_internal(ticker_history, {'pair': 'ETH/BTC'})
|
||||
@@ -290,6 +284,21 @@ def test__analyze_ticker_internal_skip_analyze(ticker_history, mocker, caplog) -
|
||||
assert 'sell' in ret.columns
|
||||
assert ret['buy'].sum() == 0
|
||||
assert ret['sell'].sum() == 0
|
||||
assert not log_has('TA Analysis Launched', caplog.record_tuples)
|
||||
assert log_has('Skipping TA Analysis for already analyzed candle',
|
||||
caplog.record_tuples)
|
||||
assert not log_has('TA Analysis Launched', caplog)
|
||||
assert log_has('Skipping TA Analysis for already analyzed candle', caplog)
|
||||
|
||||
|
||||
def test_is_pair_locked(default_conf):
|
||||
strategy = DefaultStrategy(default_conf)
|
||||
# dict should be empty
|
||||
assert not strategy._pair_locked_until
|
||||
|
||||
pair = 'ETH/BTC'
|
||||
assert not strategy.is_pair_locked(pair)
|
||||
strategy.lock_pair(pair, arrow.utcnow().shift(minutes=4).datetime)
|
||||
# ETH/BTC locked for 4 minutes
|
||||
assert strategy.is_pair_locked(pair)
|
||||
|
||||
# XRP/BTC should not be locked now
|
||||
pair = 'XRP/BTC'
|
||||
assert not strategy.is_pair_locked(pair)
|
||||
|
@@ -15,7 +15,7 @@ from freqtrade.resolvers import StrategyResolver
|
||||
from freqtrade.strategy import import_strategy
|
||||
from freqtrade.strategy.default_strategy import DefaultStrategy
|
||||
from freqtrade.strategy.interface import IStrategy
|
||||
from freqtrade.tests.conftest import log_has_re
|
||||
from freqtrade.tests.conftest import log_has, log_has_re
|
||||
|
||||
|
||||
def test_import_strategy(caplog):
|
||||
@@ -35,12 +35,8 @@ def test_import_strategy(caplog):
|
||||
assert imported_strategy.__module__ == 'freqtrade.strategy'
|
||||
assert imported_strategy.some_method() == 42
|
||||
|
||||
assert (
|
||||
'freqtrade.strategy',
|
||||
logging.DEBUG,
|
||||
'Imported strategy freqtrade.strategy.default_strategy.DefaultStrategy '
|
||||
'as freqtrade.strategy.DefaultStrategy',
|
||||
) in caplog.record_tuples
|
||||
assert log_has('Imported strategy freqtrade.strategy.default_strategy.DefaultStrategy '
|
||||
'as freqtrade.strategy.DefaultStrategy', caplog)
|
||||
|
||||
|
||||
def test_search_strategy():
|
||||
@@ -79,8 +75,7 @@ def test_load_strategy_base64(result, caplog, default_conf):
|
||||
assert 'adx' in resolver.strategy.advise_indicators(result, {'pair': 'ETH/BTC'})
|
||||
# Make sure strategy was loaded from base64 (using temp directory)!!
|
||||
assert log_has_re(r"Using resolved strategy TestStrategy from '"
|
||||
+ tempfile.gettempdir() + r"/.*/TestStrategy\.py'\.\.\.",
|
||||
caplog.record_tuples)
|
||||
+ tempfile.gettempdir() + r"/.*/TestStrategy\.py'\.\.\.", caplog)
|
||||
|
||||
|
||||
def test_load_strategy_invalid_directory(result, caplog, default_conf):
|
||||
@@ -88,7 +83,7 @@ def test_load_strategy_invalid_directory(result, caplog, default_conf):
|
||||
extra_dir = Path.cwd() / 'some/path'
|
||||
resolver._load_strategy('TestStrategy', config=default_conf, extra_dir=extra_dir)
|
||||
|
||||
assert log_has_re(r'Path .*' + r'some.*path.*' + r'.* does not exist', caplog.record_tuples)
|
||||
assert log_has_re(r'Path .*' + r'some.*path.*' + r'.* does not exist', caplog)
|
||||
|
||||
assert 'adx' in resolver.strategy.advise_indicators(result, {'pair': 'ETH/BTC'})
|
||||
|
||||
@@ -108,7 +103,7 @@ def test_load_staticmethod_importerror(mocker, caplog, default_conf):
|
||||
match=r"Impossible to load Strategy 'DefaultStrategy'. "
|
||||
r"This class does not exist or contains Python code errors."):
|
||||
StrategyResolver(default_conf)
|
||||
assert log_has_re(r".*Error: can't pickle staticmethod objects", caplog.record_tuples)
|
||||
assert log_has_re(r".*Error: can't pickle staticmethod objects", caplog)
|
||||
|
||||
|
||||
def test_strategy(result, default_conf):
|
||||
@@ -146,10 +141,7 @@ def test_strategy_override_minimal_roi(caplog, default_conf):
|
||||
resolver = StrategyResolver(default_conf)
|
||||
|
||||
assert resolver.strategy.minimal_roi[0] == 0.5
|
||||
assert ('freqtrade.resolvers.strategy_resolver',
|
||||
logging.INFO,
|
||||
"Override strategy 'minimal_roi' with value in config file: {'0': 0.5}."
|
||||
) in caplog.record_tuples
|
||||
assert log_has("Override strategy 'minimal_roi' with value in config file: {'0': 0.5}.", caplog)
|
||||
|
||||
|
||||
def test_strategy_override_stoploss(caplog, default_conf):
|
||||
@@ -161,10 +153,7 @@ def test_strategy_override_stoploss(caplog, default_conf):
|
||||
resolver = StrategyResolver(default_conf)
|
||||
|
||||
assert resolver.strategy.stoploss == -0.5
|
||||
assert ('freqtrade.resolvers.strategy_resolver',
|
||||
logging.INFO,
|
||||
"Override strategy 'stoploss' with value in config file: -0.5."
|
||||
) in caplog.record_tuples
|
||||
assert log_has("Override strategy 'stoploss' with value in config file: -0.5.", caplog)
|
||||
|
||||
|
||||
def test_strategy_override_trailing_stop(caplog, default_conf):
|
||||
@@ -177,10 +166,7 @@ def test_strategy_override_trailing_stop(caplog, default_conf):
|
||||
|
||||
assert resolver.strategy.trailing_stop
|
||||
assert isinstance(resolver.strategy.trailing_stop, bool)
|
||||
assert ('freqtrade.resolvers.strategy_resolver',
|
||||
logging.INFO,
|
||||
"Override strategy 'trailing_stop' with value in config file: True."
|
||||
) in caplog.record_tuples
|
||||
assert log_has("Override strategy 'trailing_stop' with value in config file: True.", caplog)
|
||||
|
||||
|
||||
def test_strategy_override_trailing_stop_positive(caplog, default_conf):
|
||||
@@ -194,16 +180,12 @@ def test_strategy_override_trailing_stop_positive(caplog, default_conf):
|
||||
resolver = StrategyResolver(default_conf)
|
||||
|
||||
assert resolver.strategy.trailing_stop_positive == -0.1
|
||||
assert ('freqtrade.resolvers.strategy_resolver',
|
||||
logging.INFO,
|
||||
"Override strategy 'trailing_stop_positive' with value in config file: -0.1."
|
||||
) in caplog.record_tuples
|
||||
assert log_has("Override strategy 'trailing_stop_positive' with value in config file: -0.1.",
|
||||
caplog)
|
||||
|
||||
assert resolver.strategy.trailing_stop_positive_offset == -0.2
|
||||
assert ('freqtrade.resolvers.strategy_resolver',
|
||||
logging.INFO,
|
||||
"Override strategy 'trailing_stop_positive' with value in config file: -0.1."
|
||||
) in caplog.record_tuples
|
||||
assert log_has("Override strategy 'trailing_stop_positive' with value in config file: -0.1.",
|
||||
caplog)
|
||||
|
||||
|
||||
def test_strategy_override_ticker_interval(caplog, default_conf):
|
||||
@@ -218,10 +200,8 @@ def test_strategy_override_ticker_interval(caplog, default_conf):
|
||||
|
||||
assert resolver.strategy.ticker_interval == 60
|
||||
assert resolver.strategy.stake_currency == 'ETH'
|
||||
assert ('freqtrade.resolvers.strategy_resolver',
|
||||
logging.INFO,
|
||||
"Override strategy 'ticker_interval' with value in config file: 60."
|
||||
) in caplog.record_tuples
|
||||
assert log_has("Override strategy 'ticker_interval' with value in config file: 60.",
|
||||
caplog)
|
||||
|
||||
|
||||
def test_strategy_override_process_only_new_candles(caplog, default_conf):
|
||||
@@ -234,10 +214,8 @@ def test_strategy_override_process_only_new_candles(caplog, default_conf):
|
||||
resolver = StrategyResolver(default_conf)
|
||||
|
||||
assert resolver.strategy.process_only_new_candles
|
||||
assert ('freqtrade.resolvers.strategy_resolver',
|
||||
logging.INFO,
|
||||
"Override strategy 'process_only_new_candles' with value in config file: True."
|
||||
) in caplog.record_tuples
|
||||
assert log_has("Override strategy 'process_only_new_candles' with value in config file: True.",
|
||||
caplog)
|
||||
|
||||
|
||||
def test_strategy_override_order_types(caplog, default_conf):
|
||||
@@ -259,12 +237,9 @@ def test_strategy_override_order_types(caplog, default_conf):
|
||||
for method in ['buy', 'sell', 'stoploss', 'stoploss_on_exchange']:
|
||||
assert resolver.strategy.order_types[method] == order_types[method]
|
||||
|
||||
assert ('freqtrade.resolvers.strategy_resolver',
|
||||
logging.INFO,
|
||||
"Override strategy 'order_types' with value in config file:"
|
||||
" {'buy': 'market', 'sell': 'limit', 'stoploss': 'limit',"
|
||||
" 'stoploss_on_exchange': True}."
|
||||
) in caplog.record_tuples
|
||||
assert log_has("Override strategy 'order_types' with value in config file:"
|
||||
" {'buy': 'market', 'sell': 'limit', 'stoploss': 'limit',"
|
||||
" 'stoploss_on_exchange': True}.", caplog)
|
||||
|
||||
default_conf.update({
|
||||
'strategy': 'DefaultStrategy',
|
||||
@@ -295,11 +270,8 @@ def test_strategy_override_order_tif(caplog, default_conf):
|
||||
for method in ['buy', 'sell']:
|
||||
assert resolver.strategy.order_time_in_force[method] == order_time_in_force[method]
|
||||
|
||||
assert ('freqtrade.resolvers.strategy_resolver',
|
||||
logging.INFO,
|
||||
"Override strategy 'order_time_in_force' with value in config file:"
|
||||
" {'buy': 'fok', 'sell': 'gtc'}."
|
||||
) in caplog.record_tuples
|
||||
assert log_has("Override strategy 'order_time_in_force' with value in config file:"
|
||||
" {'buy': 'fok', 'sell': 'gtc'}.", caplog)
|
||||
|
||||
default_conf.update({
|
||||
'strategy': 'DefaultStrategy',
|
||||
@@ -334,10 +306,7 @@ def test_strategy_override_use_sell_signal(caplog, default_conf):
|
||||
|
||||
assert resolver.strategy.use_sell_signal
|
||||
assert isinstance(resolver.strategy.use_sell_signal, bool)
|
||||
assert ('freqtrade.resolvers.strategy_resolver',
|
||||
logging.INFO,
|
||||
"Override strategy 'use_sell_signal' with value in config file: True."
|
||||
) in caplog.record_tuples
|
||||
assert log_has("Override strategy 'use_sell_signal' with value in config file: True.", caplog)
|
||||
|
||||
|
||||
def test_strategy_override_use_sell_profit_only(caplog, default_conf):
|
||||
@@ -362,10 +331,7 @@ def test_strategy_override_use_sell_profit_only(caplog, default_conf):
|
||||
|
||||
assert resolver.strategy.sell_profit_only
|
||||
assert isinstance(resolver.strategy.sell_profit_only, bool)
|
||||
assert ('freqtrade.resolvers.strategy_resolver',
|
||||
logging.INFO,
|
||||
"Override strategy 'sell_profit_only' with value in config file: True."
|
||||
) in caplog.record_tuples
|
||||
assert log_has("Override strategy 'sell_profit_only' with value in config file: True.", caplog)
|
||||
|
||||
|
||||
@pytest.mark.filterwarnings("ignore:deprecated")
|
||||
|
Reference in New Issue
Block a user