Search in sources :

Example 6 with AccountInfo

use of org.knowm.xchange.dto.account.AccountInfo in project XChange by knowm.

the class CryptoFacilitiesAdapters method adaptAccounts.

public static AccountInfo adaptAccounts(CryptoFacilitiesAccounts cryptoFacilitiesAccounts, String username) {
    Map<String, CryptoFacilitiesAccountInfo> accounts = cryptoFacilitiesAccounts.getAccounts();
    List<Wallet> wallets = new ArrayList<>();
    for (String accountName : accounts.keySet()) {
        List<Balance> balances = new ArrayList<>(accounts.get(accountName).getBalances().size());
        Balance balance;
        for (Entry<String, BigDecimal> balancePair : accounts.get(accountName).getBalances().entrySet()) {
            if (!accountName.equalsIgnoreCase("cash") && 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(), accounts.get(accountName).getAuxiliary().get("af"));
            } else {
                Currency currency = adaptCurrency(balancePair.getKey());
                balance = new Balance(currency, balancePair.getValue());
            }
            balances.add(balance);
        }
        wallets.add(Wallet.Builder.from(balances).id(accountName).name(accountName).build());
    }
    return new AccountInfo(username, wallets);
}
Also used : CryptoFacilitiesAccountInfo(org.knowm.xchange.cryptofacilities.dto.account.CryptoFacilitiesAccountInfo) Wallet(org.knowm.xchange.dto.account.Wallet) 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 7 with AccountInfo

use of org.knowm.xchange.dto.account.AccountInfo 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 8 with AccountInfo

use of org.knowm.xchange.dto.account.AccountInfo in project XChange by knowm.

the class GateioAccountDemo method generic.

private static void generic(AccountService accountService) throws IOException {
    AccountInfo accountInfo = accountService.getAccountInfo();
    System.out.println(accountInfo);
}
Also used : AccountInfo(org.knowm.xchange.dto.account.AccountInfo)

Example 9 with AccountInfo

use of org.knowm.xchange.dto.account.AccountInfo in project XChange by knowm.

the class HitbtcAccountDemo method generic.

private static void generic(AccountService accountService) throws IOException {
    AccountInfo accountInfo = accountService.getAccountInfo();
    System.out.println(accountInfo);
}
Also used : AccountInfo(org.knowm.xchange.dto.account.AccountInfo)

Example 10 with AccountInfo

use of org.knowm.xchange.dto.account.AccountInfo 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)

Aggregations

AccountInfo (org.knowm.xchange.dto.account.AccountInfo)96 Balance (org.knowm.xchange.dto.account.Balance)50 Wallet (org.knowm.xchange.dto.account.Wallet)35 BigDecimal (java.math.BigDecimal)34 ArrayList (java.util.ArrayList)25 Test (org.junit.Test)23 Currency (org.knowm.xchange.currency.Currency)18 Date (java.util.Date)13 AccountService (org.knowm.xchange.service.account.AccountService)13 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)9 InputStream (java.io.InputStream)9 Exchange (org.knowm.xchange.Exchange)9 Map (java.util.Map)6 IOException (java.io.IOException)5 HashMap (java.util.HashMap)5 List (java.util.List)5 Arrays (java.util.Arrays)3 FileNotFoundException (java.io.FileNotFoundException)2 ZERO (java.math.BigDecimal.ZERO)2 Collection (java.util.Collection)2