Minute bar limit

I have pro subscription plan… I’m using Python API to get minute bar data for 5 days. The total number of bars is max 1950. Per documentation, the limit of bars is 10,000. However when I run the code below:
barset = api.get_barset(‘AAPL’, ‘day’, limit=1950)
I receive an error:
alpaca_trade_api.rest.APIError: maximum 1000 bars per symbol per request
What’s the issue?

@Amir The get_barset method, behind the scenes, is fetching data using the older ‘v1’ data API /v1/bars/{timeframe}. That has a limit of 1000 bars.

The method referenced in the above documentation link is for the ‘v2’ data API /v2/stocks/{symbol}/bars which does have a larger 10,000 limit.

The Python SDK method for the v2 method is get_bars. So something like this should work

import pandas as pd
import alpaca_trade_api as alpacaapi
from alpaca_trade_api.rest import TimeFrame

start_time = pd.to_datetime('2021-06-28 04:00:00', utc=True)
end_time = pd.to_datetime('2021-06-28 23:00', utc=True)

symbol = 'AAPL'

bars = api.get_bars(symbol, TimeFrame.Minute, start=start_time.isoformat(), end=end_time.isoformat(), adjustment='raw').df

bars.index = bars.index.tz_convert('America/New_York')

The v1 data APIs are going away in August so hopefully there won’t be this confusion going forward.

.

3 Likes