Search in sources :

Example 1 with MarketService

use of tech.cassandre.trading.bot.service.MarketService in project cassandre-trading-bot by cassandre-tech.

the class BasicTa4jCassandreStrategyTestMock method marketService.

@Bean
@Primary
public MarketService marketService() {
    MarketService service = mock(MarketService.class);
    // We don't use the getTickers method.
    given(service.getTickers(any())).willThrow(new NotAvailableFromExchangeException("Not available in test"));
    // Returns three values.
    given(service.getTicker(BTC_USDT)).willReturn(Optional.of(TickerDTO.builder().currencyPair(BTC_USDT).timestamp(BaseTest.createZonedDateTime(1)).open(new BigDecimal(100)).high(new BigDecimal(100)).low(new BigDecimal(100)).last(new BigDecimal(100)).volume(new BigDecimal(1060)).build()), Optional.of(TickerDTO.builder().currencyPair(BTC_USDT).timestamp(BaseTest.createZonedDateTime(2)).open(new BigDecimal(100)).high(new BigDecimal(100)).low(new BigDecimal(100)).last(new BigDecimal(100)).volume(new BigDecimal(1060)).build()), Optional.of(TickerDTO.builder().currencyPair(BTC_USDT).timestamp(BaseTest.createZonedDateTime(3)).open(new BigDecimal(110)).high(new BigDecimal(110)).low(new BigDecimal(110)).last(new BigDecimal(110)).volume(new BigDecimal(1070)).build()), Optional.of(TickerDTO.builder().currencyPair(BTC_USDT).timestamp(BaseTest.createZonedDateTime(4)).open(new BigDecimal(100)).high(new BigDecimal(100)).low(new BigDecimal(100)).last(new BigDecimal(100)).volume(new BigDecimal(1060)).build()), Optional.of(TickerDTO.builder().currencyPair(BTC_USDT).timestamp(BaseTest.createZonedDateTime(5)).open(new BigDecimal(140)).high(new BigDecimal(140)).low(new BigDecimal(140)).last(new BigDecimal(140)).volume(new BigDecimal(1080)).build()), Optional.of(TickerDTO.builder().currencyPair(BTC_USDT).timestamp(BaseTest.createZonedDateTime(6)).open(new BigDecimal(100)).high(new BigDecimal(100)).low(new BigDecimal(100)).last(new BigDecimal(100)).volume(new BigDecimal(1060)).build()), Optional.of(TickerDTO.builder().currencyPair(BTC_USDT).timestamp(BaseTest.createZonedDateTime(7)).open(new BigDecimal(119)).high(new BigDecimal(119)).low(new BigDecimal(119)).last(new BigDecimal(119)).volume(new BigDecimal(1090)).build()), Optional.of(TickerDTO.builder().currencyPair(BTC_USDT).timestamp(BaseTest.createZonedDateTime(8)).open(new BigDecimal(100)).high(new BigDecimal(100)).low(new BigDecimal(100)).last(new BigDecimal(100)).volume(new BigDecimal(1060)).build()), Optional.of(TickerDTO.builder().currencyPair(BTC_USDT).timestamp(BaseTest.createZonedDateTime(9)).open(new BigDecimal(100)).high(new BigDecimal(100)).low(new BigDecimal(100)).last(new BigDecimal(100)).volume(new BigDecimal(1100)).build()), Optional.of(TickerDTO.builder().currencyPair(BTC_USDT).timestamp(BaseTest.createZonedDateTime(10)).open(new BigDecimal(100)).high(new BigDecimal(100)).low(new BigDecimal(100)).last(new BigDecimal(100)).volume(new BigDecimal(1060)).build()), Optional.of(TickerDTO.builder().currencyPair(BTC_USDT).timestamp(BaseTest.createZonedDateTime(11)).open(new BigDecimal(110)).high(new BigDecimal(110)).low(new BigDecimal(110)).last(new BigDecimal(110)).volume(new BigDecimal(1100)).build()), Optional.of(TickerDTO.builder().currencyPair(BTC_USDT).timestamp(BaseTest.createZonedDateTime(12)).open(new BigDecimal(100)).high(new BigDecimal(100)).low(new BigDecimal(100)).last(new BigDecimal(100)).volume(new BigDecimal(1060)).build()), Optional.of(TickerDTO.builder().currencyPair(BTC_USDT).timestamp(BaseTest.createZonedDateTime(13)).open(new BigDecimal(120)).high(new BigDecimal(120)).low(new BigDecimal(120)).last(new BigDecimal(120)).volume(new BigDecimal(1120)).build()), Optional.of(TickerDTO.builder().currencyPair(BTC_USDT).timestamp(BaseTest.createZonedDateTime(14)).open(new BigDecimal(100)).high(new BigDecimal(100)).low(new BigDecimal(100)).last(new BigDecimal(100)).volume(new BigDecimal(1060)).build()), Optional.of(TickerDTO.builder().currencyPair(BTC_USDT).timestamp(BaseTest.createZonedDateTime(15)).open(new BigDecimal(130)).high(new BigDecimal(130)).low(new BigDecimal(130)).last(new BigDecimal(130)).volume(new BigDecimal(1130)).build()), Optional.empty());
    return service;
}
Also used : NotAvailableFromExchangeException(org.knowm.xchange.exceptions.NotAvailableFromExchangeException) BigDecimal(java.math.BigDecimal) MarketService(tech.cassandre.trading.bot.service.MarketService) Primary(org.springframework.context.annotation.Primary) Bean(org.springframework.context.annotation.Bean)

Example 2 with MarketService

use of tech.cassandre.trading.bot.service.MarketService in project cassandre-trading-bot by cassandre-tech.

the class PositionServiceDryModeTestMock method marketService.

@Bean
@Primary
public MarketService marketService() {
    // Creates the mock.
    MarketService marketService = mock(MarketService.class);
    // We don't use the getTickers method.
    given(marketService.getTickers(any())).willThrow(new NotAvailableFromExchangeException("Not available during tests"));
    // Replies for ETH / BTC.
    given(marketService.getTicker(ETH_BTC)).willReturn(Optional.empty());
    // Replies for ETH / USDT.
    given(marketService.getTicker(ETH_USDT)).willReturn(Optional.empty());
    return marketService;
}
Also used : NotAvailableFromExchangeException(org.knowm.xchange.exceptions.NotAvailableFromExchangeException) MarketService(tech.cassandre.trading.bot.service.MarketService) Primary(org.springframework.context.annotation.Primary) Bean(org.springframework.context.annotation.Bean)

Example 3 with MarketService

use of tech.cassandre.trading.bot.service.MarketService in project cassandre-trading-bot by cassandre-tech.

the class BasicCassandreStrategyTestMock method marketService.

@Bean
@Primary
public MarketService marketService() {
    MarketService service = mock(MarketService.class);
    // We don't use the getTickers method.
    given(service.getTickers(any())).willThrow(new NotAvailableFromExchangeException("Not available during tests"));
    // Returns three values for ETH/BTC.
    given(service.getTicker(ETH_BTC)).willReturn(BaseTest.getFakeTicker(ETH_BTC, new BigDecimal("1")), BaseTest.getFakeTicker(ETH_BTC, new BigDecimal("2")), BaseTest.getFakeTicker(ETH_BTC, new BigDecimal("3")), BaseTest.getFakeTicker(ETH_BTC, new BigDecimal("4")), BaseTest.getFakeTicker(ETH_BTC, new BigDecimal("5")), BaseTest.getFakeTicker(ETH_BTC, new BigDecimal("6")), Optional.empty());
    // Returns one value for ETH/USDT.
    given(service.getTicker(ETH_USDT)).willReturn(BaseTest.getFakeTicker(ETH_USDT, new BigDecimal("10000")), Optional.empty());
    return service;
}
Also used : NotAvailableFromExchangeException(org.knowm.xchange.exceptions.NotAvailableFromExchangeException) BigDecimal(java.math.BigDecimal) MarketService(tech.cassandre.trading.bot.service.MarketService) Primary(org.springframework.context.annotation.Primary) Bean(org.springframework.context.annotation.Bean)

Example 4 with MarketService

use of tech.cassandre.trading.bot.service.MarketService in project cassandre-trading-bot by cassandre-tech.

the class Issue426TestMock method marketService.

@Bean
@Primary
public MarketService marketService() {
    // Creates the mock.
    MarketService marketService = mock(MarketService.class);
    // Replies for ETH/BTC.
    given(marketService.getTicker(ETH_BTC)).willReturn(Optional.of(TickerDTO.builder().currencyPair(ETH_BTC).timestamp(createZonedDateTime(1)).last(new BigDecimal("0.2")).build()), Optional.of(TickerDTO.builder().currencyPair(ETH_BTC).timestamp(createZonedDateTime(2)).last(new BigDecimal("0.3")).build()), Optional.of(TickerDTO.builder().currencyPair(ETH_BTC).timestamp(createZonedDateTime(3)).last(new BigDecimal("0.4")).build()), Optional.of(TickerDTO.builder().currencyPair(ETH_BTC).timestamp(createZonedDateTime(4)).last(new BigDecimal("0.4")).build()));
    // Replies for ETH/USDT.
    given(marketService.getTicker(ETH_USDT)).willReturn(Optional.of(TickerDTO.builder().currencyPair(ETH_USDT).timestamp(createZonedDateTime(5)).last(new BigDecimal("0.3")).build()), Optional.of(TickerDTO.builder().currencyPair(ETH_USDT).timestamp(createZonedDateTime(6)).last(new BigDecimal("0.3")).build()), Optional.of(TickerDTO.builder().currencyPair(ETH_USDT).timestamp(createZonedDateTime(7)).last(new BigDecimal("0.6")).build()), Optional.of(TickerDTO.builder().currencyPair(ETH_USDT).timestamp(createZonedDateTime(8)).last(new BigDecimal("0.1")).build()));
    return marketService;
}
Also used : BigDecimal(java.math.BigDecimal) MarketService(tech.cassandre.trading.bot.service.MarketService) Primary(org.springframework.context.annotation.Primary) Bean(org.springframework.context.annotation.Bean)

Example 5 with MarketService

use of tech.cassandre.trading.bot.service.MarketService in project cassandre-trading-bot by cassandre-tech.

the class Issue427TestMock method marketService.

@Bean
@Primary
public MarketService marketService() {
    // Creates the mock.
    MarketService marketService = mock(MarketService.class);
    // Replies for ETH/BTC.
    given(marketService.getTicker(ETH_BTC)).willReturn(Optional.of(TickerDTO.builder().currencyPair(ETH_BTC).timestamp(createZonedDateTime(1)).last(new BigDecimal("0.2")).build()), Optional.of(TickerDTO.builder().currencyPair(ETH_BTC).timestamp(createZonedDateTime(2)).last(new BigDecimal("0.3")).build()), Optional.of(TickerDTO.builder().currencyPair(ETH_BTC).timestamp(createZonedDateTime(3)).last(new BigDecimal("0.4")).build()), Optional.of(TickerDTO.builder().currencyPair(ETH_BTC).timestamp(createZonedDateTime(4)).last(new BigDecimal("0.4")).build()));
    // Replies for ETH/USDT.
    given(marketService.getTicker(ETH_USDT)).willReturn(Optional.of(TickerDTO.builder().currencyPair(ETH_USDT).timestamp(createZonedDateTime(5)).last(new BigDecimal("0.3")).build()), Optional.of(TickerDTO.builder().currencyPair(ETH_USDT).timestamp(createZonedDateTime(6)).last(new BigDecimal("0.3")).build()), Optional.of(TickerDTO.builder().currencyPair(ETH_USDT).timestamp(createZonedDateTime(7)).last(new BigDecimal("0.6")).build()), Optional.of(TickerDTO.builder().currencyPair(ETH_USDT).timestamp(createZonedDateTime(8)).last(new BigDecimal("0.1")).build()));
    return marketService;
}
Also used : BigDecimal(java.math.BigDecimal) MarketService(tech.cassandre.trading.bot.service.MarketService) Primary(org.springframework.context.annotation.Primary) Bean(org.springframework.context.annotation.Bean)

Aggregations

Bean (org.springframework.context.annotation.Bean)7 Primary (org.springframework.context.annotation.Primary)7 MarketService (tech.cassandre.trading.bot.service.MarketService)7 BigDecimal (java.math.BigDecimal)5 NotAvailableFromExchangeException (org.knowm.xchange.exceptions.NotAvailableFromExchangeException)4 CsvToBeanBuilder (com.opencsv.bean.CsvToBeanBuilder)1 IOException (java.io.IOException)1 Files (java.nio.file.Files)1 Arrays (java.util.Arrays)1 Collections (java.util.Collections)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Set (java.util.Set)1 AtomicLong (java.util.concurrent.atomic.AtomicLong)1 RequiredArgsConstructor (lombok.RequiredArgsConstructor)1 Mappers (org.mapstruct.factory.Mappers)1 Logger (org.slf4j.Logger)1 LoggerFactory (org.slf4j.LoggerFactory)1 TestConfiguration (org.springframework.boot.test.context.TestConfiguration)1 ApplicationContext (org.springframework.context.ApplicationContext)1