-
Notifications
You must be signed in to change notification settings - Fork 7
News endpoint was done, model, API and test were created #37
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
davidfmb93
wants to merge
8
commits into
main
Choose a base branch
from
david-sentiment-news
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
ad87279
News endpoint was done, model, API and test were created
davidfmb93 345ab2f
New fields were added and two instances have been created for the news
davidfmb93 c8fe667
New comments have been added in Api rest, unit tests were created as …
davidfmb93 4d3e96b
solved comments
davidfmb93 48daa7b
version updated
davidfmb93 bda4142
New fields have been created(ArticleUrl) and others have been modifie…
davidfmb93 e4336dd
Fixed comments
davidfmb93 ee06b52
The code has been cleaned
davidfmb93 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,86 @@ | ||
| using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
| using Polygon.Net.Models; | ||
| using static Polygon.Net.Tests.TestManager; | ||
|
|
||
| namespace Polygon.Net.Tests.FunctionalTests | ||
| { | ||
| [TestClass] | ||
| public class NewsApiTests | ||
| { | ||
| private const string STATUS_OK = "OK"; | ||
| private static DateTime START_TIME = new DateTime(2023, 03, 05); // Start Specific Day | ||
| private static DateTime END_TIME = new DateTime(2023, 03, 06); // End Specific Day | ||
|
|
||
| [TestMethod] | ||
| public async Task GetNewsSucceedsAsync() | ||
| { | ||
| var newsResponse = await PolygonTestClient.GetNewsAsync(); | ||
|
|
||
| Assert.IsInstanceOfType(newsResponse.Results, typeof(List<NewsInfo>)); | ||
| Assert.IsNotNull(newsResponse); | ||
| Assert.AreEqual(STATUS_OK, newsResponse.Status); | ||
| } | ||
|
|
||
| [TestMethod] | ||
| public async Task GetNewsWithParametersSucceedsAsync() | ||
| { | ||
| int countNews = 5; | ||
| String ticker = "GOOGL"; | ||
| DateTime dateTime = START_TIME; | ||
|
|
||
| var newsResponse = await PolygonTestClient.GetNewsAsync(START_TIME, END_TIME, ticker, "asc", "published_utc", limit: countNews); | ||
|
|
||
| Assert.IsInstanceOfType(newsResponse.Results, typeof(List<NewsInfo>)); | ||
| Assert.IsNotNull(newsResponse); | ||
| Assert.AreEqual(STATUS_OK, newsResponse.Status); | ||
| Assert.AreEqual(newsResponse.Count, countNews); | ||
|
|
||
| foreach (var news in newsResponse.Results) | ||
| { | ||
| DateTime publishedNews = DateTime.Parse(news.PublishedUtc); | ||
|
|
||
| Assert.AreEqual(START_TIME.ToString("yyyy-MM-dd"), publishedNews.ToString("yyyy-MM-dd")); | ||
| Assert.IsTrue(news.Tickers.Contains(ticker), "The ticker was not found inside tickers"); | ||
| Assert.IsTrue(publishedNews > dateTime, "Date current news is not greater than before date news"); | ||
|
|
||
| dateTime = publishedNews; | ||
| } | ||
| } | ||
|
|
||
| [TestMethod] | ||
| public async Task GetNewsEmptyAsync() | ||
| { | ||
| var newsResponse = await PolygonTestClient.GetNewsAsync(ticker: "ABCXYZ"); | ||
|
|
||
| Assert.IsTrue(newsResponse.Count == 0, "the news count should be empty"); | ||
| Assert.AreEqual(STATUS_OK, newsResponse.Status); | ||
| } | ||
|
|
||
| [TestMethod] | ||
| public async Task GetTodayNewsSucceedsAsync() | ||
| { | ||
| DateTime currentDate = DateTime.Now.Date; | ||
| var newsResponse = await PolygonTestClient.GetNewsAsync(currentDate); | ||
|
|
||
| Assert.IsInstanceOfType(newsResponse.Results, typeof(List<NewsInfo>)); | ||
| Assert.IsNotNull(newsResponse); | ||
| Assert.AreEqual(STATUS_OK, newsResponse.Status); | ||
|
|
||
| foreach (var news in newsResponse.Results) | ||
| { | ||
| Assert.AreEqual(currentDate.ToString("yyyy-MM-dd"), DateTime.Parse(news.PublishedUtc).ToString("yyyy-MM-dd")); | ||
| } | ||
| } | ||
|
|
||
| [TestMethod] | ||
| public async Task GetNextPageNewsAsync() | ||
| { | ||
| var newsResponse = await PolygonTestClient.GetNewsAsync(START_TIME, END_TIME); | ||
| var nextPage = await PolygonTestClient.GetNewsAsync(nextPage: newsResponse.HashNextUrl); | ||
|
|
||
| Assert.IsInstanceOfType(nextPage.Results, typeof(List<NewsInfo>)); | ||
| Assert.IsNotNull(nextPage); | ||
| Assert.AreEqual(STATUS_OK, nextPage.Status); | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| using Microsoft.AspNetCore.Http.Extensions; | ||
| using Newtonsoft.Json; | ||
| using Polygon.Net.Http; | ||
| using Polygon.Net.Models; | ||
|
|
||
| namespace Polygon.Net; | ||
|
|
||
| public partial class PolygonClient | ||
| { | ||
| private const string NEWS_ENDPOINT = "/v2/reference/news"; | ||
|
|
||
| /// <summary> | ||
| /// Get the Polygon news. | ||
| /// </summary> | ||
| /// <param name="startTime">Return results published after this date</param> | ||
| /// <param name="endTime">Return results published before this date</param> | ||
| /// <param name="ticker">The polygon API ticker by default is desc</param> | ||
| /// <param name="order">Order results based on the sort field</param> | ||
| /// <param name="limit">Limit the number of results returned, default is 10 and max is 1000</param> | ||
| /// <param name="sort">Sort field used for ordering</param> | ||
| /// <param name="nextPage">next page </param> | ||
| /// <returns>NewsResponse</returns> | ||
| /// | ||
| public async Task<NewsResponse> GetNewsAsync(DateTime? startTime = null, DateTime? endTime = null, string? ticker = null, string? order = null, string? sort = null, int limit = 0, string? nextPage = null) | ||
| { | ||
| var qb = new QueryBuilder(); | ||
| qb.AddIf(nextPage != null, "cursor", nextPage); | ||
| qb.AddIf(ticker != null, nameof(ticker), ticker); | ||
| qb.AddIf(order != null, nameof(order), order); | ||
| qb.AddIf(limit != 0, nameof(limit), limit + ""); | ||
| qb.AddIf(sort != null, nameof(sort), sort); | ||
| qb.AddIf(startTime != null, "published_utc.gte", startTime?.ToString("yyyy'-'MM'-'dd'T'HH':'mm':'ss")); | ||
| qb.AddIf(endTime != null, "published_utc.lte", endTime?.ToString("yyyy'-'MM'-'dd'T'HH':'mm':'ss")); | ||
|
|
||
| string requestUrl = $"{_polygonSettings.ApiBaseUrl}{NEWS_ENDPOINT}{qb.ToString()}"; | ||
| string contentStr = await Get(requestUrl).ConfigureAwait(false); | ||
|
|
||
| return String.IsNullOrEmpty(contentStr) ? new NewsResponse() : JsonConvert.DeserializeObject<NewsResponse>(contentStr); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,4 @@ | ||
| using System.Collections.Generic; | ||
| using System.Threading.Tasks; | ||
| using Polygon.Net.Models; | ||
| using Polygon.Net.Models; | ||
|
|
||
| namespace Polygon.Net | ||
| { | ||
|
|
@@ -55,6 +53,16 @@ Task<AggregatesBarsResponse> GetAggregatesBarsAsync( | |
|
|
||
| Task<List<MarketHoliday>> GetMarketHolidaysAsync(); | ||
|
|
||
| Task<PolygonResponse<TickerType>> GetTickerTypesAsync(string assetClass = default, string locale = default); | ||
| Task<PolygonResponse<TickerType>> GetTickerTypesAsync(string? assetClass = default, string? locale = default); | ||
|
|
||
| Task<NewsResponse> GetNewsAsync( | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. My suggestion is to keep only one and remove the GetTodayNewsAsync and GetNextPageNewsAsync
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The function removed |
||
| DateTime? startTime = null, | ||
| DateTime? endTime = null, | ||
| string? ticker = null, | ||
| string? order = null, | ||
| string? sort = null, | ||
| int limit = 0, | ||
| string? nextPage = null | ||
| ); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| using Microsoft.AspNetCore.Http.Extensions; | ||
|
|
||
| namespace Polygon.Net.Http; | ||
|
|
||
| internal static class QueryStringExtension | ||
| { | ||
| public static void AddIf(this QueryBuilder query, bool conditional, string? name, string? value) | ||
| { | ||
| if (conditional) | ||
| { | ||
| query.Add(name, value); | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| using Newtonsoft.Json; | ||
|
|
||
| namespace Polygon.Net.Models; | ||
|
|
||
| public class NewsInfo | ||
| { | ||
| [JsonProperty("id")] | ||
| public string Id { get; set; } | ||
|
|
||
| [JsonProperty("title")] | ||
| public string Title { get; set; } | ||
|
|
||
| [JsonProperty("description")] | ||
| public string Description { get; set; } | ||
|
|
||
| [JsonProperty("author")] | ||
| public string Author { get; set; } | ||
|
|
||
| [JsonProperty("published_utc")] | ||
| public string PublishedUtc { get; set; } | ||
|
|
||
| [JsonProperty("article_url")] | ||
| public string ArticleUrl { get; set; } | ||
|
|
||
| [JsonProperty("keywords")] | ||
| public List<string> Keywords { get; set; } = new List<string>() { }; | ||
|
|
||
| [JsonProperty("tickers")] | ||
| public List<string> Tickers { get; set; } = new List<string>() { }; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| using System.Web; | ||
| using Newtonsoft.Json; | ||
|
|
||
| namespace Polygon.Net.Models; | ||
|
|
||
| public class NewsResponse | ||
| { | ||
| [JsonProperty("status")] | ||
| public string Status { get; set; } | ||
|
|
||
| [JsonProperty("request_id")] | ||
| public string RequestId { get; set; } | ||
|
|
||
| [JsonProperty("count")] | ||
| public int Count { get; set; } = 0; | ||
|
|
||
| private string? _hashNextUrl; | ||
|
|
||
| [JsonProperty("next_url")] | ||
| public string? HashNextUrl | ||
| { | ||
| get { return _hashNextUrl; } | ||
| set | ||
| { | ||
| string? hash = null; | ||
| if (value != null) | ||
| { | ||
| Uri uri = new Uri(value); | ||
| var query = HttpUtility.ParseQueryString(uri.Query); | ||
| hash = query.Get("cursor"); | ||
| } | ||
|
|
||
| _hashNextUrl = hash != null ? hash : value; | ||
| } | ||
| } | ||
|
|
||
| [JsonProperty("results")] | ||
| public List<NewsInfo> Results { get; set; } = new List<NewsInfo>() { }; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.