move strategy initialization outside Analyze

This commit is contained in:
Janne Sinivirta
2018-07-09 19:27:36 +03:00
parent 727f569e3a
commit a74147c472
8 changed files with 27 additions and 21 deletions

View File

@@ -18,6 +18,7 @@ from freqtrade.arguments import Arguments, TimeRange
from freqtrade.optimize.backtesting import (Backtesting, setup_configuration,
start)
from freqtrade.tests.conftest import log_has, patch_exchange
from freqtrade.strategy.default_strategy import DefaultStrategy
def get_args(args) -> List[str]:
@@ -348,7 +349,7 @@ def test_tickerdata_to_dataframe(default_conf, mocker) -> None:
assert len(data['UNITTEST/BTC']) == 99
# Load Analyze to compare the result between Backtesting function and Analyze are the same
analyze = Analyze(default_conf)
analyze = Analyze(default_conf, DefaultStrategy())
data2 = analyze.tickerdata_to_dataframe(tickerlist)
assert data['UNITTEST/BTC'].equals(data2['UNITTEST/BTC'])

View File

@@ -14,9 +14,10 @@ from freqtrade.analyze import Analyze, SignalType
from freqtrade.arguments import TimeRange
from freqtrade.optimize.__init__ import load_tickerdata_file
from freqtrade.tests.conftest import get_patched_exchange, log_has
from freqtrade.strategy.default_strategy import DefaultStrategy
# Avoid to reinit the same object again and again
_ANALYZE = Analyze({'strategy': 'DefaultStrategy'})
_ANALYZE = Analyze({}, DefaultStrategy())
def test_signaltype_object() -> None:
@@ -189,7 +190,7 @@ def test_tickerdata_to_dataframe(default_conf) -> None:
"""
Test Analyze.tickerdata_to_dataframe() method
"""
analyze = Analyze(default_conf)
analyze = Analyze(default_conf, DefaultStrategy())
timerange = TimeRange(None, 'line', 0, -100)
tick = load_tickerdata_file(None, 'UNITTEST/BTC', '1m', timerange=timerange)

View File

@@ -9,26 +9,26 @@ from freqtrade.strategy.resolver import StrategyResolver
_pairs = ['ETH/BTC']
def load_dataframe_pair(pairs):
def load_dataframe_pair(pairs, strategy):
ld = load_data(None, ticker_interval='5m', pairs=pairs)
assert isinstance(ld, dict)
assert isinstance(pairs[0], str)
dataframe = ld[pairs[0]]
analyze = Analyze({'strategy': 'DefaultStrategy'})
analyze = Analyze({}, strategy)
dataframe = analyze.analyze_ticker(dataframe)
return dataframe
def test_dataframe_load():
StrategyResolver({'strategy': 'DefaultStrategy'})
dataframe = load_dataframe_pair(_pairs)
strategy = StrategyResolver({'strategy': 'DefaultStrategy'}).strategy
dataframe = load_dataframe_pair(_pairs, strategy)
assert isinstance(dataframe, pandas.core.frame.DataFrame)
def test_dataframe_columns_exists():
StrategyResolver({'strategy': 'DefaultStrategy'})
dataframe = load_dataframe_pair(_pairs)
strategy = StrategyResolver({'strategy': 'DefaultStrategy'}).strategy
dataframe = load_dataframe_pair(_pairs, strategy)
assert 'high' in dataframe.columns
assert 'low' in dataframe.columns
assert 'close' in dataframe.columns

View File

@@ -316,9 +316,8 @@ def test_get_min_pair_stake_amount(mocker, default_conf) -> None:
patch_RPCManager(mocker)
mocker.patch('freqtrade.exchange.Exchange.validate_pairs', MagicMock())
mocker.patch('freqtrade.freqtradebot.Analyze.get_stoploss', MagicMock(return_value=-0.05))
freqtrade = FreqtradeBot(default_conf)
freqtrade.strategy.stoploss = -0.05
# no pair found
mocker.patch(
'freqtrade.exchange.Exchange.get_markets',

View File

@@ -11,6 +11,7 @@ from freqtrade.analyze import Analyze
from freqtrade.misc import (common_datearray, datesarray_to_datetimearray,
file_dump_json, format_ms_time, shorten_date)
from freqtrade.optimize.__init__ import load_tickerdata_file
from freqtrade.strategy.default_strategy import DefaultStrategy
def test_shorten_date() -> None:
@@ -47,7 +48,7 @@ def test_common_datearray(default_conf) -> None:
Test common_datearray()
:return: None
"""
analyze = Analyze(default_conf)
analyze = Analyze(default_conf, DefaultStrategy())
tick = load_tickerdata_file(None, 'UNITTEST/BTC', '1m')
tickerlist = {'UNITTEST/BTC': tick}
dataframes = analyze.tickerdata_to_dataframe(tickerlist)