use of tech.cassandre.trading.bot.dto.trade.OrderCreationResultDTO in project cassandre-trading-bot by cassandre-tech.
the class TradeServiceTest method checkCancelOrder.
@Test
@Tag("integration")
@DisplayName("Check cancel an order")
@Disabled("Not supported by Coinbase")
public void checkCancelOrder() {
final CurrencyPairDTO cp = new CurrencyPairDTO(BTC, USD);
// Making a buy limit order.
final OrderCreationResultDTO result1 = strategy.createSellLimitOrder(cp, new BigDecimal("0.01"), new BigDecimal("100000"));
assertNotNull(result1.getOrder().getOrderId());
// The order must exist.
await().untilAsserted(() -> assertTrue(tradeService.getOrders().stream().anyMatch(o -> o.getOrderId().equals(result1.getOrder().getOrderId()))));
// Cancel the order.
assertTrue(tradeService.cancelOrder(result1.getOrder().getOrderId()));
// The order must have disappeared.
await().untilAsserted(() -> assertFalse(tradeService.getOrders().stream().anyMatch(o -> o.getOrderId().equals(result1.getOrder().getOrderId()))));
// Cancel the order again and check it gives false.
assertFalse(tradeService.cancelOrder(result1.getOrder().getOrderId()));
}
use of tech.cassandre.trading.bot.dto.trade.OrderCreationResultDTO 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.trade.OrderCreationResultDTO in project cassandre-trading-bot by cassandre-tech.
the class TradeServiceTest method checkCreateBuySellMarketOrder.
@Test
@Tag("integration")
@DisplayName("Check creates a buy/sell market order")
public void checkCreateBuySellMarketOrder() {
final CurrencyPairDTO cp = new CurrencyPairDTO(ETH, BTC);
// =============================================================================================================
// Making a buy market order with a size below the minimum requirement. Testing error management.
final OrderCreationResultDTO result1 = strategy.createBuyMarketOrder(cp, new BigDecimal("0.00000001"));
assertFalse(result1.isSuccessful());
assertNull(result1.getOrder());
assertTrue(result1.getErrorMessage().contains("size must be a number"));
assertNotNull(result1.getException());
// =============================================================================================================
// Making a buy market order (Buy 0.01 ETH).
final OrderCreationResultDTO result2 = strategy.createBuyMarketOrder(cp, new BigDecimal("0.01"));
assertTrue(result2.isSuccessful());
assertNotNull(result2.getOrder().getOrderId());
assertNull(result2.getErrorMessage());
assertNull(result2.getException());
// =============================================================================================================
// Refunding the account.
final OrderCreationResultDTO result3 = strategy.createSellMarketOrder(cp, new BigDecimal("0.01"));
assertTrue(result3.isSuccessful());
}
use of tech.cassandre.trading.bot.dto.trade.OrderCreationResultDTO in project cassandre-trading-bot by cassandre-tech.
the class TradeServiceTest method checkCancelOrder.
@Test
@Tag("integration")
@DisplayName("Check cancel an order")
@Disabled("Gemini doesn't support market order")
public void checkCancelOrder() {
final CurrencyPairDTO cp = new CurrencyPairDTO(ETH, BTC);
// Making a buy limit order (Buy 0.0001 ETH).
final OrderCreationResultDTO result1 = strategy.createSellLimitOrder(cp, new BigDecimal("0.0001"), new BigDecimal("10000000"));
assertNotNull(result1.getOrder().getOrderId());
// The order must exist.
await().untilAsserted(() -> assertTrue(tradeService.getOrders().stream().anyMatch(o -> o.getOrderId().equals(result1.getOrder().getOrderId()))));
// Cancel the order.
assertTrue(tradeService.cancelOrder(result1.getOrder().getOrderId()));
// The order must have disappeared.
await().untilAsserted(() -> assertFalse(tradeService.getOrders().stream().anyMatch(o -> o.getOrderId().equals(result1.getOrder().getOrderId()))));
// Cancel the order again and check it gives false.
assertFalse(tradeService.cancelOrder(result1.getOrder().getOrderId()));
}
use of tech.cassandre.trading.bot.dto.trade.OrderCreationResultDTO 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)));
}
Aggregations