GetRealtimeOrder()

View as Markdown

Definition

Returns a matching real-time order object based on a specified historical order object reference.

This method is only needed if you have historical order references which you wish to transition and manage in real-time (i.e., you had a working order which was submitted historically and re-submitted in real-time as the strategy is enabled). This method only needs to be called once per order object, and should be done in OnOrderUpdate to handle all scenarios. Please see the Advanced Order Handling section on transition orders for more details.

Method Return Value

Returns a real-time order reference associated with the historical order object. If no associated order exists (i.e. OrderState is Filled, Canceled, Rejected, Unknown), a null value returns.

Syntax

GetRealtimeOrder(Order historicalOrder)

Parameters

ParameterDescription
historicalOrderThe historical order object to update to real-time

Examples

1private Order myOrder;
2
3protected override void OnOrderUpdate(Order order, double limitPrice, double stopPrice, int quantity, int filled, double averageFillPrice, OrderState orderState, DateTime time, ErrorCode error, string nativeError)
4{
5 // One time only, as we transition from historical
6 // Convert any old historical order object references to the live order submitted to the real-time account
7 if (myOrder != null && myOrder.IsBacktestOrder && State == State.Realtime)
8 myOrder = GetRealtimeOrder(myOrder);
9
10 // Assign Order objects here
11 // 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
12 if (order.Name == "myOrder Signal Name")
13 myOrder = order;
14
15 // Null Entry order if filled or cancelled. We do not use the Order objects after the order is filled, so we can null it here
16 if (myOrder != null && myOrder == order)
17 {
18 if (order.OrderState == OrderState.Cancelled && order.Filled == 0)
19 myOrder = null;
20 if (order.OrderState == OrderState.Filled)
21 myOrder = null;
22 }
23}