Add getBsqPrice method to PriceFeedService

This commit is contained in:
Manfred Karrer 2018-10-30 20:46:26 -05:00
parent 0c9a1ad1a7
commit 2d3269a07a
No known key found for this signature in database
GPG key ID: 401250966A6B2C46
3 changed files with 22 additions and 13 deletions

View file

@ -22,7 +22,6 @@ import bisq.core.btc.wallet.BsqWalletService;
import bisq.core.btc.wallet.Restrictions;
import bisq.core.locale.CurrencyUtil;
import bisq.core.locale.Res;
import bisq.core.monetary.Altcoin;
import bisq.core.monetary.Price;
import bisq.core.monetary.Volume;
import bisq.core.provider.fee.FeeService;
@ -308,10 +307,9 @@ public class OfferUtil {
if (isCurrencyForMakerFeeBtc) {
return Optional.of(userCurrencyPrice.getVolumeByAmount(makerFee));
} else {
MarketPrice bsqMarketPrice = priceFeedService.getMarketPrice("BSQ");
if (bsqMarketPrice != null) {
long bsqPriceAsLong = MathUtils.roundDoubleToLong(MathUtils.scaleUpByPowerOf10(bsqMarketPrice.getPrice(), Altcoin.SMALLEST_UNIT_EXPONENT));
Price bsqPrice = Price.valueOf("BSQ", bsqPriceAsLong);
Optional<Price> optionalBsqPrice = priceFeedService.getBsqPrice();
if (optionalBsqPrice.isPresent()) {
Price bsqPrice = optionalBsqPrice.get();
String inputValue = bsqFormatter.formatCoin(makerFee);
Volume makerFeeAsVolume = Volume.parse(inputValue, "BSQ");
Coin requiredBtc = bsqPrice.getAmountByVolume(makerFeeAsVolume);

View file

@ -19,6 +19,7 @@ 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.PriceNodeHttpClient;
import bisq.core.provider.ProvidersRepository;
@ -53,6 +54,7 @@ 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;
@ -323,6 +325,15 @@ public class PriceFeedService {
});
}
public Optional<Price> getBsqPrice() {
MarketPrice bsqMarketPrice = getMarketPrice("BSQ");
if (bsqMarketPrice != null) {
long bsqPriceAsLong = MathUtils.roundDoubleToLong(MathUtils.scaleUpByPowerOf10(bsqMarketPrice.getPrice(), Altcoin.SMALLEST_UNIT_EXPONENT));
return Optional.of(Price.valueOf("BSQ", bsqPriceAsLong));
} else {
return Optional.empty();
}
}
///////////////////////////////////////////////////////////////////////////////////////////
// Private

View file

@ -29,14 +29,11 @@ import bisq.core.dao.state.DaoStateListener;
import bisq.core.dao.state.blockchain.Block;
import bisq.core.dao.state.governance.IssuanceType;
import bisq.core.locale.Res;
import bisq.core.monetary.Altcoin;
import bisq.core.monetary.Price;
import bisq.core.provider.price.MarketPrice;
import bisq.core.provider.price.PriceFeedService;
import bisq.core.user.Preferences;
import bisq.core.util.BsqFormatter;
import bisq.common.util.MathUtils;
import bisq.common.util.Tuple3;
import org.bitcoinj.core.Coin;
@ -51,6 +48,8 @@ import javafx.scene.layout.VBox;
import javafx.beans.value.ChangeListener;
import java.util.Optional;
import static bisq.desktop.util.FormBuilder.addTitledGroupBg;
import static bisq.desktop.util.FormBuilder.addTopLabelReadOnlyTextField;
@ -219,12 +218,13 @@ public class BsqDashboardView extends ActivatableView<GridPane, Void> implements
private void updatePrice() {
Coin issuedAmount = daoFacade.getGenesisTotalSupply();
MarketPrice bsqMarketPrice = priceFeedService.getMarketPrice("BSQ");
if (bsqMarketPrice != null) {
long bsqPrice = MathUtils.roundDoubleToLong(MathUtils.scaleUpByPowerOf10(bsqMarketPrice.getPrice(), Altcoin.SMALLEST_UNIT_EXPONENT));
priceTextField.setText(bsqFormatter.formatPrice(Price.valueOf("BSQ", bsqPrice)) + " BSQ/BTC");
Optional<Price> optionalBsqPrice = priceFeedService.getBsqPrice();
if (optionalBsqPrice.isPresent()) {
Price bsqPrice = optionalBsqPrice.get();
priceTextField.setText(bsqFormatter.formatPrice(bsqPrice) + " BSQ/BTC");
marketCapTextField.setText(bsqFormatter.formatMarketCap(bsqMarketPrice, priceFeedService.getMarketPrice("USD"), issuedAmount));
marketCapTextField.setText(bsqFormatter.formatMarketCap(priceFeedService.getMarketPrice("BSQ"),
priceFeedService.getMarketPrice("USD"), issuedAmount));
} else {
priceTextField.setText(Res.get("shared.na"));
marketCapTextField.setText(Res.get("shared.na"));