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;
}
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);
}
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());
}
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());
}
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());
}
Aggregations