From 2139077e0c70f87ce5b9ee4794f74284658fb5c4 Mon Sep 17 00:00:00 2001 From: Stephan Oeste Date: Thu, 27 May 2021 12:38:16 +0200 Subject: [PATCH] Remove Bitpay as a pricenode data provider --- .../bisq/price/spot/providers/Bitpay.java | 102 ------------------ .../bisq/price/spot/providers/BitpayTest.java | 34 ------ 2 files changed, 136 deletions(-) delete mode 100644 pricenode/src/main/java/bisq/price/spot/providers/Bitpay.java delete mode 100644 pricenode/src/test/java/bisq/price/spot/providers/BitpayTest.java diff --git a/pricenode/src/main/java/bisq/price/spot/providers/Bitpay.java b/pricenode/src/main/java/bisq/price/spot/providers/Bitpay.java deleted file mode 100644 index 0c44cbc2db2..00000000000 --- a/pricenode/src/main/java/bisq/price/spot/providers/Bitpay.java +++ /dev/null @@ -1,102 +0,0 @@ -/* - * This file is part of Bisq. - * - * Bisq is free software: you can redistribute it and/or modify it - * under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or (at - * your option) any later version. - * - * Bisq is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public - * License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with Bisq. If not, see . - */ - -package bisq.price.spot.providers; - -import bisq.price.spot.ExchangeRate; -import bisq.price.spot.ExchangeRateProvider; -import bisq.price.util.bitpay.BitpayMarketData; -import bisq.price.util.bitpay.BitpayTicker; - -import org.springframework.core.ParameterizedTypeReference; -import org.springframework.http.RequestEntity; -import org.springframework.stereotype.Component; -import org.springframework.web.client.RestTemplate; -import org.springframework.web.util.UriComponentsBuilder; - -import java.time.Duration; - -import java.math.BigDecimal; -import java.math.RoundingMode; - -import java.util.Arrays; -import java.util.Date; -import java.util.HashSet; -import java.util.Set; -import java.util.function.Predicate; -import java.util.stream.Stream; - -@Component -class Bitpay extends ExchangeRateProvider { - - private final RestTemplate restTemplate = new RestTemplate(); - - public Bitpay() { - super("BITPAY", "bitpay", Duration.ofMinutes(1)); - } - - @Override - public Set doGet() { - - Set result = new HashSet(); - - Predicate isDesiredFiatPair = t -> SUPPORTED_FIAT_CURRENCIES.contains(t.getCode()); - Predicate isDesiredCryptoPair = t -> SUPPORTED_CRYPTO_CURRENCIES.contains(t.getCode()); - - getTickers() - .filter(isDesiredFiatPair.or(isDesiredCryptoPair)) - .forEach(ticker -> { - boolean useInverseRate = false; - if (SUPPORTED_CRYPTO_CURRENCIES.contains(ticker.getCode())) { - // Use inverse rate for alts, because the API returns the - // conversion rate in the opposite direction than what we need - // API returns the BTC/Alt rate, we need the Alt/BTC rate - useInverseRate = true; - } - - BigDecimal rate = ticker.getRate(); - // Find the inverse rate, while using enough decimals to reflect very - // small exchange rates - BigDecimal inverseRate = (rate.compareTo(BigDecimal.ZERO) > 0) ? - BigDecimal.ONE.divide(rate, 8, RoundingMode.HALF_UP) : - BigDecimal.ZERO; - - result.add(new ExchangeRate( - ticker.getCode(), - (useInverseRate ? inverseRate : rate), - new Date(), - this.getName() - )); - }); - - return result; - } - - private Stream getTickers() { - BitpayMarketData marketData = restTemplate.exchange( - RequestEntity - .get(UriComponentsBuilder - .fromUriString("https://bitpay.com/rates").build() - .toUri()) - .build(), - new ParameterizedTypeReference() { - } - ).getBody(); - - return Arrays.stream(marketData.getData()); - } -} diff --git a/pricenode/src/test/java/bisq/price/spot/providers/BitpayTest.java b/pricenode/src/test/java/bisq/price/spot/providers/BitpayTest.java deleted file mode 100644 index 38569e1ce84..00000000000 --- a/pricenode/src/test/java/bisq/price/spot/providers/BitpayTest.java +++ /dev/null @@ -1,34 +0,0 @@ -/* - * This file is part of Bisq. - * - * Bisq is free software: you can redistribute it and/or modify it - * under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or (at - * your option) any later version. - * - * Bisq is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public - * License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with Bisq. If not, see . - */ - -package bisq.price.spot.providers; - -import bisq.price.AbstractExchangeRateProviderTest; - -import lombok.extern.slf4j.Slf4j; - -import org.junit.jupiter.api.Test; - -@Slf4j -public class BitpayTest extends AbstractExchangeRateProviderTest { - - @Test - public void doGet_successfulCall() { - doGet_successfulCall(new Bitpay()); - } - -}