Search in sources :

Example 1 with CurrencyPairDTO

use of tech.cassandre.trading.bot.dto.util.CurrencyPairDTO 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)));
}
Also used : Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) ZonedDateTime(java.time.ZonedDateTime) Assertions.assertNull(org.junit.jupiter.api.Assertions.assertNull) Autowired(org.springframework.beans.factory.annotation.Autowired) Set(java.util.Set) ZERO(java.math.BigDecimal.ZERO) ActiveProfiles(org.springframework.test.context.ActiveProfiles) TestPropertySource(org.springframework.test.context.TestPropertySource) DisplayName(org.junit.jupiter.api.DisplayName) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) MarketService(tech.cassandre.trading.bot.service.MarketService) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) BTC(tech.cassandre.trading.bot.dto.util.CurrencyDTO.BTC) CurrencyPairDTO(tech.cassandre.trading.bot.dto.util.CurrencyPairDTO) Optional(java.util.Optional) Tag(org.junit.jupiter.api.Tag) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) TickerDTO(tech.cassandre.trading.bot.dto.market.TickerDTO) Collections(java.util.Collections) ETH(tech.cassandre.trading.bot.dto.util.CurrencyDTO.ETH) CurrencyPairDTO(tech.cassandre.trading.bot.dto.util.CurrencyPairDTO) TickerDTO(tech.cassandre.trading.bot.dto.market.TickerDTO) 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 2 with CurrencyPairDTO

use of tech.cassandre.trading.bot.dto.util.CurrencyPairDTO 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 3 with CurrencyPairDTO

use of tech.cassandre.trading.bot.dto.util.CurrencyPairDTO 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 4 with CurrencyPairDTO

use of tech.cassandre.trading.bot.dto.util.CurrencyPairDTO 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 5 with CurrencyPairDTO

use of tech.cassandre.trading.bot.dto.util.CurrencyPairDTO 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)

Aggregations

CurrencyPairDTO (tech.cassandre.trading.bot.dto.util.CurrencyPairDTO)33 DisplayName (org.junit.jupiter.api.DisplayName)24 Test (org.junit.jupiter.api.Test)24 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)24 BigDecimal (java.math.BigDecimal)21 BaseTest (tech.cassandre.trading.bot.test.util.junit.BaseTest)19 Tag (org.junit.jupiter.api.Tag)16 OrderCreationResultDTO (tech.cassandre.trading.bot.dto.trade.OrderCreationResultDTO)14 Optional (java.util.Optional)11 Assertions.assertEquals (org.junit.jupiter.api.Assertions.assertEquals)10 Assertions.assertNotNull (org.junit.jupiter.api.Assertions.assertNotNull)10 Assertions.assertTrue (org.junit.jupiter.api.Assertions.assertTrue)10 Autowired (org.springframework.beans.factory.annotation.Autowired)10 ActiveProfiles (org.springframework.test.context.ActiveProfiles)10 TradeDTO (tech.cassandre.trading.bot.dto.trade.TradeDTO)10 BTC (tech.cassandre.trading.bot.dto.util.CurrencyDTO.BTC)10 ETH (tech.cassandre.trading.bot.dto.util.CurrencyDTO.ETH)10 Assertions.assertNull (org.junit.jupiter.api.Assertions.assertNull)9 Disabled (org.junit.jupiter.api.Disabled)9 TestPropertySource (org.springframework.test.context.TestPropertySource)9