Skip to content

Commit

Permalink
Fixed JSON parsing issue with technical indicator response. Added new…
Browse files Browse the repository at this point in the history
…er technical indicator parameters. Updated unit test. (#108)
  • Loading branch information
bdbc78 committed Mar 20, 2021
1 parent 61af530 commit 389686c
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 7 deletions.
7 changes: 7 additions & 0 deletions IEXSharp/Helper/JSONConverters.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,13 @@ public override string Read(ref Utf8JsonReader reader, Type typeToConvert,
{
return null;
}
else if (reader.TokenType == JsonTokenType.StartArray)
{
using (var doc = JsonDocument.ParseValue(ref reader))
{
return doc.RootElement.GetRawText();
}
}
else
{
throw new JsonException();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System.Collections.Generic;
using System.Threading.Tasks;
using IEXSharp.Model;
using IEXSharp.Model.CoreData.StockPrices.Request;
using IEXSharp.Model.CoreData.StockResearch.Response;
using IEXSharp.Model.Shared.Request;

Expand Down Expand Up @@ -83,7 +84,10 @@ public interface IStockResearchService
/// </summary>
/// <param name="symbol"></param>
/// <param name="indicator"></param>
/// <param name="range"></param>
/// <param name="lastIndicator"></param>
/// <param name="indicatorOnly"></param>
/// <returns></returns>
Task<IEXResponse<TechnicalIndicatorsResponse>> TechnicalIndicatorsAsync(string symbol, string indicator);
Task<IEXResponse<TechnicalIndicatorsResponse>> TechnicalIndicatorsAsync(string symbol, string indicator, ChartRange range, bool lastIndicator = false, bool indicatorOnly = false);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Threading.Tasks;
using IEXSharp.Helper;
using IEXSharp.Model;
using IEXSharp.Model.CoreData.StockPrices.Request;
using IEXSharp.Model.CoreData.StockResearch.Response;
using IEXSharp.Model.Shared.Request;

Expand Down Expand Up @@ -80,7 +81,18 @@ public async Task<IEXResponse<string>> KeyStatsStatAsync(string symbol, string s
public async Task<IEXResponse<PriceTargetResponse>> PriceTargetAsync(string symbol) =>
await executor.SymbolExecuteAsync<PriceTargetResponse>("stock/[symbol]/price-target", symbol);

public async Task<IEXResponse<TechnicalIndicatorsResponse>> TechnicalIndicatorsAsync(string symbol, string indicator) =>
await executor.SymbolExecuteAsync<TechnicalIndicatorsResponse>($"stock/[symbol]/indicator/{indicator}", symbol);
public async Task<IEXResponse<TechnicalIndicatorsResponse>> TechnicalIndicatorsAsync(string symbol, string indicator, ChartRange range, bool lastIndicator = false, bool indicatorOnly = false)
{
const string urlPattern = "stock/[symbol]/indicator/[indicator]";

var qsb = new QueryStringBuilder();
qsb.Add("range", range.GetDescriptionFromEnum());
qsb.Add("lastIndicator", lastIndicator);
qsb.Add("indicatorOnly", indicatorOnly);

var pathNvc = new NameValueCollection { { "symbol", symbol }, { "indicator", indicator } };

return await executor.ExecuteAsync<TechnicalIndicatorsResponse>(urlPattern, pathNvc, qsb);
}
}
}
10 changes: 6 additions & 4 deletions IEXSharpTest/Cloud/CoreData/StockResearchTest.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System.Linq;
using System.Threading.Tasks;
using IEXSharp;
using IEXSharp.Model.CoreData.StockPrices.Request;
using IEXSharp.Model.Shared.Request;
using NUnit.Framework;

Expand Down Expand Up @@ -139,11 +140,12 @@ public async Task PriceTargetAsyncTest(string symbol)
}

[Test]
[TestCase("AAPL", "adxr")]
[TestCase("FB", "abs")]
public async Task TechnicalIndicatorsAsyncTest(string symbol, string indicator)
[TestCase("AAPL", "adxr", ChartRange.FiveDayMinute, false, false)]
[TestCase("FB", "abs", ChartRange.FiveDayMinute, true, false)]
[TestCase("GME", "rsi", ChartRange.FiveDayMinute, false, true)]
public async Task TechnicalIndicatorsAsyncTest(string symbol, string indicator, ChartRange range, bool lastIndicator = false, bool indicatorOnly = false)
{
var response = await sandBoxClient.StockResearch.TechnicalIndicatorsAsync(symbol, indicator);
var response = await sandBoxClient.StockResearch.TechnicalIndicatorsAsync(symbol, indicator, range, lastIndicator, indicatorOnly);

Assert.IsNull(response.ErrorMessage);
Assert.IsNotNull(response.Data);
Expand Down

0 comments on commit 389686c

Please sign in to comment.