# How to get Historic news C#

**URL:** <https://forum.alpaca.markets/t/how-to-get-historic-news-c/12042>\
**Category:** Getting Started with Alpaca\
**Created:** [March 23, 2023, 7:20pm UTC](https://forum.alpaca.markets/t/how-to-get-historic-news-c/12042 "2023-03-23T19:20:34Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![masoric](https://avatars.discourse-cdn.com/v4/letter/m/94ad74/32.png) [@masoric](https://forum.alpaca.markets/u/masoric)\
**Post date:** [March 23, 2023, 7:20pm UTC](https://forum.alpaca.markets/t/how-to-get-historic-news-c/12042/1 "2023-03-23T19:20:34Z")

</div>

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.

```auto

            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);

                }
            }

```

---

<div class="post-metadata">

**Author:** ![oleg.rakhmatulin](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.alpaca.markets/oleg.rakhmatulin/32/559_2.png) [@oleg.rakhmatulin](https://forum.alpaca.markets/u/oleg.rakhmatulin)\
**Post date:** [March 25, 2023, 6:41am UTC](https://forum.alpaca.markets/t/how-to-get-historic-news-c/12042/2 "2023-03-25T06:41:25Z")

</div>

If you get the “_Bad Request_” exception executing your code it’s not your problem but instead, the .NET SDK minor issue that will be fixed in the next service release. I’ve tested your scenario on my side using the next script and it works fine:

```auto
using Alpaca.Markets;
using Alpaca.Markets.Extensions;

try
{
    var key = new SecretKey("...", "...");
    using var client = Environments.Paper.GetAlpacaDataClient(key);

    var request = new NewsArticlesRequest
    {
        TimeInterval = new Interval<DateTime>().WithFrom(DateTime.Today.AddDays(-4))
    }.WithPageSize(50);

    await foreach (var article in client.GetNewsArticlesAsAsyncEnumerable(request))
    {
        Console.WriteLine(article);
    }
}
catch (Exception e)
{
    Console.Error.WriteLine(e);
}

```

There are two important differences between my code and your original snippet:

- The **WithPageSize** method sets the news request page size to a value of 50 instead of the old hard-coded default value of 100 used by the SDK package.
- I use the [Alpaca.Markets.Extensions](https://www.nuget.org/packages/Alpaca.Markets.Extensions) NuGet package - it provides a set of useful methods for handling paginated responses in a truly asynchronous manner.

---

<div class="post-metadata">

**Author:** ![masoric](https://avatars.discourse-cdn.com/v4/letter/m/94ad74/32.png) [@masoric](https://forum.alpaca.markets/u/masoric)\
**Post date:** [April 7, 2023, 7:41pm UTC](https://forum.alpaca.markets/t/how-to-get-historic-news-c/12042/3 "2023-04-07T19:41:16Z")

</div>

Appreciate the feedback. I just wanted to post something that works as people keep asking for examples thought I would contribute.
