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

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

本文整理了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

public Balance build() {
  if (frozen == null) {
   if (total == null || available == null) {
    frozen = BigDecimal.ZERO;
   }
  }
  return new Balance(
    currency, total, available, frozen, borrowed, loaned, withdrawing, depositing);
 }
}

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

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());
}

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

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

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

private static void generic(AccountService accountService) throws IOException {
 // Get the account information
 AccountInfo accountInfo = accountService.getAccountInfo();
 System.out.println("Account balances: (available / available for withdrawal / total)");
 Wallet wallet = accountInfo.getWallet();
 Map<Currency, Balance> balances = wallet.getBalances();
 for (Map.Entry<Currency, Balance> entry : balances.entrySet()) {
  Balance balance = entry.getValue();
  System.out.format(
    "%s balance: %s / %s / %s\n",
    entry.getKey().getCurrencyCode(),
    balance.getAvailable(),
    balance.getAvailableForWithdrawal(),
    balance.getTotal());
 }
}

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

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);
}

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

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

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

/**
 * 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);
  }
 }
}

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

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

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

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

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

/**
 * 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);
  }
 }
}

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

/**
 * Returns a zero balance.
 *
 * @param currency the balance currency.
 * @return a zero balance.
 */
public static Balance zero(Currency currency) {
 return new Balance(
   currency,
   BigDecimal.ZERO,
   BigDecimal.ZERO,
   BigDecimal.ZERO,
   BigDecimal.ZERO,
   BigDecimal.ZERO,
   BigDecimal.ZERO,
   BigDecimal.ZERO);
}

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

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());
}

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

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

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

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

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

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

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

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

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

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

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

public static List<Balance> adaptPoloniexBalances(
  HashMap<String, PoloniexBalance> poloniexBalances) {
 List<Balance> balances = new ArrayList<>();
 for (Map.Entry<String, PoloniexBalance> item : poloniexBalances.entrySet()) {
  Currency currency = Currency.getInstance(item.getKey());
  balances.add(
    new Balance(
      currency, null, item.getValue().getAvailable(), item.getValue().getOnOrders()));
 }
 return balances;
}

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

public Balance getBalance(Currency currency) {
  if (currency.equals(Currency.XBT)) {
   return new Balance(currency, btcBalance, btcAvailable, btcReserved);
  } else if (currency.equals(Currency.GBP)) {
   return new Balance(currency, gbpBalance, gbpAvailable, gbpReserved);
  } else if (currency.equals(Currency.EUR)) {
   return new Balance(currency, eurBalance, eurAvailable, eurReserved);
  } else if (currency.equals(Currency.USD)) {
   return new Balance(currency, usdBalance, usdAvailable, usdReserved);
  } else if (currency.equals(Currency.BCH)) {
   return new Balance(currency, bchBalance, bchAvailable, bchReserved);
  } else if (currency.equals(Currency.XRP)) {
   return new Balance(currency, xrpBalance, xrpAvailable, xrpReserved);
  } else if (currency.equals(Currency.LTC)) {
   return new Balance(currency, ltcBalance, ltcAvailable, ltcReserved);
  } else if (currency.equals(Currency.ETH)) {
   return new Balance(currency, ethBalance, ethAvailable, ethReserved);
  } else {
   throw new IllegalArgumentException("Unsupported currency: " + currency);
  }
 }
}

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

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

相关文章

微信公众号

最新文章

更多