SmartQuant Discussion

Automated Quantitative Strategy Development, SmartQuant Product Discussion and Technical Support Forums
It is currently Thu Oct 01, 2020 11:19 am

All times are UTC + 3 hours




Post new topic Reply to topic  [ 8 posts ] 
Author Message
 Post subject: IB Conditional orders
PostPosted: Thu Nov 08, 2012 1:05 am 
Offline

Joined: Mon Oct 04, 2010 5:13 pm
Posts: 362
Hi,

Is there a possibility to submit conditional orders from SQ to IB? I would like to send an OCA order that contains 3 orders. One of them is profit take limit with time condition < 3:55pm EST. Another one is stop loss with the same time condition. And the third one is a market order with time condition of > 3:55pm. The last order is used to surely exit position at the end of day. This way I can ensure that my waiting orders are cancelled at 3:55pm (5min before end of day) and the position is automatically closed after that.

Thanks
Ed


Top
 Profile  
 
PostPosted: Thu Nov 08, 2012 11:16 am 
Offline
Site Admin

Joined: Thu Jul 17, 2003 10:39 am
Posts: 1478
Hi Ed,

There is no problem with limit and stop orders:
Code:
Order limitOrder = BuyLimitOrder(...);
Order stopOrder = BuyStopOrder(...);
         
limitOrder.TimeInForce = TimeInForce.GTD; // good till date
stopOrder.TimeInForce = TimeInForce.GTD;
         
limitOrder.ExpireTime = DateTime.Today.Add(new TimeSpan(15, 55, 00); // today's 03:55 PM
stopOrder.ExpireTime = DateTime.Today.Add(new TimeSpan(15, 55, 00); // today's 03:55 PM
         
limitOrder.OCAGroup = "<some oca identifier>";
stopOrder.OCAGroup = "<some oca identifier>";
         
limitOrder.Send();
stopOrder.Send();


but, there is no possibility to send order with 'after time' condition.
you can set timer to 03:55 (plus few seconds to make sure that the limit and stop orders are proccessed) and send market order to close position if it exists.

_________________
SmartQuant Development Team


Top
 Profile  
 
PostPosted: Thu Nov 08, 2012 11:30 am 
Offline

Joined: Mon Oct 04, 2010 5:13 pm
Posts: 362
Alexey,

Thanks for quick reply. Unfortunately timer does not really help. We have such safety timers but it does not really help since they are at the client side and not server-side. The problem we attempt to solve is lost of communication between TWS and their server. It might sound like a rare event but we've encountered it twice in the last 2 months. The TWS lost connection to their farm just few minutes before 4pm EST. The solution with 3 orders in one OCA group would help right? It seems like IB supports different time forms of conditional orders so we could have the 2 orders (stop and limit) in force till 3:55pm and one market order for after 3:55pm. In such case those orders would be located on their server and thus not a subject of connection loss.

Any other ideas?

I'm thinking may be we can build a simple TWS API based application that would periodically read the OCA orders from TWS and modify them by adding that time conditions. But I"m not sure it is doable or how complicated it is.

But I hope you understand our problem.

Thanks
Ed


Top
 Profile  
 
PostPosted: Thu Nov 08, 2012 4:40 pm 
Offline
Site Admin

Joined: Thu Jul 17, 2003 10:39 am
Posts: 1478
Hi Ed,

I found that IB has custom TimeInForce=GAT(good after time), but it seems we have some problems there:
1. It is non-standard value of TimeInForce and is not supported by FIX protocol, but our order management system is based on FIX
2. I'm not sure that OCA group can be applied to such orders.
3. I'm not sure that such orders are held on IB server side, but not in TWS.

_________________
SmartQuant Development Team


Top
 Profile  
 
PostPosted: Thu Nov 08, 2012 5:17 pm 
Offline

Joined: Mon Oct 04, 2010 5:13 pm
Posts: 362
Alexei,

Thanks again for reply. I see your point.i think for now we don't have a solution to this. IB has a command Market On Close. Do you think such command may be supported by SQ? Does it make any sense or it is very IB-specific?


Ed


Top
 Profile  
 
PostPosted: Thu Nov 08, 2012 5:47 pm 
Offline
Site Admin

Joined: Thu Jul 17, 2003 10:39 am
Posts: 1478
Hi Ed,

You are able to send orders of MarketOnClose type (see OrderType enum), but are you sure that it is you need?
Quote:
An MOC (market-on-close) order will execute as a market order as close to the closing price as possible.

_________________
SmartQuant Development Team


Top
 Profile  
 
PostPosted: Thu Nov 08, 2012 6:03 pm 
Offline

Joined: Mon Oct 04, 2010 5:13 pm
Posts: 362
I am not yet entirely sure but this might be the last resort. We have several protection layers in our strategies but we must close positions at the end of day at all cost. Otherwise we violate the leverage restrictions. I don't know though how IB will handle the MOC. Do you think there is a scenario when it may be dangerous? I have many concerns about this... I know that MOC should be submitted not later than 3:45pm and it cannot be cancelled. But i'm really worried. Any other ideas?


Top
 Profile  
 
PostPosted: Fri Nov 09, 2012 10:56 am 
Offline
Site Admin

Joined: Thu Jul 17, 2003 10:39 am
Posts: 1478
Hi Ed,

Unfortunately, I have no more ideas... Could you ask IB about MOC - can it be used with OCA group.

_________________
SmartQuant Development Team


Top
 Profile  
 
PostPosted: Fri Nov 09, 2012 9:39 pm 
Offline

Joined: Mon Oct 04, 2010 5:13 pm
Posts: 362
Thanks anyway. I'll try to talk to IB and TWSAPI forum.

Ed


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

All times are UTC + 3 hours


Who is online

Users browsing this forum: No registered users and 4 guests


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