diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml index 2ae3312bb..22353cee0 100644 --- a/.github/workflows/codeql-analysis.yml +++ b/.github/workflows/codeql-analysis.yml @@ -35,8 +35,6 @@ jobs: - name: Build, run tests, package and deploy to Maven central env: # Environment variables. - # Maven options. - MAVEN_OPTS: -Xmx1024m -XX:MaxPermSize=128m # Kucoin credentials. KUCOIN_NAME: ${{ secrets.KUCOIN_NAME }} KUCOIN_USERNAME: ${{ secrets.KUCOIN_USERNAME }} diff --git a/.github/workflows/continuous-integration.yml b/.github/workflows/continuous-integration.yml index 6f1aabc2b..0534e9574 100644 --- a/.github/workflows/continuous-integration.yml +++ b/.github/workflows/continuous-integration.yml @@ -36,8 +36,6 @@ jobs: # ================================================================================================================ - name: Build, run tests, package and deploy to Maven central env: # Environment variables. - # Maven options. - MAVEN_OPTS: -Xmx1024m -XX:MaxPermSize=128m # Ossrh credentials. MAVEN_USERNAME: ${{ secrets.OSSRH_USERNAME }} MAVEN_PASSWORD: ${{ secrets.OSSRH_PASSWORD }} @@ -56,11 +54,11 @@ jobs: # ================================================================================================================ - name : Test Cassandre trading bot maven archetype - basic strategy run: | - mvn -B archetype:generate -DarchetypeGroupId=tech.cassandre.trading.bot -DarchetypeArtifactId=cassandre-trading-bot-spring-boot-starter-basic-archetype -DarchetypeVersion=${{ steps.package.outputs.version }} -DgroupId=tech.cassandre -DartifactId=archetype-test-basic -Dversion=1.0-SNAPSHOT -Dpackage=tech.cassandre + mvn -B archetype:generate -DarchetypeGroupId=tech.cassandre.trading.bot -DarchetypeArtifactId=cassandre-trading-bot-spring-boot-starter-basic-archetype -DarchetypeVersion=${{ steps.package.outputs.version }} -DgroupId=com.example -DartifactId=archetype-test-basic -Dversion=1.0-SNAPSHOT -Dpackage=com.example mvn -f archetype-test-basic/pom.xml test # ================================================================================================================ - name : Test Cassandre trading bot maven archetype - basic ta4j strategy run: | - mvn -B archetype:generate -DarchetypeGroupId=tech.cassandre.trading.bot -DarchetypeArtifactId=cassandre-trading-bot-spring-boot-starter-basic-ta4j-archetype -DarchetypeVersion=${{ steps.package.outputs.version }} -DgroupId=tech.cassandre -DartifactId=archetype-test-ta4j-basic -Dversion=1.0-SNAPSHOT -Dpackage=tech.cassandre + mvn -B archetype:generate -DarchetypeGroupId=tech.cassandre.trading.bot -DarchetypeArtifactId=cassandre-trading-bot-spring-boot-starter-basic-ta4j-archetype -DarchetypeVersion=${{ steps.package.outputs.version }} -DgroupId=com.example -DartifactId=archetype-test-ta4j-basic -Dversion=1.0-SNAPSHOT -Dpackage=com.example mvn -f archetype-test-ta4j-basic/pom.xml test diff --git a/.github/workflows/integration-tests.yml b/.github/workflows/integration-tests.yml index e36fa0dae..f848b0a37 100644 --- a/.github/workflows/integration-tests.yml +++ b/.github/workflows/integration-tests.yml @@ -24,8 +24,6 @@ jobs: # ================================================================================================================ - name: Build, run tests, package and deploy to Maven central env: # Environment variables. - # Maven options. - MAVEN_OPTS: -Xmx1024m -XX:MaxPermSize=128m # Kucoin credentials. KUCOIN_NAME: ${{ secrets.KUCOIN_NAME }} KUCOIN_USERNAME: ${{ secrets.KUCOIN_USERNAME }} diff --git a/.github/workflows/release-creation.yml b/.github/workflows/release-creation.yml index d7b10e6a3..95aa7de5b 100644 --- a/.github/workflows/release-creation.yml +++ b/.github/workflows/release-creation.yml @@ -37,8 +37,6 @@ jobs: - name: Build, run tests, package id: package env: # Environment variables. - # Maven options. - MAVEN_OPTS: -Xmx1024m -XX:MaxPermSize=128m GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Ossrh credentials. MAVEN_USERNAME: ${{ secrets.OSSRH_USERNAME }} diff --git a/.gitignore b/.gitignore index 97dfc71b0..0f1b1634b 100644 --- a/.gitignore +++ b/.gitignore @@ -50,7 +50,6 @@ hs_err_pid* # Maven log/ .notes -.mvn *.iml # Node diff --git a/.mvn/jvm.config b/.mvn/jvm.config new file mode 100644 index 000000000..05ea927b6 --- /dev/null +++ b/.mvn/jvm.config @@ -0,0 +1 @@ +-Xmx2048m -Xms1024m -Djava.awt.headless=true \ No newline at end of file diff --git a/README.md b/README.md index 9878d6f50..782f0311c 100644 --- a/README.md +++ b/README.md @@ -13,6 +13,9 @@ src="https://github.com/cassandre-tech/cassandre-trading-bot/workflows/Continuous%20integration/badge.svg" alt="GitHub Actions" /> +

+ +

tech.cassandre.trading.bot cassandre-trading-bot-project - 2.2.0 + 2.3.0 pom Cassandre trading bot https://github.com/cassandre-tech/cassandre-trading-bot diff --git a/spring-boot-starter-test/autoconfigure/pom.xml b/spring-boot-starter-test/autoconfigure/pom.xml index e272232d7..49867ec0d 100644 --- a/spring-boot-starter-test/autoconfigure/pom.xml +++ b/spring-boot-starter-test/autoconfigure/pom.xml @@ -6,7 +6,7 @@ cassandre-trading-bot-spring-boot-starter-test-autoconfigure - Trading bot spring boot starter test autoconfigure + Trading bot spring boot autoconfigure test @@ -47,6 +47,12 @@ junit-pioneer 1.0.0 + + org.hsqldb + hsqldb + 2.5.1 + test + @@ -134,7 +140,7 @@ tech.cassandre.trading.bot cassandre-trading-bot-project - 2.2.0 + 2.3.0 ../../pom.xml diff --git a/spring-boot-starter-test/autoconfigure/src/main/java/tech/cassandre/trading/bot/test/mock/TickerFluxMock.java b/spring-boot-starter-test/autoconfigure/src/main/java/tech/cassandre/trading/bot/test/mock/TickerFluxMock.java index c2b9a1a78..4f95630ed 100644 --- a/spring-boot-starter-test/autoconfigure/src/main/java/tech/cassandre/trading/bot/test/mock/TickerFluxMock.java +++ b/spring-boot-starter-test/autoconfigure/src/main/java/tech/cassandre/trading/bot/test/mock/TickerFluxMock.java @@ -4,18 +4,16 @@ import org.mockito.stubbing.Answer; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.springframework.boot.autoconfigure.domain.EntityScan; import org.springframework.boot.test.context.TestConfiguration; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Primary; import org.springframework.core.io.Resource; import org.springframework.core.io.support.PathMatchingResourcePatternResolver; -import org.springframework.data.jpa.repository.config.EnableJpaRepositories; import tech.cassandre.trading.bot.batch.TickerFlux; import tech.cassandre.trading.bot.dto.market.TickerDTO; -import tech.cassandre.trading.bot.service.MarketService; import tech.cassandre.trading.bot.dto.util.CurrencyDTO; import tech.cassandre.trading.bot.dto.util.CurrencyPairDTO; +import tech.cassandre.trading.bot.service.MarketService; import java.io.FileNotFoundException; import java.io.IOException; @@ -50,8 +48,6 @@ */ @SuppressWarnings("checkstyle:DesignForExtension") @TestConfiguration -@EntityScan(basePackages = "tech.cassandre.trading.bot.domain") -@EnableJpaRepositories(basePackages = "tech.cassandre.trading.bot.repository") public class TickerFluxMock { /** Logger. */ diff --git a/spring-boot-starter-test/autoconfigure/src/test/resources/application.properties b/spring-boot-starter-test/autoconfigure/src/test/resources/application.properties index 4c6c07315..fd7c848cb 100644 --- a/spring-boot-starter-test/autoconfigure/src/test/resources/application.properties +++ b/spring-boot-starter-test/autoconfigure/src/test/resources/application.properties @@ -19,20 +19,18 @@ cassandre.trading.bot.exchange.rates.account=100 cassandre.trading.bot.exchange.rates.ticker=101 cassandre.trading.bot.exchange.rates.trade=102 # -# Database used for backup. -spring.datasource.driver-class-name=org.hsqldb.jdbc.JDBCDriver -spring.datasource.url=jdbc:hsqldb:mem:cassandre -spring.datasource.username=sa -spring.datasource.password= +# Database configuration. +spring.jpa.hibernate.ddl-auto=update +cassandre.trading.bot.database.datasource.driver-class-name=org.hsqldb.jdbc.JDBCDriver +cassandre.trading.bot.database.datasource.url=jdbc:hsqldb:mem:cassandre +cassandre.trading.bot.database.datasource.username=sa +cassandre.trading.bot.database.datasource.password= # # ====================================================================================================================== -# Technical parameters for tests. +# Parameters for tests. # # Console logging pattern. logging.pattern.console=%d{HH:mm:ss} - %msg%n # # File logging pattern. logging.pattern.file=%d{HH:mm:ss} - %msg%n -# -# Useful for tests. -spring.main.allow-bean-definition-overriding=true diff --git a/spring-boot-starter-test/starter/pom.xml b/spring-boot-starter-test/starter/pom.xml index 48431bb67..454d0d97c 100644 --- a/spring-boot-starter-test/starter/pom.xml +++ b/spring-boot-starter-test/starter/pom.xml @@ -115,7 +115,7 @@ tech.cassandre.trading.bot cassandre-trading-bot-project - 2.2.0 + 2.3.0 ../../pom.xml diff --git a/spring-boot-starter/autoconfigure/pom.xml b/spring-boot-starter/autoconfigure/pom.xml index 96285e9cc..791f881dc 100644 --- a/spring-boot-starter/autoconfigure/pom.xml +++ b/spring-boot-starter/autoconfigure/pom.xml @@ -40,26 +40,23 @@ org.springframework.boot spring-boot-autoconfigure + + org.springframework.boot spring-boot-starter-data-jpa - - org.hsqldb - hsqldb - 2.5.1 - org.knowm.xchange xchange-core - 5.0.2 + 5.0.3 org.knowm.xchange xchange-kucoin - 5.0.2 + 5.0.3 @@ -78,7 +75,17 @@ org.mapstruct mapstruct - 1.4.0.Final + 1.4.1.Final + + + javax.xml.bind + jaxb-api + 2.3.1 + + + com.sun.xml.bind + jaxb-impl + 2.3.3 @@ -99,6 +106,12 @@ 4.0.3 test + + org.hsqldb + hsqldb + 2.5.1 + test + @@ -265,7 +278,7 @@ tech.cassandre.trading.bot cassandre-trading-bot-project - 2.2.0 + 2.3.0 ../../pom.xml diff --git a/spring-boot-starter/autoconfigure/src/main/java/tech/cassandre/trading/bot/configuration/DatabaseAutoConfiguration.java b/spring-boot-starter/autoconfigure/src/main/java/tech/cassandre/trading/bot/configuration/DatabaseAutoConfiguration.java new file mode 100644 index 000000000..5a3cc1817 --- /dev/null +++ b/spring-boot-starter/autoconfigure/src/main/java/tech/cassandre/trading/bot/configuration/DatabaseAutoConfiguration.java @@ -0,0 +1,59 @@ +package tech.cassandre.trading.bot.configuration; + +import org.hibernate.boot.model.naming.PhysicalNamingStrategy; +import org.springframework.boot.autoconfigure.domain.EntityScan; +import org.springframework.boot.autoconfigure.jdbc.DataSourceProperties; +import org.springframework.boot.context.properties.EnableConfigurationProperties; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.Primary; +import org.springframework.data.jpa.repository.config.EnableJpaRepositories; +import tech.cassandre.trading.bot.util.base.BaseConfiguration; +import tech.cassandre.trading.bot.util.database.CassandreNamingStrategy; +import tech.cassandre.trading.bot.util.parameters.DatabaseParameters; + +/** + * Database autoconfiguration. + */ +@Configuration +@EntityScan(basePackages = "tech.cassandre.trading.bot.domain") +@EnableJpaRepositories(basePackages = "tech.cassandre.trading.bot.repository") +@EnableConfigurationProperties({DatabaseParameters.class, + DatabaseParameters.Datasource.class}) +public class DatabaseAutoConfiguration extends BaseConfiguration { + + /** Database parameters. */ + private final DatabaseParameters databaseParameters; + + /** + * Constructor. + * + * @param newDatabaseParameters database parameters. + */ + public DatabaseAutoConfiguration(final DatabaseParameters newDatabaseParameters) { + this.databaseParameters = newDatabaseParameters; + } + + /** + * Gives to Hiraki the configuration of the default datasource. + * + * @return datasource configuration + */ + @Bean + @Primary + public DataSourceProperties dataSourceProperties() { + DataSourceProperties p = new DataSourceProperties(); + p.setDriverClassName(databaseParameters.getDatasource().getDriverClassName()); + p.setUrl(databaseParameters.getDatasource().getUrl()); + p.setUsername(databaseParameters.getDatasource().getUsername()); + p.setPassword(databaseParameters.getDatasource().getPassword()); + return p; + } + + @Bean + @SuppressWarnings("checkstyle:DesignForExtension") + public PhysicalNamingStrategy physical() { + return new CassandreNamingStrategy(databaseParameters.getTablePrefix()); + } + +} diff --git a/spring-boot-starter/autoconfigure/src/main/java/tech/cassandre/trading/bot/configuration/ExchangeAutoConfiguration.java b/spring-boot-starter/autoconfigure/src/main/java/tech/cassandre/trading/bot/configuration/ExchangeAutoConfiguration.java index 208eb2edf..f77738d0c 100644 --- a/spring-boot-starter/autoconfigure/src/main/java/tech/cassandre/trading/bot/configuration/ExchangeAutoConfiguration.java +++ b/spring-boot-starter/autoconfigure/src/main/java/tech/cassandre/trading/bot/configuration/ExchangeAutoConfiguration.java @@ -159,6 +159,7 @@ public void configure() { TradeServiceDryModeImplementation tradeServiceDryMode = null; if (!exchangeParameters.getModes().isDry()) { // Normal mode. + getLogger().info("Dry mode is off"); this.exchangeService = new ExchangeServiceXChangeImplementation(xChangeExchange); this.userService = new UserServiceXChangeImplementation(accountRate, xChangeAccountService); this.marketService = new MarketServiceXChangeImplementation(tickerRate, xChangeMarketDataService); @@ -166,11 +167,12 @@ public void configure() { this.positionService = new PositionServiceImplementation(tradeService, positionRepository); } else { // Dry mode. + getLogger().info("Dry mode is on"); this.exchangeService = new ExchangeServiceDryModeImplementation(applicationContext); userServiceDryMode = new UserServiceDryModeImplementation(); this.userService = userServiceDryMode; this.marketService = new MarketServiceXChangeImplementation(tickerRate, xChangeMarketDataService); - tradeServiceDryMode = new TradeServiceDryModeImplementation(userServiceDryMode); + tradeServiceDryMode = new TradeServiceDryModeImplementation(userServiceDryMode, tradeRepository); this.tradeService = tradeServiceDryMode; this.positionService = new PositionServiceImplementation(tradeService, positionRepository); } @@ -206,7 +208,7 @@ public void configure() { // Authorization failure. e.printStackTrace(); throw new ConfigurationException("Invalid credentials for " + exchangeParameters.getName(), - "Check your exchange credentials " + e.getMessage()); + "Check your exchange credentials " + e.getMessage() + " - login used : " + exchangeParameters.getUsername()); } else { // Another HTTP failure. e.printStackTrace(); diff --git a/spring-boot-starter/autoconfigure/src/main/java/tech/cassandre/trading/bot/configuration/StrategyAutoConfiguration.java b/spring-boot-starter/autoconfigure/src/main/java/tech/cassandre/trading/bot/configuration/StrategyAutoConfiguration.java index f92588642..f79fafc8d 100644 --- a/spring-boot-starter/autoconfigure/src/main/java/tech/cassandre/trading/bot/configuration/StrategyAutoConfiguration.java +++ b/spring-boot-starter/autoconfigure/src/main/java/tech/cassandre/trading/bot/configuration/StrategyAutoConfiguration.java @@ -157,15 +157,16 @@ public void configure() { if (user.isPresent()) { final Optional tradeAccount = ((CassandreStrategyInterface) o).getTradeAccount(new LinkedHashSet<>(user.get().getAccounts().values())); if (tradeAccount.isEmpty()) { + StringJoiner accountList = new StringJoiner(", "); + user.get().getAccounts().values().forEach(accountDTO -> accountList.add(accountDTO.getName())); throw new ConfigurationException("Your strategy specifies a trading account that doesn't exist", - "Check your getTradeAccount(Set accounts) method as it returns an empty result"); + "Check your getTradeAccount(Set accounts) method as it returns an empty result - Account list : " + accountList); } } else { throw new ConfigurationException("Impossible to retrieve your user information", "Impossible to retrieve your user information. Check logs."); } - // ============================================================================================================= // Getting strategy information. CassandreStrategyInterface strategy = (CassandreStrategyInterface) o; @@ -256,7 +257,7 @@ private void restoreData(final CassandreStrategyInterface strategy) { tradeService.restoreTrade(t); tradeFlux.restoreTrade(t); tradeCount.incrementAndGet(); - getLogger().info("Trade " + trade.getOrderId() + " restored"); + getLogger().info("Trade " + trade.getOrderId() + " restored : " + t); }); getLogger().info(tradeCount.get() + " trade(s) restored"); @@ -299,7 +300,7 @@ private void restoreData(final CassandreStrategyInterface strategy) { strategy.restorePosition(p); positionFlux.restorePosition(p); positionCount.incrementAndGet(); - getLogger().info("Position " + position.getId() + " restored"); + getLogger().info("Position " + position.getId() + " restored : " + p); }); getLogger().info(positionCount.get() + " position(s) restored"); } diff --git a/spring-boot-starter/autoconfigure/src/main/java/tech/cassandre/trading/bot/dto/position/PositionDTO.java b/spring-boot-starter/autoconfigure/src/main/java/tech/cassandre/trading/bot/dto/position/PositionDTO.java index 1d6d6a904..79f01adc3 100644 --- a/spring-boot-starter/autoconfigure/src/main/java/tech/cassandre/trading/bot/dto/position/PositionDTO.java +++ b/spring-boot-starter/autoconfigure/src/main/java/tech/cassandre/trading/bot/dto/position/PositionDTO.java @@ -9,6 +9,7 @@ import java.math.BigDecimal; import java.math.RoundingMode; +import java.text.DecimalFormat; import java.util.Objects; import java.util.Optional; import java.util.concurrent.atomic.AtomicLong; @@ -395,6 +396,24 @@ public final Long getVersion() { return version.longValue(); } + /** + * Returns formatted value. + * @param value value + * @return formatted value + */ + private String getFormattedValue(final BigDecimal value) { + return new DecimalFormat("#0.##").format(value); + } + + /** + * Returns formatted value. + * @param value value + * @return formatted value + */ + private String getFormattedValue(final double value) { + return new DecimalFormat("#0.##").format(value); + } + @Override public final boolean equals(final Object o) { if (this == o) { @@ -439,7 +458,7 @@ public final String toString() { value += " on " + getCurrencyPair() + " - Opened"; final Optional lastGain = getLastCalculatedGain(); if (lastGain.isPresent()) { - value += " - Last gain calculated " + getLastCalculatedGain().get().getPercentage() + " %"; + value += " - Last gain calculated " + getFormattedValue(getLastCalculatedGain().get().getPercentage()) + " %"; } break; case CLOSING: @@ -447,7 +466,7 @@ public final String toString() { break; case CLOSED: final GainDTO gain = getGain(); - value += " on " + getCurrencyPair() + " - Closed - Gain : " + gain.getPercentage() + " %"; + value += " on " + getCurrencyPair() + " - Closed - Gain : " + getFormattedValue(gain.getPercentage()) + " %"; break; default: value = "Incorrect state for position " + getId(); diff --git a/spring-boot-starter/autoconfigure/src/main/java/tech/cassandre/trading/bot/service/dry/TradeServiceDryModeImplementation.java b/spring-boot-starter/autoconfigure/src/main/java/tech/cassandre/trading/bot/service/dry/TradeServiceDryModeImplementation.java index 839d8fdf2..ddeb38b88 100644 --- a/spring-boot-starter/autoconfigure/src/main/java/tech/cassandre/trading/bot/service/dry/TradeServiceDryModeImplementation.java +++ b/spring-boot-starter/autoconfigure/src/main/java/tech/cassandre/trading/bot/service/dry/TradeServiceDryModeImplementation.java @@ -2,6 +2,7 @@ import tech.cassandre.trading.bot.batch.OrderFlux; import tech.cassandre.trading.bot.batch.TradeFlux; +import tech.cassandre.trading.bot.domain.Trade; import tech.cassandre.trading.bot.dto.market.TickerDTO; import tech.cassandre.trading.bot.dto.trade.OrderCreationResultDTO; import tech.cassandre.trading.bot.dto.trade.OrderDTO; @@ -10,6 +11,7 @@ import tech.cassandre.trading.bot.dto.user.AccountDTO; import tech.cassandre.trading.bot.dto.user.BalanceDTO; import tech.cassandre.trading.bot.dto.user.UserDTO; +import tech.cassandre.trading.bot.repository.TradeRepository; import tech.cassandre.trading.bot.service.TradeService; import tech.cassandre.trading.bot.util.base.BaseService; import tech.cassandre.trading.bot.dto.util.CurrencyPairDTO; @@ -63,13 +65,19 @@ public class TradeServiceDryModeImplementation extends BaseService implements Tr /** User service - dry mode. */ private final UserServiceDryModeImplementation userService; + /** Trade repository. */ + private final TradeRepository tradeRepository; + /** * Constructor. * * @param newUserService user service + * @param newTradeRepository trade repository */ - public TradeServiceDryModeImplementation(final UserServiceDryModeImplementation newUserService) { + public TradeServiceDryModeImplementation(final UserServiceDryModeImplementation newUserService, + final TradeRepository newTradeRepository) { this.userService = newUserService; + this.tradeRepository = newTradeRepository; } /** @@ -212,13 +220,11 @@ public final OrderCreationResultDTO createSellMarketOrder(final CurrencyPairDTO @Override public final OrderCreationResultDTO createBuyLimitOrder(final CurrencyPairDTO currencyPair, final BigDecimal amount, final BigDecimal limitPrice) { - // TODO Implement this later. return new OrderCreationResultDTO("Not implemented", new Exception("Not implemented")); } @Override public final OrderCreationResultDTO createSellLimitOrder(final CurrencyPairDTO currencyPair, final BigDecimal amount, final BigDecimal limitPrice) { - // TODO Implement this later. return new OrderCreationResultDTO("Not implemented", new Exception("Not implemented")); } @@ -275,8 +281,18 @@ public final void restoreTrade(final TradeDTO trade) { } @Override - public void backupTrade(final TradeDTO trade) { - // No backup in dry mode. + public final void backupTrade(final TradeDTO trade) { + Trade t = new Trade(); + t.setId(trade.getId()); + t.setOrderId(trade.getOrderId()); + t.setType(trade.getType().toString()); + t.setOriginalAmount(trade.getOriginalAmount()); + t.setCurrencyPair(trade.getCurrencyPair().toString()); + t.setPrice(trade.getPrice()); + t.setTimestamp(trade.getTimestamp()); + t.setFeeAmount(trade.getFee().getValue()); + t.setFeeCurrency(trade.getFee().getCurrency().toString()); + tradeRepository.save(t); } } diff --git a/spring-boot-starter/autoconfigure/src/main/java/tech/cassandre/trading/bot/service/dry/UserServiceDryModeImplementation.java b/spring-boot-starter/autoconfigure/src/main/java/tech/cassandre/trading/bot/service/dry/UserServiceDryModeImplementation.java index c22007853..e93c58eeb 100644 --- a/spring-boot-starter/autoconfigure/src/main/java/tech/cassandre/trading/bot/service/dry/UserServiceDryModeImplementation.java +++ b/spring-boot-starter/autoconfigure/src/main/java/tech/cassandre/trading/bot/service/dry/UserServiceDryModeImplementation.java @@ -121,7 +121,7 @@ public final Optional getUser() { public List getFilesToLoad() { PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver(); try { - final Resource[] resources = resolver.getResources("classpath:" + USER_FILE_PREFIX + "*" + USER_FILE_SUFFIX); + final Resource[] resources = resolver.getResources("classpath*:" + USER_FILE_PREFIX + "*" + USER_FILE_SUFFIX); return Arrays.asList(resources); } catch (IOException e) { getLogger().error("TickerFluxMock encountered an error : " + e.getMessage()); diff --git a/spring-boot-starter/autoconfigure/src/main/java/tech/cassandre/trading/bot/util/database/CassandreNamingStrategy.java b/spring-boot-starter/autoconfigure/src/main/java/tech/cassandre/trading/bot/util/database/CassandreNamingStrategy.java new file mode 100644 index 000000000..acfed422b --- /dev/null +++ b/spring-boot-starter/autoconfigure/src/main/java/tech/cassandre/trading/bot/util/database/CassandreNamingStrategy.java @@ -0,0 +1,31 @@ +package tech.cassandre.trading.bot.util.database; + +import org.hibernate.boot.model.naming.Identifier; +import org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl; +import org.hibernate.engine.jdbc.env.spi.JdbcEnvironment; + +/** + * Cassandre naming strategy. + */ +public class CassandreNamingStrategy extends PhysicalNamingStrategyStandardImpl { + + /** Table prefix (default none). */ + private String tablePrefix = ""; + + /** + * Constructor. + * + * @param newTablePrefix table prefix + */ + public CassandreNamingStrategy(final String newTablePrefix) { + if (newTablePrefix != null) { + this.tablePrefix = newTablePrefix; + } + } + + @Override + public final Identifier toPhysicalTableName(final Identifier name, final JdbcEnvironment context) { + return new Identifier(tablePrefix.concat(name.getText()), name.isQuoted()); + } + +} diff --git a/spring-boot-starter/autoconfigure/src/main/java/tech/cassandre/trading/bot/util/database/package-info.java b/spring-boot-starter/autoconfigure/src/main/java/tech/cassandre/trading/bot/util/database/package-info.java new file mode 100644 index 000000000..8f240ea37 --- /dev/null +++ b/spring-boot-starter/autoconfigure/src/main/java/tech/cassandre/trading/bot/util/database/package-info.java @@ -0,0 +1,4 @@ +/** + * Database utils. + */ +package tech.cassandre.trading.bot.util.database; \ No newline at end of file diff --git a/spring-boot-starter/autoconfigure/src/main/java/tech/cassandre/trading/bot/util/parameters/DatabaseParameters.java b/spring-boot-starter/autoconfigure/src/main/java/tech/cassandre/trading/bot/util/parameters/DatabaseParameters.java new file mode 100644 index 000000000..7d3faf9b6 --- /dev/null +++ b/spring-boot-starter/autoconfigure/src/main/java/tech/cassandre/trading/bot/util/parameters/DatabaseParameters.java @@ -0,0 +1,186 @@ +package tech.cassandre.trading.bot.util.parameters; + +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.validation.annotation.Validated; + +import javax.validation.Valid; +import javax.validation.constraints.NotNull; + +/** + * Database parameters from application.properties. + */ +@Validated +@ConfigurationProperties(prefix = "cassandre.trading.bot.database") +public class DatabaseParameters { + + /** Table prefix parameter. */ + public static final String PARAMETER_DATABASE_TABLE_PREFIX = "cassandre.trading.bot.database.table-prefix"; + + /** Table prefix. */ + private String tablePrefix; + + /** Datasource configuration. */ + @Valid + private Datasource datasource = new Datasource(); + + /** Datasource configuration. */ + @Validated + @ConfigurationProperties(prefix = "cassandre.trading.bot.database.datasource") + public class Datasource { + + /** Backup enabled parameter. */ + public static final String PARAMETER_DATABASE_DATASOURCE_DRIVER_CLASS_NAME = "cassandre.trading.bot.database.datasource.driver-class-name"; + + /** Backup enabled parameter. */ + public static final String PARAMETER_DATABASE_DATASOURCE_URL = "cassandre.trading.bot.database.datasource.url"; + + /** Backup enabled parameter. */ + public static final String PARAMETER_DATABASE_DATASOURCE_USERNAME = "cassandre.trading.bot.database.datasource.username"; + + /** Backup enabled parameter. */ + public static final String PARAMETER_DATABASE_DATASOURCE_PASSWORD = "cassandre.trading.bot.database.datasource.password"; + + /** Driver class name. */ + @NotNull(message = "Database driver class name must be set") + private String driverClassName; + + /** URL. */ + @NotNull(message = "Database url must be set") + private String url; + + /** Username. */ + @NotNull(message = "Database username must be set") + private String username; + + /** Password. */ + private String password; + + /** + * Getter driverClassName. + * + * @return driverClassName + */ + public String getDriverClassName() { + return driverClassName; + } + + /** + * Setter driverClassName. + * + * @param newDriverClassName the driverClassName to set + */ + public void setDriverClassName(final String newDriverClassName) { + driverClassName = newDriverClassName; + } + + /** + * Getter url. + * + * @return url + */ + public String getUrl() { + return url; + } + + /** + * Setter url. + * + * @param newUrl the url to set + */ + public void setUrl(final String newUrl) { + url = newUrl; + } + + /** + * Getter username. + * + * @return username + */ + public String getUsername() { + return username; + } + + /** + * Setter username. + * + * @param newUsername the username to set + */ + public void setUsername(final String newUsername) { + username = newUsername; + } + + /** + * Getter password. + * + * @return password + */ + public String getPassword() { + return password; + } + + /** + * Setter password. + * + * @param newPassword the password to set + */ + public void setPassword(final String newPassword) { + password = newPassword; + } + + @Override + public final String toString() { + return "Datasource{" + + " driverClassName='" + driverClassName + '\'' + + ", url='" + url + '\'' + + ", username='" + username + '\'' + + ", password='" + password + '\'' + + '}'; + } + + } + + /** + * Getter tablePrefix. + * + * @return tablePrefix + */ + public String getTablePrefix() { + return tablePrefix; + } + + /** + * Setter tablePrefix. + * + * @param newTablePrefix the tablePrefix to set + */ + public void setTablePrefix(final String newTablePrefix) { + tablePrefix = newTablePrefix; + } + + /** + * Getter datasource. + * + * @return datasource + */ + public Datasource getDatasource() { + return datasource; + } + + /** + * Setter datasource. + * + * @param newDatasource the datasource to set + */ + public void setDatasource(final Datasource newDatasource) { + datasource = newDatasource; + } + + @Override + public final String toString() { + return "DatabaseParameters{" + + " tablePrefix='" + tablePrefix + '\'' + + ", datasource=" + datasource + + '}'; + } + +} diff --git a/spring-boot-starter/autoconfigure/src/main/java/tech/cassandre/trading/bot/util/parameters/ExchangeParameters.java b/spring-boot-starter/autoconfigure/src/main/java/tech/cassandre/trading/bot/util/parameters/ExchangeParameters.java index 84b410029..d72228cad 100644 --- a/spring-boot-starter/autoconfigure/src/main/java/tech/cassandre/trading/bot/util/parameters/ExchangeParameters.java +++ b/spring-boot-starter/autoconfigure/src/main/java/tech/cassandre/trading/bot/util/parameters/ExchangeParameters.java @@ -16,25 +16,25 @@ public class ExchangeParameters { /** Exchange name parameter. */ - public static final String PARAMETER_NAME = "cassandre.trading.bot.exchange.name"; + public static final String PARAMETER_EXCHANGE_NAME = "cassandre.trading.bot.exchange.name"; /** Username parameter. */ - public static final String PARAMETER_USERNAME = "cassandre.trading.bot.exchange.username"; + public static final String PARAMETER_EXCHANGE_USERNAME = "cassandre.trading.bot.exchange.username"; /** Passphrase parameter. */ - public static final String PARAMETER_PASSPHRASE = "cassandre.trading.bot.exchange.passphrase"; + public static final String PARAMETER_EXCHANGE_PASSPHRASE = "cassandre.trading.bot.exchange.passphrase"; /** Key parameter. */ - public static final String PARAMETER_KEY = "cassandre.trading.bot.exchange.key"; + public static final String PARAMETER_EXCHANGE_KEY = "cassandre.trading.bot.exchange.key"; /** Secret parameter. */ - public static final String PARAMETER_SECRET = "cassandre.trading.bot.exchange.secret"; + public static final String PARAMETER_EXCHANGE_SECRET = "cassandre.trading.bot.exchange.secret"; /** Proxy host. */ - public static final String PARAMETER_PROXY_HOST = "cassandre.trading.bot.exchange.proxyHost"; + public static final String PARAMETER_EXCHANGE_PROXY_HOST = "cassandre.trading.bot.exchange.proxyHost"; /** Proxy port. */ - public static final String PARAMETER_PROXY_PORT = "cassandre.trading.bot.exchange.proxyPort"; + public static final String PARAMETER_EXCHANGE_PROXY_PORT = "cassandre.trading.bot.exchange.proxyPort"; /** Exchange name. For example : coinbase, kraken, kucoin. */ @NotEmpty(message = "Exchange name required, for example : coinbase, kraken, kucoin...") @@ -64,21 +64,22 @@ public class ExchangeParameters { /** Modes. */ @Valid - private static Modes modes = new Modes(); + private Modes modes = new Modes(); /** API Calls rates. */ @Valid - private static Rates rates = new Rates(); + private Rates rates = new Rates(); /** Exchange API rate calls. */ + @Validated @ConfigurationProperties(prefix = "cassandre.trading.bot.exchange.modes") - public static class Modes { + public class Modes { /** Sandbox parameter. */ - public static final String PARAMETER_SANDBOX = "cassandre.trading.bot.exchange.modes.sandbox"; + public static final String PARAMETER_EXCHANGE_SANDBOX = "cassandre.trading.bot.exchange.modes.sandbox"; /** Dry parameter. */ - public static final String PARAMETER_DRY = "cassandre.trading.bot.exchange.modes.dry"; + public static final String PARAMETER_EXCHANGE_DRY = "cassandre.trading.bot.exchange.modes.dry"; /** Set it to true to use the sandbox. */ @NotNull(message = "Sandbox parameter required, set it to true to use the sandbox") @@ -135,17 +136,18 @@ public final String toString() { } /** Exchange API rate calls. */ + @Validated @ConfigurationProperties(prefix = "cassandre.trading.bot.exchange.rates") public static class Rates { /** Rate for account parameter. */ - public static final String PARAMETER_RATE_ACCOUNT = "cassandre.trading.bot.exchange.rates.account"; + public static final String PARAMETER_EXCHANGE_RATE_ACCOUNT = "cassandre.trading.bot.exchange.rates.account"; /** Rate for ticker parameter. */ - public static final String PARAMETER_RATE_TICKER = "cassandre.trading.bot.exchange.rates.ticker"; + public static final String PARAMETER_EXCHANGE_RATE_TICKER = "cassandre.trading.bot.exchange.rates.ticker"; /** Rate for order parameter. */ - public static final String PARAMETER_RATE_TRADE = "cassandre.trading.bot.exchange.rates.trade"; + public static final String PARAMETER_EXCHANGE_RATE_TRADE = "cassandre.trading.bot.exchange.rates.trade"; /** Delay between calls to account API. */ @NotNull(message = "Delay between calls to account API is mandatory") diff --git a/spring-boot-starter/autoconfigure/src/main/java/tech/cassandre/trading/bot/util/validator/RateValidator.java b/spring-boot-starter/autoconfigure/src/main/java/tech/cassandre/trading/bot/util/validator/RateValidator.java index a77ae7b09..7e50e1082 100644 --- a/spring-boot-starter/autoconfigure/src/main/java/tech/cassandre/trading/bot/util/validator/RateValidator.java +++ b/spring-boot-starter/autoconfigure/src/main/java/tech/cassandre/trading/bot/util/validator/RateValidator.java @@ -11,6 +11,9 @@ public class RateValidator implements ConstraintValidator { @Override public final boolean isValid(final String value, final ConstraintValidatorContext constraintValidatorContext) { + if (value == null || value.length() == 0) { + return false; + } if (isNumeric(value)) { return true; } else { diff --git a/spring-boot-starter/autoconfigure/src/main/resources/META-INF/spring.factories b/spring-boot-starter/autoconfigure/src/main/resources/META-INF/spring.factories index 563fefa61..7cb89424c 100644 --- a/spring-boot-starter/autoconfigure/src/main/resources/META-INF/spring.factories +++ b/spring-boot-starter/autoconfigure/src/main/resources/META-INF/spring.factories @@ -1,2 +1,2 @@ org.springframework.boot.diagnostics.FailureAnalyzer=tech.cassandre.trading.bot.util.exception.ConfigurationFailureAnalyzer -org.springframework.boot.autoconfigure.EnableAutoConfiguration=tech.cassandre.trading.bot.configuration.ExchangeAutoConfiguration,tech.cassandre.trading.bot.configuration.StrategyAutoConfiguration,tech.cassandre.trading.bot.configuration.ScheduleAutoConfiguration \ No newline at end of file +org.springframework.boot.autoconfigure.EnableAutoConfiguration=tech.cassandre.trading.bot.configuration.DatabaseAutoConfiguration,tech.cassandre.trading.bot.configuration.ExchangeAutoConfiguration,tech.cassandre.trading.bot.configuration.ScheduleAutoConfiguration,tech.cassandre.trading.bot.configuration.StrategyAutoConfiguration \ No newline at end of file diff --git a/spring-boot-starter/autoconfigure/src/main/resources/application.properties b/spring-boot-starter/autoconfigure/src/main/resources/application.properties index 71590fa91..179b8d61a 100644 --- a/spring-boot-starter/autoconfigure/src/main/resources/application.properties +++ b/spring-boot-starter/autoconfigure/src/main/resources/application.properties @@ -6,7 +6,7 @@ cassandre.trading.bot.exchange.passphrase=cassandre cassandre.trading.bot.exchange.key=5df8eea30092f40009cb3c6a cassandre.trading.bot.exchange.secret=5f6e91e0-796b-4947-b75e-eaa5c06b6bed # -# Exchange specification. +# Xchange specific parameters - uncomment if required. # cassandre.trading.bot.exchange.proxyHost=127.0.0.1 # cassandre.trading.bot.exchange.proxyPort=4780 # @@ -14,13 +14,15 @@ cassandre.trading.bot.exchange.secret=5f6e91e0-796b-4947-b75e-eaa5c06b6bed cassandre.trading.bot.exchange.modes.sandbox=true cassandre.trading.bot.exchange.modes.dry=false # -# Exchange API calls rates (ms or standard ISO 8601 duration like 'PT5S'). +# Exchange API calls rates (in ms or standard ISO 8601 duration like 'PT5S'). cassandre.trading.bot.exchange.rates.account=100 cassandre.trading.bot.exchange.rates.ticker=101 cassandre.trading.bot.exchange.rates.trade=102 # -# Database used for backup. -spring.datasource.driver-class-name=org.hsqldb.jdbc.JDBCDriver -spring.datasource.url=jdbc:hsqldb:mem:cassandre -spring.datasource.username=sa -spring.datasource.password= \ No newline at end of file +# Database configuration. +spring.jpa.hibernate.ddl-auto=update +cassandre.trading.bot.database.datasource.driver-class-name=org.hsqldb.jdbc.JDBCDriver +cassandre.trading.bot.database.datasource.url=jdbc:hsqldb:mem:cassandre-database;shutdown=true +cassandre.trading.bot.database.datasource.username=sa +cassandre.trading.bot.database.datasource.password= +cassandre.trading.bot.database.table-prefix=MY_STRATEGY_ \ No newline at end of file diff --git a/spring-boot-starter/autoconfigure/src/test/java/tech/cassandre/trading/bot/test/backup/ImportedDataTest.java b/spring-boot-starter/autoconfigure/src/test/java/tech/cassandre/trading/bot/test/backup/ImportedDataTest.java index cbf23eca4..a9ad84d97 100644 --- a/spring-boot-starter/autoconfigure/src/test/java/tech/cassandre/trading/bot/test/backup/ImportedDataTest.java +++ b/spring-boot-starter/autoconfigure/src/test/java/tech/cassandre/trading/bot/test/backup/ImportedDataTest.java @@ -26,7 +26,7 @@ @Property(key = "spring.datasource.data", value = "classpath:/backup.sql"), @Property(key = "spring.jpa.hibernate.ddl-auto", value = "create-drop") }) -@DirtiesContext(classMode = DirtiesContext.ClassMode.BEFORE_EACH_TEST_METHOD) +@DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_CLASS) public class ImportedDataTest extends BaseTest { @Autowired diff --git a/spring-boot-starter/autoconfigure/src/test/java/tech/cassandre/trading/bot/test/backup/TradeBackupTest.java b/spring-boot-starter/autoconfigure/src/test/java/tech/cassandre/trading/bot/test/backup/TradeBackupTest.java index fa3202705..a192a921a 100644 --- a/spring-boot-starter/autoconfigure/src/test/java/tech/cassandre/trading/bot/test/backup/TradeBackupTest.java +++ b/spring-boot-starter/autoconfigure/src/test/java/tech/cassandre/trading/bot/test/backup/TradeBackupTest.java @@ -35,7 +35,7 @@ @Property(key = "spring.datasource.data", value = "classpath:/backup.sql"), @Property(key = "spring.jpa.hibernate.ddl-auto", value = "create-drop") }) -@DirtiesContext(classMode = DirtiesContext.ClassMode.BEFORE_EACH_TEST_METHOD) +@DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_CLASS) public class TradeBackupTest extends BaseTest { public static final CurrencyPairDTO cp = new CurrencyPairDTO(ETH, BTC); diff --git a/spring-boot-starter/autoconfigure/src/test/java/tech/cassandre/trading/bot/test/batch/AccountFluxTest.java b/spring-boot-starter/autoconfigure/src/test/java/tech/cassandre/trading/bot/test/batch/AccountFluxTest.java index b011fdc86..caf293b5a 100644 --- a/spring-boot-starter/autoconfigure/src/test/java/tech/cassandre/trading/bot/test/batch/AccountFluxTest.java +++ b/spring-boot-starter/autoconfigure/src/test/java/tech/cassandre/trading/bot/test/batch/AccountFluxTest.java @@ -5,6 +5,7 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.context.annotation.Import; +import org.springframework.test.annotation.DirtiesContext; import tech.cassandre.trading.bot.dto.user.AccountDTO; import tech.cassandre.trading.bot.service.UserService; import tech.cassandre.trading.bot.test.batch.mocks.AccountFluxTestMock; @@ -29,6 +30,7 @@ @Configuration({ @Property(key = "TEST_NAME", value = "Batch - Account flux") }) +@DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_CLASS) @Import(AccountFluxTestMock.class) public class AccountFluxTest extends BaseTest { diff --git a/spring-boot-starter/autoconfigure/src/test/java/tech/cassandre/trading/bot/test/batch/OrderFluxTest.java b/spring-boot-starter/autoconfigure/src/test/java/tech/cassandre/trading/bot/test/batch/OrderFluxTest.java index af9fbe1b8..17f7aa950 100644 --- a/spring-boot-starter/autoconfigure/src/test/java/tech/cassandre/trading/bot/test/batch/OrderFluxTest.java +++ b/spring-boot-starter/autoconfigure/src/test/java/tech/cassandre/trading/bot/test/batch/OrderFluxTest.java @@ -5,6 +5,7 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.context.annotation.Import; +import org.springframework.test.annotation.DirtiesContext; import tech.cassandre.trading.bot.dto.trade.OrderDTO; import tech.cassandre.trading.bot.service.TradeService; import tech.cassandre.trading.bot.test.batch.mocks.OrderFluxTestMock; @@ -27,6 +28,7 @@ @Configuration({ @Property(key = "TEST_NAME", value = "Batch - Order flux") }) +@DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_CLASS) @Import(OrderFluxTestMock.class) public class OrderFluxTest extends BaseTest { diff --git a/spring-boot-starter/autoconfigure/src/test/java/tech/cassandre/trading/bot/test/batch/PositionFluxTest.java b/spring-boot-starter/autoconfigure/src/test/java/tech/cassandre/trading/bot/test/batch/PositionFluxTest.java index a1099edd5..64d641593 100644 --- a/spring-boot-starter/autoconfigure/src/test/java/tech/cassandre/trading/bot/test/batch/PositionFluxTest.java +++ b/spring-boot-starter/autoconfigure/src/test/java/tech/cassandre/trading/bot/test/batch/PositionFluxTest.java @@ -5,6 +5,7 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.context.annotation.Import; +import org.springframework.test.annotation.DirtiesContext; import tech.cassandre.trading.bot.batch.TickerFlux; import tech.cassandre.trading.bot.batch.TradeFlux; import tech.cassandre.trading.bot.dto.market.TickerDTO; @@ -38,6 +39,7 @@ @Configuration({ @Property(key = "TEST_NAME", value = "Batch - Position flux") }) +@DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_CLASS) @Import(PositionFluxTestMock.class) public class PositionFluxTest extends BaseTest { diff --git a/spring-boot-starter/autoconfigure/src/test/java/tech/cassandre/trading/bot/test/batch/TickerFluxTest.java b/spring-boot-starter/autoconfigure/src/test/java/tech/cassandre/trading/bot/test/batch/TickerFluxTest.java index ca88d27f0..ded3f7756 100644 --- a/spring-boot-starter/autoconfigure/src/test/java/tech/cassandre/trading/bot/test/batch/TickerFluxTest.java +++ b/spring-boot-starter/autoconfigure/src/test/java/tech/cassandre/trading/bot/test/batch/TickerFluxTest.java @@ -5,6 +5,7 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.context.annotation.Import; +import org.springframework.test.annotation.DirtiesContext; import tech.cassandre.trading.bot.dto.market.TickerDTO; import tech.cassandre.trading.bot.service.MarketService; import tech.cassandre.trading.bot.test.batch.mocks.TickerFluxTestMock; @@ -30,6 +31,7 @@ @Configuration({ @Property(key = "TEST_NAME", value = "Batch - Ticker flux") }) +@DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_CLASS) @Import(TickerFluxTestMock.class) public class TickerFluxTest extends BaseTest { diff --git a/spring-boot-starter/autoconfigure/src/test/java/tech/cassandre/trading/bot/test/batch/TradeFluxTest.java b/spring-boot-starter/autoconfigure/src/test/java/tech/cassandre/trading/bot/test/batch/TradeFluxTest.java index 73e14adbc..65d733a6e 100644 --- a/spring-boot-starter/autoconfigure/src/test/java/tech/cassandre/trading/bot/test/batch/TradeFluxTest.java +++ b/spring-boot-starter/autoconfigure/src/test/java/tech/cassandre/trading/bot/test/batch/TradeFluxTest.java @@ -5,6 +5,7 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.context.annotation.Import; +import org.springframework.test.annotation.DirtiesContext; import tech.cassandre.trading.bot.dto.trade.TradeDTO; import tech.cassandre.trading.bot.service.TradeService; import tech.cassandre.trading.bot.test.batch.mocks.TradeFluxTestMock; @@ -26,6 +27,7 @@ @Configuration({ @Property(key = "TEST_NAME", value = "Batch - Trade flux") }) +@DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_CLASS) @Import(TradeFluxTestMock.class) public class TradeFluxTest extends BaseTest { diff --git a/spring-boot-starter/autoconfigure/src/test/java/tech/cassandre/trading/bot/test/configuration/parameters/database/NoConfigurationTest.java b/spring-boot-starter/autoconfigure/src/test/java/tech/cassandre/trading/bot/test/configuration/parameters/database/NoConfigurationTest.java new file mode 100644 index 000000000..3a35869b0 --- /dev/null +++ b/spring-boot-starter/autoconfigure/src/test/java/tech/cassandre/trading/bot/test/configuration/parameters/database/NoConfigurationTest.java @@ -0,0 +1,44 @@ +package tech.cassandre.trading.bot.test.configuration.parameters.database; + +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.springframework.boot.SpringApplication; +import org.springframework.test.annotation.DirtiesContext; +import tech.cassandre.trading.bot.CassandreTradingBot; +import tech.cassandre.trading.bot.test.util.junit.BaseTest; +import tech.cassandre.trading.bot.test.util.junit.configuration.Configuration; +import tech.cassandre.trading.bot.test.util.junit.configuration.Property; + +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; +import static tech.cassandre.trading.bot.util.parameters.DatabaseParameters.Datasource.PARAMETER_DATABASE_DATASOURCE_DRIVER_CLASS_NAME; +import static tech.cassandre.trading.bot.util.parameters.DatabaseParameters.Datasource.PARAMETER_DATABASE_DATASOURCE_PASSWORD; +import static tech.cassandre.trading.bot.util.parameters.DatabaseParameters.Datasource.PARAMETER_DATABASE_DATASOURCE_URL; +import static tech.cassandre.trading.bot.util.parameters.DatabaseParameters.Datasource.PARAMETER_DATABASE_DATASOURCE_USERNAME; + +@DisplayName("Database parameters - No configuration") +@Configuration({ + @Property(key = PARAMETER_DATABASE_DATASOURCE_DRIVER_CLASS_NAME), + @Property(key = PARAMETER_DATABASE_DATASOURCE_URL), + @Property(key = PARAMETER_DATABASE_DATASOURCE_USERNAME), + @Property(key = PARAMETER_DATABASE_DATASOURCE_PASSWORD) +}) +@DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_CLASS) +public class NoConfigurationTest extends BaseTest { + + @Test + @DisplayName("Check error messages") + public void checkErrorMessages() { + try { + SpringApplication application = new SpringApplication(CassandreTradingBot.class); + application.run(); + fail("Exception not raised"); + } catch (Exception e) { + final String message = e.getCause().getCause().getCause().getCause().getCause().getMessage(); + assertTrue(message.contains("'datasource.username'")); + assertTrue(message.contains("'datasource.url'")); + assertTrue(message.contains("'datasource.driverClassName'")); + } + } + +} diff --git a/spring-boot-starter/autoconfigure/src/test/java/tech/cassandre/trading/bot/test/configuration/parameters/database/ValidConfigurationTest.java b/spring-boot-starter/autoconfigure/src/test/java/tech/cassandre/trading/bot/test/configuration/parameters/database/ValidConfigurationTest.java new file mode 100644 index 000000000..c1d2e0913 --- /dev/null +++ b/spring-boot-starter/autoconfigure/src/test/java/tech/cassandre/trading/bot/test/configuration/parameters/database/ValidConfigurationTest.java @@ -0,0 +1,32 @@ +package tech.cassandre.trading.bot.test.configuration.parameters.database; + +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.springframework.boot.SpringApplication; +import org.springframework.test.annotation.DirtiesContext; +import tech.cassandre.trading.bot.CassandreTradingBot; +import tech.cassandre.trading.bot.test.util.junit.BaseTest; +import tech.cassandre.trading.bot.test.util.junit.configuration.Configuration; +import tech.cassandre.trading.bot.test.util.junit.configuration.Property; + +import static org.junit.jupiter.api.Assertions.fail; + +@DisplayName("Database parameters - Valid configuration") +@Configuration({ + @Property(key = "TEST_NAME", value = "Database parameters - Valid configuration") +}) +@DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_CLASS) +public class ValidConfigurationTest extends BaseTest { + + @Test + @DisplayName("Connection test") + public void checkConnection() { + try { + SpringApplication application = new SpringApplication(CassandreTradingBot.class); + application.run(); + } catch (Exception e) { + fail("Exception raised during application startup : " + e); + } + } + +} diff --git a/spring-boot-starter/autoconfigure/src/test/java/tech/cassandre/trading/bot/test/configuration/parameters/package-info.java b/spring-boot-starter/autoconfigure/src/test/java/tech/cassandre/trading/bot/test/configuration/parameters/database/package-info.java similarity index 64% rename from spring-boot-starter/autoconfigure/src/test/java/tech/cassandre/trading/bot/test/configuration/parameters/package-info.java rename to spring-boot-starter/autoconfigure/src/test/java/tech/cassandre/trading/bot/test/configuration/parameters/database/package-info.java index 44d7e901d..b40406c04 100644 --- a/spring-boot-starter/autoconfigure/src/test/java/tech/cassandre/trading/bot/test/configuration/parameters/package-info.java +++ b/spring-boot-starter/autoconfigure/src/test/java/tech/cassandre/trading/bot/test/configuration/parameters/database/package-info.java @@ -1,4 +1,4 @@ /** - * Exchange configuration test. + * Database parameters tests. */ -package tech.cassandre.trading.bot.test.configuration.parameters; \ No newline at end of file +package tech.cassandre.trading.bot.test.configuration.parameters.database; \ No newline at end of file diff --git a/spring-boot-starter/autoconfigure/src/test/java/tech/cassandre/trading/bot/test/configuration/parameters/ExchangeSpecificationTest.java b/spring-boot-starter/autoconfigure/src/test/java/tech/cassandre/trading/bot/test/configuration/parameters/exchange/ExchangeSpecificationTest.java similarity index 79% rename from spring-boot-starter/autoconfigure/src/test/java/tech/cassandre/trading/bot/test/configuration/parameters/ExchangeSpecificationTest.java rename to spring-boot-starter/autoconfigure/src/test/java/tech/cassandre/trading/bot/test/configuration/parameters/exchange/ExchangeSpecificationTest.java index 313316397..76395ab6a 100644 --- a/spring-boot-starter/autoconfigure/src/test/java/tech/cassandre/trading/bot/test/configuration/parameters/ExchangeSpecificationTest.java +++ b/spring-boot-starter/autoconfigure/src/test/java/tech/cassandre/trading/bot/test/configuration/parameters/exchange/ExchangeSpecificationTest.java @@ -1,9 +1,10 @@ -package tech.cassandre.trading.bot.test.configuration.parameters; +package tech.cassandre.trading.bot.test.configuration.parameters.exchange; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.springframework.boot.SpringApplication; import org.springframework.context.ConfigurableApplicationContext; +import org.springframework.test.annotation.DirtiesContext; import tech.cassandre.trading.bot.CassandreTradingBot; import tech.cassandre.trading.bot.test.util.junit.BaseTest; import tech.cassandre.trading.bot.test.util.junit.configuration.Configuration; @@ -13,14 +14,15 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertTrue; import static org.junit.jupiter.api.Assertions.fail; -import static tech.cassandre.trading.bot.util.parameters.ExchangeParameters.PARAMETER_PROXY_HOST; -import static tech.cassandre.trading.bot.util.parameters.ExchangeParameters.PARAMETER_PROXY_PORT; +import static tech.cassandre.trading.bot.util.parameters.ExchangeParameters.PARAMETER_EXCHANGE_PROXY_HOST; +import static tech.cassandre.trading.bot.util.parameters.ExchangeParameters.PARAMETER_EXCHANGE_PROXY_PORT; -@DisplayName("Configuration parameters - Specific exchange parameters") +@DisplayName("Exchange parameters - Specific exchange parameters") @Configuration({ - @Property(key = PARAMETER_PROXY_HOST, value = "127.0.0.1"), - @Property(key = PARAMETER_PROXY_PORT, value = "4780") + @Property(key = PARAMETER_EXCHANGE_PROXY_HOST, value = "127.0.0.1"), + @Property(key = PARAMETER_EXCHANGE_PROXY_PORT, value = "4780") }) +@DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_CLASS) public class ExchangeSpecificationTest extends BaseTest { @Test diff --git a/spring-boot-starter/autoconfigure/src/test/java/tech/cassandre/trading/bot/test/configuration/parameters/InvalidCredentialsTest.java b/spring-boot-starter/autoconfigure/src/test/java/tech/cassandre/trading/bot/test/configuration/parameters/exchange/InvalidCredentialsTest.java similarity index 76% rename from spring-boot-starter/autoconfigure/src/test/java/tech/cassandre/trading/bot/test/configuration/parameters/InvalidCredentialsTest.java rename to spring-boot-starter/autoconfigure/src/test/java/tech/cassandre/trading/bot/test/configuration/parameters/exchange/InvalidCredentialsTest.java index 8cd79b4fd..4e021f2b0 100644 --- a/spring-boot-starter/autoconfigure/src/test/java/tech/cassandre/trading/bot/test/configuration/parameters/InvalidCredentialsTest.java +++ b/spring-boot-starter/autoconfigure/src/test/java/tech/cassandre/trading/bot/test/configuration/parameters/exchange/InvalidCredentialsTest.java @@ -1,20 +1,22 @@ -package tech.cassandre.trading.bot.test.configuration.parameters; +package tech.cassandre.trading.bot.test.configuration.parameters.exchange; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.springframework.boot.SpringApplication; +import org.springframework.test.annotation.DirtiesContext; import tech.cassandre.trading.bot.CassandreTradingBot; import tech.cassandre.trading.bot.test.util.junit.configuration.Configuration; import tech.cassandre.trading.bot.test.util.junit.configuration.Property; import static org.junit.jupiter.api.Assertions.assertTrue; import static org.junit.jupiter.api.Assertions.fail; -import static tech.cassandre.trading.bot.util.parameters.ExchangeParameters.PARAMETER_SECRET; +import static tech.cassandre.trading.bot.util.parameters.ExchangeParameters.PARAMETER_EXCHANGE_SECRET; -@DisplayName("Configuration parameters - Invalid credentials") +@DisplayName("Exchange parameters - Invalid credentials") @Configuration({ - @Property(key = PARAMETER_SECRET, value = "none") + @Property(key = PARAMETER_EXCHANGE_SECRET, value = "none") }) +@DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_CLASS) public class InvalidCredentialsTest { @Test diff --git a/spring-boot-starter/autoconfigure/src/test/java/tech/cassandre/trading/bot/test/configuration/parameters/InvalidRateForAccountTest.java b/spring-boot-starter/autoconfigure/src/test/java/tech/cassandre/trading/bot/test/configuration/parameters/exchange/InvalidRateForAccountTest.java similarity index 84% rename from spring-boot-starter/autoconfigure/src/test/java/tech/cassandre/trading/bot/test/configuration/parameters/InvalidRateForAccountTest.java rename to spring-boot-starter/autoconfigure/src/test/java/tech/cassandre/trading/bot/test/configuration/parameters/exchange/InvalidRateForAccountTest.java index c26639f69..0d56f4f9a 100644 --- a/spring-boot-starter/autoconfigure/src/test/java/tech/cassandre/trading/bot/test/configuration/parameters/InvalidRateForAccountTest.java +++ b/spring-boot-starter/autoconfigure/src/test/java/tech/cassandre/trading/bot/test/configuration/parameters/exchange/InvalidRateForAccountTest.java @@ -1,8 +1,9 @@ -package tech.cassandre.trading.bot.test.configuration.parameters; +package tech.cassandre.trading.bot.test.configuration.parameters.exchange; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.springframework.boot.SpringApplication; +import org.springframework.test.annotation.DirtiesContext; import tech.cassandre.trading.bot.CassandreTradingBot; import tech.cassandre.trading.bot.test.util.junit.BaseTest; import tech.cassandre.trading.bot.test.util.junit.configuration.Configuration; @@ -11,12 +12,13 @@ import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertTrue; import static org.junit.jupiter.api.Assertions.fail; -import static tech.cassandre.trading.bot.util.parameters.ExchangeParameters.Rates.PARAMETER_RATE_ACCOUNT; +import static tech.cassandre.trading.bot.util.parameters.ExchangeParameters.Rates.PARAMETER_EXCHANGE_RATE_ACCOUNT; -@DisplayName("Configuration parameters - Invalid account rate") +@DisplayName("Exchange parameters - Invalid account rate") @Configuration({ - @Property(key = PARAMETER_RATE_ACCOUNT, value = "A") + @Property(key = PARAMETER_EXCHANGE_RATE_ACCOUNT, value = "A") }) +@DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_CLASS) public class InvalidRateForAccountTest extends BaseTest { @Test diff --git a/spring-boot-starter/autoconfigure/src/test/java/tech/cassandre/trading/bot/test/configuration/parameters/InvalidRateForTickerTest.java b/spring-boot-starter/autoconfigure/src/test/java/tech/cassandre/trading/bot/test/configuration/parameters/exchange/InvalidRateForTickerTest.java similarity index 84% rename from spring-boot-starter/autoconfigure/src/test/java/tech/cassandre/trading/bot/test/configuration/parameters/InvalidRateForTickerTest.java rename to spring-boot-starter/autoconfigure/src/test/java/tech/cassandre/trading/bot/test/configuration/parameters/exchange/InvalidRateForTickerTest.java index 990f10c8a..8ae03ee07 100644 --- a/spring-boot-starter/autoconfigure/src/test/java/tech/cassandre/trading/bot/test/configuration/parameters/InvalidRateForTickerTest.java +++ b/spring-boot-starter/autoconfigure/src/test/java/tech/cassandre/trading/bot/test/configuration/parameters/exchange/InvalidRateForTickerTest.java @@ -1,8 +1,9 @@ -package tech.cassandre.trading.bot.test.configuration.parameters; +package tech.cassandre.trading.bot.test.configuration.parameters.exchange; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.springframework.boot.SpringApplication; +import org.springframework.test.annotation.DirtiesContext; import tech.cassandre.trading.bot.CassandreTradingBot; import tech.cassandre.trading.bot.test.util.junit.BaseTest; import tech.cassandre.trading.bot.test.util.junit.configuration.Configuration; @@ -11,12 +12,13 @@ import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertTrue; import static org.junit.jupiter.api.Assertions.fail; -import static tech.cassandre.trading.bot.util.parameters.ExchangeParameters.Rates.PARAMETER_RATE_TICKER; +import static tech.cassandre.trading.bot.util.parameters.ExchangeParameters.Rates.PARAMETER_EXCHANGE_RATE_TICKER; -@DisplayName("Configuration parameters - Invalid ticker rate") +@DisplayName("Exchange parameters - Invalid ticker rate") @Configuration({ - @Property(key = PARAMETER_RATE_TICKER, value = "AT20S") + @Property(key = PARAMETER_EXCHANGE_RATE_TICKER, value = "AT20S") }) +@DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_CLASS) public class InvalidRateForTickerTest extends BaseTest { @Test diff --git a/spring-boot-starter/autoconfigure/src/test/java/tech/cassandre/trading/bot/test/configuration/parameters/InvalidRateForTradeTest.java b/spring-boot-starter/autoconfigure/src/test/java/tech/cassandre/trading/bot/test/configuration/parameters/exchange/InvalidRateForTradeTest.java similarity index 84% rename from spring-boot-starter/autoconfigure/src/test/java/tech/cassandre/trading/bot/test/configuration/parameters/InvalidRateForTradeTest.java rename to spring-boot-starter/autoconfigure/src/test/java/tech/cassandre/trading/bot/test/configuration/parameters/exchange/InvalidRateForTradeTest.java index 4fe7256a7..e9265428d 100644 --- a/spring-boot-starter/autoconfigure/src/test/java/tech/cassandre/trading/bot/test/configuration/parameters/InvalidRateForTradeTest.java +++ b/spring-boot-starter/autoconfigure/src/test/java/tech/cassandre/trading/bot/test/configuration/parameters/exchange/InvalidRateForTradeTest.java @@ -1,8 +1,9 @@ -package tech.cassandre.trading.bot.test.configuration.parameters; +package tech.cassandre.trading.bot.test.configuration.parameters.exchange; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.springframework.boot.SpringApplication; +import org.springframework.test.annotation.DirtiesContext; import tech.cassandre.trading.bot.CassandreTradingBot; import tech.cassandre.trading.bot.test.util.junit.BaseTest; import tech.cassandre.trading.bot.test.util.junit.configuration.Configuration; @@ -11,12 +12,13 @@ import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertTrue; import static org.junit.jupiter.api.Assertions.fail; -import static tech.cassandre.trading.bot.util.parameters.ExchangeParameters.Rates.PARAMETER_RATE_TRADE; +import static tech.cassandre.trading.bot.util.parameters.ExchangeParameters.Rates.PARAMETER_EXCHANGE_RATE_TRADE; -@DisplayName("Configuration parameters - Invalid trade rate") +@DisplayName("Exchange parameters - Invalid trade rate") @Configuration({ - @Property(key = PARAMETER_RATE_TRADE, value = "AT20S") + @Property(key = PARAMETER_EXCHANGE_RATE_TRADE, value = "AT20S") }) +@DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_CLASS) public class InvalidRateForTradeTest extends BaseTest { @Test diff --git a/spring-boot-starter/autoconfigure/src/test/java/tech/cassandre/trading/bot/test/configuration/parameters/NameParameterMissingTest.java b/spring-boot-starter/autoconfigure/src/test/java/tech/cassandre/trading/bot/test/configuration/parameters/exchange/NameParameterMissingTest.java similarity index 85% rename from spring-boot-starter/autoconfigure/src/test/java/tech/cassandre/trading/bot/test/configuration/parameters/NameParameterMissingTest.java rename to spring-boot-starter/autoconfigure/src/test/java/tech/cassandre/trading/bot/test/configuration/parameters/exchange/NameParameterMissingTest.java index 1cf3b32b3..b857f21fd 100644 --- a/spring-boot-starter/autoconfigure/src/test/java/tech/cassandre/trading/bot/test/configuration/parameters/NameParameterMissingTest.java +++ b/spring-boot-starter/autoconfigure/src/test/java/tech/cassandre/trading/bot/test/configuration/parameters/exchange/NameParameterMissingTest.java @@ -1,8 +1,9 @@ -package tech.cassandre.trading.bot.test.configuration.parameters; +package tech.cassandre.trading.bot.test.configuration.parameters.exchange; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.springframework.boot.SpringApplication; +import org.springframework.test.annotation.DirtiesContext; import tech.cassandre.trading.bot.CassandreTradingBot; import tech.cassandre.trading.bot.test.util.junit.BaseTest; import tech.cassandre.trading.bot.test.util.junit.configuration.Configuration; @@ -11,12 +12,13 @@ import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertTrue; import static org.junit.jupiter.api.Assertions.fail; -import static tech.cassandre.trading.bot.util.parameters.ExchangeParameters.PARAMETER_NAME; +import static tech.cassandre.trading.bot.util.parameters.ExchangeParameters.PARAMETER_EXCHANGE_NAME; -@DisplayName("Configuration parameters - Name parameter is missing") +@DisplayName("Exchange parameters - Name parameter is missing") @Configuration({ - @Property(key = PARAMETER_NAME) + @Property(key = PARAMETER_EXCHANGE_NAME) }) +@DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_CLASS) public class NameParameterMissingTest extends BaseTest { @Test diff --git a/spring-boot-starter/autoconfigure/src/test/java/tech/cassandre/trading/bot/test/configuration/parameters/NoConfigurationTest.java b/spring-boot-starter/autoconfigure/src/test/java/tech/cassandre/trading/bot/test/configuration/parameters/exchange/NoConfigurationTest.java similarity index 56% rename from spring-boot-starter/autoconfigure/src/test/java/tech/cassandre/trading/bot/test/configuration/parameters/NoConfigurationTest.java rename to spring-boot-starter/autoconfigure/src/test/java/tech/cassandre/trading/bot/test/configuration/parameters/exchange/NoConfigurationTest.java index 638a64315..7a3671b6f 100644 --- a/spring-boot-starter/autoconfigure/src/test/java/tech/cassandre/trading/bot/test/configuration/parameters/NoConfigurationTest.java +++ b/spring-boot-starter/autoconfigure/src/test/java/tech/cassandre/trading/bot/test/configuration/parameters/exchange/NoConfigurationTest.java @@ -1,8 +1,9 @@ -package tech.cassandre.trading.bot.test.configuration.parameters; +package tech.cassandre.trading.bot.test.configuration.parameters.exchange; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.springframework.boot.SpringApplication; +import org.springframework.test.annotation.DirtiesContext; import tech.cassandre.trading.bot.CassandreTradingBot; import tech.cassandre.trading.bot.test.util.junit.BaseTest; import tech.cassandre.trading.bot.test.util.junit.configuration.Configuration; @@ -10,30 +11,31 @@ import static org.junit.jupiter.api.Assertions.assertTrue; import static org.junit.jupiter.api.Assertions.fail; -import static tech.cassandre.trading.bot.util.parameters.ExchangeParameters.Modes.PARAMETER_DRY; -import static tech.cassandre.trading.bot.util.parameters.ExchangeParameters.Modes.PARAMETER_SANDBOX; -import static tech.cassandre.trading.bot.util.parameters.ExchangeParameters.PARAMETER_KEY; -import static tech.cassandre.trading.bot.util.parameters.ExchangeParameters.PARAMETER_NAME; -import static tech.cassandre.trading.bot.util.parameters.ExchangeParameters.PARAMETER_PASSPHRASE; -import static tech.cassandre.trading.bot.util.parameters.ExchangeParameters.PARAMETER_SECRET; -import static tech.cassandre.trading.bot.util.parameters.ExchangeParameters.PARAMETER_USERNAME; -import static tech.cassandre.trading.bot.util.parameters.ExchangeParameters.Rates.PARAMETER_RATE_ACCOUNT; -import static tech.cassandre.trading.bot.util.parameters.ExchangeParameters.Rates.PARAMETER_RATE_TICKER; -import static tech.cassandre.trading.bot.util.parameters.ExchangeParameters.Rates.PARAMETER_RATE_TRADE; +import static tech.cassandre.trading.bot.util.parameters.ExchangeParameters.Modes.PARAMETER_EXCHANGE_DRY; +import static tech.cassandre.trading.bot.util.parameters.ExchangeParameters.Modes.PARAMETER_EXCHANGE_SANDBOX; +import static tech.cassandre.trading.bot.util.parameters.ExchangeParameters.PARAMETER_EXCHANGE_KEY; +import static tech.cassandre.trading.bot.util.parameters.ExchangeParameters.PARAMETER_EXCHANGE_NAME; +import static tech.cassandre.trading.bot.util.parameters.ExchangeParameters.PARAMETER_EXCHANGE_PASSPHRASE; +import static tech.cassandre.trading.bot.util.parameters.ExchangeParameters.PARAMETER_EXCHANGE_SECRET; +import static tech.cassandre.trading.bot.util.parameters.ExchangeParameters.PARAMETER_EXCHANGE_USERNAME; +import static tech.cassandre.trading.bot.util.parameters.ExchangeParameters.Rates.PARAMETER_EXCHANGE_RATE_ACCOUNT; +import static tech.cassandre.trading.bot.util.parameters.ExchangeParameters.Rates.PARAMETER_EXCHANGE_RATE_TICKER; +import static tech.cassandre.trading.bot.util.parameters.ExchangeParameters.Rates.PARAMETER_EXCHANGE_RATE_TRADE; -@DisplayName("Configuration parameters - No configuration") +@DisplayName("Exchange parameters - No configuration") @Configuration({ - @Property(key = PARAMETER_NAME), - @Property(key = PARAMETER_SANDBOX), - @Property(key = PARAMETER_DRY), - @Property(key = PARAMETER_USERNAME), - @Property(key = PARAMETER_PASSPHRASE), - @Property(key = PARAMETER_KEY), - @Property(key = PARAMETER_SECRET), - @Property(key = PARAMETER_RATE_ACCOUNT), - @Property(key = PARAMETER_RATE_TICKER), - @Property(key = PARAMETER_RATE_TRADE) + @Property(key = PARAMETER_EXCHANGE_NAME), + @Property(key = PARAMETER_EXCHANGE_SANDBOX), + @Property(key = PARAMETER_EXCHANGE_DRY), + @Property(key = PARAMETER_EXCHANGE_USERNAME), + @Property(key = PARAMETER_EXCHANGE_PASSPHRASE), + @Property(key = PARAMETER_EXCHANGE_KEY), + @Property(key = PARAMETER_EXCHANGE_SECRET), + @Property(key = PARAMETER_EXCHANGE_RATE_ACCOUNT), + @Property(key = PARAMETER_EXCHANGE_RATE_TICKER), + @Property(key = PARAMETER_EXCHANGE_RATE_TRADE) }) +@DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_CLASS) public class NoConfigurationTest extends BaseTest { @Test @@ -45,17 +47,17 @@ public void checkErrorMessages() { fail("Exception not raised"); } catch (Exception e) { final String message = getParametersExceptionMessage(e); + e.printStackTrace(); assertTrue(message.contains("'name'")); assertTrue(message.contains("'username'")); assertTrue(message.contains("'passphrase'")); assertTrue(message.contains("'key'")); assertTrue(message.contains("'secret'")); - // TODO Find why the message error doesn't appear on nested fields. -// assertTrue(message.contains("'sandbox'")); -// assertTrue(message.contains("'dry'")); -// assertTrue(message.contains("Invalid account rate")); -// assertTrue(message.contains("Invalid ticker rate")); -// assertTrue(message.contains("Invalid order rate")); + assertTrue(message.contains("'modes.sandbox'")); + assertTrue(message.contains("'modes.dry'")); + assertTrue(message.contains("rates.account")); + assertTrue(message.contains("rates.ticker")); + assertTrue(message.contains("rates.trade")); } } diff --git a/spring-boot-starter/autoconfigure/src/test/java/tech/cassandre/trading/bot/test/configuration/parameters/UnknownExchangeTest.java b/spring-boot-starter/autoconfigure/src/test/java/tech/cassandre/trading/bot/test/configuration/parameters/exchange/UnknownExchangeTest.java similarity index 79% rename from spring-boot-starter/autoconfigure/src/test/java/tech/cassandre/trading/bot/test/configuration/parameters/UnknownExchangeTest.java rename to spring-boot-starter/autoconfigure/src/test/java/tech/cassandre/trading/bot/test/configuration/parameters/exchange/UnknownExchangeTest.java index df8276da9..23eb2777f 100644 --- a/spring-boot-starter/autoconfigure/src/test/java/tech/cassandre/trading/bot/test/configuration/parameters/UnknownExchangeTest.java +++ b/spring-boot-starter/autoconfigure/src/test/java/tech/cassandre/trading/bot/test/configuration/parameters/exchange/UnknownExchangeTest.java @@ -1,8 +1,9 @@ -package tech.cassandre.trading.bot.test.configuration.parameters; +package tech.cassandre.trading.bot.test.configuration.parameters.exchange; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.springframework.boot.SpringApplication; +import org.springframework.test.annotation.DirtiesContext; import tech.cassandre.trading.bot.CassandreTradingBot; import tech.cassandre.trading.bot.test.util.junit.BaseTest; import tech.cassandre.trading.bot.test.util.junit.configuration.Configuration; @@ -10,12 +11,13 @@ import static org.junit.jupiter.api.Assertions.assertTrue; import static org.junit.jupiter.api.Assertions.fail; -import static tech.cassandre.trading.bot.util.parameters.ExchangeParameters.PARAMETER_NAME; +import static tech.cassandre.trading.bot.util.parameters.ExchangeParameters.PARAMETER_EXCHANGE_NAME; -@DisplayName("Configuration parameters - Unknown exchange name") +@DisplayName("Exchange parameters - Unknown exchange name") @Configuration({ - @Property(key = PARAMETER_NAME, value = "foo") + @Property(key = PARAMETER_EXCHANGE_NAME, value = "foo") }) +@DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_CLASS) public class UnknownExchangeTest extends BaseTest { @Test diff --git a/spring-boot-starter/autoconfigure/src/test/java/tech/cassandre/trading/bot/test/configuration/parameters/ValidConfigurationTest.java b/spring-boot-starter/autoconfigure/src/test/java/tech/cassandre/trading/bot/test/configuration/parameters/exchange/ValidConfigurationTest.java similarity index 81% rename from spring-boot-starter/autoconfigure/src/test/java/tech/cassandre/trading/bot/test/configuration/parameters/ValidConfigurationTest.java rename to spring-boot-starter/autoconfigure/src/test/java/tech/cassandre/trading/bot/test/configuration/parameters/exchange/ValidConfigurationTest.java index b050531c1..95c36e152 100644 --- a/spring-boot-starter/autoconfigure/src/test/java/tech/cassandre/trading/bot/test/configuration/parameters/ValidConfigurationTest.java +++ b/spring-boot-starter/autoconfigure/src/test/java/tech/cassandre/trading/bot/test/configuration/parameters/exchange/ValidConfigurationTest.java @@ -1,8 +1,9 @@ -package tech.cassandre.trading.bot.test.configuration.parameters; +package tech.cassandre.trading.bot.test.configuration.parameters.exchange; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.springframework.boot.SpringApplication; +import org.springframework.test.annotation.DirtiesContext; import tech.cassandre.trading.bot.CassandreTradingBot; import tech.cassandre.trading.bot.test.util.junit.BaseTest; import tech.cassandre.trading.bot.test.util.junit.configuration.Configuration; @@ -12,8 +13,9 @@ @DisplayName("Configuration parameters - Valid configuration") @Configuration({ - @Property(key = "TEST_NAME", value = "Configuration parameters - Valid configuration") + @Property(key = "TEST_NAME", value = "Exchange parameters - Valid configuration") }) +@DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_CLASS) public class ValidConfigurationTest extends BaseTest { @Test diff --git a/spring-boot-starter/autoconfigure/src/test/java/tech/cassandre/trading/bot/test/configuration/parameters/exchange/package-info.java b/spring-boot-starter/autoconfigure/src/test/java/tech/cassandre/trading/bot/test/configuration/parameters/exchange/package-info.java new file mode 100644 index 000000000..d7273e828 --- /dev/null +++ b/spring-boot-starter/autoconfigure/src/test/java/tech/cassandre/trading/bot/test/configuration/parameters/exchange/package-info.java @@ -0,0 +1,4 @@ +/** + * Exchange parameters tests. + */ +package tech.cassandre.trading.bot.test.configuration.parameters.exchange; \ No newline at end of file diff --git a/spring-boot-starter/autoconfigure/src/test/java/tech/cassandre/trading/bot/test/configuration/strategy/CassandreStrategyAutoConfigurationTest.java b/spring-boot-starter/autoconfigure/src/test/java/tech/cassandre/trading/bot/test/configuration/strategy/CassandreStrategyAutoConfigurationTest.java index 24dc747b4..21123ea13 100644 --- a/spring-boot-starter/autoconfigure/src/test/java/tech/cassandre/trading/bot/test/configuration/strategy/CassandreStrategyAutoConfigurationTest.java +++ b/spring-boot-starter/autoconfigure/src/test/java/tech/cassandre/trading/bot/test/configuration/strategy/CassandreStrategyAutoConfigurationTest.java @@ -3,6 +3,7 @@ import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.springframework.boot.SpringApplication; +import org.springframework.test.annotation.DirtiesContext; import tech.cassandre.trading.bot.CassandreTradingBot; import tech.cassandre.trading.bot.test.util.junit.configuration.Configuration; import tech.cassandre.trading.bot.test.util.junit.configuration.Property; @@ -22,6 +23,7 @@ @Property(key = PARAMETER_TESTABLE_TA4J_STRATEGY_ENABLED, value = "false"), @Property(key = PARAMETER_NO_TRADING_ACCOUNT_STRATEGY_ENABLED, value = "false"), }) +@DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_CLASS) public class CassandreStrategyAutoConfigurationTest { @Test diff --git a/spring-boot-starter/autoconfigure/src/test/java/tech/cassandre/trading/bot/test/configuration/strategy/CassandreStrategyServicesTest.java b/spring-boot-starter/autoconfigure/src/test/java/tech/cassandre/trading/bot/test/configuration/strategy/CassandreStrategyServicesTest.java index 4e56d6ea1..09b8cc2ba 100644 --- a/spring-boot-starter/autoconfigure/src/test/java/tech/cassandre/trading/bot/test/configuration/strategy/CassandreStrategyServicesTest.java +++ b/spring-boot-starter/autoconfigure/src/test/java/tech/cassandre/trading/bot/test/configuration/strategy/CassandreStrategyServicesTest.java @@ -4,6 +4,7 @@ import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.annotation.DirtiesContext; import tech.cassandre.trading.bot.test.util.junit.configuration.Configuration; import tech.cassandre.trading.bot.test.util.junit.configuration.Property; import tech.cassandre.trading.bot.test.util.strategies.TestableCassandreStrategy; @@ -15,6 +16,7 @@ @Configuration({ @Property(key = "TEST_NAME", value = "Strategy configuration - Trade & position services") }) +@DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_EACH_TEST_METHOD) public class CassandreStrategyServicesTest { @Autowired diff --git a/spring-boot-starter/autoconfigure/src/test/java/tech/cassandre/trading/bot/test/dto/PositionDTOTest.java b/spring-boot-starter/autoconfigure/src/test/java/tech/cassandre/trading/bot/test/dto/PositionDTOTest.java index 8f78c035f..fe57342cc 100644 --- a/spring-boot-starter/autoconfigure/src/test/java/tech/cassandre/trading/bot/test/dto/PositionDTOTest.java +++ b/spring-boot-starter/autoconfigure/src/test/java/tech/cassandre/trading/bot/test/dto/PositionDTOTest.java @@ -333,7 +333,7 @@ public void checkToString() { // A new ticker arrived. TickerDTO t1 = TickerDTO.builder().currencyPair(new CurrencyPairDTO(ETH, BTC)).last(new BigDecimal("2")).create(); p2.shouldBeClosed(t1); - assertEquals(p2.toString(), "Position n°2 (11.0 % loss rule) on ETH/BTC - Opened - Last gain calculated 100.0 %"); + assertEquals(p2.toString(), "Position n°2 (11.0 % loss rule) on ETH/BTC - Opened - Last gain calculated 100 %"); // Position closing. PositionDTO p3 = new PositionDTO(3L, @@ -378,7 +378,7 @@ public void checkToString() { null, null); p4.tradeUpdate(closeTrade4); - assertEquals(p4.toString(), "Position n°4 (12.0 % gain rule / 9.0 % loss rule) on ETH/BTC - Closed - Gain : 100.0 %"); + assertEquals(p4.toString(), "Position n°4 (12.0 % gain rule / 9.0 % loss rule) on ETH/BTC - Closed - Gain : 100 %"); } } diff --git a/spring-boot-starter/autoconfigure/src/test/java/tech/cassandre/trading/bot/test/modes/dry/ExchangeServiceDryModeTest.java b/spring-boot-starter/autoconfigure/src/test/java/tech/cassandre/trading/bot/test/modes/dry/ExchangeServiceDryModeTest.java index 663b13495..8de91fd0c 100644 --- a/spring-boot-starter/autoconfigure/src/test/java/tech/cassandre/trading/bot/test/modes/dry/ExchangeServiceDryModeTest.java +++ b/spring-boot-starter/autoconfigure/src/test/java/tech/cassandre/trading/bot/test/modes/dry/ExchangeServiceDryModeTest.java @@ -18,15 +18,15 @@ import static tech.cassandre.trading.bot.dto.util.CurrencyDTO.BTC; import static tech.cassandre.trading.bot.dto.util.CurrencyDTO.ETH; import static tech.cassandre.trading.bot.dto.util.CurrencyDTO.USDT; -import static tech.cassandre.trading.bot.util.parameters.ExchangeParameters.Modes.PARAMETER_DRY; +import static tech.cassandre.trading.bot.util.parameters.ExchangeParameters.Modes.PARAMETER_EXCHANGE_DRY; @SpringBootTest @DisplayName("Dry mode - Exchange service") @ActiveProfiles("schedule-disabled") @Configuration({ - @Property(key = PARAMETER_DRY, value = "true") + @Property(key = PARAMETER_EXCHANGE_DRY, value = "true") }) -@DirtiesContext(classMode = DirtiesContext.ClassMode.BEFORE_EACH_TEST_METHOD) +@DirtiesContext(classMode = DirtiesContext.ClassMode.BEFORE_CLASS) public class ExchangeServiceDryModeTest { @Autowired diff --git a/spring-boot-starter/autoconfigure/src/test/java/tech/cassandre/trading/bot/test/modes/dry/PositionServiceDryModeTest.java b/spring-boot-starter/autoconfigure/src/test/java/tech/cassandre/trading/bot/test/modes/dry/PositionServiceDryModeTest.java index a8b1af989..3a7f186fe 100644 --- a/spring-boot-starter/autoconfigure/src/test/java/tech/cassandre/trading/bot/test/modes/dry/PositionServiceDryModeTest.java +++ b/spring-boot-starter/autoconfigure/src/test/java/tech/cassandre/trading/bot/test/modes/dry/PositionServiceDryModeTest.java @@ -31,16 +31,16 @@ import static tech.cassandre.trading.bot.dto.util.CurrencyDTO.BTC; import static tech.cassandre.trading.bot.dto.util.CurrencyDTO.ETH; import static tech.cassandre.trading.bot.dto.util.CurrencyDTO.USDT; -import static tech.cassandre.trading.bot.util.parameters.ExchangeParameters.Modes.PARAMETER_DRY; +import static tech.cassandre.trading.bot.util.parameters.ExchangeParameters.Modes.PARAMETER_EXCHANGE_DRY; @SpringBootTest @DisplayName("Dry mode - Position service") @ActiveProfiles("schedule-disabled") @Configuration({ - @Property(key = PARAMETER_DRY, value = "true") + @Property(key = PARAMETER_EXCHANGE_DRY, value = "true") }) -@DirtiesContext(classMode = DirtiesContext.ClassMode.BEFORE_EACH_TEST_METHOD) +@DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_CLASS) @Import(PositionServiceDryModeTestMock.class) public class PositionServiceDryModeTest extends BaseTest { diff --git a/spring-boot-starter/autoconfigure/src/test/java/tech/cassandre/trading/bot/test/modes/dry/TradeServiceDryModeTest.java b/spring-boot-starter/autoconfigure/src/test/java/tech/cassandre/trading/bot/test/modes/dry/TradeServiceDryModeTest.java index 809794d5b..409afcc58 100644 --- a/spring-boot-starter/autoconfigure/src/test/java/tech/cassandre/trading/bot/test/modes/dry/TradeServiceDryModeTest.java +++ b/spring-boot-starter/autoconfigure/src/test/java/tech/cassandre/trading/bot/test/modes/dry/TradeServiceDryModeTest.java @@ -31,15 +31,15 @@ import static tech.cassandre.trading.bot.dto.trade.OrderTypeDTO.BID; import static tech.cassandre.trading.bot.dto.util.CurrencyDTO.BTC; import static tech.cassandre.trading.bot.dto.util.CurrencyDTO.ETH; -import static tech.cassandre.trading.bot.util.parameters.ExchangeParameters.Modes.PARAMETER_DRY; +import static tech.cassandre.trading.bot.util.parameters.ExchangeParameters.Modes.PARAMETER_EXCHANGE_DRY; @SpringBootTest @DisplayName("Dry mode - Trade service") @ActiveProfiles("schedule-disabled") @Configuration({ - @Property(key = PARAMETER_DRY, value = "true") + @Property(key = PARAMETER_EXCHANGE_DRY, value = "true") }) -@DirtiesContext(classMode = DirtiesContext.ClassMode.BEFORE_EACH_TEST_METHOD) +@DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_CLASS) @Import(TradeServiceDryModeTestMock.class) public class TradeServiceDryModeTest extends BaseTest { diff --git a/spring-boot-starter/autoconfigure/src/test/java/tech/cassandre/trading/bot/test/modes/dry/UserServiceDryModeTest.java b/spring-boot-starter/autoconfigure/src/test/java/tech/cassandre/trading/bot/test/modes/dry/UserServiceDryModeTest.java index f18c645b0..7a159e7b8 100644 --- a/spring-boot-starter/autoconfigure/src/test/java/tech/cassandre/trading/bot/test/modes/dry/UserServiceDryModeTest.java +++ b/spring-boot-starter/autoconfigure/src/test/java/tech/cassandre/trading/bot/test/modes/dry/UserServiceDryModeTest.java @@ -39,15 +39,15 @@ import static tech.cassandre.trading.bot.dto.util.CurrencyDTO.ETH; import static tech.cassandre.trading.bot.dto.util.CurrencyDTO.EUR; import static tech.cassandre.trading.bot.dto.util.CurrencyDTO.USDT; -import static tech.cassandre.trading.bot.util.parameters.ExchangeParameters.Modes.PARAMETER_DRY; +import static tech.cassandre.trading.bot.util.parameters.ExchangeParameters.Modes.PARAMETER_EXCHANGE_DRY; @SpringBootTest @DisplayName("Dry mode - User service") @ActiveProfiles("schedule-disabled") @Configuration({ - @Property(key = PARAMETER_DRY, value = "true") + @Property(key = PARAMETER_EXCHANGE_DRY, value = "true") }) -@DirtiesContext(classMode = DirtiesContext.ClassMode.BEFORE_EACH_TEST_METHOD) +@DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_CLASS) @Import(TradeServiceDryModeTestMock.class) public class UserServiceDryModeTest extends BaseTest { diff --git a/spring-boot-starter/autoconfigure/src/test/java/tech/cassandre/trading/bot/test/service/PositionServiceTest.java b/spring-boot-starter/autoconfigure/src/test/java/tech/cassandre/trading/bot/test/service/PositionServiceTest.java index a57aadb95..30aa358a6 100644 --- a/spring-boot-starter/autoconfigure/src/test/java/tech/cassandre/trading/bot/test/service/PositionServiceTest.java +++ b/spring-boot-starter/autoconfigure/src/test/java/tech/cassandre/trading/bot/test/service/PositionServiceTest.java @@ -45,8 +45,8 @@ @Configuration({ @Property(key = "TEST_NAME", value = "Configuration parameters - Valid configuration") }) +@DirtiesContext(classMode = DirtiesContext.ClassMode.BEFORE_EACH_TEST_METHOD) @Import(PositionServiceTestMock.class) -@DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_EACH_TEST_METHOD) public class PositionServiceTest extends BaseTest { @Autowired diff --git a/spring-boot-starter/autoconfigure/src/test/java/tech/cassandre/trading/bot/test/service/RatesTest.java b/spring-boot-starter/autoconfigure/src/test/java/tech/cassandre/trading/bot/test/service/RatesTest.java index f3c769499..331fe5e98 100644 --- a/spring-boot-starter/autoconfigure/src/test/java/tech/cassandre/trading/bot/test/service/RatesTest.java +++ b/spring-boot-starter/autoconfigure/src/test/java/tech/cassandre/trading/bot/test/service/RatesTest.java @@ -21,17 +21,17 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static tech.cassandre.trading.bot.dto.util.CurrencyDTO.BTC; import static tech.cassandre.trading.bot.dto.util.CurrencyDTO.ETH; -import static tech.cassandre.trading.bot.util.parameters.ExchangeParameters.Rates.PARAMETER_RATE_ACCOUNT; -import static tech.cassandre.trading.bot.util.parameters.ExchangeParameters.Rates.PARAMETER_RATE_TICKER; -import static tech.cassandre.trading.bot.util.parameters.ExchangeParameters.Rates.PARAMETER_RATE_TRADE; +import static tech.cassandre.trading.bot.util.parameters.ExchangeParameters.Rates.PARAMETER_EXCHANGE_RATE_ACCOUNT; +import static tech.cassandre.trading.bot.util.parameters.ExchangeParameters.Rates.PARAMETER_EXCHANGE_RATE_TICKER; +import static tech.cassandre.trading.bot.util.parameters.ExchangeParameters.Rates.PARAMETER_EXCHANGE_RATE_TRADE; @SpringBootTest @DisplayName("Services - Rates") @ActiveProfiles("schedule-disabled") @Configuration({ - @Property(key = PARAMETER_RATE_ACCOUNT, value = "PT10S"), // 10 seconds. - @Property(key = PARAMETER_RATE_TICKER, value = "PT15S"), // 15 seconds. - @Property(key = PARAMETER_RATE_TRADE, value = "PT20S") // 20 seconds. + @Property(key = PARAMETER_EXCHANGE_RATE_ACCOUNT, value = "PT10S"), // 10 seconds. + @Property(key = PARAMETER_EXCHANGE_RATE_TICKER, value = "PT15S"), // 15 seconds. + @Property(key = PARAMETER_EXCHANGE_RATE_TRADE, value = "PT20S") // 20 seconds. }) @DirtiesContext(classMode = DirtiesContext.ClassMode.BEFORE_EACH_TEST_METHOD) public class RatesTest { diff --git a/spring-boot-starter/autoconfigure/src/test/java/tech/cassandre/trading/bot/test/strategy/BasicCassandreStrategyTest.java b/spring-boot-starter/autoconfigure/src/test/java/tech/cassandre/trading/bot/test/strategy/BasicCassandreStrategyTest.java index f1614820a..3b63863d5 100644 --- a/spring-boot-starter/autoconfigure/src/test/java/tech/cassandre/trading/bot/test/strategy/BasicCassandreStrategyTest.java +++ b/spring-boot-starter/autoconfigure/src/test/java/tech/cassandre/trading/bot/test/strategy/BasicCassandreStrategyTest.java @@ -5,6 +5,7 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.context.annotation.Import; +import org.springframework.test.annotation.DirtiesContext; import tech.cassandre.trading.bot.dto.user.AccountDTO; import tech.cassandre.trading.bot.dto.util.CurrencyPairDTO; import tech.cassandre.trading.bot.test.strategy.mocks.BasicCassandreStrategyTestMock; @@ -38,6 +39,7 @@ @Property(key = PARAMETER_TESTABLE_TA4J_STRATEGY_ENABLED, value = "false"), @Property(key = PARAMETER_NO_TRADING_ACCOUNT_STRATEGY_ENABLED, value = "false") }) +@DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_CLASS) @Import(BasicCassandreStrategyTestMock.class) public class BasicCassandreStrategyTest extends BaseTest { diff --git a/spring-boot-starter/autoconfigure/src/test/java/tech/cassandre/trading/bot/test/strategy/BasicTa4jCassandreStrategyTest.java b/spring-boot-starter/autoconfigure/src/test/java/tech/cassandre/trading/bot/test/strategy/BasicTa4jCassandreStrategyTest.java index 69191681c..cc9627b6b 100644 --- a/spring-boot-starter/autoconfigure/src/test/java/tech/cassandre/trading/bot/test/strategy/BasicTa4jCassandreStrategyTest.java +++ b/spring-boot-starter/autoconfigure/src/test/java/tech/cassandre/trading/bot/test/strategy/BasicTa4jCassandreStrategyTest.java @@ -5,6 +5,7 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.context.annotation.Import; +import org.springframework.test.annotation.DirtiesContext; import tech.cassandre.trading.bot.dto.user.AccountDTO; import tech.cassandre.trading.bot.dto.util.CurrencyPairDTO; import tech.cassandre.trading.bot.test.strategy.mocks.BasicTa4jCassandreStrategyTestMock; @@ -35,6 +36,7 @@ @Property(key = PARAMETER_TESTABLE_TA4J_STRATEGY_ENABLED, value = "true"), @Property(key = PARAMETER_NO_TRADING_ACCOUNT_STRATEGY_ENABLED, value = "false") }) +@DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_CLASS) @Import(BasicTa4jCassandreStrategyTestMock.class) public class BasicTa4jCassandreStrategyTest extends BaseTest { diff --git a/spring-boot-starter/autoconfigure/src/test/java/tech/cassandre/trading/bot/test/util/junit/configuration/ConfigurationExtension.java b/spring-boot-starter/autoconfigure/src/test/java/tech/cassandre/trading/bot/test/util/junit/configuration/ConfigurationExtension.java index 428f28975..3c56476ed 100644 --- a/spring-boot-starter/autoconfigure/src/test/java/tech/cassandre/trading/bot/test/util/junit/configuration/ConfigurationExtension.java +++ b/spring-boot-starter/autoconfigure/src/test/java/tech/cassandre/trading/bot/test/util/junit/configuration/ConfigurationExtension.java @@ -12,21 +12,26 @@ import static tech.cassandre.trading.bot.test.util.strategies.InvalidStrategy.PARAMETER_INVALID_STRATEGY_ENABLED; import static tech.cassandre.trading.bot.test.util.strategies.NoTradingAccountStrategy.PARAMETER_NO_TRADING_ACCOUNT_STRATEGY_ENABLED; import static tech.cassandre.trading.bot.test.util.strategies.TestableCassandreStrategy.PARAMETER_TESTABLE_STRATEGY_ENABLED; -import static tech.cassandre.trading.bot.util.parameters.ExchangeParameters.Modes.PARAMETER_DRY; -import static tech.cassandre.trading.bot.util.parameters.ExchangeParameters.Modes.PARAMETER_SANDBOX; -import static tech.cassandre.trading.bot.util.parameters.ExchangeParameters.PARAMETER_KEY; -import static tech.cassandre.trading.bot.util.parameters.ExchangeParameters.PARAMETER_NAME; -import static tech.cassandre.trading.bot.util.parameters.ExchangeParameters.PARAMETER_PASSPHRASE; -import static tech.cassandre.trading.bot.util.parameters.ExchangeParameters.PARAMETER_SECRET; -import static tech.cassandre.trading.bot.util.parameters.ExchangeParameters.PARAMETER_USERNAME; -import static tech.cassandre.trading.bot.util.parameters.ExchangeParameters.Rates.PARAMETER_RATE_ACCOUNT; -import static tech.cassandre.trading.bot.util.parameters.ExchangeParameters.Rates.PARAMETER_RATE_TRADE; -import static tech.cassandre.trading.bot.util.parameters.ExchangeParameters.Rates.PARAMETER_RATE_TICKER; +import static tech.cassandre.trading.bot.util.parameters.DatabaseParameters.Datasource.PARAMETER_DATABASE_DATASOURCE_DRIVER_CLASS_NAME; +import static tech.cassandre.trading.bot.util.parameters.DatabaseParameters.Datasource.PARAMETER_DATABASE_DATASOURCE_PASSWORD; +import static tech.cassandre.trading.bot.util.parameters.DatabaseParameters.Datasource.PARAMETER_DATABASE_DATASOURCE_URL; +import static tech.cassandre.trading.bot.util.parameters.DatabaseParameters.Datasource.PARAMETER_DATABASE_DATASOURCE_USERNAME; +import static tech.cassandre.trading.bot.util.parameters.DatabaseParameters.PARAMETER_DATABASE_TABLE_PREFIX; +import static tech.cassandre.trading.bot.util.parameters.ExchangeParameters.Modes.PARAMETER_EXCHANGE_DRY; +import static tech.cassandre.trading.bot.util.parameters.ExchangeParameters.Modes.PARAMETER_EXCHANGE_SANDBOX; +import static tech.cassandre.trading.bot.util.parameters.ExchangeParameters.PARAMETER_EXCHANGE_KEY; +import static tech.cassandre.trading.bot.util.parameters.ExchangeParameters.PARAMETER_EXCHANGE_NAME; +import static tech.cassandre.trading.bot.util.parameters.ExchangeParameters.PARAMETER_EXCHANGE_PASSPHRASE; +import static tech.cassandre.trading.bot.util.parameters.ExchangeParameters.PARAMETER_EXCHANGE_SECRET; +import static tech.cassandre.trading.bot.util.parameters.ExchangeParameters.PARAMETER_EXCHANGE_USERNAME; +import static tech.cassandre.trading.bot.util.parameters.ExchangeParameters.Rates.PARAMETER_EXCHANGE_RATE_ACCOUNT; +import static tech.cassandre.trading.bot.util.parameters.ExchangeParameters.Rates.PARAMETER_EXCHANGE_RATE_TICKER; +import static tech.cassandre.trading.bot.util.parameters.ExchangeParameters.Rates.PARAMETER_EXCHANGE_RATE_TRADE; /** * Configuration extension - set and clear system properties. */ -@NotThreadSafe // system properties are JVM-global, so don't run tests using this rule in parallel +@NotThreadSafe // System properties are JVM-global, so don't run tests in parallel with this rule. public class ConfigurationExtension implements BeforeAllCallback, AfterAllCallback { /** Invalid strategy enabled parameter default value. */ @@ -71,23 +76,47 @@ public class ConfigurationExtension implements BeforeAllCallback, AfterAllCallba /** Rate for trade parameter. */ public static final String PARAMETER_RATE_TRADE_DEFAULT_VALUE = "102"; + /** Database datasource driver. */ + public static final String PARAMETER_DATABASE_DATASOURCE_DRIVER_CLASS_NAME_DEFAULT_VALUE = "org.hsqldb.jdbc.JDBCDriver"; + + /** Database datasource url. */ + public static final String PARAMETER_DATABASE_DATASOURCE_URL_DEFAULT_VALUE = "jdbc:hsqldb:mem:cassandre-database;shutdown=true"; + + /** Database datasource username. */ + public static final String PARAMETER_DATABASE_DATASOURCE_USERNAME_DEFAULT_VALUE = "sa"; + + /** Database datasource password. */ + public static final String PARAMETER_DATABASE_DATASOURCE_PASSWORD_DEFAULT_VALUE = ""; + + /** Table prefix. */ + public static final String PARAMETER_DATABASE_TABLE_PREFIX_DEFAULT_VALUE = "MY_STRATEGY_"; + @Override public void beforeAll(ExtensionContext context) { - // Default values. - System.setProperty(PARAMETER_NAME, PARAMETER_NAME_DEFAULT_VALUE); // Kucoin - System.setProperty(PARAMETER_SANDBOX, PARAMETER_SANDBOX_DEFAULT_VALUE); // true - System.setProperty(PARAMETER_DRY, PARAMETER_DRY_DEFAULT_VALUE); // false - System.setProperty(PARAMETER_USERNAME, PARAMETER_USERNAME_DEFAULT_VALUE); // cassandre.crypto.bot@gmail.com - System.setProperty(PARAMETER_PASSPHRASE, PARAMETER_PASSPHRASE_DEFAULT_VALUE); // cassandre - System.setProperty(PARAMETER_KEY, PARAMETER_KEY_DEFAULT_VALUE); // 5df8eea30092f40009cb3c6a - System.setProperty(PARAMETER_SECRET, PARAMETER_SECRET_DEFAULT_VALUE); // 5f6e91e0-796b-4947-b75e-eaa5c06b6bed - System.setProperty(PARAMETER_RATE_ACCOUNT, PARAMETER_RATE_ACCOUNT_DEFAULT_VALUE); // 100 - System.setProperty(PARAMETER_RATE_TICKER, PARAMETER_RATE_TICKER_DEFAULT_VALUE); // 101 - System.setProperty(PARAMETER_RATE_TRADE, PARAMETER_RATE_TRADE_DEFAULT_VALUE); // 102 - System.setProperty(PARAMETER_INVALID_STRATEGY_ENABLED, PARAMETER_INVALID_STRATEGY_DEFAULT_VALUE); // false - System.setProperty(PARAMETER_TESTABLE_STRATEGY_ENABLED, PARAMETER_TESTABLE_STRATEGY_DEFAULT_VALUE); // true - System.setProperty(PARAMETER_TESTABLE_TA4J_STRATEGY_DEFAULT_VALUE, PARAMETER_TESTABLE_TA4J_STRATEGY_DEFAULT_VALUE); // false - System.setProperty(PARAMETER_NO_TRADING_ACCOUNT_STRATEGY_ENABLED, PARAMETER_NO_TRADING_ACCOUNT_STRATEGY_DEFAULT_VALUE); // false + // Set default values. + + // Exchange parameters. + System.setProperty(PARAMETER_EXCHANGE_NAME, PARAMETER_NAME_DEFAULT_VALUE); // Kucoin + System.setProperty(PARAMETER_EXCHANGE_SANDBOX, PARAMETER_SANDBOX_DEFAULT_VALUE); // true + System.setProperty(PARAMETER_EXCHANGE_DRY, PARAMETER_DRY_DEFAULT_VALUE); // false + System.setProperty(PARAMETER_EXCHANGE_USERNAME, PARAMETER_USERNAME_DEFAULT_VALUE); // cassandre.crypto.bot@gmail.com + System.setProperty(PARAMETER_EXCHANGE_PASSPHRASE, PARAMETER_PASSPHRASE_DEFAULT_VALUE); // cassandre + System.setProperty(PARAMETER_EXCHANGE_KEY, PARAMETER_KEY_DEFAULT_VALUE); // 5df8eea30092f40009cb3c6a + System.setProperty(PARAMETER_EXCHANGE_SECRET, PARAMETER_SECRET_DEFAULT_VALUE); // 5f6e91e0-796b-4947-b75e-eaa5c06b6bed + System.setProperty(PARAMETER_EXCHANGE_RATE_ACCOUNT, PARAMETER_RATE_ACCOUNT_DEFAULT_VALUE); // 100 + System.setProperty(PARAMETER_EXCHANGE_RATE_TICKER, PARAMETER_RATE_TICKER_DEFAULT_VALUE); // 101 + System.setProperty(PARAMETER_EXCHANGE_RATE_TRADE, PARAMETER_RATE_TRADE_DEFAULT_VALUE); // 102 + // Database parameters. + System.setProperty(PARAMETER_DATABASE_DATASOURCE_DRIVER_CLASS_NAME, PARAMETER_DATABASE_DATASOURCE_DRIVER_CLASS_NAME_DEFAULT_VALUE); // org.hsqldb.jdbc.JDBCDriver + System.setProperty(PARAMETER_DATABASE_DATASOURCE_URL, PARAMETER_DATABASE_DATASOURCE_URL_DEFAULT_VALUE); // jdbc:hsqldb:mem:cassandre-database;shutdown=true + System.setProperty(PARAMETER_DATABASE_DATASOURCE_USERNAME, PARAMETER_DATABASE_DATASOURCE_USERNAME_DEFAULT_VALUE); // sa + System.setProperty(PARAMETER_DATABASE_DATASOURCE_PASSWORD, PARAMETER_DATABASE_DATASOURCE_PASSWORD_DEFAULT_VALUE); // empty + System.setProperty(PARAMETER_DATABASE_TABLE_PREFIX, PARAMETER_DATABASE_TABLE_PREFIX_DEFAULT_VALUE); // MY_STRATEGY_ + // Strategies configuration. + System.setProperty(PARAMETER_INVALID_STRATEGY_ENABLED, PARAMETER_INVALID_STRATEGY_DEFAULT_VALUE); // false + System.setProperty(PARAMETER_NO_TRADING_ACCOUNT_STRATEGY_ENABLED, PARAMETER_NO_TRADING_ACCOUNT_STRATEGY_DEFAULT_VALUE); // false + System.setProperty(PARAMETER_TESTABLE_STRATEGY_ENABLED, PARAMETER_TESTABLE_STRATEGY_DEFAULT_VALUE); // true + System.setProperty(PARAMETER_TESTABLE_TA4J_STRATEGY_DEFAULT_VALUE, PARAMETER_TESTABLE_TA4J_STRATEGY_DEFAULT_VALUE); // false // Retrieve all the properties set by the annotation. final Optional> testClass = context.getTestClass(); @@ -107,16 +136,25 @@ public void beforeAll(ExtensionContext context) { @Override public void afterAll(ExtensionContext context) { // Reset values. - System.clearProperty(PARAMETER_NAME); - System.clearProperty(PARAMETER_SANDBOX); - System.clearProperty(PARAMETER_DRY); - System.clearProperty(PARAMETER_USERNAME); - System.clearProperty(PARAMETER_PASSPHRASE); - System.clearProperty(PARAMETER_KEY); - System.clearProperty(PARAMETER_SECRET); - System.clearProperty(PARAMETER_RATE_ACCOUNT); - System.clearProperty(PARAMETER_RATE_TICKER); - System.clearProperty(PARAMETER_RATE_TRADE); + + // Exchange parameters. + System.clearProperty(PARAMETER_EXCHANGE_NAME); + System.clearProperty(PARAMETER_EXCHANGE_SANDBOX); + System.clearProperty(PARAMETER_EXCHANGE_DRY); + System.clearProperty(PARAMETER_EXCHANGE_USERNAME); + System.clearProperty(PARAMETER_EXCHANGE_PASSPHRASE); + System.clearProperty(PARAMETER_EXCHANGE_KEY); + System.clearProperty(PARAMETER_EXCHANGE_SECRET); + System.clearProperty(PARAMETER_EXCHANGE_RATE_ACCOUNT); + System.clearProperty(PARAMETER_EXCHANGE_RATE_TICKER); + System.clearProperty(PARAMETER_EXCHANGE_RATE_TRADE); + // Database parameters. + System.clearProperty(PARAMETER_DATABASE_DATASOURCE_DRIVER_CLASS_NAME); + System.clearProperty(PARAMETER_DATABASE_DATASOURCE_URL); + System.clearProperty(PARAMETER_DATABASE_DATASOURCE_USERNAME); + System.clearProperty(PARAMETER_DATABASE_DATASOURCE_PASSWORD); + System.clearProperty(PARAMETER_DATABASE_TABLE_PREFIX); + // Strategies configuration. System.clearProperty(PARAMETER_INVALID_STRATEGY_ENABLED); System.clearProperty(PARAMETER_TESTABLE_STRATEGY_ENABLED); System.clearProperty(PARAMETER_TESTABLE_TA4J_STRATEGY_DEFAULT_VALUE); diff --git a/spring-boot-starter/autoconfigure/src/test/resources/application.properties b/spring-boot-starter/autoconfigure/src/test/resources/application.properties index 8c0c4d89f..78164c541 100644 --- a/spring-boot-starter/autoconfigure/src/test/resources/application.properties +++ b/spring-boot-starter/autoconfigure/src/test/resources/application.properties @@ -12,4 +12,10 @@ spring.main.allow-bean-definition-overriding=true # # For JDBC debug. # logging.level.org.hibernate.SQL=DEBUG -# logging.level.org.hibernate.type.descriptor.sql.BasicBinder=TRACE \ No newline at end of file +# logging.level.org.hibernate.type.descriptor.sql.BasicBinder=TRACE +# +# For pool. +spring.datasource.hikari.maximum-pool-size=10 +spring.datasource.hikari.idleTimeout=18000 +spring.datasource.hikari.maxLifetime=30000 +spring.datasource.hikari.minimum-idle=10 \ No newline at end of file diff --git a/spring-boot-starter/autoconfigure/src/test/resources/backup.sql b/spring-boot-starter/autoconfigure/src/test/resources/backup.sql index df47a301c..385506be1 100644 --- a/spring-boot-starter/autoconfigure/src/test/resources/backup.sql +++ b/spring-boot-starter/autoconfigure/src/test/resources/backup.sql @@ -1,33 +1,35 @@ -- ===================================================================================================================== -- Insert trades. -INSERT INTO TRADES (ID, ORDER_ID, ORDER_TYPE, ORIGINAL_AMOUNT, CURRENCY_PAIR, PRICE, ORDER_TIMESTAMP, FEE_AMOUNT, FEE_CURRENCY) -values -- note : No trade for order BACKUP_OPEN_ORDER_01 - This is why position 1 is in opening. - -- Order BACKUP_TRADE_01 - Trade from the order buying BACKUP_OPEN_ORDER_01. - ('BACKUP_TRADE_01', 'BACKUP_OPEN_ORDER_02', 'BID', 12, 'BTC/USDT', 14, DATE '2020-08-01', 11, 'USDT'), +INSERT INTO MY_STRATEGY_TRADES (ID, ORDER_ID, ORDER_TYPE, ORIGINAL_AMOUNT, CURRENCY_PAIR, PRICE, ORDER_TIMESTAMP, + FEE_AMOUNT, FEE_CURRENCY) +values -- note : No trade for order BACKUP_OPEN_ORDER_01 - This is why position 1 is in opening. + -- Order BACKUP_TRADE_01 - Trade from the order buying BACKUP_OPEN_ORDER_01. + ('BACKUP_TRADE_01', 'BACKUP_OPEN_ORDER_02', 'BID', 12, 'BTC/USDT', 14, DATE '2020-08-01', 11, 'USDT'), - -- Order BACKUP_TRADE_02 - Trade from the order buying BACKUP_OPEN_ORDER_02. - ('BACKUP_TRADE_02', 'BACKUP_OPEN_ORDER_03', 'BID', 22, 'BTC/USDT', 24, DATE '2020-08-02', 21, 'USDT'), + -- Order BACKUP_TRADE_02 - Trade from the order buying BACKUP_OPEN_ORDER_02. + ('BACKUP_TRADE_02', 'BACKUP_OPEN_ORDER_03', 'BID', 22, 'BTC/USDT', 24, DATE '2020-08-02', 21, 'USDT'), - -- Order BACKUP_TRADE_03 - Trade from the order buying BACKUP_OPEN_ORDER_03. - ('BACKUP_TRADE_03', 'BACKUP_OPEN_ORDER_04', 'BID', 32, 'BTC/USDT', 34, DATE '2020-08-03', 31, 'USDT'), + -- Order BACKUP_TRADE_03 - Trade from the order buying BACKUP_OPEN_ORDER_03. + ('BACKUP_TRADE_03', 'BACKUP_OPEN_ORDER_04', 'BID', 32, 'BTC/USDT', 34, DATE '2020-08-03', 31, 'USDT'), - -- Order BACKUP_TRADE_04 - Trade from the order selling BACKUP_OPEN_ORDER_04. - ('BACKUP_TRADE_04', 'BACKUP_OPEN_ORDER_05', 'ASK', 42, 'BTC/USDT', 44, DATE '2020-08-04', 41, 'USDT'), + -- Order BACKUP_TRADE_04 - Trade from the order selling BACKUP_OPEN_ORDER_04. + ('BACKUP_TRADE_04', 'BACKUP_OPEN_ORDER_05', 'ASK', 42, 'BTC/USDT', 44, DATE '2020-08-04', 41, 'USDT'), - -- Order BACKUP_TRADE_05 - Trade from the order selling BACKUP_OPEN_ORDER_05. - ('BACKUP_TRADE_05', 'BACKUP_OPEN_ORDER_06', 'ASK', 52, 'ETH/USD', 54, DATE '2020-08-05', 51, 'USD'); + -- Order BACKUP_TRADE_05 - Trade from the order selling BACKUP_OPEN_ORDER_05. + ('BACKUP_TRADE_05', 'BACKUP_OPEN_ORDER_06', 'ASK', 52, 'ETH/USD', 54, DATE '2020-08-05', 51, 'USD'); -- ===================================================================================================================== -- Insert positions. -INSERT INTO POSITIONS (ID, STATUS, RULES_STOP_GAIN_PERCENTAGE, RULES_STOP_LOSS_PERCENTAGE, OPEN_ORDER_ID, CLOSE_ORDER_ID, LOWEST_PRICE, HIGHEST_PRICE) -VALUES -- Position 1 : Opening, no rules, waiting for BACKUP_OPEN_ORDER_01 to arrive (but will not arrive). - (1, 'OPENING', null, null, 'BACKUP_OPEN_ORDER_01', null, null, null), +INSERT INTO MY_STRATEGY_POSITIONS (ID, STATUS, RULES_STOP_GAIN_PERCENTAGE, RULES_STOP_LOSS_PERCENTAGE, OPEN_ORDER_ID, + CLOSE_ORDER_ID, LOWEST_PRICE, HIGHEST_PRICE) +VALUES -- Position 1 : Opening, no rules, waiting for BACKUP_OPEN_ORDER_01 to arrive (but will not arrive). + (1, 'OPENING', null, null, 'BACKUP_OPEN_ORDER_01', null, null, null), - -- Position 2 : Opened position, 10% gain rule. - (2,'OPENED', 10, null, 'BACKUP_OPEN_ORDER_02', null, 1, 2), + -- Position 2 : Opened position, 10% gain rule. + (2, 'OPENED', 10, null, 'BACKUP_OPEN_ORDER_02', null, 1, 2), - -- Position 3 : Closing position, 20% loss rule, waiting for a not coming trade 'NON_EXISTING_TRADE'. - (3, 'CLOSING', null, 20, 'BACKUP_OPEN_ORDER_03', 'NON_EXISTING_TRADE', 17, 68), + -- Position 3 : Closing position, 20% loss rule, waiting for a not coming trade 'NON_EXISTING_TRADE'. + (3, 'CLOSING', null, 20, 'BACKUP_OPEN_ORDER_03', 'NON_EXISTING_TRADE', 17, 68), - -- Position 4 : Closed position, 30% gain & 40 % loss. - (4, 'CLOSED', 30, 40, 'BACKUP_OPEN_ORDER_04', 'BACKUP_OPEN_ORDER_05', 17, 68); \ No newline at end of file + -- Position 4 : Closed position, 30% gain & 40 % loss. + (4, 'CLOSED', 30, 40, 'BACKUP_OPEN_ORDER_04', 'BACKUP_OPEN_ORDER_05', 17, 68); \ No newline at end of file diff --git a/spring-boot-starter/autoconfigure/src/main/resources/banner.txt b/spring-boot-starter/autoconfigure/src/test/resources/banner.txt similarity index 100% rename from spring-boot-starter/autoconfigure/src/main/resources/banner.txt rename to spring-boot-starter/autoconfigure/src/test/resources/banner.txt diff --git a/spring-boot-starter/starter/pom.xml b/spring-boot-starter/starter/pom.xml index 640ab727d..a6f69e667 100644 --- a/spring-boot-starter/starter/pom.xml +++ b/spring-boot-starter/starter/pom.xml @@ -111,7 +111,7 @@ tech.cassandre.trading.bot cassandre-trading-bot-project - 2.2.0 + 2.3.0 ../../pom.xml diff --git a/trading-bot-archetypes/basic-archetype/pom.xml b/trading-bot-archetypes/basic-archetype/pom.xml index f5be0705e..468ef7ced 100644 --- a/trading-bot-archetypes/basic-archetype/pom.xml +++ b/trading-bot-archetypes/basic-archetype/pom.xml @@ -103,7 +103,7 @@ tech.cassandre.trading.bot cassandre-trading-bot-project - 2.2.0 + 2.3.0 ../../pom.xml diff --git a/trading-bot-archetypes/basic-archetype/src/main/resources/archetype-resources/pom.xml b/trading-bot-archetypes/basic-archetype/src/main/resources/archetype-resources/pom.xml index bf1e59d37..8f6d2e801 100644 --- a/trading-bot-archetypes/basic-archetype/src/main/resources/archetype-resources/pom.xml +++ b/trading-bot-archetypes/basic-archetype/src/main/resources/archetype-resources/pom.xml @@ -30,6 +30,11 @@ spring-boot-starter 2.3.3.RELEASE + + org.hsqldb + hsqldb + 2.5.1 + diff --git a/trading-bot-archetypes/basic-archetype/src/main/resources/archetype-resources/src/main/resources/application.properties b/trading-bot-archetypes/basic-archetype/src/main/resources/archetype-resources/src/main/resources/application.properties index 0f6dad716..e02b3c451 100644 --- a/trading-bot-archetypes/basic-archetype/src/main/resources/archetype-resources/src/main/resources/application.properties +++ b/trading-bot-archetypes/basic-archetype/src/main/resources/archetype-resources/src/main/resources/application.properties @@ -22,8 +22,9 @@ cassandre.trading.bot.exchange.rates.account=2000 cassandre.trading.bot.exchange.rates.ticker=2000 cassandre.trading.bot.exchange.rates.trade=2000 ${symbol_pound} -${symbol_pound} Database used for backup. -spring.datasource.driver-class-name=org.hsqldb.jdbc.JDBCDriver -spring.datasource.url=jdbc:hsqldb:mem:cassandre -spring.datasource.username=sa -spring.datasource.password= \ No newline at end of file +${symbol_pound} Database configuration. +spring.jpa.hibernate.ddl-auto=update +cassandre.trading.bot.database.datasource.driver-class-name=org.hsqldb.jdbc.JDBCDriver +cassandre.trading.bot.database.datasource.url=jdbc:hsqldb:mem:cassandre +cassandre.trading.bot.database.datasource.username=sa +cassandre.trading.bot.database.datasource.password= \ No newline at end of file diff --git a/trading-bot-archetypes/basic-ta4j-archetype/pom.xml b/trading-bot-archetypes/basic-ta4j-archetype/pom.xml index 1a23f1189..3ccc0da0e 100644 --- a/trading-bot-archetypes/basic-ta4j-archetype/pom.xml +++ b/trading-bot-archetypes/basic-ta4j-archetype/pom.xml @@ -103,7 +103,7 @@ tech.cassandre.trading.bot cassandre-trading-bot-project - 2.2.0 + 2.3.0 ../../pom.xml diff --git a/trading-bot-archetypes/basic-ta4j-archetype/src/main/resources/archetype-resources/pom.xml b/trading-bot-archetypes/basic-ta4j-archetype/src/main/resources/archetype-resources/pom.xml index bf1e59d37..8f6d2e801 100644 --- a/trading-bot-archetypes/basic-ta4j-archetype/src/main/resources/archetype-resources/pom.xml +++ b/trading-bot-archetypes/basic-ta4j-archetype/src/main/resources/archetype-resources/pom.xml @@ -30,6 +30,11 @@ spring-boot-starter 2.3.3.RELEASE + + org.hsqldb + hsqldb + 2.5.1 + diff --git a/trading-bot-archetypes/basic-ta4j-archetype/src/main/resources/archetype-resources/src/main/resources/application.properties b/trading-bot-archetypes/basic-ta4j-archetype/src/main/resources/archetype-resources/src/main/resources/application.properties index 5c98369ab..47fb3f190 100644 --- a/trading-bot-archetypes/basic-ta4j-archetype/src/main/resources/archetype-resources/src/main/resources/application.properties +++ b/trading-bot-archetypes/basic-ta4j-archetype/src/main/resources/archetype-resources/src/main/resources/application.properties @@ -22,8 +22,9 @@ cassandre.trading.bot.exchange.rates.account=PT1S cassandre.trading.bot.exchange.rates.ticker=PT1S cassandre.trading.bot.exchange.rates.trade=PT1S ${symbol_pound} -${symbol_pound} Database used for backup. -spring.datasource.driver-class-name=org.hsqldb.jdbc.JDBCDriver -spring.datasource.url=jdbc:hsqldb:mem:cassandre -spring.datasource.username=sa -spring.datasource.password= \ No newline at end of file +${symbol_pound} Database configuration. +spring.jpa.hibernate.ddl-auto=update +cassandre.trading.bot.database.datasource.driver-class-name=org.hsqldb.jdbc.JDBCDriver +cassandre.trading.bot.database.datasource.url=jdbc:hsqldb:mem:cassandre +cassandre.trading.bot.database.datasource.username=sa +cassandre.trading.bot.database.datasource.password= \ No newline at end of file diff --git a/trading-bot-server/deployment.yml b/trading-bot-server/deployment.yml new file mode 100644 index 000000000..605b1bbd3 --- /dev/null +++ b/trading-bot-server/deployment.yml @@ -0,0 +1,73 @@ +name: Deployment + +on: + push: + tags: + - '*' + +jobs: + build: + + # ================================================================================================================== + # Configuration. + runs-on: ubuntu-latest + + steps: + # ================================================================================================================ + - name: Retrieve the sources + uses: actions/checkout@v1 + + # ================================================================================================================ + - name: Set up JDK 11 + uses: actions/setup-java@v1 + with: + java-version: 11.0.x + + # ================================================================================================================ + - name: Build with Maven and creates the docker image + run: mvn spring-boot:build-image + + # ================================================================================================================ + - name: Push image to docker hub + run: | + echo ${{ secrets.DOCKER_HUB_PASSWORD }} | docker login -u ${{ secrets.DOCKER_HUB_USERNAME }} --password-stdin + docker push straumat/trading-bot:latest + + # ================================================================================================================ + - name: Deploy to production server + uses: appleboy/ssh-action@master + with: + host: ${{ secrets.SSH_HOST }} + port: ${{ secrets.SSH_PORT }} + username: ${{ secrets.SSH_USERNAME }} + password: ${{ secrets.SSH_PASSWORD }} + script: | + echo ${{ secrets.DOCKER_HUB_PASSWORD }} | docker login -u ${{ secrets.DOCKER_HUB_USERNAME }} --password-stdin + docker stop $(docker ps -aq --filter "label=trading-bot") + docker rm -f $(docker ps -aq --filter "label=trading-bot") + docker pull straumat/trading-bot:latest + docker run -d \ + --security-opt apparmor=unconfined \ + --network="cassandre" \ + -e CASSANDRE_TRADING_BOT_EXCHANGE_NAME='${{ secrets.CASSANDRE_TRADING_BOT_EXCHANGE_NAME }}' \ + -e CASSANDRE_TRADING_BOT_EXCHANGE_USERNAME='${{ secrets.CASSANDRE_TRADING_BOT_EXCHANGE_USERNAME }}' \ + -e CASSANDRE_TRADING_BOT_EXCHANGE_PASSPHRASE='${{ secrets.CASSANDRE_TRADING_BOT_EXCHANGE_PASSPHRASE }}' \ + -e CASSANDRE_TRADING_BOT_EXCHANGE_KEY='${{ secrets.CASSANDRE_TRADING_BOT_EXCHANGE_KEY }}' \ + -e CASSANDRE_TRADING_BOT_EXCHANGE_SECRET='${{ secrets.CASSANDRE_TRADING_BOT_EXCHANGE_SECRET }}' \ + -e CASSANDRE_TRADING_BOT_EXCHANGE_MODES_SANDBOX='${{ secrets.CASSANDRE_TRADING_BOT_EXCHANGE_MODES_SANDBOX }}' \ + -e CASSANDRE_TRADING_BOT_EXCHANGE_MODES_DRY='${{ secrets.CASSANDRE_TRADING_BOT_EXCHANGE_MODES_DRY }}' \ + -e CASSANDRE_TRADING_BOT_EXCHANGE_RATES_ACCOUNT='${{ secrets.CASSANDRE_TRADING_BOT_EXCHANGE_RATES_ACCOUNT }}' \ + -e CASSANDRE_TRADING_BOT_EXCHANGE_RATES_TICKER='${{ secrets.CASSANDRE_TRADING_BOT_EXCHANGE_RATES_TICKER }}' \ + -e CASSANDRE_TRADING_BOT_EXCHANGE_RATES_ORDER='${{ secrets.CASSANDRE_TRADING_BOT_EXCHANGE_RATES_ORDER }}' \ + -e CASSANDRE_TRADING_BOT_EXCHANGE_RATES_ORDER='${{ secrets.CASSANDRE_TRADING_BOT_EXCHANGE_RATES_ORDER }}' \ + -e CASSANDRE_TRADING_BOT_EXCHANGE_RATES_ORDER='${{ secrets.CASSANDRE_TRADING_BOT_EXCHANGE_RATES_ORDER }}' \ + -e CASSANDRE_TRADING_BOT_EXCHANGE_RATES_ORDER='${{ secrets.CASSANDRE_TRADING_BOT_EXCHANGE_RATES_ORDER }}' \ + -e CASSANDRE_TRADING_BOT_EXCHANGE_RATES_ORDER='${{ secrets.CASSANDRE_TRADING_BOT_EXCHANGE_RATES_ORDER }}' \ + -e CASSANDRE_TRADING_BOT_EXCHANGE_RATES_ORDER='${{ secrets.CASSANDRE_TRADING_BOT_EXCHANGE_RATES_ORDER }}' \ + -e CASSANDRE_TRADING_BOT_DATABASE_DATASOURCE_DRIVER-CLASS-NAME=${{ secrets.CASSANDRE_TRADING_BOT_DATABASE_DATASOURCE_DRIVER_CLASS_NAME }} \ + -e CASSANDRE_TRADING_BOT_DATABASE_DATASOURCE_URL=${{ secrets.CASSANDRE_TRADING_BOT_DATABASE_DATASOURCE_URL }} \ + -e CASSANDRE_TRADING_BOT_DATABASE_DATASOURCE_USERNAME=${{ secrets.CASSANDRE_TRADING_BOT_DATABASE_DATASOURCE_USERNAME }} \ + -e CASSANDRE_TRADING_BOT_DATABASE_DATASOURCE_PASSWORD=${{ secrets.CASSANDRE_TRADING_BOT_DATABASE_DATASOURCE_PASSWORD }} \ + -e CASSANDRE_TRADING_BOT_DATABASE_TABLE-PREFIX=${{ secrets.CASSANDRE_TRADING_BOT_DATABASE_TABLE_PREFIX }} \ + -l trading-bot \ + straumat/trading-bot:latest \ No newline at end of file diff --git a/trading-bot-server/docker-compose.yml b/trading-bot-server/docker-compose.yml new file mode 100644 index 000000000..86364ce24 --- /dev/null +++ b/trading-bot-server/docker-compose.yml @@ -0,0 +1,61 @@ +version: "3.5" + +# ====================================================================================================================== +# Default network. +networks: + cassandre: + name: cassandre + +# ====================================================================================================================== +# Volumes - Volumes are the preferred mechanism for persisting data generated by and used by Docker containers. +# You can list them with the command: 'docker volume ls' +# You can see the details with 'docker inspect cassandre-trading-bot-server_database' +volumes: + database: + backup: + +# ====================================================================================================================== +# Services (images). +services: + + # ==================================================================================================================== + # Postgresql - Database used to backup Cassandre trading bot data (trades/positions). + # https://hub.docker.com/_/postgres + postgresql: + image: library/postgres:13-alpine + restart: always + networks: + - cassandre + volumes: + - database:/var/lib/postgresql/data + environment: + - TZ=Europe/Paris + - PGTZ=Europe/Paris + - POSTGRES_DB=cassandre_trading_bot + - POSTGRES_USER=cassandre_trading_bot + - POSTGRES_PASSWORD=mypassword + + # ==================================================================================================================== + # Postgresql backup - Util tools to backup the database. + # https://github.com/prodrigestivill/docker-postgres-backup-local + postgresql-backup: + image: prodrigestivill/postgres-backup-local:13-alpine + depends_on: + - postgresql + restart: always + networks: + - cassandre + volumes: + - backup:/backups + environment: + - TZ=Europe/Paris + - POSTGRES_HOST=postgresql + - POSTGRES_DB=cassandre_trading_bot + - POSTGRES_USER=cassandre_trading_bot + - POSTGRES_PASSWORD=mypassword + - POSTGRES_EXTRA_OPTS=-Z9 + - SCHEDULE=@every 01h00m00s + - BACKUP_KEEP_DAYS=7 + - BACKUP_KEEP_WEEKS=4 + - BACKUP_KEEP_MONTHS=0 + - HEALTHCHECK_PORT=8080