use of org.knowm.xchange.dto.account.Balance in project XChange by knowm.
the class CryptoFacilitiesAdapters method adaptAccount.
public static AccountInfo adaptAccount(CryptoFacilitiesAccount cryptoFacilitiesAccount, String username) {
List<Balance> balances = new ArrayList<>(cryptoFacilitiesAccount.getBalances().size());
Balance balance;
for (Entry<String, BigDecimal> balancePair : cryptoFacilitiesAccount.getBalances().entrySet()) {
if (balancePair.getKey().equalsIgnoreCase("xbt")) {
// For xbt balance we construct both total=deposited xbt and available=total - margin
// balances
balance = new Balance(Currency.BTC, balancePair.getValue(), cryptoFacilitiesAccount.getAuxiliary().get("af"));
} else {
Currency currency = adaptCurrency(balancePair.getKey());
balance = new Balance(currency, balancePair.getValue());
}
balances.add(balance);
}
return new AccountInfo(username, Wallet.Builder.from(balances).build());
}
use of org.knowm.xchange.dto.account.Balance in project XChange by knowm.
the class IndependentReserveAccountDemo method generic.
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());
}
}
use of org.knowm.xchange.dto.account.Balance in project XChange by knowm.
the class OkexAdapters method adaptOkexBalances.
public static Wallet adaptOkexBalances(List<OkexWalletBalance> okexWalletBalanceList) {
List<Balance> balances = new ArrayList<>();
if (!okexWalletBalanceList.isEmpty()) {
OkexWalletBalance okexWalletBalance = okexWalletBalanceList.get(0);
balances = Arrays.stream(okexWalletBalance.getDetails()).map(detail -> new Balance.Builder().currency(new Currency(detail.getCurrency())).total(new BigDecimal(detail.getCashBalance())).available(checkForEmpty(detail.getAvailableBalance())).timestamp(new Date()).build()).collect(Collectors.toList());
}
return Wallet.Builder.from(balances).id(TRADING_WALLET_ID).features(new HashSet<>(Collections.singletonList(Wallet.WalletFeature.TRADING))).build();
}
use of org.knowm.xchange.dto.account.Balance in project XChange by knowm.
the class OkexAdapters method adaptOkexAssetBalances.
public static Wallet adaptOkexAssetBalances(List<OkexAssetBalance> okexAssetBalanceList) {
List<Balance> balances;
balances = okexAssetBalanceList.stream().map(detail -> new Balance.Builder().currency(new Currency(detail.getCurrency())).total(new BigDecimal(detail.getBalance())).available(checkForEmpty(detail.getAvailableBalance())).timestamp(new Date()).build()).collect(Collectors.toList());
return Wallet.Builder.from(balances).id(FOUNDING_WALLET_ID).features(new HashSet<>(Collections.singletonList(Wallet.WalletFeature.FUNDING))).build();
}
use of org.knowm.xchange.dto.account.Balance in project XChange by knowm.
the class BTCTradeAdapters method adaptWallet.
public static Wallet adaptWallet(BTCTradeBalance balance) {
checkException(balance);
List<Balance> balances = new ArrayList<>(5);
balances.add(new Balance(Currency.BTC, nullSafeSum(balance.getBtcBalance(), balance.getBtcReserved()), zeroIfNull(balance.getBtcBalance()), zeroIfNull(balance.getBtcReserved())));
balances.add(new Balance(Currency.LTC, nullSafeSum(balance.getLtcBalance(), balance.getLtcReserved()), zeroIfNull(balance.getLtcBalance()), zeroIfNull(balance.getLtcReserved())));
balances.add(new Balance(Currency.DOGE, nullSafeSum(balance.getDogeBalance(), balance.getDogeReserved()), zeroIfNull(balance.getDogeBalance()), zeroIfNull(balance.getDogeReserved())));
balances.add(new Balance(Currency.YBC, nullSafeSum(balance.getYbcBalance(), balance.getYbcReserved()), zeroIfNull(balance.getYbcBalance()), zeroIfNull(balance.getYbcReserved())));
balances.add(new Balance(Currency.CNY, nullSafeSum(balance.getCnyBalance(), balance.getCnyReserved()), zeroIfNull(balance.getCnyBalance()), zeroIfNull(balance.getCnyReserved())));
return Wallet.Builder.from(balances).build();
}
Aggregations