Search in sources :

Example 1 with OrderCreationResultDTO

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()));
}
Also used : CurrencyPairDTO(tech.cassandre.trading.bot.dto.util.CurrencyPairDTO) OrderCreationResultDTO(tech.cassandre.trading.bot.dto.trade.OrderCreationResultDTO) BigDecimal(java.math.BigDecimal) BaseTest(tech.cassandre.trading.bot.test.util.junit.BaseTest) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) DisplayName(org.junit.jupiter.api.DisplayName) Tag(org.junit.jupiter.api.Tag) Disabled(org.junit.jupiter.api.Disabled)

Example 2 with OrderCreationResultDTO

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)));
}
Also used : BeforeEach(org.junit.jupiter.api.BeforeEach) Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) BID(tech.cassandre.trading.bot.dto.trade.OrderTypeDTO.BID) ZonedDateTime(java.time.ZonedDateTime) Assertions.assertNull(org.junit.jupiter.api.Assertions.assertNull) Autowired(org.springframework.beans.factory.annotation.Autowired) ActiveProfiles(org.springframework.test.context.ActiveProfiles) TradeService(tech.cassandre.trading.bot.service.TradeService) Disabled(org.junit.jupiter.api.Disabled) BaseTest(tech.cassandre.trading.bot.test.util.junit.BaseTest) TestableCassandreStrategy(tech.cassandre.trading.bot.test.util.strategies.TestableCassandreStrategy) BigDecimal(java.math.BigDecimal) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) BTC(tech.cassandre.trading.bot.dto.util.CurrencyDTO.BTC) CurrencyPairDTO(tech.cassandre.trading.bot.dto.util.CurrencyPairDTO) Tag(org.junit.jupiter.api.Tag) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) ETH(tech.cassandre.trading.bot.dto.util.CurrencyDTO.ETH) Awaitility.await(org.awaitility.Awaitility.await) USD(tech.cassandre.trading.bot.dto.util.CurrencyDTO.USD) TestPropertySource(org.springframework.test.context.TestPropertySource) TradeDTO(tech.cassandre.trading.bot.dto.trade.TradeDTO) OrderDTO(tech.cassandre.trading.bot.dto.trade.OrderDTO) DisplayName(org.junit.jupiter.api.DisplayName) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) OrderCreationResultDTO(tech.cassandre.trading.bot.dto.trade.OrderCreationResultDTO) Optional(java.util.Optional) TradeDTO(tech.cassandre.trading.bot.dto.trade.TradeDTO) CurrencyPairDTO(tech.cassandre.trading.bot.dto.util.CurrencyPairDTO) OrderCreationResultDTO(tech.cassandre.trading.bot.dto.trade.OrderCreationResultDTO) BigDecimal(java.math.BigDecimal) BaseTest(tech.cassandre.trading.bot.test.util.junit.BaseTest) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) DisplayName(org.junit.jupiter.api.DisplayName) Tag(org.junit.jupiter.api.Tag)

Example 3 with OrderCreationResultDTO

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());
}
Also used : CurrencyPairDTO(tech.cassandre.trading.bot.dto.util.CurrencyPairDTO) OrderCreationResultDTO(tech.cassandre.trading.bot.dto.trade.OrderCreationResultDTO) BigDecimal(java.math.BigDecimal) BaseTest(tech.cassandre.trading.bot.test.util.junit.BaseTest) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) DisplayName(org.junit.jupiter.api.DisplayName) Tag(org.junit.jupiter.api.Tag)

Example 4 with OrderCreationResultDTO

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()));
}
Also used : CurrencyPairDTO(tech.cassandre.trading.bot.dto.util.CurrencyPairDTO) OrderCreationResultDTO(tech.cassandre.trading.bot.dto.trade.OrderCreationResultDTO) BigDecimal(java.math.BigDecimal) BaseTest(tech.cassandre.trading.bot.test.util.junit.BaseTest) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) DisplayName(org.junit.jupiter.api.DisplayName) Tag(org.junit.jupiter.api.Tag) Disabled(org.junit.jupiter.api.Disabled)

Example 5 with OrderCreationResultDTO

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)));
}
Also used : BeforeEach(org.junit.jupiter.api.BeforeEach) Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) BID(tech.cassandre.trading.bot.dto.trade.OrderTypeDTO.BID) ZonedDateTime(java.time.ZonedDateTime) Assertions.assertNull(org.junit.jupiter.api.Assertions.assertNull) Autowired(org.springframework.beans.factory.annotation.Autowired) ActiveProfiles(org.springframework.test.context.ActiveProfiles) TradeService(tech.cassandre.trading.bot.service.TradeService) Disabled(org.junit.jupiter.api.Disabled) BaseTest(tech.cassandre.trading.bot.test.util.junit.BaseTest) TestableCassandreStrategy(tech.cassandre.trading.bot.test.util.strategies.TestableCassandreStrategy) BigDecimal(java.math.BigDecimal) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) BTC(tech.cassandre.trading.bot.dto.util.CurrencyDTO.BTC) CurrencyPairDTO(tech.cassandre.trading.bot.dto.util.CurrencyPairDTO) Tag(org.junit.jupiter.api.Tag) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) NEW(tech.cassandre.trading.bot.dto.trade.OrderStatusDTO.NEW) ETH(tech.cassandre.trading.bot.dto.util.CurrencyDTO.ETH) Awaitility.await(org.awaitility.Awaitility.await) ZERO(java.math.BigDecimal.ZERO) TestPropertySource(org.springframework.test.context.TestPropertySource) TradeDTO(tech.cassandre.trading.bot.dto.trade.TradeDTO) OrderDTO(tech.cassandre.trading.bot.dto.trade.OrderDTO) DisplayName(org.junit.jupiter.api.DisplayName) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) OrderCreationResultDTO(tech.cassandre.trading.bot.dto.trade.OrderCreationResultDTO) Optional(java.util.Optional) TradeDTO(tech.cassandre.trading.bot.dto.trade.TradeDTO) CurrencyPairDTO(tech.cassandre.trading.bot.dto.util.CurrencyPairDTO) OrderCreationResultDTO(tech.cassandre.trading.bot.dto.trade.OrderCreationResultDTO) BigDecimal(java.math.BigDecimal) BaseTest(tech.cassandre.trading.bot.test.util.junit.BaseTest) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) DisplayName(org.junit.jupiter.api.DisplayName) Tag(org.junit.jupiter.api.Tag) Disabled(org.junit.jupiter.api.Disabled)

Aggregations

OrderCreationResultDTO (tech.cassandre.trading.bot.dto.trade.OrderCreationResultDTO)30 BigDecimal (java.math.BigDecimal)24 DisplayName (org.junit.jupiter.api.DisplayName)16 Test (org.junit.jupiter.api.Test)16 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)16 BaseTest (tech.cassandre.trading.bot.test.util.junit.BaseTest)16 CurrencyPairDTO (tech.cassandre.trading.bot.dto.util.CurrencyPairDTO)14 Tag (org.junit.jupiter.api.Tag)12 OrderDTO (tech.cassandre.trading.bot.dto.trade.OrderDTO)12 Disabled (org.junit.jupiter.api.Disabled)9 Optional (java.util.Optional)7 Awaitility.await (org.awaitility.Awaitility.await)7 Assertions.assertEquals (org.junit.jupiter.api.Assertions.assertEquals)7 Assertions.assertNotNull (org.junit.jupiter.api.Assertions.assertNotNull)7 Assertions.assertNull (org.junit.jupiter.api.Assertions.assertNull)7 Assertions.assertTrue (org.junit.jupiter.api.Assertions.assertTrue)7 Autowired (org.springframework.beans.factory.annotation.Autowired)7 BID (tech.cassandre.trading.bot.dto.trade.OrderTypeDTO.BID)7 TradeDTO (tech.cassandre.trading.bot.dto.trade.TradeDTO)7 TradeService (tech.cassandre.trading.bot.service.TradeService)7