Skip to content
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

Add ETF Exposure Endpoint #46

Merged
merged 1 commit into from
Jul 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions FinancialModelingPrepApi/Abstractions/Fund/IFundProvider.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using MatthiWare.FinancialModelingPrep.Model;
using MatthiWare.FinancialModelingPrep.Model.Fund;
using System.Collections.Generic;
using System.Threading.Tasks;

namespace MatthiWare.FinancialModelingPrep.Abstractions.Fund
{
public interface IFundProvider
{
public Task<ApiResponse<List<ETFStockExposureResponse>>> GetETFStockExposureAsync(string symbol);

}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using MatthiWare.FinancialModelingPrep.Abstractions.AdvancedData;
using MatthiWare.FinancialModelingPrep.Abstractions.Calendars;
using MatthiWare.FinancialModelingPrep.Abstractions.CompanyValuation;
using MatthiWare.FinancialModelingPrep.Abstractions.Fund;
using MatthiWare.FinancialModelingPrep.Abstractions.InstitutionalFund;
using MatthiWare.FinancialModelingPrep.Abstractions.MarketIndexes;
using MatthiWare.FinancialModelingPrep.Abstractions.Statistics;
Expand Down Expand Up @@ -54,5 +55,15 @@ public interface IFinancialModelingPrepApiClient
/// Statistic Related Endpoint are grouped here (Estimates)
/// </summary>
IStockStatisticsProvider StockStatistics { get; }

/// <summary>
/// Cryptomarket related enpoints
/// </summary>
ICryptoMarketProvider Crypto { get; }

/// <summary>
/// ETF/Mutual Fund related enpoints
/// </summary>
IFundProvider Fund { get; }
}
}
14 changes: 13 additions & 1 deletion FinancialModelingPrepApi/Core/FinancialModelingPrepApiClient.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using MatthiWare.FinancialModelingPrep.Abstractions.AdvancedData;
using MatthiWare.FinancialModelingPrep.Abstractions.Calendars;
using MatthiWare.FinancialModelingPrep.Abstractions.CompanyValuation;
using MatthiWare.FinancialModelingPrep.Abstractions.Fund;
using MatthiWare.FinancialModelingPrep.Abstractions.InstitutionalFund;
using MatthiWare.FinancialModelingPrep.Abstractions.MarketIndexes;
using MatthiWare.FinancialModelingPrep.Abstractions.Statistics;
Expand Down Expand Up @@ -33,8 +34,15 @@ public class FinancialModelingPrepApiClient : IFinancialModelingPrepApiClient
/// <inheritdoc/>
public IStockMarketProvider StockMarket { get; }

/// <inheritdoc/>
public IStockStatisticsProvider StockStatistics { get; }

/// <inheritdoc/>
public ICryptoMarketProvider Crypto { get; }

/// <inheritdoc/>
public IFundProvider Fund { get; }

/// <inheritdoc/>
public FinancialModelingPrepApiClient(ICompanyValuationProvider companyValuation,
IMarketIndexesProvider marketIndexes,
Expand All @@ -43,7 +51,9 @@ public FinancialModelingPrepApiClient(ICompanyValuationProvider companyValuation
IInstitutionalFundProvider institutionalFund,
IStockTimeSeriesProvider stockTimeSeries,
IStockMarketProvider stockMarket,
IStockStatisticsProvider stockStatistics)
IStockStatisticsProvider stockStatistics,
ICryptoMarketProvider cryptoMarket,
IFundProvider fund)
{
CompanyValuation = companyValuation;
MarketIndexes = marketIndexes;
Expand All @@ -53,6 +63,8 @@ public FinancialModelingPrepApiClient(ICompanyValuationProvider companyValuation
StockTimeSeries = stockTimeSeries;
StockMarket = stockMarket;
StockStatistics = stockStatistics;
Crypto = cryptoMarket;
Fund = fund;
}
}
}
34 changes: 34 additions & 0 deletions FinancialModelingPrepApi/Core/Fund/FundProvider.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
using MatthiWare.FinancialModelingPrep.Abstractions.Fund;
using MatthiWare.FinancialModelingPrep.Core.Http;
using MatthiWare.FinancialModelingPrep.Model;
using MatthiWare.FinancialModelingPrep.Model.Fund;
using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Threading.Tasks;

namespace MatthiWare.FinancialModelingPrep.Core.Fund
{
public class FundProvider : IFundProvider
{
private readonly FinancialModelingPrepHttpClient client;

public FundProvider(FinancialModelingPrepHttpClient client)
{
this.client = client ?? throw new System.ArgumentNullException(nameof(client));
}

public Task<ApiResponse<List<ETFStockExposureResponse>>> GetETFStockExposureAsync(string symbol)
{
const string url = "[version]/etf-stock-exposure/[symbol]";

var pathParams = new NameValueCollection()
{
{ "version", ApiVersion.v3.ToString() },
{ "symbol", symbol }
};

return client.GetJsonAsync<List<ETFStockExposureResponse>>(url, pathParams, null);
}
}
}
3 changes: 3 additions & 0 deletions FinancialModelingPrepApi/DependencyInjectionExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using MatthiWare.FinancialModelingPrep.Abstractions.AdvancedData;
using MatthiWare.FinancialModelingPrep.Abstractions.Calendars;
using MatthiWare.FinancialModelingPrep.Abstractions.CompanyValuation;
using MatthiWare.FinancialModelingPrep.Abstractions.Fund;
using MatthiWare.FinancialModelingPrep.Abstractions.Http;
using MatthiWare.FinancialModelingPrep.Abstractions.InstitutionalFund;
using MatthiWare.FinancialModelingPrep.Abstractions.MarketIndexes;
Expand All @@ -11,6 +12,7 @@
using MatthiWare.FinancialModelingPrep.Core.AdvancedData;
using MatthiWare.FinancialModelingPrep.Core.Calendars;
using MatthiWare.FinancialModelingPrep.Core.CompanyValuation;
using MatthiWare.FinancialModelingPrep.Core.Fund;
using MatthiWare.FinancialModelingPrep.Core.Http;
using MatthiWare.FinancialModelingPrep.Core.InstitutionalFund;
using MatthiWare.FinancialModelingPrep.Core.MarketIndexes;
Expand Down Expand Up @@ -51,6 +53,7 @@ public static void AddFinancialModelingPrepApiClient(this IServiceCollection ser
services.TryAddTransient<IStockMarketProvider, StockMarketProvider>();
services.TryAddTransient<ICryptoMarketProvider, CryptoMarketProvider>();
services.TryAddTransient<IStockStatisticsProvider, StockStatisticsProvider>();
services.TryAddTransient<IFundProvider, FundProvider>();
}
}
}
22 changes: 22 additions & 0 deletions FinancialModelingPrepApi/Model/Fund/ETFStockExposureResponse.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using System.Text.Json.Serialization;

namespace MatthiWare.FinancialModelingPrep.Model.Fund
{
public class ETFStockExposureResponse
{
[JsonPropertyName("etfSymbol")]
public string EtfSymbol { get; set; }

[JsonPropertyName("assetExposure")]
public string AssetExposure { get; set; }

[JsonPropertyName("sharesNumber")]
public int SharesNumber { get; set; }

[JsonPropertyName("weightPercentage")]
public double WeightPercentage { get; set; }

[JsonPropertyName("marketValue")]
public double MarketValue { get; set; }
}
}
12 changes: 12 additions & 0 deletions Tests/ClientFactoryTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,5 +53,17 @@ public void API_Contains_StockMarket_Provider()
{
Assert.NotNull(api.StockMarket);
}

[Fact]
public void API_Contains_CryptoMarket_Provider()
{
Assert.NotNull(api.Crypto);
}

[Fact]
public void API_Contains_Fund_Provider()
{
Assert.NotNull(api.Fund);
}
}
}
2 changes: 1 addition & 1 deletion Tests/CompanyValuation/CompanyValuationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public async Task GetCompanyProfileTests(string symbol)
[Theory]
[InlineData("AAPL", false)]
[InlineData("BST", true, Skip = "IsFund returns incorrect result")]
public async Task GetCompanyProfile_IsFund_Tests(string symbol, bool isFund)
public async Task GetCompanyProfile_IsFund_Tests(string symbol, bool isFund)
{
var result = await api.GetCompanyProfileAsync(symbol);

Expand Down
31 changes: 31 additions & 0 deletions Tests/Fund/FundTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
using MatthiWare.FinancialModelingPrep.Abstractions.Fund;
using Microsoft.Extensions.DependencyInjection;
using System.Threading.Tasks;
using Xunit;
using Xunit.Abstractions;

namespace Tests.CompanyValuation
{
public class FundTests : TestingBase
{
private readonly IFundProvider api;

public FundTests(ITestOutputHelper testOutput) : base(testOutput)
{
api = ServiceProvider.GetRequiredService<IFundProvider>();
}

[Theory]
[InlineData("AAPL")]
[InlineData("AGS.BR")]
[InlineData("O")]
[InlineData("LGEN.L")]
public async Task GetETFStockExposureAsyncTest(string symbol)
{
var result = await api.GetETFStockExposureAsync(symbol);

result.AssertNoErrors();
Assert.NotEmpty(result.Data);
}
}
}