Internal Server Error Code 500 : Trade data from API v2

Hello - While fetching data from API v2, I get b’{“code”:50010000,“message”:“internal server error occurred”}’
I was trying to fetch Trade data for AAPL for March 5th, After about 15 call, 16th call fails consisitently.

Can you please advise!

Thanks!

@Dan_Whitnable_Alpaca anyone provide any insight on this? this is exactly my issue as well

Seeing this obnoxiously high today, as in every several minutes. Anyone? Bueller… Bueller…

OK so. ListHistoricalBarAsync no longer throws the 500 error but is extremely slow to respond…

Now I get a “Too many requests” error when using BarSetAsync. (using latest on NuGet pkmg). I’m using ListHistoricalBarAsync to rebuild historical data and I’m using BarSeetAsync to get data while application is running to get the latest bars. SO my question again, why is there a rate limit on pro market data?

Too Many Requests
StackTrace: at Alpaca.Markets.HttpResponseMethodExtensions.DeserializeAsync[TApi,TJson](HttpResponseMessage response)
at Alpaca.Markets.HttpClientExtensions.callAndDeserializeAsync[TApi,TJson](HttpClient httpClient, HttpRequestMessage request, CancellationToken cancellationToken, IThrottler throttler)
at Alpaca.Markets.HttpClientExtensions.callAndDeserializeAsync[TApi,TJson](HttpClient httpClient, HttpMethod method, Uri endpointUri, CancellationToken cancellationToken, IThrottler throttler)
at Alpaca.Markets.HttpClientExtensions.GetAsync[TKeyApi,TValueApi,TKeyJson,TValueJson](HttpClient httpClient, UriBuilder uriBuilder, IEqualityComparer`1 comparer, CancellationToken cancellationToken)

@dynamic3 Could you please provide code snippet for your GetBarSetAsync call? How many symbols do you use for this call?

Here is my method to get the data that is causing “Too many requests”

public static async Task GetBatchData(List<string> alpacaSymbols)
 {
 List<Task> tasks = new List<Task>();
 foreach(var symbolCode in alpacaSymbols)
 {
   tasks.Add(Task.Run() => GetNewBars(symbolCode);
 }
await Task.WhenAll(tasks);
}

public async Task GetNewBars(string symbolCode)
{
var iclient = Alpaca.Markets.Environments.Live.GetAlpacaDataClient(new SecretKey(LIVE_API_KEY, LIVE_API_SECRET));
                BarSetRequest barRequest = new BarSetRequest(symbolCode, TimeFrame.Minute);
                barRequest.Limit = 1000;
var raw_bars= await iclient.GetBarSetAsync(barRequest);
}

The GetBarSetAsync is part of Alpaca Data API v1 and therefore it follows the rate limit rule for this API. You just try to call a lot of similar requests in parallel and as expected server returns an HTTP 429 error (Too many requests) on some of your requests. I suggest you batch your requests - the GetBarSetAsync supports up
to 100 symbols in requests in the current NuGet package version.

The reason for the slow ListHistoricalBarAsync method execution is the same - this API also is subject to a rate limit (at least for now) so the server can return the same response. Fortunately, (for most users) this method tries to repeat requests several times with random delay. As a result of this built-in throttling, your code will receive results with significant delay.

The general rule for preventing big delays - try to minimize the number of parallel requests: batch them if possible and request only required data.

In the next release of the NuGet package, I’ll increase the max allowed batch size up to 200 (the actual max value already supported by the server) and will add throttling for the GetBarSetAsync.

When will there be a V2 equivalent of this call? My concern is using a method that may be deprecated in the future.

There is no v2 equivalent for requesting bars for several symbols in one request.

I don’t know about the v1 deprecation schedule and if you need minute bars you can, of course, use the ListHistoricalBarsAsync method in the same way as you use the GetBarSetAsync method now (with a single symbol). But again, there is no magic in SDK - if the server rejects a request due to rate limit SDK just repeats it with some delay.

Another option is streaming - there is no limit of minute bars subscription on both Basic and Pro plans so you can just subscribe on such bars and listen for updates instead of pulling the same data.

I’m using ListHistoricalBarsAsync to “catch” up the bars to today; and then using GetBarSetAsync for last N bars in a 15-30 sec cycle. I suppose I need to leave this running over the weekend to meaningfully catchup; then I can listen for new bars with Streaming or continue to use GetBarSetAsync until it’s no longer supported in the SDK.