Skip to content

Commit

Permalink
Merge pull request freqtrade#823 from creslinux/timerange_unixtime_ar…
Browse files Browse the repository at this point in the history
…gument

Timerange unixtime argument
  • Loading branch information
vertti authored Jun 3, 2018
2 parents a657e3d + 94e586c commit 7edafbb
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
2 changes: 2 additions & 0 deletions docs/backtesting.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ The full timerange specification:
- Use tickframes till 2018/01/31: `--timerange=-20180131`
- Use tickframes since 2018/01/31: `--timerange=20180131-`
- Use tickframes since 2018/01/31 till 2018/03/01 : `--timerange=20180131-20180301`
- Use tickframes between POSIX timestamps 1527595200 1527618600:
`--timerange=1527595200-1527618600`


**Update testdata directory**
Expand Down
9 changes: 7 additions & 2 deletions freqtrade/arguments.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,9 @@ def parse_timerange(text: str) -> Optional[Tuple[List, int, int]]:
syntax = [(r'^-(\d{8})$', (None, 'date')),
(r'^(\d{8})-$', ('date', None)),
(r'^(\d{8})-(\d{8})$', ('date', 'date')),
(r'^-(\d{10})$', (None, 'date')),
(r'^(\d{10})-$', ('date', None)),
(r'^(\d{10})-(\d{10})$', ('date', 'date')),
(r'^(-\d+)$', (None, 'line')),
(r'^(\d+)-$', ('line', None)),
(r'^(\d+)-(\d+)$', ('index', 'index'))]
Expand All @@ -236,14 +239,16 @@ def parse_timerange(text: str) -> Optional[Tuple[List, int, int]]:
if stype[0]:
start = rvals[index]
if stype[0] == 'date':
start = arrow.get(start, 'YYYYMMDD').timestamp
start = int(start) if len(start) == 10 \
else arrow.get(start, 'YYYYMMDD').timestamp
else:
start = int(start)
index += 1
if stype[1]:
stop = rvals[index]
if stype[1] == 'date':
stop = arrow.get(stop, 'YYYYMMDD').timestamp
stop = int(stop) if len(stop) == 10 \
else arrow.get(stop, 'YYYYMMDD').timestamp
else:
stop = int(stop)
return stype, start, stop
Expand Down
6 changes: 6 additions & 0 deletions freqtrade/tests/test_arguments.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,12 @@ def test_parse_timerange_incorrect() -> None:
timerange = Arguments.parse_timerange('20100522-20150730')
assert timerange == (('date', 'date'), 1274486400, 1438214400)

# Added test for unix timestamp - BTC genesis date
assert (('date', None), 1231006505, None) == Arguments.parse_timerange('1231006505-')
assert ((None, 'date'), None, 1233360000) == Arguments.parse_timerange('-1233360000')
timerange = Arguments.parse_timerange('1231006505-1233360000')
assert timerange == (('date', 'date'), 1231006505, 1233360000)

with pytest.raises(Exception, match=r'Incorrect syntax.*'):
Arguments.parse_timerange('-')

Expand Down

0 comments on commit 7edafbb

Please sign in to comment.