SmartQuant Discussion

Automated Quantitative Strategy Development, SmartQuant Product Discussion and Technical Support Forums
It is currently Mon Jul 23, 2018 4:56 am

All times are UTC + 3 hours




Post new topic Reply to topic  [ 4 posts ] 
Author Message
PostPosted: Wed Jul 04, 2018 12:56 pm 
Offline

Joined: Tue Oct 13, 2009 12:19 pm
Posts: 233
Dear Team,

I have a few strategies in OQ2014 which are all firing orders. And one point in time, I like to check all these orders and if certain things have happened. Each strategies order placing is in a independent thread.

When I foreach through framework.OrderManager.Orders, I some get excpetions, that the Collecition was modified.

What is your best bet on locking framework.OrderManager.Orders or maybe making a copy of framework.OrderManager.Orders (var oF = new List<Orders>(framework.OrderManager.Orders), so that it does have this exception when it gets modified from the other threads.

Thanks
Mike


Top
 Profile  
 
PostPosted: Fri Jul 06, 2018 10:00 am 
Offline

Joined: Wed May 05, 2010 9:49 pm
Posts: 430
Hello Mike,
Do you create threads in your code and why?
Common strategies are using single thread logic and ordermanager is threadsafe in this case.


Top
 Profile  
 
PostPosted: Fri Jul 06, 2018 10:07 am 
Offline

Joined: Tue Oct 13, 2009 12:19 pm
Posts: 233
yes, I create threads in my code.

I have 5 strategies, and on each OnBar Event, the last of the 5 strategies OnBar Event was maybe 2 sec after the first OnBar event. Since the other OnBar Event had all some complex processing logic. So, in PaperMode, I put the calculation into a new function, which is put into a new thread. Now, I will get each event fire within milliseconds... since the logic is processed in its own thread. These threads tough, place orders, so, the main thread, if he checks into: framework.OrderManager.Orders, which might change then.

Hope this helps.
Mike


Top
 Profile  
 
PostPosted: Fri Jul 06, 2018 12:04 pm 
Offline

Joined: Wed May 05, 2010 9:49 pm
Posts: 430
Ok, in case if you don't need orders from other strategies you can hold all orders in local List and use it locally.

In case when you plan to use orders from other strategies you should create thread-safe List/Dictionary and use it from all threads.
This thread-safe Dictionary can be placed in strategy.Global or as static field of strategy.
Each strategy should Add new orders to this Dictionary.

I think that copying orders from OrderManager can decrease performance of strategy so it is not good way.

Other way - iterating orders in OrderManager by OrderId.
In this case all you need is holding the latest value of OrderId in Global/Static.
And you can iterate like this:
for (int id = 0; id < latestOrderId; id++)
{
Order order = OrderManager.Get(id);
}
It will thread-safe


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC + 3 hours


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB® Forum Software © phpBB Group