Browse Source

Get dynamic quote only if american stock

Daniel Bohry 1 year ago
parent
commit
e919ee6429

+ 2 - 2
src/main/java/com/danielbohry/stocks/repository/StockRepository.java

@@ -79,7 +79,7 @@ public class StockRepository {
     public boolean isValid(String code) {
         Quote quote = repository.findByCode(code).stream().findFirst().orElse(null);
 
-        if (quote != null) return true;
+        if (quote != null && "BRL".equals(quote.getCurrency())) return true;
 
         try {
             log.info("Current stock's name is null. Requesting latest information...");
@@ -110,7 +110,7 @@ public class StockRepository {
     }
 
     private BigDecimal getLastPrice(Quote quote) {
-        if (quote.getPrice() == null) {
+        if (quote.getPrice() == null && "USD".equals(quote.getCurrency())) {
             log.info("Current quote for [{}] is null. Requesting latest quote...", quote);
             return new BigDecimal(client.getStockQuote(quote.getCode(), key).get(0).getLastPrice());
         } else if (quote.getUpdatedAt().isBefore(now().minusDays(1))) {