mirror of
https://github.com/boldsuck/haveno.git
synced 2024-12-22 20:19:21 +00:00
support price feed for btc and other cryptos
add btc and remove xmr from market price map closes #125
This commit is contained in:
parent
ed4394dc5d
commit
728760bbc2
3 changed files with 12 additions and 13 deletions
|
@ -27,7 +27,6 @@ import java.util.function.Consumer;
|
|||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import static bisq.common.util.MathUtils.roundDouble;
|
||||
import static bisq.core.locale.CurrencyUtil.isFiatCurrency;
|
||||
import static java.lang.String.format;
|
||||
|
||||
@Singleton
|
||||
|
@ -44,14 +43,11 @@ class CorePriceService {
|
|||
public void getMarketPrice(String currencyCode, Consumer<Double> resultHandler) {
|
||||
String upperCaseCurrencyCode = currencyCode.toUpperCase();
|
||||
|
||||
if (!isFiatCurrency(upperCaseCurrencyCode))
|
||||
throw new IllegalStateException(format("%s is not a valid currency code", upperCaseCurrencyCode));
|
||||
|
||||
if (!priceFeedService.hasPrices())
|
||||
throw new IllegalStateException("price feed service has no prices");
|
||||
|
||||
try {
|
||||
priceFeedService.setCurrencyCode(upperCaseCurrencyCode);
|
||||
priceFeedService.setCurrencyCode(upperCaseCurrencyCode, false); // TODO (woodser): skipping applying to consumer to avoid console warning spam when getting market prices over the api
|
||||
} catch (Throwable throwable) {
|
||||
log.warn("Could not set currency code in PriceFeedService", throwable);
|
||||
}
|
||||
|
|
|
@ -19,7 +19,6 @@ package bisq.core.provider.price;
|
|||
|
||||
import bisq.core.locale.CurrencyUtil;
|
||||
import bisq.core.locale.TradeCurrency;
|
||||
import bisq.core.monetary.Altcoin;
|
||||
import bisq.core.monetary.Price;
|
||||
import bisq.core.provider.PriceHttpClient;
|
||||
import bisq.core.provider.ProvidersRepository;
|
||||
|
@ -55,7 +54,6 @@ import java.util.Date;
|
|||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.Random;
|
||||
import java.util.Set;
|
||||
import java.util.function.Consumer;
|
||||
|
@ -272,15 +270,19 @@ public class PriceFeedService {
|
|||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
public void setCurrencyCode(String currencyCode) {
|
||||
setCurrencyCode(currencyCode, true);
|
||||
}
|
||||
|
||||
// TODO (woodser): necessary to skip applying to consumer to avoid console warning spam when getting market prices over the api
|
||||
public void setCurrencyCode(String currencyCode, boolean applyPriceToConsumer) {
|
||||
if (this.currencyCode == null || !this.currencyCode.equals(currencyCode)) {
|
||||
this.currencyCode = currencyCode;
|
||||
currencyCodeProperty.set(currencyCode);
|
||||
if (priceConsumer != null)
|
||||
if (applyPriceToConsumer && priceConsumer != null)
|
||||
applyPriceToConsumer();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Getter
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
|
|
@ -62,7 +62,6 @@ public class PriceProvider extends HttpClientProvider {
|
|||
String json = httpClient.get("getAllMarketPrices", "User-Agent", "bisq/"
|
||||
+ Version.VERSION + hsVersion);
|
||||
|
||||
|
||||
LinkedTreeMap<?, ?> map = new Gson().fromJson(json, LinkedTreeMap.class);
|
||||
Map<String, Long> tsMap = new HashMap<>();
|
||||
tsMap.put("btcAverageTs", ((Double) map.get("btcAverageTs")).longValue());
|
||||
|
@ -96,15 +95,17 @@ public class PriceProvider extends HttpClientProvider {
|
|||
if (isFiat) price = price * btcPerXmrFinal;
|
||||
else price = price / btcPerXmrFinal;
|
||||
|
||||
// TODO (woodser): remove xmr from list since base currency and add btc, test by doing btc/xmr trade
|
||||
|
||||
// add currency price to map
|
||||
marketPriceMap.put(currencyCode, new MarketPrice(currencyCode, price, timestampSec, true));
|
||||
} catch (Throwable t) {
|
||||
log.error(t.toString());
|
||||
t.printStackTrace();
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
// add btc to price map, remove xmr since base currency
|
||||
marketPriceMap.put("BTC", new MarketPrice("BTC", 1 / btcPerXmrFinal, marketPriceMap.get("XMR").getTimestampSec(), true));
|
||||
marketPriceMap.remove("XMR");
|
||||
return new Tuple2<>(tsMap, marketPriceMap);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue