use of tech.cassandre.trading.bot.dto.util.CurrencyDTO.BTC in project cassandre-trading-bot by cassandre-tech.
the class MarketServiceTest method checkGetTicker.
@Test
@Tag("integration")
@DisplayName("Check get ticker")
public void checkGetTicker() {
CurrencyPairDTO cp = new CurrencyPairDTO(ETH, BTC);
Set<TickerDTO> tickers = marketService.getTickers(Collections.singleton(cp));
final Optional<TickerDTO> t = tickers.stream().filter(tickerDTO -> tickerDTO.getCurrencyPair().equals(cp)).findFirst();
assertTrue(t.isPresent());
// currencyPair.
assertNotNull(t.get().getCurrencyPair());
assertEquals(t.get().getCurrencyPair(), cp);
// open.
assertNull(t.get().getOpen());
// last.
assertNotNull(t.get().getLast());
assertTrue(t.get().getLast().compareTo(ZERO) >= 0);
// bid.
// assertNotNull(t.get().getBid());
// assertTrue(t.get().getBid().compareTo(ZERO) > 0);
// ask.
// assertNotNull(t.get().getAsk());
// assertTrue(t.get().getAsk().compareTo(ZERO) > 0);
// volume.
assertNotNull(t.get().getVolume());
// assertTrue(t.get().getVolume().compareTo(ZERO) > 0);
// quote volume.
assertNotNull(t.get().getQuoteVolume());
// assertTrue(t.get().getQuoteVolume().compareTo(ZERO) > 0);
// bidSize.
assertNull(t.get().getBidSize());
// askSize.
assertNull(t.get().getAskSize());
// timestamp.
assertNotNull(t.get().getTimestamp());
assertTrue(t.get().getTimestamp().isAfter(ZonedDateTime.now().minusMinutes(1)));
assertTrue(t.get().getTimestamp().isBefore(ZonedDateTime.now().plusMinutes(1)));
}
use of tech.cassandre.trading.bot.dto.util.CurrencyDTO.BTC in project cassandre-trading-bot by cassandre-tech.
the class TradeServiceTest method checkGetTrades.
@Test
@Tag("integration")
@DisplayName("Check get trades")
public void checkGetTrades() {
final CurrencyPairDTO cp = new CurrencyPairDTO(BTC, USD);
// Creates two orders of the same amount (one buy, one sell).
final OrderCreationResultDTO result1 = strategy.createBuyMarketOrder(cp, new BigDecimal("0.1"));
final OrderCreationResultDTO result2 = strategy.createSellMarketOrder(cp, new BigDecimal("0.1"));
// Check that the two orders appears in the trade history.
assertTrue(result1.isSuccessful());
assertTrue(result2.isSuccessful());
await().untilAsserted(() -> assertTrue(tradeService.getTrades().stream().anyMatch(t -> t.getOrderId().equals(result1.getOrder().getOrderId()))));
await().untilAsserted(() -> assertTrue(tradeService.getTrades().stream().anyMatch(t -> t.getOrderId().equals(result2.getOrder().getOrderId()))));
// Retrieve trade & test values.
final Optional<TradeDTO> t = tradeService.getTrades().stream().filter(trade -> trade.getOrderId().equals(result1.getOrder().getOrderId())).findFirst();
assertTrue(t.isPresent());
assertNull(t.get().getId());
assertNotNull(t.get().getTradeId());
assertEquals(BID, t.get().getType());
assertEquals(result1.getOrderId(), t.get().getOrderId());
assertEquals(cp, t.get().getCurrencyPair());
assertNotNull(t.get().getAmount().getValue());
assertEquals(BTC, t.get().getAmount().getCurrency());
assertNotNull(t.get().getPrice().getValue());
assertNotNull(t.get().getFee().getValue());
assertNotNull(t.get().getFee().getCurrency());
assertTrue(t.get().getTimestamp().isAfter(ZonedDateTime.now().minusMinutes(1)));
assertTrue(t.get().getTimestamp().isBefore(ZonedDateTime.now().plusMinutes(1)));
}
use of tech.cassandre.trading.bot.dto.util.CurrencyDTO.BTC in project cassandre-trading-bot by cassandre-tech.
the class TradeServiceTest method checkGetTrades.
@Test
@Tag("integration")
@DisplayName("Check get trades")
@Disabled("Gemini doesn't support market order")
public void checkGetTrades() {
final CurrencyPairDTO cp = new CurrencyPairDTO(ETH, BTC);
// Creates two orders of the same amount (one buy, one sell).
final OrderCreationResultDTO result1 = strategy.createBuyMarketOrder(cp, new BigDecimal("0.0001"));
final OrderCreationResultDTO result2 = strategy.createSellMarketOrder(cp, new BigDecimal("0.0001"));
// Check that the two orders appears in the trade history.
assertTrue(result1.isSuccessful());
await().untilAsserted(() -> assertTrue(tradeService.getTrades().stream().anyMatch(t -> t.getOrderId().equals(result1.getOrder().getOrderId()))));
assertNotNull(result2.getOrder().getOrderId());
await().untilAsserted(() -> assertTrue(tradeService.getTrades().stream().anyMatch(t -> t.getOrderId().equals(result2.getOrder().getOrderId()))));
// Retrieve trade & test values.
final Optional<TradeDTO> t = tradeService.getTrades().stream().filter(trade -> trade.getOrderId().equals(result1.getOrder().getOrderId())).findFirst();
assertTrue(t.isPresent());
assertNull(t.get().getId());
assertNotNull(t.get().getTradeId());
assertEquals(BID, t.get().getType());
assertEquals(result1.getOrderId(), t.get().getOrderId());
assertEquals(cp, t.get().getCurrencyPair());
assertNotNull(t.get().getAmount().getValue());
assertEquals(ETH, t.get().getAmount().getCurrency());
assertNotNull(t.get().getPrice().getValue());
assertEquals(BTC, t.get().getAmount().getCurrency());
assertNotNull(t.get().getFee().getValue());
assertNotNull(t.get().getFee().getCurrency());
assertTrue(t.get().getTimestamp().isAfter(ZonedDateTime.now().minusMinutes(1)));
assertTrue(t.get().getTimestamp().isBefore(ZonedDateTime.now().plusMinutes(1)));
}
use of tech.cassandre.trading.bot.dto.util.CurrencyDTO.BTC in project cassandre-trading-bot by cassandre-tech.
the class TradeServiceTest method checkCreateBuyLimitOrder.
@Test
@Tag("integration")
@DisplayName("Check creates a buy limit order")
public void checkCreateBuyLimitOrder() {
final CurrencyPairDTO cp = new CurrencyPairDTO(ETH, BTC);
// =============================================================================================================
// Making a buy limit order (Buy 0.0001 ETH).
final OrderCreationResultDTO result1 = strategy.createBuyLimitOrder(cp, new BigDecimal("0.0001"), new BigDecimal("0.1"));
assertTrue(result1.isSuccessful());
assertNull(result1.getErrorMessage());
assertNull(result1.getException());
assertNotNull(result1.getOrder().getOrderId());
// =============================================================================================================
// Getting a non-existing order.
assertFalse(tradeService.getOrders().stream().anyMatch(o -> o.getOrderId().equals("")));
// =============================================================================================================
// Getting the order and testing the data.
final Optional<OrderDTO> order1 = tradeService.getOrders().stream().filter(o -> o.getOrderId().equals(result1.getOrder().getOrderId())).findFirst();
assertTrue(order1.isPresent());
assertNotNull(order1.get().getOrderId());
assertEquals(result1.getOrder().getOrderId(), order1.get().getOrderId());
assertEquals(BID, order1.get().getType());
assertEquals(cp, order1.get().getCurrencyPair());
assertEquals(0, order1.get().getAmount().getValue().compareTo(new BigDecimal("0.0001")));
assertEquals(cp.getBaseCurrency(), order1.get().getAmount().getCurrency());
assertEquals(0, order1.get().getLimitPrice().getValue().compareTo(new BigDecimal("0.000001")));
assertEquals(cp.getQuoteCurrency(), order1.get().getLimitPrice().getCurrency());
assertNull(order1.get().getLeverage());
assertNull(order1.get().getUserReference());
assertNotNull(order1.get().getTimestamp());
assertTrue(order1.get().getTimestamp().isAfter(ZonedDateTime.now().minusMinutes(1)));
assertTrue(order1.get().getTimestamp().isBefore(ZonedDateTime.now().plusMinutes(1)));
// Cancel the order.
tradeService.cancelOrder(result1.getOrder().getOrderId());
}
use of tech.cassandre.trading.bot.dto.util.CurrencyDTO.BTC in project cassandre-trading-bot by cassandre-tech.
the class AccountDataFetcherTest method accountByAccountId.
@Test
@DisplayName("accountByAccountId(accountId: String): Account")
void accountByAccountId() {
// Query and fields definition.
GraphQLQueryRequest graphQLQueryRequest = new GraphQLQueryRequest(new AccountByAccountIdGraphQLQuery.Builder().accountId("trade").build(), new AccountByAccountIdProjectionRoot().accountId().name().balances().currency().code().getParent().total().available().frozen().loaned().borrowed().withdrawing().depositing());
// Query execution.
Account account = dgsQueryExecutor.executeAndExtractJsonPathAsObject(graphQLQueryRequest.serialize(), "data." + DgsConstants.QUERY.AccountByAccountId, new TypeRef<>() {
});
// Tests
assertNotNull(account);
assertEquals("trade", account.getAccountId());
assertEquals("trade account name", account.getName());
assertEquals(2, account.getBalances().size());
// Testing BTC balance.
final Optional<Balance> btcBalance = account.getBalances().stream().filter(balance -> balance.getCurrency().equals(BTC)).findAny();
assertTrue(btcBalance.isPresent());
assertEquals(BTC, btcBalance.get().getCurrency());
assertEquals(0, new BigDecimal("1").compareTo(btcBalance.get().getTotal()));
assertEquals(0, new BigDecimal("2").compareTo(btcBalance.get().getAvailable()));
assertEquals(0, new BigDecimal("3").compareTo(btcBalance.get().getFrozen()));
assertEquals(0, new BigDecimal("4").compareTo(btcBalance.get().getBorrowed()));
assertEquals(0, new BigDecimal("5").compareTo(btcBalance.get().getLoaned()));
assertEquals(0, new BigDecimal("6").compareTo(btcBalance.get().getWithdrawing()));
assertEquals(0, new BigDecimal("7").compareTo(btcBalance.get().getDepositing()));
// Testing ETH balance.
final Optional<Balance> ethBalance = account.getBalances().stream().filter(balance -> balance.getCurrency().equals(ETH)).findAny();
assertTrue(ethBalance.isPresent());
assertEquals(ETH, ethBalance.get().getCurrency());
assertEquals(0, new BigDecimal("11").compareTo(ethBalance.get().getTotal()));
assertEquals(0, new BigDecimal("22").compareTo(ethBalance.get().getAvailable()));
assertEquals(0, new BigDecimal("33").compareTo(ethBalance.get().getFrozen()));
assertEquals(0, new BigDecimal("44").compareTo(ethBalance.get().getBorrowed()));
assertEquals(0, new BigDecimal("55").compareTo(ethBalance.get().getLoaned()));
assertEquals(0, new BigDecimal("66").compareTo(ethBalance.get().getWithdrawing()));
assertEquals(0, new BigDecimal("77").compareTo(ethBalance.get().getDepositing()));
}
Aggregations