-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Implement ExchangeRateTransformer (@alvasw) - Implement BlueLyticsApi (@alvasw) - Implement ArsBlueMarketGapProvider (@alvasw) - Implement ArsBlueRateTransformer (@alvasw) - merge @alvasw improvements - fixed bug lossing prices after merge - fix tests, all green - delete unused code
- Loading branch information
Showing
10 changed files
with
269 additions
and
211 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
/* | ||
* 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 <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package bisq.price.spot; | ||
|
||
import bisq.price.spot.providers.BlueRateProvider; | ||
import bisq.price.util.bluelytics.ArsBlueMarketGapProvider; | ||
import org.springframework.stereotype.Component; | ||
|
||
import java.util.Optional; | ||
import java.util.OptionalDouble; | ||
|
||
@Component | ||
public class ArsBlueRateTransformer implements ExchangeRateTransformer { | ||
private final ArsBlueMarketGapProvider blueMarketGapProvider; | ||
|
||
public ArsBlueRateTransformer(ArsBlueMarketGapProvider blueMarketGapProvider) { | ||
this.blueMarketGapProvider = blueMarketGapProvider; | ||
} | ||
|
||
@Override | ||
public Optional<ExchangeRate> apply(ExchangeRateProvider provider, ExchangeRate originalExchangeRate) { | ||
if (provider instanceof BlueRateProvider) { | ||
return Optional.of(originalExchangeRate); | ||
} | ||
|
||
OptionalDouble sellGapMultiplier = blueMarketGapProvider.get(); | ||
if (sellGapMultiplier.isEmpty()) { | ||
return Optional.empty(); | ||
} | ||
|
||
double blueRate = originalExchangeRate.getPrice() * sellGapMultiplier.getAsDouble(); | ||
|
||
ExchangeRate newExchangeRate = new ExchangeRate( | ||
originalExchangeRate.getCurrency(), | ||
blueRate, | ||
originalExchangeRate.getTimestamp(), | ||
originalExchangeRate.getProvider() | ||
); | ||
return Optional.of(newExchangeRate); | ||
} | ||
|
||
@Override | ||
public String supportedCurrency() { | ||
return "ARS"; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
src/main/java/bisq/price/spot/ExchangeRateTransformer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/* | ||
* 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 <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package bisq.price.spot; | ||
|
||
import java.util.Optional; | ||
|
||
public interface ExchangeRateTransformer { | ||
Optional<ExchangeRate> apply(ExchangeRateProvider provider, ExchangeRate exchangeRate); | ||
|
||
String supportedCurrency(); | ||
} |
21 changes: 21 additions & 0 deletions
21
src/main/java/bisq/price/spot/providers/BlueRateProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
/* | ||
* 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 <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package bisq.price.spot.providers; | ||
|
||
public interface BlueRateProvider { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
src/main/java/bisq/price/util/bluelytics/ArsBlueMarketGapProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
/* | ||
* 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 <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package bisq.price.util.bluelytics; | ||
|
||
import bisq.price.PriceProvider; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.stereotype.Component; | ||
|
||
import java.time.Duration; | ||
import java.util.Optional; | ||
import java.util.OptionalDouble; | ||
|
||
@Slf4j | ||
@Component | ||
public class ArsBlueMarketGapProvider extends PriceProvider<OptionalDouble> { | ||
public interface Listener { | ||
void onUpdate(OptionalDouble sellGapMultiplier); | ||
} | ||
|
||
private static final Duration REFRESH_INTERVAL = Duration.ofHours(1); | ||
|
||
private final BlueLyticsApi blueLyticsApi = new BlueLyticsApi(); | ||
private final Optional<Listener> onUpdateListener; | ||
|
||
public ArsBlueMarketGapProvider() { | ||
super(REFRESH_INTERVAL); | ||
this.onUpdateListener = Optional.empty(); | ||
} | ||
|
||
public ArsBlueMarketGapProvider(Listener onUpdateListener) { | ||
super(REFRESH_INTERVAL); | ||
this.onUpdateListener = Optional.of(onUpdateListener); | ||
} | ||
|
||
@Override | ||
protected OptionalDouble doGet() { | ||
OptionalDouble sellGapMultiplier = blueLyticsApi.getSellGapMultiplier(); | ||
onUpdateListener.ifPresent(listener -> listener.onUpdate(sellGapMultiplier)); | ||
return sellGapMultiplier; | ||
} | ||
} |
41 changes: 41 additions & 0 deletions
41
src/main/java/bisq/price/util/bluelytics/BlueLyticsApi.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/* | ||
* 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 <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package bisq.price.util.bluelytics; | ||
|
||
import org.springframework.http.MediaType; | ||
import org.springframework.web.reactive.function.client.WebClient; | ||
|
||
import java.time.Duration; | ||
import java.time.temporal.ChronoUnit; | ||
import java.util.OptionalDouble; | ||
|
||
public class BlueLyticsApi { | ||
private static final String API_URL = "https://api.bluelytics.com.ar/v2/latest"; | ||
private final WebClient webClient = WebClient.create(); | ||
|
||
public OptionalDouble getSellGapMultiplier() { | ||
BlueLyticsDto blueLyticsDto = webClient.get() | ||
.uri(API_URL) | ||
.accept(MediaType.APPLICATION_JSON) | ||
.retrieve() | ||
.bodyToMono(BlueLyticsDto.class) | ||
.block(Duration.of(30, ChronoUnit.SECONDS)); | ||
|
||
return blueLyticsDto == null ? OptionalDouble.empty() : blueLyticsDto.gapSellMultiplier(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.