I noticed that strategy events such as OnBar(), OnTrade() and order events OnNewOrder(), OnOrderStatusChanged() get triggered in different threads.
For some reason, I see events for one symbol not even on the same thread but on two threads.
My strategy uses multiple symbols and I need to keep a "global" object where I store some parameters. These parameters are used for sorting which orders to execute.
Can someone mention if OnTrade() events are called asynchronously and we need our own locking? And if these are synchronized, why are they on separate threads?
If they are asynchronous - then putting a construct similar to the following should be fine?
Code:
static object globalLock = new object()
public override void OnTrade(Trade trade)
{
lock (globalLock)
{
... access my global object synchronously
}
}
Reason I am asking - I am trying to see if this can relate to the IQFeed getting out of memory once every few weeks.
I am trying to see where potentially a deadlock may occur.
Thanks