Merge branch 'feat/short' into pr/samgermain/5378
This commit is contained in:
@@ -5,5 +5,5 @@ import nonexiting_module # noqa
|
||||
from freqtrade.strategy.interface import IStrategy
|
||||
|
||||
|
||||
class TestStrategyLegacy(IStrategy):
|
||||
class TestStrategyLegacyV1(IStrategy):
|
||||
pass
|
||||
|
@@ -10,7 +10,7 @@ from freqtrade.strategy.interface import IStrategy
|
||||
# --------------------------------
|
||||
|
||||
# This class is a sample. Feel free to customize it.
|
||||
class TestStrategyLegacy(IStrategy):
|
||||
class TestStrategyLegacyV1(IStrategy):
|
||||
"""
|
||||
This is a test strategy using the legacy function headers, which will be
|
||||
removed in a future update.
|
@@ -7,9 +7,9 @@ import freqtrade.vendor.qtpylib.indicators as qtpylib
|
||||
from freqtrade.strategy.interface import IStrategy
|
||||
|
||||
|
||||
class DefaultStrategy(IStrategy):
|
||||
class StrategyTestV2(IStrategy):
|
||||
"""
|
||||
Default Strategy provided by freqtrade bot.
|
||||
Strategy used by tests freqtrade bot.
|
||||
Please do not modify this strategy, it's intended for internal use only.
|
||||
Please look at the SampleStrategy in the user_data/strategy directory
|
||||
or strategy repository https://github.com/freqtrade/freqtrade-strategies
|
@@ -4,20 +4,20 @@ from pandas import DataFrame
|
||||
|
||||
from freqtrade.persistence.models import Trade
|
||||
|
||||
from .strats.default_strategy import DefaultStrategy
|
||||
from .strats.strategy_test_v2 import StrategyTestV2
|
||||
|
||||
|
||||
def test_default_strategy_structure():
|
||||
assert hasattr(DefaultStrategy, 'minimal_roi')
|
||||
assert hasattr(DefaultStrategy, 'stoploss')
|
||||
assert hasattr(DefaultStrategy, 'timeframe')
|
||||
assert hasattr(DefaultStrategy, 'populate_indicators')
|
||||
assert hasattr(DefaultStrategy, 'populate_buy_trend')
|
||||
assert hasattr(DefaultStrategy, 'populate_sell_trend')
|
||||
def test_strategy_test_v2_structure():
|
||||
assert hasattr(StrategyTestV2, 'minimal_roi')
|
||||
assert hasattr(StrategyTestV2, 'stoploss')
|
||||
assert hasattr(StrategyTestV2, 'timeframe')
|
||||
assert hasattr(StrategyTestV2, 'populate_indicators')
|
||||
assert hasattr(StrategyTestV2, 'populate_buy_trend')
|
||||
assert hasattr(StrategyTestV2, 'populate_sell_trend')
|
||||
|
||||
|
||||
def test_default_strategy(result, fee):
|
||||
strategy = DefaultStrategy({})
|
||||
def test_strategy_test_v2(result, fee):
|
||||
strategy = StrategyTestV2({})
|
||||
|
||||
metadata = {'pair': 'ETH/BTC'}
|
||||
assert type(strategy.minimal_roi) is dict
|
||||
|
@@ -23,11 +23,11 @@ from freqtrade.strategy.interface import SellCheckTuple
|
||||
from freqtrade.strategy.strategy_wrapper import strategy_safe_wrapper
|
||||
from tests.conftest import log_has, log_has_re
|
||||
|
||||
from .strats.default_strategy import DefaultStrategy
|
||||
from .strats.strategy_test_v2 import StrategyTestV2
|
||||
|
||||
|
||||
# Avoid to reinit the same object again and again
|
||||
_STRATEGY = DefaultStrategy(config={})
|
||||
_STRATEGY = StrategyTestV2(config={})
|
||||
_STRATEGY.dp = DataProvider({}, None, None)
|
||||
|
||||
|
||||
@@ -149,7 +149,7 @@ def test_get_signal_no_sell_column(default_conf, mocker, caplog, ohlcv_history):
|
||||
|
||||
|
||||
def test_ignore_expired_candle(default_conf):
|
||||
default_conf.update({'strategy': 'DefaultStrategy'})
|
||||
default_conf.update({'strategy': 'StrategyTestV2'})
|
||||
strategy = StrategyResolver.load_strategy(default_conf)
|
||||
strategy.ignore_buying_expired_candle_after = 60
|
||||
|
||||
@@ -234,7 +234,7 @@ def test_assert_df(ohlcv_history, caplog):
|
||||
|
||||
|
||||
def test_advise_all_indicators(default_conf, testdatadir) -> None:
|
||||
default_conf.update({'strategy': 'DefaultStrategy'})
|
||||
default_conf.update({'strategy': 'StrategyTestV2'})
|
||||
strategy = StrategyResolver.load_strategy(default_conf)
|
||||
|
||||
timerange = TimeRange.parse_timerange('1510694220-1510700340')
|
||||
@@ -245,7 +245,7 @@ def test_advise_all_indicators(default_conf, testdatadir) -> None:
|
||||
|
||||
|
||||
def test_advise_all_indicators_copy(mocker, default_conf, testdatadir) -> None:
|
||||
default_conf.update({'strategy': 'DefaultStrategy'})
|
||||
default_conf.update({'strategy': 'StrategyTestV2'})
|
||||
strategy = StrategyResolver.load_strategy(default_conf)
|
||||
aimock = mocker.patch('freqtrade.strategy.interface.IStrategy.advise_indicators')
|
||||
timerange = TimeRange.parse_timerange('1510694220-1510700340')
|
||||
@@ -263,7 +263,7 @@ def test_min_roi_reached(default_conf, fee) -> None:
|
||||
min_roi_list = [{20: 0.05, 55: 0.01, 0: 0.1},
|
||||
{0: 0.1, 20: 0.05, 55: 0.01}]
|
||||
for roi in min_roi_list:
|
||||
default_conf.update({'strategy': 'DefaultStrategy'})
|
||||
default_conf.update({'strategy': 'StrategyTestV2'})
|
||||
strategy = StrategyResolver.load_strategy(default_conf)
|
||||
strategy.minimal_roi = roi
|
||||
trade = Trade(
|
||||
@@ -302,7 +302,7 @@ def test_min_roi_reached2(default_conf, fee) -> None:
|
||||
},
|
||||
]
|
||||
for roi in min_roi_list:
|
||||
default_conf.update({'strategy': 'DefaultStrategy'})
|
||||
default_conf.update({'strategy': 'StrategyTestV2'})
|
||||
strategy = StrategyResolver.load_strategy(default_conf)
|
||||
strategy.minimal_roi = roi
|
||||
trade = Trade(
|
||||
@@ -337,7 +337,7 @@ def test_min_roi_reached3(default_conf, fee) -> None:
|
||||
30: 0.05,
|
||||
55: 0.30,
|
||||
}
|
||||
default_conf.update({'strategy': 'DefaultStrategy'})
|
||||
default_conf.update({'strategy': 'StrategyTestV2'})
|
||||
strategy = StrategyResolver.load_strategy(default_conf)
|
||||
strategy.minimal_roi = min_roi
|
||||
trade = Trade(
|
||||
@@ -390,7 +390,7 @@ def test_min_roi_reached3(default_conf, fee) -> None:
|
||||
def test_stop_loss_reached(default_conf, fee, profit, adjusted, expected, trailing, custom,
|
||||
profit2, adjusted2, expected2, custom_stop) -> None:
|
||||
|
||||
default_conf.update({'strategy': 'DefaultStrategy'})
|
||||
default_conf.update({'strategy': 'StrategyTestV2'})
|
||||
|
||||
strategy = StrategyResolver.load_strategy(default_conf)
|
||||
trade = Trade(
|
||||
@@ -438,7 +438,7 @@ def test_stop_loss_reached(default_conf, fee, profit, adjusted, expected, traili
|
||||
|
||||
def test_custom_sell(default_conf, fee, caplog) -> None:
|
||||
|
||||
default_conf.update({'strategy': 'DefaultStrategy'})
|
||||
default_conf.update({'strategy': 'StrategyTestV2'})
|
||||
|
||||
strategy = StrategyResolver.load_strategy(default_conf)
|
||||
trade = Trade(
|
||||
@@ -500,7 +500,7 @@ def test_analyze_ticker_default(ohlcv_history, mocker, caplog) -> None:
|
||||
advise_sell=sell_mock,
|
||||
|
||||
)
|
||||
strategy = DefaultStrategy({})
|
||||
strategy = StrategyTestV2({})
|
||||
strategy.analyze_ticker(ohlcv_history, {'pair': 'ETH/BTC'})
|
||||
assert ind_mock.call_count == 1
|
||||
assert buy_mock.call_count == 1
|
||||
@@ -531,7 +531,7 @@ def test__analyze_ticker_internal_skip_analyze(ohlcv_history, mocker, caplog) ->
|
||||
advise_sell=sell_mock,
|
||||
|
||||
)
|
||||
strategy = DefaultStrategy({})
|
||||
strategy = StrategyTestV2({})
|
||||
strategy.dp = DataProvider({}, None, None)
|
||||
strategy.process_only_new_candles = True
|
||||
|
||||
@@ -563,7 +563,7 @@ def test__analyze_ticker_internal_skip_analyze(ohlcv_history, mocker, caplog) ->
|
||||
|
||||
@pytest.mark.usefixtures("init_persistence")
|
||||
def test_is_pair_locked(default_conf):
|
||||
default_conf.update({'strategy': 'DefaultStrategy'})
|
||||
default_conf.update({'strategy': 'StrategyTestV2'})
|
||||
PairLocks.timeframe = default_conf['timeframe']
|
||||
PairLocks.use_db = True
|
||||
strategy = StrategyResolver.load_strategy(default_conf)
|
||||
@@ -616,7 +616,7 @@ def test_is_pair_locked(default_conf):
|
||||
|
||||
|
||||
def test_is_informative_pairs_callback(default_conf):
|
||||
default_conf.update({'strategy': 'TestStrategyLegacy'})
|
||||
default_conf.update({'strategy': 'TestStrategyLegacyV1'})
|
||||
strategy = StrategyResolver.load_strategy(default_conf)
|
||||
# Should return empty
|
||||
# Uses fallback to base implementation
|
||||
|
@@ -18,7 +18,7 @@ def test_search_strategy():
|
||||
|
||||
s, _ = StrategyResolver._search_object(
|
||||
directory=default_location,
|
||||
object_name='DefaultStrategy',
|
||||
object_name='StrategyTestV2',
|
||||
add_source=True,
|
||||
)
|
||||
assert issubclass(s, IStrategy)
|
||||
@@ -74,10 +74,10 @@ def test_load_strategy_base64(result, caplog, default_conf):
|
||||
|
||||
|
||||
def test_load_strategy_invalid_directory(result, caplog, default_conf):
|
||||
default_conf['strategy'] = 'DefaultStrategy'
|
||||
default_conf['strategy'] = 'StrategyTestV2'
|
||||
extra_dir = Path.cwd() / 'some/path'
|
||||
with pytest.raises(OperationalException):
|
||||
StrategyResolver._load_strategy('DefaultStrategy', config=default_conf,
|
||||
StrategyResolver._load_strategy('StrategyTestV2', config=default_conf,
|
||||
extra_dir=extra_dir)
|
||||
|
||||
assert log_has_re(r'Path .*' + r'some.*path.*' + r'.* does not exist', caplog)
|
||||
@@ -100,7 +100,7 @@ def test_load_strategy_noname(default_conf):
|
||||
|
||||
|
||||
def test_strategy(result, default_conf):
|
||||
default_conf.update({'strategy': 'DefaultStrategy'})
|
||||
default_conf.update({'strategy': 'StrategyTestV2'})
|
||||
|
||||
strategy = StrategyResolver.load_strategy(default_conf)
|
||||
metadata = {'pair': 'ETH/BTC'}
|
||||
@@ -129,7 +129,7 @@ def test_strategy(result, default_conf):
|
||||
def test_strategy_override_minimal_roi(caplog, default_conf):
|
||||
caplog.set_level(logging.INFO)
|
||||
default_conf.update({
|
||||
'strategy': 'DefaultStrategy',
|
||||
'strategy': 'StrategyTestV2',
|
||||
'minimal_roi': {
|
||||
"20": 0.1,
|
||||
"0": 0.5
|
||||
@@ -146,7 +146,7 @@ def test_strategy_override_minimal_roi(caplog, default_conf):
|
||||
def test_strategy_override_stoploss(caplog, default_conf):
|
||||
caplog.set_level(logging.INFO)
|
||||
default_conf.update({
|
||||
'strategy': 'DefaultStrategy',
|
||||
'strategy': 'StrategyTestV2',
|
||||
'stoploss': -0.5
|
||||
})
|
||||
strategy = StrategyResolver.load_strategy(default_conf)
|
||||
@@ -158,7 +158,7 @@ def test_strategy_override_stoploss(caplog, default_conf):
|
||||
def test_strategy_override_trailing_stop(caplog, default_conf):
|
||||
caplog.set_level(logging.INFO)
|
||||
default_conf.update({
|
||||
'strategy': 'DefaultStrategy',
|
||||
'strategy': 'StrategyTestV2',
|
||||
'trailing_stop': True
|
||||
})
|
||||
strategy = StrategyResolver.load_strategy(default_conf)
|
||||
@@ -171,7 +171,7 @@ def test_strategy_override_trailing_stop(caplog, default_conf):
|
||||
def test_strategy_override_trailing_stop_positive(caplog, default_conf):
|
||||
caplog.set_level(logging.INFO)
|
||||
default_conf.update({
|
||||
'strategy': 'DefaultStrategy',
|
||||
'strategy': 'StrategyTestV2',
|
||||
'trailing_stop_positive': -0.1,
|
||||
'trailing_stop_positive_offset': -0.2
|
||||
|
||||
@@ -191,7 +191,7 @@ def test_strategy_override_timeframe(caplog, default_conf):
|
||||
caplog.set_level(logging.INFO)
|
||||
|
||||
default_conf.update({
|
||||
'strategy': 'DefaultStrategy',
|
||||
'strategy': 'StrategyTestV2',
|
||||
'timeframe': 60,
|
||||
'stake_currency': 'ETH'
|
||||
})
|
||||
@@ -207,7 +207,7 @@ def test_strategy_override_process_only_new_candles(caplog, default_conf):
|
||||
caplog.set_level(logging.INFO)
|
||||
|
||||
default_conf.update({
|
||||
'strategy': 'DefaultStrategy',
|
||||
'strategy': 'StrategyTestV2',
|
||||
'process_only_new_candles': True
|
||||
})
|
||||
strategy = StrategyResolver.load_strategy(default_conf)
|
||||
@@ -227,7 +227,7 @@ def test_strategy_override_order_types(caplog, default_conf):
|
||||
'stoploss_on_exchange': True,
|
||||
}
|
||||
default_conf.update({
|
||||
'strategy': 'DefaultStrategy',
|
||||
'strategy': 'StrategyTestV2',
|
||||
'order_types': order_types
|
||||
})
|
||||
strategy = StrategyResolver.load_strategy(default_conf)
|
||||
@@ -241,12 +241,12 @@ def test_strategy_override_order_types(caplog, default_conf):
|
||||
" 'stoploss_on_exchange': True}.", caplog)
|
||||
|
||||
default_conf.update({
|
||||
'strategy': 'DefaultStrategy',
|
||||
'strategy': 'StrategyTestV2',
|
||||
'order_types': {'buy': 'market'}
|
||||
})
|
||||
# Raise error for invalid configuration
|
||||
with pytest.raises(ImportError,
|
||||
match=r"Impossible to load Strategy 'DefaultStrategy'. "
|
||||
match=r"Impossible to load Strategy 'StrategyTestV2'. "
|
||||
r"Order-types mapping is incomplete."):
|
||||
StrategyResolver.load_strategy(default_conf)
|
||||
|
||||
@@ -260,7 +260,7 @@ def test_strategy_override_order_tif(caplog, default_conf):
|
||||
}
|
||||
|
||||
default_conf.update({
|
||||
'strategy': 'DefaultStrategy',
|
||||
'strategy': 'StrategyTestV2',
|
||||
'order_time_in_force': order_time_in_force
|
||||
})
|
||||
strategy = StrategyResolver.load_strategy(default_conf)
|
||||
@@ -273,12 +273,12 @@ def test_strategy_override_order_tif(caplog, default_conf):
|
||||
" {'buy': 'fok', 'sell': 'gtc'}.", caplog)
|
||||
|
||||
default_conf.update({
|
||||
'strategy': 'DefaultStrategy',
|
||||
'strategy': 'StrategyTestV2',
|
||||
'order_time_in_force': {'buy': 'fok'}
|
||||
})
|
||||
# Raise error for invalid configuration
|
||||
with pytest.raises(ImportError,
|
||||
match=r"Impossible to load Strategy 'DefaultStrategy'. "
|
||||
match=r"Impossible to load Strategy 'StrategyTestV2'. "
|
||||
r"Order-time-in-force mapping is incomplete."):
|
||||
StrategyResolver.load_strategy(default_conf)
|
||||
|
||||
@@ -286,7 +286,7 @@ def test_strategy_override_order_tif(caplog, default_conf):
|
||||
def test_strategy_override_use_sell_signal(caplog, default_conf):
|
||||
caplog.set_level(logging.INFO)
|
||||
default_conf.update({
|
||||
'strategy': 'DefaultStrategy',
|
||||
'strategy': 'StrategyTestV2',
|
||||
})
|
||||
strategy = StrategyResolver.load_strategy(default_conf)
|
||||
assert strategy.use_sell_signal
|
||||
@@ -296,7 +296,7 @@ def test_strategy_override_use_sell_signal(caplog, default_conf):
|
||||
assert default_conf['use_sell_signal']
|
||||
|
||||
default_conf.update({
|
||||
'strategy': 'DefaultStrategy',
|
||||
'strategy': 'StrategyTestV2',
|
||||
'use_sell_signal': False,
|
||||
})
|
||||
strategy = StrategyResolver.load_strategy(default_conf)
|
||||
@@ -309,7 +309,7 @@ def test_strategy_override_use_sell_signal(caplog, default_conf):
|
||||
def test_strategy_override_use_sell_profit_only(caplog, default_conf):
|
||||
caplog.set_level(logging.INFO)
|
||||
default_conf.update({
|
||||
'strategy': 'DefaultStrategy',
|
||||
'strategy': 'StrategyTestV2',
|
||||
})
|
||||
strategy = StrategyResolver.load_strategy(default_conf)
|
||||
assert not strategy.sell_profit_only
|
||||
@@ -319,7 +319,7 @@ def test_strategy_override_use_sell_profit_only(caplog, default_conf):
|
||||
assert not default_conf['sell_profit_only']
|
||||
|
||||
default_conf.update({
|
||||
'strategy': 'DefaultStrategy',
|
||||
'strategy': 'StrategyTestV2',
|
||||
'sell_profit_only': True,
|
||||
})
|
||||
strategy = StrategyResolver.load_strategy(default_conf)
|
||||
@@ -332,7 +332,7 @@ def test_strategy_override_use_sell_profit_only(caplog, default_conf):
|
||||
@pytest.mark.filterwarnings("ignore:deprecated")
|
||||
def test_deprecate_populate_indicators(result, default_conf):
|
||||
default_location = Path(__file__).parent / "strats"
|
||||
default_conf.update({'strategy': 'TestStrategyLegacy',
|
||||
default_conf.update({'strategy': 'TestStrategyLegacyV1',
|
||||
'strategy_path': default_location})
|
||||
strategy = StrategyResolver.load_strategy(default_conf)
|
||||
with warnings.catch_warnings(record=True) as w:
|
||||
@@ -367,7 +367,7 @@ def test_deprecate_populate_indicators(result, default_conf):
|
||||
def test_call_deprecated_function(result, monkeypatch, default_conf, caplog):
|
||||
default_location = Path(__file__).parent / "strats"
|
||||
del default_conf['timeframe']
|
||||
default_conf.update({'strategy': 'TestStrategyLegacy',
|
||||
default_conf.update({'strategy': 'TestStrategyLegacyV1',
|
||||
'strategy_path': default_location})
|
||||
strategy = StrategyResolver.load_strategy(default_conf)
|
||||
metadata = {'pair': 'ETH/BTC'}
|
||||
@@ -397,8 +397,7 @@ def test_call_deprecated_function(result, monkeypatch, default_conf, caplog):
|
||||
|
||||
|
||||
def test_strategy_interface_versioning(result, default_conf):
|
||||
# Tests interface compatibility with Interface version 2.
|
||||
default_conf.update({'strategy': 'DefaultStrategy'})
|
||||
default_conf.update({'strategy': 'StrategyTestV2'})
|
||||
strategy = StrategyResolver.load_strategy(default_conf)
|
||||
metadata = {'pair': 'ETH/BTC'}
|
||||
|
||||
|
Reference in New Issue
Block a user