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