I have been struggling with getting historic news requests to work so I thought I would post what I had to do. Fair warning its ugly but it seems to get the info. If anyone has a better solution please let me know.
String KEY_ID = "enteryourID";
String SECRET_KEY = "EnteryourKey";
List<string> symbols = new List<string>(); // eventually I would pull my full list of symbols
symbols.Add("F");
symbols.Add("U");
symbols.AsEnumerable();
DateTime nowTime = DateTime.Now.ToUniversalTime();
DateTime pastTime = DateTime.Now.AddDays(-4).ToUniversalTime();
TimeSpan newsTime = new TimeSpan();
Alpaca.Markets.Interval<DateTime> newsInt = new Alpaca.Markets.Interval<DateTime>(pastTime, nowTime);
var newsArticleRequest = new NewsArticlesRequest(symbols);
newsArticleRequest.ExcludeItemsWithoutContent = false;
newsArticleRequest.SendFullContentForItems = true;
newsArticleRequest.TimeInterval = newsInt;
var newsClient = Alpaca.Markets.Environments.Live.GetAlpacaDataClient(new SecretKey(KEY_ID, SECRET_KEY)).ListNewsArticlesAsync(newsArticleRequest);
var cancellationTokenSource = new CancellationTokenSource();
await foreach (var article in newsClient.ToAsyncEnumerable())
{
try
{
foreach(var item in article.Items)
{
Console.WriteLine(item.Author);
Console.WriteLine(item.Source); //Etc. etc. untill you have all data
}
}
catch(Exception ex)
{
Console.WriteLine("prior news errror: " + ex);
}
}