-
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.
Merge pull request #17 from rodvar/feature/ars_pricenode_redundancy
Feature/ars pricenode redundancy
- Loading branch information
Showing
14 changed files
with
379 additions
and
57 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
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
31 changes: 31 additions & 0 deletions
31
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,31 @@ | ||
/* | ||
* 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; | ||
|
||
/** | ||
* An ExchangeRateTransformer allows to apply a transformation on a particular ExchangeRate | ||
* for particular supported currencies. This is useful for countries with currency controls | ||
* that have a "blue" market in place for real/free trades. | ||
*/ | ||
public interface ExchangeRateTransformer { | ||
Optional<ExchangeRate> apply(ExchangeRateProvider provider, ExchangeRate exchangeRate); | ||
|
||
String supportedCurrency(); | ||
} |
24 changes: 24 additions & 0 deletions
24
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,24 @@ | ||
/* | ||
* 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; | ||
|
||
/** | ||
* Tag for providers that provide a "blue" market exchange rate (unofficial real/free traded) | ||
*/ | ||
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
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; | ||
} | ||
} |
Oops, something went wrong.