use of org.knowm.xchange.dto.account.Balance in project XChange by knowm.
the class LgoStreamingAccountServiceTest method it_connects_one_time_and_filters_by_currency.
@Test
public void it_connects_one_time_and_filters_by_currency() throws IOException {
JsonNode snapshot = TestUtils.getJsonContent("/account/balance-snapshot.json");
JsonNode update = TestUtils.getJsonContent("/account/balance-update.json");
LgoStreamingService streamingService = mock(LgoStreamingService.class);
LgoStreamingAccountService service = new LgoStreamingAccountService(streamingService);
when(streamingService.subscribeChannel(anyString())).thenReturn(Observable.just(snapshot, update));
TestObserver<Balance> btcChanges = service.getBalanceChanges(Currency.BTC).test();
TestObserver<Balance> usdChanges = service.getBalanceChanges(Currency.USD).test();
verify(streamingService, times(1)).subscribeChannel("balance");
btcChanges.assertValueAt(1, new Balance(Currency.BTC, new BigDecimal("2299.01329566"), new BigDecimal("2295.01329566"), new BigDecimal("4.00000000")));
usdChanges.assertValueAt(1, new Balance(Currency.USD, new BigDecimal("453616.3125"), new BigDecimal("453616.3125"), new BigDecimal("0.0000")));
}
use of org.knowm.xchange.dto.account.Balance in project XChange by knowm.
the class LgoStreamingAccountServiceTest method it_gives_initial_wallet_snapshot.
@Test
public void it_gives_initial_wallet_snapshot() throws IOException {
JsonNode snapshot = TestUtils.getJsonContent("/account/balance-snapshot.json");
LgoStreamingService streamingService = mock(LgoStreamingService.class);
LgoStreamingAccountService service = new LgoStreamingAccountService(streamingService);
Observable<JsonNode> source = Observable.just(snapshot);
when(streamingService.subscribeChannel(anyString())).thenReturn(source);
TestObserver<Wallet> wallet = service.getWallet().test();
verify(streamingService).subscribeChannel("balance");
wallet.assertSubscribed();
wallet.assertValueCount(1);
wallet.values().contains(buildWallet(new Balance(Currency.BTC, new BigDecimal("2301.01329566"), new BigDecimal("2297.01329566"), new BigDecimal("4.00000000")), new Balance(Currency.USD, new BigDecimal("453616.3125"), new BigDecimal("453616.3125"), new BigDecimal("0.0000"))));
}
use of org.knowm.xchange.dto.account.Balance in project XChange by knowm.
the class AscendexAdapters method adaptAccountInfo.
public static AccountInfo adaptAccountInfo(List<AscendexCashAccountBalanceDto> ascendexCashAccountBalanceDtoList) {
List<Balance> balances = new ArrayList<>(ascendexCashAccountBalanceDtoList.size());
ascendexCashAccountBalanceDtoList.forEach(ascendexCashAccountBalanceDto -> balances.add(new Balance.Builder().currency(new Currency(ascendexCashAccountBalanceDto.getAsset())).available(ascendexCashAccountBalanceDto.getAvailableBalance()).total(ascendexCashAccountBalanceDto.getTotalBalance()).frozen(ascendexCashAccountBalanceDto.getTotalBalance().subtract(ascendexCashAccountBalanceDto.getAvailableBalance())).build()));
return new AccountInfo(Wallet.Builder.from(balances).id("spot").features(new HashSet<>(Collections.singletonList(Wallet.WalletFeature.TRADING))).build());
}
use of org.knowm.xchange.dto.account.Balance in project XChange by knowm.
the class BleutradeAccountServiceIntegration method shouldGetAccountInfo.
@Test
public void shouldGetAccountInfo() throws IOException {
// given
BleutradeBalancesReturn balancesReturn = new BleutradeBalancesReturn();
balancesReturn.setSuccess(true);
balancesReturn.setMessage("test message");
balancesReturn.setResult(expectedBleutradeAccountInfo());
when(bleutrade.getBalances(eq(SPECIFICATION_API_KEY), any(ParamsDigest.class), any(SynchronizedValueFactory.class))).thenReturn(balancesReturn);
final Balance[] expectedAccountBalances = expectedAccountBalances();
// when
AccountInfo accountInfo = accountService.getAccountInfo();
// then
assertThat(accountInfo.getWallets()).hasSize(1);
Map<Currency, Balance> balances = accountInfo.getWallet().getBalances();
assertThat(balances).hasSize(3);
BleutradeAssert.assertEquals(balances.get(Currency.AUD), expectedAccountBalances[0]);
BleutradeAssert.assertEquals(balances.get(Currency.BTC), expectedAccountBalances[1]);
BleutradeAssert.assertEquals(balances.get(Currency.getInstance("BLEU")), expectedAccountBalances[2]);
}
use of org.knowm.xchange.dto.account.Balance in project XChange by knowm.
the class DsxAdapters method adaptWallet.
public static Wallet adaptWallet(String name, List<DsxBalance> dsxBalances) {
List<Balance> balances = new ArrayList<>(dsxBalances.size());
for (DsxBalance balanceRaw : dsxBalances) {
Currency currency = Currency.getInstance(balanceRaw.getCurrency());
Balance balance = new Balance(currency, null, balanceRaw.getAvailable(), balanceRaw.getReserved());
balances.add(balance);
}
return Wallet.Builder.from(balances).id(name).name(name).build();
}
Aggregations