use of network.bisq.api.model.Currency in project bisq-api by mrosseel.
the class BisqProxy method calculateCurrencyList.
public static CurrencyList calculateCurrencyList() {
CurrencyList currencyList = new CurrencyList();
CurrencyUtil.getAllSortedCryptoCurrencies().forEach(cryptoCurrency -> currencyList.add(cryptoCurrency.getCode(), cryptoCurrency.getName(), "crypto"));
CurrencyUtil.getAllSortedFiatCurrencies().forEach(fiatCurrency -> currencyList.add(fiatCurrency.getCurrency().getCurrencyCode(), fiatCurrency.getName(), "fiat"));
Collections.sort(currencyList.currencies, (network.bisq.api.model.Currency p1, Currency p2) -> p1.name.compareTo(p2.name));
return currencyList;
}
use of network.bisq.api.model.Currency in project bisq-api by mrosseel.
the class BisqProxy method addPaymentAccount.
public PaymentAccount addPaymentAccount(PaymentAccount paymentAccount) {
if (paymentAccount instanceof CryptoCurrencyAccount) {
final CryptoCurrencyAccount cryptoCurrencyAccount = (CryptoCurrencyAccount) paymentAccount;
final TradeCurrency tradeCurrency = cryptoCurrencyAccount.getSingleTradeCurrency();
if (null == tradeCurrency) {
throw new ValidationException("There must be exactly one trade currency");
}
final AltCoinAddressValidator altCoinAddressValidator = injector.getInstance(AltCoinAddressValidator.class);
altCoinAddressValidator.setCurrencyCode(tradeCurrency.getCode());
final InputValidator.ValidationResult validationResult = altCoinAddressValidator.validate(cryptoCurrencyAccount.getAddress());
if (!validationResult.isValid) {
throw new ValidationException(validationResult.errorMessage);
}
}
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()) {
if (tradeCurrencies.contains(CurrencyUtil.getDefaultTradeCurrency()))
paymentAccount.setSelectedTradeCurrency(CurrencyUtil.getDefaultTradeCurrency());
else
paymentAccount.setSelectedTradeCurrency(tradeCurrencies.get(0));
tradeCurrencies.forEach(tradeCurrency -> {
if (tradeCurrency instanceof FiatCurrency)
preferences.addFiatCurrency((FiatCurrency) tradeCurrency);
else
preferences.addCryptoCurrency((CryptoCurrency) tradeCurrency);
});
}
accountAgeWitnessService.publishMyAccountAgeWitness(paymentAccount.getPaymentAccountPayload());
return paymentAccount;
}
use of network.bisq.api.model.Currency in project bisq-api by mrosseel.
the class CurrencyResourceIT method getCurrencyList_always_returns200.
@InSequence(1)
@Test
public void getCurrencyList_always_returns200() {
final CurrencyList currencyList = given().port(getAlicePort()).when().get("/api/v1/currencies").then().statusCode(200).and().body("total", isA(Integer.class)).and().body("currencies[0].code", isA(String.class)).and().body("currencies[0].name", isA(String.class)).and().body("currencies[0].type", isA(String.class)).and().body("currencies[0].type", isOneOf("crypto", "fiat")).extract().as(CurrencyList.class);
/**
* Make sure that currency code is used instead of symbol
*/
final Optional<Currency> usd = currencyList.currencies.stream().filter(currency -> "USD".equals(currency.code)).findFirst();
Assert.assertTrue(usd.isPresent());
}
use of network.bisq.api.model.Currency in project bisq-api by mrosseel.
the class BisqProxy method calculateMarketList.
public static MarketList calculateMarketList() {
MarketList marketList = new MarketList();
// we calculate this twice but only at startup
CurrencyList currencyList = calculateCurrencyList();
// currencyList.getCurrencies().stream().flatMap(currency -> marketList.getMarkets().forEach(currency1 -> cur))
List<Market> btc = CurrencyUtil.getAllSortedCryptoCurrencies().stream().filter(cryptoCurrency -> !(cryptoCurrency.getCode().equals("BTC"))).map(cryptoCurrency -> new Market(cryptoCurrency.getCode(), "BTC")).collect(toList());
marketList.markets.addAll(btc);
btc = CurrencyUtil.getAllSortedFiatCurrencies().stream().map(cryptoCurrency -> new Market("BTC", cryptoCurrency.getCode())).collect(toList());
marketList.markets.addAll(btc);
Collections.sort(currencyList.currencies, Comparator.comparing(p -> p.name));
return marketList;
}
Aggregations