Merge pull request #2179 from freqtrade/timeframe_use_ccxt
[minor] Use ccxt methods to round timeframe
This commit is contained in:
commit
6d1c54ed92
@ -14,6 +14,7 @@ from typing import Any, Dict, List, Optional, Tuple
|
|||||||
import arrow
|
import arrow
|
||||||
import ccxt
|
import ccxt
|
||||||
import ccxt.async_support as ccxt_async
|
import ccxt.async_support as ccxt_async
|
||||||
|
from ccxt.base.decimal_to_precision import ROUND_UP, ROUND_DOWN
|
||||||
from pandas import DataFrame
|
from pandas import DataFrame
|
||||||
|
|
||||||
from freqtrade import (DependencyException, InvalidOrderException,
|
from freqtrade import (DependencyException, InvalidOrderException,
|
||||||
@ -808,11 +809,9 @@ def timeframe_to_prev_date(timeframe: str, date: datetime = None) -> datetime:
|
|||||||
"""
|
"""
|
||||||
if not date:
|
if not date:
|
||||||
date = datetime.now(timezone.utc)
|
date = datetime.now(timezone.utc)
|
||||||
timeframe_secs = timeframe_to_seconds(timeframe)
|
|
||||||
# Get offset based on timerame_secs
|
new_timestamp = ccxt.Exchange.round_timeframe(timeframe, date.timestamp() * 1000,
|
||||||
offset = date.timestamp() % timeframe_secs
|
ROUND_DOWN) // 1000
|
||||||
# Subtract seconds passed since last offset
|
|
||||||
new_timestamp = date.timestamp() - offset
|
|
||||||
return datetime.fromtimestamp(new_timestamp, tz=timezone.utc)
|
return datetime.fromtimestamp(new_timestamp, tz=timezone.utc)
|
||||||
|
|
||||||
|
|
||||||
@ -823,9 +822,8 @@ def timeframe_to_next_date(timeframe: str, date: datetime = None) -> datetime:
|
|||||||
:param date: date to use. Defaults to utcnow()
|
:param date: date to use. Defaults to utcnow()
|
||||||
:returns: date of next candle (with utc timezone)
|
:returns: date of next candle (with utc timezone)
|
||||||
"""
|
"""
|
||||||
prevdate = timeframe_to_prev_date(timeframe, date)
|
if not date:
|
||||||
timeframe_secs = timeframe_to_seconds(timeframe)
|
date = datetime.now(timezone.utc)
|
||||||
|
new_timestamp = ccxt.Exchange.round_timeframe(timeframe, date.timestamp() * 1000,
|
||||||
# Add one interval to previous candle
|
ROUND_UP) // 1000
|
||||||
new_timestamp = prevdate.timestamp() + timeframe_secs
|
|
||||||
return datetime.fromtimestamp(new_timestamp, tz=timezone.utc)
|
return datetime.fromtimestamp(new_timestamp, tz=timezone.utc)
|
||||||
|
@ -1531,7 +1531,7 @@ def test_timeframe_to_prev_date():
|
|||||||
assert timeframe_to_prev_date(interval, date) == result
|
assert timeframe_to_prev_date(interval, date) == result
|
||||||
|
|
||||||
date = datetime.now(tz=timezone.utc)
|
date = datetime.now(tz=timezone.utc)
|
||||||
assert timeframe_to_prev_date("5m", date) < date
|
assert timeframe_to_prev_date("5m") < date
|
||||||
|
|
||||||
|
|
||||||
def test_timeframe_to_next_date():
|
def test_timeframe_to_next_date():
|
||||||
@ -1556,4 +1556,4 @@ def test_timeframe_to_next_date():
|
|||||||
assert timeframe_to_next_date(interval, date) == result
|
assert timeframe_to_next_date(interval, date) == result
|
||||||
|
|
||||||
date = datetime.now(tz=timezone.utc)
|
date = datetime.now(tz=timezone.utc)
|
||||||
assert timeframe_to_next_date("5m", date) > date
|
assert timeframe_to_next_date("5m") > date
|
||||||
|
4
setup.py
4
setup.py
@ -45,7 +45,7 @@ setup(name='freqtrade',
|
|||||||
tests_require=['pytest', 'pytest-mock', 'pytest-cov'],
|
tests_require=['pytest', 'pytest-mock', 'pytest-cov'],
|
||||||
install_requires=[
|
install_requires=[
|
||||||
# from requirements-common.txt
|
# from requirements-common.txt
|
||||||
'ccxt>=1.18',
|
'ccxt>=1.18.1080',
|
||||||
'SQLAlchemy',
|
'SQLAlchemy',
|
||||||
'python-telegram-bot',
|
'python-telegram-bot',
|
||||||
'arrow',
|
'arrow',
|
||||||
@ -76,7 +76,7 @@ setup(name='freqtrade',
|
|||||||
'plot': plot,
|
'plot': plot,
|
||||||
'all': all_extra,
|
'all': all_extra,
|
||||||
'jupyter': jupyter,
|
'jupyter': jupyter,
|
||||||
|
|
||||||
},
|
},
|
||||||
include_package_data=True,
|
include_package_data=True,
|
||||||
zip_safe=False,
|
zip_safe=False,
|
||||||
|
Loading…
Reference in New Issue
Block a user