Position management

Cassandre provides a simple way to manage your positions automatically.

Long position

You can create a long position with the createLongPosition()open in new window method with those parameters:

  • The currency pair, for example, ETH/USDT.
  • The amount, for example, 0.5.
  • The rules, for example, 100% stop gain and 50% stop loss.

The first step is to create the rules you want to apply to the position thanks to the PositionRulesDTOopen in new window class like this:

PositionRulesDTO rules=PositionRulesDTO.builder()
        .stopGainPercentage(100)
        .stopLossPercentage(50)
        .build();

Then, you can create the position:

createLongPosition(new CurrencyPairDTO(ETH,BTC),new BigDecimal("0.5"),rules);

At this moment, Cassandre will create a buy order of 0.5 ETH (1 ETH costs 1500 USDT) that will cost 750 USDT. The position status will be OPENINGopen in new window and, when all the corresponding trades have arrived, the status will be OPENEDopen in new window .

TIP

Note: if you want to check if you have enough funds available (at least 750 USDT in our case) before creating the position, you can use the canBuy()open in new window method.

From now on, for every ticker received, Cassandre will automatically calculate the position gain to see if it triggers one of our two rules (100% stop gain and 50% stop loss).

For example, if we receive a ticker with a price of 3000 USDT for 1 ETH, Cassandre will calculate that if we sell our position right now (AKA "closing the position"), we will get 1 500 USDT, a 100% gain. As our rule is triggered, Cassandre will automatically create a selling order of our 0.5 ETH. The position status will move to CLOSINGopen in new window , and when all the corresponding trades have arrived, the status will be CLOSEDopen in new window .

You can know your exact gain on this position by calling its getGain()open in new window method.

Short position

A short positionopen in new window works the opposite way. With a short position, you bet that the price will go down.

Let's say you create a short position on 1 ETH with this command:

createShortPosition(new CurrencyPairDTO(ETH,BTC),new BigDecimal("1"),rules);

Cassandre will sell 1 ETH for 1 500 USDT and wait until the price is down enough to buy 2 ETH with the 1 500 USDT.

TIP

Note: if you want to check if you have enough funds available (at 1 ETH in our case) before creating the position, you can use the canSell()open in new window method.

Gains

On PositionDTOopen in new window, you can get the:

On a closed position, you can get the gain & fees with getGain()open in new window