Convert InformativeData to dataclass

This commit is contained in:
Matthias 2022-01-29 19:59:54 +01:00
parent ab932d8398
commit 8a6823deb1
3 changed files with 11 additions and 11 deletions

View File

@ -1,4 +1,5 @@
from typing import Any, Callable, NamedTuple, Optional, Union from dataclasses import dataclass
from typing import Any, Callable, Optional, Union
from pandas import DataFrame from pandas import DataFrame
@ -10,7 +11,8 @@ from freqtrade.strategy.strategy_helper import merge_informative_pair
PopulateIndicators = Callable[[Any, DataFrame, dict], DataFrame] PopulateIndicators = Callable[[Any, DataFrame, dict], DataFrame]
class InformativeData(NamedTuple): @dataclass
class InformativeData:
asset: Optional[str] asset: Optional[str]
timeframe: str timeframe: str
fmt: Union[str, Callable[[Any], str], None] fmt: Union[str, Callable[[Any], str], None]

View File

@ -158,9 +158,7 @@ class IStrategy(ABC, HyperStrategyMixin):
raise OperationalException('Informative timeframe must be equal or higher than ' raise OperationalException('Informative timeframe must be equal or higher than '
'strategy timeframe!') 'strategy timeframe!')
if not informative_data.candle_type: if not informative_data.candle_type:
informative_data = InformativeData( informative_data.candle_type = config['candle_type_def']
informative_data.asset, informative_data.timeframe, informative_data.fmt,
informative_data.ffill, config['candle_type_def'])
self._ft_informative.append((informative_data, cls_method)) self._ft_informative.append((informative_data, cls_method))
@abstractmethod @abstractmethod

View File

@ -6,6 +6,7 @@ import pytest
from freqtrade.data.dataprovider import DataProvider from freqtrade.data.dataprovider import DataProvider
from freqtrade.enums import CandleType from freqtrade.enums import CandleType
from freqtrade.resolvers.strategy_resolver import StrategyResolver
from freqtrade.strategy import (merge_informative_pair, stoploss_from_absolute, stoploss_from_open, from freqtrade.strategy import (merge_informative_pair, stoploss_from_absolute, stoploss_from_open,
timeframe_to_minutes) timeframe_to_minutes)
from tests.conftest import get_patched_exchange from tests.conftest import get_patched_exchange
@ -172,9 +173,9 @@ def test_stoploss_from_absolute():
@pytest.mark.parametrize('trading_mode', ['futures', 'spot']) @pytest.mark.parametrize('trading_mode', ['futures', 'spot'])
def test_informative_decorator(mocker, default_conf, trading_mode): def test_informative_decorator(mocker, default_conf_usdt, trading_mode):
candle_def = CandleType.get_default(trading_mode) candle_def = CandleType.get_default(trading_mode)
default_conf['candle_type_def'] = candle_def default_conf_usdt['candle_type_def'] = candle_def
test_data_5m = generate_test_data('5m', 40) test_data_5m = generate_test_data('5m', 40)
test_data_30m = generate_test_data('30m', 40) test_data_30m = generate_test_data('30m', 40)
test_data_1h = generate_test_data('1h', 40) test_data_1h = generate_test_data('1h', 40)
@ -193,10 +194,9 @@ def test_informative_decorator(mocker, default_conf, trading_mode):
('ETH/USDT', '30m', candle_def): test_data_30m, ('ETH/USDT', '30m', candle_def): test_data_30m,
('ETH/BTC', '1h', CandleType.SPOT): test_data_1h, # Explicitly selected as spot ('ETH/BTC', '1h', CandleType.SPOT): test_data_1h, # Explicitly selected as spot
} }
from .strats.informative_decorator_strategy import InformativeDecoratorTest default_conf_usdt['strategy'] = 'InformativeDecoratorTest'
default_conf['stake_currency'] = 'USDT' strategy = StrategyResolver.load_strategy(default_conf_usdt)
strategy = InformativeDecoratorTest(config=default_conf) exchange = get_patched_exchange(mocker, default_conf_usdt)
exchange = get_patched_exchange(mocker, default_conf)
strategy.dp = DataProvider({}, exchange, None) strategy.dp = DataProvider({}, exchange, None)
mocker.patch.object(strategy.dp, 'current_whitelist', return_value=[ mocker.patch.object(strategy.dp, 'current_whitelist', return_value=[
'XRP/USDT', 'LTC/USDT', 'NEO/USDT' 'XRP/USDT', 'LTC/USDT', 'NEO/USDT'