Search in sources :

Example 21 with Balance

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")));
}
Also used : JsonNode(com.fasterxml.jackson.databind.JsonNode) Balance(org.knowm.xchange.dto.account.Balance) BigDecimal(java.math.BigDecimal) Test(org.junit.Test)

Example 22 with Balance

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"))));
}
Also used : Wallet(org.knowm.xchange.dto.account.Wallet) JsonNode(com.fasterxml.jackson.databind.JsonNode) Balance(org.knowm.xchange.dto.account.Balance) BigDecimal(java.math.BigDecimal) Test(org.junit.Test)

Example 23 with Balance

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());
}
Also used : Currency(org.knowm.xchange.currency.Currency) ArrayList(java.util.ArrayList) Balance(org.knowm.xchange.dto.account.Balance) AccountInfo(org.knowm.xchange.dto.account.AccountInfo)

Example 24 with Balance

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]);
}
Also used : BleutradeBalancesReturn(org.knowm.xchange.bleutrade.dto.account.BleutradeBalancesReturn) ParamsDigest(si.mazi.rescu.ParamsDigest) Currency(org.knowm.xchange.currency.Currency) BleutradeBalance(org.knowm.xchange.bleutrade.dto.account.BleutradeBalance) Balance(org.knowm.xchange.dto.account.Balance) AccountInfo(org.knowm.xchange.dto.account.AccountInfo) SynchronizedValueFactory(si.mazi.rescu.SynchronizedValueFactory) Test(org.junit.Test)

Example 25 with Balance

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();
}
Also used : Currency(org.knowm.xchange.currency.Currency) ArrayList(java.util.ArrayList) Balance(org.knowm.xchange.dto.account.Balance) DsxBalance(org.knowm.xchange.dsx.dto.DsxBalance) DsxBalance(org.knowm.xchange.dsx.dto.DsxBalance)

Aggregations

Balance (org.knowm.xchange.dto.account.Balance)99 BigDecimal (java.math.BigDecimal)51 ArrayList (java.util.ArrayList)50 AccountInfo (org.knowm.xchange.dto.account.AccountInfo)50 Wallet (org.knowm.xchange.dto.account.Wallet)38 Currency (org.knowm.xchange.currency.Currency)37 Test (org.junit.Test)23 Map (java.util.Map)14 Date (java.util.Date)13 HashMap (java.util.HashMap)10 List (java.util.List)8 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)7 InputStream (java.io.InputStream)6 IOException (java.io.IOException)5 OrderBook (org.knowm.xchange.dto.marketdata.OrderBook)5 Ticker (org.knowm.xchange.dto.marketdata.Ticker)5 JsonNode (com.fasterxml.jackson.databind.JsonNode)4 Arrays (java.util.Arrays)4 HashSet (java.util.HashSet)4 Collection (java.util.Collection)3