Skip to content

Commit

Permalink
Merge pull request #32 from alvasw/mark_binance_as_blue_rate_provider
Browse files Browse the repository at this point in the history
Mark Binance as BlueRateProvider
  • Loading branch information
gabernard authored Sep 18, 2023
2 parents c9c8296 + aa00c05 commit ce8634a
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 10 deletions.
6 changes: 6 additions & 0 deletions src/main/java/bisq/price/spot/ArsBlueRateTransformer.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,14 @@

import bisq.price.spot.providers.BlueRateProvider;
import bisq.price.util.bluelytics.ArsBlueMarketGapProvider;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import java.util.Optional;
import java.util.OptionalDouble;

@Component
@Slf4j
public class ArsBlueRateTransformer implements ExchangeRateTransformer {
private final ArsBlueMarketGapProvider blueMarketGapProvider;

Expand All @@ -51,6 +53,10 @@ public Optional<ExchangeRate> apply(ExchangeRateProvider provider, ExchangeRate
originalExchangeRate.getTimestamp(),
originalExchangeRate.getProvider()
);

log.info(String.format("%s transformed from %s to %s",
originalExchangeRate.getCurrency(), originalExchangeRate.getPrice(), blueRate));

return Optional.of(newExchangeRate);
}

Expand Down
14 changes: 5 additions & 9 deletions src/main/java/bisq/price/spot/ExchangeRateService.java
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ private Map<String, List<ExchangeRate>> getCurrencyCodeToExchangeRates() {
for (ExchangeRate exchangeRate : exchangeRates) {
String currencyCode = exchangeRate.getCurrency();

List<ExchangeRate> transformedExchangeRates = transformers.stream()
List<ExchangeRate> finalExchangeRates = transformers.stream()
.filter(transformer -> transformer.supportedCurrency()
.equalsIgnoreCase(currencyCode)
)
Expand All @@ -184,23 +184,19 @@ private Map<String, List<ExchangeRate>> getCurrencyCodeToExchangeRates() {
.map(Optional::get)
.collect(Collectors.toList());

if (!transformedExchangeRates.isEmpty()) {
log.info(String.format("%s transformed from %s to %s", currencyCode, exchangeRate.getPrice(), transformedExchangeRates.get(0).getPrice()));
}

if (currencyCodeToExchangeRates.containsKey(currencyCode)) {
List<ExchangeRate> l = new ArrayList<>(currencyCodeToExchangeRates.get(currencyCode));
if (transformedExchangeRates.isEmpty()) {
if (finalExchangeRates.isEmpty()) {
l.add(exchangeRate);
} else {
l.addAll(transformedExchangeRates);
l.addAll(finalExchangeRates);
}
currencyCodeToExchangeRates.put(currencyCode, l);
} else {
if (transformedExchangeRates.isEmpty()) {
if (finalExchangeRates.isEmpty()) {
currencyCodeToExchangeRates.put(currencyCode, List.of(exchangeRate));
} else {
currencyCodeToExchangeRates.put(currencyCode, transformedExchangeRates);
currencyCodeToExchangeRates.put(currencyCode, finalExchangeRates);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/bisq/price/spot/providers/Binance.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
import java.util.Set;

@Component
class Binance extends ExchangeRateProvider {
class Binance extends ExchangeRateProvider implements BlueRateProvider {

public Binance(Environment env) {
super(env, "BINANCE", "binance", Duration.ofMinutes(1));
Expand Down

0 comments on commit ce8634a

Please sign in to comment.