Search in sources :

Example 16 with Balance

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

the class ExmoAccountServiceRaw method balances.

public List<Balance> balances() {
    Map map = exmo.userInfo(signatureCreator, apiKey, exchange.getNonceFactory());
    Map<String, String> balances = (Map<String, String>) map.get("balances");
    Map<String, String> reserved = (Map<String, String>) map.get("reserved");
    List<Balance> results = new ArrayList<>();
    for (String ccy : balances.keySet()) {
        results.add(ExmoAdapters.adaptBalance(balances, reserved, ccy));
    }
    return results;
}
Also used : ArrayList(java.util.ArrayList) Map(java.util.Map) Balance(org.knowm.xchange.dto.account.Balance)

Example 17 with Balance

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

the class ExmoAdapters method adaptBalance.

public static Balance adaptBalance(Map<String, String> balances, Map<String, String> reserved, String ccy) {
    Currency currency = Currency.getInstance(ccy);
    BigDecimal available = new BigDecimal(balances.get(ccy));
    BigDecimal frozen = new BigDecimal(reserved.get(ccy));
    return new Balance(currency, available.add(frozen), available, frozen);
}
Also used : Currency(org.knowm.xchange.currency.Currency) Balance(org.knowm.xchange.dto.account.Balance) BigDecimal(java.math.BigDecimal)

Example 18 with Balance

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

the class MercadoBitcoinAdapters method adaptAccountInfo.

/**
 * Adapts a MercadoBitcoinBaseTradeApiResult<MercadoBitcoinAccountInfo> to an AccountInfo
 *
 * @param accountInfo The Mercado Bitcoin accountInfo
 * @param userName The user name
 * @return The account info
 */
public static AccountInfo adaptAccountInfo(MercadoBitcoinBaseTradeApiResult<MercadoBitcoinAccountInfo> accountInfo, String userName) {
    // Adapt to XChange DTOs
    Balance brlBalance = new Balance(Currency.BRL, accountInfo.getTheReturn().getFunds().getBrl());
    Balance btcBalance = new Balance(Currency.BTC, accountInfo.getTheReturn().getFunds().getBtc());
    Balance ltcBalance = new Balance(Currency.LTC, accountInfo.getTheReturn().getFunds().getLtc());
    return new AccountInfo(userName, Wallet.Builder.from(Stream.of(brlBalance, btcBalance, ltcBalance).collect(Collectors.toList())).build());
}
Also used : Balance(org.knowm.xchange.dto.account.Balance) MercadoBitcoinAccountInfo(org.knowm.xchange.mercadobitcoin.dto.account.MercadoBitcoinAccountInfo) AccountInfo(org.knowm.xchange.dto.account.AccountInfo)

Example 19 with Balance

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

the class OkCoinAdapters method adaptAccountInfo.

public static AccountInfo adaptAccountInfo(OkCoinUserInfo userInfo) {
    OkCoinFunds funds = userInfo.getInfo().getFunds();
    Map<String, Balance.Builder> builders = new TreeMap<>();
    for (Map.Entry<String, BigDecimal> available : funds.getFree().entrySet()) {
        builders.put(available.getKey(), new Balance.Builder().currency(Currency.getInstance(available.getKey())).available(available.getValue()));
    }
    for (Map.Entry<String, BigDecimal> frozen : funds.getFreezed().entrySet()) {
        Balance.Builder builder = builders.get(frozen.getKey());
        if (builder == null) {
            builder = new Balance.Builder().currency(Currency.getInstance(frozen.getKey()));
        }
        builders.put(frozen.getKey(), builder.frozen(frozen.getValue()));
    }
    for (Map.Entry<String, BigDecimal> borrowed : funds.getBorrow().entrySet()) {
        Balance.Builder builder = builders.get(borrowed.getKey());
        if (builder == null) {
            builder = new Balance.Builder().currency(Currency.getInstance(borrowed.getKey()));
        }
        builders.put(borrowed.getKey(), builder.borrowed(borrowed.getValue()));
    }
    List<Balance> wallet = new ArrayList<>(builders.size());
    for (Balance.Builder builder : builders.values()) {
        wallet.add(builder.build());
    }
    return new AccountInfo(Wallet.Builder.from(wallet).build());
}
Also used : OkCoinFunds(org.knowm.xchange.okcoin.dto.account.OkCoinFunds) ArrayList(java.util.ArrayList) TreeMap(java.util.TreeMap) BigDecimal(java.math.BigDecimal) Map(java.util.Map) TreeMap(java.util.TreeMap) Balance(org.knowm.xchange.dto.account.Balance) AccountInfo(org.knowm.xchange.dto.account.AccountInfo)

Example 20 with Balance

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

the class TheRockAdapters method adaptAccountInfo.

public static AccountInfo adaptAccountInfo(List<TheRockBalance> trBalances, String userName) {
    ArrayList<Balance> balances = new ArrayList<>(trBalances.size());
    for (TheRockBalance blc : trBalances) {
        Currency currency = Currency.getInstance(blc.getCurrency());
        balances.add(new Balance(currency, blc.getBalance(), blc.getTradingBalance()));
    }
    return new AccountInfo(userName, Wallet.Builder.from(balances).id("spot").build());
}
Also used : TheRockBalance(org.knowm.xchange.therock.dto.account.TheRockBalance) Currency(org.knowm.xchange.currency.Currency) ArrayList(java.util.ArrayList) Balance(org.knowm.xchange.dto.account.Balance) TheRockBalance(org.knowm.xchange.therock.dto.account.TheRockBalance) AccountInfo(org.knowm.xchange.dto.account.AccountInfo)

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