From 389686c2526d00b19b923627494dd2ae1a0526fc Mon Sep 17 00:00:00 2001 From: Brian Carlton <4741621+bdbc78@users.noreply.github.com> Date: Fri, 19 Mar 2021 20:15:26 -0400 Subject: [PATCH] Fixed JSON parsing issue with technical indicator response. Added newer technical indicator parameters. Updated unit test. (#108) --- IEXSharp/Helper/JSONConverters.cs | 7 +++++++ .../StockResearch/IStockResearchService.cs | 6 +++++- .../StockResearch/StockResearchService.cs | 16 ++++++++++++++-- IEXSharpTest/Cloud/CoreData/StockResearchTest.cs | 10 ++++++---- 4 files changed, 32 insertions(+), 7 deletions(-) diff --git a/IEXSharp/Helper/JSONConverters.cs b/IEXSharp/Helper/JSONConverters.cs index 6c7a4dc7..c7f8d0a8 100644 --- a/IEXSharp/Helper/JSONConverters.cs +++ b/IEXSharp/Helper/JSONConverters.cs @@ -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(); diff --git a/IEXSharp/Service/Cloud/CoreData/StockResearch/IStockResearchService.cs b/IEXSharp/Service/Cloud/CoreData/StockResearch/IStockResearchService.cs index 49c10976..094d0c00 100644 --- a/IEXSharp/Service/Cloud/CoreData/StockResearch/IStockResearchService.cs +++ b/IEXSharp/Service/Cloud/CoreData/StockResearch/IStockResearchService.cs @@ -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; @@ -83,7 +84,10 @@ public interface IStockResearchService /// /// /// + /// + /// + /// /// - Task> TechnicalIndicatorsAsync(string symbol, string indicator); + Task> TechnicalIndicatorsAsync(string symbol, string indicator, ChartRange range, bool lastIndicator = false, bool indicatorOnly = false); } } diff --git a/IEXSharp/Service/Cloud/CoreData/StockResearch/StockResearchService.cs b/IEXSharp/Service/Cloud/CoreData/StockResearch/StockResearchService.cs index 904bf6d7..b69dde9c 100644 --- a/IEXSharp/Service/Cloud/CoreData/StockResearch/StockResearchService.cs +++ b/IEXSharp/Service/Cloud/CoreData/StockResearch/StockResearchService.cs @@ -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; @@ -80,7 +81,18 @@ public async Task> KeyStatsStatAsync(string symbol, string s public async Task> PriceTargetAsync(string symbol) => await executor.SymbolExecuteAsync("stock/[symbol]/price-target", symbol); - public async Task> TechnicalIndicatorsAsync(string symbol, string indicator) => - await executor.SymbolExecuteAsync($"stock/[symbol]/indicator/{indicator}", symbol); + public async Task> 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(urlPattern, pathNvc, qsb); + } } } diff --git a/IEXSharpTest/Cloud/CoreData/StockResearchTest.cs b/IEXSharpTest/Cloud/CoreData/StockResearchTest.cs index ee473579..3b839cd1 100644 --- a/IEXSharpTest/Cloud/CoreData/StockResearchTest.cs +++ b/IEXSharpTest/Cloud/CoreData/StockResearchTest.cs @@ -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; @@ -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);