Reduce code duplication in datahandlers
This commit is contained in:
parent
975bf8fe88
commit
b420614d65
@ -21,29 +21,6 @@ class HDF5DataHandler(IDataHandler):
|
|||||||
|
|
||||||
_columns = DEFAULT_DATAFRAME_COLUMNS
|
_columns = DEFAULT_DATAFRAME_COLUMNS
|
||||||
|
|
||||||
@classmethod
|
|
||||||
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, CandleType)
|
|
||||||
"""
|
|
||||||
if trading_mode == TradingMode.FUTURES:
|
|
||||||
datadir = datadir.joinpath('futures')
|
|
||||||
_tmp = [
|
|
||||||
re.search(
|
|
||||||
cls._OHLCV_REGEX, p.name
|
|
||||||
) for p in datadir.glob("*.h5")
|
|
||||||
]
|
|
||||||
return [
|
|
||||||
(
|
|
||||||
cls.rebuild_pair_from_filename(match[1]),
|
|
||||||
cls.rebuild_timeframe_from_filename(match[2]),
|
|
||||||
CandleType.from_string(match[3])
|
|
||||||
) for match in _tmp if match and len(match.groups()) > 1]
|
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def ohlcv_get_pairs(cls, datadir: Path, timeframe: str, candle_type: CandleType) -> List[str]:
|
def ohlcv_get_pairs(cls, datadir: Path, timeframe: str, candle_type: CandleType) -> List[str]:
|
||||||
"""
|
"""
|
||||||
|
@ -39,7 +39,6 @@ class IDataHandler(ABC):
|
|||||||
raise NotImplementedError()
|
raise NotImplementedError()
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
@abstractmethod
|
|
||||||
def ohlcv_get_available_data(
|
def ohlcv_get_available_data(
|
||||||
cls, datadir: Path, trading_mode: TradingMode) -> ListPairsWithTimeframes:
|
cls, datadir: Path, trading_mode: TradingMode) -> ListPairsWithTimeframes:
|
||||||
"""
|
"""
|
||||||
@ -48,6 +47,18 @@ class IDataHandler(ABC):
|
|||||||
:param trading_mode: trading-mode to be used
|
:param trading_mode: trading-mode to be used
|
||||||
:return: List of Tuples of (pair, timeframe, CandleType)
|
:return: List of Tuples of (pair, timeframe, CandleType)
|
||||||
"""
|
"""
|
||||||
|
if trading_mode == TradingMode.FUTURES:
|
||||||
|
datadir = datadir.joinpath('futures')
|
||||||
|
_tmp = [
|
||||||
|
re.search(
|
||||||
|
cls._OHLCV_REGEX, p.name
|
||||||
|
) for p in datadir.glob(f"*.{cls._get_file_extension()}")]
|
||||||
|
return [
|
||||||
|
(
|
||||||
|
cls.rebuild_pair_from_filename(match[1]),
|
||||||
|
cls.rebuild_timeframe_from_filename(match[2]),
|
||||||
|
CandleType.from_string(match[3])
|
||||||
|
) for match in _tmp if match and len(match.groups()) > 1]
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
@abstractmethod
|
@abstractmethod
|
||||||
|
@ -23,28 +23,6 @@ class JsonDataHandler(IDataHandler):
|
|||||||
_use_zip = False
|
_use_zip = False
|
||||||
_columns = DEFAULT_DATAFRAME_COLUMNS
|
_columns = DEFAULT_DATAFRAME_COLUMNS
|
||||||
|
|
||||||
@classmethod
|
|
||||||
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, CandleType)
|
|
||||||
"""
|
|
||||||
if trading_mode == 'futures':
|
|
||||||
datadir = datadir.joinpath('futures')
|
|
||||||
_tmp = [
|
|
||||||
re.search(
|
|
||||||
cls._OHLCV_REGEX, p.name
|
|
||||||
) for p in datadir.glob(f"*.{cls._get_file_extension()}")]
|
|
||||||
return [
|
|
||||||
(
|
|
||||||
cls.rebuild_pair_from_filename(match[1]),
|
|
||||||
cls.rebuild_timeframe_from_filename(match[2]),
|
|
||||||
CandleType.from_string(match[3])
|
|
||||||
) for match in _tmp if match and len(match.groups()) > 1]
|
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def ohlcv_get_pairs(cls, datadir: Path, timeframe: str, candle_type: CandleType) -> List[str]:
|
def ohlcv_get_pairs(cls, datadir: Path, timeframe: str, candle_type: CandleType) -> List[str]:
|
||||||
"""
|
"""
|
||||||
|
Loading…
Reference in New Issue
Block a user