From f33643cacf4a4eafb3d5c925426a8a480ff0928b Mon Sep 17 00:00:00 2001 From: Matthias Date: Fri, 3 Dec 2021 12:46:18 +0100 Subject: [PATCH] Add candletype from string --- freqtrade/data/converter.py | 1 + freqtrade/enums/candletype.py | 7 +++++++ tests/leverage/test_candletype.py | 18 ++++++++++++++++++ 3 files changed, 26 insertions(+) create mode 100644 tests/leverage/test_candletype.py diff --git a/freqtrade/data/converter.py b/freqtrade/data/converter.py index 680b95ab2..bdb8c3464 100644 --- a/freqtrade/data/converter.py +++ b/freqtrade/data/converter.py @@ -275,6 +275,7 @@ def convert_ohlcv_format( :param convert_from: Source format :param convert_to: Target format :param erase: Erase source data (does not apply if source and target format are identical) + :param candle_type: Any of the enum CandleType (must match trading mode!) """ from freqtrade.data.history.idatahandler import get_datahandler src = get_datahandler(config['datadir'], convert_from) diff --git a/freqtrade/enums/candletype.py b/freqtrade/enums/candletype.py index b4052a212..9818bb67b 100644 --- a/freqtrade/enums/candletype.py +++ b/freqtrade/enums/candletype.py @@ -11,3 +11,10 @@ class CandleType(str, Enum): PREMIUMINDEX = "premiumIndex" # TODO-lev: not sure this belongs here, as the datatype is really different FUNDING_RATE = "funding_rate" + + @classmethod + def from_string(cls, value: str) -> 'CandleType': + if not value: + # Default to spot + return CandleType.SPOT + return CandleType(value) diff --git a/tests/leverage/test_candletype.py b/tests/leverage/test_candletype.py new file mode 100644 index 000000000..3eb73a07c --- /dev/null +++ b/tests/leverage/test_candletype.py @@ -0,0 +1,18 @@ +import pytest + +from freqtrade.enums import CandleType + + +@pytest.mark.parametrize('input,expected', [ + ('', CandleType.SPOT), + ('spot', CandleType.SPOT), + (CandleType.SPOT, CandleType.SPOT), + (CandleType.FUTURES, CandleType.FUTURES), + (CandleType.INDEX, CandleType.INDEX), + (CandleType.MARK, CandleType.MARK), + ('futures', CandleType.FUTURES), + ('mark', CandleType.MARK), + ('premiumIndex', CandleType.PREMIUMINDEX), +]) +def test_candle_type_from_string(input, expected): + assert CandleType.from_string(input) == expected