Skip to content

Commit

Permalink
incorporated IEXResponse into remaining StockService V2 methods which…
Browse files Browse the repository at this point in the history
… use SymbolExecuteAsync()

- adjusted tests accordingly
- second half of methods in StockService V2
  • Loading branch information
vslee committed Mar 23, 2020
1 parent 51b943c commit bd06047
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 52 deletions.
22 changes: 11 additions & 11 deletions IEXSharp/Service/V2/Stock/IStockService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ public interface IStockService
/// </summary>
/// <param name="symbol"></param>
/// <returns></returns>
Task<KeyStatsResponse> KeyStatsAsync(string symbol);
Task<IEXResponse<KeyStatsResponse>> KeyStatsAsync(string symbol);

/// <summary>
/// <see cref="https://iexcloud.io/docs/api/#key-stats"/>
Expand All @@ -282,7 +282,7 @@ public interface IStockService
/// </summary>
/// <param name="symbol"></param>
/// <returns></returns>
Task<IEnumerable<LargestTradeResponse>> LargestTradesAsync(string symbol);
Task<IEXResponse<IEnumerable<LargestTradeResponse>>> LargestTradesAsync(string symbol);

/// <summary>
/// <see cref="https://iexcloud.io/docs/api/#list"/>
Expand All @@ -296,7 +296,7 @@ public interface IStockService
/// </summary>
/// <param name="symbol"></param>
/// <returns></returns>
Task<LogoResponse> LogoAsync(string symbol);
Task<IEXResponse<LogoResponse>> LogoAsync(string symbol);

/// <summary>
/// <see cref="https://iexcloud.io/docs/api/#market-volume-u-s"/>
Expand All @@ -317,42 +317,42 @@ public interface IStockService
/// </summary>
/// <param name="symbol"></param>
/// <returns></returns>
Task<OHLCResponse> OHLCAsync(string symbol);
Task<IEXResponse<OHLCResponse>> OHLCAsync(string symbol);

/// <summary>
/// <see cref="https://iexcloud.io/docs/api/#peers"/>
/// </summary>
/// <param name="symbol"></param>
/// <returns></returns>
Task<IEnumerable<string>> PeersAsync(string symbol);
Task<IEXResponse<IEnumerable<string>>> PeersAsync(string symbol);

/// <summary>
/// <see cref="https://iexcloud.io/docs/api/#previous-day-price"/>
/// </summary>
/// <param name="symbol"></param>
/// <returns></returns>
Task<HistoricalPriceResponse> PreviousDayPriceAsync(string symbol);
Task<IEXResponse<HistoricalPriceResponse>> PreviousDayPriceAsync(string symbol);

/// <summary>
/// <see cref="https://iexcloud.io/docs/api/#price"/>
/// </summary>
/// <param name="symbol"></param>
/// <returns></returns>
Task<decimal> PriceAsync(string symbol);
Task<IEXResponse<decimal>> PriceAsync(string symbol);

/// <summary>
/// <see cref="https://iexcloud.io/docs/api/#price-target"/>
/// </summary>
/// <param name="symbol"></param>
/// <returns></returns>
Task<PriceTargetResponse> PriceTargetAsync(string symbol);
Task<IEXResponse<PriceTargetResponse>> PriceTargetAsync(string symbol);

/// <summary>
/// <see cref="https://iexcloud.io/docs/api/#quote"/>
/// </summary>
/// <param name="symbol"></param>
/// <returns></returns>
Task<Quote> QuoteAsync(string symbol);
Task<IEXResponse<Quote>> QuoteAsync(string symbol);

/// <summary>
/// <see cref="https://iexcloud.io/docs/api/#quote"/>
Expand All @@ -367,7 +367,7 @@ public interface IStockService
/// </summary>
/// <param name="symbol"></param>
/// <returns></returns>
Task<IEnumerable<RecommendationTrendResponse>> RecommendationTrendAsync(string symbol);
Task<IEXResponse<IEnumerable<RecommendationTrendResponse>>> RecommendationTrendAsync(string symbol);

/// <summary>
/// <see cref="https://iexcloud.io/docs/api/#sector-performance"/>
Expand Down Expand Up @@ -404,6 +404,6 @@ public interface IStockService
/// </summary>
/// <param name="symbol"></param>
/// <returns></returns>
Task<VolumeByVenueResponse> VolumeByVenueAsync(string symbol);
Task<IEXResponse<VolumeByVenueResponse>> VolumeByVenueAsync(string symbol);
}
}
49 changes: 26 additions & 23 deletions IEXSharp/Service/V2/Stock/StockService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -354,8 +354,8 @@ public async Task<IEXResponse<IPOCalendar>> IPOCalendarAsync(IPOType ipoType)
return await executor.ExecuteAsync<IPOCalendar>(urlPattern, pathNvc, qsb);
}

public async Task<KeyStatsResponse> KeyStatsAsync(string symbol) =>
await executor.SymbolExecuteAsyncLegacy<KeyStatsResponse>("stock/[symbol]/stats", symbol);
public async Task<IEXResponse<KeyStatsResponse>> KeyStatsAsync(string symbol) =>
await executor.SymbolExecuteAsync<KeyStatsResponse>("stock/[symbol]/stats", symbol);

public async Task<IEXResponse<KeyStatsResponse>> KeyStatsStatAsync(string symbol, string stat)
{
Expand All @@ -369,8 +369,8 @@ public async Task<IEXResponse<KeyStatsResponse>> KeyStatsStatAsync(string symbol
return await executor.ExecuteAsync<KeyStatsResponse>(urlPattern, pathNvc, qsb);
}

public async Task<IEnumerable<LargestTradeResponse>> LargestTradesAsync(string symbol) =>
await executor.SymbolExecuteAsyncLegacy<IEnumerable<LargestTradeResponse>>("stock/[symbol]/largest-trades", symbol);
public async Task<IEXResponse<IEnumerable<LargestTradeResponse>>> LargestTradesAsync(string symbol) =>
await executor.SymbolExecuteAsync<IEnumerable<LargestTradeResponse>>("stock/[symbol]/largest-trades", symbol);

public async Task<IEXResponse<IEnumerable<Quote>>> ListAsync(string listType)
{
Expand All @@ -384,35 +384,38 @@ public async Task<IEXResponse<IEnumerable<Quote>>> ListAsync(string listType)
return await executor.ExecuteAsync<IEnumerable<Quote>>(urlPattern, pathNvc, qsb);
}

public async Task<LogoResponse> LogoAsync(string symbol) =>
await executor.SymbolExecuteAsyncLegacy<LogoResponse>("stock/[symbol]/logo", symbol);
public async Task<IEXResponse<LogoResponse>> LogoAsync(string symbol) =>
await executor.SymbolExecuteAsync<LogoResponse>("stock/[symbol]/logo", symbol);

public async Task<IEXResponse<IEnumerable<MarketVolumeUSResponse>>> MarketVolumeUSAsync() =>
await executor.NoParamExecute<IEnumerable<MarketVolumeUSResponse>>("market");

public async Task<IEXResponse<IEnumerable<NewsResponse>>> NewsAsync(string symbol, int last = 10) =>
await executor.SymbolLastExecuteAsync<IEnumerable<NewsResponse>>("stock/[symbol]/news/last/[last]", symbol, last);

public async Task<OHLCResponse> OHLCAsync(string symbol) =>
await executor.SymbolExecuteAsyncLegacy<OHLCResponse>("stock/[symbol]/ohlc", symbol);
public async Task<IEXResponse<OHLCResponse>> OHLCAsync(string symbol) =>
await executor.SymbolExecuteAsync<OHLCResponse>("stock/[symbol]/ohlc", symbol);

public async Task<IEnumerable<string>> PeersAsync(string symbol) =>
await executor.SymbolExecuteAsyncLegacy<IEnumerable<string>>("stock/[symbol]/peers", symbol);
public async Task<IEXResponse<IEnumerable<string>>> PeersAsync(string symbol) =>
await executor.SymbolExecuteAsync<IEnumerable<string>>("stock/[symbol]/peers", symbol);

public async Task<HistoricalPriceResponse> PreviousDayPriceAsync(string symbol) =>
await executor.SymbolExecuteAsyncLegacy<HistoricalPriceResponse>("stock/[symbol]/previous", symbol);
public async Task<IEXResponse<HistoricalPriceResponse>> PreviousDayPriceAsync(string symbol) =>
await executor.SymbolExecuteAsync<HistoricalPriceResponse>("stock/[symbol]/previous", symbol);

public async Task<decimal> PriceAsync(string symbol)
public async Task<IEXResponse<decimal>> PriceAsync(string symbol)
{
var returnValue = await executor.SymbolExecuteAsyncLegacy<string>("stock/[symbol]/price", symbol);
return decimal.Parse(returnValue);
var returnValue = await executor.SymbolExecuteAsync<string>("stock/[symbol]/price", symbol);
if (returnValue.ErrorMessage != null)
return new IEXResponse<decimal>() { ErrorMessage = returnValue.ErrorMessage };
else
return new IEXResponse<decimal>() { Data = decimal.Parse(returnValue.Data) };
}

public async Task<PriceTargetResponse> PriceTargetAsync(string symbol) =>
await executor.SymbolExecuteAsyncLegacy<PriceTargetResponse>("stock/[symbol]/price-target", symbol);
public async Task<IEXResponse<PriceTargetResponse>> PriceTargetAsync(string symbol) =>
await executor.SymbolExecuteAsync<PriceTargetResponse>("stock/[symbol]/price-target", symbol);

public async Task<Quote> QuoteAsync(string symbol) =>
await executor.SymbolExecuteAsyncLegacy<Quote>("stock/[symbol]/quote", symbol);
public async Task<IEXResponse<Quote>> QuoteAsync(string symbol) =>
await executor.SymbolExecuteAsync<Quote>("stock/[symbol]/quote", symbol);

public async Task<IEXResponse<string>> QuoteFieldAsync(string symbol, string field)
{
Expand All @@ -426,8 +429,8 @@ public async Task<IEXResponse<string>> QuoteFieldAsync(string symbol, string fie
return await executor.ExecuteAsync<string>(urlPattern, pathNvc, qsb);
}

public async Task<IEnumerable<RecommendationTrendResponse>> RecommendationTrendAsync(string symbol) =>
await executor.SymbolExecuteAsyncLegacy<IEnumerable<RecommendationTrendResponse>>(
public async Task<IEXResponse<IEnumerable<RecommendationTrendResponse>>> RecommendationTrendAsync(string symbol) =>
await executor.SymbolExecuteAsync<IEnumerable<RecommendationTrendResponse>>(
"stock/[symbol]/recommendation-trends", symbol);

public async Task<IEXResponse<IEnumerable<SectorPerformanceResponse>>> SectorPerformanceAsync() =>
Expand Down Expand Up @@ -469,7 +472,7 @@ public async Task<IEXResponse<UpcomingEventMarketResponse>> UpcomingEventMarketA
return await executor.ExecuteAsync<UpcomingEventMarketResponse>(urlPattern, pathNvc, qsb);
}

public async Task<VolumeByVenueResponse> VolumeByVenueAsync(string symbol) =>
await executor.SymbolExecuteAsyncLegacy<VolumeByVenueResponse>("stock/[symbol]/delayed-quote", symbol);
public async Task<IEXResponse<VolumeByVenueResponse>> VolumeByVenueAsync(string symbol) =>
await executor.SymbolExecuteAsync<VolumeByVenueResponse>("stock/[symbol]/delayed-quote", symbol);
}
}
51 changes: 33 additions & 18 deletions IEXSharpTest/Cloud(V2)/StockTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,8 @@ public async Task KeyStatsAsyncTest(string symbol)
{
var response = await sandBoxClient.Stock.KeyStatsAsync(symbol);

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

[Test]
Expand All @@ -455,7 +456,8 @@ public async Task KeyStatsStatAsync(string symbol, string stat)
{
var response = await sandBoxClient.Stock.KeyStatsStatAsync(symbol, stat);

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

[Test]
Expand All @@ -465,8 +467,9 @@ public async Task LargestTradesAsyncTest(string symbol)
{
var response = await sandBoxClient.Stock.LargestTradesAsync(symbol);

Assert.IsNotNull(response);
Assert.GreaterOrEqual(response.Count(), 0);
Assert.IsNull(response.ErrorMessage);
Assert.IsNotNull(response.Data);
Assert.GreaterOrEqual(response.Data.Count(), 1);
}

[Test]
Expand All @@ -492,7 +495,8 @@ public async Task LogoAsyncTest(string symbol)
{
var response = await sandBoxClient.Stock.LogoAsync(symbol);

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

[Test]
Expand Down Expand Up @@ -524,7 +528,8 @@ public async Task OHLCAsyncTest(string symbol)
{
var response = await sandBoxClient.Stock.OHLCAsync(symbol);

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

[Test]
Expand All @@ -534,8 +539,9 @@ public async Task PeersAsyncTest(string symbol)
{
var response = await sandBoxClient.Stock.PeersAsync(symbol);

Assert.IsNotNull(response);
Assert.GreaterOrEqual(response.Count(), 0);
Assert.IsNull(response.ErrorMessage);
Assert.IsNotNull(response.Data);
Assert.GreaterOrEqual(response.Data.Count(), 1);
}

[Test]
Expand All @@ -545,7 +551,8 @@ public async Task PreviousDayPriceAsyncTest(string symbol)
{
var response = await sandBoxClient.Stock.PreviousDayPriceAsync(symbol);

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

[Test]
Expand All @@ -555,7 +562,8 @@ public async Task PriceAsyncTest(string symbol)
{
var response = await sandBoxClient.Stock.PriceAsync(symbol);

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

[Test]
Expand All @@ -565,7 +573,8 @@ public async Task PriceTargetAsyncTest(string symbol)
{
var response = await sandBoxClient.Stock.PriceTargetAsync(symbol);

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

[Test]
Expand All @@ -575,7 +584,8 @@ public async Task QuoteAsyncTest(string symbol)
{
var response = await sandBoxClient.Stock.QuoteAsync(symbol);

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

[Test]
Expand All @@ -585,7 +595,8 @@ public async Task QuoteFieldAsyncTest(string symbol, string field)
{
var response = await sandBoxClient.Stock.QuoteFieldAsync(symbol, field);

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

[Test]
Expand All @@ -595,8 +606,9 @@ public async Task RecommandationTrendAsyncTest(string symbol)
{
var response = await sandBoxClient.Stock.RecommendationTrendAsync(symbol);

Assert.IsNotNull(response);
Assert.GreaterOrEqual(response.Count(), 0);
Assert.IsNull(response.ErrorMessage);
Assert.IsNotNull(response.Data);
Assert.GreaterOrEqual(response.Data.Count(), 1);
}

[Test]
Expand Down Expand Up @@ -637,7 +649,8 @@ public async Task UpcomingEventSymbolAsyncTest(string symbol, UpcomingEventType
{
var response = await sandBoxClient.Stock.UpcomingEventSymbolAsync(symbol, type);

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

// Not supported for free account
Expand All @@ -651,7 +664,8 @@ public async Task UpcomingEventMarketAsyncTest(UpcomingEventType type)
{
var response = await sandBoxClient.Stock.UpcomingEventMarketAsync(type);

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

[Test]
Expand All @@ -661,7 +675,8 @@ public async Task VolumeByVenueAsyncTest(string symbol)
{
var response = await sandBoxClient.Stock.VolumeByVenueAsync(symbol);

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

0 comments on commit bd06047

Please sign in to comment.