Skip to content

Commit

Permalink
add data v2 changes
Browse files Browse the repository at this point in the history
  • Loading branch information
camelpac committed Jun 19, 2021
1 parent 1714732 commit df46fee
Showing 1 changed file with 7 additions and 13 deletions.
20 changes: 7 additions & 13 deletions alpaca_backtrader_api/alpacastore.py
Original file line number Diff line number Diff line change
Expand Up @@ -512,15 +512,16 @@ def _iterate_api_calls():
"""
got_all = False
curr = end
response = []
response = pd.DataFrame()
while not got_all:
timeframe = _granularity_to_timeframe(granularity)
r = self.oapi.get_bars(dataname, timeframe, start, curr)
r = self.oapi.get_bars(dataname,
timeframe,
start.isoformat(),
curr.isoformat())
if r:
earliest_sample = r[0].t
r = r._raw
r.extend(response)
response = r
response = pd.concat([r.df, response], axis=0)
if earliest_sample <= (pytz.timezone(NY).localize(
start) if not start.tzname() else start):
got_all = True
Expand Down Expand Up @@ -592,19 +593,12 @@ def _resample(df):
timeframe, start, end)._raw
else:
response = _iterate_api_calls()
for bar in response:
# Aggs are in milliseconds, we multiply by 1000 to
# change seconds to ms
bar['t'] *= 1000
response = Aggs({"results": response})

cdl = response.df
cdl = response
if granularity == Granularity.Minute:
cdl = _clear_out_of_market_hours(cdl)
cdl = _drop_early_samples(cdl)
if compression != 1:
response = _resample(cdl)
# response = _back_to_aggs(cdl)
else:
response = cdl
response = response.dropna()
Expand Down

0 comments on commit df46fee

Please sign in to comment.