From 25e0392f3de520abbdfb2038be3feb7193dda226 Mon Sep 17 00:00:00 2001 From: Alva Swanson Date: Thu, 3 Aug 2023 20:30:39 +0200 Subject: [PATCH 1/2] Update bisq module to 17abc0b - Enforce bisq module Guava version --- bisq | 2 +- build.gradle | 2 ++ platform/build.gradle | 9 +++++++++ settings.gradle | 2 ++ 4 files changed, 14 insertions(+), 1 deletion(-) create mode 100644 platform/build.gradle diff --git a/bisq b/bisq index 169aca1..17abc0b 160000 --- a/bisq +++ b/bisq @@ -1 +1 @@ -Subproject commit 169aca18c22ecc6b5553dd182708e14237ee01d6 +Subproject commit 17abc0bc8dc93ab836040662017f81a5c391c436 diff --git a/build.gradle b/build.gradle index 72f5471..f439779 100644 --- a/build.gradle +++ b/build.gradle @@ -42,6 +42,8 @@ configurations.all { } dependencies { + implementation enforcedPlatform(project(':platform')) + // We need three subprojects from includeBuild('bisq'), with some of their transitive dependencies. implementation 'bisq:assets' implementation 'bisq:common' diff --git a/platform/build.gradle b/platform/build.gradle new file mode 100644 index 0000000..12dd285 --- /dev/null +++ b/platform/build.gradle @@ -0,0 +1,9 @@ +plugins { + id 'java-platform' +} + +dependencies { + constraints { + api 'com.google.guava:guava:30.1.1-jre' + } +} \ No newline at end of file diff --git a/settings.gradle b/settings.gradle index ab010b4..96caa95 100644 --- a/settings.gradle +++ b/settings.gradle @@ -5,4 +5,6 @@ pluginManagement { includeBuild('bisq-gradle') } rootProject.name = 'bisq-pricenode' + includeBuild('bisq') +include 'platform' \ No newline at end of file From a3cd9a198a270e3f4041b5fd1dc49029cf4af85d Mon Sep 17 00:00:00 2001 From: Rodrigo Varela Date: Thu, 13 Jul 2023 16:45:53 +1000 Subject: [PATCH 2/2] Add support for ARS free market price - setup cryptoya api price provider - add cryptoya pricenode provider - algorithm to decide rate based on fetched tickers - add test for new exchange rate provider - code review suggestions --- .../bisq/price/spot/providers/CryptoYa.java | 86 +++++++++++++++++++ .../util/cryptoya/CryptoYaMarketData.java | 75 ++++++++++++++++ .../price/util/cryptoya/CryptoYaTicker.java | 37 ++++++++ .../price/spot/providers/CryptoYaTest.java | 33 +++++++ 4 files changed, 231 insertions(+) create mode 100644 src/main/java/bisq/price/spot/providers/CryptoYa.java create mode 100644 src/main/java/bisq/price/util/cryptoya/CryptoYaMarketData.java create mode 100644 src/main/java/bisq/price/util/cryptoya/CryptoYaTicker.java create mode 100644 src/test/java/bisq/price/spot/providers/CryptoYaTest.java diff --git a/src/main/java/bisq/price/spot/providers/CryptoYa.java b/src/main/java/bisq/price/spot/providers/CryptoYa.java new file mode 100644 index 0000000..cfd431e --- /dev/null +++ b/src/main/java/bisq/price/spot/providers/CryptoYa.java @@ -0,0 +1,86 @@ +/* + * 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.cryptoya.CryptoYaMarketData; +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.math.BigDecimal; +import java.time.Duration; +import java.util.Date; +import java.util.HashSet; +import java.util.Set; + +/** + * CryptoYa is used only for Argentina Peso (ARS). + * Currency controls in the country forces a black market where the currency can be traded freely. + * Official and easily available rates cannot be trusted, therefore a specific fetch needs to be done + * for these scenarios. + * This ExchangeRateProvider provides a real market rate (black or "blue") for ARS/BTC + */ +@Component +class CryptoYa extends ExchangeRateProvider { + + private static final String ARS_BTC_URL = "https://criptoya.com/api/btc/ars/0.1"; + + private final RestTemplate restTemplate = new RestTemplate(); + + public CryptoYa(Environment env) { + super(env, "CRYPTOYA", "cryptoya", Duration.ofMinutes(1)); + } + + /** + * + * @return average price buy/sell price averaging different providers suported by cryptoya api + * which uses the free market (or blue, or unofficial) ARS price for BTC + */ + @Override + public Set doGet() { + Set result = new HashSet<>(); + String key = "ARS"; + Double rate = getARSBlueMarketData().averageBlueRate(); + if (rate > 0.0d) { + result.add(new ExchangeRate( + key, + BigDecimal.valueOf(rate), + new Date(), + this.getName() + )); + } + return result; + } + + private CryptoYaMarketData getARSBlueMarketData() { + return restTemplate.exchange( + RequestEntity + .get(UriComponentsBuilder + .fromUriString(CryptoYa.ARS_BTC_URL).build() + .toUri()) + .build(), + new ParameterizedTypeReference() { + } + ).getBody(); + } +} diff --git a/src/main/java/bisq/price/util/cryptoya/CryptoYaMarketData.java b/src/main/java/bisq/price/util/cryptoya/CryptoYaMarketData.java new file mode 100644 index 0000000..894d90c --- /dev/null +++ b/src/main/java/bisq/price/util/cryptoya/CryptoYaMarketData.java @@ -0,0 +1,75 @@ +/* + * 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.util.cryptoya; + + +import lombok.Getter; +import lombok.Setter; + +import java.time.Instant; +import java.time.temporal.ChronoUnit; +import java.util.Objects; +import java.util.stream.Stream; + +@Getter +@Setter +public class CryptoYaMarketData { + + private CryptoYaTicker argenbtc; + private CryptoYaTicker buenbit; + private CryptoYaTicker ripio; + private CryptoYaTicker ripioexchange; + private CryptoYaTicker satoshitango; + private CryptoYaTicker cryptomkt; + private CryptoYaTicker decrypto; + private CryptoYaTicker latamex; + private CryptoYaTicker bitso; + private CryptoYaTicker letsbit; + private CryptoYaTicker fiwind; + private CryptoYaTicker lemoncash; + private CryptoYaTicker bitmonedero; + private CryptoYaTicker belo; + private CryptoYaTicker tiendacrypto; + private CryptoYaTicker saldo; + private CryptoYaTicker kriptonmarket; + private CryptoYaTicker calypso; + private CryptoYaTicker bybit; + private CryptoYaTicker binance; + + /** + * + * @return the avg ask price from all the exchanges that have updated ask prices (not older than 1 day) + * if no market data available returns 0 + */ + public Double averageBlueRate() { + // filter more than 1 day old values with yesterday UTC timestamp + Long yesterdayTimestamp = Instant.now().minus(1, ChronoUnit.DAYS).getEpochSecond(); + return streamLatestAvailableMarkets(yesterdayTimestamp).mapToDouble(CryptoYaTicker::getAsk) + .average() + .orElse(0.0d); + } + + private Stream streamLatestAvailableMarkets(Long startingTime) { + return Stream.of(argenbtc, buenbit, ripio, ripioexchange, satoshitango, + cryptomkt, decrypto, latamex, bitso, letsbit, fiwind, + lemoncash, bitmonedero, belo, tiendacrypto, saldo, + kriptonmarket, calypso, bybit, binance) + .filter(Objects::nonNull) + .filter(rate -> rate.getTime() > startingTime); + } +} diff --git a/src/main/java/bisq/price/util/cryptoya/CryptoYaTicker.java b/src/main/java/bisq/price/util/cryptoya/CryptoYaTicker.java new file mode 100644 index 0000000..e3ac0a3 --- /dev/null +++ b/src/main/java/bisq/price/util/cryptoya/CryptoYaTicker.java @@ -0,0 +1,37 @@ +/* + * 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.util.cryptoya; + +import lombok.Getter; +import lombok.Setter; + +@Getter +@Setter +public class CryptoYaTicker { + + private Double ask; + + private Double totalAsk; + + private Double bid; + + private Double totalBid; + + private Integer time; + +} diff --git a/src/test/java/bisq/price/spot/providers/CryptoYaTest.java b/src/test/java/bisq/price/spot/providers/CryptoYaTest.java new file mode 100644 index 0000000..1aecb83 --- /dev/null +++ b/src/test/java/bisq/price/spot/providers/CryptoYaTest.java @@ -0,0 +1,33 @@ +/* + * 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; +import org.springframework.core.env.StandardEnvironment; + +@Slf4j +public class CryptoYaTest extends AbstractExchangeRateProviderTest { + + @Test + public void doGet_successfulCall() { + doGet_successfulCall(new CryptoYa(new StandardEnvironment())); + } + +}