Keyboard Shortcuts
Likes
Search
A couple of questions regarding the C++ Tws api client
Dear community,
i have been working with the tws api client (c++) for more than two weeks now. Even after carefully studying the code provided by Interactive Brokers i couldn't manage to find a suitable closing function for the opended Orders. So my first question is: - How is that done properly ? Shall i create a new order to "neutralize" the old one ? For example "Long apple stock with? quantity 3" shall be neutralized with "Sell apple stock with quantity3" . IS this always matched correctly by TWS ? The second one is, why are there "api orders", what is that and why it is different from active orders . This is confusing and i couldn't find an explanation in the documentation. The third and last (for now) is, can it be guaranteed, that for every symbole there is a history of 1 minute candles that at least is, 2-3 weeks in duration ? Thanks in advance, Arthur |
¿ªÔÆÌåÓýSounds like you might not have found the documentation, which should be able to help with many things:Malcolm
|
Hello Malcolm,
as a matter of fact i work with the documentation and i'm well aware of the cancel_order function. If my order is filled i get an error that it's not possible to cancel an order that's already filled. Due to this, i suppose that canceling orders is when they are not active. And this is the confusing part. So again my question: What is the proper way of closing an order ? Shall i save the quantity, direction (Buy / Sell) and "construct" an order to "neutralize" the existing one or is there a simpler approach to this ? regards, Arthur |
¿ªÔÆÌåÓýHi ArthurMaybe I¡¯m misunderstanding your question, but a filled order does not need to be closed. As far is IB are concerned, a filled order is history. Malcolm
|
Hi,
i place an order and i get the following: ExecDetails. ReqId: -1 - EUR, CASH, USD - 000132b0.64c2e326.01.01, 9, 20000, 20000, 2 OrderStatus. Id: 9, Status: Filled, Filled: 20000, Remaining: 0, AvgFillPrice: 1.10343, PermId: 1476143489, LastFillPrice: 1.10343, ClientId: 0, WhyHeld: , MktCapPrice: 0 This states (i'm not mistaken) that the sent order was executed. If i check the tws server there is a position with -20.000 (as it was a sell order). Then i try to close it by executing ->? m_pClient->cancelOrder(m_orderId, ""); It states: Error. Id: 9, Code: 10147, Msg: OrderId 9 that needs to be cancelled is not found. As i see it, the order is still open. If i send a buy order with +20.000 in quantity i can close it. Cancel implies for me, that if the order isn't executed i can cancel it but not to close an opened order regards, |
¿ªÔÆÌåÓýThis is a problem with nomenclature. Your order is not open, but you have an open position.You were correct in your first email. To close the position just do the opposite in a new order. Malcolm
|
Thank you for clarifying this.
The second question is, why there is such a thing like api orders ? As i see it all the provided callbacks can't see sent orders that are listed in the api tab. if i set the transmit-flag to false in the order object the order is stored in the api tab but i cant "reach" them anymore (and i already looked in the documentation). BTW. Are you a developer at IB ? I found an error in the linux version of the client and emailed it to feedback@... but didn't get any reply. I post the mail here if this is of any use. |
On Fri, Jul 28, 2023 at 03:18 PM, aSchwenk64@... wrote:
You're welcome.
The short answer is: so that you can automate your trading and make or lose money in quantities and time-frames never imagined before :-) But, I suspect the crux of your question may be getting lost in translation. So, apologies in advance if my answer sounds flippant.
You've jammed quite a bit into this so I'll only address what stands out to me which is that you may have neglected to set and use a .
No, but sometimes I wish I were so I could help them avoid some of their questionable design decisions and fix bugs they're "too busy for", lol. Seriously though... if you really think you've found a bug, emailing the feedback address is not be the best course of action. I'd suggest that you first establish, beyond doubt, that it is a bug by bringing the issue up to their support team. More often than not they'll help address the misunderstanding and then triage the bug, internally, if it really exists. If you visit you'll find helpful resources along with an option, further down the page, to report problems and bugs. -Good luck |
On Fri, Jul 28, 2023 at 04:22 PM, aSchwenk64@... wrote:
That's been brought up before here. |
It sounds like you are struggling with some of the concepts, Arthur. Such as how Orders may have Executions that become Trades and change the Account Position. If you have not done so yet, fire up TWS, do some manual trading and look at the various windows (orders, trades, account). Every major function in TWS has a corresponding set of requests and responses within TWS API. TWS API is very flexible and you could envision a complex scenario where orders are placed by several clients and, unless you use IBGW for the connection with IBKR, manually through TWS. In order ro manage that correctly:
The and sections have more detail. The C++ compile issue you are experiencing is going on for a while (since the introduction of the Decimal data type during the transition of V9 to V10) and you can find many posts about this in our forum. ´³¨¹°ù²µ±ð²Ô On Fri, Jul 28, 2023 at 11:22 AM, <aSchwenk64@...> wrote:
I try my approach with a set Master Client ID. This sounds interesting. |
On Fri, Jul 28, 2023 at 04:50 PM, aSchwenk64@... wrote:
I don't blame you one bit! That said... I'd like the tooth-fairy to come and leave gold bullion under my pillow. In other words, IBKR will get around to fixing the problems they value, which may not necessarily coincide perfectly with the ones their individual customers value. Hey, it's a developer's God given right to complain sometimes, no? |
Thank you guys for all the replies and help sofar. @´³¨¹°ù²µ±ð²Ô Struggling is indeed the case, as the complexity of tws itself and the api client is quite big. I do the trading and programming in parallel for the particular reason you mentioned. As coming from the MetaTrader 4 i find some functionality very different in tws.
|
Arthur,
are you perhaps coming from a trading environment where a hedging position accounting system is being used (e.g. MetaTrader)? In those systems you have to "neutralize" a previous order. Your IB account does not work like that. Instead it is a netting position accounting system. For each contract (stock, futures, options, etc) you can have only one position at any moment in time. The result is that any past order which (partially) executed resulted in you have a new position size (i.e your new net position size). Past, executed, orders are therefore considered not relevant and not kept or maintained. Some of the basic differences between a hedging and netting account are described here:? https://www.mql5.com/en/articles/2299 |