Search in sources :

Example 1 with CryptoFacilitiesAccountInfo

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

Aggregations

BigDecimal (java.math.BigDecimal)1 ArrayList (java.util.ArrayList)1 CryptoFacilitiesAccountInfo (org.knowm.xchange.cryptofacilities.dto.account.CryptoFacilitiesAccountInfo)1 Currency (org.knowm.xchange.currency.Currency)1 AccountInfo (org.knowm.xchange.dto.account.AccountInfo)1 Balance (org.knowm.xchange.dto.account.Balance)1 Wallet (org.knowm.xchange.dto.account.Wallet)1