From 9bcc79e1180aeab29ec1214669a1e7ed37420762 Mon Sep 17 00:00:00 2001 From: Matthias Date: Thu, 3 Mar 2022 07:06:13 +0100 Subject: [PATCH] Use parsed TradingMode from config --- freqtrade/commands/data_commands.py | 8 +++++--- freqtrade/data/history/hdf5datahandler.py | 7 ++++--- freqtrade/data/history/idatahandler.py | 5 +++-- freqtrade/data/history/jsondatahandler.py | 5 +++-- freqtrade/rpc/api_server/api_v1.py | 4 ++-- tests/data/test_history.py | 10 +++++----- 6 files changed, 22 insertions(+), 17 deletions(-) diff --git a/freqtrade/commands/data_commands.py b/freqtrade/commands/data_commands.py index 95ad67a65..e41512ccc 100644 --- a/freqtrade/commands/data_commands.py +++ b/freqtrade/commands/data_commands.py @@ -8,7 +8,7 @@ from freqtrade.configuration import TimeRange, setup_utils_configuration from freqtrade.data.converter import convert_ohlcv_format, convert_trades_format from freqtrade.data.history import (convert_trades_to_ohlcv, refresh_backtest_ohlcv_data, refresh_backtest_trades_data) -from freqtrade.enums import CandleType, RunMode +from freqtrade.enums import CandleType, RunMode, TradingMode from freqtrade.exceptions import OperationalException from freqtrade.exchange import timeframe_to_minutes from freqtrade.exchange.exchange import market_is_active @@ -160,8 +160,10 @@ def start_list_data(args: Dict[str, Any]) -> None: from freqtrade.data.history.idatahandler import get_datahandler dhc = get_datahandler(config['datadir'], config['dataformat_ohlcv']) - # TODO-lev: trading-mode should be parsed at config level, and available as Enum in the config. - paircombs = dhc.ohlcv_get_available_data(config['datadir'], config.get('trading_mode', 'spot')) + paircombs = dhc.ohlcv_get_available_data( + config['datadir'], + config.get('trading_mode', TradingMode.SPOT) + ) if args['pairs']: paircombs = [comb for comb in paircombs if comb[0] in args['pairs']] diff --git a/freqtrade/data/history/hdf5datahandler.py b/freqtrade/data/history/hdf5datahandler.py index e0db3dece..db96bdf21 100644 --- a/freqtrade/data/history/hdf5datahandler.py +++ b/freqtrade/data/history/hdf5datahandler.py @@ -9,7 +9,7 @@ import pandas as pd from freqtrade.configuration import TimeRange from freqtrade.constants import (DEFAULT_DATAFRAME_COLUMNS, DEFAULT_TRADES_COLUMNS, ListPairsWithTimeframes, TradeList) -from freqtrade.enums import CandleType +from freqtrade.enums import CandleType, TradingMode from .idatahandler import IDataHandler @@ -22,14 +22,15 @@ class HDF5DataHandler(IDataHandler): _columns = DEFAULT_DATAFRAME_COLUMNS @classmethod - def ohlcv_get_available_data(cls, datadir: Path, trading_mode: str) -> ListPairsWithTimeframes: + def ohlcv_get_available_data( + cls, datadir: Path, trading_mode: TradingMode) -> ListPairsWithTimeframes: """ Returns a list of all pairs with ohlcv data available in this datadir :param datadir: Directory to search for ohlcv files :param trading_mode: trading-mode to be used :return: List of Tuples of (pair, timeframe) """ - if trading_mode == 'futures': + if trading_mode == TradingMode.FUTURES: datadir = datadir.joinpath('futures') _tmp = [ re.search( diff --git a/freqtrade/data/history/idatahandler.py b/freqtrade/data/history/idatahandler.py index 31d768a5f..4a5eb6bc2 100644 --- a/freqtrade/data/history/idatahandler.py +++ b/freqtrade/data/history/idatahandler.py @@ -17,7 +17,7 @@ from freqtrade import misc from freqtrade.configuration import TimeRange from freqtrade.constants import ListPairsWithTimeframes, TradeList from freqtrade.data.converter import clean_ohlcv_dataframe, trades_remove_duplicates, trim_dataframe -from freqtrade.enums import CandleType +from freqtrade.enums import CandleType, TradingMode from freqtrade.exchange import timeframe_to_seconds @@ -39,7 +39,8 @@ class IDataHandler(ABC): raise NotImplementedError() @abstractclassmethod - def ohlcv_get_available_data(cls, datadir: Path, trading_mode: str) -> ListPairsWithTimeframes: + def ohlcv_get_available_data( + cls, datadir: Path, trading_mode: TradingMode) -> ListPairsWithTimeframes: """ Returns a list of all pairs with ohlcv data available in this datadir :param datadir: Directory to search for ohlcv files diff --git a/freqtrade/data/history/jsondatahandler.py b/freqtrade/data/history/jsondatahandler.py index 82ab1abbf..23054ac51 100644 --- a/freqtrade/data/history/jsondatahandler.py +++ b/freqtrade/data/history/jsondatahandler.py @@ -10,7 +10,7 @@ from freqtrade import misc from freqtrade.configuration import TimeRange from freqtrade.constants import DEFAULT_DATAFRAME_COLUMNS, ListPairsWithTimeframes, TradeList from freqtrade.data.converter import trades_dict_to_list -from freqtrade.enums import CandleType +from freqtrade.enums import CandleType, TradingMode from .idatahandler import IDataHandler @@ -24,7 +24,8 @@ class JsonDataHandler(IDataHandler): _columns = DEFAULT_DATAFRAME_COLUMNS @classmethod - def ohlcv_get_available_data(cls, datadir: Path, trading_mode: str) -> ListPairsWithTimeframes: + def ohlcv_get_available_data( + cls, datadir: Path, trading_mode: TradingMode) -> ListPairsWithTimeframes: """ Returns a list of all pairs with ohlcv data available in this datadir :param datadir: Directory to search for ohlcv files diff --git a/freqtrade/rpc/api_server/api_v1.py b/freqtrade/rpc/api_server/api_v1.py index f6b6c9eda..adcdd313a 100644 --- a/freqtrade/rpc/api_server/api_v1.py +++ b/freqtrade/rpc/api_server/api_v1.py @@ -9,7 +9,7 @@ from fastapi.exceptions import HTTPException from freqtrade import __version__ from freqtrade.constants import USERPATH_STRATEGIES from freqtrade.data.history import get_datahandler -from freqtrade.enums import CandleType +from freqtrade.enums import CandleType, TradingMode from freqtrade.exceptions import OperationalException from freqtrade.rpc import RPC from freqtrade.rpc.api_server.api_schemas import (AvailablePairs, Balances, BlacklistPayload, @@ -279,7 +279,7 @@ def list_available_pairs(timeframe: Optional[str] = None, stake_currency: Option candletype: Optional[CandleType] = None, config=Depends(get_config)): dh = get_datahandler(config['datadir'], config.get('dataformat_ohlcv', None)) - trading_mode = config.get('trading_mode', 'spot') + trading_mode: TradingMode = config.get('trading_mode', TradingMode.SPOT) pair_interval = dh.ohlcv_get_available_data(config['datadir'], trading_mode) if timeframe: diff --git a/tests/data/test_history.py b/tests/data/test_history.py index ad388a2c8..148b22973 100644 --- a/tests/data/test_history.py +++ b/tests/data/test_history.py @@ -24,7 +24,7 @@ from freqtrade.data.history.history_utils import (_download_pair_history, _downl validate_backtest_data) from freqtrade.data.history.idatahandler import IDataHandler, get_datahandler, get_datahandlerclass from freqtrade.data.history.jsondatahandler import JsonDataHandler, JsonGzDataHandler -from freqtrade.enums import CandleType +from freqtrade.enums import CandleType, TradingMode from freqtrade.exchange import timeframe_to_minutes from freqtrade.misc import file_dump_json from freqtrade.resolvers import StrategyResolver @@ -716,7 +716,7 @@ def test_rebuild_pair_from_filename(input, expected): def test_datahandler_ohlcv_get_available_data(testdatadir): - paircombs = JsonDataHandler.ohlcv_get_available_data(testdatadir, 'spot') + paircombs = JsonDataHandler.ohlcv_get_available_data(testdatadir, TradingMode.SPOT) # Convert to set to avoid failures due to sorting assert set(paircombs) == { ('UNITTEST/BTC', '5m', CandleType.SPOT), @@ -738,7 +738,7 @@ def test_datahandler_ohlcv_get_available_data(testdatadir): ('NOPAIR/XXX', '4m', CandleType.SPOT), } - paircombs = JsonDataHandler.ohlcv_get_available_data(testdatadir, 'futures') + paircombs = JsonDataHandler.ohlcv_get_available_data(testdatadir, TradingMode.FUTURES) # Convert to set to avoid failures due to sorting assert set(paircombs) == { ('UNITTEST/USDT', '1h', 'mark'), @@ -748,9 +748,9 @@ def test_datahandler_ohlcv_get_available_data(testdatadir): ('XRP/USDT', '8h', 'funding_rate'), } - paircombs = JsonGzDataHandler.ohlcv_get_available_data(testdatadir, 'spot') + paircombs = JsonGzDataHandler.ohlcv_get_available_data(testdatadir, TradingMode.SPOT) assert set(paircombs) == {('UNITTEST/BTC', '8m', CandleType.SPOT)} - paircombs = HDF5DataHandler.ohlcv_get_available_data(testdatadir, 'spot') + paircombs = HDF5DataHandler.ohlcv_get_available_data(testdatadir, TradingMode.SPOT) assert set(paircombs) == {('UNITTEST/BTC', '5m', CandleType.SPOT)}