Interface OrderContext


public interface OrderContext
This interface provides the capability to create and manage orders.
  • Method Details

    • getDataContext

      DataContext getDataContext()
      Gets the data context associated with this strategy. This provides access to the historical data.
      Returns:
      data context
    • getInstrument

      Instrument getInstrument()
      Gets the instrument associated with the data provided in this context.
      Returns:
      primary instrument associated with this strategy
    • getDefaults

      Defaults getDefaults()
      Defaults defined by the system.
      Returns:
      system defaults
    • getCurrentTime

      long getCurrentTime()
      Gets the current time. This is the time synchronized with the Broker/Data Service (if supported by the underlying service).
      Returns:
      current time in milliseconds since 1970
    • getPosition

      int getPosition()
      Gets the current open position for this strategy for the default (chart) instrument. A negative number is returned if this is a 'Short' position.
      Returns:
      current open position.
    • getPositionAsFloat

      float getPositionAsFloat()
      Gets the current open position for this strategy for the default (chart) instrument. A negative number is returned if this is a 'Short' position.
      Returns:
      current open position.
    • getPosition

      int getPosition(Instrument instr)
      Gets the current open position for this strategy for the given instrument. A negative number is returned if this is a 'Short' position.
      Returns:
      current open position.
    • getPositionAsFloat

      float getPositionAsFloat(Instrument instr)
      Gets the current open position for this strategy for the given instrument. A negative number is returned if this is a 'Short' position.
      Returns:
      current open position.
    • getAvgEntryPrice

      float getAvgEntryPrice()
      Gets the average entry price for the current position using the default (chart) instrument.
      Returns:
      average entry price for the current position
    • getAvgEntryPrice

      float getAvgEntryPrice(Instrument instr)
      Gets the average entry price for the current position and instrument.
      Returns:
      average entry price for the current position
    • getTotalRealizedPnL

      double getTotalRealizedPnL()
      Gets the total realized pnl (profit/loss) since this strategy was opened (or last reset).
      Returns:
      total realized profit/loss
    • getRealizedPnL

      double getRealizedPnL()
      Gets the realized PnL (profit/loss) for the current 'leg' of the strategy.
      Returns:
      realized profit/loss
    • getUnrealizedPnL

      double getUnrealizedPnL()
      Gets the PnL for the open position. This value will change with every tick.
      Returns:
      unrealized profit/loss for the open position.
    • getAccountPosition

      int getAccountPosition()
      Gets the current open position for the account (for the default position). A negative number is returned if this is a 'Short' position.
      Returns:
      current open position for the selected account.
    • getAccountPositionAsFloat

      float getAccountPositionAsFloat()
      Gets the current open position for the account (for the default position). A negative number is returned if this is a 'Short' position.
      Returns:
      current open position for the selected account.
    • getAccountPosition

      int getAccountPosition(Instrument instr)
      Gets the current open position for the account for the given instrument. A negative number is returned if this is a 'Short' position.
      Returns:
      current open position for the selected account.
    • getAccountPositionAsFloat

      float getAccountPositionAsFloat(Instrument instr)
      Gets the current open position for the account for the given instrument. A negative number is returned if this is a 'Short' position.
      Returns:
      current open position for the selected account.
    • getAccountAvgEntryPrice

      float getAccountAvgEntryPrice()
      Gets the average entry price for the current position on the selected account (for the chart instrument).
      Returns:
      average entry price for the current position on the selected account
    • getAccountAvgEntryPrice

      float getAccountAvgEntryPrice(Instrument instr)
      Gets the average entry price for the current position on the selected account for the given instrument.
      Returns:
      average entry price for the current position on the selected account
    • getAccountUnrealizedPnL

      float getAccountUnrealizedPnL()
      Gets the average entry price for the current position on the selected account.
      Returns:
      average entry price for the current position on the selected account
    • getCashBalance

      double getCashBalance()
      Gets the current cash balance for the account.
      Returns:
      current cash balance for the account
    • getExecutions

      List<Execution> getExecutions()
      Gets the list of executed orders that have occurred since this strategy was activated.
      Returns:
      list of executions for this strategy
    • getBaseCurrency

      String getBaseCurrency()
      Gets the symbol for the base currency.
      Returns:
      base currency
    • convertToBaseCurrency

      double convertToBaseCurrency(double pnl)
      Converts the given amount to the amount in the base currency using the instrument associated with this context.
      Parameters:
      pnl - profit/loss
      Returns:
      the pnl converted to the base currency
    • convertToBaseCurrency

      double convertToBaseCurrency(Instrument instr, double pnl)
      Converts the given amount to the amount in the base currency.
      Parameters:
      instr - instrument
      pnl - profit/loss
      Returns:
      the pnl converted to the base currency
    • calcPnl

      double calcPnl(float entryPrice, int qty)
      Convenience Method. Calculates the current profit/loss from the given entry price and quantity (using the primary instrument). Note: this is in the currency of the instrument associated with this context.
      Parameters:
      entryPrice -
      qty -
      Returns:
      calculated profit/loss
    • calcPnl

      double calcPnl(float entryPrice, float qty)
      Convenience Method. Calculates the current profit/loss from the given entry price and quantity (using the primary instrument). Note: this is in the currency of the instrument associated with this context.
      Parameters:
      entryPrice -
      qty -
      Returns:
      calculated profit/loss
    • calcPnl

      double calcPnl(Instrument instr, float entryPrice, int qty)
      Convenience Method. Calculates the current profit/loss from the given entry price, quantity and instrument. Note: this is in the currency of the instrument associated with this context.
      Parameters:
      instr - instrument
      entryPrice -
      qty -
      Returns:
      calculated profit/loss
    • calcPnl

      double calcPnl(Instrument instr, float entryPrice, float qty)
      Convenience Method. Calculates the current profit/loss from the given entry price, quantity and instrument. Note: this is in the currency of the instrument associated with this context.
      Parameters:
      instr - instrument
      entryPrice -
      qty -
      Returns:
      calculated profit/loss
    • calcPnl

      double calcPnl(float entryPrice, float exitPrice, int qty)
      Convenience Method. Calculates the profit/loss from the given entry price, exit price and quantity (using the primary instrument). Note: this is in the currency of the instrument associated with this context.
      Parameters:
      entryPrice -
      exitPrice -
      qty -
      Returns:
      calculated profit/loss
    • calcPnl

      double calcPnl(float entryPrice, float exitPrice, float qty)
      Convenience Method. Calculates the profit/loss from the given entry price, exit price and quantity (using the primary instrument). Note: this is in the currency of the instrument associated with this context.
      Parameters:
      entryPrice -
      exitPrice -
      qty -
      Returns:
      calculated profit/loss
    • calcPnl

      double calcPnl(Instrument instr, float entryPrice, float exitPrice, int qty)
      Convenience Method. Calculates the profit/loss from the given entry price, exit price, quantity and instrument.
      Parameters:
      instr - instrument
      entryPrice -
      exitPrice -
      qty -
      Returns:
      calculated profit/loss
    • calcPnl

      double calcPnl(Instrument instr, float entryPrice, float exitPrice, float qty)
      Convenience Method. Calculates the profit/loss from the given entry price, exit price, quantity and instrument.
      Parameters:
      instr - instrument
      entryPrice -
      exitPrice -
      qty -
      Returns:
      calculated profit/loss
    • supportsHedging

      boolean supportsHedging()
      Determines if this account (broker) supports hedging.
      Returns:
      true if the broker supports hedging.
    • getActiveOrders

      List<Order> getActiveOrders()
      Gets all of the active orders that are associated with this strategy.
      Returns:
      list of all active orders associated to this strategy
    • buy

      void buy(Instrument instr, int qty)
      Convenience Method: Places a BUY order for the given instrument at market price.
      Parameters:
      instr - instrument
      qty - number of shares/units to buy
    • buy

      void buy(int qty)
      Convenience Method: Places a BUY order for the current instrument at market price.
      Parameters:
      qty - number of shares/units to buy
    • sell

      void sell(Instrument instr, int qty)
      Convenience Method: Places a SELL order for the given instrument at market price.
      Parameters:
      instr - instrument
      qty - number of shares/units to sell
    • sell

      void sell(int qty)
      Convenience Method: Places a SELL order for the current instrument at market price.
      Parameters:
      qty - number of shares/units to sell
    • buy

      void buy(Instrument instr, float qty)
      Convenience Method: Places a BUY order for the given instrument at market price.
      Parameters:
      instr - instrument
      qty - number of shares/units to buy
    • buy

      void buy(float qty)
      Convenience Method: Places a BUY order for the current instrument at market price.
      Parameters:
      qty - number of shares/units to buy
    • sell

      void sell(Instrument instr, float qty)
      Convenience Method: Places a SELL order for the given instrument at market price.
      Parameters:
      instr - instrument
      qty - number of shares/units to sell
    • sell

      void sell(float qty)
      Convenience Method: Places a SELL order for the current instrument at market price.
      Parameters:
      qty - number of shares/units to sell
    • closeAtMarket

      void closeAtMarket()
      Closes the position held by this strategy. This method will wait until the market order(s) have been filled.
    • closeAccountAtMarket

      void closeAccountAtMarket() throws MException
      Closes the position held by the selected account. This method will wait until the market order(s) have been filled.
      Throws:
      MException
    • submitOrders

      void submitOrders(Order... orders)
      Use this method to submit one or more orders to the broker. If one or more of the orders are new, the orders will be created otherwise the existing order will be modified. Please note: this is a synchronous call and may take a significant amount of time to return.
      Parameters:
      orders - orders to submit
    • submitOrders

      void submitOrders(List<Order> orders)
      Use this method to submit one or more orders to the broker. If one or more of the orders are new, the orders will be created otherwise the existing order will be modified. Please note: this is a synchronous call and may take a significant amount of time to return.
      Parameters:
      orders - list of orders to submit
    • cancelOrders

      void cancelOrders(Order... orders)
      Use this method to cancel one or more existing orders. Please note: this is a synchronous call and may take a significant amount of time to return.
      Parameters:
      orders - list of orders to cancel
    • cancelOrders

      void cancelOrders(List<Order> orders)
      Use this method to cancel one or more existing orders. Please note: this is a synchronous call and may take a significant amount of time to return.
      Parameters:
      orders - list of orders to cancel
    • cancelOrders

      void cancelOrders()
      Cancels all of the open orders for this strategy.
    • createMarketOrder

      Order createMarketOrder(Enums.OrderAction action, int qty)
      Creates a new 'Market' order.
      Parameters:
      action - order action (buy/sell)
      qty - quantity of shares/units
      Returns:
      order object
    • createMarketOrder

      Order createMarketOrder(Instrument instr, Enums.OrderAction action, int qty)
      Creates a new 'Market' order.
      Parameters:
      instr - instrument
      action - order action (buy/sell)
      qty - quantity of shares/units
      Returns:
      order object
    • createLimitOrder

      Order createLimitOrder(Enums.OrderAction action, Enums.TIF tif, int qty, float limitPrice)
      Creates a new 'Limit' order.
      Parameters:
      action - order action (buy/sell)
      tif - time in force
      qty - quantity of shares/units
      limitPrice -
      Returns:
      order object
    • createLimitOrder

      Order createLimitOrder(Instrument instr, Enums.OrderAction action, Enums.TIF tif, int qty, float limitPrice)
      Creates a new 'Limit' order.
      Parameters:
      instr - instrument
      action - order action (buy/sell)
      tif - time in force
      qty - quantity of shares/units
      limitPrice -
      Returns:
      order object
    • createStopOrder

      Order createStopOrder(Enums.OrderAction action, Enums.TIF tif, int qty, float stopPrice)
      Creates a new 'Stop' order.
      Parameters:
      action - order action (buy/sell)
      tif - time in force
      qty - quantity of shares/units
      stopPrice -
      Returns:
      order object
    • createStopOrder

      Order createStopOrder(Instrument instr, Enums.OrderAction action, Enums.TIF tif, int qty, float stopPrice)
      Creates a new 'Stop' order.
      Parameters:
      instr - instrument
      action - order action (buy/sell)
      tif - time in force
      qty - quantity of shares/units
      stopPrice -
      Returns:
      order object
    • createMarketOrder

      Order createMarketOrder(Object refId, Enums.OrderAction action, int qty)
      Creates a new 'Market' order using the current instrument. The refId parameter is used for hedging accounts to associate this order to an existing position.
      Parameters:
      refId - reference id
      action - order action (buy/sell)
      qty - quantity
      Returns:
      order object
    • createMarketOrder

      Order createMarketOrder(Instrument instr, Object refId, Enums.OrderAction action, int qty)
      Creates a new 'Market' order using the given instrument. The refId parameter is used for hedging accounts to associate this order to an existing position.
      Parameters:
      instr - instrument
      refId - reference id
      action - order action (buy/sell)
      qty - quantity
      Returns:
      order object
    • createLimitOrder

      Order createLimitOrder(Object refId, Enums.OrderAction action, Enums.TIF tif, int qty, float limitPrice)
      Creates a new 'Limit' order using the current instrument. The refId parameter is used for hedging accounts to associate this order to an existing position.
      Parameters:
      refId - reference id
      action - order action (buy/sell)
      qty - quantity
      limitPrice - limit price
      Returns:
      order object
    • createLimitOrder

      Order createLimitOrder(Instrument instr, Object refId, Enums.OrderAction action, Enums.TIF tif, int qty, float limitPrice)
      Creates a new 'Limit' order using the given instrument. The refId parameter is used for hedging accounts to associate this order to an existing position.
      Parameters:
      instr - instrument
      refId - reference id
      action - order action (buy/sell)
      qty - quantity
      limitPrice - limit price
      Returns:
      order object
    • createStopOrder

      Order createStopOrder(Object refId, Enums.OrderAction action, Enums.TIF tif, int qty, float stopPrice)
      Creates a new 'Stop' order using the current instrument. The refId parameter is used for hedging accounts to associate this order to an existing position.
      Parameters:
      refId - reference id
      action - order action (buy/sell)
      qty - quantity
      stopPrice - stop price
      Returns:
      order object
    • createStopOrder

      Order createStopOrder(Instrument instr, Object refId, Enums.OrderAction action, Enums.TIF tif, int qty, float stopPrice)
      Creates a new 'Stop' order using the given instrument. The refId parameter is used for hedging accounts to associate this order to an existing position.
      Parameters:
      instr - instrument
      refId - reference id
      action - order action (buy/sell)
      qty - quantity
      stopPrice - stop price
      Returns:
      order object
    • createMarketOrder

      Order createMarketOrder(Enums.OrderAction action, float qty)
      Creates a new 'Market' order.
      Parameters:
      action - order action (buy/sell)
      qty - quantity of shares/units
      Returns:
      order object
    • createMarketOrder

      Order createMarketOrder(Instrument instr, Enums.OrderAction action, float qty)
      Creates a new 'Market' order.
      Parameters:
      instr - instrument
      action - order action (buy/sell)
      qty - quantity of shares/units
      Returns:
      order object
    • createLimitOrder

      Order createLimitOrder(Enums.OrderAction action, Enums.TIF tif, float qty, float limitPrice)
      Creates a new 'Limit' order.
      Parameters:
      action - order action (buy/sell)
      tif - time in force
      qty - quantity of shares/units
      limitPrice -
      Returns:
      order object
    • createLimitOrder

      Order createLimitOrder(Instrument instr, Enums.OrderAction action, Enums.TIF tif, float qty, float limitPrice)
      Creates a new 'Limit' order.
      Parameters:
      instr - instrument
      action - order action (buy/sell)
      tif - time in force
      qty - quantity of shares/units
      limitPrice -
      Returns:
      order object
    • createStopOrder

      Order createStopOrder(Enums.OrderAction action, Enums.TIF tif, float qty, float stopPrice)
      Creates a new 'Stop' order.
      Parameters:
      action - order action (buy/sell)
      tif - time in force
      qty - quantity of shares/units
      stopPrice -
      Returns:
      order object
    • createStopOrder

      Order createStopOrder(Instrument instr, Enums.OrderAction action, Enums.TIF tif, float qty, float stopPrice)
      Creates a new 'Stop' order.
      Parameters:
      instr - instrument
      action - order action (buy/sell)
      tif - time in force
      qty - quantity of shares/units
      stopPrice -
      Returns:
      order object
    • createMarketOrder

      Order createMarketOrder(Object refId, Enums.OrderAction action, float qty)
      Creates a new 'Market' order using the current instrument. The refId parameter is used for hedging accounts to associate this order to an existing position.
      Parameters:
      refId - reference id
      action - order action (buy/sell)
      qty - quantity
      Returns:
      order object
    • createMarketOrder

      Order createMarketOrder(Instrument instr, Object refId, Enums.OrderAction action, float qty)
      Creates a new 'Market' order using the given instrument. The refId parameter is used for hedging accounts to associate this order to an existing position.
      Parameters:
      instr - instrument
      refId - reference id
      action - order action (buy/sell)
      qty - quantity
      Returns:
      order object
    • createLimitOrder

      Order createLimitOrder(Object refId, Enums.OrderAction action, Enums.TIF tif, float qty, float limitPrice)
      Creates a new 'Limit' order using the current instrument. The refId parameter is used for hedging accounts to associate this order to an existing position.
      Parameters:
      refId - reference id
      action - order action (buy/sell)
      qty - quantity
      limitPrice - limit price
      Returns:
      order object
    • createLimitOrder

      Order createLimitOrder(Instrument instr, Object refId, Enums.OrderAction action, Enums.TIF tif, float qty, float limitPrice)
      Creates a new 'Limit' order using the given instrument. The refId parameter is used for hedging accounts to associate this order to an existing position.
      Parameters:
      instr - instrument
      refId - reference id
      action - order action (buy/sell)
      qty - quantity
      limitPrice - limit price
      Returns:
      order object
    • createStopOrder

      Order createStopOrder(Object refId, Enums.OrderAction action, Enums.TIF tif, float qty, float stopPrice)
      Creates a new 'Stop' order using the current instrument. The refId parameter is used for hedging accounts to associate this order to an existing position.
      Parameters:
      refId - reference id
      action - order action (buy/sell)
      qty - quantity
      stopPrice - stop price
      Returns:
      order object
    • createStopOrder

      Order createStopOrder(Instrument instr, Object refId, Enums.OrderAction action, Enums.TIF tif, float qty, float stopPrice)
      Creates a new 'Stop' order using the given instrument. The refId parameter is used for hedging accounts to associate this order to an existing position.
      Parameters:
      instr - instrument
      refId - reference id
      action - order action (buy/sell)
      qty - quantity
      stopPrice - stop price
      Returns:
      order object