Add candleType enum

This commit is contained in:
Matthias 2021-12-03 12:12:33 +01:00
parent e0e4369c8e
commit a87e256737
5 changed files with 48 additions and 19 deletions

View File

@ -9,6 +9,7 @@ import pandas as pd
from freqtrade.configuration import TimeRange from freqtrade.configuration import TimeRange
from freqtrade.constants import (DEFAULT_DATAFRAME_COLUMNS, DEFAULT_TRADES_COLUMNS, from freqtrade.constants import (DEFAULT_DATAFRAME_COLUMNS, DEFAULT_TRADES_COLUMNS,
ListPairsWithTimeframes, TradeList) ListPairsWithTimeframes, TradeList)
from freqtrade.enums.candletype import CandleType
from .idatahandler import IDataHandler from .idatahandler import IDataHandler
@ -39,24 +40,27 @@ class HDF5DataHandler(IDataHandler):
if match and len(match.groups()) > 1] if match and len(match.groups()) > 1]
@classmethod @classmethod
def ohlcv_get_pairs(cls, datadir: Path, timeframe: str, candle_type: str = '') -> List[str]: def ohlcv_get_pairs(
cls,
datadir: Path,
timeframe: str,
candle_type: CandleType = CandleType.SPOT_
) -> List[str]:
""" """
Returns a list of all pairs with ohlcv data available in this datadir Returns a list of all pairs with ohlcv data available in this datadir
for the specified timeframe for the specified timeframe
:param datadir: Directory to search for ohlcv files :param datadir: Directory to search for ohlcv files
:param timeframe: Timeframe to search pairs for :param timeframe: Timeframe to search pairs for
:param candle_type: '', mark, index, premiumIndex, or funding_rate :param candle_type: Any of the enum CandleType (must match your trading mode!)
:return: List of Pairs :return: List of Pairs
""" """
candle = ""
if candle_type: if candle_type not in (CandleType.SPOT, CandleType.SPOT_):
datadir = datadir.joinpath('futures') datadir = datadir.joinpath('futures')
candle_type = f"-{candle_type}" candle = f"-{candle_type}"
else:
candle_type = ""
_tmp = [re.search(r'^(\S+)(?=\-' + timeframe + candle_type + '.h5)', p.name) _tmp = [re.search(r'^(\S+)(?=\-' + timeframe + candle + '.h5)', p.name)
for p in datadir.glob(f"*{timeframe}{candle_type}.h5")] for p in datadir.glob(f"*{timeframe}{candle}.h5")]
# Check if regex found something and only return these results # Check if regex found something and only return these results
return [match[0].replace('_', '/') for match in _tmp if match] return [match[0].replace('_', '/') for match in _tmp if match]

View File

@ -17,6 +17,7 @@ from freqtrade import misc
from freqtrade.configuration import TimeRange from freqtrade.configuration import TimeRange
from freqtrade.constants import ListPairsWithTimeframes, TradeList from freqtrade.constants import ListPairsWithTimeframes, TradeList
from freqtrade.data.converter import clean_ohlcv_dataframe, trades_remove_duplicates, trim_dataframe from freqtrade.data.converter import clean_ohlcv_dataframe, trades_remove_duplicates, trim_dataframe
from freqtrade.enums.candletype import CandleType
from freqtrade.exchange import timeframe_to_seconds from freqtrade.exchange import timeframe_to_seconds
@ -47,13 +48,18 @@ class IDataHandler(ABC):
""" """
@abstractclassmethod @abstractclassmethod
def ohlcv_get_pairs(cls, datadir: Path, timeframe: str, candle_type: str = '') -> List[str]: def ohlcv_get_pairs(
cls,
datadir: Path,
timeframe: str,
candle_type: CandleType = CandleType.SPOT_
) -> List[str]:
""" """
Returns a list of all pairs with ohlcv data available in this datadir Returns a list of all pairs with ohlcv data available in this datadir
for the specified timeframe for the specified timeframe
:param datadir: Directory to search for ohlcv files :param datadir: Directory to search for ohlcv files
:param timeframe: Timeframe to search pairs for :param timeframe: Timeframe to search pairs for
:param candle_type: '', mark, index, premiumIndex, or funding_rate :param candle_type: Any of the enum CandleType (must match your trading mode!)
:return: List of Pairs :return: List of Pairs
""" """

View File

@ -10,6 +10,7 @@ from freqtrade import misc
from freqtrade.configuration import TimeRange from freqtrade.configuration import TimeRange
from freqtrade.constants import DEFAULT_DATAFRAME_COLUMNS, ListPairsWithTimeframes, TradeList from freqtrade.constants import DEFAULT_DATAFRAME_COLUMNS, ListPairsWithTimeframes, TradeList
from freqtrade.data.converter import trades_dict_to_list from freqtrade.data.converter import trades_dict_to_list
from freqtrade.enums.candletype import CandleType
from .idatahandler import IDataHandler from .idatahandler import IDataHandler
@ -40,23 +41,27 @@ class JsonDataHandler(IDataHandler):
if match and len(match.groups()) > 1] if match and len(match.groups()) > 1]
@classmethod @classmethod
def ohlcv_get_pairs(cls, datadir: Path, timeframe: str, candle_type: str = '') -> List[str]: def ohlcv_get_pairs(
cls,
datadir: Path,
timeframe: str,
candle_type: CandleType = CandleType.SPOT_
) -> List[str]:
""" """
Returns a list of all pairs with ohlcv data available in this datadir Returns a list of all pairs with ohlcv data available in this datadir
for the specified timeframe for the specified timeframe
:param datadir: Directory to search for ohlcv files :param datadir: Directory to search for ohlcv files
:param timeframe: Timeframe to search pairs for :param timeframe: Timeframe to search pairs for
:param candle_type: '', mark, index, premiumIndex, or funding_rate :param candle_type: Any of the enum CandleType (must match your trading mode!)
:return: List of Pairs :return: List of Pairs
""" """
if candle_type: candle = ""
if candle_type not in (CandleType.SPOT, CandleType.SPOT_):
datadir = datadir.joinpath('futures') datadir = datadir.joinpath('futures')
candle_type = f"-{candle_type}" candle = f"-{candle_type}"
else:
candle_type = ""
_tmp = [re.search(r'^(\S+)(?=\-' + timeframe + candle_type + '.json)', p.name) _tmp = [re.search(r'^(\S+)(?=\-' + timeframe + candle + '.json)', p.name)
for p in datadir.glob(f"*{timeframe}{candle_type}.{cls._get_file_extension()}")] for p in datadir.glob(f"*{timeframe}{candle}.{cls._get_file_extension()}")]
# Check if regex found something and only return these results # Check if regex found something and only return these results
return [match[0].replace('_', '/') for match in _tmp if match] return [match[0].replace('_', '/') for match in _tmp if match]

View File

@ -1,5 +1,6 @@
# flake8: noqa: F401 # flake8: noqa: F401
from freqtrade.enums.backteststate import BacktestState from freqtrade.enums.backteststate import BacktestState
from freqtrade.enums.candletype import CandleType
from freqtrade.enums.collateral import Collateral from freqtrade.enums.collateral import Collateral
from freqtrade.enums.rpcmessagetype import RPCMessageType from freqtrade.enums.rpcmessagetype import RPCMessageType
from freqtrade.enums.runmode import NON_UTIL_MODES, OPTIMIZE_MODES, TRADING_MODES, RunMode from freqtrade.enums.runmode import NON_UTIL_MODES, OPTIMIZE_MODES, TRADING_MODES, RunMode

View File

@ -0,0 +1,13 @@
from enum import Enum
class CandleType(str, Enum):
"""Enum to distinguish candle types"""
SPOT = "spot"
SPOT_ = ""
FUTURES = "futures"
MARK = "mark"
INDEX = "index"
PREMIUMINDEX = "premiumIndex"
# TODO-lev: not sure this belongs here, as the datatype is really different
FUNDING_RATE = "funding_rate"