Subscription does not permit querying recent SIP data

hi, dear all,

I am learning to use the alpaca APIs. Actually I have used for some days to download the recent historical data which was totally fine. But today when I was trying to do the same thing (nothing changed). But with same code I have received an exception: {“message”:“subscription does not permit querying recent SIP data”}

May I ask what is the reason?

Here is my source code:

        start_date = last_timestamp - timedelta(days=2)
        end_date = datetime.now(timezone.utc) - timedelta(minutes=15)

        if end_date <= start_date:
            return

        request_params = StockBarsRequest(
            symbol_or_symbols=self.ticker,
            timeframe=TimeFrame(15, TimeFrameUnit.Minute),
            start=start_date,
            end=end_date,
        )

Best regards,
YL

@yy824 I believe the Alpaca API is reading your end parameter as not being more than 15 minutes from the previous time. Not sure if this is the correct log entry, but I found many errors like this in the logs. Notice the timestamp and the end parameter.

“level”:“warn”,“timestamp”:“2024-08-02T18:47:18.702Z”,
“host”:“data.alpaca.markets”,
“method”:“GET”,
“path”:“/v2/stocks/AAPL/bars”,
“query”:
start=2024-07-31T18:30:00+00:00
end= 2024-08-02T18:32:20.437651+00:00
timeframe=15Min

The end parameter must be before 18:32:18.702 (ie timestamp - 15Min), but the request was for 18:32:20.437651 which was after that time.

The issue is probably your local machine’s clock is not synched to NIS time. Check out this page for how to do that. Alternately, rather than calling datetime.now(timezone.utc). to get the time, make a cal to the Alpaca’s clock API. To test if that is the issue, maybe try subtracting 15:05 Min from the current time.

Could that be the issue?

One more tip: if you’d like to set your end date to 15 minutes ago because you’re on the free plan, you can simply leave it out (not set end at all) and in that case it will default to exactly what you want.

Hi, Dan,

Thank you very much! I think it is the issue that my PC has actually different clock than Alpaca’s which caused the issue.

Best regards,
YL

Hi, Gergely,

thank you very much! I have removed the end_data, it worked for me.

Best regards,
YL