diff --git a/src/main/java/com/sparrowwallet/sparrow/net/ExchangeSource.java b/src/main/java/com/sparrowwallet/sparrow/net/ExchangeSource.java index 437f59e6..94296430 100644 --- a/src/main/java/com/sparrowwallet/sparrow/net/ExchangeSource.java +++ b/src/main/java/com/sparrowwallet/sparrow/net/ExchangeSource.java @@ -107,6 +107,48 @@ public enum ExchangeSource { return new CoinGeckoRates(); } } + }, + BYLLS("Bylls") + { + @Override + public List getSupportedCurrencies() { + // Bylls is a CAD only exchange + String currency = getRates().public_price.to_currency; + if (ExchangeSource.isValidISO4217Code(currency.toUpperCase(Locale.ROOT))) { + return Arrays.asList(Currency.getInstance(currency.toUpperCase(Locale.ROOT))); + } else { + return new ArrayList(); + } + } + + @Override + public Double getExchangeRate(Currency currency) { + return getRates().public_price.to_price; + } + + private ByllsRates getRates() + { + String url = "https://bylls.com/api/price?from_currency=BTC&to_currency=CAD"; + Proxy proxy = AppServices.getProxy(); + + if(log.isInfoEnabled()) { + log.info("Requesting exchange rates from " + url); + } + + try(InputStream is = (proxy == null ? new URL(url).openStream() : new URL(url).openConnection(proxy).getInputStream()); Reader reader = new InputStreamReader(is, StandardCharsets.UTF_8)) + { + Gson gson = new Gson(); + return gson.fromJson(reader, ByllsRates.class); + } + catch (Exception e) { + if (log.isDebugEnabled()) { + log.warn("Error retrieving currency rates", e); + } else { + log.warn("Error retrieving currency rates (" + e.getMessage() + ")"); + } + return new ByllsRates(); + } + } }; private static final Logger log = LoggerFactory.getLogger(ExchangeSource.class); @@ -194,4 +236,15 @@ public enum ExchangeSource { Double value; String type; } + + private static class ByllsRate { + String from_currency; + String to_currency; + Double from_price; + Double to_price; + } + + private static class ByllsRates { + ByllsRate public_price; + } } diff --git a/src/main/resources/com/sparrowwallet/sparrow/preferences/general.fxml b/src/main/resources/com/sparrowwallet/sparrow/preferences/general.fxml index b008a55d..9a74347a 100644 --- a/src/main/resources/com/sparrowwallet/sparrow/preferences/general.fxml +++ b/src/main/resources/com/sparrowwallet/sparrow/preferences/general.fxml @@ -66,6 +66,7 @@ +