React to signals

Now that your strategy is in place, Cassandre will call shouldEnter() when it's time to buy and shouldExit() when it's time to sell. You can do things manually by creating orders, but you can also use positions.

For example, you can do something like that on shouldEnter() :

if (canBuy(new BigDecimal("0.01"))) {
// Create rules.
PositionRulesDTO rules = PositionRulesDTO
// Create position.
new CurrencyPairDTO(BTC, USDT),
new BigDecimal("0.01"),

Cassandre trading provides positions to manage your trading automatically. First, we created a rule saying this position should be closed if the gain is at least 10% or if the loss is at last 5%.

Then we called the createLongPosition() method. It will automatically create a buy order. From now, with every ticker received, Cassandre will check the gain or loss made on this position; if it triggers one of the rules, Cassandre will automatically create a sell order to close it.

Inside your strategy, you can call canBuy() and canSell() method to see if your account has enough money to buy or sell assets.