Class PositionDTO
java.lang.Object
tech.cassandre.trading.bot.dto.position.PositionDTO
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
-
Constructor Summary
ConstructorDescriptionPositionDTO
(long newId, PositionTypeDTO newType, StrategyDTO newStrategy, CurrencyPairDTO newCurrencyPair, BigDecimal newAmount, OrderDTO newOpenOrder, PositionRulesDTO newRules) Constructor. -
Method Summary
Modifier and TypeMethodDescriptionbuilder()
calculateGainFromPrice
(BigDecimal price) Calculate the gain from a price.final void
closePositionWithOrder
(OrderDTO newCloseOrder) Close position with order.final boolean
Position amount.Returns amount locked by this position.The order created to close the position.Currency pair.final String
Get position description.getGain()
Returns the gain of the position.Getter highestCalculatedGain.Price of the highest gain reached by this position.Getter latestCalculatedGain.Price of the latest gain price for this position.Getter lowestCalculatedGain.Price of the lowest gain reached by this position.The order created to open the position.long
An identifier that uniquely identifies the position.getRules()
Position rules.final PositionStatusDTO
Returns position status.The strategy that created the position.getType()
Position type (Long or Short).long
getUid()
Technical ID.final int
hashCode()
boolean
Indicates if the position should be closed automatically by Cassandre.boolean
Indicates that the position must be closed no matter the rules.final boolean
orderUpdate
(OrderDTO updatedOrder) Method called by Cassandre on every order update.boolean
Returns true if the position should be closed.final boolean
tickerUpdate
(TickerDTO ticker) Method called by Cassandre on every ticker update.toString()
boolean
tradeUpdate
(TradeDTO trade) Method called by Cassandre on every trade update.
-
Constructor Details
-
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 Details
-
getStatus
Returns position status.- Returns:
- status
-
calculateGainFromPrice
Calculate the gain from a price.- Parameters:
price
- price- Returns:
- gain
-
orderUpdate
Method called by Cassandre on every order update.- Parameters:
updatedOrder
- order- Returns:
- true if the order is linked to the position.
-
tradeUpdate
Method called by Cassandre on every trade update.- Parameters:
trade
- trade- Returns:
- true if the trade is linked to the position.
-
tickerUpdate
Method called by Cassandre on every ticker update.- Parameters:
ticker
- ticker- Returns:
- true if the ticker is linked to the position.
-
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
Close position with order.- Parameters:
newCloseOrder
- the order closing the position
-
getLowestCalculatedGain
Getter lowestCalculatedGain.- Returns:
- lowestCalculatedGain
-
getHighestCalculatedGain
Getter highestCalculatedGain.- Returns:
- highestCalculatedGain
-
getLatestCalculatedGain
Getter latestCalculatedGain.- Returns:
- latestCalculatedGain
-
getGain
Returns the gain of the position. Of course the position should be closed to have a gain.- Returns:
- gain
-
getDescription
Get position description.- Returns:
- description
-
equals
-
hashCode
public final int hashCode() -
builder
-
getUid
public long getUid()Technical ID. -
getPositionId
public long getPositionId()An identifier that uniquely identifies the position. -
getType
Position type (Long or Short). -
getStrategy
The strategy that created the position. -
getCurrencyPair
Currency pair. -
getAmount
Position amount. -
getRules
Position rules. -
isAutoClose
public boolean isAutoClose()Indicates if the position should be closed automatically by Cassandre. -
isForceClosing
public boolean isForceClosing()Indicates that the position must be closed no matter the rules. -
getOpeningOrder
The order created to open the position. -
getClosingOrder
The order created to close the position. -
getLowestGainPrice
Price of the lowest gain reached by this position. -
getHighestGainPrice
Price of the highest gain reached by this position. -
getLatestGainPrice
Price of the latest gain price for this position. -
toString
-