use of tech.cassandre.trading.bot.dto.user.AccountDTO in project cassandre-trading-bot by cassandre-tech.
the class AccountDTOTest method checkEqualsOnAccountIdAndName.
@Test
@DisplayName("Check equals() on account id & name")
public void checkEqualsOnAccountIdAndName() {
// Account 1 (null).
AccountDTO account1 = AccountDTO.builder().accountId(null).name(null).build();
// Account 2.
AccountDTO account2 = AccountDTO.builder().accountId("01").name("01").build();
assertNotEquals(account2, account1);
assertNotEquals(account1, account2);
// Account 3 - Same as account2.
AccountDTO account3 = AccountDTO.builder().accountId("01").name("01").build();
assertEquals(account2, account3);
assertEquals(account3, account2);
// Account 4 - id changed compared to account 2.
AccountDTO account4 = AccountDTO.builder().accountId("CHANGED").name("01").build();
assertNotEquals(account2, account4);
assertNotEquals(account4, account2);
// Account 5 - Name changed compared to account 2.
AccountDTO account5 = AccountDTO.builder().accountId("01").name("CHANGED").build();
assertNotEquals(account2, account5);
assertNotEquals(account5, account2);
}
use of tech.cassandre.trading.bot.dto.user.AccountDTO in project cassandre-trading-bot by cassandre-tech.
the class AccountDTOTest method checkEqualToForBalancesValues.
@Test
@SuppressWarnings("checkstyle:MethodLength")
@DisplayName("Check equals() on balances values")
public void checkEqualToForBalancesValues() {
Set<BalanceDTO> balances = new LinkedHashSet<>();
// Account 1.
BalanceDTO account1Balance1 = BalanceDTO.builder().currency(BTC).total(new BigDecimal("1")).available(new BigDecimal("1")).frozen(new BigDecimal("1")).loaned(new BigDecimal("1")).borrowed(new BigDecimal("1")).withdrawing(new BigDecimal("1")).depositing(new BigDecimal("1")).build();
BalanceDTO account1Balance2 = BalanceDTO.builder().currency(ETH).total(new BigDecimal("2")).available(new BigDecimal("2")).frozen(new BigDecimal("2")).loaned(new BigDecimal("2")).borrowed(new BigDecimal("2")).withdrawing(new BigDecimal("2")).depositing(new BigDecimal("2")).build();
balances.add(account1Balance1);
balances.add(account1Balance2);
AccountDTO account1 = AccountDTO.builder().balances(balances).build();
balances.clear();
// Account 2 - same values.
BalanceDTO account2Balance1 = BalanceDTO.builder().currency(BTC).total(new BigDecimal("1")).available(new BigDecimal("1")).frozen(new BigDecimal("1")).loaned(new BigDecimal("1")).borrowed(new BigDecimal("1")).withdrawing(new BigDecimal("1")).depositing(new BigDecimal("1")).build();
BalanceDTO account2Balance2 = BalanceDTO.builder().currency(ETH).total(new BigDecimal("2")).available(new BigDecimal("2")).frozen(new BigDecimal("2")).loaned(new BigDecimal("2")).borrowed(new BigDecimal("2")).withdrawing(new BigDecimal("2")).depositing(new BigDecimal("2")).build();
balances.add(account2Balance1);
balances.add(account2Balance2);
AccountDTO account2 = AccountDTO.builder().balances(balances).build();
balances.clear();
assertEquals(account1, account1);
assertEquals(account2, account2);
// Account 3 - available changes.
BalanceDTO account3Balance1 = BalanceDTO.builder().currency(BTC).total(new BigDecimal("1")).available(new BigDecimal("11")).frozen(new BigDecimal("1")).loaned(new BigDecimal("1")).borrowed(new BigDecimal("1")).withdrawing(new BigDecimal("1")).depositing(new BigDecimal("1")).build();
BalanceDTO account3Balance2 = BalanceDTO.builder().currency(ETH).total(new BigDecimal("2")).available(new BigDecimal("2")).frozen(new BigDecimal("2")).loaned(new BigDecimal("2")).borrowed(new BigDecimal("2")).withdrawing(new BigDecimal("2")).depositing(new BigDecimal("2")).build();
balances.add(account3Balance2);
balances.add(account3Balance1);
AccountDTO account3 = AccountDTO.builder().balances(balances).build();
balances.clear();
assertNotEquals(account1, account3);
assertNotEquals(account3, account1);
// Account 4 - borrowed changed.
BalanceDTO account4Balance1 = BalanceDTO.builder().currency(BTC).total(new BigDecimal("1")).available(new BigDecimal("1")).frozen(new BigDecimal("1")).loaned(new BigDecimal("1")).borrowed(new BigDecimal("11")).withdrawing(new BigDecimal("1")).depositing(new BigDecimal("1")).build();
BalanceDTO account4Balance2 = BalanceDTO.builder().currency(ETH).total(new BigDecimal("2")).available(new BigDecimal("2")).frozen(new BigDecimal("2")).loaned(new BigDecimal("2")).borrowed(new BigDecimal("2")).withdrawing(new BigDecimal("2")).depositing(new BigDecimal("2")).build();
balances.add(account4Balance2);
balances.add(account4Balance1);
AccountDTO account4 = AccountDTO.builder().balances(balances).build();
balances.clear();
assertNotEquals(account1, account4);
assertNotEquals(account4, account1);
// Account 5 - currency changed.
BalanceDTO account5Balance1 = BalanceDTO.builder().currency(USDT).total(new BigDecimal("1")).available(new BigDecimal("1")).frozen(new BigDecimal("1")).loaned(new BigDecimal("1")).borrowed(new BigDecimal("1")).withdrawing(new BigDecimal("1")).depositing(new BigDecimal("1")).build();
BalanceDTO account5Balance2 = BalanceDTO.builder().currency(ETH).total(new BigDecimal("2")).available(new BigDecimal("2")).frozen(new BigDecimal("2")).loaned(new BigDecimal("2")).borrowed(new BigDecimal("2")).withdrawing(new BigDecimal("2")).depositing(new BigDecimal("2")).build();
balances.add(account5Balance2);
balances.add(account5Balance1);
AccountDTO account5 = AccountDTO.builder().balances(balances).build();
balances.clear();
assertNotEquals(account1, account5);
assertNotEquals(account5, account1);
// Account 6 - depositing changed.
BalanceDTO account6Balance1 = BalanceDTO.builder().currency(BTC).total(new BigDecimal("1")).available(new BigDecimal("1")).frozen(new BigDecimal("1")).loaned(new BigDecimal("1")).borrowed(new BigDecimal("1")).withdrawing(new BigDecimal("1")).depositing(new BigDecimal("11")).build();
BalanceDTO account6Balance2 = BalanceDTO.builder().currency(ETH).total(new BigDecimal("2")).available(new BigDecimal("2")).frozen(new BigDecimal("2")).loaned(new BigDecimal("2")).borrowed(new BigDecimal("2")).withdrawing(new BigDecimal("2")).depositing(new BigDecimal("2")).build();
balances.add(account6Balance2);
balances.add(account6Balance1);
AccountDTO account6 = AccountDTO.builder().balances(balances).build();
balances.clear();
assertNotEquals(account1, account6);
assertNotEquals(account6, account1);
// Account 7 - frozen changed.
BalanceDTO account7Balance1 = BalanceDTO.builder().currency(BTC).total(new BigDecimal("1")).available(new BigDecimal("1")).frozen(new BigDecimal("11")).loaned(new BigDecimal("1")).borrowed(new BigDecimal("1")).withdrawing(new BigDecimal("1")).depositing(new BigDecimal("1")).build();
BalanceDTO account7Balance2 = BalanceDTO.builder().currency(ETH).total(new BigDecimal("2")).available(new BigDecimal("2")).frozen(new BigDecimal("2")).loaned(new BigDecimal("2")).borrowed(new BigDecimal("2")).withdrawing(new BigDecimal("2")).depositing(new BigDecimal("2")).build();
balances.add(account7Balance2);
balances.add(account7Balance1);
AccountDTO account7 = AccountDTO.builder().balances(balances).build();
balances.clear();
assertNotEquals(account1, account7);
assertNotEquals(account7, account1);
// Account 8 - loaned changed.
BalanceDTO account8Balance1 = BalanceDTO.builder().currency(BTC).total(new BigDecimal("1")).available(new BigDecimal("1")).frozen(new BigDecimal("1")).loaned(new BigDecimal("11")).borrowed(new BigDecimal("1")).withdrawing(new BigDecimal("1")).depositing(new BigDecimal("1")).build();
BalanceDTO account8Balance2 = BalanceDTO.builder().currency(ETH).total(new BigDecimal("2")).available(new BigDecimal("2")).frozen(new BigDecimal("2")).loaned(new BigDecimal("2")).borrowed(new BigDecimal("2")).withdrawing(new BigDecimal("2")).depositing(new BigDecimal("2")).build();
balances.add(account8Balance2);
balances.add(account8Balance1);
AccountDTO account8 = AccountDTO.builder().balances(balances).build();
balances.clear();
assertNotEquals(account1, account8);
assertNotEquals(account8, account1);
// Account 9 - total changed.
BalanceDTO account9Balance1 = BalanceDTO.builder().currency(BTC).total(new BigDecimal("11")).available(new BigDecimal("1")).frozen(new BigDecimal("11")).loaned(new BigDecimal("1")).borrowed(new BigDecimal("1")).withdrawing(new BigDecimal("1")).depositing(new BigDecimal("1")).build();
BalanceDTO account9Balance2 = BalanceDTO.builder().currency(ETH).total(new BigDecimal("2")).available(new BigDecimal("2")).frozen(new BigDecimal("2")).loaned(new BigDecimal("2")).borrowed(new BigDecimal("2")).withdrawing(new BigDecimal("2")).depositing(new BigDecimal("2")).build();
balances.add(account9Balance1);
balances.add(account9Balance2);
AccountDTO account9 = AccountDTO.builder().balances(balances).build();
balances.clear();
assertNotEquals(account1, account9);
assertNotEquals(account9, account1);
// Account 10 - withdrawing changed.
BalanceDTO account10Balance1 = BalanceDTO.builder().currency(BTC).total(new BigDecimal("1")).available(new BigDecimal("1")).frozen(new BigDecimal("1")).loaned(new BigDecimal("1")).borrowed(new BigDecimal("1")).withdrawing(new BigDecimal("11")).depositing(new BigDecimal("1")).build();
BalanceDTO account10Balance2 = BalanceDTO.builder().currency(ETH).total(new BigDecimal("2")).available(new BigDecimal("2")).frozen(new BigDecimal("2")).loaned(new BigDecimal("2")).borrowed(new BigDecimal("2")).withdrawing(new BigDecimal("2")).depositing(new BigDecimal("2")).build();
balances.add(account10Balance1);
balances.add(account10Balance2);
AccountDTO account10 = AccountDTO.builder().balances(balances).build();
balances.clear();
assertNotEquals(account1, account10);
assertNotEquals(account10, account1);
}
use of tech.cassandre.trading.bot.dto.user.AccountDTO in project cassandre-trading-bot by cassandre-tech.
the class AccountFluxTest method checkReceivedData.
@Test
@DisplayName("Check received data")
public void checkReceivedData() {
// The mock has 7 replies configured - The first reply is used by configuration class.
final int numberOfRepliesExpected = 7;
// Waiting for the service to have been called 7 times.
await().untilAsserted(() -> verify(accountService, atLeast(numberOfRepliesExpected)).getAccountInfo());
// Waiting for the strategy to have received all the test values.
await().untilAsserted(() -> assertEquals(numberOfRepliesExpected, strategy.getAccountsUpdatesReceived().size()));
// =============================================================================================================
// Test all values received by the strategy with update methods.
final Iterator<AccountDTO> iterator = strategy.getAccountsUpdatesReceived().iterator();
// Check update 1.
AccountDTO a = iterator.next();
assertEquals("01", a.getAccountId());
assertEquals("Account 01", a.getName());
assertEquals(2, a.getBalances().size());
final Optional<BalanceDTO> update1BTCBalance = a.getBalance(BTC);
assertTrue(update1BTCBalance.isPresent());
assertEquals(BTC, update1BTCBalance.get().getCurrency());
assertEquals(0, 0, update1BTCBalance.get().getTotal().compareTo(new BigDecimal("1")));
assertEquals(0, 0, update1BTCBalance.get().getAvailable().compareTo(new BigDecimal("1")));
assertEquals(0, 0, update1BTCBalance.get().getFrozen().compareTo(new BigDecimal("1")));
assertEquals(0, 0, update1BTCBalance.get().getLoaned().compareTo(new BigDecimal("1")));
assertEquals(0, 0, update1BTCBalance.get().getBorrowed().compareTo(new BigDecimal("1")));
assertEquals(0, 0, update1BTCBalance.get().getWithdrawing().compareTo(new BigDecimal("1")));
assertEquals(0, 0, update1BTCBalance.get().getDepositing().compareTo(new BigDecimal("1")));
final Optional<BalanceDTO> update1ETHBalance = a.getBalance(ETH);
assertTrue(update1ETHBalance.isPresent());
assertEquals(ETH, update1ETHBalance.get().getCurrency());
assertEquals(0, 0, update1ETHBalance.get().getTotal().compareTo(new BigDecimal("2")));
assertEquals(0, 0, update1ETHBalance.get().getAvailable().compareTo(new BigDecimal("2")));
assertEquals(0, 0, update1ETHBalance.get().getFrozen().compareTo(new BigDecimal("2")));
assertEquals(0, 0, update1ETHBalance.get().getLoaned().compareTo(new BigDecimal("2")));
assertEquals(0, 0, update1ETHBalance.get().getBorrowed().compareTo(new BigDecimal("2")));
assertEquals(0, 0, update1ETHBalance.get().getWithdrawing().compareTo(new BigDecimal("2")));
assertEquals(0, 0, update1ETHBalance.get().getDepositing().compareTo(new BigDecimal("2")));
// Check update 2.
a = iterator.next();
assertEquals("02", a.getAccountId());
assertEquals("Account 02", a.getName());
assertEquals(1, a.getBalances().size());
final Optional<BalanceDTO> update2BTCBalance = a.getBalance(BTC);
assertTrue(update2BTCBalance.isPresent());
assertEquals(BTC, update2BTCBalance.get().getCurrency());
assertEquals(0, 0, update2BTCBalance.get().getTotal().compareTo(new BigDecimal("1")));
assertEquals(0, 0, update2BTCBalance.get().getAvailable().compareTo(new BigDecimal("1")));
assertEquals(0, 0, update2BTCBalance.get().getFrozen().compareTo(new BigDecimal("1")));
assertEquals(0, 0, update2BTCBalance.get().getLoaned().compareTo(new BigDecimal("1")));
assertEquals(0, 0, update2BTCBalance.get().getBorrowed().compareTo(new BigDecimal("1")));
assertEquals(0, 0, update2BTCBalance.get().getWithdrawing().compareTo(new BigDecimal("1")));
assertEquals(0, 0, update2BTCBalance.get().getDepositing().compareTo(new BigDecimal("1")));
// Check update 3.
a = iterator.next();
assertEquals("01", a.getAccountId());
assertEquals("Account 01", a.getName());
assertEquals(3, a.getBalances().size());
final Optional<BalanceDTO> update3BTCBalance = a.getBalance(BTC);
assertTrue(update3BTCBalance.isPresent());
assertEquals(BTC, update3BTCBalance.get().getCurrency());
assertEquals(0, 0, update3BTCBalance.get().getTotal().compareTo(new BigDecimal("1")));
assertEquals(0, 0, update3BTCBalance.get().getAvailable().compareTo(new BigDecimal("1")));
assertEquals(0, 0, update3BTCBalance.get().getFrozen().compareTo(new BigDecimal("1")));
assertEquals(0, 0, update3BTCBalance.get().getLoaned().compareTo(new BigDecimal("1")));
assertEquals(0, 0, update3BTCBalance.get().getBorrowed().compareTo(new BigDecimal("1")));
assertEquals(0, 0, update3BTCBalance.get().getWithdrawing().compareTo(new BigDecimal("1")));
assertEquals(0, 0, update3BTCBalance.get().getDepositing().compareTo(new BigDecimal("1")));
final Optional<BalanceDTO> update3ETHBalance = a.getBalance(ETH);
assertTrue(update3ETHBalance.isPresent());
assertEquals(ETH, update3ETHBalance.get().getCurrency());
assertEquals(0, 0, update3ETHBalance.get().getTotal().compareTo(new BigDecimal("2")));
assertEquals(0, 0, update3ETHBalance.get().getAvailable().compareTo(new BigDecimal("2")));
assertEquals(0, 0, update3ETHBalance.get().getFrozen().compareTo(new BigDecimal("2")));
assertEquals(0, 0, update3ETHBalance.get().getLoaned().compareTo(new BigDecimal("2")));
assertEquals(0, 0, update3ETHBalance.get().getBorrowed().compareTo(new BigDecimal("2")));
assertEquals(0, 0, update3ETHBalance.get().getWithdrawing().compareTo(new BigDecimal("2")));
assertEquals(0, 0, update3ETHBalance.get().getDepositing().compareTo(new BigDecimal("2")));
final Optional<BalanceDTO> update3USDTBalance = a.getBalance(USDT);
assertTrue(update3USDTBalance.isPresent());
assertEquals(USDT, update3USDTBalance.get().getCurrency());
assertEquals(0, 0, update3USDTBalance.get().getTotal().compareTo(new BigDecimal("2")));
assertEquals(0, 0, update3USDTBalance.get().getAvailable().compareTo(new BigDecimal("2")));
assertEquals(0, 0, update3USDTBalance.get().getFrozen().compareTo(new BigDecimal("2")));
assertEquals(0, 0, update3USDTBalance.get().getLoaned().compareTo(new BigDecimal("2")));
assertEquals(0, 0, update3USDTBalance.get().getBorrowed().compareTo(new BigDecimal("2")));
assertEquals(0, 0, update3USDTBalance.get().getWithdrawing().compareTo(new BigDecimal("2")));
assertEquals(0, 0, update3USDTBalance.get().getDepositing().compareTo(new BigDecimal("2")));
// Check update 4 - ETH balance of account 01 changed (borrowed value).
a = iterator.next();
assertEquals("01", a.getAccountId());
assertEquals("Account 01", a.getName());
final Optional<BalanceDTO> update4BTCBalance = a.getBalance(BTC);
assertTrue(update4BTCBalance.isPresent());
assertEquals(BTC, update4BTCBalance.get().getCurrency());
assertEquals(0, 0, update4BTCBalance.get().getTotal().compareTo(new BigDecimal("1")));
assertEquals(0, 0, update4BTCBalance.get().getAvailable().compareTo(new BigDecimal("1")));
assertEquals(0, 0, update4BTCBalance.get().getFrozen().compareTo(new BigDecimal("1")));
assertEquals(0, 0, update4BTCBalance.get().getLoaned().compareTo(new BigDecimal("1")));
assertEquals(0, 0, update4BTCBalance.get().getBorrowed().compareTo(new BigDecimal("1")));
assertEquals(0, 0, update4BTCBalance.get().getWithdrawing().compareTo(new BigDecimal("1")));
assertEquals(0, 0, update4BTCBalance.get().getDepositing().compareTo(new BigDecimal("1")));
final Optional<BalanceDTO> update4ETHBalance = a.getBalance(ETH);
assertTrue(update4ETHBalance.isPresent());
assertEquals(ETH, update4ETHBalance.get().getCurrency());
assertEquals(0, 0, update4ETHBalance.get().getTotal().compareTo(new BigDecimal("2")));
assertEquals(0, 0, update4ETHBalance.get().getAvailable().compareTo(new BigDecimal("2")));
assertEquals(0, 0, update4ETHBalance.get().getFrozen().compareTo(new BigDecimal("2")));
assertEquals(0, 0, update4ETHBalance.get().getLoaned().compareTo(new BigDecimal("2")));
assertEquals(0, 0, update4ETHBalance.get().getBorrowed().compareTo(new BigDecimal("5")));
assertEquals(0, 0, update4ETHBalance.get().getWithdrawing().compareTo(new BigDecimal("2")));
assertEquals(0, 0, update4ETHBalance.get().getDepositing().compareTo(new BigDecimal("2")));
final Optional<BalanceDTO> update4USDTBalance = a.getBalance(USDT);
assertTrue(update4USDTBalance.isPresent());
assertEquals(USDT, update4USDTBalance.get().getCurrency());
assertEquals(0, 0, update4USDTBalance.get().getTotal().compareTo(new BigDecimal("2")));
assertEquals(0, 0, update4USDTBalance.get().getAvailable().compareTo(new BigDecimal("2")));
assertEquals(0, 0, update4USDTBalance.get().getFrozen().compareTo(new BigDecimal("2")));
assertEquals(0, 0, update4USDTBalance.get().getLoaned().compareTo(new BigDecimal("2")));
assertEquals(0, 0, update4USDTBalance.get().getBorrowed().compareTo(new BigDecimal("2")));
assertEquals(0, 0, update4USDTBalance.get().getWithdrawing().compareTo(new BigDecimal("2")));
assertEquals(0, 0, update4USDTBalance.get().getDepositing().compareTo(new BigDecimal("2")));
// Check update 5 - BTC balance of account 02 changed (all values).
a = iterator.next();
assertEquals("02", a.getAccountId());
assertEquals("Account 02", a.getName());
final Optional<BalanceDTO> update5BTCBalance = a.getBalance(BTC);
assertTrue(update5BTCBalance.isPresent());
assertEquals(BTC, update5BTCBalance.get().getCurrency());
assertEquals(0, 0, update5BTCBalance.get().getTotal().compareTo(new BigDecimal("1")));
assertEquals(0, 0, update5BTCBalance.get().getAvailable().compareTo(new BigDecimal("1")));
assertEquals(0, 0, update5BTCBalance.get().getFrozen().compareTo(new BigDecimal("1")));
assertEquals(0, 0, update5BTCBalance.get().getLoaned().compareTo(new BigDecimal("1")));
assertEquals(0, 0, update5BTCBalance.get().getBorrowed().compareTo(new BigDecimal("1")));
assertEquals(0, 0, update5BTCBalance.get().getWithdrawing().compareTo(new BigDecimal("1")));
assertEquals(0, 0, update5BTCBalance.get().getDepositing().compareTo(new BigDecimal("1")));
// Check update 6 - ETH balance removed on account 01.
a = iterator.next();
assertEquals("01", a.getAccountId());
assertEquals("Account 01", a.getName());
assertEquals(2, a.getBalances().size());
final Optional<BalanceDTO> update6BTCBalance = a.getBalance(BTC);
assertTrue(update6BTCBalance.isPresent());
assertEquals(BTC, update6BTCBalance.get().getCurrency());
assertEquals(0, 0, update6BTCBalance.get().getTotal().compareTo(new BigDecimal("1")));
assertEquals(0, 0, update6BTCBalance.get().getAvailable().compareTo(new BigDecimal("1")));
assertEquals(0, 0, update6BTCBalance.get().getFrozen().compareTo(new BigDecimal("1")));
assertEquals(0, 0, update6BTCBalance.get().getLoaned().compareTo(new BigDecimal("1")));
assertEquals(0, 0, update6BTCBalance.get().getBorrowed().compareTo(new BigDecimal("1")));
assertEquals(0, 0, update6BTCBalance.get().getWithdrawing().compareTo(new BigDecimal("1")));
assertEquals(0, 0, update6BTCBalance.get().getDepositing().compareTo(new BigDecimal("1")));
final Optional<BalanceDTO> update6ETHBalance = a.getBalance(ETH);
assertFalse(update6ETHBalance.isPresent());
final Optional<BalanceDTO> update6USDTBalance = a.getBalance(USDT);
assertTrue(update6USDTBalance.isPresent());
assertEquals(USDT, update6USDTBalance.get().getCurrency());
assertEquals(0, 0, update6USDTBalance.get().getTotal().compareTo(new BigDecimal("2")));
assertEquals(0, 0, update6USDTBalance.get().getAvailable().compareTo(new BigDecimal("2")));
assertEquals(0, 0, update6USDTBalance.get().getFrozen().compareTo(new BigDecimal("2")));
assertEquals(0, 0, update6USDTBalance.get().getLoaned().compareTo(new BigDecimal("2")));
assertEquals(0, 0, update6USDTBalance.get().getBorrowed().compareTo(new BigDecimal("2")));
assertEquals(0, 0, update6USDTBalance.get().getWithdrawing().compareTo(new BigDecimal("2")));
assertEquals(0, 0, update6USDTBalance.get().getDepositing().compareTo(new BigDecimal("2")));
// Check update 7 - New account 03.
a = iterator.next();
assertEquals("03", a.getAccountId());
assertEquals("Account 03", a.getName());
assertEquals(1, a.getBalances().size());
final Optional<BalanceDTO> update7BTCBalance = a.getBalance(BTC);
assertTrue(update7BTCBalance.isPresent());
assertEquals(BTC, update7BTCBalance.get().getCurrency());
assertEquals(0, 0, update7BTCBalance.get().getTotal().compareTo(new BigDecimal("11")));
assertEquals(0, 0, update7BTCBalance.get().getAvailable().compareTo(new BigDecimal("12")));
assertEquals(0, 0, update7BTCBalance.get().getFrozen().compareTo(new BigDecimal("13")));
assertEquals(0, 0, update7BTCBalance.get().getLoaned().compareTo(new BigDecimal("15")));
assertEquals(0, 0, update7BTCBalance.get().getBorrowed().compareTo(new BigDecimal("14")));
assertEquals(0, 0, update7BTCBalance.get().getWithdrawing().compareTo(new BigDecimal("16")));
assertEquals(0, 0, update7BTCBalance.get().getDepositing().compareTo(new BigDecimal("17")));
// =============================================================================================================
// Check data we have in strategy.
final Map<String, AccountDTO> strategyAccounts = strategy.getAccounts();
assertEquals(4, strategyAccounts.size());
// First reply of the mock when Cassandre starts.
assertNotNull(strategyAccounts.get("trade"));
assertNotNull(strategyAccounts.get("01"));
assertNotNull(strategyAccounts.get("02"));
assertNotNull(strategyAccounts.get("03"));
// Check account 01.
Optional<AccountDTO> a1 = strategy.getAccountByAccountId("01");
assertTrue(a1.isPresent());
assertEquals("01", a1.get().getAccountId());
assertEquals("Account 01", a1.get().getName());
assertEquals(2, a1.get().getBalances().size());
final Optional<BalanceDTO> account01BTCBalance = a1.get().getBalance(BTC);
assertTrue(account01BTCBalance.isPresent());
assertEquals(BTC, account01BTCBalance.get().getCurrency());
assertEquals(0, 0, account01BTCBalance.get().getTotal().compareTo(new BigDecimal("1")));
assertEquals(0, 0, account01BTCBalance.get().getAvailable().compareTo(new BigDecimal("1")));
assertEquals(0, 0, account01BTCBalance.get().getFrozen().compareTo(new BigDecimal("1")));
assertEquals(0, 0, account01BTCBalance.get().getLoaned().compareTo(new BigDecimal("1")));
assertEquals(0, 0, account01BTCBalance.get().getBorrowed().compareTo(new BigDecimal("1")));
assertEquals(0, 0, account01BTCBalance.get().getWithdrawing().compareTo(new BigDecimal("1")));
assertEquals(0, 0, account01BTCBalance.get().getDepositing().compareTo(new BigDecimal("1")));
final Optional<BalanceDTO> account01ETHBalance = a1.get().getBalance(ETH);
assertFalse(account01ETHBalance.isPresent());
final Optional<BalanceDTO> account01USDTBalance = a1.get().getBalance(USDT);
assertTrue(account01USDTBalance.isPresent());
assertEquals(USDT, account01USDTBalance.get().getCurrency());
assertEquals(0, 0, account01USDTBalance.get().getTotal().compareTo(new BigDecimal("2")));
assertEquals(0, 0, account01USDTBalance.get().getAvailable().compareTo(new BigDecimal("2")));
assertEquals(0, 0, account01USDTBalance.get().getFrozen().compareTo(new BigDecimal("2")));
assertEquals(0, 0, account01USDTBalance.get().getLoaned().compareTo(new BigDecimal("2")));
assertEquals(0, 0, account01USDTBalance.get().getBorrowed().compareTo(new BigDecimal("2")));
assertEquals(0, 0, account01USDTBalance.get().getWithdrawing().compareTo(new BigDecimal("2")));
assertEquals(0, 0, account01USDTBalance.get().getDepositing().compareTo(new BigDecimal("2")));
// Check account 02.
Optional<AccountDTO> a2 = strategy.getAccountByAccountId("02");
assertTrue(a2.isPresent());
assertEquals("02", a2.get().getAccountId());
assertEquals("Account 02", a2.get().getName());
assertEquals(1, a2.get().getBalances().size());
final Optional<BalanceDTO> account02BTCBalance = a2.get().getBalance(BTC);
assertTrue(account02BTCBalance.isPresent());
assertEquals(BTC, account02BTCBalance.get().getCurrency());
assertEquals(0, 0, account02BTCBalance.get().getTotal().compareTo(new BigDecimal("1")));
assertEquals(0, 0, account02BTCBalance.get().getAvailable().compareTo(new BigDecimal("1")));
assertEquals(0, 0, account02BTCBalance.get().getFrozen().compareTo(new BigDecimal("1")));
assertEquals(0, 0, account02BTCBalance.get().getLoaned().compareTo(new BigDecimal("1")));
assertEquals(0, 0, account02BTCBalance.get().getBorrowed().compareTo(new BigDecimal("1")));
assertEquals(0, 0, account02BTCBalance.get().getWithdrawing().compareTo(new BigDecimal("1")));
assertEquals(0, 0, account02BTCBalance.get().getDepositing().compareTo(new BigDecimal("1")));
// Check account 03.
Optional<AccountDTO> a3 = strategy.getAccountByAccountId("03");
assertTrue(a3.isPresent());
assertEquals("03", a3.get().getAccountId());
assertEquals("Account 03", a3.get().getName());
assertEquals(1, a3.get().getBalances().size());
final Optional<BalanceDTO> account03BTCBalance = a3.get().getBalance(BTC);
assertTrue(account03BTCBalance.isPresent());
assertEquals(BTC, account03BTCBalance.get().getCurrency());
assertEquals(0, 0, account03BTCBalance.get().getTotal().compareTo(new BigDecimal("11")));
assertEquals(0, 0, account03BTCBalance.get().getAvailable().compareTo(new BigDecimal("12")));
assertEquals(0, 0, account03BTCBalance.get().getFrozen().compareTo(new BigDecimal("13")));
assertEquals(0, 0, account03BTCBalance.get().getLoaned().compareTo(new BigDecimal("15")));
assertEquals(0, 0, account03BTCBalance.get().getBorrowed().compareTo(new BigDecimal("14")));
assertEquals(0, 0, account03BTCBalance.get().getWithdrawing().compareTo(new BigDecimal("16")));
assertEquals(0, 0, account03BTCBalance.get().getDepositing().compareTo(new BigDecimal("17")));
}
use of tech.cassandre.trading.bot.dto.user.AccountDTO in project cassandre-trading-bot by cassandre-tech.
the class UserServiceXChangeImplementation method getUser.
@Override
@SuppressWarnings("checkstyle:DesignForExtension")
public Optional<UserDTO> getUser() {
try {
// Consume a token from the token bucket.
// If a token is not available this method will block until the refill adds one to the bucket.
bucket.asBlocking().consume(1);
logger.debug("Retrieving account information");
final UserDTO user = ACCOUNT_MAPPER.mapToUserDTO(xChangeAccountService.getAccountInfo());
logger.debug("Account information retrieved " + user);
// Update the cached reply.
if (user != null && user.getAccounts() != null) {
user.getAccounts().values().stream().filter(accountDTO -> accountDTO.getAccountId() != null).forEach(accountDTO -> cachedReply.put(accountDTO.getAccountId(), accountDTO));
}
return Optional.ofNullable(user);
} catch (IOException e) {
logger.error("Error retrieving account information: {}", e.getMessage());
return Optional.empty();
} catch (InterruptedException e) {
return Optional.empty();
}
}
use of tech.cassandre.trading.bot.dto.user.AccountDTO in project cassandre-trading-bot by cassandre-tech.
the class TradeServiceDryModeAOP method createSellMarketOrder.
@Around(value = "execution(* tech.cassandre.trading.bot.service.TradeService.createSellMarketOrder(..)) && args(strategy, currencyPair, amount)", argNames = "pjp, strategy, currencyPair, amount")
public final OrderCreationResultDTO createSellMarketOrder(final ProceedingJoinPoint pjp, final CassandreStrategy strategy, final CurrencyPairDTO currencyPair, final BigDecimal amount) {
// We check that we have the trade account.
final Optional<AccountDTO> tradeAccount = strategy.getTradeAccount();
if (tradeAccount.isEmpty()) {
throw new DryModeException("Trade account was not found");
}
// Selling order - we sell ETH to buy BTC.
// We are selling the amount
Optional<BalanceDTO> balance = tradeAccount.get().getBalance(currencyPair.getBaseCurrency());
final Optional<TickerDTO> ticker = strategy.getLastTickerByCurrencyPair(currencyPair);
if (balance.isPresent() && ticker.isPresent()) {
BigDecimal ownedAssets = balance.get().getAvailable();
if (amount.compareTo(ownedAssets) > 0) {
final String errorMessage = "Not enough assets (amount: " + amount + " " + currencyPair.getQuoteCurrency() + " - owned assets: " + ownedAssets + " " + currencyPair.getBaseCurrency();
return new OrderCreationResultDTO(errorMessage, new RuntimeException());
}
} else {
return new OrderCreationResultDTO("No assets (" + currencyPair.getBaseCurrency() + ")", new RuntimeException());
}
// We execute the sell.
Object result = null;
try {
result = pjp.proceed();
} catch (Throwable throwable) {
logger.error("Error in Dry mode AOP: {}", throwable.getMessage());
}
// We update the account.
userService.addToBalance(strategy, CURRENCY_MAPPER.mapToCurrency(currencyPair.getBaseCurrency()), amount.multiply(new BigDecimal("-1")));
userService.addToBalance(strategy, CURRENCY_MAPPER.mapToCurrency(currencyPair.getQuoteCurrency()), amount.multiply(ticker.get().getLast()));
return (OrderCreationResultDTO) result;
}
Aggregations