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

Fixed JSON parsing issue with technical indicator response. Added new… #108

Merged
merged 1 commit into from
Mar 20, 2021
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
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