Skip to content

Commit

Permalink
Merge branch 'release/2.3.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
straumat committed Oct 19, 2020
2 parents 6383aa8 + 90fe805 commit 665418e
Show file tree
Hide file tree
Showing 70 changed files with 872 additions and 231 deletions.
2 changes: 0 additions & 2 deletions .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand Down
6 changes: 2 additions & 4 deletions .github/workflows/continuous-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand All @@ -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
2 changes: 0 additions & 2 deletions .github/workflows/integration-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand Down
2 changes: 0 additions & 2 deletions .github/workflows/release-creation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand Down
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ hs_err_pid*
# Maven
log/
.notes
.mvn
*.iml

# Node
Expand Down
1 change: 1 addition & 0 deletions .mvn/jvm.config
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
-Xmx2048m -Xms1024m -Djava.awt.headless=true
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
src="https://github.com/cassandre-tech/cassandre-trading-bot/workflows/Continuous%20integration/badge.svg"
alt="GitHub Actions" />
</a>
</p>

<p align="center">
<a href="https://www.codacy.com/gh/cassandre-tech/cassandre-trading-bot?utm_source=github.com&amp;utm_medium=referral&amp;utm_content=cassandre-tech/cassandre-trading-bot&amp;utm_campaign=Badge_Grade">
<img
src="https://api.codacy.com/project/badge/Grade/f26dc41008a64bb18dcd404b46b69fc8"
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<!-- Project information -->
<groupId>tech.cassandre.trading.bot</groupId>
<artifactId>cassandre-trading-bot-project</artifactId>
<version>2.2.0</version>
<version>2.3.0</version>
<packaging>pom</packaging>
<name>Cassandre trading bot</name>
<url>https://github.com/cassandre-tech/cassandre-trading-bot</url>
Expand Down
10 changes: 8 additions & 2 deletions spring-boot-starter-test/autoconfigure/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<!-- =========================================================================================================== -->
<!-- Project information -->
<artifactId>cassandre-trading-bot-spring-boot-starter-test-autoconfigure</artifactId>
<name>Trading bot spring boot starter test autoconfigure</name>
<name>Trading bot spring boot autoconfigure test</name>
<!-- =========================================================================================================== -->

<!-- =========================================================================================================== -->
Expand Down Expand Up @@ -47,6 +47,12 @@
<artifactId>junit-pioneer</artifactId>
<version>1.0.0</version>
</dependency>
<dependency>
<groupId>org.hsqldb</groupId>
<artifactId>hsqldb</artifactId>
<version>2.5.1</version>
<scope>test</scope>
</dependency>
</dependencies>
<!-- =========================================================================================================== -->

Expand Down Expand Up @@ -134,7 +140,7 @@
<parent>
<groupId>tech.cassandre.trading.bot</groupId>
<artifactId>cassandre-trading-bot-project</artifactId>
<version>2.2.0</version>
<version>2.3.0</version>
<relativePath>../../pom.xml</relativePath>
</parent>
<!-- =========================================================================================================== -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion spring-boot-starter-test/starter/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@
<parent>
<groupId>tech.cassandre.trading.bot</groupId>
<artifactId>cassandre-trading-bot-project</artifactId>
<version>2.2.0</version>
<version>2.3.0</version>
<relativePath>../../pom.xml</relativePath>
</parent>
<!-- =========================================================================================================== -->
Expand Down
31 changes: 22 additions & 9 deletions spring-boot-starter/autoconfigure/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -40,26 +40,23 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-autoconfigure</artifactId>
</dependency>

<!-- Database -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.hsqldb</groupId>
<artifactId>hsqldb</artifactId>
<version>2.5.1</version>
</dependency>

<!-- XChange -->
<dependency>
<groupId>org.knowm.xchange</groupId>
<artifactId>xchange-core</artifactId>
<version>5.0.2</version>
<version>5.0.3</version>
</dependency>
<dependency>
<groupId>org.knowm.xchange</groupId>
<artifactId>xchange-kucoin</artifactId>
<version>5.0.2</version>
<version>5.0.3</version>
</dependency>

<!-- Ta4j -->
Expand All @@ -78,7 +75,17 @@
<dependency>
<groupId>org.mapstruct</groupId>
<artifactId>mapstruct</artifactId>
<version>1.4.0.Final</version>
<version>1.4.1.Final</version>
</dependency>
<dependency>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
<version>2.3.1</version>
</dependency>
<dependency>
<groupId>com.sun.xml.bind</groupId>
<artifactId>jaxb-impl</artifactId>
<version>2.3.3</version>
</dependency>

<!-- Tests -->
Expand All @@ -99,6 +106,12 @@
<version>4.0.3</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.hsqldb</groupId>
<artifactId>hsqldb</artifactId>
<version>2.5.1</version>
<scope>test</scope>
</dependency>
</dependencies>
<!-- =========================================================================================================== -->

Expand Down Expand Up @@ -265,7 +278,7 @@
<parent>
<groupId>tech.cassandre.trading.bot</groupId>
<artifactId>cassandre-trading-bot-project</artifactId>
<version>2.2.0</version>
<version>2.3.0</version>
<relativePath>../../pom.xml</relativePath>
</parent>
<!-- =========================================================================================================== -->
Expand Down
Original file line number Diff line number Diff line change
@@ -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());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -159,18 +159,20 @@ 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);
this.tradeService = new TradeServiceXChangeImplementation(tradeRate, xChangeTradeService, tradeRepository);
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);
}
Expand Down Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,15 +157,16 @@ public void configure() {
if (user.isPresent()) {
final Optional<AccountDTO> 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<AccountDTO> accounts) method as it returns an empty result");
"Check your getTradeAccount(Set<AccountDTO> 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;
Expand Down Expand Up @@ -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");

Expand Down Expand Up @@ -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");
}
Expand Down
Loading

0 comments on commit 665418e

Please sign in to comment.