Skip to content

Commit a7b9911

Browse files
committed
store:polygon data:fix - previous stop condition missed data
if segment_end passes dtend, we may stop even though we still haven;t collected all the data until dtend
1 parent abe23b0 commit a7b9911

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

alpaca_backtrader_api/alpacastore.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -518,12 +518,11 @@ def _clear_out_of_market_hours(df):
518518
segment_start = dtbegin
519519
segment_end = segment_start + timedelta(weeks=2) if \
520520
dtend - dtbegin >= timedelta(weeks=2) else dtend
521-
while segment_end <= dtend:
522-
if not cdl.empty and dtend <= cdl.index[-1]:
523-
# when resampling the data dtend is not promised to be
524-
# a part of cdl. we just want to make sure we have data
525-
# that should contain it.
526-
break
521+
while cdl.empty or cdl.index[-1] < dtend:
522+
# we want to collect data until the last row is later than
523+
# the requested dtend. we don't force it to contain dtend
524+
# because it might be missing, or we may be resampling (so
525+
# again, it will be missing)
527526
response = self.oapi.polygon.historic_agg_v2(
528527
dataname,
529528
compression,

0 commit comments

Comments
 (0)