diff --git a/provider/src/main/java/io/bisq/provider/price/PriceData.java b/provider/src/main/java/io/bisq/provider/price/PriceData.java index 57db053ed1..9d62ad8d1e 100644 --- a/provider/src/main/java/io/bisq/provider/price/PriceData.java +++ b/provider/src/main/java/io/bisq/provider/price/PriceData.java @@ -23,13 +23,13 @@ public class PriceData { public final double a; // ask; public final double b; // bid public final double l; // last - public final long e; // epochSec + public final long ts; // timestamp - public PriceData(String currencyCode, double ask, double bid, double last, long epochSec) { + public PriceData(String currencyCode, double ask, double bid, double last, long ts) { this.c = currencyCode; this.a = ask; this.b = bid; this.l = last; - this.e = epochSec; + this.ts = ts; } } diff --git a/provider/src/main/java/io/bisq/provider/price/PriceRequestService.java b/provider/src/main/java/io/bisq/provider/price/PriceRequestService.java index da5b3a4e91..264429ec65 100644 --- a/provider/src/main/java/io/bisq/provider/price/PriceRequestService.java +++ b/provider/src/main/java/io/bisq/provider/price/PriceRequestService.java @@ -155,7 +155,10 @@ public class PriceRequestService { .filter(e -> poloniexMap == null || !poloniexMap.containsKey(e.getKey())) .forEach(e -> allPricesMap.put(e.getKey(), e.getValue())); coinmarketcapTs = Instant.now().getEpochSecond(); - log.info("Coinmarketcap LTC (last): " + map.get("LTC").l); + + if (map.get("LTC") != null) + log.info("Coinmarketcap LTC (last): " + map.get("LTC").l); + writeToJson(); } @@ -167,15 +170,21 @@ public class PriceRequestService { removeOutdatedPrices(allPricesMap); allPricesMap.putAll(poloniexMap); poloniexTs = Instant.now().getEpochSecond(); - log.info("Poloniex LTC (last): " + poloniexMap.get("LTC").l); + + if (poloniexMap.get("LTC") != null) + log.info("Poloniex LTC (last): " + poloniexMap.get("LTC").l); + writeToJson(); } private void requestBtcAverageLocalPrices() throws NoSuchAlgorithmException, InvalidKeyException, IOException, HttpException { long ts = System.currentTimeMillis(); btcAverageLocalMap = btcAverageProvider.getLocal(); - log.info("BTCAverage local USD (last):" + btcAverageLocalMap.get("USD").l); + + if (btcAverageLocalMap.get("USD") != null) + log.info("BTCAverage local USD (last):" + btcAverageLocalMap.get("USD").l); log.info("requestBtcAverageLocalPrices took {} ms.", (System.currentTimeMillis() - ts)); + removeOutdatedPrices(allPricesMap); allPricesMap.putAll(btcAverageLocalMap); btcAverageTs = Instant.now().getEpochSecond(); @@ -185,8 +194,11 @@ public class PriceRequestService { private void requestBtcAverageGlobalPrices() throws NoSuchAlgorithmException, InvalidKeyException, IOException, HttpException { long ts = System.currentTimeMillis(); Map map = btcAverageProvider.getGlobal(); - log.info("BTCAverage global USD (last):" + map.get("USD").l); + + if (map.get("USD") != null) + log.info("BTCAverage global USD (last):" + map.get("USD").l); log.info("requestBtcAverageGlobalPrices took {} ms.", (System.currentTimeMillis() - ts)); + removeOutdatedPrices(btcAverageLocalMap); removeOutdatedPrices(allPricesMap); // we don't replace prices which we got form the local request, just in case the global data are received @@ -208,10 +220,10 @@ public class PriceRequestService { } private void removeOutdatedPrices(Map map) { - long epochSecond = Instant.now().getEpochSecond(); - long limit = epochSecond - MARKET_PRICE_TTL_SEC; + long now = Instant.now().getEpochSecond(); + long limit = now - MARKET_PRICE_TTL_SEC; Map filtered = map.entrySet().stream() - .filter(e -> e.getValue().e > limit) + .filter(e -> e.getValue().ts > limit) .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)); map.clear(); map.putAll(filtered); diff --git a/provider/src/main/java/io/bisq/provider/price/providers/BtcAverageProvider.java b/provider/src/main/java/io/bisq/provider/price/providers/BtcAverageProvider.java index b71be7c16d..48c24c15bb 100644 --- a/provider/src/main/java/io/bisq/provider/price/providers/BtcAverageProvider.java +++ b/provider/src/main/java/io/bisq/provider/price/providers/BtcAverageProvider.java @@ -67,7 +67,7 @@ public class BtcAverageProvider { private Map getMap(String json) { Map marketPriceMap = new HashMap<>(); LinkedTreeMap treeMap = new Gson().>fromJson(json, LinkedTreeMap.class); - long epochSec = Instant.now().getEpochSecond(); + long ts = Instant.now().getEpochSecond(); treeMap.entrySet().stream().forEach(e -> { Object value = e.getValue(); // We need to check the type as we get an unexpected "timestamp" object at the end: @@ -79,7 +79,7 @@ public class BtcAverageProvider { (double) data.get("ask"), (double) data.get("bid"), (double) data.get("last"), - epochSec)); + ts)); } }); return marketPriceMap; diff --git a/provider/src/main/java/io/bisq/provider/price/providers/CoinmarketcapProvider.java b/provider/src/main/java/io/bisq/provider/price/providers/CoinmarketcapProvider.java index 544c7c00ec..fd2a57735c 100644 --- a/provider/src/main/java/io/bisq/provider/price/providers/CoinmarketcapProvider.java +++ b/provider/src/main/java/io/bisq/provider/price/providers/CoinmarketcapProvider.java @@ -34,7 +34,7 @@ public class CoinmarketcapProvider { Map marketPriceMap = new HashMap<>(); String response = httpClient.requestWithGET("v1/ticker/?limit=200", "User-Agent", ""); List> list = new Gson().fromJson(response, ArrayList.class); - long epochSec = Instant.now().getEpochSecond(); + long ts = Instant.now().getEpochSecond(); list.stream().forEach(treeMap -> { String code = (String) treeMap.get("symbol"); if (supportedAltcoins.contains(code)) { @@ -43,7 +43,7 @@ public class CoinmarketcapProvider { price_btc, price_btc, price_btc, - epochSec)); + ts)); } }); return marketPriceMap; diff --git a/provider/src/main/java/io/bisq/provider/price/providers/PoloniexProvider.java b/provider/src/main/java/io/bisq/provider/price/providers/PoloniexProvider.java index dfe195daef..5b5274856a 100644 --- a/provider/src/main/java/io/bisq/provider/price/providers/PoloniexProvider.java +++ b/provider/src/main/java/io/bisq/provider/price/providers/PoloniexProvider.java @@ -37,7 +37,7 @@ public class PoloniexProvider { Map marketPriceMap = new HashMap<>(); String response = httpClient.requestWithGET("?command=returnTicker", "User-Agent", ""); LinkedTreeMap treeMap = new Gson().fromJson(response, LinkedTreeMap.class); - long epochSec = Instant.now().getEpochSecond(); + long ts = Instant.now().getEpochSecond(); treeMap.entrySet().stream().forEach(e -> { Object value = e.getValue(); String invertedCurrencyPair = e.getKey(); @@ -54,7 +54,7 @@ public class PoloniexProvider { parseDouble((String) data.get("lowestAsk")), parseDouble((String) data.get("highestBid")), parseDouble((String) data.get("last")), - epochSec) + ts) ); } }