Skip to content

Commit

Permalink
Added Reported financials (#105)
Browse files Browse the repository at this point in the history
  • Loading branch information
dharmendra94 authored Feb 24, 2021
1 parent f680b97 commit 0362633
Show file tree
Hide file tree
Showing 7 changed files with 354 additions and 16 deletions.

Large diffs are not rendered by default.

12 changes: 12 additions & 0 deletions IEXSharp/Model/Shared/Request/Filing.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using System.ComponentModel;

namespace IEXSharp.Model.Shared.Request
{
public enum Filing
{
[Description("10-K")]
Annual,
[Description("10-Q")]
Quarterly
}
}
23 changes: 16 additions & 7 deletions IEXSharp/Model/Shared/Request/TimeSeries.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System;
using Common.Logging.Configuration;
using IEXSharp.Helper;

namespace IEXSharp.Model.Shared.Request
Expand Down Expand Up @@ -36,22 +35,32 @@ public TimeSeries SetDateRange(DateTime? from, DateTime? to = default)
return this;
}

public NameValueCollection TimeSeriesQueryParams()
public TimeSeries SetLast(int last)
{
var nvc = new NameValueCollection();
Last = last;
return this;
}

/// <summary>
/// Updates give query string builder class with required Time series query params
/// </summary>
/// <param name="qsb"></param>
public void AddTimeSeriesQueryParams(QueryStringBuilder qsb)
{
if (qsb == null) return;

if (From != null)
{
nvc.Add("from", From);
nvc.Add("to", To);
qsb.Add("from", From);
qsb.Add("to", To);
}

if (!string.IsNullOrEmpty(Range) && string.IsNullOrEmpty(From))
{
nvc.Add("range", Range);
qsb.Add("range", Range);
}

return nvc;
if (Last > 0) qsb.Add("last", Last.ToString());
}
}
}
2 changes: 1 addition & 1 deletion IEXSharp/Model/Shared/Response/Financial.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;

namespace IEXSharp.Model.Shared.Response
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,16 @@ public interface IStockFundamentalsService
/// <returns></returns>
Task<IEXResponse<FinancialResponse>> FinancialAsync(string symbol, int last = 1);

/// <summary>
/// <see cref="https://iexcloud.io/docs/api/#financials-as-reported"/>
/// As reported financials are pulled directly from the raw SEC filings. Returns raw financial data reported in 10-K and 10-Q filings
/// </summary>
/// <param name="symbol"></param>
/// <param name="filing"></param>
/// <param name="timeSeries"></param>
/// <returns></returns>
Task<IEXResponse<IEnumerable<ReportedFinancialResponse>>> ReportedFinancialsAsync(string symbol, Filing filing = Filing.Quarterly, TimeSeries timeSeries = null);

/// <summary>
/// <see cref="https://iexcloud.io/docs/api/#financials"/>
/// Financial Firms report financials in a different format than our 3rd party processes therefore our data is limited
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,7 @@ public async Task<IEXResponse<IEnumerable<AdvancedFundamentalsResponse>>> Advanc

var qsb = new QueryStringBuilder();

if (timeSeries != null)
{
var queryParams = timeSeries.TimeSeriesQueryParams();
foreach (var nameValue in queryParams)
{
qsb.Add(nameValue.Key, nameValue.Value);
}
}
timeSeries?.AddTimeSeriesQueryParams(qsb);

var pathNvc = new NameValueCollection
{
Expand Down Expand Up @@ -119,6 +112,23 @@ public async Task<IEXResponse<string>> EarningFieldAsync(string symbol, string f
public async Task<IEXResponse<FinancialResponse>> FinancialAsync(string symbol, int last = 1) =>
await executor.SymbolLastExecuteAsync<FinancialResponse>("stock/[symbol]/financials/[last]", symbol, last);

public async Task<IEXResponse<IEnumerable<ReportedFinancialResponse>>> ReportedFinancialsAsync(string symbol, Filing filing = Filing.Quarterly, TimeSeries timeSeries = null)
{
const string urlPattern = "time-series/reported_financials/[symbol]/[filing]";

var qsb = new QueryStringBuilder();

timeSeries?.AddTimeSeriesQueryParams(qsb);

var pathNvc = new NameValueCollection
{
{"symbol", symbol},
{"filing", filing.GetDescriptionFromEnum()}
};

return await executor.ExecuteAsync<IEnumerable<ReportedFinancialResponse>>(urlPattern, pathNvc, qsb);
}

public async Task<IEXResponse<string>> FinancialFieldAsync(string symbol, string field, int last = 1) =>
await executor.SymbolLastFieldExecuteAsync("stock/[symbol]/financials/[last]/[field]", symbol, field, last);

Expand Down
25 changes: 25 additions & 0 deletions IEXSharpTest/Cloud/CoreData/StockFundamentalsTest.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using IEXSharp;
Expand Down Expand Up @@ -161,6 +162,30 @@ public async Task FinancialAsyncTest(string symbol, int last)
Assert.GreaterOrEqual(response.Data.financials.Count, 1);
}

public static List<TestCaseData> ReportedFinancialsTestCaseSourceData()
{
return new List<TestCaseData>{
new TestCaseData("AAPL", Filing.Quarterly, null),
new TestCaseData("AAPL", Filing.Quarterly, new TimeSeries(TimeSeriesPeriod.Quarterly).SetLast(2)),
new TestCaseData("AAPL", Filing.Quarterly, new TimeSeries(TimeSeriesPeriod.Annual).SetLast(2)),
new TestCaseData("AAPL", Filing.Quarterly, new TimeSeries(TimeSeriesPeriod.Quarterly).SetDateRange(new DateTime(2019,1,1), new DateTime(2021,1,1)))
};
}

[Test]
[TestCaseSource("ReportedFinancialsTestCaseSourceData")]
public async Task ReportedFinancialsTest(string symbol, Filing filing, TimeSeries timeSeries = null)
{
var response = await sandBoxClient.StockFundamentals.ReportedFinancialsAsync(symbol, filing, timeSeries);

Assert.IsNull(response.ErrorMessage);
foreach (var data in response.Data)
{
Assert.IsNotNull(data);
Assert.IsNotNull(data.AccountsPayableCurrent);
}
}

[Test]
[TestCase("AAPL", "grossProfit", 1)]
[TestCase("FB", "grossProfit", 2)]
Expand Down

0 comments on commit 0362633

Please sign in to comment.