Keyboard Shortcuts
Likes
- Twsapi
- Messages
Search
Re: Closing positions
I mean that if I enter a trade for 1 lot and that trade goes so well that it doubles the value of the account. Like if I enter a long position and the value of the eur/usd skyrockets. "Doubling" the account is purely for a hypothetical. It looks like for now, I'll have to manually change the order quantity value as I see fit. |
Re: When to update ibgateway
That is not entirely correct. While TWS/IBGW 10.30 does seem to send an extraneous empty string at the end of openOrder messages, TWS API is designed such that older TWS API version simply ignore the extra data. There is no error if you use IBKR provided TWS API implementations or if you use custom API implementations that properly decode messages. See for Richard's detailed description. My client applications use TWS API version 173 (10.17.02) with stable TWS and IBGW 10.30 and everything works just fine, including openOrder callbacks. ´³¨¹°ù²µ±ð²Ô ? On Fri, Mar 21, 2025 at 10:07 AM, Yair Altman wrote:
|
Re: When to update ibgateway
While in general the stable version is indeed more stable (as in "less buggy", at the expense of fewer new features) compared to the latest version, in some specific cases the stable version may actually be more buggy. For example, the current stable version (10.30) has a known issue for users of old API engines, causing a Fatal 505 error after order placement. This was reportedly fixed in 10.31 onward, and the latest version (10.34) does not exhibit this problem. In other words, users of old API engines CANNOT use the stable version and MUST use the latest version instead, especially since using a pre-10.30 version is no longer possible as of yesterday. Unfortunately, it takes a bit of digging in the IBKR website to find the latest version, since the stable version is offered by default. I have no clue as to why IBKR continues to use the 10.30 branch as the promoted "stable" version rather than 10.31 or newer, although they know about the 505 problem for at least the past 6 months. |
Re: When to update ibgateway
On Thu, Mar 20, 2025 at 02:31 PM, Scott Kister wrote:
I haven't found any logging, errors I am monitoring error callbacks. In my case up till this week I was running 1019.2 gateway yet the "stable" branch is 1030.1 (1030+ has major bugs with real time data delivery for my scenarios so I tried to delay "upgrading" as long as possible). In my experience several month before retiring a version IB would call the error callback with a descriptive message giving plenty of time to upgrade. For example for past several months I was getting this error:
?
The version of the application you are running, 1019.2, needs to be upgraded, as it will be desupported on 20250320. The minimum supported version at that time will be 1030.1.??
?
Just FYI, the error Id is 2172. But I wouldn't count on that :). I just log all the errors and analyze offline. I know you say you didn't see the error. But maybe worth double checking the code for error monitoring (that specific error comes with reqId = -1, i.e. general application wide error). At least I was getting above message up until I upgraded to 1030 (and was getting similar messages before with other builds in the past if I was running older builds and they were about to be retired by IB)
?
AJ |
Re: When to update ibgateway
Not much to add to Richard's detailed reply except mentioning that I subscribe to the idea that the "stable" channel is likely the most reliable and light on maintenance, so I only use TWS and GW versions therefrom. If IB announced that a "stable" version is no longer supported, I guess it must have been really old enough to warrant an upgrade. I will typically check and upgrade myself about once in a quarter on ad hoc basis, so I'm now using TWS 10.30.1t on my home-office development computer and GW 10.30.1u on my unattended trading virtual private server which is a cheap 24/7 machine where I rely on auto-restart and weekly manual logons through RDP, without IBC.
--
Best, DS |
Re: When to update ibgateway
¿ªÔÆÌåÓý[The following is my understanding of how IBKR deals with Gateway and TWS version updates. This is based on my 22 years of using TWS (and somewhat less for Gateway, which is younger). However it may well not be completely correct, since IBKR has never explained all this in detail to my knowledge.] ? The are two versions of Gateway, ¡®Stable¡¯ and ¡®Latest¡¯ (possibly ¡®beta¡¯ as well but I¡¯m not sure about that). For some reason, the IBKR website doesn¡¯t seem to contain a published link to the stable version, only the Latest (in the Login menu at top right). However, the stable version can be found at https://www.interactivebrokers.com/en/trading/ibgateway-stable.php. ? The ¡®Stable¡¯ version does not have any new features added, but it may still have bugs. These bugs are fixed by IBKR, and a new version is published with just the last part of the version number (the letter) updated. So the version you were using (10.30.1g) is rather old and has been superseded by several later 10.30.1? versions: the current one is 10.30.1u. I¡¯d be willing to bet that version would work well for you. ? The ¡®Latest¡¯ version is under active development, and is more likely to have faults, though I think that by the time IBKR release a new ¡®Latest¡¯, they¡¯re pretty happy with it. If a significant new feature is introduced, this will be released as a new ¡®Latest¡¯ version, so the ¡®Latest¡¯ version number might go from 10.34.1c to 10.35.1a (fictional example). ? Periodically IBKR decide that what was once the ¡®Latest¡¯ version has proven to be nice and reliable, and they promote it to be the ¡®Stable¡¯ version (it¡¯s not normally the actual latest ¡¯Latest¡¯ that gets promoted ¨C so the next ¡®Stable¡¯ version from 10.30.1u could be say 10.33.nn, rather than 10.34.nn or later)). ? Rather less frequently, IBKR decide that an old version is no longer safe to use, and they retire it completely: this usually involves plenty of notice to users via various mechanisms, but invariably there are some users who fail to notice the warnings (or ignore them) until that version actually stops working. It¡¯s generally advisable to take careful note of what IBKR says. ? Once a ¡®Latest¡¯ version has been superseded by a new ¡®Latest¡¯, development of the first one ceases ¨C no bug fixes, no new features (unless it has been promoted to ¡®Stable¡¯). So if you¡¯re using a version like 10.31.1j, which was once a ¡®Latest¡¯ but is now neither a ¡®Stable¡¯ nor a ¡®Latest¡¯, it may contain bugs that have been fixed in a later version. Therefore it¡¯s always safer to use either the current ¡®Stable¡¯ or the current ¡®Latest¡¯ (with the latter being somewhat more vulnerable than the former). ? As you¡¯ve noticed, IBKR does nothing to actively notify users of routine new versions, so it¡¯s entirely up to you to monitor the status of the various downloads. I¡¯m not very disciplined about this myself¡ ? Richard ? ? ? From: [email protected] <[email protected]> On Behalf Of Scott Kister
Sent: 20 March 2025 13:31 To: [email protected] Subject: [TWS API] When to update ibgateway ? What policy do you use for when to update the ibgateway? It seems like every 4-8 months, my ibgateway fails to login after a daily restart and updating to the newest version fixes it. ? I haven't found any logging, errors, or other notifications that the old version is no longer being supported. Today, my version 10.30.1g stopped working, and was still failing after I restarted it again, so I updated to 10.34.1c. It is possible the old version does still work, but for some reason upgrading consistently fixes it. It seems odd that they would make the change mid-week and there were no errors in the ibc logs, it just never logged "IBC: Login has completed". I wanted to get it running, so didn't debug it too long. ? Is there a way to get notifications when IB increases a version, or should I just set a monthly or quarterly upgrade reminder? |
Re: Closing positions
What do you mean by the sentence "enter a position for 1 lot in EURUSD that trade would double the size of the account"? Your account size is measured by the NLV, net liquidation value. That value does not suddenly double if you take on a larger position size.
The way how you have worded your question make me guess that you are familiar with operating a so-called hedging account. That is not how IBKR operates. Your IBKR account is a so-called netting account. This difference makes that you have to look differently at account value, position size, and opening, modifying and closing positions. |
Re: When to update ibgateway
I notice that you mention two pieces of software in your message. Both IB Gateway, and IBC (IB Controller). Which of these is causing the problem for you?
I am running IB Gateway 10.31.1j together with IBC version 3.20.0 and have not experienced any issue with this combination. I log on on Sunday evening and then let it run until the next Saturday morning. |
Re: Accounting for 2024, always 10% off
FifoPnlRealized reports the value of trades realized as partially or fully closed positions during the reporting period, taking into account respective expenses in FIFO order. I believe it is net of any commissions paid, if memory serves me well. It also does not differentiate between long and short term P&L, so it may not necessarily be useful for computing taxable income if such difference has tax implications. It is generally more of a raw finalized performance indicator rather than a tax reporting one, although it can be used for taxes if the tax code allows.
?
You will find IBKR reporting references at
(1) https://www.ibkrguides.com/clientportal/performanceandstatements/reports.htm
(2) https://www.ibkrguides.com/reportingreference/reportguide/reportreference.htm
?
However they leave quite a bit to be desired in detail, eloquence and structure.
?
The issue of tax is complex and depends on your tax residence, the domicile of the business you are trading, the type of proceeds, and IB tax status in your country of residence.
?
Generally speaking, your IB account is very unlikely to be charged any capital gains tax whatsoever unless IB is a tax agent in your country of residence and your country charges such a tax, i.e. if it is obligated to pay taxes for you to the tax authorities in the country of your tax residence where you physically conduct any trading activity including remote trading on overseas markets. And even then I would expect the tax to be reported separately from any investment proceeds proper, similarly to how dividends and dividend taxes withheld are treated.
?
? |
When to update ibgateway
What policy do you use for when to update the ibgateway? It seems like every 4-8 months, my ibgateway fails to login after a daily restart and updating to the newest version fixes it.
?
I haven't found any logging, errors, or other notifications that the old version is no longer being supported. Today, my version 10.30.1g stopped working, and was still failing after I restarted it again, so I updated to 10.34.1c. It is possible the old version does still work, but for some reason upgrading consistently fixes it. It seems odd that they would make the change mid-week and there were no errors in the ibc logs, it just never logged "IBC: Login has completed". I wanted to get it running, so didn't debug it too long.
?
Is there a way to get notifications when IB increases a version, or should I just set a monthly or quarterly upgrade reminder? |
Closing positions
What's the best way to close previous positions when I have new order position sizes calculated by account size? For example, if I enter a position for 1 lot in EURUSD, and (purely hypothetically) that trade doubles the size of the account. My next order position size would be for 2 lots. That makes it difficult to close the first position if all I'm going to do is do an opposite position because the order quantity would change. The help I've received from the api support is to request positions and then do an opposite order based on what comes back. I've never seen that put into code. |
Re: Accounting for 2024, always 10% off
Thank you ´³¨¹°ù²µ±ð²Ô. You always come with great information.
?
My flex-query just takes information from the "Trades" section. There it doesn't differentiate between CapitalGainsPnl and FifoPnlRealized. I just crossed "Realized PnL" and both columns pop up in the CSV.
?
I understand that ?CapitalGainsPnl somehow is influenced by taxes although I'm unsure how this effects me living in Sweden having my account at IB Ireland and being granted an exemption from Irish withholding tax (it says so in my account management).
?
Would be perfect if there was a field for the raw realized PnL before any tax considerations. |
Re: "438 : The application is now locked" and "326 : Unable to connect as the client id is already in use..." discontinued ?
I have just received the following update from IB regarding this issue:
"Please be aware that "Client ID is already in use" error will be brought back in the upcoming releases." I have asked that other error messages that were dropped in recent versions of the API be brought back: 438 | The application is now locked 10141 | Paper trading disclaimer must first be accepted for API connection. 1300 | Socket port has been reset and this connection is being dropped. Please reconnect on the new port -7498 I have also asked that a new error is added for the scenario of 32 client applications already connected to TWS and no more connections being allowed. In recent versions of the API, all these errors return the default 502 error which is not informative. -- |
Is a race condition that causes inconsistent states of position and open orders possible?
If in the messages TWS streams back to the client, it sends the order/execution message first before it sends the position update message, it is possible for the client to be in an inconsistent state as it no longer sees the open order, but the position is not updated. This is dangerous because the program may sneakily go above the risk limits without the program noticing. I have done a search of this forum, and it appears no one has had such an issue in practice. However, in the TWS API official documentation, I also do not see any mention of it talking about synchronization guarantees. Is it something I really need to worry about? I really appreciate any input. |
Re: Accounting for 2024, always 10% off
I am not a tax expert either and use FlexQueries only infrequently (so I am not very well qualified for an answer, but ...) Depending on what instrument you trade, at least here in the US, trade gains can get taxed as "Capital Gains", "Ordinary Income" or a combination. Tax rates differ for the various scenarios where capital gains rates are usually lower than ordinary income rates. Also, "long term capital gains" rates (when held for more than a year) are lower than "short term capital gains". FifoPnlRealized comes into play when you have a position that you hold for a long time and you buy and sell at very different prices over time. Say you sell a portion of this position now, P&L an be calculated as:
P&L can obviously be very different in both cases even to a point where one would show a profit while the other shows a loss. On the other side, if you always close out the entire position, both methods of determining P&L would calculate identical values. When you create your FlexQuery, which of the sections do the CapitalGainsPnl and FifoPnlRealized fields come from? ´³¨¹°ù²µ±ð²Ô ? ?
On Tue, Mar 18, 2025 at 12:04 PM, Despair wrote:
|
Re: Accounting for 2024, always 10% off
1.) I think they are subtracted.
2.) They are luckily not 10%.
?
Has anybody a link to where all the fields of the flex query are explained in detail? I searched but couldn't find this info.
?
There are for example two fields CapitalGainsPnl and FifoPnlRealized. What is the exact difference? And there are many questions like this. |
Re: Accounting for 2024, always 10% off
Hmm I'm not US citizen. I'm in Europe and with IB Ireland. I sent in this form to avoid double taxation but that maybe has nothing to do with it (I'm awful with all this tax things)?
?
However the value I get from summing up the trades from the flex-query is 10% less than what I see on my account. Would it be this way round? |