Class PositionDTO
- java.lang.Object
-
- tech.cassandre.trading.bot.dto.position.PositionDTO
-
public class PositionDTO extends Object
DTO representing a position. A position is the amount of a security, commodity or currency which is owned by an individual, dealer, institution, or other fiscal entity.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
PositionDTO.PositionDTOBuilder
-
Constructor Summary
Constructors Constructor Description PositionDTO(long newId, PositionTypeDTO newType, StrategyDTO newStrategy, CurrencyPairDTO newCurrencyPair, BigDecimal newAmount, OrderDTO newOpenOrder, PositionRulesDTO newRules)
Constructor.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static PositionDTO.PositionDTOBuilder
builder()
Optional<GainDTO>
calculateGainFromPrice(BigDecimal price)
Calculate the gain from a price.void
closePositionWithOrder(OrderDTO newCloseOrder)
Close position with order id.boolean
equals(Object o)
CurrencyAmountDTO
getAmount()
Amount that was ordered.CurrencyAmountDTO
getAmountToLock()
Returns amount locked by this position.OrderDTO
getClosingOrder()
The order created to close the position.CurrencyPairDTO
getCurrencyPair()
Currency pair.String
getDescription()
Get position description.GainDTO
getGain()
Returns the gain of the position.Optional<GainDTO>
getHighestCalculatedGain()
Getter highestCalculatedGain.CurrencyAmountDTO
getHighestGainPrice()
Price of the highest gain reached by this position.long
getId()
Technical ID.Optional<GainDTO>
getLatestCalculatedGain()
Getter latestCalculatedGain.CurrencyAmountDTO
getLatestGainPrice()
Price of the latest gain price for this position.Optional<GainDTO>
getLowestCalculatedGain()
Getter lowestCalculatedGain.CurrencyAmountDTO
getLowestGainPrice()
Price of the lowest gain reached by this position.OrderDTO
getOpeningOrder()
The order created to open the position.long
getPositionId()
An identifier that uniquely identifies the position.PositionRulesDTO
getRules()
Position rules.PositionStatusDTO
getStatus()
Returns position status.StrategyDTO
getStrategy()
The strategy that created the position.PositionTypeDTO
getType()
Position type (Long or Short).int
hashCode()
boolean
isForceClosing()
Indicates that the position must be closed no matter the rules.boolean
orderUpdate(OrderDTO updatedOrder)
Method called by Cassandre on every order update.boolean
shouldBeClosed()
Returns true if the position should be closed.boolean
tickerUpdate(TickerDTO ticker)
Method called by Cassandre on every ticker update.String
toString()
boolean
tradeUpdate(TradeDTO trade)
Method called by Cassandre on every trade update.
-
-
-
Constructor Detail
-
PositionDTO
public PositionDTO(long newId, PositionTypeDTO newType, StrategyDTO newStrategy, CurrencyPairDTO newCurrencyPair, BigDecimal newAmount, OrderDTO newOpenOrder, PositionRulesDTO newRules)
Constructor.- Parameters:
newId
- position idnewType
- position typenewStrategy
- strategynewCurrencyPair
- currency pairnewAmount
- amountnewOpenOrder
- open ordernewRules
- position rules
-
-
Method Detail
-
getStatus
public final PositionStatusDTO getStatus()
Returns position status.- Returns:
- status
-
calculateGainFromPrice
public Optional<GainDTO> calculateGainFromPrice(BigDecimal price)
Calculate the gain from a price.- Parameters:
price
- price- Returns:
- gain
-
orderUpdate
public final boolean orderUpdate(OrderDTO updatedOrder)
Method called by Cassandre on every order update.- Parameters:
updatedOrder
- order- Returns:
- true if the order updated the position.
-
tradeUpdate
public boolean tradeUpdate(TradeDTO trade)
Method called by Cassandre on every trade update.- Parameters:
trade
- trade- Returns:
- true if the trade updated the position.
-
tickerUpdate
public final boolean tickerUpdate(TickerDTO ticker)
Method called by Cassandre on every ticker update.- Parameters:
ticker
- ticker- Returns:
- true if the ticker updated the position.
-
getAmountToLock
public CurrencyAmountDTO getAmountToLock()
Returns amount locked by this position.- Returns:
- amount
-
shouldBeClosed
public boolean shouldBeClosed()
Returns true if the position should be closed.- Returns:
- true if the rules says the position should be closed.
-
closePositionWithOrder
public final void closePositionWithOrder(OrderDTO newCloseOrder)
Close position with order id.- Parameters:
newCloseOrder
- the closeOrderId to set
-
getLowestCalculatedGain
public final Optional<GainDTO> getLowestCalculatedGain()
Getter lowestCalculatedGain.- Returns:
- lowestCalculatedGain
-
getHighestCalculatedGain
public final Optional<GainDTO> getHighestCalculatedGain()
Getter highestCalculatedGain.- Returns:
- highestCalculatedGain
-
getLatestCalculatedGain
public final Optional<GainDTO> getLatestCalculatedGain()
Getter latestCalculatedGain.- Returns:
- latestCalculatedGain
-
getGain
public GainDTO getGain()
Returns the gain of the position. Of course the position should be closed to have a gain.- Returns:
- gain
-
getDescription
public final String getDescription()
Get position description.- Returns:
- description
-
builder
public static PositionDTO.PositionDTOBuilder builder()
-
getId
public long getId()
Technical ID.
-
getPositionId
public long getPositionId()
An identifier that uniquely identifies the position.
-
getType
public PositionTypeDTO getType()
Position type (Long or Short).
-
getStrategy
public StrategyDTO getStrategy()
The strategy that created the position.
-
getCurrencyPair
public CurrencyPairDTO getCurrencyPair()
Currency pair.
-
getAmount
public CurrencyAmountDTO getAmount()
Amount that was ordered.
-
getRules
public PositionRulesDTO getRules()
Position rules.
-
isForceClosing
public boolean isForceClosing()
Indicates that the position must be closed no matter the rules.
-
getOpeningOrder
public OrderDTO getOpeningOrder()
The order created to open the position.
-
getClosingOrder
public OrderDTO getClosingOrder()
The order created to close the position.
-
getLowestGainPrice
public CurrencyAmountDTO getLowestGainPrice()
Price of the lowest gain reached by this position.
-
getHighestGainPrice
public CurrencyAmountDTO getHighestGainPrice()
Price of the highest gain reached by this position.
-
getLatestGainPrice
public CurrencyAmountDTO getLatestGainPrice()
Price of the latest gain price for this position.
-
-