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.
  • Constructor Details

    • PositionDTO

      public PositionDTO(long newId, PositionTypeDTO newType, StrategyDTO newStrategy, CurrencyPairDTO newCurrencyPair, BigDecimal newAmount, OrderDTO newOpenOrder, PositionRulesDTO newRules)
      Constructor.
      Parameters:
      newId - position id
      newType - position type
      newStrategy - strategy
      newCurrencyPair - currency pair
      newAmount - amount
      newOpenOrder - open order
      newRules - position rules
  • Method Details

    • 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 is linked to the position.
    • tradeUpdate

      public boolean tradeUpdate(TradeDTO trade)
      Method called by Cassandre on every trade update.
      Parameters:
      trade - trade
      Returns:
      true if the trade is linked to 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 is linked to 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.
      Parameters:
      newCloseOrder - the order closing the position
    • 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
    • equals

      public final boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public final int hashCode()
      Overrides:
      hashCode in class Object
    • builder

      public static PositionDTO.PositionDTOBuilder builder()
    • getUid

      public long getUid()
      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()
      Position amount.
    • getRules

      public PositionRulesDTO 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

      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.
    • toString

      public String toString()
      Overrides:
      toString in class Object