Java Code Examples for org.bitcoinj.utils.Fiat

The following examples show how to use org.bitcoinj.utils.Fiat. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: bisq-core   Source File: BSFormatter.java    License: GNU Affero General Public License v3.0 6 votes vote down vote up
public String formatFiat(Fiat fiat, MonetaryFormat format, boolean appendCurrencyCode) {
    if (fiat != null) {
        try {
            final String res = format.noCode().format(fiat).toString();
            if (appendCurrencyCode)
                return res + " " + fiat.getCurrencyCode();
            else
                return res;
        } catch (Throwable t) {
            log.warn("Exception at formatFiatWithCode: " + t.toString());
            return Res.get("shared.na") + " " + fiat.getCurrencyCode();
        }
    } else {
        return Res.get("shared.na");
    }
}
 
Example 2
Source Project: GreenBits   Source File: AmountFields.java    License: GNU General Public License v3.0 6 votes vote down vote up
private void convertFiatToBtc() {
    if (mConverting || mIsPausing)
        return;

    mConverting = true;

    if (mService.isElements()) {
        // fiat == btc in elements
        mAmountEdit.setText(UI.getText(mAmountFiatEdit));
        finishConversion();
        return;
    }

    try {
        final Fiat fiatValue = Fiat.parseFiat("???", UI.getText(mAmountFiatEdit));
        mAmountEdit.setText(UI.formatCoinValue(mService, mService.getFiatRate().fiatToCoin(fiatValue)));
    } catch (final ArithmeticException | IllegalArgumentException e) {
        UI.clear(mAmountEdit);
    }
    finishConversion();
}
 
Example 3
Source Project: bisq   Source File: GUIUtil.java    License: GNU Affero General Public License v3.0 6 votes vote down vote up
public static String getBsqInUsd(Price bsqPrice,
                                 Coin bsqAmount,
                                 PriceFeedService priceFeedService,
                                 BsqFormatter bsqFormatter) {
    MarketPrice usdMarketPrice = priceFeedService.getMarketPrice("USD");
    if (usdMarketPrice == null) {
        return Res.get("shared.na");
    }
    long usdMarketPriceAsLong = MathUtils.roundDoubleToLong(MathUtils.scaleUpByPowerOf10(usdMarketPrice.getPrice(),
            Fiat.SMALLEST_UNIT_EXPONENT));
    Price usdPrice = Price.valueOf("USD", usdMarketPriceAsLong);
    String bsqAmountAsString = bsqFormatter.formatCoin(bsqAmount);
    Volume bsqAmountAsVolume = Volume.parse(bsqAmountAsString, "BSQ");
    Coin requiredBtc = bsqPrice.getAmountByVolume(bsqAmountAsVolume);
    Volume volumeByAmount = usdPrice.getVolumeByAmount(requiredBtc);
    return DisplayUtils.formatAverageVolumeWithCode(volumeByAmount);
}
 
Example 4
Source Project: bisq   Source File: FormattingUtils.java    License: GNU Affero General Public License v3.0 6 votes vote down vote up
public static String formatFiat(Fiat fiat, MonetaryFormat format, boolean appendCurrencyCode) {
    if (fiat != null) {
        try {
            final String res = format.noCode().format(fiat).toString();
            if (appendCurrencyCode)
                return res + " " + fiat.getCurrencyCode();
            else
                return res;
        } catch (Throwable t) {
            log.warn("Exception at formatFiatWithCode: " + t.toString());
            return Res.get("shared.na") + " " + fiat.getCurrencyCode();
        }
    } else {
        return Res.get("shared.na");
    }
}
 
Example 5
Source Project: bcm-android   Source File: WalletTest.java    License: GNU General Public License v3.0 5 votes vote down vote up
@Test
public void sendRequestExchangeRate() throws Exception {
    receiveATransaction(wallet, myAddress);
    SendRequest sendRequest = SendRequest.to(myAddress, Coin.COIN);
    sendRequest.exchangeRate = new ExchangeRate(Fiat.parseFiat("EUR", "500"));
    wallet.completeTx(sendRequest);
    assertEquals(sendRequest.exchangeRate, sendRequest.tx.getExchangeRate());
}
 
Example 6
Source Project: bisq-core   Source File: PriceAlert.java    License: GNU Affero General Public License v3.0 5 votes vote down vote up
private void update() {
    if (user.getPriceAlertFilter() != null) {
        PriceAlertFilter filter = user.getPriceAlertFilter();
        String currencyCode = filter.getCurrencyCode();
        MarketPrice marketPrice = priceFeedService.getMarketPrice(currencyCode);
        if (marketPrice != null) {
            int exp = CurrencyUtil.isCryptoCurrency(currencyCode) ? Altcoin.SMALLEST_UNIT_EXPONENT : Fiat.SMALLEST_UNIT_EXPONENT;
            double priceAsDouble = marketPrice.getPrice();
            long priceAsLong = MathUtils.roundDoubleToLong(MathUtils.scaleUpByPowerOf10(priceAsDouble, exp));
            String currencyName = CurrencyUtil.getNameByCode(currencyCode);
            if (priceAsLong > filter.getHigh() || priceAsLong < filter.getLow()) {
                String msg = Res.get("account.notifications.priceAlert.message.msg",
                        currencyName,
                        formatter.formatMarketPrice(priceAsDouble, currencyCode),
                        formatter.getCurrencyPair(currencyCode));
                MobileMessage message = new MobileMessage(Res.get("account.notifications.priceAlert.message.title", currencyName),
                        msg,
                        MobileMessageType.PRICE);
                log.error(msg);
                try {
                    mobileNotificationService.sendMessage(message);

                    // If we got triggered an alert we remove the filter.
                    user.removePriceAlertFilter();
                } catch (Exception e) {
                    log.error(e.toString());
                    e.printStackTrace();
                }
            }
        }
    }
}
 
Example 7
Source Project: bisq-core   Source File: Price.java    License: GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * Parse the Bitcoin {@code Price} given a {@code currencyCode} and {@code inputValue}.
 *
 * @param currencyCode The currency code to parse, e.g "USD" or "LTC".
 * @param value        The value to parse as a String, e.g "2.54" or "-0.0001".
 * @return             The parsed Price.
 */
public static Price parse(String currencyCode, String value) {
    final String cleaned = value.replace(",", ".");
    if (CurrencyUtil.isFiatCurrency(currencyCode))
        return new Price(Fiat.parseFiat(currencyCode, cleaned));
    else
        return new Price(Altcoin.parseAltcoin(currencyCode, cleaned));
}
 
Example 8
Source Project: bisq-core   Source File: Price.java    License: GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * Parse the Bitcoin {@code Price} given a {@code currencyCode} and {@code inputValue}.
 *
 * @param currencyCode The currency code to parse, e.g "USD" or "LTC".
 * @param value        The value to parse.
 * @return             The parsed Price.
 */
public static Price valueOf(String currencyCode, long value) {
    if (CurrencyUtil.isFiatCurrency(currencyCode)) {
        return new Price(Fiat.valueOf(currencyCode, value));
    } else {
        return new Price(Altcoin.valueOf(currencyCode, value));
    }
}
 
Example 9
Source Project: bisq-core   Source File: Price.java    License: GNU Affero General Public License v3.0 5 votes vote down vote up
public Volume getVolumeByAmount(Coin amount) {
    if (monetary instanceof Fiat)
        return new Volume(new ExchangeRate((Fiat) monetary).coinToFiat(amount));
    else if (monetary instanceof Altcoin)
        return new Volume(new AltcoinExchangeRate((Altcoin) monetary).coinToAltcoin(amount));
    else
        throw new IllegalStateException("Monetary must be either of type Fiat or Altcoin");
}
 
Example 10
Source Project: bisq-core   Source File: Price.java    License: GNU Affero General Public License v3.0 5 votes vote down vote up
public Coin getAmountByVolume(Volume volume) {
    Monetary monetary = volume.getMonetary();
    if (monetary instanceof Fiat && this.monetary instanceof Fiat)
        return new ExchangeRate((Fiat) this.monetary).fiatToCoin((Fiat) monetary);
    else if (monetary instanceof Altcoin && this.monetary instanceof Altcoin)
        return new AltcoinExchangeRate((Altcoin) this.monetary).altcoinToCoin((Altcoin) monetary);
    else
        return Coin.ZERO;
}
 
Example 11
Source Project: bisq-core   Source File: Price.java    License: GNU Affero General Public License v3.0 5 votes vote down vote up
public Price subtract(Price other) {
    if (monetary instanceof Altcoin) {
        return new Price(((Altcoin) monetary).subtract((Altcoin) other.monetary));
    } else {
        return new Price(((Fiat) monetary).subtract((Fiat) other.monetary));
    }
}
 
Example 12
Source Project: bisq-core   Source File: Volume.java    License: GNU Affero General Public License v3.0 5 votes vote down vote up
public static Volume parse(String inputValue, String currencyCode) {
    final String cleaned = inputValue.replace(",", ".");
    if (CurrencyUtil.isFiatCurrency(currencyCode))
        return new Volume(Fiat.parseFiat(currencyCode, cleaned));
    else
        return new Volume(Altcoin.parseAltcoin(currencyCode, cleaned));
}
 
Example 13
Source Project: bisq-core   Source File: BSFormatter.java    License: GNU Affero General Public License v3.0 5 votes vote down vote up
protected Fiat parseToFiat(String input, String currencyCode) {
    if (input != null && input.length() > 0) {
        try {
            return Fiat.parseFiat(currencyCode, cleanDoubleInput(input));
        } catch (Exception e) {
            log.warn("Exception at parseToFiat: " + e.toString());
            return Fiat.valueOf(currencyCode, 0);
        }

    } else {
        return Fiat.valueOf(currencyCode, 0);
    }
}
 
Example 14
Source Project: bisq-core   Source File: BSFormatter.java    License: GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * Converts to a fiat with max. 2 decimal places. Last place gets rounded.
 * 0.234 -> 0.23
 * 0.235 -> 0.24
 *
 * @param input
 * @return
 */

public Fiat parseToFiatWithPrecision(String input, String currencyCode) {
    if (input != null && input.length() > 0) {
        try {
            return parseToFiat(new BigDecimal(cleanDoubleInput(input)).setScale(2, BigDecimal.ROUND_HALF_UP).toString(),
                    currencyCode);
        } catch (Throwable t) {
            log.warn("Exception at parseToFiatWithPrecision: " + t.toString());
            return Fiat.valueOf(currencyCode, 0);
        }

    }
    return Fiat.valueOf(currencyCode, 0);
}
 
Example 15
Source Project: bisq-core   Source File: BSFormatter.java    License: GNU Affero General Public License v3.0 5 votes vote down vote up
public String formatVolume(Volume volume, MonetaryFormat fiatVolumeFormat, boolean appendCurrencyCode) {
    if (volume != null) {
        Monetary monetary = volume.getMonetary();
        if (monetary instanceof Fiat)
            return formatFiat((Fiat) monetary, fiatVolumeFormat, appendCurrencyCode);
        else
            return formatAltcoinVolume((Altcoin) monetary, appendCurrencyCode);
    } else {
        return "";
    }
}
 
Example 16
Source Project: bisq-core   Source File: BSFormatter.java    License: GNU Affero General Public License v3.0 5 votes vote down vote up
public String formatPrice(Price price, MonetaryFormat fiatPriceFormat, boolean appendCurrencyCode) {
    if (price != null) {
        Monetary monetary = price.getMonetary();
        if (monetary instanceof Fiat)
            return formatFiat((Fiat) monetary, fiatPriceFormat, appendCurrencyCode);
        else
            return formatAltcoin((Altcoin) monetary, appendCurrencyCode);
    } else {
        return Res.get("shared.na");
    }
}
 
Example 17
Source Project: bisq-core   Source File: Offer.java    License: GNU Affero General Public License v3.0 5 votes vote down vote up
@Nullable
public Price getPrice() {
    String currencyCode = getCurrencyCode();
    if (offerPayload.isUseMarketBasedPrice()) {
        checkNotNull(priceFeedService, "priceFeed must not be null");
        MarketPrice marketPrice = priceFeedService.getMarketPrice(currencyCode);
        if (marketPrice != null && marketPrice.isRecentExternalPriceAvailable()) {
            double factor;
            double marketPriceMargin = offerPayload.getMarketPriceMargin();
            if (CurrencyUtil.isCryptoCurrency(currencyCode)) {
                factor = getDirection() == OfferPayload.Direction.SELL ?
                        1 - marketPriceMargin : 1 + marketPriceMargin;
            } else {
                factor = getDirection() == OfferPayload.Direction.BUY ?
                        1 - marketPriceMargin : 1 + marketPriceMargin;
            }
            double marketPriceAsDouble = marketPrice.getPrice();
            double targetPriceAsDouble = marketPriceAsDouble * factor;
            try {
                int precision = CurrencyUtil.isCryptoCurrency(currencyCode) ?
                        Altcoin.SMALLEST_UNIT_EXPONENT :
                        Fiat.SMALLEST_UNIT_EXPONENT;
                double scaled = MathUtils.scaleUpByPowerOf10(targetPriceAsDouble, precision);
                final long roundedToLong = MathUtils.roundDoubleToLong(scaled);
                return Price.valueOf(currencyCode, roundedToLong);
            } catch (Exception e) {
                log.error("Exception at getPrice / parseToFiat: " + e.toString() + "\n" +
                        "That case should never happen.");
                return null;
            }
        } else {
            log.debug("We don't have a market price.\n" +
                    "That case could only happen if you don't have a price feed.");
            return null;
        }
    } else {
        return Price.valueOf(currencyCode, offerPayload.getPrice());
    }
}
 
Example 18
Source Project: green_android   Source File: WalletTest.java    License: GNU General Public License v3.0 5 votes vote down vote up
@Test
public void sendRequestExchangeRate() throws Exception {
    receiveATransaction(wallet, myAddress);
    SendRequest sendRequest = SendRequest.to(myAddress, Coin.COIN);
    sendRequest.exchangeRate = new ExchangeRate(Fiat.parseFiat("EUR", "500"));
    wallet.completeTx(sendRequest);
    assertEquals(sendRequest.exchangeRate, sendRequest.tx.getExchangeRate());
}
 
Example 19
Source Project: GreenBits   Source File: GaService.java    License: GNU General Public License v3.0 5 votes vote down vote up
public String coinToFiat(final Coin btcValue) {
    if (!hasFiatRate())
        return "N/A";
    Fiat fiatValue = getFiatRate().coinToFiat(btcValue);
    // strip extra decimals (over 2 places) because that's what the old JS client does
    fiatValue = fiatValue.subtract(fiatValue.divideAndRemainder((long) Math.pow(10, Fiat.SMALLEST_UNIT_EXPONENT - 2))[1]);
    return MonetaryFormat.FIAT.minDecimals(2).noCode().format(fiatValue).toString();
}
 
Example 20
Source Project: GreenBits   Source File: GaService.java    License: GNU General Public License v3.0 5 votes vote down vote up
private Coin getSpendingLimitAmount() {
    final Coin unconverted = mLimitsData.getCoin("total");
    if (isElements())
        return unconverted.multiply(100);
    if (!mLimitsData.getBool("is_fiat"))
        return unconverted;
    // Fiat class uses SMALLEST_UNIT_EXPONENT units (10^4), our limit is
    // held in 10^2 (e.g. cents) units, hence we * 100 below.
    final Fiat fiatLimit = Fiat.valueOf("???", mLimitsData.getLong("total") * 100);
    return getFiatRate().fiatToCoin(fiatLimit);
}
 
Example 21
Source Project: GreenBits   Source File: Exchanger.java    License: GNU General Public License v3.0 5 votes vote down vote up
private double convertBtcToFiat(final Coin btcValue) {
    try {
        Fiat fiatValue = mService.getFiatRate().coinToFiat(btcValue);
        // strip extra decimals (over 2 places) because that's what the old JS client does
        fiatValue = fiatValue.subtract(fiatValue.divideAndRemainder((long) Math.pow(10, Fiat.SMALLEST_UNIT_EXPONENT - 2))[1]);
        return Double.valueOf(fiatValue.toPlainString());
    } catch (final ArithmeticException | IllegalArgumentException e) {
        return -1;
    }
}
 
Example 22
Source Project: GreenBits   Source File: WalletTest.java    License: GNU General Public License v3.0 5 votes vote down vote up
@Test
public void sendRequestExchangeRate() throws Exception {
    receiveATransaction(wallet, myAddress);
    SendRequest sendRequest = SendRequest.to(myAddress, Coin.COIN);
    sendRequest.exchangeRate = new ExchangeRate(Fiat.parseFiat("EUR", "500"));
    wallet.completeTx(sendRequest);
    assertEquals(sendRequest.exchangeRate, sendRequest.tx.getExchangeRate());
}
 
Example 23
Source Project: bisq   Source File: BsqDashboardView.java    License: GNU Affero General Public License v3.0 5 votes vote down vote up
private long getUSDAverage(List<TradeStatistics2> bsqList, List<TradeStatistics2> usdList) {
    // Use next USD/BTC print as price to calculate BSQ/USD rate
    // Store each trade as amount of USD and amount of BSQ traded
    List<Tuple2<Double, Double>> usdBsqList = new ArrayList<>(bsqList.size());
    usdList.sort(Comparator.comparing(o -> o.getTradeDate().getTime()));
    var usdBTCPrice = 10000d; // Default to 10000 USD per BTC if there is no USD feed at all

    for (TradeStatistics2 item : bsqList) {
        // Find usdprice for trade item
        usdBTCPrice = usdList.stream()
                .filter(usd -> usd.getTradeDate().getTime() > item.getTradeDate().getTime())
                .map(usd -> MathUtils.scaleDownByPowerOf10((double) usd.getTradePrice().getValue(),
                        Fiat.SMALLEST_UNIT_EXPONENT))
                .findFirst()
                .orElse(usdBTCPrice);
        var bsqAmount = MathUtils.scaleDownByPowerOf10((double) item.getTradeVolume().getValue(),
                Altcoin.SMALLEST_UNIT_EXPONENT);
        var btcAmount = MathUtils.scaleDownByPowerOf10((double) item.getTradeAmount().getValue(),
                Altcoin.SMALLEST_UNIT_EXPONENT);
        usdBsqList.add(new Tuple2<>(usdBTCPrice * btcAmount, bsqAmount));
    }
    long averagePrice;
    var usdTraded = usdBsqList.stream()
            .mapToDouble(item -> item.first)
            .sum();
    var bsqTraded = usdBsqList.stream()
            .mapToDouble(item -> item.second)
            .sum();
    var averageAsDouble = bsqTraded > 0 ? usdTraded / bsqTraded : 0d;
    var averageScaledUp = MathUtils.scaleUpByPowerOf10(averageAsDouble, Fiat.SMALLEST_UNIT_EXPONENT);
    averagePrice = bsqTraded > 0 ? MathUtils.roundDoubleToLong(averageScaledUp) : 0;

    return averagePrice;
}
 
Example 24
private void updateMarketPriceToManual() {
    final String currencyCode = dataModel.getTradeCurrencyCode().get();
    MarketPrice marketPrice = priceFeedService.getMarketPrice(currencyCode);
    if (marketPrice != null && marketPrice.isRecentExternalPriceAvailable()) {
        double marketPriceAsDouble = marketPrice.getPrice();
        double amountAsDouble = ParsingUtils.parseNumberStringToDouble(amount.get());
        double volumeAsDouble = ParsingUtils.parseNumberStringToDouble(volume.get());
        double manualPriceAsDouble = dataModel.calculateMarketPriceManual(marketPriceAsDouble, volumeAsDouble, amountAsDouble);

        final boolean isCryptoCurrency = CurrencyUtil.isCryptoCurrency(currencyCode);
        int precision = isCryptoCurrency ?
                Altcoin.SMALLEST_UNIT_EXPONENT : Fiat.SMALLEST_UNIT_EXPONENT;
        price.set(FormattingUtils.formatRoundedDoubleWithPrecision(manualPriceAsDouble, precision));
        setPriceToModel();
        dataModel.calculateTotalToPay();
        updateButtonDisableState();
        applyMakerFee();
    } else {
        marketPriceMargin.set("");
        String id = "showNoPriceFeedAvailablePopup";
        if (preferences.showAgain(id)) {
            new Popup().warning(Res.get("popup.warning.noPriceFeedAvailable"))
                    .dontShowAgainId(id)
                    .show();
        }
    }
}
 
Example 25
Source Project: bisq   Source File: DisplayUtils.java    License: GNU Affero General Public License v3.0 5 votes vote down vote up
private static String formatVolume(Volume volume, MonetaryFormat fiatVolumeFormat, boolean appendCurrencyCode) {
    if (volume != null) {
        Monetary monetary = volume.getMonetary();
        if (monetary instanceof Fiat)
            return FormattingUtils.formatFiat((Fiat) monetary, fiatVolumeFormat, appendCurrencyCode);
        else
            return FormattingUtils.formatAltcoinVolume((Altcoin) monetary, appendCurrencyCode);
    } else {
        return "";
    }
}
 
Example 26
@SuppressWarnings("ConstantConditions")
@Test
public void testGetCandleData() {
    model.selectedTradeCurrencyProperty.setValue(new FiatCurrency("EUR"));

    long low = Fiat.parseFiat("EUR", "500").value;
    long open = Fiat.parseFiat("EUR", "520").value;
    long close = Fiat.parseFiat("EUR", "580").value;
    long high = Fiat.parseFiat("EUR", "600").value;
    long average = Fiat.parseFiat("EUR", "550").value;
    long median = Fiat.parseFiat("EUR", "550").value;
    long amount = Coin.parseCoin("4").value;
    long volume = Fiat.parseFiat("EUR", "2200").value;
    boolean isBullish = true;

    Set<TradeStatistics2> set = new HashSet<>();
    final Date now = new Date();

    set.add(new TradeStatistics2(offer, Price.parse("EUR", "520"), Coin.parseCoin("1"), new Date(now.getTime()), null, null));
    set.add(new TradeStatistics2(offer, Price.parse("EUR", "500"), Coin.parseCoin("1"), new Date(now.getTime() + 100), null, null));
    set.add(new TradeStatistics2(offer, Price.parse("EUR", "600"), Coin.parseCoin("1"), new Date(now.getTime() + 200), null, null));
    set.add(new TradeStatistics2(offer, Price.parse("EUR", "580"), Coin.parseCoin("1"), new Date(now.getTime() + 300), null, null));

    CandleData candleData = model.getCandleData(model.roundToTick(now, TradesChartsViewModel.TickUnit.DAY).getTime(), set);
    assertEquals(open, candleData.open);
    assertEquals(close, candleData.close);
    assertEquals(high, candleData.high);
    assertEquals(low, candleData.low);
    assertEquals(average, candleData.average);
    assertEquals(median, candleData.median);
    assertEquals(amount, candleData.accumulatedAmount);
    assertEquals(volume, candleData.accumulatedVolume);
    assertEquals(isBullish, candleData.isBullish);
}
 
Example 27
Source Project: bisq   Source File: PriceAlert.java    License: GNU Affero General Public License v3.0 5 votes vote down vote up
private void update() {
    if (user.getPriceAlertFilter() != null) {
        PriceAlertFilter filter = user.getPriceAlertFilter();
        String currencyCode = filter.getCurrencyCode();
        MarketPrice marketPrice = priceFeedService.getMarketPrice(currencyCode);
        if (marketPrice != null) {
            int exp = CurrencyUtil.isCryptoCurrency(currencyCode) ? Altcoin.SMALLEST_UNIT_EXPONENT : Fiat.SMALLEST_UNIT_EXPONENT;
            double priceAsDouble = marketPrice.getPrice();
            long priceAsLong = MathUtils.roundDoubleToLong(MathUtils.scaleUpByPowerOf10(priceAsDouble, exp));
            String currencyName = CurrencyUtil.getNameByCode(currencyCode);
            if (priceAsLong > filter.getHigh() || priceAsLong < filter.getLow()) {
                String msg = Res.get("account.notifications.priceAlert.message.msg",
                        currencyName,
                        FormattingUtils.formatMarketPrice(priceAsDouble, currencyCode),
                        CurrencyUtil.getCurrencyPair(currencyCode));
                MobileMessage message = new MobileMessage(Res.get("account.notifications.priceAlert.message.title", currencyName),
                        msg,
                        MobileMessageType.PRICE);
                log.error(msg);
                try {
                    mobileNotificationService.sendMessage(message);

                    // If an alert got triggered we remove the filter.
                    user.removePriceAlertFilter();
                } catch (Exception e) {
                    log.error(e.toString());
                    e.printStackTrace();
                }
            }
        }
    }
}
 
Example 28
Source Project: bisq   Source File: TradeStatistics2.java    License: GNU Affero General Public License v3.0 5 votes vote down vote up
public Volume getTradeVolume() {
    if (getTradePrice().getMonetary() instanceof Altcoin) {
        return new Volume(new AltcoinExchangeRate((Altcoin) getTradePrice().getMonetary()).coinToAltcoin(getTradeAmount()));
    } else {
        Volume volume = new Volume(new ExchangeRate((Fiat) getTradePrice().getMonetary()).coinToFiat(getTradeAmount()));
        return OfferUtil.getRoundedFiatVolume(volume);
    }
}
 
Example 29
Source Project: bisq   Source File: Price.java    License: GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * Parse the Bitcoin {@code Price} given a {@code currencyCode} and {@code inputValue}.
 *
 * @param currencyCode The currency code to parse, e.g "USD" or "LTC".
 * @param input        The input value to parse as a String, e.g "2.54" or "-0.0001".
 * @return The parsed Price.
 */
public static Price parse(String currencyCode, String input) {
    String cleaned = ParsingUtils.convertCharsForNumber(input);
    if (CurrencyUtil.isFiatCurrency(currencyCode))
        return new Price(Fiat.parseFiat(currencyCode, cleaned));
    else
        return new Price(Altcoin.parseAltcoin(currencyCode, cleaned));
}
 
Example 30
Source Project: bisq   Source File: Price.java    License: GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * Parse the Bitcoin {@code Price} given a {@code currencyCode} and {@code inputValue}.
 *
 * @param currencyCode The currency code to parse, e.g "USD" or "LTC".
 * @param value        The value to parse.
 * @return The parsed Price.
 */
public static Price valueOf(String currencyCode, long value) {
    if (CurrencyUtil.isFiatCurrency(currencyCode)) {
        return new Price(Fiat.valueOf(currencyCode, value));
    } else {
        return new Price(Altcoin.valueOf(currencyCode, value));
    }
}