Keyboard Shortcuts
Likes
- Twsapi
- Messages
Search
Re: Can a bracket order have two take profit orders to exit a position at two different profit levels?
I actually tried that (and slight variations) when I saw your original post last night, but it did not work for me.
toggle quoted message
Show quoted text
What happens is that IB automatically sets the quantity for #3 to the same full amount of #1. I guess the basic idea is that the profit and stop legs of a bracket order should protect the entire position. If you just place orders #1, #3, and #4 (no stop loss orders in the brackets) you can actually adjust quantities to Full/Half/Half right after the three orders are placed. Both via API or TWS. But once #1 was filled, IB again adjusted quantity of? #3 to the actually filled quantity. Again it was possible to adjust the quantity of #3 (the now active order) to Half via API or TWS. When placing all five orders, quantity changes failed via API and the fields were greyed out in TWS. JR On Thu, Apr 29, 2021 at 10:22 AM, Levente wrote: Unfortunately I did not have the luxury (time) to try this out myself, so a BIG thank you to Richard. |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Re: Can a bracket order have two take profit orders to exit a position at two different profit levels?
Nick
Ruh roh, the forum may have gotten pwned by IP support.
toggle quoted message
Show quoted text
On 4/29/2021 11:22 AM, Levente wrote:
However, I managed to call IB API support and was suggested the following: |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Re: Can a bracket order have two take profit orders to exit a position at two different profit levels?
Unfortunately I did not have the luxury (time) to try this out myself, so a BIG thank you to Richard.
However, I managed to call IB API support and was suggested the following: Create 5 (!!!) orders 1. Position opening order (assume ID is 1) 2. Stop loss order for the full amount (assume ID is 2) + set parent to 1 3. Take profit order for HALF of the amount?(assume ID is 3) + set parent to 1 4. Take profit order for HALF of the amount at the other price level (assume ID is 4)? + set parent to 3 5. Stop loss order for HALF of the amount (assume ID is 5) + set parent to 3 When position opening order fills, orders with ID 2 and 3 will get activated. If stop loss order 2 fills, the take profit 3 will get cancelled and orders 4 and 5 will never activate. If take profit order 3 fills, the stop loss order 2 will get cancelled, and orders 4 and 5 will get activated and will belong to a NEW OCA group. I will try this out and will post my findings. |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Re: Custom Scanners?
Here is a list of available scancodes. I don't know if there are more.
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Re: Can a bracket order have two take profit orders to exit a position at two different profit levels?
Nick
I don't know the commission impact or if it fits with your strategy but perhaps you could place two brackets each for N/2 shares. This would leave you always protected and you wouldn't have to deal with possible outages.
toggle quoted message
Show quoted text
There's no perfect solution so it's a matter of picking the least evil alternative. On 4/28/2021 5:47 PM, Levente wrote:
I would like to know if there is a mechanism that would allow me to place a position opening order for N contracts, together with two take profit orders, each of size N/2 but at different price levels. |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Re: Can a bracket order have two take profit orders to exit a position at two different profit levels?
开云体育I tried out my suggestion and it seems to work fine. I bought 1000 shares of TSCO at market at the LSE, with a stop-loss STP order at 215 and a take-profit LMT order at 225. ? After the entry market order filled, I modified both the stop-loss and take-profit orders to a size of 500 and set the parentId to 0 in both. ? Then I create a new OCA group with a sell 500 STP order at 215 and a sell 500 LMT at 223. ? The TWS API tab now looks like the attached screenshot. Note that this shows a Position of 3200 – that's because I already had 2200 TSCO in the portfolio. ? Because there are four PLACE_ORDER operations to do after the entry order has filled, there is still a small risk of getting into trouble if you lose your TWS connection for any reason during that sequence: but given that you can just bang these operations in within a very short time, you'd have to be very unlucky. ? Also some refinement would presumably be needed if the entry order had partial fills: you'd have to monitor the executions until the entry order was fully filled. ? ? ? ? ? ? From: [email protected] <[email protected]> On Behalf Of Richard L King
Sent: 29 April 2021 10:18 To: [email protected] Subject: Re: [TWS API] Can a bracket order have two take profit orders to exit a position at two different profit levels? ? No, there's no easy way to do that. ? Obviously you can program this so that you create a bracket order with a stop-loss but no take-profit: as soon as the entry order fills, create the two take-profit orders, and then monitor the stop-loss so that if it fills, you can cancel the take-profits. Easy enough, provided you use a stop order for your stop-loss rather than a stop-limit, which then gives you potential complications with partial fills. And of course ?your program has to keep running to ensure that the take-profits are cancelled if need be. ? A possible alternative that I haven't tried but seems like it should work is to create your initial bracket order with stop-loss and a single take-profit, and then when the entry order fills, halve the size of the OCA group containing the stop-loss and take-profit, and then create another OCA group containing another half-size stop-loss and the other take-profit. Once that's done you can walk away, as it were. The only question in my mind is whether you can actually change the size of an OCA group that was once attached to a parent order, but I can't see why it wouldn't be allowed. I'll try this when I've got a few spare minutes. ? ? From: [email protected] <[email protected]> On Behalf Of Levente ? I would like to know if there is a mechanism that would allow me to place a position opening order for N contracts, together with two take profit orders, each of size N/2 but at different price levels. |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Custom Scanners?
Hey guys, I've been looking through this page and it seems the ability to create scanners in Python is very limited. To my understanding, we cannot pull our already made scanners in TWS into Python? And that the scanners "are being made in python" and use the basic list on that page and this page??which isnt much. I'm trying to make a gap scanner
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Re: Can a bracket order have two take profit orders to exit a position at two different profit levels?
开云体育No, there's no easy way to do that. ? Obviously you can program this so that you create a bracket order with a stop-loss but no take-profit: as soon as the entry order fills, create the two take-profit orders, and then monitor the stop-loss so that if it fills, you can cancel the take-profits. Easy enough, provided you use a stop order for your stop-loss rather than a stop-limit, which then gives you potential complications with partial fills. And of course ?your program has to keep running to ensure that the take-profits are cancelled if need be. ? A possible alternative that I haven't tried but seems like it should work is to create your initial bracket order with stop-loss and a single take-profit, and then when the entry order fills, halve the size of the OCA group containing the stop-loss and take-profit, and then create another OCA group containing another half-size stop-loss and the other take-profit. Once that's done you can walk away, as it were. The only question in my mind is whether you can actually change the size of an OCA group that was once attached to a parent order, but I can't see why it wouldn't be allowed. I'll try this when I've got a few spare minutes. ? ? From: [email protected] <[email protected]> On Behalf Of Levente
Sent: 28 April 2021 22:48 To: [email protected] Subject: [TWS API] Can a bracket order have two take profit orders to exit a position at two different profit levels? ? I would like to know if there is a mechanism that would allow me to place a position opening order for N contracts, together with two take profit orders, each of size N/2 but at different price levels. |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Can a bracket order have two take profit orders to exit a position at two different profit levels?
I would like to know if there is a mechanism that would allow me to place a position opening order for N contracts, together with two take profit orders, each of size N/2 but at different price levels.
If I create a bracket order with these 3 orders, when the position opening order fills the two take profit orders will be activated, but they will belong to the same OCA group, so that when the first one fills, the other will get cancelled automatically, which is not what I want. |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Re: Inconsistent behaviour of WHATIF orders
@Francois: There is no error message. Everything is returned as it should just that both change in initial margin and change in maintenance margin are returned as zero.
I tested it now all week and since the market opened on Monday it works perfectly. No problems at all. It just did not work during the weekend and Monday morning before the market opened. Have you tested your code on a weekend? |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Re: Options contract volume and open interest
To get the current day's volume, a simple snapshot request via reqMktData(reqId, contract, "", true)?is sufficient, and you'll receive the volume as one of the returned data fields.
If you also want the open interest, then you need to use streaming quotes with a GenericTickList of 101 (see ?i.e.?reqMktData(reqId, contract, "101", false). Do not forget?to cancel the streaming quotes request after you receive the data! |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Re: Inconsistent behaviour of WHATIF orders
Despair, I just tried now (07:29 AM UTC) markets closed, and it works fine, either for single leg or combo whatif orders.
See attached screenshot, one is for single legs, one is for combo. I use WHATIF orders to get the margin requirements before I transmit the order. Did you track error messages? There can be errors code 110: 'The price does not conform to the minimum price variation for this contract'. I remember when coding my app that this error forced me to manage 'minimum price increment' through marketRuleId, for normal orders AND whatif orders. |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Model Portfolios functionality in TWS API
Hello guys, my client needs the following functionality for their platform:
Basically I would like to programatically achieve what is described in the following article: Thank you! |