Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support USDT price, update haveno submodule #39

Merged
merged 1 commit into from
Nov 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion haveno
Submodule haveno updated 185 files
19 changes: 12 additions & 7 deletions src/main/java/haveno/price/spot/ExchangeRateProvider.java
Original file line number Diff line number Diff line change
Expand Up @@ -135,10 +135,11 @@ public Set<String> getSupportedCryptoCurrencies() {
SUPPORTED_CRYPTO_CURRENCIES = CurrencyUtil.getAllSortedCryptoCurrencies().stream()
.map(TradeCurrency::getCode)
.filter(ccy -> !validatedExclusionList.contains(ccy.toUpperCase()))
.map(CurrencyUtil::getCurrencyCodeBase)
.collect(Collectors.toSet());
SUPPORTED_CRYPTO_CURRENCIES.add("XMR"); // XMR is skipped because it's a base currency
log.info("crypto currencies excluded: {}", validatedExclusionList);
log.info("crypto currencies supported: {}", SUPPORTED_CRYPTO_CURRENCIES.size());
log.info("crypto currencies supported: {}", SUPPORTED_CRYPTO_CURRENCIES);
}
// filter out any provider specific ccy exclusions
return SUPPORTED_CRYPTO_CURRENCIES.stream()
Expand Down Expand Up @@ -176,7 +177,7 @@ public void maybeClearStaleRates() {
@Override
protected void onRefresh() {
get().stream()
.filter(e -> "USD".equals(e.getCounterCurrency()) || "XMR".equals(e.getBaseCurrency()) || "ETH".equals(e.getBaseCurrency()) || "BCH".equals(e.getBaseCurrency()))
.filter(e -> "USD".equals(e.getCounterCurrency()) || "XMR".equals(e.getBaseCurrency()) || "ETH".equals(e.getBaseCurrency()) || "BCH".equals(e.getBaseCurrency()) || "USDT".equals(e.getBaseCurrency()))
.forEach(e -> log.info("{}/{}: {}", e.getBaseCurrency(), e.getCounterCurrency(), e.getPrice()));
}

Expand Down Expand Up @@ -217,8 +218,10 @@ private Set<ExchangeRate> doGetInternal(Class<? extends Exchange> exchangeClass)

// Find the desired fiat pairs (pair format is CRYPTO-FIAT)
List<CurrencyPair> desiredFiatPairs = allCurrencyPairsOnExchange.stream()
.filter(cp -> cp.base.equals(Currency.BTC) || cp.base.equals(Currency.XMR))
.filter(cp -> getSupportedFiatCurrencies().contains(cp.counter.getCurrencyCode()))
.filter(cp -> cp.base.equals(Currency.BTC) || (cp.base.equals(Currency.XMR) && !cp.counter.equals(Currency.BTC)))
.filter(cp -> getSupportedFiatCurrencies().contains(cp.counter.getCurrencyCode()) ||
// include also stablecoins, which are quoted fiat-like.. see below isInverted()
getSupportedCryptoCurrencies().contains(translateToHavenoCurrency(cp.counter.getCurrencyCode())))
.collect(Collectors.toList());

// Find the desired crypto pairs (pair format is CRYPTO-BTC)
Expand Down Expand Up @@ -348,7 +351,7 @@ public Collection<CurrencyPair> getCurrencyPairs() {
result.add(new ExchangeRate(
translateToHavenoCurrency(t.getCurrencyPair().base.getCurrencyCode()),
translateToHavenoCurrency(t.getCurrencyPair().counter.getCurrencyCode()),
t.getLast(),
last,
t.getTimestamp() == null ? new Date() : t.getTimestamp(), // some exchanges don't provide timestamps
this.getName()
));
Expand Down Expand Up @@ -383,7 +386,9 @@ protected boolean requiresFilterDuringBulkTickerRetrieval() {
}

private String translateToHavenoCurrency(String exchangeCurrency) {
// until Haveno client code is changed we map between USDT & USDT-E
return exchangeCurrency.equalsIgnoreCase("USDT") ? "USDT-E" : exchangeCurrency;
return exchangeCurrency; // skip mapping for usdt so it's universal

// map between USDT and USDT-ERC20
//return exchangeCurrency.equalsIgnoreCase("USDT") ? "USDT-ERC20" : exchangeCurrency;
}
}
8 changes: 3 additions & 5 deletions src/main/java/haveno/price/spot/ExchangeRateService.java
Original file line number Diff line number Diff line change
Expand Up @@ -299,11 +299,9 @@ private Map<String, Map<String, List<ExchangeRate>>> getAllExchangeRates() {
for (ExchangeRate providerRate : providerRates) {
if (!exchangeRates.containsKey(providerRate.getBaseCurrency())) exchangeRates.put(providerRate.getBaseCurrency(), new HashMap<String, List<ExchangeRate>>());
Map<String, List<ExchangeRate>> baseMap = exchangeRates.get(providerRate.getBaseCurrency());

String currencyCode = providerRate.getCounterCurrency();

if (!baseMap.containsKey(providerRate.getCounterCurrency())) baseMap.put(providerRate.getCounterCurrency(), new ArrayList<ExchangeRate>());
List<ExchangeRate> rates = baseMap.get(providerRate.getCounterCurrency());
String counterCurrencyCode = providerRate.getCounterCurrency();
if (!baseMap.containsKey(counterCurrencyCode)) baseMap.put(counterCurrencyCode, new ArrayList<ExchangeRate>());
List<ExchangeRate> rates = baseMap.get(counterCurrencyCode);
rates.add(providerRate);
}
}
Expand Down
Loading