Search in sources :

Example 26 with AccountInfo

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

the class LunoAccountService method getAccountInfo.

@Override
public AccountInfo getAccountInfo() throws IOException {
    LunoBalance lunoBalance = lunoAPI.balance();
    List<Wallet> wallets = new ArrayList<>();
    for (org.knowm.xchange.luno.dto.account.LunoBalance.Balance lb : lunoBalance.getBalance()) {
        List<Balance> balances = new ArrayList<>();
        balances.add(new Balance(LunoUtil.fromLunoCurrency(lb.asset), lb.balance, lb.balance.subtract(lb.reserved)));
        wallets.add(Wallet.Builder.from(balances).id(lb.accountId).name(lb.name).build());
    }
    return new AccountInfo(exchange.getExchangeSpecification().getUserName(), wallets);
}
Also used : LunoBalance(org.knowm.xchange.luno.dto.account.LunoBalance) Wallet(org.knowm.xchange.dto.account.Wallet) ArrayList(java.util.ArrayList) Exchange(org.knowm.xchange.Exchange) Balance(org.knowm.xchange.dto.account.Balance) LunoBalance(org.knowm.xchange.luno.dto.account.LunoBalance) AccountInfo(org.knowm.xchange.dto.account.AccountInfo)

Example 27 with AccountInfo

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

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

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

the class CoinfloorAdaptersTests method adaptAccountInfoTest.

@Test
public void adaptAccountInfoTest() throws JsonParseException, JsonMappingException, IOException {
    ObjectMapper mapper = new ObjectMapper();
    InputStream btcgbpStream = getClass().getResourceAsStream("/org/knowm/xchange/coinfloor/dto/account/example-balance-btcgbp.json");
    CoinfloorBalance btcgbp = mapper.readValue(btcgbpStream, CoinfloorBalance.class);
    InputStream btcusdStream = getClass().getResourceAsStream("/org/knowm/xchange/coinfloor/dto/account/example-balance-btcusd.json");
    CoinfloorBalance btcusd = mapper.readValue(btcusdStream, CoinfloorBalance.class);
    Currency[] currencies = { Currency.BTC, Currency.GBP, Currency.USD, Currency.EUR };
    CoinfloorBalance[] rawBalances = { btcgbp, btcusd };
    AccountInfo info = CoinfloorAdapters.adaptAccountInfo(Arrays.asList(currencies), Arrays.asList(rawBalances));
    assertThat(info.getWallet().getBalances()).hasSize(3);
    Balance btc = info.getWallet().getBalance(Currency.BTC);
    assertThat(btc.getTotal()).isEqualTo("120.3500");
    assertThat(btc.getFrozen()).isEqualTo("0");
    assertThat(btc.getAvailable()).isEqualTo("120.3500");
    Balance gbp = info.getWallet().getBalance(Currency.GBP);
    assertThat(gbp.getTotal()).isEqualTo("50000.00");
    assertThat(gbp.getFrozen()).isEqualTo("20000.00");
    assertThat(gbp.getAvailable()).isEqualTo("0.00");
    Balance usd = info.getWallet().getBalance(Currency.USD);
    assertThat(usd.getTotal()).isEqualTo("700.00");
    assertThat(usd.getFrozen()).isEqualTo("0");
    assertThat(usd.getAvailable()).isEqualTo("700.00");
}
Also used : CoinfloorBalance(org.knowm.xchange.coinfloor.dto.account.CoinfloorBalance) InputStream(java.io.InputStream) Currency(org.knowm.xchange.currency.Currency) Balance(org.knowm.xchange.dto.account.Balance) CoinfloorBalance(org.knowm.xchange.coinfloor.dto.account.CoinfloorBalance) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) AccountInfo(org.knowm.xchange.dto.account.AccountInfo) Test(org.junit.Test)

Example 30 with AccountInfo

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

Aggregations

AccountInfo (org.knowm.xchange.dto.account.AccountInfo)96 Balance (org.knowm.xchange.dto.account.Balance)50 Wallet (org.knowm.xchange.dto.account.Wallet)35 BigDecimal (java.math.BigDecimal)34 ArrayList (java.util.ArrayList)25 Test (org.junit.Test)23 Currency (org.knowm.xchange.currency.Currency)18 Date (java.util.Date)13 AccountService (org.knowm.xchange.service.account.AccountService)13 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)9 InputStream (java.io.InputStream)9 Exchange (org.knowm.xchange.Exchange)9 Map (java.util.Map)6 IOException (java.io.IOException)5 HashMap (java.util.HashMap)5 List (java.util.List)5 Arrays (java.util.Arrays)3 FileNotFoundException (java.io.FileNotFoundException)2 ZERO (java.math.BigDecimal.ZERO)2 Collection (java.util.Collection)2