org.knowm.xchange.dto.account.Balance类的使用及代码示例

x33g5p2x  于2022-01-16 转载在 其他  
字(9.6k)|赞(0)|评价(0)|浏览(187)

本文整理了Java中org.knowm.xchange.dto.account.Balance类的一些代码示例,展示了Balance类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Balance类的具体详情如下:
包路径:org.knowm.xchange.dto.account.Balance
类名称:Balance

Balance介绍

[英]DTO representing a balance in a currency

This is simply defined by an amount of money in a given currency, contained in the cash object.

This class is immutable.
[中]DTO表示一种货币的余额
这只是由现金对象中包含的以给定货币表示的金额定义的。
这个类是不可变的。

代码示例

代码示例来源:origin: knowm/XChange

  1. public Balance build() {
  2. if (frozen == null) {
  3. if (total == null || available == null) {
  4. frozen = BigDecimal.ZERO;
  5. }
  6. }
  7. return new Balance(
  8. currency, total, available, frozen, borrowed, loaned, withdrawing, depositing);
  9. }
  10. }

代码示例来源:origin: knowm/XChange

  1. public static Builder from(Balance balance) {
  2. return new Builder()
  3. .currency(balance.getCurrency())
  4. .total(balance.getTotal())
  5. .available(balance.getAvailable())
  6. .frozen(balance.getFrozen())
  7. .borrowed(balance.getBorrowed())
  8. .loaned(balance.getLoaned())
  9. .withdrawing(balance.getWithdrawing())
  10. .depositing(balance.getDepositing());
  11. }

代码示例来源:origin: knowm/XChange

  1. /**
  2. * Returns the amount of the <code>currency</code> in this balance that may be withdrawn. Equal to
  3. * <code>available - borrowed</code>.
  4. *
  5. * @return the amount that is available to withdraw.
  6. */
  7. public BigDecimal getAvailableForWithdrawal() {
  8. return getAvailable().subtract(getBorrowed());
  9. }

代码示例来源:origin: knowm/XChange

  1. private static void generic(AccountService accountService) throws IOException {
  2. // Get the account information
  3. AccountInfo accountInfo = accountService.getAccountInfo();
  4. System.out.println("Account balances: (available / available for withdrawal / total)");
  5. Wallet wallet = accountInfo.getWallet();
  6. Map<Currency, Balance> balances = wallet.getBalances();
  7. for (Map.Entry<Currency, Balance> entry : balances.entrySet()) {
  8. Balance balance = entry.getValue();
  9. System.out.format(
  10. "%s balance: %s / %s / %s\n",
  11. entry.getKey().getCurrencyCode(),
  12. balance.getAvailable(),
  13. balance.getAvailableForWithdrawal(),
  14. balance.getTotal());
  15. }
  16. }

代码示例来源:origin: knowm/XChange

  1. public static Wallet adaptWallet(GateioFunds bterAccountInfo) {
  2. List<Balance> balances = new ArrayList<>();
  3. for (Entry<String, BigDecimal> funds : bterAccountInfo.getAvailableFunds().entrySet()) {
  4. Currency currency = Currency.getInstance(funds.getKey().toUpperCase());
  5. BigDecimal amount = funds.getValue();
  6. BigDecimal locked = bterAccountInfo.getLockedFunds().get(currency.toString());
  7. balances.add(new Balance(currency, null, amount, locked == null ? BigDecimal.ZERO : locked));
  8. }
  9. for (Entry<String, BigDecimal> funds : bterAccountInfo.getLockedFunds().entrySet()) {
  10. Currency currency = Currency.getInstance(funds.getKey().toUpperCase());
  11. if (balances.stream().noneMatch(balance -> balance.getCurrency().equals(currency))) {
  12. BigDecimal amount = funds.getValue();
  13. balances.add(new Balance(currency, null, BigDecimal.ZERO, amount));
  14. }
  15. }
  16. return new Wallet(balances);
  17. }

代码示例来源:origin: knowm/XChange

  1. private static void generic(AccountService accountService) throws IOException {
  2. AccountInfo accountInfo = accountService.getAccountInfo();
  3. System.out.println("Wallet: " + accountInfo);
  4. System.out.println(
  5. "ETH balance: " + accountInfo.getWallet().getBalance(Currency.ETH).getAvailable());
  6. }

代码示例来源:origin: knowm/XChange

  1. /**
  2. * Constructs a {@link Wallet}.
  3. *
  4. * @param id the wallet id
  5. * @param name a descriptive name for the wallet
  6. * @param balances the balances, the currencies of the balances should not be duplicated.
  7. */
  8. public Wallet(String id, String name, Collection<Balance> balances) {
  9. this.id = id;
  10. if (name == null) {
  11. this.name = id;
  12. } else {
  13. this.name = name;
  14. }
  15. if (balances.size() == 0) {
  16. this.balances = Collections.emptyMap();
  17. } else if (balances.size() == 1) {
  18. Balance balance = balances.iterator().next();
  19. this.balances = Collections.singletonMap(balance.getCurrency(), balance);
  20. } else {
  21. this.balances = new HashMap<>();
  22. for (Balance balance : balances) {
  23. if (this.balances.containsKey(balance.getCurrency()))
  24. // this class could merge balances, but probably better to catch mistakes and let the
  25. // exchange merge them
  26. throw new IllegalArgumentException("duplicate balances in wallet");
  27. this.balances.put(balance.getCurrency(), balance);
  28. }
  29. }
  30. }

代码示例来源:origin: org.knowm.xchange/xchange-core

  1. /**
  2. * Returns the amount of the <code>currency</code> in this balance that may be withdrawn. Equal to
  3. * <code>available - borrowed</code>.
  4. *
  5. * @return the amount that is available to withdraw.
  6. */
  7. public BigDecimal getAvailableForWithdrawal() {
  8. return getAvailable().subtract(getBorrowed());
  9. }

代码示例来源:origin: knowm/XChange

  1. private static void generic(AccountService accountService) throws IOException {
  2. // Get the account information
  3. AccountInfo accountInfo = accountService.getAccountInfo();
  4. System.out.println("Wallet: " + accountInfo);
  5. System.out.println(
  6. "BTC balance: " + accountInfo.getWallet().getBalance(Currency.BTC).getAvailable());
  7. }

代码示例来源:origin: org.knowm.xchange/xchange-core

  1. /**
  2. * Constructs a {@link Wallet}.
  3. *
  4. * @param id the wallet id
  5. * @param name a descriptive name for the wallet
  6. * @param balances the balances, the currencies of the balances should not be duplicated.
  7. */
  8. public Wallet(String id, String name, Collection<Balance> balances) {
  9. this.id = id;
  10. if (name == null) {
  11. this.name = id;
  12. } else {
  13. this.name = name;
  14. }
  15. if (balances.size() == 0) {
  16. this.balances = Collections.emptyMap();
  17. } else if (balances.size() == 1) {
  18. Balance balance = balances.iterator().next();
  19. this.balances = Collections.singletonMap(balance.getCurrency(), balance);
  20. } else {
  21. this.balances = new HashMap<>();
  22. for (Balance balance : balances) {
  23. if (this.balances.containsKey(balance.getCurrency()))
  24. // this class could merge balances, but probably better to catch mistakes and let the
  25. // exchange merge them
  26. throw new IllegalArgumentException("duplicate balances in wallet");
  27. this.balances.put(balance.getCurrency(), balance);
  28. }
  29. }
  30. }

代码示例来源:origin: knowm/XChange

  1. /**
  2. * Returns a zero balance.
  3. *
  4. * @param currency the balance currency.
  5. * @return a zero balance.
  6. */
  7. public static Balance zero(Currency currency) {
  8. return new Balance(
  9. currency,
  10. BigDecimal.ZERO,
  11. BigDecimal.ZERO,
  12. BigDecimal.ZERO,
  13. BigDecimal.ZERO,
  14. BigDecimal.ZERO,
  15. BigDecimal.ZERO,
  16. BigDecimal.ZERO);
  17. }

代码示例来源:origin: org.knowm.xchange/xchange-core

  1. public static Builder from(Balance balance) {
  2. return new Builder()
  3. .currency(balance.getCurrency())
  4. .total(balance.getTotal())
  5. .available(balance.getAvailable())
  6. .frozen(balance.getFrozen())
  7. .borrowed(balance.getBorrowed())
  8. .loaned(balance.getLoaned())
  9. .withdrawing(balance.getWithdrawing())
  10. .depositing(balance.getDepositing());
  11. }

代码示例来源:origin: knowm/XChange

  1. private static void generic(AccountService accountService) throws IOException {
  2. AccountInfo accountInfo = accountService.getAccountInfo();
  3. System.out.println("Wallet: " + accountInfo);
  4. System.out.println(
  5. "ETH balance: " + accountInfo.getWallet().getBalance(Currency.ETH).getAvailable());
  6. }

代码示例来源:origin: knowm/XChange

  1. public static Balance adaptBalance(
  2. Map<String, String> balances, Map<String, String> reserved, String ccy) {
  3. Currency currency = Currency.getInstance(ccy);
  4. BigDecimal available = new BigDecimal(balances.get(ccy));
  5. BigDecimal frozen = new BigDecimal(reserved.get(ccy));
  6. return new Balance(currency, available.add(frozen), available, frozen);
  7. }

代码示例来源:origin: knowm/XChange

  1. private Balance mapBalance(AcxAccount acc) {
  2. return new Balance(
  3. Currency.getInstance(acc.currency), acc.balance.add(acc.locked), acc.balance, acc.locked);
  4. }

代码示例来源:origin: knowm/XChange

  1. public static Wallet adaptWallet(Map<String, BigDecimal> krakenWallet) {
  2. List<Balance> balances = new ArrayList<>(krakenWallet.size());
  3. for (Entry<String, BigDecimal> balancePair : krakenWallet.entrySet()) {
  4. Currency currency = adaptCurrency(balancePair.getKey());
  5. Balance balance = new Balance(currency, balancePair.getValue());
  6. balances.add(balance);
  7. }
  8. return new Wallet(balances);
  9. }

代码示例来源:origin: knowm/XChange

  1. public static Wallet adaptWallet(Map<String, BigDecimal> bitmexWallet) {
  2. List<Balance> balances = new ArrayList<>(bitmexWallet.size());
  3. for (Entry<String, BigDecimal> balancePair : bitmexWallet.entrySet()) {
  4. Currency currency = adaptCurrency(balancePair.getKey());
  5. Balance balance = new Balance(currency, balancePair.getValue());
  6. balances.add(balance);
  7. }
  8. return new Wallet(balances);
  9. }

代码示例来源:origin: knowm/XChange

  1. public static List<Balance> adaptPoloniexBalances(
  2. HashMap<String, PoloniexBalance> poloniexBalances) {
  3. List<Balance> balances = new ArrayList<>();
  4. for (Map.Entry<String, PoloniexBalance> item : poloniexBalances.entrySet()) {
  5. Currency currency = Currency.getInstance(item.getKey());
  6. balances.add(
  7. new Balance(
  8. currency, null, item.getValue().getAvailable(), item.getValue().getOnOrders()));
  9. }
  10. return balances;
  11. }

代码示例来源:origin: knowm/XChange

  1. public Balance getBalance(Currency currency) {
  2. if (currency.equals(Currency.XBT)) {
  3. return new Balance(currency, btcBalance, btcAvailable, btcReserved);
  4. } else if (currency.equals(Currency.GBP)) {
  5. return new Balance(currency, gbpBalance, gbpAvailable, gbpReserved);
  6. } else if (currency.equals(Currency.EUR)) {
  7. return new Balance(currency, eurBalance, eurAvailable, eurReserved);
  8. } else if (currency.equals(Currency.USD)) {
  9. return new Balance(currency, usdBalance, usdAvailable, usdReserved);
  10. } else if (currency.equals(Currency.BCH)) {
  11. return new Balance(currency, bchBalance, bchAvailable, bchReserved);
  12. } else if (currency.equals(Currency.XRP)) {
  13. return new Balance(currency, xrpBalance, xrpAvailable, xrpReserved);
  14. } else if (currency.equals(Currency.LTC)) {
  15. return new Balance(currency, ltcBalance, ltcAvailable, ltcReserved);
  16. } else if (currency.equals(Currency.ETH)) {
  17. return new Balance(currency, ethBalance, ethAvailable, ethReserved);
  18. } else {
  19. throw new IllegalArgumentException("Unsupported currency: " + currency);
  20. }
  21. }
  22. }

代码示例来源:origin: knowm/XChange

  1. public static Wallet adaptWallet(WexAccountInfo wexAccountInfo) {
  2. List<Balance> balances = new ArrayList<>();
  3. Map<String, BigDecimal> funds = wexAccountInfo.getFunds();
  4. for (String lcCurrency : funds.keySet()) {
  5. /* BTC-E signals DASH as DSH. This is a different coin. Translate in correct DASH name */
  6. BigDecimal fund = funds.get(lcCurrency);
  7. Currency currency = adaptCurrencyIn(lcCurrency);
  8. balances.add(new Balance(currency, fund));
  9. }
  10. return new Wallet(balances);
  11. }

相关文章