Skip to content

Commit d28f226

Browse files
committed
Add MarketIndexes API
1 parent 2bcd300 commit d28f226

File tree

7 files changed

+165
-2
lines changed

7 files changed

+165
-2
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
using MatthiWare.FinancialModelingPrepApi.Abstractions.CompanyValuation;
2+
using MatthiWare.FinancialModelingPrepApi.Abstractions.MarketIndexes;
23

34
namespace MatthiWare.FinancialModelingPrepApi
45
{
56
public interface IFinancialModelingPrepApiClient
67
{
78
ICompanyValuation CompanyValuation { get; }
9+
IMarketIndexes MarketIndexes { get; }
810
}
911
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
using MatthiWare.FinancialModelingPrepApi.Model;
2+
using MatthiWare.FinancialModelingPrepApi.Model.MarketIndexes;
3+
using System.Collections.Generic;
4+
using System.Threading.Tasks;
5+
6+
namespace MatthiWare.FinancialModelingPrepApi.Abstractions.MarketIndexes
7+
{
8+
public interface IMarketIndexes
9+
{
10+
Task<ApiResponse<List<IndexConstituentResponse>>> GetSP500CompaniesAsync();
11+
Task<ApiResponse<List<IndexConstituentResponse>>> GetNasdaqCompaniesAsync();
12+
Task<ApiResponse<List<IndexConstituentResponse>>> GetDowJonesCompaniesAsync();
13+
}
14+
}
Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
11
using MatthiWare.FinancialModelingPrepApi.Abstractions.CompanyValuation;
2+
using MatthiWare.FinancialModelingPrepApi.Abstractions.MarketIndexes;
23

34
namespace MatthiWare.FinancialModelingPrepApi.Core
45
{
56
public class FinancialModelingPrepApiClient : IFinancialModelingPrepApiClient
67
{
78
public ICompanyValuation CompanyValuation { get; private set; }
89

9-
public FinancialModelingPrepApiClient(ICompanyValuation companyValuation)
10+
public IMarketIndexes MarketIndexes { get; private set; }
11+
12+
public FinancialModelingPrepApiClient(ICompanyValuation companyValuation, IMarketIndexes marketIndexes)
1013
{
11-
this.CompanyValuation = companyValuation;
14+
CompanyValuation = companyValuation;
15+
MarketIndexes = marketIndexes;
1216
}
1317
}
1418
}
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
using MatthiWare.FinancialModelingPrepApi.Abstractions.MarketIndexes;
2+
using MatthiWare.FinancialModelingPrepApi.Core.Http;
3+
using MatthiWare.FinancialModelingPrepApi.Model;
4+
using MatthiWare.FinancialModelingPrepApi.Model.CompanyValuation;
5+
using MatthiWare.FinancialModelingPrepApi.Model.MarketIndexes;
6+
using System.Collections.Generic;
7+
using System.Collections.Specialized;
8+
using System.Threading.Tasks;
9+
10+
namespace MatthiWare.FinancialModelingPrepApi.Core.MarketIndexes
11+
{
12+
public class MarketIndexes : IMarketIndexes
13+
{
14+
private readonly FinancialModelingPrepHttpClient client;
15+
16+
public MarketIndexes(FinancialModelingPrepHttpClient client)
17+
{
18+
this.client = client ?? throw new System.ArgumentNullException(nameof(client));
19+
}
20+
21+
public Task<ApiResponse<List<IndexConstituentResponse>>> GetDowJonesCompaniesAsync()
22+
{
23+
const string url = "[version]/dowjones_constituent";
24+
25+
var pathParams = new NameValueCollection()
26+
{
27+
{ "version", ApiVersion.v3.ToString() },
28+
};
29+
30+
return client.GetAsync<List<IndexConstituentResponse>>(url, pathParams, null);
31+
}
32+
33+
public Task<ApiResponse<List<IndexConstituentResponse>>> GetNasdaqCompaniesAsync()
34+
{
35+
const string url = "[version]/nasdaq_constituent";
36+
37+
var pathParams = new NameValueCollection()
38+
{
39+
{ "version", ApiVersion.v3.ToString() },
40+
};
41+
42+
return client.GetAsync<List<IndexConstituentResponse>>(url, pathParams, null);
43+
}
44+
45+
public Task<ApiResponse<List<IndexConstituentResponse>>> GetSP500CompaniesAsync()
46+
{
47+
const string url = "[version]/sp500_constituent";
48+
49+
var pathParams = new NameValueCollection()
50+
{
51+
{ "version", ApiVersion.v3.ToString() },
52+
};
53+
54+
return client.GetAsync<List<IndexConstituentResponse>>(url, pathParams, null);
55+
}
56+
}
57+
}

FinancialModelingPrepApi/DependencyInjectionExtensions.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
using MatthiWare.FinancialModelingPrepApi.Abstractions.CompanyValuation;
2+
using MatthiWare.FinancialModelingPrepApi.Abstractions.MarketIndexes;
23
using MatthiWare.FinancialModelingPrepApi.Core;
34
using MatthiWare.FinancialModelingPrepApi.Core.CompanyValuation;
45
using MatthiWare.FinancialModelingPrepApi.Core.Http;
6+
using MatthiWare.FinancialModelingPrepApi.Core.MarketIndexes;
57
using Microsoft.Extensions.DependencyInjection;
68
using Microsoft.Extensions.DependencyInjection.Extensions;
79
using System;
@@ -21,6 +23,7 @@ public static void AddFinancialModelingPrepApiClient(this IServiceCollection ser
2123

2224
services.TryAddSingleton<IFinancialModelingPrepApiClient, FinancialModelingPrepApiClient>();
2325
services.TryAddScoped<ICompanyValuation, CompanyValuation>();
26+
services.TryAddScoped<IMarketIndexes, MarketIndexes>();
2427
}
2528
}
2629
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
using System.Text.Json.Serialization;
2+
3+
namespace MatthiWare.FinancialModelingPrepApi.Model.MarketIndexes
4+
{
5+
public class IndexConstituentResponse
6+
{
7+
[JsonPropertyName("symbol")]
8+
public string Symbol { get; set; }
9+
10+
[JsonPropertyName("name")]
11+
public string Name { get; set; }
12+
13+
[JsonPropertyName("sector")]
14+
public string Sector { get; set; }
15+
16+
[JsonPropertyName("subSector")]
17+
public string SubSector { get; set; }
18+
19+
[JsonPropertyName("headQuarter")]
20+
public string HeadQuarter { get; set; }
21+
22+
[JsonPropertyName("dateFirstAdded")]
23+
public string DateFirstAdded { get; set; }
24+
25+
[JsonPropertyName("cik")]
26+
public string Cik { get; set; }
27+
28+
[JsonPropertyName("founded")]
29+
public string Founded { get; set; }
30+
}
31+
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
using MatthiWare.FinancialModelingPrepApi;
2+
using MatthiWare.FinancialModelingPrepApi.Model;
3+
using Microsoft.Extensions.DependencyInjection;
4+
using System.Threading.Tasks;
5+
using Xunit;
6+
using Xunit.Abstractions;
7+
8+
namespace Tests.CompanyValuation
9+
{
10+
public class MarketIndexesTests : TestingBase
11+
{
12+
public MarketIndexesTests(ITestOutputHelper testOutput) : base(testOutput)
13+
{
14+
}
15+
16+
[Fact]
17+
public async Task GetDowJonesCompaniesTests()
18+
{
19+
var api = ServiceProvider.GetRequiredService<IFinancialModelingPrepApiClient>();
20+
21+
var result = await api.MarketIndexes.GetDowJonesCompaniesAsync();
22+
23+
Assert.NotNull(result);
24+
Assert.False(result.HasError);
25+
Assert.NotEmpty(result.Data);
26+
}
27+
28+
[Fact]
29+
public async Task GetNasdaqCompaniesTests()
30+
{
31+
var api = ServiceProvider.GetRequiredService<IFinancialModelingPrepApiClient>();
32+
33+
var result = await api.MarketIndexes.GetNasdaqCompaniesAsync();
34+
35+
Assert.NotNull(result);
36+
Assert.False(result.HasError);
37+
Assert.NotEmpty(result.Data);
38+
}
39+
40+
[Fact]
41+
public async Task GetSP500CompaniesTests()
42+
{
43+
var api = ServiceProvider.GetRequiredService<IFinancialModelingPrepApiClient>();
44+
45+
var result = await api.MarketIndexes.GetSP500CompaniesAsync();
46+
47+
Assert.NotNull(result);
48+
Assert.False(result.HasError);
49+
Assert.NotEmpty(result.Data);
50+
}
51+
}
52+
}

0 commit comments

Comments
 (0)