Skip to content

Commit

Permalink
bug fix: close price null from the api causing changePercent to be -I…
Browse files Browse the repository at this point in the history
…nfinite
  • Loading branch information
syuraj committed Nov 4, 2021
1 parent 57ac450 commit 9b24281
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,17 +62,18 @@ public void fetchLiveQuotesTask() throws IOException {
Stock stock = stocks.stream().filter(s -> s.symbol.equals(entry.getKey())).findFirst().get();

IexNewsQuoteResponse.Quote quote = entry.getValue().quote;
stock.price = quote.close;
if (stock.yesterdaysPrice != 0)
if (stock.yesterdaysPrice != 0 && stock.price != 0) {
stock.price = quote.latestPrice;
stock.changePercent = ((stock.price - stock.yesterdaysPrice) * 100) / stock.price;
}
stock.company = quote.companyName;
stock.peRatio = quote.peRatio;
stock.week52High = quote.week52High;
stock.week52Low = quote.week52Low;

StockHistory stockHistory = stockHistories.stream().filter(s -> s.symbol.equals(entry.getKey())).findFirst().get();

StockHistory.StockPrice intradayPrice = new StockHistory.StockPrice(quote.open, quote.high, quote.low, quote.close, quote.volume);
StockHistory.StockPrice intradayPrice = new StockHistory.StockPrice(quote.open, quote.high, quote.low, quote.latestPrice, quote.volume);
if (stockHistory.intraday_priceHistory == null)
stockHistory.intraday_priceHistory = new ArrayList<>();
stockHistory.intraday_priceHistory.add(intradayPrice);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public void execute(JobExecutionContext jobExecutionContext) throws JobExecution
&& sp.time > yesterdayStartEpoch
&& sp.time < yesterdayEndEpoch).findFirst();

if (lastPriceOptional.isPresent()) {
if (lastPriceOptional.isPresent() && stockOptional.get().price != 0) {
stockOptional.get().yesterdaysPrice = lastPriceOptional.get().close;
stockOptional.get().changePercent = ((stockOptional.get().price - stockOptional.get().yesterdaysPrice) * 100) / stockOptional.get().price;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public class Quote {
public float open;
public float high;
public float low;
public float close;
public float latestPrice;
public float volume;
public float peRatio;
public float week52High;
Expand Down

0 comments on commit 9b24281

Please sign in to comment.