@Override public BigDecimal getExchangeRateLast(String cryptoCurrency, String fiatCurrency) { if (!(ICurrencies.GRS.equalsIgnoreCase(cryptoCurrency))) { return null; } if (!(ICurrencies.EUR.equalsIgnoreCase(fiatCurrency))) { return null; } String key = cryptoCurrency + "_" + fiatCurrency; synchronized (rateAmounts) { long now = System.currentTimeMillis(); BigDecimal amount = rateAmounts.get(key); if (amount == null) { BigDecimal result = getExchangeRateLastSync(cryptoCurrency, fiatCurrency); log.debug("Called GroestlcoinTicker exchange for rate: " + key + " = " + result); rateAmounts.put(key, result); rateTimes.put(key, now + MAXIMUM_ALLOWED_TIME_OFFSET); return result; } else { Long expirationTime = rateTimes.get(key); if (expirationTime > now) { return rateAmounts.get(key); } else { // do the job; BigDecimal result = getExchangeRateLastSync(cryptoCurrency, fiatCurrency); log.debug("Called GroestlcoinTicker exchange for rate: " + key + " = " + result); rateAmounts.put(key, result); rateTimes.put(key, now + MAXIMUM_ALLOWED_TIME_OFFSET); return result; } } } }
private BigDecimal getExchangeRateLastSync(String cryptoCurrency, String fiatCurrency) { if (!(ICurrencies.GRS.equalsIgnoreCase(cryptoCurrency))) { return null; } if (!(ICurrencies.EUR.equalsIgnoreCase(fiatCurrency))) { return null; } GroestlcoinTickerResponse ticker = api.getTicker(); if (ticker != null && ticker.getEUR() != null) { if (ICurrencies.EUR.equalsIgnoreCase(fiatCurrency)) { return ticker.getEUR().getSell15m(); } return null; } return null; }