Search in sources :

Example 1 with Balance

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

the class BitsoAdapters method adaptWallet.

public static Wallet adaptWallet(BitsoBalance bitsoBalance) {
    // Adapt to XChange DTOs
    Balance mxnBalance = new Balance(Currency.MXN, bitsoBalance.getMxnBalance(), bitsoBalance.getMxnAvailable(), bitsoBalance.getMxnReserved());
    Balance btcBalance = new Balance(Currency.BTC, bitsoBalance.getBtcBalance(), bitsoBalance.getBtcAvailable(), bitsoBalance.getBtcReserved());
    return Wallet.Builder.from(Arrays.asList(mxnBalance, btcBalance)).build();
}
Also used : Balance(org.knowm.xchange.dto.account.Balance) BitsoBalance(org.knowm.xchange.bitso.dto.account.BitsoBalance)

Example 2 with Balance

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

the class LatokenAccountService method getAccountInfo.

@Override
public AccountInfo getAccountInfo() throws IOException {
    try {
        List<LatokenBalance> latokenBalances = getLatokenBalances();
        List<Balance> balances = latokenBalances.stream().map(latokenBalance -> LatokenAdapters.adaptBalance(latokenBalance)).collect(Collectors.toList());
        Wallet wallet = Wallet.Builder.from(balances).build();
        return new AccountInfo(null, TRADING_FEE, Arrays.asList(wallet), new Date());
    } catch (LatokenException e) {
        throw LatokenErrorAdapter.adapt(e);
    }
}
Also used : AccountInfo(org.knowm.xchange.dto.account.AccountInfo) Arrays(java.util.Arrays) AccountService(org.knowm.xchange.service.account.AccountService) LatokenException(org.knowm.xchange.latoken.dto.LatokenException) Wallet(org.knowm.xchange.dto.account.Wallet) Date(java.util.Date) LatokenBalance(org.knowm.xchange.latoken.dto.account.LatokenBalance) IOException(java.io.IOException) Exchange(org.knowm.xchange.Exchange) Collectors(java.util.stream.Collectors) Balance(org.knowm.xchange.dto.account.Balance) BigDecimal(java.math.BigDecimal) List(java.util.List) LatokenErrorAdapter(org.knowm.xchange.latoken.LatokenErrorAdapter) LatokenAdapters(org.knowm.xchange.latoken.LatokenAdapters) LatokenException(org.knowm.xchange.latoken.dto.LatokenException) LatokenBalance(org.knowm.xchange.latoken.dto.account.LatokenBalance) Wallet(org.knowm.xchange.dto.account.Wallet) LatokenBalance(org.knowm.xchange.latoken.dto.account.LatokenBalance) Balance(org.knowm.xchange.dto.account.Balance) AccountInfo(org.knowm.xchange.dto.account.AccountInfo) Date(java.util.Date)

Example 3 with Balance

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

the class AccountServiceIntegration method testBalances.

@Test
public void testBalances() throws Exception {
    Wallet wallet = accountService.getAccountInfo().getWallet();
    Assert.assertNotNull(wallet);
    Map<Currency, Balance> balances = wallet.getBalances();
    for (Entry<Currency, Balance> entry : balances.entrySet()) {
        Currency curr = entry.getKey();
        Balance bal = entry.getValue();
        if (0 < bal.getAvailable().doubleValue()) {
            Assert.assertSame(curr, bal.getCurrency());
            Assert.assertSame(Currency.getInstance(curr.getCurrencyCode()), bal.getCurrency());
        }
    }
}
Also used : Wallet(org.knowm.xchange.dto.account.Wallet) Currency(org.knowm.xchange.currency.Currency) Balance(org.knowm.xchange.dto.account.Balance) Test(org.junit.Test)

Example 4 with Balance

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

the class BitbayAdapters method adaptAccountInfo.

public static AccountInfo adaptAccountInfo(String userName, BitbayAccountInfoResponse bitbayAccountInfo) {
    List<Balance> balances = new ArrayList<>(bitbayAccountInfo.getBitbayBalances().size());
    for (Map.Entry<String, BitbayBalance> entry : bitbayAccountInfo.getBitbayBalances().entrySet()) {
        Currency currency = Currency.getInstance(entry.getKey());
        BitbayBalance balance = entry.getValue();
        balances.add(new Balance(currency, balance.getAvailable().add(balance.getLocked()), balance.getAvailable(), balance.getLocked()));
    }
    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) BitbayBalance(org.knowm.xchange.bitbay.dto.acount.BitbayBalance) Map(java.util.Map) AccountInfo(org.knowm.xchange.dto.account.AccountInfo) BitbayBalance(org.knowm.xchange.bitbay.dto.acount.BitbayBalance)

Example 5 with Balance

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

the class BitbayAccountService method getAccountInfo.

@Override
public AccountInfo getAccountInfo() throws IOException {
    List<Wallet> wallets = new ArrayList<>();
    for (BitbayBalances.BitbayBalance balance : balances()) {
        Wallet wallet = Wallet.Builder.from(Arrays.asList(new Balance(Currency.getInstance(balance.getCurrency()), balance.getTotalFunds(), balance.getAvailableFunds(), balance.getLockedFunds()))).id(balance.getId()).build();
        wallets.add(wallet);
    }
    return new AccountInfo(wallets);
}
Also used : Wallet(org.knowm.xchange.dto.account.Wallet) BitbayBalances(org.knowm.xchange.bitbay.v3.dto.BitbayBalances) ArrayList(java.util.ArrayList) Balance(org.knowm.xchange.dto.account.Balance) 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