Interface OrderContext
public interface OrderContext
This interface provides the capability to create and manage orders.
-
Method Summary
Modifier and TypeMethodDescriptionvoid
buy
(float qty) Convenience Method: Places a BUY order for the current instrument at market price.void
buy
(int qty) Convenience Method: Places a BUY order for the current instrument at market price.void
buy
(Instrument instr, float qty) Convenience Method: Places a BUY order for the given instrument at market price.void
buy
(Instrument instr, int qty) Convenience Method: Places a BUY order for the given instrument at market price.double
calcPnl
(float entryPrice, float qty) Convenience Method.double
calcPnl
(float entryPrice, float exitPrice, float qty) Convenience Method.double
calcPnl
(float entryPrice, float exitPrice, int qty) Convenience Method.double
calcPnl
(float entryPrice, int qty) Convenience Method.double
calcPnl
(Instrument instr, float entryPrice, float qty) Convenience Method.double
calcPnl
(Instrument instr, float entryPrice, float exitPrice, float qty) Convenience Method.double
calcPnl
(Instrument instr, float entryPrice, float exitPrice, int qty) Convenience Method.double
calcPnl
(Instrument instr, float entryPrice, int qty) Convenience Method.void
Cancels all of the open orders for this strategy.void
cancelOrders
(Order... orders) Use this method to cancel one or more existing orders.void
cancelOrders
(List<Order> orders) Use this method to cancel one or more existing orders.void
Closes the position held by the selected account.void
Closes the position held by this strategy.double
convertToBaseCurrency
(double pnl) Converts the given amount to the amount in the base currency using the instrument associated with this context.double
convertToBaseCurrency
(Instrument instr, double pnl) Converts the given amount to the amount in the base currency.createLimitOrder
(Enums.OrderAction action, Enums.TIF tif, float qty, float limitPrice) Creates a new 'Limit' order.createLimitOrder
(Enums.OrderAction action, Enums.TIF tif, int qty, float limitPrice) Creates a new 'Limit' order.createLimitOrder
(Instrument instr, Enums.OrderAction action, Enums.TIF tif, float qty, float limitPrice) Creates a new 'Limit' order.createLimitOrder
(Instrument instr, Enums.OrderAction action, Enums.TIF tif, int qty, float limitPrice) Creates a new 'Limit' 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.createLimitOrder
(Instrument instr, Object refId, Enums.OrderAction action, Enums.TIF tif, int qty, float limitPrice) Creates a new 'Limit' order using the given instrument.createLimitOrder
(Object refId, Enums.OrderAction action, Enums.TIF tif, float qty, float limitPrice) Creates a new 'Limit' order using the current instrument.createLimitOrder
(Object refId, Enums.OrderAction action, Enums.TIF tif, int qty, float limitPrice) Creates a new 'Limit' order using the current instrument.createMarketOrder
(Enums.OrderAction action, float qty) Creates a new 'Market' order.createMarketOrder
(Enums.OrderAction action, int qty) Creates a new 'Market' order.createMarketOrder
(Instrument instr, Enums.OrderAction action, float qty) Creates a new 'Market' order.createMarketOrder
(Instrument instr, Enums.OrderAction action, int qty) Creates a new 'Market' order.createMarketOrder
(Instrument instr, Object refId, Enums.OrderAction action, float qty) Creates a new 'Market' order using the given instrument.createMarketOrder
(Instrument instr, Object refId, Enums.OrderAction action, int qty) Creates a new 'Market' order using the given instrument.createMarketOrder
(Object refId, Enums.OrderAction action, float qty) Creates a new 'Market' order using the current instrument.createMarketOrder
(Object refId, Enums.OrderAction action, int qty) Creates a new 'Market' order using the current instrument.createStopOrder
(Enums.OrderAction action, Enums.TIF tif, float qty, float stopPrice) Creates a new 'Stop' order.createStopOrder
(Enums.OrderAction action, Enums.TIF tif, int qty, float stopPrice) Creates a new 'Stop' order.createStopOrder
(Instrument instr, Enums.OrderAction action, Enums.TIF tif, float qty, float stopPrice) Creates a new 'Stop' order.createStopOrder
(Instrument instr, Enums.OrderAction action, Enums.TIF tif, int qty, float stopPrice) Creates a new 'Stop' 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.createStopOrder
(Instrument instr, Object refId, Enums.OrderAction action, Enums.TIF tif, int qty, float stopPrice) Creates a new 'Stop' order using the given instrument.createStopOrder
(Object refId, Enums.OrderAction action, Enums.TIF tif, float qty, float stopPrice) Creates a new 'Stop' order using the current instrument.createStopOrder
(Object refId, Enums.OrderAction action, Enums.TIF tif, int qty, float stopPrice) Creates a new 'Stop' order using the current instrument.float
Gets the average entry price for the current position on the selected account (for the chart instrument).float
Gets the average entry price for the current position on the selected account for the given instrument.int
Gets the current open position for the account (for the default position).int
getAccountPosition
(Instrument instr) Gets the current open position for the account for the given instrument.float
Gets the current open position for the account (for the default position).float
Gets the current open position for the account for the given instrument.float
Gets the average entry price for the current position on the selected account.Gets all of the active orders that are associated with this strategy.float
Gets the average entry price for the current position using the default (chart) instrument.float
getAvgEntryPrice
(Instrument instr) Gets the average entry price for the current position and instrument.Gets the symbol for the base currency.double
Gets the current cash balance for the account.long
Gets the current time.Gets the data context associated with this strategy.Defaults defined by the system.Gets the list of executed orders that have occurred since this strategy was activated.Gets the instrument associated with the data provided in this context.int
Gets the current open position for this strategy for the default (chart) instrument.int
getPosition
(Instrument instr) Gets the current open position for this strategy for the given instrument.float
Gets the current open position for this strategy for the default (chart) instrument.float
getPositionAsFloat
(Instrument instr) Gets the current open position for this strategy for the given instrument.double
Gets the realized PnL (profit/loss) for the current 'leg' of the strategy.double
Gets the total realized pnl (profit/loss) since this strategy was opened (or last reset).double
Gets the PnL for the open position.void
sell
(float qty) Convenience Method: Places a SELL order for the current instrument at market price.void
sell
(int qty) Convenience Method: Places a SELL order for the current instrument at market price.void
sell
(Instrument instr, float qty) Convenience Method: Places a SELL order for the given instrument at market price.void
sell
(Instrument instr, int qty) Convenience Method: Places a SELL order for the given instrument at market price.void
submitOrders
(Order... orders) Use this method to submit one or more orders to the broker.void
submitOrders
(List<Order> orders) Use this method to submit one or more orders to the broker.boolean
Determines if this account (broker) supports hedging.
-
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
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
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
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
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
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
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
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
Converts the given amount to the amount in the base currency.- Parameters:
instr
- instrumentpnl
- 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
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
- instrumententryPrice
-qty
-- Returns:
- calculated profit/loss
-
calcPnl
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
- instrumententryPrice
-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
Convenience Method. Calculates the profit/loss from the given entry price, exit price, quantity and instrument.- Parameters:
instr
- instrumententryPrice
-exitPrice
-qty
-- Returns:
- calculated profit/loss
-
calcPnl
Convenience Method. Calculates the profit/loss from the given entry price, exit price, quantity and instrument.- Parameters:
instr
- instrumententryPrice
-exitPrice
-qty
-- Returns:
- calculated profit/loss
-
supportsHedging
boolean supportsHedging()Determines if this account (broker) supports hedging.- Returns:
- true if the broker supports hedging.
-
getActiveOrders
Gets all of the active orders that are associated with this strategy.- Returns:
- list of all active orders associated to this strategy
-
buy
Convenience Method: Places a BUY order for the given instrument at market price.- Parameters:
instr
- instrumentqty
- 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
Convenience Method: Places a SELL order for the given instrument at market price.- Parameters:
instr
- instrumentqty
- 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
Convenience Method: Places a BUY order for the given instrument at market price.- Parameters:
instr
- instrumentqty
- 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
Convenience Method: Places a SELL order for the given instrument at market price.- Parameters:
instr
- instrumentqty
- 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
Closes the position held by the selected account. This method will wait until the market order(s) have been filled.- Throws:
MException
-
submitOrders
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
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
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
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
Creates a new 'Market' order.- Parameters:
action
- order action (buy/sell)qty
- quantity of shares/units- Returns:
- order object
-
createMarketOrder
Creates a new 'Market' order.- Parameters:
instr
- instrumentaction
- order action (buy/sell)qty
- quantity of shares/units- Returns:
- order object
-
createLimitOrder
Creates a new 'Limit' order.- Parameters:
action
- order action (buy/sell)tif
- time in forceqty
- quantity of shares/unitslimitPrice
-- 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
- instrumentaction
- order action (buy/sell)tif
- time in forceqty
- quantity of shares/unitslimitPrice
-- Returns:
- order object
-
createStopOrder
Creates a new 'Stop' order.- Parameters:
action
- order action (buy/sell)tif
- time in forceqty
- quantity of shares/unitsstopPrice
-- 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
- instrumentaction
- order action (buy/sell)tif
- time in forceqty
- quantity of shares/unitsstopPrice
-- Returns:
- order object
-
createMarketOrder
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 idaction
- order action (buy/sell)qty
- quantity- Returns:
- order object
-
createMarketOrder
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
- instrumentrefId
- reference idaction
- 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 idaction
- order action (buy/sell)qty
- quantitylimitPrice
- 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
- instrumentrefId
- reference idaction
- order action (buy/sell)qty
- quantitylimitPrice
- 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 idaction
- order action (buy/sell)qty
- quantitystopPrice
- 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
- instrumentrefId
- reference idaction
- order action (buy/sell)qty
- quantitystopPrice
- stop price- Returns:
- order object
-
createMarketOrder
Creates a new 'Market' order.- Parameters:
action
- order action (buy/sell)qty
- quantity of shares/units- Returns:
- order object
-
createMarketOrder
Creates a new 'Market' order.- Parameters:
instr
- instrumentaction
- order action (buy/sell)qty
- quantity of shares/units- Returns:
- order object
-
createLimitOrder
Creates a new 'Limit' order.- Parameters:
action
- order action (buy/sell)tif
- time in forceqty
- quantity of shares/unitslimitPrice
-- 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
- instrumentaction
- order action (buy/sell)tif
- time in forceqty
- quantity of shares/unitslimitPrice
-- Returns:
- order object
-
createStopOrder
Creates a new 'Stop' order.- Parameters:
action
- order action (buy/sell)tif
- time in forceqty
- quantity of shares/unitsstopPrice
-- 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
- instrumentaction
- order action (buy/sell)tif
- time in forceqty
- quantity of shares/unitsstopPrice
-- Returns:
- order object
-
createMarketOrder
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 idaction
- order action (buy/sell)qty
- quantity- Returns:
- order object
-
createMarketOrder
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
- instrumentrefId
- reference idaction
- 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 idaction
- order action (buy/sell)qty
- quantitylimitPrice
- 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
- instrumentrefId
- reference idaction
- order action (buy/sell)qty
- quantitylimitPrice
- 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 idaction
- order action (buy/sell)qty
- quantitystopPrice
- 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
- instrumentrefId
- reference idaction
- order action (buy/sell)qty
- quantitystopPrice
- stop price- Returns:
- order object
-