Skip to content

Commit 0c1e3d6

Browse files
committed
Add market cap endpoint
1 parent d6f6129 commit 0c1e3d6

File tree

4 files changed

+79
-0
lines changed

4 files changed

+79
-0
lines changed

FinancialModelingPrepApi/Abstractions/CompanyValuation/ICompanyValuation.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ public interface ICompanyValuation
1717
public Task<ApiResponse<List<HistoricalDCFResponse>>> GetHistoricalDiscountedCashFlowAsync(string symbol, Period period = Period.Annual);
1818
public Task<ApiResponse<List<HistoricalDailyDCFResponse>>> GetHistoricalDiscountedCashFlowDailyAsync(string symbol, int limit = 100);
1919

20+
public Task<ApiResponse<MarketCapResponse>> GetMarketCapitalizationAsync(string symbol);
21+
public Task<ApiResponse<List<MarketCapResponse>>> GetHistoricalMarketCapitalizationAsync(string symbol, int limit = 100);
22+
2023
public Task<ApiResponse<List<SymbolResponse>>> GetSymbolsListAsync();
2124
public Task<ApiResponse<List<SymbolResponse>>> GetTradableSymbolsListAsync();
2225
public Task<ApiResponse<List<SymbolResponse>>> GetETFListAsync();

FinancialModelingPrepApi/Core/CompanyValuation/CompanyValuation.cs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -334,5 +334,41 @@ public async Task<ApiResponse<QuoteResponse>> GetQuoteAsync(string symbol)
334334

335335
return ApiResponse.FromSucces(result.Data.First());
336336
}
337+
338+
public async Task<ApiResponse<MarketCapResponse>> GetMarketCapitalizationAsync(string symbol)
339+
{
340+
const string url = "[version]/historical-market-capitalization/[symbol]";
341+
342+
var pathParams = new NameValueCollection()
343+
{
344+
{ "version", ApiVersion.v3.ToString() },
345+
{ "symbol", symbol }
346+
};
347+
348+
var result = await client.GetAsync<List<MarketCapResponse>>(url, pathParams, null);
349+
350+
if (result.HasError)
351+
{
352+
return ApiResponse.FromError<MarketCapResponse>(result.Error);
353+
}
354+
355+
return ApiResponse.FromSucces(result.Data.First());
356+
}
357+
358+
public Task<ApiResponse<List<MarketCapResponse>>> GetHistoricalMarketCapitalizationAsync(string symbol, int limit = 100)
359+
{
360+
const string url = "[version]/historical-market-capitalization/[symbol]";
361+
362+
var pathParams = new NameValueCollection()
363+
{
364+
{ "version", ApiVersion.v3.ToString() },
365+
{ "symbol", symbol }
366+
};
367+
368+
var queryString = new QueryStringBuilder();
369+
queryString.Add("limit", limit);
370+
371+
return client.GetAsync<List<MarketCapResponse>>(url, pathParams, queryString);
372+
}
337373
}
338374
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
using System.Text.Json.Serialization;
2+
3+
namespace MatthiWare.FinancialModelingPrepApi.Model.CompanyValuation
4+
{
5+
public class MarketCapResponse
6+
{
7+
[JsonPropertyName("symbol")]
8+
public string Symbol { get; set; }
9+
10+
[JsonPropertyName("date")]
11+
public string Date { get; set; }
12+
13+
[JsonPropertyName("marketCap")]
14+
public double MarketCap { get; set; }
15+
}
16+
}

Tests/CompanyValuation/CompanyValuationTests.cs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,5 +227,29 @@ public async Task GetQuoteAsync()
227227
result.AssertNoErrors();
228228
Assert.Equal("AAPL", result.Data.Symbol);
229229
}
230+
231+
[Fact]
232+
public async Task GetHistoricalMarketCapAsync()
233+
{
234+
var api = ServiceProvider.GetRequiredService<IFinancialModelingPrepApiClient>();
235+
236+
var result = await api.CompanyValuation.GetHistoricalMarketCapitalizationAsync("AAPL", 5);
237+
238+
result.AssertNoErrors();
239+
Assert.NotEmpty(result.Data);
240+
Assert.Equal(5, result.Data.Count);
241+
Assert.All(result.Data, data => Assert.Equal("AAPL", data.Symbol));
242+
}
243+
244+
[Fact]
245+
public async Task GetMarketCapAsync()
246+
{
247+
var api = ServiceProvider.GetRequiredService<IFinancialModelingPrepApiClient>();
248+
249+
var result = await api.CompanyValuation.GetMarketCapitalizationAsync("AAPL");
250+
251+
result.AssertNoErrors();
252+
Assert.Equal("AAPL", result.Data.Symbol);
253+
}
230254
}
231255
}

0 commit comments

Comments
 (0)