From 8d63b89d5c5ebb249343da08ee79a3a1378fe5d8 Mon Sep 17 00:00:00 2001 From: erciccione Date: Thu, 4 Aug 2022 09:11:23 +0200 Subject: [PATCH] pricenode: remove provider huobi and leftover coinpaprika --- .../price/spot/providers/Coinpaprika.java | 102 ------------------ .../java/bisq/price/spot/providers/Huobi.java | 46 -------- .../bisq/price/spot/providers/HuobiTest.java | 36 ------- 3 files changed, 184 deletions(-) delete mode 100644 pricenode/src/main/java/bisq/price/spot/providers/Coinpaprika.java delete mode 100644 pricenode/src/main/java/bisq/price/spot/providers/Huobi.java delete mode 100644 pricenode/src/test/java/bisq/price/spot/providers/HuobiTest.java diff --git a/pricenode/src/main/java/bisq/price/spot/providers/Coinpaprika.java b/pricenode/src/main/java/bisq/price/spot/providers/Coinpaprika.java deleted file mode 100644 index 7dbd77122c..0000000000 --- a/pricenode/src/main/java/bisq/price/spot/providers/Coinpaprika.java +++ /dev/null @@ -1,102 +0,0 @@ -/* - * This file is part of Haveno. - * - * Haveno 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. - * - * Haveno 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 Haveno. If not, see . - */ - -package bisq.price.spot.providers; - -import bisq.price.spot.ExchangeRate; -import bisq.price.spot.ExchangeRateProvider; -import bisq.price.util.coinpaprika.CoinpaprikaMarketData; - -import org.springframework.core.ParameterizedTypeReference; -import org.springframework.core.env.Environment; -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.util.Date; -import java.util.HashSet; -import java.util.Map; -import java.util.Set; -import java.util.function.Predicate; -import java.util.stream.Collectors; - -@Component -class Coinpaprika extends ExchangeRateProvider { - - private final RestTemplate restTemplate = new RestTemplate(); - - /** - * Used to determine the currencies in which the BTC price can be quoted. There seems - * to be no programatic way to retrieve it, so we get the value from the API - * documentation (see "quotes" param decsribed at - * https://api.coinpaprika.com/#operation/getTickersById ). The hardcoded value below - * is the list of allowed values as per the API documentation, but without BTC and ETH - * as it makes no sense to quote the BTC price in them. - */ - private final static String SUPPORTED_CURRENCIES = - ("USD, EUR, PLN, KRW, GBP, CAD, JPY, RUB, TRY, NZD, AUD, CHF, UAH, HKD, " + - "SGD, NGN, PHP, MXN, BRL, THB, CLP, CNY, CZK, DKK, HUF, IDR, ILS," + - "INR, MYR, NOK, PKR, SEK, TWD, ZAR, VND, BOB, COP, PEN, ARS, ISK") - .replace(" ", ""); // Strip any spaces - - public Coinpaprika(Environment env) { - super(env, "COINPAPRIKA", "coinpaprika", Duration.ofMinutes(1)); - } - - @Override - public Set doGet() { - - // Single IP address can send less than 10 requests per second - // We make only 1 API call per provider poll, so we're not at risk of reaching it - - Set result = new HashSet(); - - Predicate isDesiredFiatPair = t -> getSupportedFiatCurrencies().contains(t.getKey()); - - getMarketData().getQuotes().entrySet().stream() - .filter(isDesiredFiatPair) - .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)) - .forEach((key, ticker) -> { - - result.add(new ExchangeRate( - key, - ticker.getPrice(), - new Date(), - this.getName() - )); - }); - - return result; - } - - private CoinpaprikaMarketData getMarketData() { - return restTemplate.exchange( - RequestEntity - .get(UriComponentsBuilder - .fromUriString( - "https://api.coinpaprika.com/v1/tickers/btc-bitcoin?quotes=" + - SUPPORTED_CURRENCIES).build() - .toUri()) - .build(), - new ParameterizedTypeReference() { - } - ).getBody(); - } -} diff --git a/pricenode/src/main/java/bisq/price/spot/providers/Huobi.java b/pricenode/src/main/java/bisq/price/spot/providers/Huobi.java deleted file mode 100644 index a64b96681c..0000000000 --- a/pricenode/src/main/java/bisq/price/spot/providers/Huobi.java +++ /dev/null @@ -1,46 +0,0 @@ -/* - * This file is part of Haveno. - * - * Haveno 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. - * - * Haveno 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 Haveno. If not, see . - */ - -package bisq.price.spot.providers; - -import bisq.price.spot.ExchangeRate; -import bisq.price.spot.ExchangeRateProvider; - -import org.knowm.xchange.huobi.HuobiExchange; - -import org.springframework.core.env.Environment; -import org.springframework.stereotype.Component; - -import java.time.Duration; - -import java.util.Set; - -@Component -class Huobi extends ExchangeRateProvider { - - public Huobi(Environment env) { - super(env, "HUOBI", "huobi", Duration.ofMinutes(1)); - } - - @Override - public Set doGet() { - // Supported fiat: - - // Supported alts: BTM, DASH, DCR, DOGE, ETC, ETH, FAIR, LTC, XMR, XZC, ZEC, ZEN - return doGet(HuobiExchange.class); - } - -} diff --git a/pricenode/src/test/java/bisq/price/spot/providers/HuobiTest.java b/pricenode/src/test/java/bisq/price/spot/providers/HuobiTest.java deleted file mode 100644 index 01e42fa72d..0000000000 --- a/pricenode/src/test/java/bisq/price/spot/providers/HuobiTest.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * This file is part of Haveno. - * - * Haveno 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. - * - * Haveno 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 Haveno. If not, see . - */ - -package bisq.price.spot.providers; - -import bisq.price.AbstractExchangeRateProviderTest; - -import org.springframework.core.env.StandardEnvironment; - -import lombok.extern.slf4j.Slf4j; - -import org.junit.jupiter.api.Test; - -@Slf4j -public class HuobiTest extends AbstractExchangeRateProviderTest { - - @Test - public void doGet_successfulCall() { - doGet_successfulCall(new Huobi(new StandardEnvironment())); - } - -}