Skip to content

Commit

Permalink
- TICKS data download in some cases might miss some days (#16)
Browse files Browse the repository at this point in the history
  • Loading branch information
ffeast committed Feb 6, 2021
1 parent 721ff74 commit 53b5678
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 14 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [4.0.2]
### Fixed
- TICKS data download in some cases might miss some days (https://github.com/ffeast/finam-export/issues/16)

## [4.0.1]
### Fixed
- version in setup.py
Expand Down
12 changes: 6 additions & 6 deletions finam/interval.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,19 @@ def split_interval(start_date, end_date, timeframe):
if end_date < start_date:
raise ValueError('start_date must be >= end_date, but got {} and {}'
.format(start_date, end_date))
delta_days = (end_date - start_date).days
delta_days = (end_date - start_date).days + 1
max_days = _MAX_DAYS_PER_TIMEFRAME[timeframe]
chunks_count, remainder = divmod(delta_days, max_days)
if remainder != 0:
chunks_count += 1
if chunks_count <= 1:
return ((start_date, end_date),)
chunks = []
delta = 0
offset_start = timedelta(0)
offset_end = timedelta(max_days)
for chunk_i in range(chunks_count):
offset_start = timedelta(chunk_i * max_days + delta)
offset_end = timedelta((chunk_i + 1) * max_days)
chunks.append((start_date + offset_start,
min(start_date + offset_end, end_date)))
delta = 1
min(start_date + offset_end - timedelta(1), end_date)))
offset_start += timedelta(max_days)
offset_end += timedelta(max_days)
return tuple(chunks)
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# coding: utf8
from setuptools import setup

VERSION = '4.0.1'
VERSION = '4.0.2'

long_description = open('README.md').read()

Expand Down
25 changes: 18 additions & 7 deletions tests/tests_unit.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,16 +127,27 @@ def test_lookup_by_market_and_codes(self):
(date(2016, 1, 1), date(2016, 1, 2), Timeframe.MINUTES1,
((date(2016, 1, 1), date(2016, 1, 2)),)),
(date(2018, 1, 1), date(2020, 9, 15), Timeframe.MINUTES1,
((date(2018, 1, 1), date(2019, 1, 1)),
(date(2019, 1, 2), date(2020, 1, 1)),
(date(2020, 1, 2), date(2020, 9, 15)),)),
((date(2018, 1, 1), date(2018, 12, 31)),
(date(2019, 1, 1), date(2019, 12, 31)),
(date(2020, 1, 1), date(2020, 9, 15)),)),
(date(2019, 3, 1), date(2020, 3, 1), Timeframe.MINUTES1,
((date(2019, 3, 1), date(2020, 2, 29)),
(date(2020, 3, 1), date(2020, 3, 1)),)),
((date(2019, 3, 1), date(2020, 2, 28)),
(date(2020, 2, 29), date(2020, 3, 1)),)),
(date(2018, 3, 1), date(2019, 3, 1), Timeframe.MINUTES1,
((date(2018, 3, 1), date(2019, 3, 1)),)),
((date(2018, 3, 1), date(2019, 2, 28)),
(date(2019, 3, 1), date(2019, 3, 1)),)),
(date(2019, 3, 1), date(2020, 2, 29), Timeframe.MINUTES1,
((date(2019, 3, 1), date(2020, 2, 29)),))
((date(2019, 3, 1), date(2020, 2, 28)),
(date(2020, 2, 29), date(2020, 2, 29)),)),
(date(2016, 1, 1), date(2016, 1, 1), Timeframe.TICKS,
((date(2016, 1, 1), date(2016, 1, 1)),)),
(date(2020, 2, 29), date(2020, 3, 1), Timeframe.TICKS,
((date(2020, 2, 29), date(2020, 2, 29)),
(date(2020, 3, 1), date(2020, 3, 1)),)),
(date(2020, 1, 30), date(2020, 2, 1), Timeframe.TICKS,
((date(2020, 1, 30), date(2020, 1, 30)),
(date(2020, 1, 31), date(2020, 1, 31)),
(date(2020, 2, 1), date(2020, 2, 1)),)),
])
def test_split_interval(start_date, end_date, interval, expected):
actual = split_interval(start_date, end_date, interval)
Expand Down

0 comments on commit 53b5678

Please sign in to comment.