Skip to content

Commit

Permalink
Merge branch 'release/4.2.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
straumat committed Apr 30, 2021
2 parents 8b251c8 + da85030 commit 47d2265
Show file tree
Hide file tree
Showing 57 changed files with 359 additions and 136 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: "CodeQL"

on:
schedule:
- cron: '0 19 * * FRI'
- cron: '0 18 * * FRI'

jobs:
analyze:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/integration-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: Integration tests

on:
schedule:
- cron: '0 19 * * FRI'
- cron: '0 18 * * FRI'

jobs:
build:
Expand Down
2 changes: 1 addition & 1 deletion docs/src/ressources/how-tos/how-to-create-a-release.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,5 @@ mvn gitflow:release-finish
```

## Update
* Close the corresponding [milestone in Github](https://github.com/cassandre-tech/cassandre-trading-bot/milestones).
* Close the corresponding [milestone in Github](https://github.com/cassandre-tech/cassandre-trading-bot/milestones?direction=asc&sort=due_date&state=open).
* Write and send a [substack post](https://cassandre.substack.com/publish?utm_source=menu).
6 changes: 3 additions & 3 deletions docs/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -6866,9 +6866,9 @@ sshpk@^1.7.0:
tweetnacl "~0.14.0"

ssri@^6.0.1:
version "6.0.1"
resolved "https://registry.yarnpkg.com/ssri/-/ssri-6.0.1.tgz#2a3c41b28dd45b62b63676ecb74001265ae9edd8"
integrity sha512-3Wge10hNcT1Kur4PDFwEieXSCMCJs/7WvSACcrMYrNp+b8kDL1/0wJch5Ni2WrtwEa2IO8OsVfeKIciKCDx/QA==
version "6.0.2"
resolved "https://registry.yarnpkg.com/ssri/-/ssri-6.0.2.tgz#157939134f20464e7301ddba3e90ffa8f7728ac5"
integrity sha512-cepbSq/neFK7xB6A50KHN0xHDotYzq58wWCa5LeWqnPrHG8GzfEjO/4O8kpmcGW+oaxkvhEJCWgbgNk4/ZV93Q==
dependencies:
figgy-pudding "^3.5.1"

Expand Down
4 changes: 2 additions & 2 deletions 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>4.2.0</version>
<version>4.2.1</version>
<packaging>pom</packaging>
<name>Cassandre trading bot</name>
<url>https://github.com/cassandre-tech/cassandre-trading-bot</url>
Expand Down Expand Up @@ -36,7 +36,7 @@
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.4.4</version>
<version>2.4.5</version>
<relativePath/>
</parent>
<!-- =========================================================================================================== -->
Expand Down
4 changes: 2 additions & 2 deletions spring-boot-starter-test/autoconfigure/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
<dependency>
<groupId>org.hsqldb</groupId>
<artifactId>hsqldb</artifactId>
<version>2.5.1</version>
<version>2.6.0</version>
<scope>test</scope>
</dependency>
<!-- Used for tests -->
Expand Down Expand Up @@ -148,7 +148,7 @@
<parent>
<groupId>tech.cassandre.trading.bot</groupId>
<artifactId>cassandre-trading-bot-project</artifactId>
<version>4.2.0</version>
<version>4.2.1</version>
<relativePath>../../pom.xml</relativePath>
</parent>
<!-- =========================================================================================================== -->
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package tech.cassandre.trading.bot.test.mock;

import org.knowm.xchange.exceptions.NotAvailableFromExchangeException;
import org.mockito.invocation.InvocationOnMock;
import org.mockito.stubbing.Answer;
import org.slf4j.Logger;
Expand Down Expand Up @@ -32,6 +33,8 @@
import java.util.Scanner;
import java.util.concurrent.TimeUnit;

import static org.mockito.ArgumentMatchers.any;
import static org.mockito.BDDMockito.given;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

Expand Down Expand Up @@ -81,6 +84,9 @@ public MarketService marketService() {
// Creates the mock.
MarketService marketService = mock(MarketService.class);

// We don't use the getTickers method.
given(marketService.getTickers(any())).willThrow(new NotAvailableFromExchangeException("Not available in this mode"));

// For every files.
getFilesToLoad()
.stream().filter(resource -> resource.getFilename() != null)
Expand Down
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 @@ -116,7 +116,7 @@
<parent>
<groupId>tech.cassandre.trading.bot</groupId>
<artifactId>cassandre-trading-bot-project</artifactId>
<version>4.2.0</version>
<version>4.2.1</version>
<relativePath>../../pom.xml</relativePath>
</parent>
<!-- =========================================================================================================== -->
Expand Down
6 changes: 3 additions & 3 deletions spring-boot-starter/autoconfigure/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
<dependency>
<groupId>org.liquibase</groupId>
<artifactId>liquibase-core</artifactId>
<version>4.3.3</version>
<version>4.3.4</version>
</dependency>

<!-- XChange -->
Expand Down Expand Up @@ -170,7 +170,7 @@
<dependency>
<groupId>io.projectreactor</groupId>
<artifactId>reactor-bom</artifactId>
<version>Dysprosium-SR18</version>
<version>Dysprosium-SR19</version>
<type>pom</type>
<scope>import</scope>
</dependency>
Expand Down Expand Up @@ -371,7 +371,7 @@
<parent>
<groupId>tech.cassandre.trading.bot</groupId>
<artifactId>cassandre-trading-bot-project</artifactId>
<version>4.2.0</version>
<version>4.2.1</version>
<relativePath>../../pom.xml</relativePath>
</parent>
<!-- =========================================================================================================== -->
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package tech.cassandre.trading.bot.batch;

import com.google.common.collect.Iterators;
import org.knowm.xchange.exceptions.NotAvailableFromExchangeException;
import org.knowm.xchange.exceptions.NotYetImplementedForExchangeException;
import tech.cassandre.trading.bot.dto.market.TickerDTO;
import tech.cassandre.trading.bot.dto.util.CurrencyPairDTO;
import tech.cassandre.trading.bot.service.MarketService;
Expand All @@ -21,6 +23,9 @@ public class TickerFlux extends BaseExternalFlux<TickerDTO> {
/** Market service. */
private final MarketService marketService;

/** Cycle iterator over requested currency pairs. */
private final Set<CurrencyPairDTO> currencyPairs = new LinkedHashSet<>();

/** Cycle iterator over requested currency pairs. */
private Iterator<CurrencyPairDTO> currencyPairsIterator;

Expand All @@ -42,20 +47,35 @@ public TickerFlux(final MarketService newMarketService) {
* @param requestedCurrencyPairs list of requested currency pairs.
*/
public void updateRequestedCurrencyPairs(final Set<CurrencyPairDTO> requestedCurrencyPairs) {
currencyPairs.addAll(requestedCurrencyPairs);
currencyPairsIterator = Iterators.cycle(requestedCurrencyPairs);
}

@Override
protected final Set<TickerDTO> getNewValues() {
logger.debug("TickerFlux - Retrieving new values");
Set<TickerDTO> newValues = new LinkedHashSet<>();
marketService.getTicker(currencyPairsIterator.next()).ifPresent(ticker -> {
if (!ticker.equals(previousValues.get(ticker.getCurrencyPair()))) {
logger.debug("TickerFlux - New ticker received : {}", ticker);
previousValues.put(ticker.getCurrencyPair(), ticker);
newValues.add(ticker);
}
});

try {
// GetTickers from market service is available so we retrieve all tickers at once.
marketService.getTickers(currencyPairs).forEach(ticker -> {
if (!ticker.equals(previousValues.get(ticker.getCurrencyPair()))) {
logger.debug("TickerFlux - New ticker received : {}", ticker);
previousValues.put(ticker.getCurrencyPair(), ticker);
newValues.add(ticker);
}
});
} catch (NotAvailableFromExchangeException | NotYetImplementedForExchangeException e) {
logger.debug("MarketService - getTickers not available {}", e.getMessage());
// GetTickers from market service is unavailable so we do ticker by ticker.
marketService.getTicker(currencyPairsIterator.next()).ifPresent(t -> {
if (!t.equals(previousValues.get(t.getCurrencyPair()))) {
logger.debug("TickerFlux - New ticker received : {}", t);
previousValues.put(t.getCurrencyPair(), t);
newValues.add(t);
}
});
}
return newValues;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,11 @@

import tech.cassandre.trading.bot.domain.Trade;
import tech.cassandre.trading.bot.dto.trade.TradeDTO;
import tech.cassandre.trading.bot.dto.util.CurrencyPairDTO;
import tech.cassandre.trading.bot.repository.OrderRepository;
import tech.cassandre.trading.bot.repository.TradeRepository;
import tech.cassandre.trading.bot.service.TradeService;
import tech.cassandre.trading.bot.util.base.batch.BaseExternalFlux;

import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.Optional;
import java.util.Set;
Expand All @@ -28,9 +26,6 @@ public class TradeFlux extends BaseExternalFlux<TradeDTO> {
/** Trade repository. */
private final TradeRepository tradeRepository;

/** Currency pairs requested. */
private final Set<CurrencyPairDTO> currencyPairs = new HashSet<>();

/**
* Constructor.
*
Expand All @@ -46,22 +41,13 @@ public TradeFlux(final TradeService newTradeService,
this.tradeService = newTradeService;
}

/**
* Add currency pairs for trades.
*
* @param newCurrencyPairs currency pairs
*/
public void addCurrencyPairs(final Set<CurrencyPairDTO> newCurrencyPairs) {
currencyPairs.addAll(newCurrencyPairs);
}

@Override
protected final Set<TradeDTO> getNewValues() {
logger.debug("TradeFlux - Retrieving new values");
Set<TradeDTO> newValues = new LinkedHashSet<>();

// Finding which trades has been updated.
tradeService.getTrades(currencyPairs)
tradeService.getTrades()
.stream().filter(t -> orderRepository.findByOrderId(t.getOrderId()).isPresent()) // We only accept trades with order present in database
.forEach(trade -> {
logger.debug("TradeFlux - Treating trade : {}", trade.getTradeId());
Expand All @@ -84,14 +70,14 @@ public final Optional<TradeDTO> saveValue(final TradeDTO newValue) {
// Update trade.
tradeMapper.updateTrade(newValue, trade);
orderRepository.findByOrderId(newValue.getOrderId())
.ifPresent(order -> trade.setOrder(order.getId()));
.ifPresent(trade::setOrder);
valueToSave.set(trade);
logger.debug("TradeFlux - Updating trade in database {}", trade);
}, () -> {
// Create trade.
final Trade newTrade = tradeMapper.mapToTrade(newValue);
orderRepository.findByOrderId(newValue.getOrderId())
.ifPresent(order -> newTrade.setOrder(order.getId()));
.ifPresent(newTrade::setOrder);
valueToSave.set(newTrade);
logger.debug("TradeFlux - Creating trade in database {}", newTrade);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,13 @@
public class ScheduleAutoConfiguration extends BaseConfiguration {

/** Await termination in seconds. */
private static final int AWAIT_TERMINATION_SECONDS = 120;
private static final int AWAIT_TERMINATION_SECONDS = 30;

/** Scheduler pool size. */
private static final int SCHEDULER_POOL_SIZE = 3;

/** Initial delay before starting threads. */
public static final int INITIAL_DELAY = 1000;

/** Indicate that the batch should be running. */
private final AtomicBoolean enabled = new AtomicBoolean(true);
Expand Down Expand Up @@ -70,8 +76,7 @@ public TaskScheduler taskScheduler() {
ThreadPoolTaskScheduler scheduler = new ThreadPoolTaskScheduler();
scheduler.setAwaitTerminationSeconds(AWAIT_TERMINATION_SECONDS);
scheduler.setWaitForTasksToCompleteOnShutdown(true);
// TODO Setting a pool size breaks OrderFluxTest.
// scheduler.setPoolSize(SCHEDULER_POOL_SIZE);
scheduler.setPoolSize(SCHEDULER_POOL_SIZE);
scheduler.setErrorHandler(throwable -> {
try {
logger.error("ScheduleAutoConfiguration - Error in scheduled tasks : {}", throwable.getMessage());
Expand All @@ -85,7 +90,7 @@ public TaskScheduler taskScheduler() {
/**
* Recurrent calls the account flux.
*/
@Scheduled(fixedDelay = 1)
@Scheduled(initialDelay = INITIAL_DELAY, fixedDelay = 1)
public void accountFluxUpdate() {
if (enabled.get()) {
accountFlux.update();
Expand All @@ -95,7 +100,7 @@ public void accountFluxUpdate() {
/**
* Recurrent calls the ticker flux.
*/
@Scheduled(fixedDelay = 1)
@Scheduled(initialDelay = INITIAL_DELAY, fixedDelay = 1)
public void tickerFluxUpdate() {
if (enabled.get()) {
tickerFlux.update();
Expand All @@ -105,7 +110,7 @@ public void tickerFluxUpdate() {
/**
* Recurrent calls the trade flux.
*/
@Scheduled(fixedDelay = 1)
@Scheduled(initialDelay = INITIAL_DELAY, fixedDelay = 1)
public void tradeFluxUpdate() {
if (enabled.get()) {
orderFlux.update();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,6 @@ public void configure() {
.collect(Collectors.toCollection(LinkedHashSet::new));
tickerFlux.updateRequestedCurrencyPairs(currencyPairs);
final ConnectableFlux<TickerDTO> connectableTickerFlux = tickerFlux.getFlux().publish();
tradeFlux.addCurrencyPairs(currencyPairs);
final ConnectableFlux<TradeDTO> connectableTradeFlux = tradeFlux.getFlux().publish();
// =============================================================================================================
// Connecting flux.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,9 @@ public class Order extends BaseDomain {
private ZonedDateTime timestamp;

/** All trades related to order. */
@OneToMany(fetch = EAGER)
@OneToMany(mappedBy = "order", fetch = EAGER)
@OrderBy("timestamp")
@JoinColumn(name = "FK_ORDER_ID", updatable = false)
// @JoinColumn(name = "FK_ORDER_ID", updatable = false)
private Set<Trade> trades = new LinkedHashSet<>();

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
import javax.persistence.Enumerated;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import java.time.ZonedDateTime;

Expand Down Expand Up @@ -45,8 +47,9 @@ public class Trade extends BaseDomain {
private OrderTypeDTO type;

/** The id of the order responsible for execution of this trade. */
@Column(name = "FK_ORDER_ID", updatable = false)
private Long order;
@ManyToOne
@JoinColumn(name = "FK_ORDER_ID", nullable = false)
private Order order;

/** The id of the order responsible for execution of this trade. */
@Column(name = "ORDER_ID")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
@Builder
@ToString
@AllArgsConstructor(access = PRIVATE)
@SuppressWarnings({"checkstyle:VisibilityModifier", "DuplicatedCode"})
@SuppressWarnings({"checkstyle:VisibilityModifier"})
public class PositionDTO {

/** Technical ID. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import lombok.Builder;
import lombok.Value;
import org.apache.commons.lang3.builder.HashCodeBuilder;
import tech.cassandre.trading.bot.domain.Order;
import tech.cassandre.trading.bot.dto.util.CurrencyAmountDTO;
import tech.cassandre.trading.bot.dto.util.CurrencyPairDTO;
import tech.cassandre.trading.bot.util.java.EqualsBuilder;
Expand Down Expand Up @@ -52,6 +53,9 @@ public class TradeDTO {
/** The id of the order responsible for execution of this trade. */
String orderId;

/** Order. */
Order order;

/** Currency pair. */
CurrencyPairDTO currencyPair;

Expand Down
Loading

0 comments on commit 47d2265

Please sign in to comment.