simplify timeframe_next_date calculation

This commit is contained in:
Matthias 2019-08-12 20:04:19 +02:00
parent 200b6ea10f
commit 2600cb7b64
2 changed files with 7 additions and 7 deletions

View File

@ -5,6 +5,8 @@ from freqtrade.exchange.exchange import (is_exchange_bad, # noqa: F401
available_exchanges)
from freqtrade.exchange.exchange import (timeframe_to_seconds, # noqa: F401
timeframe_to_minutes,
timeframe_to_msecs)
timeframe_to_msecs,
timeframe_to_next_date,
timeframe_to_prev_date)
from freqtrade.exchange.kraken import Kraken # noqa: F401
from freqtrade.exchange.binance import Binance # noqa: F401

View File

@ -817,11 +817,9 @@ def timeframe_to_next_date(timeframe: str, date: datetime = None) -> datetime:
:param date: date to use. Defaults to utcnow()
:returns: date of next candle (with utc timezone)
"""
if not date:
date = datetime.utcnow()
prevdate = timeframe_to_prev_date(timeframe, date)
timeframe_secs = timeframe_to_seconds(timeframe)
# Get offset to prev timeframe
offset = date.timestamp() % timeframe_secs
# Add remaining seconds to next timeframe
new_timestamp = date.timestamp() + (timeframe_secs - offset)
# Add one interval to previous candle
new_timestamp = prevdate.timestamp() + timeframe_secs
return datetime.fromtimestamp(new_timestamp, tz=timezone.utc)