Search in sources :

Example 6 with Balance

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

the class CexIOAdapters method adaptBalance.

public static Balance adaptBalance(Currency currency, CexIOBalance balance) {
    BigDecimal inOrders = balance.getOrders();
    BigDecimal frozen = inOrders == null ? BigDecimal.ZERO : inOrders;
    return new Balance(currency, null, balance.getAvailable(), frozen);
}
Also used : CexIOBalance(org.knowm.xchange.cexio.dto.account.CexIOBalance) Balance(org.knowm.xchange.dto.account.Balance) BigDecimal(java.math.BigDecimal)

Example 7 with Balance

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

the class BTCTurkAdapters method adaptWallet.

public static Wallet adaptWallet(String name, BTCTurkAccountBalance btcTurkBalance) {
    List<Balance> balances = new ArrayList<>(7);
    balances.add(new Balance(Currency.TRY, null, btcTurkBalance.getTry_available(), btcTurkBalance.getTry_reserved()));
    balances.add(new Balance(Currency.BTC, null, btcTurkBalance.getBtc_available(), btcTurkBalance.getBtc_reserved()));
    balances.add(new Balance(Currency.ETH, null, btcTurkBalance.getEth_available(), btcTurkBalance.getEth_reserved()));
    balances.add(new Balance(Currency.XRP, null, btcTurkBalance.getXrp_available(), btcTurkBalance.getXrp_reserved()));
    balances.add(new Balance(Currency.LTC, null, btcTurkBalance.getLtc_available(), btcTurkBalance.getLtc_reserved()));
    balances.add(new Balance(Currency.USDT, null, btcTurkBalance.getUsdt_available(), btcTurkBalance.getUsdt_reserved()));
    balances.add(new Balance(Currency.XLM, null, btcTurkBalance.getXlm_available(), btcTurkBalance.getXlm_reserved()));
    return Wallet.Builder.from(balances).id(name).name(name).build();
}
Also used : ArrayList(java.util.ArrayList) BTCTurkAccountBalance(org.knowm.xchange.btcturk.dto.account.BTCTurkAccountBalance) Balance(org.knowm.xchange.dto.account.Balance)

Example 8 with Balance

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

the class CexIOAdapters method adaptWallet.

/**
 * Adapts CexIOBalanceInfo to Wallet
 *
 * @param cexIOBalanceInfo CexIOBalanceInfo balance
 * @return The account info
 */
public static Wallet adaptWallet(CexIOBalanceInfo cexIOBalanceInfo) {
    List<Balance> balances = new ArrayList<>();
    for (String ccyName : cexIOBalanceInfo.getBalances().keySet()) {
        CexIOBalance cexIOBalance = cexIOBalanceInfo.getBalances().get(ccyName);
        balances.add(adaptBalance(Currency.getInstance(ccyName), cexIOBalance));
    }
    return Wallet.Builder.from(balances).build();
}
Also used : CexIOBalance(org.knowm.xchange.cexio.dto.account.CexIOBalance) ArrayList(java.util.ArrayList) DateUtils.fromISODateString(org.knowm.xchange.utils.DateUtils.fromISODateString) CexIOBalance(org.knowm.xchange.cexio.dto.account.CexIOBalance) Balance(org.knowm.xchange.dto.account.Balance)

Example 9 with Balance

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

the class CryptopiaAccountServiceRaw method getBalances.

public List<Balance> getBalances() throws IOException {
    CryptopiaBaseResponse<List<Map>> response = cryptopia.getBalance(signatureCreator, new HashMap<>());
    List<Balance> balances = new ArrayList<>();
    for (Map datum : response.getData()) {
        Currency symbol = Currency.getInstance(datum.get("Symbol").toString());
        BigDecimal total = new BigDecimal(datum.get("Total").toString());
        BigDecimal available = new BigDecimal(datum.get("Available").toString());
        BigDecimal heldForTrades = new BigDecimal(datum.get("HeldForTrades").toString());
        BigDecimal pendingWithdraw = new BigDecimal(datum.get("PendingWithdraw").toString());
        BigDecimal unconfirmed = new BigDecimal(datum.get("Unconfirmed").toString());
        Balance balance = new Balance(symbol, total, available, heldForTrades, BigDecimal.ZERO, BigDecimal.ZERO, pendingWithdraw, unconfirmed);
        balances.add(balance);
    }
    return balances;
}
Also used : Currency(org.knowm.xchange.currency.Currency) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) Balance(org.knowm.xchange.dto.account.Balance) HashMap(java.util.HashMap) Map(java.util.Map) BigDecimal(java.math.BigDecimal)

Example 10 with Balance

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

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