Search in sources :

Example 1 with Wallet

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

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

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

Example 4 with Wallet

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

Example 5 with Wallet

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

the class IndependentReserveAccountDemo method generic.

private static void generic(AccountService accountService) throws IOException {
    // Get the account information
    AccountInfo accountInfo = accountService.getAccountInfo();
    System.out.println("Account balances: (available / available for withdrawal / total)");
    Wallet wallet = accountInfo.getWallet();
    Map<Currency, Balance> balances = wallet.getBalances();
    for (Map.Entry<Currency, Balance> entry : balances.entrySet()) {
        Balance balance = entry.getValue();
        System.out.format("%s balance: %s / %s / %s\n", entry.getKey().getCurrencyCode(), balance.getAvailable(), balance.getAvailableForWithdrawal(), balance.getTotal());
    }
}
Also used : Wallet(org.knowm.xchange.dto.account.Wallet) Currency(org.knowm.xchange.currency.Currency) IndependentReserveBalance(org.knowm.xchange.independentreserve.dto.account.IndependentReserveBalance) Balance(org.knowm.xchange.dto.account.Balance) Map(java.util.Map) AccountInfo(org.knowm.xchange.dto.account.AccountInfo)

Aggregations

Wallet (org.knowm.xchange.dto.account.Wallet)47 Balance (org.knowm.xchange.dto.account.Balance)36 AccountInfo (org.knowm.xchange.dto.account.AccountInfo)34 BigDecimal (java.math.BigDecimal)29 Test (org.junit.Test)17 ArrayList (java.util.ArrayList)12 Date (java.util.Date)10 Currency (org.knowm.xchange.currency.Currency)9 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)8 InputStream (java.io.InputStream)8 HashMap (java.util.HashMap)5 List (java.util.List)4 Map (java.util.Map)4 JsonNode (com.fasterxml.jackson.databind.JsonNode)3 IOException (java.io.IOException)3 Arrays (java.util.Arrays)3 FileNotFoundException (java.io.FileNotFoundException)2 ZERO (java.math.BigDecimal.ZERO)2 Collection (java.util.Collection)2 Collections (java.util.Collections)2