Issue Retrieving Minutes Data

Hi ,
i am new to Algo trading and I am trying to retrieve minutes data using below C# code .

My program stop moving further after it hits ListHistoricalBarsAsync line and its not giving me the minutes barset info .

            var into = DateTime.Now;
            var from = into.Subtract(TimeSpan.FromMinutes(25));
            var barSet = await alpacaDataClient.ListHistoricalBarsAsync(
                new HistoricalBarsRequest(symbol, from, into, BarTimeFrame.Minute).WithPageSize(20));
            var bars = barSet.Items;

Note - I am able to retrieve day chart from ListHistoricalBarsAsync , But having issues with the above minutes code . Also I am using free base plan .

Kindly suggest .

Thanks
Suren

Are you sure that it really ‘stops’ at this point? Maybe it just throws some exception that your code doesn’t handle properly? I’ve just tried your code snippet and it works fine on my side. Just a few comments:

  1. Try to use the UTC time in your code - SDK returns most timestamps in UTC and it’s always better to use a single timezone in your code.
  2. Add exception handling around this call - SDK tries to repeat HTTP GET calls several times due to server-side rate limitations. it can increase overall execution time and if all attempts will fail SDK throws an exception.

Thank you for looking at my issue .

I am able to find the root cause . Since i am using free version it throws me an exception while trying to retrieve the current market data as below .

“Alpaca.Markets.RestClientErrorException: ‘your subscription does not permit querying data from the past 15 minutes’”

i have modified the code to go back in time before 15 mins to get it resolved .

But is this how we are supposed to test it out even in paper trading ?

        var into = DateTime.UtcNow.AddMinutes(-15);
        var from = into.Subtract(TimeSpan.FromMinutes(90));
        HistoricalBarsRequest barRequest = new HistoricalBarsRequest(ticker, from, into, BarTimeFrame.Minute);
        var barSet = await client.ListHistoricalBarsAsync(barRequest);
        var bars = barSet.Items;

Thanks,
Suren

I see only one option - trial the `Unlimited’ market data plan. AFAIK it doesn’t have such limitations and provides more accurate data.

I am getting the below error while trying to retrieve the latest market data .

i am using latest Alpaca.markets version 5.0.3.10 NuGet package

You set up endTime to 5 minutes from now and the server restricts this request due to your subscription limitations. The error message received from the server-side is clear. Maybe API should return data even for timestamps pointing to the future but it’s just server implementation details.

Unfortunately, you are unable to do anything with it on the client side. You should use the right timestamps or use a higher subscription level.