Add candleType enum
This commit is contained in:
parent
e0e4369c8e
commit
a87e256737
@ -9,6 +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.candletype import CandleType
|
||||
|
||||
from .idatahandler import IDataHandler
|
||||
|
||||
@ -39,24 +40,27 @@ class HDF5DataHandler(IDataHandler):
|
||||
if match and len(match.groups()) > 1]
|
||||
|
||||
@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
|
||||
for the specified timeframe
|
||||
:param datadir: Directory to search for ohlcv files
|
||||
: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
|
||||
"""
|
||||
|
||||
if candle_type:
|
||||
candle = ""
|
||||
if candle_type not in (CandleType.SPOT, CandleType.SPOT_):
|
||||
datadir = datadir.joinpath('futures')
|
||||
candle_type = f"-{candle_type}"
|
||||
else:
|
||||
candle_type = ""
|
||||
candle = f"-{candle_type}"
|
||||
|
||||
_tmp = [re.search(r'^(\S+)(?=\-' + timeframe + candle_type + '.h5)', p.name)
|
||||
for p in datadir.glob(f"*{timeframe}{candle_type}.h5")]
|
||||
_tmp = [re.search(r'^(\S+)(?=\-' + timeframe + candle + '.h5)', p.name)
|
||||
for p in datadir.glob(f"*{timeframe}{candle}.h5")]
|
||||
# Check if regex found something and only return these results
|
||||
return [match[0].replace('_', '/') for match in _tmp if match]
|
||||
|
||||
|
@ -17,6 +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.candletype import CandleType
|
||||
from freqtrade.exchange import timeframe_to_seconds
|
||||
|
||||
|
||||
@ -47,13 +48,18 @@ class IDataHandler(ABC):
|
||||
"""
|
||||
|
||||
@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
|
||||
for the specified timeframe
|
||||
:param datadir: Directory to search for ohlcv files
|
||||
: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
|
||||
"""
|
||||
|
||||
|
@ -10,6 +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.candletype import CandleType
|
||||
|
||||
from .idatahandler import IDataHandler
|
||||
|
||||
@ -40,23 +41,27 @@ class JsonDataHandler(IDataHandler):
|
||||
if match and len(match.groups()) > 1]
|
||||
|
||||
@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
|
||||
for the specified timeframe
|
||||
:param datadir: Directory to search for ohlcv files
|
||||
: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
|
||||
"""
|
||||
if candle_type:
|
||||
candle = ""
|
||||
if candle_type not in (CandleType.SPOT, CandleType.SPOT_):
|
||||
datadir = datadir.joinpath('futures')
|
||||
candle_type = f"-{candle_type}"
|
||||
else:
|
||||
candle_type = ""
|
||||
candle = f"-{candle_type}"
|
||||
|
||||
_tmp = [re.search(r'^(\S+)(?=\-' + timeframe + candle_type + '.json)', p.name)
|
||||
for p in datadir.glob(f"*{timeframe}{candle_type}.{cls._get_file_extension()}")]
|
||||
_tmp = [re.search(r'^(\S+)(?=\-' + timeframe + candle + '.json)', p.name)
|
||||
for p in datadir.glob(f"*{timeframe}{candle}.{cls._get_file_extension()}")]
|
||||
# Check if regex found something and only return these results
|
||||
return [match[0].replace('_', '/') for match in _tmp if match]
|
||||
|
||||
|
@ -1,5 +1,6 @@
|
||||
# flake8: noqa: F401
|
||||
from freqtrade.enums.backteststate import BacktestState
|
||||
from freqtrade.enums.candletype import CandleType
|
||||
from freqtrade.enums.collateral import Collateral
|
||||
from freqtrade.enums.rpcmessagetype import RPCMessageType
|
||||
from freqtrade.enums.runmode import NON_UTIL_MODES, OPTIMIZE_MODES, TRADING_MODES, RunMode
|
||||
|
13
freqtrade/enums/candletype.py
Normal file
13
freqtrade/enums/candletype.py
Normal 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"
|
Loading…
Reference in New Issue
Block a user