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