Skip to content

Commit 2bcd300

Browse files
committed
Add stock news call
1 parent 74901b2 commit 2bcd300

File tree

4 files changed

+61
-0
lines changed

4 files changed

+61
-0
lines changed

FinancialModelingPrepApi/Abstractions/CompanyValuation/ICompanyValuation.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,7 @@ public interface ICompanyValuation
1818
public Task<ApiResponse<List<BalanceSheetResponse>>> GetBalanceSheetStatementAsync(string symbol, Period period = Period.Quarter, int limit = 40);
1919
public Task<ApiResponse<List<CashFlowResponse>>> GetCashFlowStatementAsync(string symbol, Period period = Period.Quarter, int limit = 40);
2020
public Task<ApiResponse<List<IncomeStatementResponse>>> GetIncomeStatementAsync(string symbol, Period period = Period.Quarter, int limit = 40);
21+
22+
public Task<ApiResponse<List<StockNewsResponse>>> GetStockNewsAsync(string symbol, int limit = 50);
2123
}
2224
}

FinancialModelingPrepApi/Core/CompanyValuation/CompanyValuation.cs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,5 +161,22 @@ public Task<ApiResponse<List<IncomeStatementResponse>>> GetIncomeStatementAsync(
161161

162162
return client.GetAsync<List<IncomeStatementResponse>>(url, pathParams, queryString);
163163
}
164+
165+
public Task<ApiResponse<List<StockNewsResponse>>> GetStockNewsAsync(string symbol, int limit = 50)
166+
{
167+
const string url = "[version]/stock_news";
168+
169+
var pathParams = new NameValueCollection()
170+
{
171+
{ "version", ApiVersion.v3.ToString() },
172+
};
173+
174+
var queryString = new QueryStringBuilder();
175+
176+
queryString.Add("tickers", symbol);
177+
queryString.Add("limit", limit);
178+
179+
return client.GetAsync<List<StockNewsResponse>>(url, pathParams, queryString);
180+
}
164181
}
165182
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
using System.Text.Json.Serialization;
2+
3+
namespace MatthiWare.FinancialModelingPrepApi.Model.CompanyValuation
4+
{
5+
public class StockNewsResponse
6+
{
7+
[JsonPropertyName("symbol")]
8+
public string Symbol { get; set; }
9+
10+
[JsonPropertyName("publishedDate")]
11+
public string PublishedDate { get; set; }
12+
13+
[JsonPropertyName("title")]
14+
public string Title { get; set; }
15+
16+
[JsonPropertyName("image")]
17+
public string Image { get; set; }
18+
19+
[JsonPropertyName("site")]
20+
public string Site { get; set; }
21+
22+
[JsonPropertyName("text")]
23+
public string Text { get; set; }
24+
25+
[JsonPropertyName("url")]
26+
public string Url { get; set; }
27+
}
28+
}

Tests/CompanyValuation/CompanyValuationTests.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,5 +128,19 @@ public async Task GetBalanceSheetStatement()
128128
Assert.Equal(5, result.Data.Count);
129129
Assert.All(result.Data, data => Assert.Equal("AAPL", data.Symbol));
130130
}
131+
132+
[Fact]
133+
public async Task GetStockNewsAsync()
134+
{
135+
var api = ServiceProvider.GetRequiredService<IFinancialModelingPrepApiClient>();
136+
137+
var result = await api.CompanyValuation.GetStockNewsAsync("AAPL", 5);
138+
139+
Assert.NotNull(result);
140+
Assert.False(result.HasError);
141+
Assert.NotEmpty(result.Data);
142+
Assert.Equal(5, result.Data.Count);
143+
Assert.All(result.Data, data => Assert.Equal("AAPL", data.Symbol));
144+
}
131145
}
132146
}

0 commit comments

Comments
 (0)