Position management
Cassandre provides a simple way to manage your positions automatically.
Long position
You can create a long position with the createLongPosition() 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 PositionRulesDTO 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 OPENING and, when all the corresponding trades have arrived, the status will be OPENED .
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() 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 CLOSING , and when all the corresponding trades have arrived, the status will be CLOSED .
You can know your exact gain on this position by calling its getGain() method.
Short position
A short position 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() method.
Gains
On PositionDTO, you can get the:
- The lowest calculated gain with getLowestCalculatedGain()
- The highest calculated gain with getHighestCalculatedGain()
- The latest calculated gain with getLatestCalculatedGain()
On a closed position, you can get the gain & fees with getGain()