Skip to content

Commit 23b8e7c

Browse files
authored
Add ETF Exposure fixes #45 (#46)
1 parent 3193495 commit 23b8e7c

File tree

9 files changed

+140
-2
lines changed

9 files changed

+140
-2
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
using MatthiWare.FinancialModelingPrep.Model;
2+
using MatthiWare.FinancialModelingPrep.Model.Fund;
3+
using System.Collections.Generic;
4+
using System.Threading.Tasks;
5+
6+
namespace MatthiWare.FinancialModelingPrep.Abstractions.Fund
7+
{
8+
public interface IFundProvider
9+
{
10+
public Task<ApiResponse<List<ETFStockExposureResponse>>> GetETFStockExposureAsync(string symbol);
11+
12+
}
13+
}

FinancialModelingPrepApi/Abstractions/IFinancialModelingPrepApiClient.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using MatthiWare.FinancialModelingPrep.Abstractions.AdvancedData;
22
using MatthiWare.FinancialModelingPrep.Abstractions.Calendars;
33
using MatthiWare.FinancialModelingPrep.Abstractions.CompanyValuation;
4+
using MatthiWare.FinancialModelingPrep.Abstractions.Fund;
45
using MatthiWare.FinancialModelingPrep.Abstractions.InstitutionalFund;
56
using MatthiWare.FinancialModelingPrep.Abstractions.MarketIndexes;
67
using MatthiWare.FinancialModelingPrep.Abstractions.Statistics;
@@ -54,5 +55,15 @@ public interface IFinancialModelingPrepApiClient
5455
/// Statistic Related Endpoint are grouped here (Estimates)
5556
/// </summary>
5657
IStockStatisticsProvider StockStatistics { get; }
58+
59+
/// <summary>
60+
/// Cryptomarket related enpoints
61+
/// </summary>
62+
ICryptoMarketProvider Crypto { get; }
63+
64+
/// <summary>
65+
/// ETF/Mutual Fund related enpoints
66+
/// </summary>
67+
IFundProvider Fund { get; }
5768
}
5869
}

FinancialModelingPrepApi/Core/FinancialModelingPrepApiClient.cs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using MatthiWare.FinancialModelingPrep.Abstractions.AdvancedData;
22
using MatthiWare.FinancialModelingPrep.Abstractions.Calendars;
33
using MatthiWare.FinancialModelingPrep.Abstractions.CompanyValuation;
4+
using MatthiWare.FinancialModelingPrep.Abstractions.Fund;
45
using MatthiWare.FinancialModelingPrep.Abstractions.InstitutionalFund;
56
using MatthiWare.FinancialModelingPrep.Abstractions.MarketIndexes;
67
using MatthiWare.FinancialModelingPrep.Abstractions.Statistics;
@@ -33,8 +34,15 @@ public class FinancialModelingPrepApiClient : IFinancialModelingPrepApiClient
3334
/// <inheritdoc/>
3435
public IStockMarketProvider StockMarket { get; }
3536

37+
/// <inheritdoc/>
3638
public IStockStatisticsProvider StockStatistics { get; }
3739

40+
/// <inheritdoc/>
41+
public ICryptoMarketProvider Crypto { get; }
42+
43+
/// <inheritdoc/>
44+
public IFundProvider Fund { get; }
45+
3846
/// <inheritdoc/>
3947
public FinancialModelingPrepApiClient(ICompanyValuationProvider companyValuation,
4048
IMarketIndexesProvider marketIndexes,
@@ -43,7 +51,9 @@ public FinancialModelingPrepApiClient(ICompanyValuationProvider companyValuation
4351
IInstitutionalFundProvider institutionalFund,
4452
IStockTimeSeriesProvider stockTimeSeries,
4553
IStockMarketProvider stockMarket,
46-
IStockStatisticsProvider stockStatistics)
54+
IStockStatisticsProvider stockStatistics,
55+
ICryptoMarketProvider cryptoMarket,
56+
IFundProvider fund)
4757
{
4858
CompanyValuation = companyValuation;
4959
MarketIndexes = marketIndexes;
@@ -53,6 +63,8 @@ public FinancialModelingPrepApiClient(ICompanyValuationProvider companyValuation
5363
StockTimeSeries = stockTimeSeries;
5464
StockMarket = stockMarket;
5565
StockStatistics = stockStatistics;
66+
Crypto = cryptoMarket;
67+
Fund = fund;
5668
}
5769
}
5870
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
using MatthiWare.FinancialModelingPrep.Abstractions.Fund;
2+
using MatthiWare.FinancialModelingPrep.Core.Http;
3+
using MatthiWare.FinancialModelingPrep.Model;
4+
using MatthiWare.FinancialModelingPrep.Model.Fund;
5+
using System;
6+
using System.Collections.Generic;
7+
using System.Collections.Specialized;
8+
using System.Threading.Tasks;
9+
10+
namespace MatthiWare.FinancialModelingPrep.Core.Fund
11+
{
12+
public class FundProvider : IFundProvider
13+
{
14+
private readonly FinancialModelingPrepHttpClient client;
15+
16+
public FundProvider(FinancialModelingPrepHttpClient client)
17+
{
18+
this.client = client ?? throw new System.ArgumentNullException(nameof(client));
19+
}
20+
21+
public Task<ApiResponse<List<ETFStockExposureResponse>>> GetETFStockExposureAsync(string symbol)
22+
{
23+
const string url = "[version]/etf-stock-exposure/[symbol]";
24+
25+
var pathParams = new NameValueCollection()
26+
{
27+
{ "version", ApiVersion.v3.ToString() },
28+
{ "symbol", symbol }
29+
};
30+
31+
return client.GetJsonAsync<List<ETFStockExposureResponse>>(url, pathParams, null);
32+
}
33+
}
34+
}

FinancialModelingPrepApi/DependencyInjectionExtensions.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using MatthiWare.FinancialModelingPrep.Abstractions.AdvancedData;
22
using MatthiWare.FinancialModelingPrep.Abstractions.Calendars;
33
using MatthiWare.FinancialModelingPrep.Abstractions.CompanyValuation;
4+
using MatthiWare.FinancialModelingPrep.Abstractions.Fund;
45
using MatthiWare.FinancialModelingPrep.Abstractions.Http;
56
using MatthiWare.FinancialModelingPrep.Abstractions.InstitutionalFund;
67
using MatthiWare.FinancialModelingPrep.Abstractions.MarketIndexes;
@@ -11,6 +12,7 @@
1112
using MatthiWare.FinancialModelingPrep.Core.AdvancedData;
1213
using MatthiWare.FinancialModelingPrep.Core.Calendars;
1314
using MatthiWare.FinancialModelingPrep.Core.CompanyValuation;
15+
using MatthiWare.FinancialModelingPrep.Core.Fund;
1416
using MatthiWare.FinancialModelingPrep.Core.Http;
1517
using MatthiWare.FinancialModelingPrep.Core.InstitutionalFund;
1618
using MatthiWare.FinancialModelingPrep.Core.MarketIndexes;
@@ -51,6 +53,7 @@ public static void AddFinancialModelingPrepApiClient(this IServiceCollection ser
5153
services.TryAddTransient<IStockMarketProvider, StockMarketProvider>();
5254
services.TryAddTransient<ICryptoMarketProvider, CryptoMarketProvider>();
5355
services.TryAddTransient<IStockStatisticsProvider, StockStatisticsProvider>();
56+
services.TryAddTransient<IFundProvider, FundProvider>();
5457
}
5558
}
5659
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
using System.Text.Json.Serialization;
2+
3+
namespace MatthiWare.FinancialModelingPrep.Model.Fund
4+
{
5+
public class ETFStockExposureResponse
6+
{
7+
[JsonPropertyName("etfSymbol")]
8+
public string EtfSymbol { get; set; }
9+
10+
[JsonPropertyName("assetExposure")]
11+
public string AssetExposure { get; set; }
12+
13+
[JsonPropertyName("sharesNumber")]
14+
public int SharesNumber { get; set; }
15+
16+
[JsonPropertyName("weightPercentage")]
17+
public double WeightPercentage { get; set; }
18+
19+
[JsonPropertyName("marketValue")]
20+
public double MarketValue { get; set; }
21+
}
22+
}

Tests/ClientFactoryTests.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,5 +53,17 @@ public void API_Contains_StockMarket_Provider()
5353
{
5454
Assert.NotNull(api.StockMarket);
5555
}
56+
57+
[Fact]
58+
public void API_Contains_CryptoMarket_Provider()
59+
{
60+
Assert.NotNull(api.Crypto);
61+
}
62+
63+
[Fact]
64+
public void API_Contains_Fund_Provider()
65+
{
66+
Assert.NotNull(api.Fund);
67+
}
5668
}
5769
}

Tests/CompanyValuation/CompanyValuationTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public async Task GetCompanyProfileTests(string symbol)
4646
[Theory]
4747
[InlineData("AAPL", false)]
4848
[InlineData("BST", true, Skip = "IsFund returns incorrect result")]
49-
public async Task GetCompanyProfile_IsFund_Tests(string symbol, bool isFund)
49+
public async Task GetCompanyProfile_IsFund_Tests(string symbol, bool isFund)
5050
{
5151
var result = await api.GetCompanyProfileAsync(symbol);
5252

Tests/Fund/FundTests.cs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
using MatthiWare.FinancialModelingPrep.Abstractions.Fund;
2+
using Microsoft.Extensions.DependencyInjection;
3+
using System.Threading.Tasks;
4+
using Xunit;
5+
using Xunit.Abstractions;
6+
7+
namespace Tests.CompanyValuation
8+
{
9+
public class FundTests : TestingBase
10+
{
11+
private readonly IFundProvider api;
12+
13+
public FundTests(ITestOutputHelper testOutput) : base(testOutput)
14+
{
15+
api = ServiceProvider.GetRequiredService<IFundProvider>();
16+
}
17+
18+
[Theory]
19+
[InlineData("AAPL")]
20+
[InlineData("AGS.BR")]
21+
[InlineData("O")]
22+
[InlineData("LGEN.L")]
23+
public async Task GetETFStockExposureAsyncTest(string symbol)
24+
{
25+
var result = await api.GetETFStockExposureAsync(symbol);
26+
27+
result.AssertNoErrors();
28+
Assert.NotEmpty(result.Data);
29+
}
30+
}
31+
}

0 commit comments

Comments
 (0)