Execution

View as Markdown

Definition

Represents a read only interface that exposes information regarding an execution (filled order) resulting from an order and is passed as a parameter in the OnExecutionUpdate() method.

Not all executions will have associated Order objects (e.g ExitOnSessionClose executions or AtmStrategyCreate() executions)

Methods and Properties

PropertyDescription
AccountThe Account the execution occurred
BarsInProgressAn int value representing the BarsArray in which the execution occurred
CommissionA double value representing the commission of an execution
ExecutionIdA string value representing the exchange generated execution id
InstrumentAn Instrument value representing the instrument of an order
MarketPositionThe position of the execution. Possible values are: MarketPosition.Long MarketPosition.Short
NameA string representing the name of an order which can be provided by the entry or exit signal name
OrderAn Order value representing an order associated to the execution.
OrderIdA string representing the unique id of the order which was executed
PositionAn int value represents the current quantity of account position at the time of execution
PositionStrategyAn int value represents the current quantity of strategy position at the time of execution
PriceA double value representing the price of an execution
QuantityAn int value representing quantity of an execution
RateA double value representing the exchange rate calculated for non-USD base products (1 if no rate was applied)
SlippageA double value representing the number of ticks calculated between the last trade price and the execution price
TimeA DateTime structure representing the time the execution occurred
ToString()A string representation of an execution

Examples

Finding the executions of a particular Order object

1// Example #1
2private Order entryOrder = null;
3
4protected override void OnBarUpdate()
5{
6 if (entryOrder == null && Close[0] > Open[0])
7 EnterLong("myEntryOrder");
8}
9
10protected override void OnExecutionUpdate(Execution execution, string executionId, double price, int quantity, MarketPosition marketPosition, string orderId, DateTime time)
11{
12 // Assign entryOrder in OnExecutionUpdate() to ensure the assignment occurs when expected.
13 // This is more reliable than assigning Order objects in OnBarUpdate, as the assignment is not guaranteed to be complete if it is referenced immediately after submitting
14 if (execution.Order.Name == "myEntryOrder" && execution.Order.OrderState == OrderState.Filled)
15 entryOrder = execution.order;
16
17 if (entryOrder != null && entryOrder == execution.Order)
18 Print(execution.ToString());
19}

Generic execution logic not specific to a particular Order object

1// Example #2
2protected override void OnExecutionUpdate(Execution execution, string executionId, double price, int quantity, MarketPosition marketPosition, string orderId, DateTime time)
3{
4 // Remember to check the underlying Order object for null before trying to access its properties
5 if (execution.Order != null && execution.Order.OrderState == OrderState.Filled)
6 Print(execution.ToString());
7}