replaced candle_type: Optional[str] = '' with candle_type: str = ''

This commit is contained in:
Sam Germain 2021-11-21 00:21:10 -06:00
parent 64a6abc541
commit e2f98a8dab
8 changed files with 63 additions and 43 deletions

View File

@ -266,7 +266,7 @@ def convert_ohlcv_format(
convert_from: str, convert_from: str,
convert_to: str, convert_to: str,
erase: bool, erase: bool,
candle_type: Optional[str] = "" candle_type: str = ''
): ):
""" """
Convert OHLCV from one format to another Convert OHLCV from one format to another

View File

@ -99,7 +99,12 @@ class DataProvider:
logger.warning(f"No data found for ({pair}, {timeframe}).") logger.warning(f"No data found for ({pair}, {timeframe}).")
return data return data
def get_analyzed_dataframe(self, pair: str, timeframe: str) -> Tuple[DataFrame, datetime]: def get_analyzed_dataframe(
self,
pair: str,
timeframe: str,
candle_type: str = ''
) -> Tuple[DataFrame, datetime]:
""" """
Retrieve the analyzed dataframe. Returns the full dataframe in trade mode (live / dry), Retrieve the analyzed dataframe. Returns the full dataframe in trade mode (live / dry),
and the last 1000 candles (up to the time evaluated at this moment) in all other modes. and the last 1000 candles (up to the time evaluated at this moment) in all other modes.
@ -177,7 +182,13 @@ class DataProvider:
raise OperationalException(NO_EXCHANGE_EXCEPTION) raise OperationalException(NO_EXCHANGE_EXCEPTION)
return list(self._exchange._klines.keys()) return list(self._exchange._klines.keys())
def ohlcv(self, pair: str, timeframe: str = None, copy: bool = True) -> DataFrame: def ohlcv(
self,
pair: str,
timeframe: str = None,
copy: bool = True,
candle_type: str = ''
) -> DataFrame:
""" """
Get candle (OHLCV) data for the given pair as DataFrame Get candle (OHLCV) data for the given pair as DataFrame
Please use the `available_pairs` method to verify which pairs are currently cached. Please use the `available_pairs` method to verify which pairs are currently cached.

View File

@ -42,7 +42,7 @@ class HDF5DataHandler(IDataHandler):
cls, cls,
datadir: Path, datadir: Path,
timeframe: str, timeframe: str,
candle_type: Optional[str] = "" candle_type: str = ''
) -> List[str]: ) -> 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
@ -67,7 +67,7 @@ class HDF5DataHandler(IDataHandler):
pair: str, pair: str,
timeframe: str, timeframe: str,
data: pd.DataFrame, data: pd.DataFrame,
candle_type: Optional[str] = "" candle_type: str = ''
) -> None: ) -> None:
""" """
Store data in hdf5 file. Store data in hdf5 file.
@ -88,7 +88,7 @@ class HDF5DataHandler(IDataHandler):
def _ohlcv_load(self, pair: str, timeframe: str, def _ohlcv_load(self, pair: str, timeframe: str,
timerange: Optional[TimeRange] = None, timerange: Optional[TimeRange] = None,
candle_type: Optional[str] = "") -> pd.DataFrame: candle_type: str = '') -> pd.DataFrame:
""" """
Internal method used to load data for one pair from disk. Internal method used to load data for one pair from disk.
Implements the loading and conversion to a Pandas dataframe. Implements the loading and conversion to a Pandas dataframe.
@ -125,7 +125,7 @@ class HDF5DataHandler(IDataHandler):
'low': 'float', 'close': 'float', 'volume': 'float'}) 'low': 'float', 'close': 'float', 'volume': 'float'})
return pairdata return pairdata
def ohlcv_purge(self, pair: str, timeframe: str, candle_type: Optional[str] = "") -> bool: def ohlcv_purge(self, pair: str, timeframe: str, candle_type: str = '') -> bool:
""" """
Remove data for this pair Remove data for this pair
:param pair: Delete data for this pair. :param pair: Delete data for this pair.
@ -143,7 +143,7 @@ class HDF5DataHandler(IDataHandler):
pair: str, pair: str,
timeframe: str, timeframe: str,
data: pd.DataFrame, data: pd.DataFrame,
candle_type: Optional[str] = "" candle_type: str = ''
) -> None: ) -> None:
""" """
Append data to existing data structures Append data to existing data structures
@ -238,7 +238,7 @@ class HDF5DataHandler(IDataHandler):
datadir: Path, datadir: Path,
pair: str, pair: str,
timeframe: str, timeframe: str,
candle_type: Optional[str] = "" candle_type: str = ''
) -> Path: ) -> Path:
pair_s = misc.pair_to_filename(pair) pair_s = misc.pair_to_filename(pair)
if candle_type: if candle_type:

View File

@ -29,6 +29,7 @@ def load_pair_history(pair: str,
startup_candles: int = 0, startup_candles: int = 0,
data_format: str = None, data_format: str = None,
data_handler: IDataHandler = None, data_handler: IDataHandler = None,
candle_type: str = ''
) -> DataFrame: ) -> DataFrame:
""" """
Load cached ohlcv history for the given pair. Load cached ohlcv history for the given pair.
@ -64,6 +65,7 @@ def load_data(datadir: Path,
startup_candles: int = 0, startup_candles: int = 0,
fail_without_data: bool = False, fail_without_data: bool = False,
data_format: str = 'json', data_format: str = 'json',
candle_type: str = ''
) -> Dict[str, DataFrame]: ) -> Dict[str, DataFrame]:
""" """
Load ohlcv history data for a list of pairs. Load ohlcv history data for a list of pairs.
@ -105,6 +107,7 @@ def refresh_data(datadir: Path,
exchange: Exchange, exchange: Exchange,
data_format: str = None, data_format: str = None,
timerange: Optional[TimeRange] = None, timerange: Optional[TimeRange] = None,
candle_type: str = ''
) -> None: ) -> None:
""" """
Refresh ohlcv history data for a list of pairs. Refresh ohlcv history data for a list of pairs.
@ -124,8 +127,13 @@ def refresh_data(datadir: Path,
timerange=timerange, exchange=exchange, data_handler=data_handler) timerange=timerange, exchange=exchange, data_handler=data_handler)
def _load_cached_data_for_updating(pair: str, timeframe: str, timerange: Optional[TimeRange], def _load_cached_data_for_updating(
data_handler: IDataHandler) -> Tuple[DataFrame, Optional[int]]: pair: str,
timeframe: str,
timerange: Optional[TimeRange],
data_handler: IDataHandler,
candle_type: str = ''
) -> Tuple[DataFrame, Optional[int]]:
""" """
Load cached data to download more data. Load cached data to download more data.
If timerange is passed in, checks whether data from an before the stored data will be If timerange is passed in, checks whether data from an before the stored data will be
@ -162,7 +170,7 @@ def _download_pair_history(pair: str, *,
new_pairs_days: int = 30, new_pairs_days: int = 30,
data_handler: IDataHandler = None, data_handler: IDataHandler = None,
timerange: Optional[TimeRange] = None, timerange: Optional[TimeRange] = None,
candle_type: Optional[str] = "") -> bool: candle_type: str = '') -> bool:
""" """
Download latest candles from the exchange for the pair and timeframe passed in parameters Download latest candles from the exchange for the pair and timeframe passed in parameters
The data is downloaded starting from the last correct data that The data is downloaded starting from the last correct data that
@ -232,7 +240,7 @@ def refresh_backtest_ohlcv_data(exchange: Exchange, pairs: List[str], timeframes
datadir: Path, timerange: Optional[TimeRange] = None, datadir: Path, timerange: Optional[TimeRange] = None,
new_pairs_days: int = 30, erase: bool = False, new_pairs_days: int = 30, erase: bool = False,
data_format: str = None, data_format: str = None,
candle_type: Optional[str] = "") -> List[str]: candle_type: str = '') -> List[str]:
""" """
Refresh stored ohlcv data for backtesting and hyperopt operations. Refresh stored ohlcv data for backtesting and hyperopt operations.
Used by freqtrade download-data subcommand. Used by freqtrade download-data subcommand.
@ -365,7 +373,7 @@ def convert_trades_to_ohlcv(
erase: bool = False, erase: bool = False,
data_format_ohlcv: str = 'json', data_format_ohlcv: str = 'json',
data_format_trades: str = 'jsongz', data_format_trades: str = 'jsongz',
candle_type: Optional[str] = "" candle_type: str = ''
) -> None: ) -> None:
""" """
Convert stored trades data to ohlcv data Convert stored trades data to ohlcv data

View File

@ -39,7 +39,7 @@ class IDataHandler(ABC):
cls, cls,
datadir: Path, datadir: Path,
timeframe: str, timeframe: str,
candle_type: Optional[str] = '' candle_type: str = ''
) -> List[str]: ) -> 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
@ -55,7 +55,7 @@ class IDataHandler(ABC):
pair: str, pair: str,
timeframe: str, timeframe: str,
data: DataFrame, data: DataFrame,
candle_type: Optional[str] = '' candle_type: str = ''
) -> None: ) -> None:
""" """
Store ohlcv data. Store ohlcv data.
@ -68,7 +68,7 @@ class IDataHandler(ABC):
@abstractmethod @abstractmethod
def _ohlcv_load(self, pair: str, timeframe: str, def _ohlcv_load(self, pair: str, timeframe: str,
timerange: Optional[TimeRange] = None, timerange: Optional[TimeRange] = None,
candle_type: Optional[str] = '' candle_type: str = ''
) -> DataFrame: ) -> DataFrame:
""" """
Internal method used to load data for one pair from disk. Internal method used to load data for one pair from disk.
@ -83,7 +83,7 @@ class IDataHandler(ABC):
""" """
@abstractmethod @abstractmethod
def ohlcv_purge(self, pair: str, timeframe: str, candle_type: Optional[str] = '') -> bool: def ohlcv_purge(self, pair: str, timeframe: str, candle_type: str = '') -> bool:
""" """
Remove data for this pair Remove data for this pair
:param pair: Delete data for this pair. :param pair: Delete data for this pair.
@ -97,7 +97,7 @@ class IDataHandler(ABC):
pair: str, pair: str,
timeframe: str, timeframe: str,
data: DataFrame, data: DataFrame,
candle_type: Optional[str] = '' candle_type: str = ''
) -> None: ) -> None:
""" """
Append data to existing data structures Append data to existing data structures
@ -165,7 +165,7 @@ class IDataHandler(ABC):
drop_incomplete: bool = True, drop_incomplete: bool = True,
startup_candles: int = 0, startup_candles: int = 0,
warn_no_data: bool = True, warn_no_data: bool = True,
candle_type: Optional[str] = '' candle_type: str = ''
) -> DataFrame: ) -> DataFrame:
""" """
Load cached candle (OHLCV) data for the given pair. Load cached candle (OHLCV) data for the given pair.

View File

@ -42,7 +42,7 @@ class JsonDataHandler(IDataHandler):
cls, cls,
datadir: Path, datadir: Path,
timeframe: str, timeframe: str,
candle_type: Optional[str] = "" candle_type: str = ''
) -> List[str]: ) -> 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
@ -66,7 +66,7 @@ class JsonDataHandler(IDataHandler):
pair: str, pair: str,
timeframe: str, timeframe: str,
data: DataFrame, data: DataFrame,
candle_type: Optional[str] = "" candle_type: str = ''
) -> None: ) -> None:
""" """
Store data in json format "values". Store data in json format "values".
@ -94,7 +94,7 @@ class JsonDataHandler(IDataHandler):
def _ohlcv_load(self, pair: str, timeframe: str, def _ohlcv_load(self, pair: str, timeframe: str,
timerange: Optional[TimeRange] = None, timerange: Optional[TimeRange] = None,
candle_type: Optional[str] = "" candle_type: str = ''
) -> DataFrame: ) -> DataFrame:
""" """
Internal method used to load data for one pair from disk. Internal method used to load data for one pair from disk.
@ -124,7 +124,7 @@ class JsonDataHandler(IDataHandler):
infer_datetime_format=True) infer_datetime_format=True)
return pairdata return pairdata
def ohlcv_purge(self, pair: str, timeframe: str, candle_type: Optional[str] = "") -> bool: def ohlcv_purge(self, pair: str, timeframe: str, candle_type: str = '') -> bool:
""" """
Remove data for this pair Remove data for this pair
:param pair: Delete data for this pair. :param pair: Delete data for this pair.
@ -142,7 +142,7 @@ class JsonDataHandler(IDataHandler):
pair: str, pair: str,
timeframe: str, timeframe: str,
data: DataFrame, data: DataFrame,
candle_type: Optional[str] = "" candle_type: str = ''
) -> None: ) -> None:
""" """
Append data to existing data structures Append data to existing data structures
@ -222,7 +222,7 @@ class JsonDataHandler(IDataHandler):
datadir: Path, datadir: Path,
pair: str, pair: str,
timeframe: str, timeframe: str,
candle_type: Optional[str] = "" candle_type: str = ''
) -> Path: ) -> Path:
pair_s = misc.pair_to_filename(pair) pair_s = misc.pair_to_filename(pair)
if candle_type: if candle_type:

View File

@ -200,15 +200,11 @@ class Binance(Exchange):
except ccxt.BaseError as e: except ccxt.BaseError as e:
raise OperationalException(e) from e raise OperationalException(e) from e
async def _async_get_historic_ohlcv( async def _async_get_historic_ohlcv(self, pair: str, timeframe: str,
self, since_ms: int, is_new_pair: bool = False,
pair: str, raise_: bool = False,
timeframe: str, candle_type: str = ''
since_ms: int, ) -> Tuple[str, str, List]:
is_new_pair: bool,
raise_: bool = False,
candle_type: Optional[str] = ""
) -> Tuple[str, str, List]:
""" """
Overwrite to introduce "fast new pair" functionality by detecting the pair's listing date Overwrite to introduce "fast new pair" functionality by detecting the pair's listing date
Does not work for other exchanges, which don't return the earliest data when called with "0" Does not work for other exchanges, which don't return the earliest data when called with "0"

View File

@ -1311,7 +1311,7 @@ class Exchange:
def get_historic_ohlcv(self, pair: str, timeframe: str, def get_historic_ohlcv(self, pair: str, timeframe: str,
since_ms: int, is_new_pair: bool = False, since_ms: int, is_new_pair: bool = False,
candle_type: Optional[str] = "") -> List: candle_type: str = '') -> List:
""" """
Get candle history using asyncio and returns the list of candles. Get candle history using asyncio and returns the list of candles.
Handles all async work for this. Handles all async work for this.
@ -1329,7 +1329,7 @@ class Exchange:
return data return data
def get_historic_ohlcv_as_df(self, pair: str, timeframe: str, def get_historic_ohlcv_as_df(self, pair: str, timeframe: str,
since_ms: int, candle_type: Optional[str] = "") -> DataFrame: since_ms: int, candle_type: str = '') -> DataFrame:
""" """
Minimal wrapper around get_historic_ohlcv - converting the result into a dataframe Minimal wrapper around get_historic_ohlcv - converting the result into a dataframe
:param pair: Pair to download :param pair: Pair to download
@ -1344,7 +1344,7 @@ class Exchange:
async def _async_get_historic_ohlcv(self, pair: str, timeframe: str, async def _async_get_historic_ohlcv(self, pair: str, timeframe: str,
since_ms: int, is_new_pair: bool, since_ms: int, is_new_pair: bool,
raise_: bool = False, raise_: bool = False,
candle_type: Optional[str] = "" candle_type: str = ''
) -> Tuple[str, str, List]: ) -> Tuple[str, str, List]:
""" """
Download historic ohlcv Download historic ohlcv
@ -1383,8 +1383,8 @@ class Exchange:
def refresh_latest_ohlcv(self, pair_list: ListPairsWithTimeframes, *, def refresh_latest_ohlcv(self, pair_list: ListPairsWithTimeframes, *,
since_ms: Optional[int] = None, cache: bool = True, since_ms: Optional[int] = None, cache: bool = True,
candle_type: Optional[str] = "" candle_type: str = ''
) -> Dict[Tuple[str, str], DataFrame]: ) -> Dict[Tuple[str, str, str], DataFrame]:
""" """
Refresh in-memory OHLCV asynchronously and set `_klines` with the result Refresh in-memory OHLCV asynchronously and set `_klines` with the result
Loops asynchronously over pair_list and downloads all pairs async (semi-parallel). Loops asynchronously over pair_list and downloads all pairs async (semi-parallel).
@ -1450,7 +1450,12 @@ class Exchange:
return results_df return results_df
def _now_is_time_to_refresh(self, pair: str, timeframe: str) -> bool: def _now_is_time_to_refresh(
self,
pair: str,
timeframe: str,
candle_type: str = ''
) -> bool:
# Timeframe in seconds # Timeframe in seconds
interval_in_sec = timeframe_to_seconds(timeframe) interval_in_sec = timeframe_to_seconds(timeframe)
@ -1463,8 +1468,8 @@ class Exchange:
pair: str, pair: str,
timeframe: str, timeframe: str,
since_ms: Optional[int] = None, since_ms: Optional[int] = None,
candle_type: Optional[str] = "", candle_type: str = '',
) -> Tuple[str, str, List]: ) -> Tuple[str, str, str, List]:
""" """
Asynchronously get candle history data using fetch_ohlcv Asynchronously get candle history data using fetch_ohlcv
:param candle_type: :param candle_type: