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 something like that on shouldEnter() :

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

Cassandre trading provides positions to automatically manage your trade this way. 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 createPosition() method. This 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 make a sell order to close this position.