Search in sources :

Example 6 with FiatCurrency

use of bisq.core.locale.FiatCurrency in project bisq-desktop by bisq-network.

the class AltCoinAccountsDataModel method onSaveNewAccount.

// /////////////////////////////////////////////////////////////////////////////////////////
// UI actions
// /////////////////////////////////////////////////////////////////////////////////////////
public void onSaveNewAccount(PaymentAccount paymentAccount) {
    user.addPaymentAccount(paymentAccount);
    TradeCurrency singleTradeCurrency = paymentAccount.getSingleTradeCurrency();
    List<TradeCurrency> tradeCurrencies = paymentAccount.getTradeCurrencies();
    if (singleTradeCurrency != null) {
        if (singleTradeCurrency instanceof FiatCurrency)
            preferences.addFiatCurrency((FiatCurrency) singleTradeCurrency);
        else
            preferences.addCryptoCurrency((CryptoCurrency) singleTradeCurrency);
    } else if (tradeCurrencies != null && !tradeCurrencies.isEmpty()) {
        tradeCurrencies.stream().forEach(tradeCurrency -> {
            if (tradeCurrency instanceof FiatCurrency)
                preferences.addFiatCurrency((FiatCurrency) tradeCurrency);
            else
                preferences.addCryptoCurrency((CryptoCurrency) tradeCurrency);
        });
    }
    if (!(paymentAccount instanceof CryptoCurrencyAccount))
        accountAgeWitnessService.publishMyAccountAgeWitness(paymentAccount.getPaymentAccountPayload());
}
Also used : GUIUtil(bisq.desktop.util.GUIUtil) TradeCurrency(bisq.core.locale.TradeCurrency) CryptoCurrencyAccount(bisq.core.payment.CryptoCurrencyAccount) ActivatableDataModel(bisq.desktop.common.model.ActivatableDataModel) Inject(com.google.inject.Inject) SetChangeListener(javafx.collections.SetChangeListener) FXCollections(javafx.collections.FXCollections) FiatCurrency(bisq.core.locale.FiatCurrency) PaymentMethod(bisq.core.payment.payload.PaymentMethod) Collectors(java.util.stream.Collectors) OpenOfferManager(bisq.core.offer.OpenOfferManager) AccountAgeWitnessService(bisq.core.payment.AccountAgeWitnessService) User(bisq.core.user.User) PersistenceProtoResolver(bisq.common.proto.persistable.PersistenceProtoResolver) ArrayList(java.util.ArrayList) PaymentAccount(bisq.core.payment.PaymentAccount) List(java.util.List) CryptoCurrency(bisq.core.locale.CryptoCurrency) Stage(javafx.stage.Stage) TradeManager(bisq.core.trade.TradeManager) Preferences(bisq.core.user.Preferences) ObservableList(javafx.collections.ObservableList) CryptoCurrency(bisq.core.locale.CryptoCurrency) TradeCurrency(bisq.core.locale.TradeCurrency) FiatCurrency(bisq.core.locale.FiatCurrency) CryptoCurrencyAccount(bisq.core.payment.CryptoCurrencyAccount)

Example 7 with FiatCurrency

use of bisq.core.locale.FiatCurrency in project bisq-desktop by bisq-network.

the class OfferBookView method setDirectionTitles.

private void setDirectionTitles() {
    TradeCurrency selectedTradeCurrency = model.getSelectedTradeCurrency();
    if (selectedTradeCurrency != null) {
        OfferPayload.Direction direction = model.getDirection();
        String directionText = direction == OfferPayload.Direction.BUY ? Res.get("shared.buy") : Res.get("shared.sell");
        String mirroredDirectionText = direction == OfferPayload.Direction.SELL ? Res.get("shared.buy") : Res.get("shared.sell");
        String code = selectedTradeCurrency.getCode();
        if (model.showAllTradeCurrenciesProperty.get())
            createOfferButton.setText(Res.get("offerbook.createOfferTo", directionText, Res.getBaseCurrencyCode()));
        else if (selectedTradeCurrency instanceof FiatCurrency)
            createOfferButton.setText(Res.get("offerbook.createOfferTo", directionText, Res.getBaseCurrencyCode()) + " " + (direction == OfferPayload.Direction.BUY ? Res.get("offerbook.buyWithOtherCurrency", code) : Res.get("offerbook.sellForOtherCurrency", code)));
        else
            createOfferButton.setText(Res.get("offerbook.createOfferTo", mirroredDirectionText, code) + " (" + directionText + " " + Res.getBaseCurrencyCode() + ")");
    }
}
Also used : TradeCurrency(bisq.core.locale.TradeCurrency) FiatCurrency(bisq.core.locale.FiatCurrency) OfferPayload(bisq.core.offer.OfferPayload)

Example 8 with FiatCurrency

use of bisq.core.locale.FiatCurrency in project bisq-desktop by bisq-network.

the class PreferencesView method activateDisplayCurrencies.

private void activateDisplayCurrencies() {
    preferredTradeCurrencyComboBox.setItems(tradeCurrencies);
    preferredTradeCurrencyComboBox.getSelectionModel().select(preferences.getPreferredTradeCurrency());
    preferredTradeCurrencyComboBox.setVisibleRowCount(25);
    preferredTradeCurrencyComboBox.setOnAction(e -> {
        TradeCurrency selectedItem = preferredTradeCurrencyComboBox.getSelectionModel().getSelectedItem();
        if (selectedItem != null)
            preferences.setPreferredTradeCurrency(selectedItem);
    });
    fiatCurrenciesComboBox.setItems(allFiatCurrencies);
    fiatCurrenciesListView.setItems(fiatCurrencies);
    fiatCurrenciesComboBox.setOnAction(e -> {
        FiatCurrency selectedItem = fiatCurrenciesComboBox.getSelectionModel().getSelectedItem();
        if (selectedItem != null) {
            preferences.addFiatCurrency(selectedItem);
            if (allFiatCurrencies.contains(selectedItem)) {
                UserThread.execute(() -> {
                    fiatCurrenciesComboBox.getSelectionModel().clearSelection();
                    allFiatCurrencies.remove(selectedItem);
                });
            }
        }
    });
    cryptoCurrenciesComboBox.setItems(allCryptoCurrencies);
    cryptoCurrenciesListView.setItems(cryptoCurrencies);
    cryptoCurrenciesComboBox.setOnAction(e -> {
        CryptoCurrency selectedItem = cryptoCurrenciesComboBox.getSelectionModel().getSelectedItem();
        if (selectedItem != null) {
            preferences.addCryptoCurrency(selectedItem);
            if (allCryptoCurrencies.contains(selectedItem)) {
                UserThread.execute(() -> {
                    cryptoCurrenciesComboBox.getSelectionModel().clearSelection();
                    allCryptoCurrencies.remove(selectedItem);
                });
            }
        }
    });
}
Also used : CryptoCurrency(bisq.core.locale.CryptoCurrency) TradeCurrency(bisq.core.locale.TradeCurrency) FiatCurrency(bisq.core.locale.FiatCurrency)

Example 9 with FiatCurrency

use of bisq.core.locale.FiatCurrency in project bisq-desktop by bisq-network.

the class TradesChartsViewModelTest method testItemLists.

@Test
public void testItemLists() throws ParseException {
    // Helper class to add historic trades
    class Trade {

        Trade(String date, String size, String price, String cc) {
            try {
                this.date = dateFormat.parse(date);
            } catch (ParseException p) {
                this.date = new Date();
            }
            this.size = size;
            this.price = price;
            this.cc = cc;
        }

        Date date;

        String size;

        String price;

        String cc;
    }
    ;
    // Trade EUR
    model.selectedTradeCurrencyProperty.setValue(new FiatCurrency("EUR"));
    ArrayList<Trade> trades = new ArrayList<Trade>();
    // Set predetermined time to use as "now" during test
    // Monday
    Date test_time = dateFormat.parse("2018-01-01T00:00:05");
    new MockUp<System>() {

        @Mock
        long currentTimeMillis() {
            return test_time.getTime();
        }
    };
    // Two trades 10 seconds apart, different YEAR, MONTH, WEEK, DAY, HOUR, MINUTE_10
    trades.add(new Trade("2017-12-31T23:59:52", "1", "100", "EUR"));
    trades.add(new Trade("2018-01-01T00:00:02", "1", "110", "EUR"));
    Set<TradeStatistics2> set = new HashSet<>();
    trades.forEach(t -> {
        set.add(new TradeStatistics2(offer, Price.parse(t.cc, t.price), Coin.parseCoin(t.size), t.date, null));
    });
    ObservableSet<TradeStatistics2> tradeStats = FXCollections.observableSet(set);
    // Run test for each tick type
    for (TradesChartsViewModel.TickUnit tick : TradesChartsViewModel.TickUnit.values()) {
        new Expectations() {

            {
                tsm.getObservableTradeStatisticsSet();
                result = tradeStats;
            }
        };
        // Trigger chart update
        model.setTickUnit(tick);
        assertEquals(model.selectedTradeCurrencyProperty.get().getCode(), tradeStats.iterator().next().getCurrencyCode());
        assertEquals(2, model.priceItems.size());
        assertEquals(2, model.volumeItems.size());
    }
}
Also used : Expectations(mockit.Expectations) ArrayList(java.util.ArrayList) TradeStatistics2(bisq.core.trade.statistics.TradeStatistics2) MockUp(mockit.MockUp) Date(java.util.Date) FiatCurrency(bisq.core.locale.FiatCurrency) ParseException(java.text.ParseException) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 10 with FiatCurrency

use of bisq.core.locale.FiatCurrency in project bisq-desktop by bisq-network.

the class TradesChartsViewModelTest method testGetCandleData.

@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 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));
    set.add(new TradeStatistics2(offer, Price.parse("EUR", "500"), Coin.parseCoin("1"), new Date(now.getTime() + 100), null));
    set.add(new TradeStatistics2(offer, Price.parse("EUR", "600"), Coin.parseCoin("1"), new Date(now.getTime() + 200), null));
    set.add(new TradeStatistics2(offer, Price.parse("EUR", "580"), Coin.parseCoin("1"), new Date(now.getTime() + 300), 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(amount, candleData.accumulatedAmount);
    assertEquals(volume, candleData.accumulatedVolume);
    assertEquals(isBullish, candleData.isBullish);
}
Also used : CandleData(bisq.desktop.main.market.trades.charts.CandleData) TradeStatistics2(bisq.core.trade.statistics.TradeStatistics2) FiatCurrency(bisq.core.locale.FiatCurrency) Date(java.util.Date) HashSet(java.util.HashSet) Test(org.junit.Test)

Aggregations

FiatCurrency (bisq.core.locale.FiatCurrency)16 Country (bisq.core.locale.Country)8 TradeCurrency (bisq.core.locale.TradeCurrency)8 CryptoCurrency (bisq.core.locale.CryptoCurrency)5 PaymentAccount (bisq.core.payment.PaymentAccount)4 Popup (bisq.desktop.main.overlays.popups.Popup)4 ArrayList (java.util.ArrayList)4 ComboBox (javafx.scene.control.ComboBox)4 Label (javafx.scene.control.Label)4 Region (bisq.core.locale.Region)3 CountryBasedPaymentAccount (bisq.core.payment.CountryBasedPaymentAccount)3 Preferences (bisq.core.user.Preferences)3 PersistenceProtoResolver (bisq.common.proto.persistable.PersistenceProtoResolver)2 CurrencyUtil (bisq.core.locale.CurrencyUtil)2 OpenOfferManager (bisq.core.offer.OpenOfferManager)2 AccountAgeWitnessService (bisq.core.payment.AccountAgeWitnessService)2 CryptoCurrencyAccount (bisq.core.payment.CryptoCurrencyAccount)2 PaymentMethod (bisq.core.payment.payload.PaymentMethod)2 TradeManager (bisq.core.trade.TradeManager)2 TradeStatistics2 (bisq.core.trade.statistics.TradeStatistics2)2