So I have this code at the top of the function:
/// Check the order state for both entry end exit
if (entryOrder != null && entryOrder == execution.Order)
{
string type = (execution.IsEntryStrategy) ? " ENTRY " : " EXIT ";
/// If part filled, I do nothing, and hope that this method gets called again with order state == filled.
/// If that never happens, not sure what is the "right" thing to do, or how to tell it never happened...
if (execution.Order.OrderState == OrderState.PartFilled)
Log(type + "ORDER ONLY PARTIALLY FILLED; execution.Order.Filled = " + execution.Order.Filled + ", Position.Quantity = " + Position.Quantity);
/// If the order was somehow cancelled, then we need to just close the position if partially opened
else if (execution.Order.OrderState == OrderState.Cancelled)
{
Log(type + "ORDER CANCELLED; dir = " + marketPosition.ToString() + ", execution.Order.Filled = " + execution.Order.Filled);
if (execution.Order.Filled > 0 && entryOrder != null)
{
Log("Order partially filled, now cancelled, so cancelling order");
// I HAD THE CODE LIKE THIS, BUT IT DOES NOT SEEN RIGHT. THE ORDER IS ALREADY
// CANCELLED, SO I WANT TO CLOSE THE PARTIAL POSITION, AND CAN I DO IT FROM
// HERE, OR DO I NEED TO SOMEHOW 'QUEUE' IT TO BE DONE AFTER THIS COMPLETES?
CancelOrder(entryOrder);
}
}
else if (execution.Order.OrderState == OrderState.Filled)
Log(type + "ORDER FILLED (execution.Order.OrderState == OrderState.Filled); execution.Order.Filled = " + execution.Order.Filled + ", Position.Quantity = " + Position.Quantity);
}
else
Log("entryOrder (" + entryOrder + ") null or not == execution.Order; execution.Order.OrderState = " + execution.Order.OrderState);
Also, this is all assuming a market order, but what if I have placed a limit order? Does OnExecutionUpdate() get called when I place a pending (limit) order, and then again when filled? Because I do not seem to see my logging output for that function until it's filled.

Comment