Search in sources :

Example 11 with Balance

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());
}
Also used : Currency(org.knowm.xchange.currency.Currency) ArrayList(java.util.ArrayList) Balance(org.knowm.xchange.dto.account.Balance) BigDecimal(java.math.BigDecimal) AccountInfo(org.knowm.xchange.dto.account.AccountInfo) CryptoFacilitiesAccountInfo(org.knowm.xchange.cryptofacilities.dto.account.CryptoFacilitiesAccountInfo)

Example 12 with Balance

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());
    }
}
Also used : Wallet(org.knowm.xchange.dto.account.Wallet) Currency(org.knowm.xchange.currency.Currency) IndependentReserveBalance(org.knowm.xchange.independentreserve.dto.account.IndependentReserveBalance) Balance(org.knowm.xchange.dto.account.Balance) Map(java.util.Map) AccountInfo(org.knowm.xchange.dto.account.AccountInfo)

Example 13 with Balance

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();
}
Also used : OkexWalletBalance(org.knowm.xchange.okex.v5.dto.account.OkexWalletBalance) Currency(org.knowm.xchange.currency.Currency) OkexCurrency(org.knowm.xchange.okex.v5.dto.marketdata.OkexCurrency) ArrayList(java.util.ArrayList) Balance(org.knowm.xchange.dto.account.Balance) OkexWalletBalance(org.knowm.xchange.okex.v5.dto.account.OkexWalletBalance) OkexAssetBalance(org.knowm.xchange.okex.v5.dto.account.OkexAssetBalance) BigDecimal(java.math.BigDecimal) Date(java.util.Date) HashSet(java.util.HashSet)

Example 14 with Balance

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();
}
Also used : Currency(org.knowm.xchange.currency.Currency) OkexCurrency(org.knowm.xchange.okex.v5.dto.marketdata.OkexCurrency) Balance(org.knowm.xchange.dto.account.Balance) OkexWalletBalance(org.knowm.xchange.okex.v5.dto.account.OkexWalletBalance) OkexAssetBalance(org.knowm.xchange.okex.v5.dto.account.OkexAssetBalance) BigDecimal(java.math.BigDecimal) Date(java.util.Date) HashSet(java.util.HashSet)

Example 15 with Balance

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();
}
Also used : ArrayList(java.util.ArrayList) BTCTradeBalance(org.knowm.xchange.btctrade.dto.account.BTCTradeBalance) Balance(org.knowm.xchange.dto.account.Balance)

Aggregations

Balance (org.knowm.xchange.dto.account.Balance)99 BigDecimal (java.math.BigDecimal)51 ArrayList (java.util.ArrayList)50 AccountInfo (org.knowm.xchange.dto.account.AccountInfo)50 Wallet (org.knowm.xchange.dto.account.Wallet)38 Currency (org.knowm.xchange.currency.Currency)37 Test (org.junit.Test)23 Map (java.util.Map)14 Date (java.util.Date)13 HashMap (java.util.HashMap)10 List (java.util.List)8 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)7 InputStream (java.io.InputStream)6 IOException (java.io.IOException)5 OrderBook (org.knowm.xchange.dto.marketdata.OrderBook)5 Ticker (org.knowm.xchange.dto.marketdata.Ticker)5 JsonNode (com.fasterxml.jackson.databind.JsonNode)4 Arrays (java.util.Arrays)4 HashSet (java.util.HashSet)4 Collection (java.util.Collection)3