Class GridTradeRule


  • public class GridTradeRule
    extends Object
    Grid trading rule.

    The full constructor takes the fields a valid grid order requires; optional parameters are set through the chained setters. A no-arg constructor is also available for setter-only use.

    • Constructor Detail

      • GridTradeRule

        public GridTradeRule()
        Creates an empty rule; populate it through the chained setters.
      • GridTradeRule

        public GridTradeRule​(BigDecimal basePrice,
                             BigDecimal upperPrice,
                             BigDecimal lowerPrice,
                             GridTrigger trigger,
                             BigDecimal quantity,
                             BigDecimal upperQuantity,
                             BigDecimal lowerQuantity,
                             GridTimeInForce timeInForce)
        Creates a rule with the fields a valid grid order requires. The gateway still validates business rules, but this makes the minimum field set visible in the signature instead of leaving every field optional.
        Parameters:
        basePrice - base price the grid is anchored to
        upperPrice - upper price bound
        lowerPrice - lower price bound
        trigger - up/down trigger thresholds (percent or spread)
        quantity - quantity per trigger
        upperQuantity - quantity handled when the upper bound is reached
        lowerQuantity - quantity handled when the lower bound is reached
        timeInForce - time in force
    • Method Detail

      • limitEvents

        public GridTradeRule limitEvents​(GridLimitEvent upper,
                                         GridLimitEvent lower)
        Sets the actions taken at the upper / lower bounds.
        Parameters:
        upper - action at the upper bound
        lower - action at the lower bound
        Returns:
        this instance for chaining
      • depths

        public GridTradeRule depths​(int sell,
                                    int buy)
        Sets the sell / buy order-book depths (0 = use the order type).
        Parameters:
        sell - sell-side depth
        buy - buy-side depth
        Returns:
        this instance for chaining
      • orderTypes

        public GridTradeRule orderTypes​(String up,
                                        String down)
        Sets the sell / buy order types (GMO / GLO / GTG).
        Parameters:
        up - sell-side order type
        down - buy-side order type
        Returns:
        this instance for chaining
      • multipleTrigger

        public GridTradeRule multipleTrigger​(boolean value)
        Allows a single grid level to trigger multiple times.
        Parameters:
        value - multiple-trigger flag
        Returns:
        this instance for chaining
      • supportShortsell

        public GridTradeRule supportShortsell​(boolean value)
        Allows short selling.
        Parameters:
        value - short-sell flag
        Returns:
        this instance for chaining
      • rth

        public GridTradeRule rth​(int value)
        Sets the regular-trading-hours flag (0 / 1 / 2).
        Parameters:
        value - regular trading hours flag
        Returns:
        this instance for chaining
      • expireTime

        public GridTradeRule expireTime​(long unixSeconds)
        Sets the expiry time (unix seconds), used with a GTD time-in-force.
        Parameters:
        unixSeconds - expiry time (unix seconds)
        Returns:
        this instance for chaining
      • setSubmittedBasePrice

        public GridTradeRule setSubmittedBasePrice​(BigDecimal submittedBasePrice)
        Sets the base price the grid is anchored to.
        Parameters:
        submittedBasePrice - base price
        Returns:
        this instance for chaining
      • setUpperLimitPrice

        public GridTradeRule setUpperLimitPrice​(BigDecimal upperLimitPrice)
        Sets the upper price bound.
        Parameters:
        upperLimitPrice - upper price bound
        Returns:
        this instance for chaining
      • setLowerLimitPrice

        public GridTradeRule setLowerLimitPrice​(BigDecimal lowerLimitPrice)
        Sets the lower price bound.
        Parameters:
        lowerLimitPrice - lower price bound
        Returns:
        this instance for chaining
      • setTriggerPriceType

        public GridTradeRule setTriggerPriceType​(TriggerPriceType triggerPriceType)
        Sets the trigger price type.
        Parameters:
        triggerPriceType - trigger price type
        Returns:
        this instance for chaining
      • setTriggerSpreadUp

        public GridTradeRule setTriggerSpreadUp​(BigDecimal triggerSpreadUp)
        Sets the upward trigger spread (absolute).
        Parameters:
        triggerSpreadUp - upward trigger spread
        Returns:
        this instance for chaining
      • setTriggerSpreadDown

        public GridTradeRule setTriggerSpreadDown​(BigDecimal triggerSpreadDown)
        Sets the downward trigger spread (absolute).
        Parameters:
        triggerSpreadDown - downward trigger spread
        Returns:
        this instance for chaining
      • setTriggerPercentUp

        public GridTradeRule setTriggerPercentUp​(BigDecimal triggerPercentUp)
        Sets the upward trigger percent.
        Parameters:
        triggerPercentUp - upward trigger percent
        Returns:
        this instance for chaining
      • setTriggerPercentDown

        public GridTradeRule setTriggerPercentDown​(BigDecimal triggerPercentDown)
        Sets the downward trigger percent.
        Parameters:
        triggerPercentDown - downward trigger percent
        Returns:
        this instance for chaining
      • setMultipleTrigger

        public GridTradeRule setMultipleTrigger​(Boolean multipleTrigger)
        Sets whether a single grid level may trigger multiple times.
        Parameters:
        multipleTrigger - multiple-trigger flag
        Returns:
        this instance for chaining
      • setTimeInForce

        public GridTradeRule setTimeInForce​(GridTimeInForce timeInForce)
        Sets the time in force.
        Parameters:
        timeInForce - time in force
        Returns:
        this instance for chaining
      • setUpperLimitQuantity

        public GridTradeRule setUpperLimitQuantity​(BigDecimal upperLimitQuantity)
        Sets the quantity handled when the upper bound is reached.
        Parameters:
        upperLimitQuantity - quantity
        Returns:
        this instance for chaining
      • setLowerLimitQuantity

        public GridTradeRule setLowerLimitQuantity​(BigDecimal lowerLimitQuantity)
        Sets the quantity handled when the lower bound is reached.
        Parameters:
        lowerLimitQuantity - quantity
        Returns:
        this instance for chaining
      • setExpireTime

        public GridTradeRule setExpireTime​(Long expireTime)
        Sets the expiry time (unix seconds), used with GTD.
        Parameters:
        expireTime - expiry time (unix seconds)
        Returns:
        this instance for chaining
      • setUpperLimitEvent

        public GridTradeRule setUpperLimitEvent​(GridLimitEvent upperLimitEvent)
        Sets the action when the upper bound is reached.
        Parameters:
        upperLimitEvent - action
        Returns:
        this instance for chaining
      • setLowerLimitEvent

        public GridTradeRule setLowerLimitEvent​(GridLimitEvent lowerLimitEvent)
        Sets the action when the lower bound is reached.
        Parameters:
        lowerLimitEvent - action
        Returns:
        this instance for chaining
      • setTriggerSellDepth

        public GridTradeRule setTriggerSellDepth​(Integer triggerSellDepth)
        Sets the sell-side order-book depth (-5..5, 0 = use gridOrderTypeUp).
        Parameters:
        triggerSellDepth - sell-side depth
        Returns:
        this instance for chaining
      • setTriggerBuyDepth

        public GridTradeRule setTriggerBuyDepth​(Integer triggerBuyDepth)
        Sets the buy-side order-book depth (-5..5, 0 = use gridOrderTypeDown).
        Parameters:
        triggerBuyDepth - buy-side depth
        Returns:
        this instance for chaining
      • setTriggerQuantity

        public GridTradeRule setTriggerQuantity​(BigDecimal triggerQuantity)
        Sets the quantity per trigger.
        Parameters:
        triggerQuantity - quantity per trigger
        Returns:
        this instance for chaining
      • setSupportShortsell

        public GridTradeRule setSupportShortsell​(Boolean supportShortsell)
        Sets whether short selling is allowed.
        Parameters:
        supportShortsell - short-sell flag
        Returns:
        this instance for chaining
      • setRth

        public GridTradeRule setRth​(Integer rth)
        Sets the regular trading hours flag (0 / 1 / 2).
        Parameters:
        rth - regular trading hours flag
        Returns:
        this instance for chaining
      • setGridOrderTypeUp

        public GridTradeRule setGridOrderTypeUp​(String gridOrderTypeUp)
        Sets the sell-side order type when depth is 0 (GMO / GLO / GTG).
        Parameters:
        gridOrderTypeUp - sell-side order type
        Returns:
        this instance for chaining
      • setGridOrderTypeDown

        public GridTradeRule setGridOrderTypeDown​(String gridOrderTypeDown)
        Sets the buy-side order type when depth is 0 (GMO / GLO / GTG).
        Parameters:
        gridOrderTypeDown - buy-side order type
        Returns:
        this instance for chaining