I am a seasoned programmer and I understand the general concepts of asynchronous programming. I have two questions about how order status updating in QC work.

First question. I know that the handler OnOrderEvent will be called whenever any order status has been updated. The documentation stated that it can be called asynchronously. I think it means OnOrderEvent is run on another thread other than the one running the OnData handler. Is that correct?

Second question. Will any order status be updated asynchronously by other thread while the code in OnData is running? Is it possible that the situation shown in below code happen?

public override void OnData(Slice sl)
{
// Assume we have already placed a limit order on symbol,
// it is submitted but not filled by this point.

var isInvested1 = Securities[symbol].Invested; // isInvested1 = false
var openOrderCount1 = Transactions.GetOpenOrders(symbol).Count; // openOrderCount1 = 1


// The order has just been filled and the order status has been updated
// in another thread by this point.


var isInvested2 = Securities[symbol].Invested; // isInvested2 = true
var openOrderCount2 = Transactions.GetOpenOrders(symbol).Count; // openOrderCount2 = 0
}

 

Author