fix: add dynamic timeframe_floor freq
fixes problems where funding-rates may be on the 1st second of the hour (observed on gate from time to time)
This commit is contained in:
@@ -39,7 +39,11 @@ def ohlcv_to_dataframe(
|
|||||||
df = DataFrame(ohlcv, columns=cols)
|
df = DataFrame(ohlcv, columns=cols)
|
||||||
|
|
||||||
# Floor date to seconds to account for exchange imprecisions
|
# 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.
|
# Some exchanges return int values for Volume and even for OHLC.
|
||||||
# Convert them since TA-LIB indicators used in the strategy assume floats
|
# Convert them since TA-LIB indicators used in the strategy assume floats
|
||||||
|
|||||||
@@ -30,6 +30,7 @@ from freqtrade.exchange.exchange_utils import (
|
|||||||
validate_exchange,
|
validate_exchange,
|
||||||
)
|
)
|
||||||
from freqtrade.exchange.exchange_utils_timeframe import (
|
from freqtrade.exchange.exchange_utils_timeframe import (
|
||||||
|
timeframe_to_floor_freq,
|
||||||
timeframe_to_minutes,
|
timeframe_to_minutes,
|
||||||
timeframe_to_msecs,
|
timeframe_to_msecs,
|
||||||
timeframe_to_next_date,
|
timeframe_to_next_date,
|
||||||
|
|||||||
@@ -29,6 +29,21 @@ def timeframe_to_msecs(timeframe: str) -> int:
|
|||||||
return ccxt.Exchange.parse_timeframe(timeframe) * 1000
|
return ccxt.Exchange.parse_timeframe(timeframe) * 1000
|
||||||
|
|
||||||
|
|
||||||
|
def timeframe_to_floor_freq(timeframe: str) -> str:
|
||||||
|
"""
|
||||||
|
Translates the timeframe interval value written in the human readable
|
||||||
|
form ('1m', '5m', '1h', '1d', '1w', etc.) to the desired floor frequency used by pandas
|
||||||
|
("1m", "5m", "1h", "1d", "1w", etc.).
|
||||||
|
Will use minute for most higher timeframes.
|
||||||
|
"""
|
||||||
|
timeframe_seconds = timeframe_to_seconds(timeframe)
|
||||||
|
timeframe_minutes = timeframe_seconds // 60
|
||||||
|
if timeframe_minutes <= 1:
|
||||||
|
return "1s"
|
||||||
|
else:
|
||||||
|
return "1min"
|
||||||
|
|
||||||
|
|
||||||
def timeframe_to_resample_freq(timeframe: str) -> str:
|
def timeframe_to_resample_freq(timeframe: str) -> str:
|
||||||
"""
|
"""
|
||||||
Translates the timeframe interval value written in the human readable
|
Translates the timeframe interval value written in the human readable
|
||||||
|
|||||||
Reference in New Issue
Block a user