Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 11 additions & 7 deletions freqtrade/data/converter/converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,11 @@ def ohlcv_to_dataframe(
df = DataFrame(ohlcv, columns=cols)

# Floor date to seconds to account for exchange imprecisions
df["date"] = to_datetime(df["date"], unit="ms", utc=True).dt.floor("s")
from freqtrade.exchange import timeframe_to_floor_freq

resample_interval = timeframe_to_floor_freq(timeframe)

df["date"] = to_datetime(df["date"], unit="ms", utc=True).dt.floor(resample_interval)

# Some exchanges return int values for Volume and even for OHLC.
# Convert them since TA-LIB indicators used in the strategy assume floats
Expand All @@ -59,14 +63,14 @@ def ohlcv_to_dataframe(


def clean_ohlcv_dataframe(
data: DataFrame, timeframe: str, pair: str, *, fill_missing: bool, drop_incomplete: bool
dataframe: DataFrame, timeframe: str, pair: str, *, fill_missing: bool, drop_incomplete: bool
) -> DataFrame:
"""
Cleanse a OHLCV dataframe by
* Grouping it by date (removes duplicate tics)
* dropping last candles if requested
* Filling up missing data (if requested)
:param data: DataFrame containing candle (OHLCV) data.
:param dataframe: DataFrame containing candle (OHLCV) data.
:param timeframe: timeframe (e.g. 5m). Used to fill up eventual missing data
:param pair: Pair this data is for (used to warn if fillup was necessary)
:param fill_missing: fill up missing candles with 0 candles
Expand All @@ -75,7 +79,7 @@ def clean_ohlcv_dataframe(
:return: DataFrame
"""
# group by index and aggregate results to eliminate duplicate ticks
data = data.groupby(by="date", as_index=False, sort=True).agg(
dataframe = dataframe.groupby(by="date", as_index=False, sort=True).agg(
{
"open": "first",
"high": "max",
Expand All @@ -86,13 +90,13 @@ def clean_ohlcv_dataframe(
)
# eliminate partial candle
if drop_incomplete:
data.drop(data.tail(1).index, inplace=True)
dataframe.drop(dataframe.tail(1).index, inplace=True)
logger.debug("Dropping last candle")

if fill_missing:
return ohlcv_fill_up_missing_data(data, timeframe, pair)
return ohlcv_fill_up_missing_data(dataframe, timeframe, pair)
else:
return data
return dataframe


def ohlcv_fill_up_missing_data(dataframe: DataFrame, timeframe: str, pair: str) -> DataFrame:
Expand Down
1 change: 1 addition & 0 deletions freqtrade/exchange/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
validate_exchange,
)
from freqtrade.exchange.exchange_utils_timeframe import (
timeframe_to_floor_freq,
timeframe_to_minutes,
timeframe_to_msecs,
timeframe_to_next_date,
Expand Down
Loading
Loading