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

Adding Economic Data Service #34

Merged
merged 13 commits into from
May 7, 2020
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
5 changes: 5 additions & 0 deletions IEXSharp/IEXCloudClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using IEXSharp.Service.Cloud.Commodities;
using IEXSharp.Service.Cloud.CorporateActions;
using IEXSharp.Service.Cloud.Crypto;
using IEXSharp.Service.Cloud.EconomicData;
using IEXSharp.Service.Cloud.ForexCurrencies;
using IEXSharp.Service.Cloud.InvestorsExchangeData;
using IEXSharp.Service.Cloud.MarketInfo;
Expand Down Expand Up @@ -52,6 +53,7 @@ public class IEXCloudClient : IDisposable
private ISocialSentimentService socialSentimentService;
private ITreasuriesService treasuriesService;
private INewsService newsService;
private IEconomicDataService economicDataService;
private ICommoditiesService commoditiesService;

public IAccountService Account => accountService ?? (accountService =
Expand Down Expand Up @@ -112,6 +114,9 @@ public class IEXCloudClient : IDisposable
public INewsService News => newsService
?? (newsService = new NewsService(client, baseSSEURL, secretToken, publishableToken, signRequest));

public IEconomicDataService EconomicData => economicDataService
?? (economicDataService = new EconomicDataService(client, secretToken, publishableToken, signRequest));

public ICommoditiesService Commodities => commoditiesService
?? (commoditiesService = new CommoditiesService(client, secretToken, publishableToken, signRequest));

Expand Down
118 changes: 118 additions & 0 deletions IEXSharp/Model/EconomicData/Request/EconomicDataSymbol.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
using System.ComponentModel;

namespace IEXSharp.Model.EconomicData.Request
{
public enum EconomicDataSymbol
{
/// <summary>
/// CD Rate Non-Jumbo less than $100,000 Money market
/// </summary>
[Description("MMNRNJ")]
MMNRNJ,

/// <summary>
/// CD Rate Jumbo more than $100,000 Money market
/// </summary>
[Description("MMNRJD")]
MMNRJD,

/// <summary>
/// Consumer Price Index All Urban Consumers
/// </summary>
[Description("CPIAUCSL")]
CPIAUCSL,

/// <summary>
/// Commercial bank credit card interest rate as a percent, not seasonally adjusted
/// </summary>
[Description("TERMCBCCALLNS")]
TERMCBCCALLNS,

/// <summary>
/// Effective federal funds rate
/// </summary>
[Description("FEDFUNDS")]
FEDFUNDS,

/// <summary>
/// Real Gross Domestic Product
/// </summary>
[Description("A191RL1Q225SBEA")]
A191RL1Q225SBEA,

/// <summary>
/// Institutional money funds returned as billions of dollars,seasonally adjusted
/// </summary>
[Description("WIMFSL")]
WIMFSL,

/// <summary>
/// Initial Claims 4 week moving average, seasonally adjusted
/// </summary>
[Description("IC4WSA")]
IC4WSA,

/// <summary>
/// Industrial Production Index
/// </summary>
[Description("INDPRO")]
INDPRO,

/// <summary>
/// US 30-Year fixed rate mortgage average
/// </summary>
[Description("MORTGAGE30US")]
MORTGAGE30US,

/// <summary>
/// US 15-Year fixed rate mortgage average
/// </summary>
[Description("MORTGAGE15US")]
MORTGAGE15US,

/// <summary>
/// US 5/1-Year adjustable rate mortgage average
/// </summary>
[Description("MORTGAGE5US")]
MORTGAGE5US,

/// <summary>
/// Total Housing Starts in thousands of units, seasonally adjusted annual rate
/// </summary>
[Description("HOUST")]
HOUST,

/// <summary>
/// Total nonfarm employees in thousands of persons seasonally adjusted
/// </summary>
[Description("PAYEMS")]
PAYEMS,

/// <summary>
/// Total Vehicle Sales in millions of units
/// </summary>
[Description("TOTALSA")]
TOTALSA,

/// <summary>
/// Retail money funds returned as billions of dollars, seasonally adjusted
/// </summary>
[Description("WRMFSL")]
WRMFSL,

/// <summary>
/// Retail money funds returned as billions of dollars, seasonally adjusted
/// </summary>
[Description("UNRATE")]
UNRATE,

/// <summary>
/// US Recession Probabilities. Smoothed recession probabilities for the United States are obtained
/// from a dynamic-factor markov-switching model applied to four monthly coincident variables:
/// non-farm payroll employment, the index of industrial production, real personal income excluding
/// transfer payments, and real manufacturing and trade sales.
/// </summary>
[Description("RECPROUSM156N")]
RECPROUSM156N,
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
using System.ComponentModel;

namespace IEXSharp.Model.EconomicData.Request
{
public enum EconomicDataTimeSeriesSymbol
{
/// <summary>
/// Real Gross Domestic Product
/// </summary>
[Description("A191RL1Q225SBEA")]
A191RL1Q225SBEA,

/// <summary>
/// US 30-Year fixed rate mortgage average
/// </summary>
[Description("MORTGAGE30US")]
MORTGAGE30US,

/// <summary>
/// US 15-Year fixed rate mortgage average
/// </summary>
[Description("MORTGAGE15US")]
MORTGAGE15US,

/// <summary>
/// US 5/1-Year adjustable rate mortgage average
/// </summary>
[Description("MORTGAGE5US")]
MORTGAGE5US,

/// <summary>
/// Total Housing Starts in thousands of units, seasonally adjusted annual rate
/// </summary>
[Description("HOUST")]
HOUST,

/// <summary>
/// Retail money funds returned as billions of dollars, seasonally adjusted
/// </summary>
[Description("UNRATE")]
UNRATE,
}
}
1 change: 0 additions & 1 deletion IEXSharp/Model/News/Response/HistoricalNewResponse.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using System;
namespace IEXSharp.Model.News.Response
{
public class HistoricalNewResponse : NewsResponse
Expand Down
3 changes: 2 additions & 1 deletion IEXSharp/Model/Shared/Response/TimeSeriesResponse.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;

namespace IEXSharp.Model.Shared.Response
{
public class TimeSeriesResponse
Expand All @@ -11,4 +12,4 @@ public class TimeSeriesResponse
public long date { get; set; }
public long updated { get; set; }
}
}
}
32 changes: 32 additions & 0 deletions IEXSharp/Service/Cloud/EconomicData/EconomicDataService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
using System.Collections.Generic;
using System.Net.Http;
using System.Threading.Tasks;
using IEXSharp.Helper;
using IEXSharp.Model;
using IEXSharp.Model.EconomicData.Request;
using IEXSharp.Model.Shared.Response;

namespace IEXSharp.Service.Cloud.EconomicData
{
public class EconomicDataService : IEconomicDataService
{
private readonly ExecutorREST executor;

public EconomicDataService(HttpClient client, string sk, string pk, bool sign)
{
executor = new ExecutorREST(client, sk, pk, sign);
}

public async Task<IEXResponse<decimal>> DataPointAsync(EconomicDataSymbol symbol)
{
var returnValue = await executor.SymbolExecuteAsync<string>("data-points/market/[symbol]", symbol.GetDescriptionFromEnum());
if (returnValue.ErrorMessage != null)
return new IEXResponse<decimal> { ErrorMessage = returnValue.ErrorMessage };
else
return new IEXResponse<decimal> { Data = decimal.Parse(returnValue.Data) };
}

public async Task<IEXResponse<IEnumerable<TimeSeriesResponse>>> TimeSeriesAsync(EconomicDataTimeSeriesSymbol? symbol) =>
await executor.SymbolExecuteAsync<IEnumerable<TimeSeriesResponse>>("time-series/economic/[symbol]", symbol.GetDescriptionFromEnum());
}
}
25 changes: 25 additions & 0 deletions IEXSharp/Service/Cloud/EconomicData/IEconomicDataService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using System.Collections.Generic;
using System.Threading.Tasks;
using IEXSharp.Model;
using IEXSharp.Model.EconomicData.Request;
using IEXSharp.Model.Shared.Response;

namespace IEXSharp.Service.Cloud.EconomicData
{
public interface IEconomicDataService
{
/// <summary>
/// <see cref="https://iexcloud.io/docs/api/#economic-data"/>
/// </summary>
/// <param name="symbol"></param>
/// <returns></returns>
Task<IEXResponse<decimal>> DataPointAsync(EconomicDataSymbol symbol);

/// <summary>
/// <see cref="https://iexcloud.io/docs/api/#economic-data"/>
/// </summary>
/// <param name="symbol"></param>
/// <returns></returns>
Task<IEXResponse<IEnumerable<TimeSeriesResponse>>> TimeSeriesAsync(EconomicDataTimeSeriesSymbol? symbol);
}
}
61 changes: 61 additions & 0 deletions IEXSharpTest/Cloud/EconomicDataTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
using System.Threading.Tasks;
using IEXSharp;
using IEXSharp.Model.EconomicData.Request;
using NUnit.Framework;

namespace IEXSharpTest.Cloud
{
public class EconomicDataTest
{
private IEXCloudClient sandBoxClient;

[SetUp]
public void Setup()
{
sandBoxClient = new IEXCloudClient(TestGlobal.pk, TestGlobal.sk, false, true);
}

[Test]
[TestCase(EconomicDataSymbol.MMNRNJ)]
[TestCase(EconomicDataSymbol.MMNRJD)]
[TestCase(EconomicDataSymbol.CPIAUCSL)]
[TestCase(EconomicDataSymbol.TERMCBCCALLNS)]
[TestCase(EconomicDataSymbol.FEDFUNDS)]
[TestCase(EconomicDataSymbol.A191RL1Q225SBEA)]
[TestCase(EconomicDataSymbol.WIMFSL)]
[TestCase(EconomicDataSymbol.IC4WSA)]
[TestCase(EconomicDataSymbol.INDPRO)]
[TestCase(EconomicDataSymbol.MORTGAGE30US)]
[TestCase(EconomicDataSymbol.MORTGAGE15US)]
[TestCase(EconomicDataSymbol.MORTGAGE5US)]
[TestCase(EconomicDataSymbol.HOUST)]
[TestCase(EconomicDataSymbol.PAYEMS)]
[TestCase(EconomicDataSymbol.TOTALSA)]
[TestCase(EconomicDataSymbol.WRMFSL)]
[TestCase(EconomicDataSymbol.UNRATE)]
[TestCase(EconomicDataSymbol.RECPROUSM156N)]
public async Task GetDataPointsTest(EconomicDataSymbol symbol)
{
var response = await sandBoxClient.EconomicData.DataPointAsync(symbol);

Assert.IsNull(response.ErrorMessage);
Assert.IsNotNull(response.Data);
}

[Test]
[TestCase(null)]
[TestCase(EconomicDataTimeSeriesSymbol.A191RL1Q225SBEA)]
[TestCase(EconomicDataTimeSeriesSymbol.MORTGAGE30US)]
[TestCase(EconomicDataTimeSeriesSymbol.MORTGAGE15US)]
[TestCase(EconomicDataTimeSeriesSymbol.MORTGAGE5US)]
[TestCase(EconomicDataTimeSeriesSymbol.HOUST)]
[TestCase(EconomicDataTimeSeriesSymbol.UNRATE)]
public async Task GetTimeSeriesTest(EconomicDataTimeSeriesSymbol symbol)
{
var response = await sandBoxClient.EconomicData.TimeSeriesAsync(symbol);

Assert.IsNull(response.ErrorMessage);
Assert.IsNotNull(response.Data);
}
}
}