use of org.knowm.xchange.dto.account.Balance in project XChange by knowm.
the class HuobiAdapters method adaptWallet.
public static Wallet adaptWallet(Map<String, HuobiBalanceSum> huobiWallet) {
List<Balance> balances = new ArrayList<>(huobiWallet.size());
for (Map.Entry<String, HuobiBalanceSum> record : huobiWallet.entrySet()) {
try {
Currency currency = adaptCurrency(record.getKey());
if (currency == null) {
// Avoid creating Balance objects with null currency.
continue;
}
Balance balance = new Balance(currency, record.getValue().getTotal(), record.getValue().getAvailable(), record.getValue().getFrozen());
balances.add(balance);
} catch (ExchangeException e) {
// It might be a new currency. Ignore the exception and continue with other currency.
}
}
return Wallet.Builder.from(balances).build();
}
use of org.knowm.xchange.dto.account.Balance in project XChange by knowm.
the class HuobiPrivateApiIntegration method getBalanceTest.
@Test
public void getBalanceTest() throws IOException {
AccountService accountService = exchange.getAccountService();
Balance balance = accountService.getAccountInfo().getWallet().getBalance(Currency.USDT);
System.out.println(balance.toString());
assertThat(balance).isNotNull();
}
use of org.knowm.xchange.dto.account.Balance in project XChange by knowm.
the class TestSimulatedExchange method testBalanceIsReleasedOnCancel.
@Test
public void testBalanceIsReleasedOnCancel() throws IOException {
// When
String orderId = exchange.getTradeService().placeLimitOrder(new LimitOrder.Builder(BID, BTC_USD).limitPrice(new BigDecimal(10)).originalAmount(new BigDecimal("0.7")).build());
exchange.getTradeService().cancelOrder(orderId);
Balance baseBalance = exchange.getAccountService().getAccountInfo().getWallet().getBalance(BTC);
// THen
assertThat(baseBalance.getTotal()).isEqualTo(INITIAL_BALANCE);
assertThat(baseBalance.getFrozen()).isEqualTo(ZERO);
assertThat(baseBalance.getAvailable()).isEqualTo(INITIAL_BALANCE);
}
use of org.knowm.xchange.dto.account.Balance in project XChange by knowm.
the class TestSimulatedExchange method testTradingMarketAsk.
@Test
public void testTradingMarketAsk() throws IOException {
// When
exchange.getTradeService().placeMarketOrder(new MarketOrder.Builder(ASK, BTC_USD).originalAmount(new BigDecimal("0.7")).build());
OrderBook orderBook = exchange.getMarketDataService().getOrderBook(BTC_USD);
Ticker ticker = exchange.getMarketDataService().getTicker(BTC_USD);
Balance baseBalance = exchange.getAccountService().getAccountInfo().getWallet().getBalance(BTC);
Balance counterBalance = exchange.getAccountService().getAccountInfo().getWallet().getBalance(USD);
// Then
assertThat(orderBook.getAsks()).hasSize(4);
assertThat(orderBook.getBids()).hasSize(5);
assertThat(ticker.getAsk()).isEqualTo(new BigDecimal(98));
assertThat(ticker.getBid()).isEqualTo(new BigDecimal(96));
assertThat(ticker.getLast()).isEqualTo(new BigDecimal(96));
assertThat(getTradeHistory(exchange).getTrades()).hasSize(3);
BigDecimal expectedUsdProceeds = new BigDecimal(97).multiply(new BigDecimal("0.40")).add(new BigDecimal(96).multiply(new BigDecimal("0.30")));
assertThat(baseBalance.getAvailable()).isEqualTo(INITIAL_BALANCE.subtract(new BigDecimal("0.70")));
assertThat(baseBalance.getTotal()).isEqualTo(INITIAL_BALANCE.subtract(new BigDecimal("0.70")));
assertThat(baseBalance.getFrozen()).isEqualTo(ZERO);
assertThat(counterBalance.getAvailable()).isEqualTo(INITIAL_BALANCE.add(expectedUsdProceeds));
assertThat(counterBalance.getTotal()).isEqualTo(INITIAL_BALANCE.add(expectedUsdProceeds));
assertThat(counterBalance.getFrozen()).isEqualTo(ZERO);
}
use of org.knowm.xchange.dto.account.Balance in project XChange by knowm.
the class TestSimulatedExchange method testTradingMarketBid.
@Test
public void testTradingMarketBid() throws IOException {
// When
exchange.getTradeService().placeMarketOrder(new MarketOrder.Builder(BID, BTC_USD).originalAmount(new BigDecimal("0.56")).build());
OrderBook orderBook = exchange.getMarketDataService().getOrderBook(BTC_USD);
Ticker ticker = exchange.getMarketDataService().getTicker(BTC_USD);
Balance baseBalance = exchange.getAccountService().getAccountInfo().getWallet().getBalance(BTC);
Balance counterBalance = exchange.getAccountService().getAccountInfo().getWallet().getBalance(USD);
// THen
assertThat(orderBook.getAsks()).hasSize(3);
assertThat(orderBook.getBids()).hasSize(6);
assertThat(ticker.getAsk()).isEqualTo(new BigDecimal(99));
assertThat(ticker.getBid()).isEqualTo(new BigDecimal(97));
assertThat(ticker.getLast()).isEqualTo(new BigDecimal(99));
assertThat(getTradeHistory(exchange).getTrades()).hasSize(3);
BigDecimal expectedUsdCost = new BigDecimal(98).multiply(new BigDecimal("0.3")).add(new BigDecimal(99).multiply(new BigDecimal("0.26")));
assertThat(baseBalance.getAvailable()).isEqualTo(INITIAL_BALANCE.add(new BigDecimal("0.56")));
assertThat(baseBalance.getTotal()).isEqualTo(INITIAL_BALANCE.add(new BigDecimal("0.56")));
assertThat(baseBalance.getFrozen()).isEqualTo(ZERO);
assertThat(counterBalance.getAvailable()).isEqualTo(INITIAL_BALANCE.subtract(expectedUsdCost));
assertThat(counterBalance.getTotal()).isEqualTo(INITIAL_BALANCE.subtract(expectedUsdCost));
assertThat(counterBalance.getFrozen()).isEqualTo(ZERO);
}
Aggregations