No. And it is more complicated than you’d expect. Plus : This is one of my outstanding 2000+ tickets (how come I always need to mention this ?). I think back in 2019 I already reported this from manual trading. This is important, because it more easily shows what is going on.
Side note : it will be nothing new to justisan, but it could help him to further decide (as in : plainly give up on this one).
1.
If you have a manual position and want to revert that, the exact same situation occurs.
Side note : I have reported about this in this forum as well (several times) and I recall that in IG you can’t even perform the “reversal” action. Within the IB version of PRT the order types are subject to change and currently I don’t even know whether this “revert” is still possible.
No worries : you can perform a Sell 2 on an open 1x Long and it is exactly the same (but feels as if you need 2 extra positions for margin).
2.
It gets complicated as PRT is in between that as well, actively (!). For example, PRT may explicitly ask for the margin headroom prior to putting an order to the broker. Or it may not (a sloppy programmer forgot it in the situation of concern) and then the broker brings the message to PRT, PRT passing it on to you. Note that this gets exciting when you earn a lot in your current session and with say 10K portfolio but 100K profit (this exists) you can’t do a thing, never mind you’d need 5% of the total only for your next order. This is (GraHal) indeed IBKR’s risk calculation, which *also* adds some just in case (your AI forgot to dig that out). Example : you have 1 spare in margin, want to buy 1, but it is rejected because you need 2 (you can sort out the remainder with AI because it is good at this, but first ask for it (guide it)). Already this phenomenon makes that you lose track (no logic). Anyway PRT does *not* contain this logic – it is the broker who rules here (and never make the mistake to compare this with IG because IG is a joke).
3.
#2 has to be extended with the PRT specialties. So, exactly in the realm of justisan’s issues, I once was allowed (by PRT !) to decide how PRT should act when I’d put a limit buy order under an already open position. But this quite impossible to explain. An attempt :
You have a position of 10 lots and it makes a profit of 100. I now put a limit under that position with 1 lot. Now the profit shows 101. Huh ? yes. huh. It is now PRT who decides that the 100 will be 101 once the limit order is filled. It is even logic, once you see that the price drops towards the Limit and ends up at 90 once it is there, and your limit of 1 lot it filled; the profit will now be ~ 91 (it will be 90 but if the price rises to the original 100 profit level, it will be 101).
Sort of. This is to be mimicked in Live before this can be grasped.
Anyway I objected to this once introduced way of working and was asked whether I could find a better way of expressing (by the PRT platform) how this should work. The context of this indeed was : what about the margin headroom ? hence, the situation is the same : you have a position eating your margin, put a new limit and once that limit will be filled you’re in trouble.
Note : turn this into a Buy Stop order (yes, above the price) while you *know* that you will have sufficient $ by the time the price went all the way up to that level, and the situation becomes 100% justisan’s but from a very different angle. Thus, by that time you earned 3 lots, want to buy one extra, but the Buy Stop is rejected because at this moment you have room for 1 only. This just s*cks.
*Yes, in PRT-IB such Buy Stop orders can be placed via the chart – not via program code (there they are marketable right away (“wrong side of the price”)).
These specialties mostly are not possible in PRT-IG, but again mostly (with a different subset) are possible in the PRT coding environment because that is general (not dedicated to either IG or IBKR). It is trialing what works where, and justisan clearly did that (all ?).
justisan, what I don’t see you write about is the checking via TWS how the orders look like; you won’t find nothing new, but where OCO emerges and where it breaks could be interesting to track. And mind you, it is *here* where PRT is involved severely, because it is there where the order numbers are created (thus also : what forms an OCO and what will not). Also : this is totally different for IG. You just need to look at all the connection lines in IG, to see that a virtual none of these exist in PRT-IB. This tells me : the OCO’s are not even there in the first place and PRT manages them (by means of so called “soft orders” (some of those are even denoted like that explicitly in the order types form)).
Regarding this latter I could also say : such connection lines *can* be there when applied manually (right click on the order label and choose from the presented options (those who were in the way of GraHal two weeks or so back) and from there you’d get the connection lines (a real OCO). But I never ever I saw such connection lines from whatever the nest of order mess I create in PRT-IB code. And the very same code applied in IG *does* create those lines.
Last thing : these “OCO lines” are created by the broker, not by PRT (the OCO lays with the broker (or even exchange) not with PRT). Thus, don’t see the lines – and you already *know* there is no OCO. That simple. Conclusion : PRT-IB can not do this from your code (PRT-IG can).
That this fact leads to numerous errors (and a 100+ open tickets which never get solved) is clear, because trying to control a software OCO (which is what PRT-IB does) is quite impossible. This leads to communication errors in the API (between PRT and IBKR) and the 100s of faults I experienced (this is not exaggerated); you just can’t get it synchronized decently, knowing that the broker (or mostly exchange for what we do with futures) is 100% leading.
This was in a nutshell why you can’t get this done.
But wait … of course you can get it done, because you know what is going on. Just turn your reversal into a Sell and in the next bar followed by a Sell again. Not such a big deal if your timeframe is 1 second (but if it is not, you’re in trouble). And then still … then will appear the synchronization issues again because if you sell the one second and sell again the next, 1 out of 10 or so the first sell did not happen yet, and now you have laying two sells at the broker and the margin issue is there again.
Plus PRT throws you out, because it knows it is still waiting for the confirmation of the first sell and it can’t bear that.
There is no real way out of this and this is already outside the margin issue. No such thing with IG because that is “immediate” (there is no broker). IG is like backtesting (but has a million other issues).