Interface OrderContext
public interface OrderContext
This interface provides the capability to create and manage orders.
-
Method Summary
Modifier and TypeMethodDescriptionvoidbuy(float qty) Convenience Method: Places a BUY order for the current instrument at market price.voidbuy(int qty) Convenience Method: Places a BUY order for the current instrument at market price.voidbuy(Instrument instr, float qty) Convenience Method: Places a BUY order for the given instrument at market price.voidbuy(Instrument instr, int qty) Convenience Method: Places a BUY order for the given instrument at market price.doublecalcPnl(float entryPrice, float qty) Convenience Method.doublecalcPnl(float entryPrice, float exitPrice, float qty) Convenience Method.doublecalcPnl(float entryPrice, float exitPrice, int qty) Convenience Method.doublecalcPnl(float entryPrice, int qty) Convenience Method.doublecalcPnl(Instrument instr, float entryPrice, float qty) Convenience Method.doublecalcPnl(Instrument instr, float entryPrice, float exitPrice, float qty) Convenience Method.doublecalcPnl(Instrument instr, float entryPrice, float exitPrice, int qty) Convenience Method.doublecalcPnl(Instrument instr, float entryPrice, int qty) Convenience Method.voidCancels all of the open orders for this strategy.voidcancelOrders(Order... orders) Use this method to cancel one or more existing orders.voidcancelOrders(List<Order> orders) Use this method to cancel one or more existing orders.voidCloses the position held by the selected account.voidCloses the position held by this strategy.doubleconvertToBaseCurrency(double pnl) Converts the given amount to the amount in the base currency using the instrument associated with this context.doubleconvertToBaseCurrency(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.floatGets the average entry price for the current position on the selected account (for the chart instrument).floatGets the average entry price for the current position on the selected account for the given instrument.intGets the current open position for the account (for the default position).intgetAccountPosition(Instrument instr) Gets the current open position for the account for the given instrument.floatGets the current open position for the account (for the default position).floatGets the current open position for the account for the given instrument.floatGets the average entry price for the current position on the selected account.Gets all of the active orders that are associated with this strategy.floatGets the average entry price for the current position using the default (chart) instrument.floatgetAvgEntryPrice(Instrument instr) Gets the average entry price for the current position and instrument.Gets the symbol for the base currency.doubleGets the current cash balance for the account.longGets 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.intGets the current open position for this strategy for the default (chart) instrument.intgetPosition(Instrument instr) Gets the current open position for this strategy for the given instrument.floatGets the current open position for this strategy for the default (chart) instrument.floatgetPositionAsFloat(Instrument instr) Gets the current open position for this strategy for the given instrument.doubleGets the realized PnL (profit/loss) for the current 'leg' of the strategy.doubleGets the total realized pnl (profit/loss) since this strategy was opened (or last reset).doubleGets the PnL for the open position.voidsell(float qty) Convenience Method: Places a SELL order for the current instrument at market price.voidsell(int qty) Convenience Method: Places a SELL order for the current instrument at market price.voidsell(Instrument instr, float qty) Convenience Method: Places a SELL order for the given instrument at market price.voidsell(Instrument instr, int qty) Convenience Method: Places a SELL order for the given instrument at market price.voidsubmitOrders(Order... orders) Use this method to submit one or more orders to the broker.voidsubmitOrders(List<Order> orders) Use this method to submit one or more orders to the broker.booleanDetermines 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
-
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
-
getBaseCurrency
-
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
-
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
-
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
-