Class 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 Detail

      • 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 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 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 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 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
      • hashCode

        public final int hashCode()
        Overrides:
        hashCode in class Object
      • 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.
      • 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 lowest gain reached by this position.
      • getHighestGainPrice

        public CurrencyAmountDTO getHighestGainPrice()
        Price of highest gain reached by this position.
      • getLatestGainPrice

        public CurrencyAmountDTO getLatestGainPrice()
        Price of latest gain price for this position.