Java Code Examples for org.bitcoinj.utils.Fiat#parseFiat()

The following examples show how to use org.bitcoinj.utils.Fiat#parseFiat() . 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 File: AmountFields.java    From GreenBits with 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 2
Source File: WalletTest.java    From bcm-android with 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 3
Source File: Price.java    From bisq-core with 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 4
Source File: Volume.java    From bisq-core with 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 5
Source File: BSFormatter.java    From bisq-core with 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 6
Source File: WalletTest.java    From green_android with 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 7
Source File: WalletTest.java    From GreenBits with 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 8
Source File: TradesChartsViewModelTest.java    From bisq with GNU Affero General Public License v3.0 5 votes vote down vote up
@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 9
Source File: Price.java    From bisq with 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 10
Source File: Volume.java    From bisq with GNU Affero General Public License v3.0 5 votes vote down vote up
public static Volume parse(String input, String currencyCode) {
    String cleaned = ParsingUtils.convertCharsForNumber(input);
    if (CurrencyUtil.isFiatCurrency(currencyCode))
        return new Volume(Fiat.parseFiat(currencyCode, cleaned));
    else
        return new Volume(Altcoin.parseAltcoin(currencyCode, cleaned));
}