2018-01-28 07:38:41 +00:00
|
|
|
# pragma pylint: disable=missing-docstring, protected-access, C0103
|
2018-01-15 08:35:11 +00:00
|
|
|
import logging
|
2019-07-21 13:16:19 +00:00
|
|
|
import tempfile
|
2019-04-16 18:25:48 +00:00
|
|
|
import warnings
|
2018-07-05 21:30:24 +00:00
|
|
|
from base64 import urlsafe_b64encode
|
2018-07-18 21:23:30 +00:00
|
|
|
from os import path
|
2018-11-24 19:39:16 +00:00
|
|
|
from pathlib import Path
|
2019-04-16 18:25:48 +00:00
|
|
|
from unittest.mock import Mock
|
2018-03-24 20:56:20 +00:00
|
|
|
|
2018-03-25 14:28:04 +00:00
|
|
|
import pytest
|
2018-07-22 15:39:35 +00:00
|
|
|
from pandas import DataFrame
|
2018-03-25 14:28:04 +00:00
|
|
|
|
2019-07-12 20:45:49 +00:00
|
|
|
from freqtrade import OperationalException
|
2019-04-16 18:25:48 +00:00
|
|
|
from freqtrade.resolvers import StrategyResolver
|
2018-06-23 09:14:31 +00:00
|
|
|
from freqtrade.strategy import import_strategy
|
|
|
|
from freqtrade.strategy.default_strategy import DefaultStrategy
|
2018-03-24 20:56:20 +00:00
|
|
|
from freqtrade.strategy.interface import IStrategy
|
2019-04-16 18:25:48 +00:00
|
|
|
from freqtrade.tests.conftest import log_has_re
|
2018-01-15 08:35:11 +00:00
|
|
|
|
|
|
|
|
2018-06-23 09:14:31 +00:00
|
|
|
def test_import_strategy(caplog):
|
|
|
|
caplog.set_level(logging.DEBUG)
|
2018-07-16 05:11:17 +00:00
|
|
|
default_config = {}
|
2018-06-23 09:14:31 +00:00
|
|
|
|
2018-07-16 05:11:17 +00:00
|
|
|
strategy = DefaultStrategy(default_config)
|
2018-06-23 09:14:31 +00:00
|
|
|
strategy.some_method = lambda *args, **kwargs: 42
|
|
|
|
|
|
|
|
assert strategy.__module__ == 'freqtrade.strategy.default_strategy'
|
|
|
|
assert strategy.some_method() == 42
|
|
|
|
|
2018-07-16 05:11:17 +00:00
|
|
|
imported_strategy = import_strategy(strategy, default_config)
|
2018-06-23 09:14:31 +00:00
|
|
|
|
2018-06-23 09:57:26 +00:00
|
|
|
assert dir(strategy) == dir(imported_strategy)
|
|
|
|
|
2018-06-23 09:14:31 +00:00
|
|
|
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
|
|
|
|
|
|
|
|
|
2018-01-15 08:35:11 +00:00
|
|
|
def test_search_strategy():
|
2018-07-20 19:48:59 +00:00
|
|
|
default_config = {}
|
2018-11-24 19:39:16 +00:00
|
|
|
default_location = Path(__file__).parent.parent.joinpath('strategy').resolve()
|
2019-07-12 20:45:49 +00:00
|
|
|
|
|
|
|
s, _ = StrategyResolver._search_object(
|
|
|
|
directory=default_location,
|
|
|
|
object_type=IStrategy,
|
|
|
|
kwargs={'config': default_config},
|
|
|
|
object_name='DefaultStrategy'
|
2018-03-24 21:16:42 +00:00
|
|
|
)
|
2019-07-12 20:45:49 +00:00
|
|
|
assert isinstance(s, IStrategy)
|
|
|
|
|
|
|
|
s, _ = StrategyResolver._search_object(
|
2018-11-24 19:00:02 +00:00
|
|
|
directory=default_location,
|
|
|
|
object_type=IStrategy,
|
|
|
|
kwargs={'config': default_config},
|
|
|
|
object_name='NotFoundStrategy'
|
2019-07-12 20:45:49 +00:00
|
|
|
)
|
|
|
|
assert s is None
|
2018-01-15 08:35:11 +00:00
|
|
|
|
|
|
|
|
|
|
|
def test_load_strategy(result):
|
2018-06-23 09:14:31 +00:00
|
|
|
resolver = StrategyResolver({'strategy': 'TestStrategy'})
|
2019-06-11 07:58:19 +00:00
|
|
|
assert 'adx' in resolver.strategy.advise_indicators(result, {'pair': 'ETH/BTC'})
|
2018-01-15 08:35:11 +00:00
|
|
|
|
|
|
|
|
2019-07-21 13:16:19 +00:00
|
|
|
def test_load_strategy_base64(result, caplog):
|
|
|
|
with open("user_data/strategies/test_strategy.py", "rb") as file:
|
2019-07-14 18:05:28 +00:00
|
|
|
encoded_string = urlsafe_b64encode(file.read()).decode("utf-8")
|
2018-08-01 05:28:12 +00:00
|
|
|
resolver = StrategyResolver({'strategy': 'TestStrategy:{}'.format(encoded_string)})
|
2019-06-11 07:58:19 +00:00
|
|
|
assert 'adx' in resolver.strategy.advise_indicators(result, {'pair': 'ETH/BTC'})
|
2019-07-21 13:16:19 +00:00
|
|
|
# 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)
|
2018-07-05 21:30:24 +00:00
|
|
|
|
|
|
|
|
2018-06-23 12:42:22 +00:00
|
|
|
def test_load_strategy_invalid_directory(result, caplog):
|
2018-03-25 14:28:04 +00:00
|
|
|
resolver = StrategyResolver()
|
2019-06-17 12:34:45 +00:00
|
|
|
extra_dir = Path.cwd() / 'some/path'
|
2018-07-20 19:48:59 +00:00
|
|
|
resolver._load_strategy('TestStrategy', config={}, extra_dir=extra_dir)
|
2018-06-23 12:42:22 +00:00
|
|
|
|
2019-06-17 12:34:45 +00:00
|
|
|
assert log_has_re(r'Path .*' + r'some.*path.*' + r'.* does not exist', caplog.record_tuples)
|
2018-03-25 14:28:04 +00:00
|
|
|
|
2018-07-29 19:07:21 +00:00
|
|
|
assert 'adx' in resolver.strategy.advise_indicators(result, {'pair': 'ETH/BTC'})
|
2018-03-25 14:28:04 +00:00
|
|
|
|
|
|
|
|
|
|
|
def test_load_not_found_strategy():
|
|
|
|
strategy = StrategyResolver()
|
2019-07-12 20:45:49 +00:00
|
|
|
with pytest.raises(OperationalException,
|
|
|
|
match=r"Impossible to load Strategy 'NotFoundStrategy'. "
|
|
|
|
r"This class does not exist or contains Python code errors."):
|
2018-07-16 05:11:17 +00:00
|
|
|
strategy._load_strategy(strategy_name='NotFoundStrategy', config={})
|
2018-02-02 09:01:09 +00:00
|
|
|
|
|
|
|
|
2019-04-16 18:25:48 +00:00
|
|
|
def test_load_staticmethod_importerror(mocker, caplog):
|
|
|
|
mocker.patch("freqtrade.resolvers.strategy_resolver.import_strategy", Mock(
|
|
|
|
side_effect=TypeError("can't pickle staticmethod objects")))
|
2019-07-12 20:45:49 +00:00
|
|
|
with pytest.raises(OperationalException,
|
|
|
|
match=r"Impossible to load Strategy 'DefaultStrategy'. "
|
|
|
|
r"This class does not exist or contains Python code errors."):
|
2019-04-16 18:25:48 +00:00
|
|
|
StrategyResolver()
|
|
|
|
assert log_has_re(r".*Error: can't pickle staticmethod objects", caplog.record_tuples)
|
|
|
|
|
|
|
|
|
2018-01-15 08:35:11 +00:00
|
|
|
def test_strategy(result):
|
2018-07-15 07:01:08 +00:00
|
|
|
config = {'strategy': 'DefaultStrategy'}
|
2018-01-15 08:35:11 +00:00
|
|
|
|
2018-07-15 07:01:08 +00:00
|
|
|
resolver = StrategyResolver(config)
|
2018-07-29 18:36:03 +00:00
|
|
|
metadata = {'pair': 'ETH/BTC'}
|
2018-03-24 22:20:21 +00:00
|
|
|
assert resolver.strategy.minimal_roi[0] == 0.04
|
2018-07-15 07:08:14 +00:00
|
|
|
assert config["minimal_roi"]['0'] == 0.04
|
2018-01-15 08:35:11 +00:00
|
|
|
|
2018-03-24 22:20:21 +00:00
|
|
|
assert resolver.strategy.stoploss == -0.10
|
2018-07-15 07:01:08 +00:00
|
|
|
assert config['stoploss'] == -0.10
|
|
|
|
|
|
|
|
assert resolver.strategy.ticker_interval == '5m'
|
|
|
|
assert config['ticker_interval'] == '5m'
|
2018-01-15 08:35:11 +00:00
|
|
|
|
2018-07-29 18:36:03 +00:00
|
|
|
df_indicators = resolver.strategy.advise_indicators(result, metadata=metadata)
|
2018-07-18 20:04:34 +00:00
|
|
|
assert 'adx' in df_indicators
|
2018-01-15 08:35:11 +00:00
|
|
|
|
2018-07-29 18:36:03 +00:00
|
|
|
dataframe = resolver.strategy.advise_buy(df_indicators, metadata=metadata)
|
2018-01-15 08:35:11 +00:00
|
|
|
assert 'buy' in dataframe.columns
|
|
|
|
|
2018-07-29 18:36:03 +00:00
|
|
|
dataframe = resolver.strategy.advise_sell(df_indicators, metadata=metadata)
|
2018-01-15 08:35:11 +00:00
|
|
|
assert 'sell' in dataframe.columns
|
|
|
|
|
|
|
|
|
|
|
|
def test_strategy_override_minimal_roi(caplog):
|
2018-01-31 17:37:38 +00:00
|
|
|
caplog.set_level(logging.INFO)
|
2018-01-15 08:35:11 +00:00
|
|
|
config = {
|
2018-03-24 19:44:04 +00:00
|
|
|
'strategy': 'DefaultStrategy',
|
2018-01-15 08:35:11 +00:00
|
|
|
'minimal_roi': {
|
|
|
|
"0": 0.5
|
|
|
|
}
|
|
|
|
}
|
2018-03-24 22:20:21 +00:00
|
|
|
resolver = StrategyResolver(config)
|
2018-01-15 08:35:11 +00:00
|
|
|
|
2018-03-24 22:20:21 +00:00
|
|
|
assert resolver.strategy.minimal_roi[0] == 0.5
|
2018-11-24 19:14:08 +00:00
|
|
|
assert ('freqtrade.resolvers.strategy_resolver',
|
2018-01-15 08:35:11 +00:00
|
|
|
logging.INFO,
|
2018-08-16 09:35:01 +00:00
|
|
|
"Override strategy 'minimal_roi' with value in config file: {'0': 0.5}."
|
2018-01-15 08:35:11 +00:00
|
|
|
) in caplog.record_tuples
|
|
|
|
|
|
|
|
|
|
|
|
def test_strategy_override_stoploss(caplog):
|
2018-01-31 17:37:38 +00:00
|
|
|
caplog.set_level(logging.INFO)
|
2018-01-15 08:35:11 +00:00
|
|
|
config = {
|
2018-03-24 19:44:04 +00:00
|
|
|
'strategy': 'DefaultStrategy',
|
2018-01-15 08:35:11 +00:00
|
|
|
'stoploss': -0.5
|
|
|
|
}
|
2018-03-24 22:20:21 +00:00
|
|
|
resolver = StrategyResolver(config)
|
2018-01-15 08:35:11 +00:00
|
|
|
|
2018-03-24 22:20:21 +00:00
|
|
|
assert resolver.strategy.stoploss == -0.5
|
2018-11-24 19:14:08 +00:00
|
|
|
assert ('freqtrade.resolvers.strategy_resolver',
|
2018-01-15 08:35:11 +00:00
|
|
|
logging.INFO,
|
2018-08-09 18:12:45 +00:00
|
|
|
"Override strategy 'stoploss' with value in config file: -0.5."
|
2018-01-20 22:40:41 +00:00
|
|
|
) in caplog.record_tuples
|
|
|
|
|
|
|
|
|
2019-01-05 06:10:25 +00:00
|
|
|
def test_strategy_override_trailing_stop(caplog):
|
|
|
|
caplog.set_level(logging.INFO)
|
|
|
|
config = {
|
|
|
|
'strategy': 'DefaultStrategy',
|
|
|
|
'trailing_stop': True
|
|
|
|
}
|
|
|
|
resolver = StrategyResolver(config)
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
|
|
|
|
def test_strategy_override_trailing_stop_positive(caplog):
|
|
|
|
caplog.set_level(logging.INFO)
|
|
|
|
config = {
|
|
|
|
'strategy': 'DefaultStrategy',
|
|
|
|
'trailing_stop_positive': -0.1,
|
|
|
|
'trailing_stop_positive_offset': -0.2
|
|
|
|
|
|
|
|
}
|
|
|
|
resolver = StrategyResolver(config)
|
|
|
|
|
|
|
|
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 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
|
|
|
|
|
|
|
|
|
2018-01-20 22:40:41 +00:00
|
|
|
def test_strategy_override_ticker_interval(caplog):
|
2018-01-31 17:37:38 +00:00
|
|
|
caplog.set_level(logging.INFO)
|
|
|
|
|
2018-01-20 22:40:41 +00:00
|
|
|
config = {
|
2018-03-24 19:44:04 +00:00
|
|
|
'strategy': 'DefaultStrategy',
|
2019-03-23 19:40:07 +00:00
|
|
|
'ticker_interval': 60,
|
|
|
|
'stake_currency': 'ETH'
|
2018-01-20 22:40:41 +00:00
|
|
|
}
|
2018-03-24 22:20:21 +00:00
|
|
|
resolver = StrategyResolver(config)
|
2018-01-20 22:40:41 +00:00
|
|
|
|
2018-03-24 22:20:21 +00:00
|
|
|
assert resolver.strategy.ticker_interval == 60
|
2019-03-23 19:40:07 +00:00
|
|
|
assert resolver.strategy.stake_currency == 'ETH'
|
2018-11-24 19:14:08 +00:00
|
|
|
assert ('freqtrade.resolvers.strategy_resolver',
|
2018-01-20 22:40:41 +00:00
|
|
|
logging.INFO,
|
2018-08-09 18:12:45 +00:00
|
|
|
"Override strategy 'ticker_interval' with value in config file: 60."
|
2018-01-15 08:35:11 +00:00
|
|
|
) in caplog.record_tuples
|
2018-07-18 19:45:04 +00:00
|
|
|
|
|
|
|
|
2018-09-01 17:52:40 +00:00
|
|
|
def test_strategy_override_process_only_new_candles(caplog):
|
2018-08-09 18:12:45 +00:00
|
|
|
caplog.set_level(logging.INFO)
|
|
|
|
|
|
|
|
config = {
|
|
|
|
'strategy': 'DefaultStrategy',
|
2018-09-01 17:52:40 +00:00
|
|
|
'process_only_new_candles': True
|
2018-08-09 18:12:45 +00:00
|
|
|
}
|
|
|
|
resolver = StrategyResolver(config)
|
|
|
|
|
2018-09-01 17:52:40 +00:00
|
|
|
assert resolver.strategy.process_only_new_candles
|
2018-11-24 19:14:08 +00:00
|
|
|
assert ('freqtrade.resolvers.strategy_resolver',
|
2018-08-09 18:12:45 +00:00
|
|
|
logging.INFO,
|
2019-01-05 06:20:38 +00:00
|
|
|
"Override strategy 'process_only_new_candles' with value in config file: True."
|
2018-08-09 18:12:45 +00:00
|
|
|
) in caplog.record_tuples
|
|
|
|
|
2018-08-09 18:17:55 +00:00
|
|
|
|
2018-11-17 09:14:18 +00:00
|
|
|
def test_strategy_override_order_types(caplog):
|
|
|
|
caplog.set_level(logging.INFO)
|
|
|
|
|
|
|
|
order_types = {
|
|
|
|
'buy': 'market',
|
|
|
|
'sell': 'limit',
|
2018-11-25 18:03:28 +00:00
|
|
|
'stoploss': 'limit',
|
|
|
|
'stoploss_on_exchange': True,
|
2018-11-17 09:14:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
config = {
|
|
|
|
'strategy': 'DefaultStrategy',
|
|
|
|
'order_types': order_types
|
|
|
|
}
|
|
|
|
resolver = StrategyResolver(config)
|
|
|
|
|
|
|
|
assert resolver.strategy.order_types
|
2018-11-25 18:03:28 +00:00
|
|
|
for method in ['buy', 'sell', 'stoploss', 'stoploss_on_exchange']:
|
2018-11-17 09:14:18 +00:00
|
|
|
assert resolver.strategy.order_types[method] == order_types[method]
|
|
|
|
|
2018-11-24 19:14:08 +00:00
|
|
|
assert ('freqtrade.resolvers.strategy_resolver',
|
2018-11-17 09:14:18 +00:00
|
|
|
logging.INFO,
|
|
|
|
"Override strategy 'order_types' with value in config file:"
|
2018-11-25 18:09:11 +00:00
|
|
|
" {'buy': 'market', 'sell': 'limit', 'stoploss': 'limit',"
|
|
|
|
" 'stoploss_on_exchange': True}."
|
2018-11-17 09:14:18 +00:00
|
|
|
) in caplog.record_tuples
|
|
|
|
|
2018-11-17 12:12:11 +00:00
|
|
|
config = {
|
|
|
|
'strategy': 'DefaultStrategy',
|
|
|
|
'order_types': {'buy': 'market'}
|
|
|
|
}
|
|
|
|
# Raise error for invalid configuration
|
|
|
|
with pytest.raises(ImportError,
|
|
|
|
match=r"Impossible to load Strategy 'DefaultStrategy'. "
|
|
|
|
r"Order-types mapping is incomplete."):
|
|
|
|
StrategyResolver(config)
|
|
|
|
|
2018-11-17 09:14:18 +00:00
|
|
|
|
2018-12-10 18:17:56 +00:00
|
|
|
def test_strategy_override_order_tif(caplog):
|
|
|
|
caplog.set_level(logging.INFO)
|
|
|
|
|
|
|
|
order_time_in_force = {
|
|
|
|
'buy': 'fok',
|
|
|
|
'sell': 'gtc',
|
|
|
|
}
|
|
|
|
|
|
|
|
config = {
|
|
|
|
'strategy': 'DefaultStrategy',
|
|
|
|
'order_time_in_force': order_time_in_force
|
|
|
|
}
|
|
|
|
resolver = StrategyResolver(config)
|
|
|
|
|
|
|
|
assert resolver.strategy.order_time_in_force
|
|
|
|
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
|
|
|
|
|
|
|
|
config = {
|
|
|
|
'strategy': 'DefaultStrategy',
|
|
|
|
'order_time_in_force': {'buy': 'fok'}
|
|
|
|
}
|
|
|
|
# Raise error for invalid configuration
|
|
|
|
with pytest.raises(ImportError,
|
|
|
|
match=r"Impossible to load Strategy 'DefaultStrategy'. "
|
|
|
|
r"Order-time-in-force mapping is incomplete."):
|
|
|
|
StrategyResolver(config)
|
|
|
|
|
|
|
|
|
2019-01-24 06:03:41 +00:00
|
|
|
def test_strategy_override_use_sell_signal(caplog):
|
|
|
|
caplog.set_level(logging.INFO)
|
|
|
|
config = {
|
|
|
|
'strategy': 'DefaultStrategy',
|
|
|
|
}
|
|
|
|
resolver = StrategyResolver(config)
|
|
|
|
assert not resolver.strategy.use_sell_signal
|
|
|
|
assert isinstance(resolver.strategy.use_sell_signal, bool)
|
|
|
|
# must be inserted to configuration
|
|
|
|
assert 'use_sell_signal' in config['experimental']
|
|
|
|
assert not config['experimental']['use_sell_signal']
|
|
|
|
|
|
|
|
config = {
|
|
|
|
'strategy': 'DefaultStrategy',
|
|
|
|
'experimental': {
|
|
|
|
'use_sell_signal': True,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
resolver = StrategyResolver(config)
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
|
|
|
|
def test_strategy_override_use_sell_profit_only(caplog):
|
|
|
|
caplog.set_level(logging.INFO)
|
|
|
|
config = {
|
|
|
|
'strategy': 'DefaultStrategy',
|
|
|
|
}
|
|
|
|
resolver = StrategyResolver(config)
|
|
|
|
assert not resolver.strategy.sell_profit_only
|
|
|
|
assert isinstance(resolver.strategy.sell_profit_only, bool)
|
|
|
|
# must be inserted to configuration
|
|
|
|
assert 'sell_profit_only' in config['experimental']
|
|
|
|
assert not config['experimental']['sell_profit_only']
|
|
|
|
|
|
|
|
config = {
|
|
|
|
'strategy': 'DefaultStrategy',
|
|
|
|
'experimental': {
|
|
|
|
'sell_profit_only': True,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
resolver = StrategyResolver(config)
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
|
2018-07-18 19:45:04 +00:00
|
|
|
def test_deprecate_populate_indicators(result):
|
2018-07-22 15:39:35 +00:00
|
|
|
default_location = path.join(path.dirname(path.realpath(__file__)))
|
|
|
|
resolver = StrategyResolver({'strategy': 'TestStrategyLegacy',
|
|
|
|
'strategy_path': default_location})
|
2018-07-18 19:45:04 +00:00
|
|
|
with warnings.catch_warnings(record=True) as w:
|
|
|
|
# Cause all warnings to always be triggered.
|
|
|
|
warnings.simplefilter("always")
|
2019-06-11 07:58:19 +00:00
|
|
|
indicators = resolver.strategy.advise_indicators(result, {'pair': 'ETH/BTC'})
|
2018-07-18 19:45:04 +00:00
|
|
|
assert len(w) == 1
|
|
|
|
assert issubclass(w[-1].category, DeprecationWarning)
|
2018-07-22 15:39:35 +00:00
|
|
|
assert "deprecated - check out the Sample strategy to see the current function headers!" \
|
|
|
|
in str(w[-1].message)
|
2018-07-18 19:45:04 +00:00
|
|
|
|
|
|
|
with warnings.catch_warnings(record=True) as w:
|
2019-01-31 05:51:03 +00:00
|
|
|
# Cause all warnings to always be triggered.
|
2018-07-18 19:45:04 +00:00
|
|
|
warnings.simplefilter("always")
|
2019-06-11 07:58:19 +00:00
|
|
|
resolver.strategy.advise_buy(indicators, {'pair': 'ETH/BTC'})
|
2018-07-18 19:45:04 +00:00
|
|
|
assert len(w) == 1
|
|
|
|
assert issubclass(w[-1].category, DeprecationWarning)
|
2018-07-22 15:39:35 +00:00
|
|
|
assert "deprecated - check out the Sample strategy to see the current function headers!" \
|
|
|
|
in str(w[-1].message)
|
2018-07-18 19:45:04 +00:00
|
|
|
|
|
|
|
with warnings.catch_warnings(record=True) as w:
|
|
|
|
# Cause all warnings to always be triggered.
|
|
|
|
warnings.simplefilter("always")
|
2019-06-11 07:58:19 +00:00
|
|
|
resolver.strategy.advise_sell(indicators, {'pair': 'ETH_BTC'})
|
2018-07-18 19:45:04 +00:00
|
|
|
assert len(w) == 1
|
|
|
|
assert issubclass(w[-1].category, DeprecationWarning)
|
2018-07-22 15:39:35 +00:00
|
|
|
assert "deprecated - check out the Sample strategy to see the current function headers!" \
|
|
|
|
in str(w[-1].message)
|
2018-07-18 21:23:30 +00:00
|
|
|
|
|
|
|
|
|
|
|
def test_call_deprecated_function(result, monkeypatch):
|
|
|
|
default_location = path.join(path.dirname(path.realpath(__file__)))
|
|
|
|
resolver = StrategyResolver({'strategy': 'TestStrategyLegacy',
|
|
|
|
'strategy_path': default_location})
|
2018-07-29 18:36:03 +00:00
|
|
|
metadata = {'pair': 'ETH/BTC'}
|
2018-07-18 21:23:30 +00:00
|
|
|
|
2018-07-22 15:39:35 +00:00
|
|
|
# Make sure we are using a legacy function
|
2018-07-23 16:38:21 +00:00
|
|
|
assert resolver.strategy._populate_fun_len == 2
|
|
|
|
assert resolver.strategy._buy_fun_len == 2
|
|
|
|
assert resolver.strategy._sell_fun_len == 2
|
2018-07-22 15:39:35 +00:00
|
|
|
|
2018-07-29 18:36:03 +00:00
|
|
|
indicator_df = resolver.strategy.advise_indicators(result, metadata=metadata)
|
2018-11-25 18:03:28 +00:00
|
|
|
assert isinstance(indicator_df, DataFrame)
|
2018-07-22 15:39:35 +00:00
|
|
|
assert 'adx' in indicator_df.columns
|
|
|
|
|
2018-07-29 18:36:03 +00:00
|
|
|
buydf = resolver.strategy.advise_buy(result, metadata=metadata)
|
2018-11-25 18:03:28 +00:00
|
|
|
assert isinstance(buydf, DataFrame)
|
2018-07-22 15:39:35 +00:00
|
|
|
assert 'buy' in buydf.columns
|
|
|
|
|
2018-07-29 18:36:03 +00:00
|
|
|
selldf = resolver.strategy.advise_sell(result, metadata=metadata)
|
2018-11-25 18:03:28 +00:00
|
|
|
assert isinstance(selldf, DataFrame)
|
2018-07-22 15:39:35 +00:00
|
|
|
assert 'sell' in selldf
|