Allow initializing handler-class just once
This commit is contained in:
parent
416517b0c9
commit
5fca17d7e1
@ -8,7 +8,7 @@ Includes:
|
|||||||
|
|
||||||
import logging
|
import logging
|
||||||
import operator
|
import operator
|
||||||
from datetime import datetime, timezone
|
from datetime import datetime
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from typing import Any, Dict, List, Optional, Tuple
|
from typing import Any, Dict, List, Optional, Tuple
|
||||||
|
|
||||||
@ -18,6 +18,7 @@ from pandas import DataFrame
|
|||||||
from freqtrade import OperationalException, misc
|
from freqtrade import OperationalException, misc
|
||||||
from freqtrade.configuration import TimeRange
|
from freqtrade.configuration import TimeRange
|
||||||
from freqtrade.data.converter import trades_to_ohlcv
|
from freqtrade.data.converter import trades_to_ohlcv
|
||||||
|
from freqtrade.data.datahandlers.idatahandler import IDataHandler
|
||||||
from freqtrade.exchange import Exchange, timeframe_to_minutes
|
from freqtrade.exchange import Exchange, timeframe_to_minutes
|
||||||
from .datahandlers import get_datahandlerclass
|
from .datahandlers import get_datahandlerclass
|
||||||
|
|
||||||
@ -105,7 +106,8 @@ def load_pair_history(pair: str,
|
|||||||
fill_up_missing: bool = True,
|
fill_up_missing: bool = True,
|
||||||
drop_incomplete: bool = True,
|
drop_incomplete: bool = True,
|
||||||
startup_candles: int = 0,
|
startup_candles: int = 0,
|
||||||
data_format: str = 'json'
|
data_format: str = 'json',
|
||||||
|
data_handler: IDataHandler,
|
||||||
) -> DataFrame:
|
) -> DataFrame:
|
||||||
"""
|
"""
|
||||||
Load cached ticker history for the given pair.
|
Load cached ticker history for the given pair.
|
||||||
@ -117,12 +119,15 @@ def load_pair_history(pair: str,
|
|||||||
:param fill_up_missing: Fill missing values with "No action"-candles
|
:param fill_up_missing: Fill missing values with "No action"-candles
|
||||||
:param drop_incomplete: Drop last candle assuming it may be incomplete.
|
:param drop_incomplete: Drop last candle assuming it may be incomplete.
|
||||||
:param startup_candles: Additional candles to load at the start of the period
|
:param startup_candles: Additional candles to load at the start of the period
|
||||||
:param data_format: Format of the data
|
:param data_format: Format of the data. Ignored if data_handler is set.
|
||||||
|
:param data_handler: Initialized data-handler to use.
|
||||||
|
Will be initialized from data_format if not set
|
||||||
:return: DataFrame with ohlcv data, or empty DataFrame
|
:return: DataFrame with ohlcv data, or empty DataFrame
|
||||||
"""
|
"""
|
||||||
|
if not data_handler:
|
||||||
HandlerClass = get_datahandlerclass(data_format)
|
HandlerClass = get_datahandlerclass(data_format)
|
||||||
loader = HandlerClass(datadir)
|
data_handler = HandlerClass(datadir)
|
||||||
return loader.ohlcv_load(pair=pair,
|
return data_handler.ohlcv_load(pair=pair,
|
||||||
timeframe=timeframe,
|
timeframe=timeframe,
|
||||||
timerange=timerange,
|
timerange=timerange,
|
||||||
fill_missing=fill_up_missing,
|
fill_missing=fill_up_missing,
|
||||||
@ -137,7 +142,8 @@ def load_data(datadir: Path,
|
|||||||
timerange: Optional[TimeRange] = None,
|
timerange: Optional[TimeRange] = None,
|
||||||
fill_up_missing: bool = True,
|
fill_up_missing: bool = True,
|
||||||
startup_candles: int = 0,
|
startup_candles: int = 0,
|
||||||
fail_without_data: bool = False
|
fail_without_data: bool = False,
|
||||||
|
data_format: str = 'json',
|
||||||
) -> Dict[str, DataFrame]:
|
) -> Dict[str, DataFrame]:
|
||||||
"""
|
"""
|
||||||
Load ticker history data for a list of pairs.
|
Load ticker history data for a list of pairs.
|
||||||
@ -149,17 +155,23 @@ def load_data(datadir: Path,
|
|||||||
:param fill_up_missing: Fill missing values with "No action"-candles
|
:param fill_up_missing: Fill missing values with "No action"-candles
|
||||||
:param startup_candles: Additional candles to load at the start of the period
|
:param startup_candles: Additional candles to load at the start of the period
|
||||||
:param fail_without_data: Raise OperationalException if no data is found.
|
:param fail_without_data: Raise OperationalException if no data is found.
|
||||||
|
:param data_handler: Initialized data-handler to use.
|
||||||
:return: dict(<pair>:<Dataframe>)
|
:return: dict(<pair>:<Dataframe>)
|
||||||
"""
|
"""
|
||||||
result: Dict[str, DataFrame] = {}
|
result: Dict[str, DataFrame] = {}
|
||||||
if startup_candles > 0 and timerange:
|
if startup_candles > 0 and timerange:
|
||||||
logger.info(f'Using indicator startup period: {startup_candles} ...')
|
logger.info(f'Using indicator startup period: {startup_candles} ...')
|
||||||
|
|
||||||
|
HandlerClass = get_datahandlerclass(data_format)
|
||||||
|
data_handler = HandlerClass(datadir)
|
||||||
|
|
||||||
for pair in pairs:
|
for pair in pairs:
|
||||||
hist = load_pair_history(pair=pair, timeframe=timeframe,
|
hist = load_pair_history(pair=pair, timeframe=timeframe,
|
||||||
datadir=datadir, timerange=timerange,
|
datadir=datadir, timerange=timerange,
|
||||||
fill_up_missing=fill_up_missing,
|
fill_up_missing=fill_up_missing,
|
||||||
startup_candles=startup_candles)
|
startup_candles=startup_candles,
|
||||||
|
data_handler=data_handler
|
||||||
|
)
|
||||||
if not hist.empty:
|
if not hist.empty:
|
||||||
result[pair] = hist
|
result[pair] = hist
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user