WojciechZankowski / iextrading4j

IEX Cloud open source API wrapper

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Invalid 'marketAverage' Values (-1) In 1d Chart

theoilie opened this issue · comments

Describe the bug
marketAverage (and occasionally average) sometimes returns a value of -1 when querying a chart for a given date.

To Reproduce
Steps to reproduce the behavior:

  1. Copy the Java code below.
  2. Observe which times of the day (2018-05-29 for this example) have a marketAverage of -1.
  3. Compare the value from the JSON supplied in the stocks endpoint at the same time of the same day ("/stock/aapl/chart/date/20180529" in this example). It is not -1 in the JSON.

Expected behavior
The values for average and marketAverage in the Chart class of this Java API should always match the corresponding values from the direct JSON API.

Screenshots
N/A

Additional context
Code to reproduce:

IEXTradingClient client = IEXTradingClient.create();
List<Chart> chartList = client.executeRequest(new ChartRequestBuilder()
                .withSymbol("AAPL")
                .withChartRange(ChartRange.ONE_DAY)
                .withDate(LocalDate.of(2018, 5, 29))
                .build());
 
for (int i = 0; i < chartList.size(); i++) {
    Chart chart = chartList.get(i);
    if (chart.getMarketAverage().equals(BigDecimal.valueOf(-1))) {
        System.out.println("avg: " + chart.getAverage() + "; marketAvg: " + chart.getMarketAverage() + "(at " + chart.getMinute() + ")");
    }
}

Hey again!

So the thing is that library does strictly validates requests. According to the specification you can send a request with chartRange OR date. If you defined both parameters, library will take them in order:

  • range
  • date

So instead of sending "/stock/aapl/chart/date/20180529" request, you send request to "/stock/aapl/chart/1d" and in fact there is couple positions with -1 for marketAverage there...

So valid request would be:

List<Chart> chartList = client.executeRequest(new ChartRequestBuilder()
                .withSymbol("AAPL")
                .withDate(LocalDate.of(2018, 5, 29))
                .build());

Cheers!

Great explanation, thank you!