Search in sources :

Example 16 with Wallet

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

the class KrakenAccountService method getAccountInfo.

@Override
public AccountInfo getAccountInfo() throws IOException {
    KrakenTradeBalanceInfo krakenTradeBalanceInfo = getKrakenTradeBalance();
    Wallet tradingWallet = KrakenAdapters.adaptWallet(getKrakenBalance());
    Wallet marginWallet = Wallet.Builder.from(tradingWallet.getBalances().values()).id("margin").features(EnumSet.of(Wallet.WalletFeature.FUNDING, Wallet.WalletFeature.MARGIN_TRADING)).maxLeverage(BigDecimal.valueOf(5)).currentLeverage((BigDecimal.ZERO.compareTo(krakenTradeBalanceInfo.getTradeBalance()) == 0) ? BigDecimal.ZERO : krakenTradeBalanceInfo.getCostBasis().divide(krakenTradeBalanceInfo.getTradeBalance(), MathContext.DECIMAL32)).build();
    return new AccountInfo(exchange.getExchangeSpecification().getUserName(), tradingWallet, marginWallet);
}
Also used : Wallet(org.knowm.xchange.dto.account.Wallet) KrakenTradeBalanceInfo(org.knowm.xchange.kraken.dto.account.KrakenTradeBalanceInfo) AccountInfo(org.knowm.xchange.dto.account.AccountInfo)

Example 17 with Wallet

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

the class BitmexAccountService method getAccountInfo.

@Override
public AccountInfo getAccountInfo() throws IOException {
    BitmexAccount account = super.getBitmexAccountInfo();
    BitmexMarginAccount bitmexMarginAccount = getBitmexMarginAccountStatus();
    BigDecimal amount = bitmexMarginAccount.getAmount().divide(BigDecimal.valueOf(100_000_000L));
    BigDecimal available = bitmexMarginAccount.getAvailableMargin().divide(BigDecimal.valueOf(100_000_000L));
    List<Balance> balances = new ArrayList<>();
    balances.add(new Balance(Currency.BTC, amount, available));
    Wallet wallet = Wallet.Builder.from(balances).id("margin").features(EnumSet.of(Wallet.WalletFeature.MARGIN_TRADING, Wallet.WalletFeature.FUNDING)).maxLeverage(BigDecimal.valueOf(100)).currentLeverage(bitmexMarginAccount.getMarginLeverage()).build();
    return new AccountInfo(account.getUsername(), wallet);
}
Also used : BitmexMarginAccount(org.knowm.xchange.bitmex.dto.account.BitmexMarginAccount) Wallet(org.knowm.xchange.dto.account.Wallet) ArrayList(java.util.ArrayList) BitmexAccount(org.knowm.xchange.bitmex.dto.account.BitmexAccount) Balance(org.knowm.xchange.dto.account.Balance) BigDecimal(java.math.BigDecimal) AccountInfo(org.knowm.xchange.dto.account.AccountInfo)

Example 18 with Wallet

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

the class CoinEggAdapters method adaptAccountInfo.

// TODO: Implement XAS Currency
public static AccountInfo adaptAccountInfo(CoinEggBalance coinEggBalance, Exchange exchange) {
    String userName = exchange.getExchangeSpecification().getUserName();
    Wallet btcWallet = Wallet.Builder.from(Arrays.asList(new Balance(Currency.BTC, coinEggBalance.getBTCBalance()))).id(Currency.BTC.getCurrencyCode()).build();
    Wallet ethWallet = Wallet.Builder.from(Arrays.asList(new Balance(Currency.ETH, coinEggBalance.getETHBalance()))).id(Currency.ETH.getCurrencyCode()).build();
    // Wallet xasWallet = new Wallet(new Balance(Currency.XAS, coinEggBalance.getXASBalance()));
    Set<Wallet> wallets = new HashSet<Wallet>();
    wallets.add(btcWallet);
    wallets.add(ethWallet);
    return new AccountInfo(userName, null, wallets);
}
Also used : Wallet(org.knowm.xchange.dto.account.Wallet) CoinEggBalance(org.knowm.xchange.coinegg.dto.accounts.CoinEggBalance) Balance(org.knowm.xchange.dto.account.Balance) AccountInfo(org.knowm.xchange.dto.account.AccountInfo) HashSet(java.util.HashSet)

Example 19 with Wallet

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

the class RippleAdapters method adaptAccountInfo.

/**
 * Adapts a Ripple Account to an XChange Wallet object.
 */
public static AccountInfo adaptAccountInfo(final RippleAccountBalances account, final String username) {
    // Adapt account balances to XChange balances
    final Map<String, List<Balance>> balances = new HashMap<>();
    for (final RippleBalance balance : account.getBalances()) {
        final String walletId;
        if (balance.getCurrency().equals("XRP")) {
            walletId = "main";
        } else {
            walletId = balance.getCounterparty();
        }
        if (!balances.containsKey(walletId)) {
            balances.put(walletId, new LinkedList<Balance>());
        }
        balances.get(walletId).add(new Balance(Currency.getInstance(balance.getCurrency()), balance.getValue()));
    }
    final List<Wallet> accountInfo = new ArrayList<>(balances.size());
    for (final Map.Entry<String, List<Balance>> wallet : balances.entrySet()) {
        accountInfo.add(Wallet.Builder.from(wallet.getValue()).id(wallet.getKey()).build());
    }
    return new AccountInfo(username, BigDecimal.ZERO, accountInfo);
}
Also used : HashMap(java.util.HashMap) Wallet(org.knowm.xchange.dto.account.Wallet) ArrayList(java.util.ArrayList) RippleBalance(org.knowm.xchange.ripple.dto.account.RippleBalance) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) List(java.util.List) Balance(org.knowm.xchange.dto.account.Balance) RippleBalance(org.knowm.xchange.ripple.dto.account.RippleBalance) HashMap(java.util.HashMap) Map(java.util.Map) AccountInfo(org.knowm.xchange.dto.account.AccountInfo)

Example 20 with Wallet

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

the class QuoineAdaptersTest method testAdaptAccountinfo.

@Test
public void testAdaptAccountinfo() throws IOException {
    // Read in the JSON from the example resources
    InputStream is = QuoineWalletJSONTest.class.getResourceAsStream("/org/knowm/xchange/quoine/dto/account/example-account-data.json");
    // Use Jackson to parse it
    ObjectMapper mapper = new ObjectMapper();
    QuoineAccountInfo quoineWallet = mapper.readValue(is, QuoineAccountInfo.class);
    Wallet wallet = QuoineAdapters.adaptWallet(quoineWallet);
    // Verify that the example data was unmarshalled correctly
    assertThat(wallet.getBalances()).hasSize(6);
    System.out.println(wallet.getBalance(Currency.JPY).toString());
    assertThat(wallet.getBalance(Currency.JPY).getCurrency()).isEqualTo(Currency.JPY);
    assertThat(wallet.getBalance(Currency.JPY).getTotal()).isEqualTo(new BigDecimal("12546.36144"));
}
Also used : InputStream(java.io.InputStream) Wallet(org.knowm.xchange.dto.account.Wallet) QuoineAccountInfo(org.knowm.xchange.quoine.dto.account.QuoineAccountInfo) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) BigDecimal(java.math.BigDecimal) QuoineOrderBookJSONTest(org.knowm.xchange.quoine.dto.marketdata.QuoineOrderBookJSONTest) QuoineWalletJSONTest(org.knowm.xchange.quoine.dto.account.QuoineWalletJSONTest) Test(org.junit.Test) QuoineTickerJSONTest(org.knowm.xchange.quoine.dto.marketdata.QuoineTickerJSONTest) QuoineOrdersListJSONTest(org.knowm.xchange.quoine.dto.trade.QuoineOrdersListJSONTest)

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