/** * Constructs a {@link Wallet}. * * @param id the wallet id * @param name a descriptive name for the wallet * @param balances the balances, the currencies of the balances should not be duplicated. */ public Wallet(String id, String name, Collection<Balance> balances) { this.id = id; if (name == null) { this.name = id; } else { this.name = name; } if (balances.size() == 0) { this.balances = Collections.emptyMap(); } else if (balances.size() == 1) { Balance balance = balances.iterator().next(); this.balances = Collections.singletonMap(balance.getCurrency(), balance); } else { this.balances = new HashMap<>(); for (Balance balance : balances) { if (this.balances.containsKey(balance.getCurrency())) // this class could merge balances, but probably better to catch mistakes and let the // exchange merge them throw new IllegalArgumentException("duplicate balances in wallet"); this.balances.put(balance.getCurrency(), balance); } } }
public static Wallet adaptWallet(GateioFunds bterAccountInfo) { List<Balance> balances = new ArrayList<>(); for (Entry<String, BigDecimal> funds : bterAccountInfo.getAvailableFunds().entrySet()) { Currency currency = Currency.getInstance(funds.getKey().toUpperCase()); BigDecimal amount = funds.getValue(); BigDecimal locked = bterAccountInfo.getLockedFunds().get(currency.toString()); balances.add(new Balance(currency, null, amount, locked == null ? BigDecimal.ZERO : locked)); } for (Entry<String, BigDecimal> funds : bterAccountInfo.getLockedFunds().entrySet()) { Currency currency = Currency.getInstance(funds.getKey().toUpperCase()); if (balances.stream().noneMatch(balance -> balance.getCurrency().equals(currency))) { BigDecimal amount = funds.getValue(); balances.add(new Balance(currency, null, BigDecimal.ZERO, amount)); } } return new Wallet(balances); }
public static Builder from(Balance balance) { return new Builder() .currency(balance.getCurrency()) .total(balance.getTotal()) .available(balance.getAvailable()) .frozen(balance.getFrozen()) .borrowed(balance.getBorrowed()) .loaned(balance.getLoaned()) .withdrawing(balance.getWithdrawing()) .depositing(balance.getDepositing()); }
/** * Constructs a {@link Wallet}. * * @param id the wallet id * @param name a descriptive name for the wallet * @param balances the balances, the currencies of the balances should not be duplicated. */ public Wallet(String id, String name, Collection<Balance> balances) { this.id = id; if (name == null) { this.name = id; } else { this.name = name; } if (balances.size() == 0) { this.balances = Collections.emptyMap(); } else if (balances.size() == 1) { Balance balance = balances.iterator().next(); this.balances = Collections.singletonMap(balance.getCurrency(), balance); } else { this.balances = new HashMap<>(); for (Balance balance : balances) { if (this.balances.containsKey(balance.getCurrency())) // this class could merge balances, but probably better to catch mistakes and let the // exchange merge them throw new IllegalArgumentException("duplicate balances in wallet"); this.balances.put(balance.getCurrency(), balance); } } }
public static Builder from(Balance balance) { return new Builder() .currency(balance.getCurrency()) .total(balance.getTotal()) .available(balance.getAvailable()) .frozen(balance.getFrozen()) .borrowed(balance.getBorrowed()) .loaned(balance.getLoaned()) .withdrawing(balance.getWithdrawing()) .depositing(balance.getDepositing()); }