Data.alpaca.markets does not return data for requested dates

Hi Alpaca Staff and @hitoshi,
This is similar to Data.alpaca.markets returns quotes from incorrect dates in the programming forum.

I’m using R’s httr:GET to request the following URL:
"https://data.alpaca.markets/v1/bars/5Min?symbols=FB,NFLX,AMZN,MSFT&limit=1000&start=2020-02-05T09:30:00-0500&end=2020-02-24T14:45:00-0500"
I’ve also tried the request with the URL encoded form of the request:
"https://data.alpaca.markets/v1/bars/5Min?symbols=FB%2CNFLX%2CAMZN%2CMSFT&limit=1000&start=2020-02-05T09%3A30%3A00-0500&end=2020-02-24T14%3A45%3A00-0500"
However, the data that I get back from either request is for the following date range:
"2020-03-02T09:50:00" to "2020-03-18T15:55:00"
Any ideas as to what’s going on here?

I posted a couple days ago of my bar data with incorrect timestamps. It appears that leap day may have caused some issues. Not sure if this is related to your issue.

Thanks @winser, yes I’ve noticed a few threads about people encountering issues with the lead year. That would seem like a high priority fix - I would wonder why they haven’t fixed it nearly three weeks out now?

Yeah, idk. Not sure if they’re not aware or if it’s not a high priority.

It’s bizarre because you would think that being able to access the appropriate data is a high priority. I’m submitting a support ticket about it.

I am having the same problem with the python sdk, I am trying a workaround with numpy and to removbe the outliers but this is really annoying

I have made a workaround for python, it will filter out the bad values from the v value, feel free to transpose it to other language.

import alpaca_trade_api as tradeapi
import time

from datetime import datetime

def price(stock):
API_KEY = “”
API_SECRET = “”
APCA_API_BASE_URL = “https://paper-api.alpaca.markets

api = tradeapi.REST(API_KEY, API_SECRET, APCA_API_BASE_URL, 'v2')
now = datetime.now()
dt_string = now.strftime("%d/%m/%Y %H:%M:%S")
# Get daily price data for AAPL over the last 5 trading days.
barset = api.get_barset(symbols=stock, timeframe='1Min', limit=1, start=dt_string)
aapl_bars = barset[stock]
print(barset)
if aapl_bars[0].v > 10000:
    while aapl_bars[0].v > 2000:
        barset = api.get_barset(symbols=stock, timeframe='1Min', limit=1, start=dt_string)
        aapl_bars = barset[stock]
        print(aapl_bars)
        time.sleep(1)
    else:
        current = aapl_bars[0].c

        return current

else:
    # See how much AAPL moved in that timeframe.
    #print(aapl_bars)
    current = aapl_bars[0].c

    return current

def get(stock):
first = price(stock)

return first

fff = get(“AAPL”)
print(fff)

@Ryan I mostly use R, but Python is somewhat readable for me. It appears to me that you’re filtering out outliers in volume with this script?
The issue I’m describing in this thread is that the API is not returning data for the requested dates, it returns an arbitrary date range.
Does api.get_barset actually use a v2 API? I’ve only found that v1 works for data.alpaca.markets.
Additionally, perhaps you could check to see if the date issue is reproducible?
You would just need to do something like:

from datetime import datetime

start = datetime.strptime('2020-02-05 09:30:00-0500', "%Y-%m-%d %H:%M:%S-%z")
end = datetime.strptime('2020-02-24 014:45:00-0500', "%Y-%m-%d %H:%M:%S-%z")
api.get_barset(symbols=stock, timeframe='5Min', limit=1000, start=start, end = end)

Which should return data between those dates. Does it?

Hi all,

Thanks for the report on the data integrity issue and we’ve looked at it over the weekend, and found one issue that has been fixed by now. It should be fine now but there could be still something after the market opens, so we will monitor it.

Awesome. Mine is working.

1 Like

Hi @hitoshi, thank you for the response!
I received a response on the ticket I submitted as well. I tested it again as of this morning using the following URL:
https://data.alpaca.markets/v1/bars/5Min?symbols=FB,NFLX,AMZN,MSFT&limit=1000&start=2020-02-11T09:30:00-0500&end=2020-02-28T14:45:00-0500
and the API is returning data for a range of slightly different dates:
2020-03-05 10:00:00 EST to 2020-03-23 15:55:00 EDT
but not the dates requested.
As far as I can tell the issue persists

The timestamp format for the parameters “start” and “end” need a colon for the time offset part. I know it’s a bit too strict but this way you can make it work.

1 Like

This did the trick! Thank you for spotting this!

I’m still seeing a problem with this. I’m trying to get current data (4-11-2020) as of this post. And it’s returning candles from March 31. I have omitted any of the filtering dates so it should be returning the most recent data, right?

Also seems like the aggregate endpoint only returns data for 2 weeks at the moment from the start date - eg, if I make a request for data starting from April 1st until today, it will only go to the 18th or so. It’s useless if I want to get hourly data for a 90 period EMA or something

Edit - this might be a Polygon issue, I was going directly through the Polygon API

A few issues using the tradeapi; the timeframe of 15Min isn’t getting respected (still returns minutes)

df = self.client.get_barset(
                symbol,
                timeframe='15min',
                limit=1000,
                start='2020-04-06',
                end='2020-04-21').df

And the DataFrame from get_barset() looks messed up, for example, exporting to_csv():

,DBX,DBX,DBX,DBX,DBX
,open,high,low,close,volume
time,,,,,
2020-04-20 15:38:00-04:00,20.255,20.255,20.21,20.21,3214
...

This is what print(df.head(10)) returns:

                              DBX                               
                             open    high     low   close volume
time                                                            
2020-04-20 15:38:00-04:00  20.255  20.255  20.210  20.210   3214

It would also be nice to have 1 hour intervals without having to resample.

Python API version is alpaca-trade-api 0.46

@nabeel It has to be 15Min I believe, case sensitive.

Can you post the URL you are trying to call?

I seem to be having problems querying for specific dates and times, as well. For the sake of illustration, I am requesting the URL

https://data.alpaca.markets/v1/bars/1Min?symbols=AAPL&limit=1&start=2020-05-12T12:30:00-04:00

which returns the data

{"AAPL":[{"t":1590782460,"o":318.5,"h":318.5,"l":318.5,"c":318.5,"v":2262}]}

That time stamp corresponds to Fri May 29 16:01:00 EDT 2020. So, the last bar as the market closed today.

I was able to reproduce. That’s puzzling indeed. Why would you need a single bar of data though? I can’t seem to figure out a use case for a query like this.

The Last Quote endpoint from Polygon is better suited for getting the current asking price, if that’s what you’re trying to figure out how to do?