Keyboard Shortcuts
Likes
- Twsapi
- Messages
Search
Re: IB Gateway auto-restart fails - "COMPETE: session kicked out" and "Disconnect all farms due to competing session [control=false,context=]."
Ok, here's a (hopefully) good development: I just casually let a container displaying on the X server run on my local machine, went away, the machine went in standby and:
?
Excatly the same log messages and apparently the same window popping up!
So it all seems due to a lost internet connection and having to confirm a re-login request..
I wonder what's the equivalent of the standby causing the disconnection on my local machine is on the remote server, but that can easily be found out,a nd I have a problem to solve now.
If this is now sorted, I hope it'll be useful for someone ending up in the same trap. Thank you 闯ü谤驳别苍 for the quick help.
?
Renato |
Re: duplicated order id
The precise TWS API requirement is that order IDs for new orders shall be "greater than all previous order IDs returned to the client application in openOrder or orderStatus callbacks". Your nextOrderId method does seem to generate a sequence of increasing numbers, but here a few thoughts:
That should suffice to avoid the duplicate orderId issue in multi-threaded order placement scenarios. But to be absolutely sure, you also want to monitor the orderIds you receive from openOrder() and orderStatus() callbacks and make sure to nudge the counter in nextOrderId() in case you receive orderIds that are higher than the counter in nextOrderId(). That can happen in cases where your client application gets exposed to orders that where placed by other clients or from within TWS or other tools, 闯ü谤驳别苍 ? ?
On Sat, Mar 15, 2025 at 12:32 PM, Marco wrote:
|
duplicated order id
Hi All, I have an issue with orderId assignment. I have a python code where the client is a class and assign orderId to different strategies running in parallel (each strategy implemented in a separate class). When a strategy has to generate an order, it request?the order id calling client member function nextOrderId(). In order to avoid assigning the same id do different strategies I implemented this function as below:
?# return next available order id ? ? def nextOrderId(self,stratId):
? ? ? ? #locking the assignment and increase of order id to avoid same order id assigned to different strategies ? ? ? ? with self.lockOrderIdIncrease: ? ? ? ? ? ? self.strategyList[stratId].validOrderId = self.order_id ? ? ? ? ? ? self.order_id += 1 ? ? ? ? return self.strategyList[stratId].validOrderId
where self.lockOrderIdIncrease is a threading Lock object, initialized in the constructor class:
self.lockOrderIdIncrease = Lock()
and self.strategyList is a list that for each strategy stores the current used order id, while self.order_id contains the last available order id
iI have a couple of strategies that can be activated in the same instant and in paper trading in past days I observed 2 times the error “Error 103: Duplicate order id”. Can someone help me? I do not understand why this is happening as the fragment accessing to the current order Id seems to me allowing access to one thread per time, blocking the others
thank you in advance Marco
|
Re: IB Gateway auto-restart fails - "COMPETE: session kicked out" and "Disconnect all farms due to competing session [control=false,context=]."
Hard to say what is going on, Renato. While IBGW does not implement fancy forms and complex media content (compared to TWS), it still needs a complete and pretty sophisticated graphics subsystem for JavaFX 2.0 to work properly. And mot likely a window manager as well. I have been using Xtigervnc with Xfce4 on Ubuntu for years and it works great. But I don't use Docker containers. And you might want to get this working manually before you start IBGW with IBC since IBC will not be able to help you if the root cause relates to the graphics subsystem or X11 window management. 闯ü谤驳别苍 ? ? On Sat, Mar 15, 2025 at 12:07 PM, Renato Votto wrote:
|
Re: IB Gateway auto-restart fails - "COMPETE: session kicked out" and "Disconnect all farms due to competing session [control=false,context=]."
Thank you 闯ü谤驳别苍,
This is weird though: that only time I tried to login from the phone in paper account to test whether the Linux instance was still logged in after the restart, I always refused to continue with the login from the phone (as the warning itself was the only proof I was looking for). Then I struggle to undersant how 20+ hours later, at the time of the second daily restart, the phone app owns a session. Also, on the second day, when I try again to login from the phone to see whether the Linux instance restarted and logged in correctly, I have to enter both credentials from scratch.
?
This gave me a hint though, I'll test the container locally with UI on the X server and attempt a login from the phone or my local IB installation before running an auto-restart and see if any unepected windows pop up or different behaviour. Also, in my initial post I forgot to mention that, speaking of display windows, by printing out the the current windows from the Xvfb virtual display during the "limbo" state of the endless SPLASH attempts, I noticed that some re-login related window was on (but I have never been able to replicate this with physical UI): Window ID: 0x400e3d _NET_WM_NAME(UTF8_STRING) = "Re-login is required" WM_NAME(STRING) = "Re-login is required" Window ID: 0x400e48 _NET_WM_NAME(UTF8_STRING) = "FocusProxy" WM_NAME(STRING) = "FocusProxy" Window ID: 0x400e45 _NET_WM_NAME(UTF8_STRING) = "Content window" WM_NAME(STRING) = "Content window" Window ID: 0x400e44 _NET_WM_NAME(UTF8_STRING) = "sun-awt-X11-XIconWindow" WM_NAME(STRING) = "sun-awt-X11-XIconWindow" Window ID: 0x40002a _NET_WM_NAME(UTF8_STRING) = "Attempt 160: Authenticating..." WM_NAME(STRING) = "Attempt 160: Authenticating..." Window ID: 0x400035 _NET_WM_NAME(UTF8_STRING) = "FocusProxy" WM_NAME(STRING) = "FocusProxy" Window ID: 0x400032 _NET_WM_NAME(UTF8_STRING) = "Content window" WM_NAME(STRING) = "Content window" Window ID: 0x400009 _NET_WM_NAME(UTF8_STRING) = "IBKR Gateway" WM_NAME(STRING) = "IBKR Gateway" Window ID: 0x400023 _NET_WM_NAME(UTF8_STRING) = "FocusProxy" WM_NAME(STRING) = "FocusProxy" Window ID: 0x400020 _NET_WM_NAME(UTF8_STRING) = "Content window" WM_NAME(STRING) = "Content window" Window ID: 0x40003a _NET_WM_NAME(UTF8_STRING) = "Loading..." WM_NAME(STRING) = "Loading..." Window ID: 0x400045 _NET_WM_NAME(UTF8_STRING) = "FocusProxy" WM_NAME(STRING) = "FocusProxy" Window ID: 0x400042 _NET_WM_NAME(UTF8_STRING) = "Content window" WM_NAME(STRING) = "Content window" Window ID: 0x400041 _NET_WM_NAME(UTF8_STRING) = "sun-awt-X11-XIconWindow" WM_NAME(STRING) = "sun-awt-X11-XIconWindow" Window ID: 0x400031 _NET_WM_NAME(UTF8_STRING) = "sun-awt-X11-XIconWindow" WM_NAME(STRING) = "sun-awt-X11-XIconWindow" Window ID: 0x40001f _NET_WM_NAME(UTF8_STRING) = "sun-awt-X11-XIconWindow" WM_NAME(STRING) = "sun-awt-X11-XIconWindow" Window ID: 0x40000a _NET_WM_NAME(UTF8_STRING) = "install4j-ibgateway-GWClient" WM_NAME(STRING) = "install4j-ibgateway-GWClient" Window ID: 0x600002 ? Thank you for your help, much appreciated. If I cannot come up with a solution shortly, I'll give up and just go with IBC. Though I liked the portable container implementation, the minimal settings and the only need to delegate to a cron task for the weekly re-authentication. By the way, here's the container source, if anyone wants to play with it (originally forked by Ryan Clouser similar concept): ? Renato |
Re: IB Gateway auto-restart fails - "COMPETE: session kicked out" and "Disconnect all farms due to competing session [control=false,context=]."
You can have only one session at a time for each user/password combination. When there are simultaneous logins from IBGW on Linux and your phone, only one of the two can own the session and the other is disconnected from IBKR. It sounds like from your description, IBGW on Linux does not own the session when it is time for restart. Not owning the session, IBGW will not be able to restart. To assure proper IBGW operation on Linux, do not log into the same account from your phone (or Client Portal or Web Trader). For live accounts, you can create additional user accounts so that IBGW and your phone use two different sessions. But even in that setup you need to make sure that the phone does not take the market data subscriptions from IBGW. Alternatively you can purchase separate market data subscriptions for the secondary user account on the phone. 闯ü谤驳别苍 ?
On Sat, Mar 15, 2025 at 09:52 AM, Renato Votto wrote:
|
IB Gateway auto-restart fails - "COMPETE: session kicked out" and "Disconnect all farms due to competing session [control=false,context=]."
Hi,
My first post here and I hope I'm posting in the right way and place.
Context: - I have a Docker container running an instance of the Interactive Brokers Gateway, paper trading account, on a remote Linux server - The IB Gateway is set to auto-restart every day at 8:30 AM GMT - I use Xvfb, a virtual display, so I have no physical graphic interface whilst running
- I am currently solely testing the daily auto-restart, thus the app has no clients connected and no requests whatsoever submitted
My problem is that so far, it never made it to a second restart: I may start the container today, that will successfully (reading the logs and experiencing the "another session is running..." warnings both on my phone or local instance of IB Gateway/TWS) launch and run IB Gateway, it will make it to the following day restart and succede (judging again from logs and trying to login from somewhere else); however, the second day auto-restart always fails. Worth to clarify that the failing restart is not on a Saturday/Sunday, which I'm aware is expected to require authentication again. What I can see in the launcher.log of a succesfull restart as opposed to the one of the failing restart is that the latter, at some point after the message ?
"SPLASH Authenticating"
?
reads
?
"COMPETE: session kicked out"
?
and few milliseconds after
?
"Disconnect all farms due to competing session [control=false,context=]."
?
and then after a few (just number after SPLASH ending differently)
"SPLASH 20001 step 2 AuthDispatcher.processDataItr" "Received NS_TEST_REQUEST"
....
?
i get a
?
"Socket for connection cdc1.ibllc.com:4001 (SSL) was closed by peer."
"Listener thread terminating [sessionID=2] [seen=399,totalShifted=399,moreAvailable=0]"
"Disconnecting cdc1.ibllc.com:4001 (SSL) [disconnectDetails=DisconnectDetails[sessionID=2,endPoint=cdc1.ibllc.com:4001 (SSL),reason=DISCONNECT_ON_BROKEN_SOCKET,cause=null,systemMessage=recv: EOF,keepSocketOpen=false]]..." "Socket closed." then
?
"SPLASH Attempt 1: server error, will retry in seconds"
?
And after this the whole log, for hours will repeat everything again and again with just increasing the attempt number in the following message
?
"SPLASH Attempt 2: connecting to server"
In a successful restart log, right after the first message listed above, things would have taken a different fold, the authentication would succede, and some routing tasks before rotating to the operational log would be printed. To be frank, I do have a X server option when for when I test locally on my machine where I built the Doicker image, but I never tested?for days the behaviour to see what might pop up. I did test few restarts in a row by just changing the restart time on the go, and they all succeded, but I understand many things change between the two setups, so this might be of little help. Anyone care to help with what's going on here? I surely can provide the logs if needed. Thank you,
Renato? ? |
Re: Simplest Way to know if Individual Candle Data is Pre-market, Market or After-hours.
Thanks for the good reply.
?
I had ended up writing a function to calculate the start of pre-market, start of market and start of after-hours and would then compare each candle's time to see which period it fits within. The function is working well and ensures to only re-calculate the start of pre-market, start of market and start of after-hours values only when required to minimise computations.
?
The details you provided are really useful though and I am now looking to update my code to obtain some of these details from IBKR API calls directly where possible. I am using REST endpoints directly however and need to obtain data from the returned JSONs which I map into my own data models as I am working with Dart language myself.
?
For others who may be reading this, from a REST endpoint perspective the details above can be obtained from the endpoints trsrv/secdef/schedule (for instrument trading times) and iserver/marketdata/history with param startTime for history data for a? given period of time (It is important to note here that, for some odd reason, the current REST api uses the startTime param as the end time and it then subtracts the period param value from startTime to use as the actual start time of the historical data being requested; crazy stuff!). |
Re: Why SPX options strike 5635 missing from options chain for 2025-03-14?
It’s normal. Sometimes the exchanges don’t publish all “expected” strikes. Also happens for stocks. With IBKR’s? reqSecDefOptParams you can retrieve valid strikes.? Daniel On Sat, 15 Mar 2025 at 08:49, Lewis_Tang via <lewis91960127=gmail.com@groups.io> wrote:
|
Why SPX options strike 5635 missing from options chain for 2025-03-14?
My algo tried to define options contract for strike price 5635 with expiry on 2025-04-14 (0DTE), but got error message saying "Unknown contract". I then found that this particular strike (5635) was missing from the options chain (spot was trading at around 5610 at that moment). I suppose SPX's strikes are listed every 5 points (unless the strike is very far away from spot or it is long dated like a year ahead). Is this common ? How do you guys' code cater for this missing strike ? |
Re: Simplest Way to know if Individual Candle Data is Pre-market, Market or After-hours.
Welcome to the group. Generally, the exact schedules for regular and extended trading hours are defined by the individual exchanges, so that you could implement a few functions for the exchanges you are interested in. On the other hand, a single strategy that works for any instrument is not that hard either. The object for a given instrument (that you can and should lookup through ) gives you the native time zone for the instrument as well as the regular ("liquid") and extended trading hours for the next few days. Below a couple of examples ContractDetails objects from Thursday afternoon. Using this information has the advantage that exchange closures (regular during the weekend, for holidays, or emergency situations) are announced that way, too. It is a good practice that client applications make calls when they start or at least once a day for all instruments they deal with.
You can get the same information for days in the past as well. The data is requested via method with whatToShow "SCHEDULE" and delivered via method.? The session information looks like this and you can request regular and extended hour schedules separately.
refDate ? ??????????? "20240104" Each programming language has built-in or library functions to parse and compare dates and times such as Java's or to convert the resulting time into an absolute timezone free representation (such as Java's ) They bring simple tests such as IsBefore, isAfter, isBetween, ... that you an use to determine from the above data, where a given point in time for a given intrument is within the regular trading hours or bot. Hope this helps, 闯ü谤驳别苍 ? On Wed, Mar 12, 2025 at 07:03 AM, <dubiousposition@...> wrote:
|
Re: can't seem to find IB information on PCUSEQTR
开云体育hey there thanks for trying. I got the info I wanted. I'm not interested in
trading it. Just using it as one of the events in a state engine I
use to change my model. ??? skew_contract = Contract()
thanks again, cp
On 3/13/25 22:40, J G via groups.io
wrote:
|
Re: can't seem to find IB information on PCUSEQTR
I typed that symbol into IB's contract search engine. It appears to be the CBOE Equity Put-Call Ratio. No other information available. As it is a ratio, it is not something that can be traded.
misc.interactivebrokers.com/cstools/contract_info/v3.10/index.php?action=Advanced Search&entityId=a203707427&lang=en&ib_entity=&wlId=IB&showEntities=Y |
Re: 10326 - OCA group revision is not allowed
I am glad this worked for you, too. Looks like the problem and the solution is now well understood. It might be best for me to merge the two parallel topics. 闯ü谤驳别苍 On Thu, Mar 13, 2025 at 08:07 PM, wordd wrote:
|
Re: 10326 - OCA group revision is not allowed
Unfortunately we have two (almost identical) topics on this issue. You may want to check out "10326 OCA group revision is not allowed - it strikes again" as well. [MODERATOR EDIT: The two topics have been merged and posts from both topics are in this topics now] The root cause for error 10326 in that post was the fact, that the original bracket order did assign a custom OCA group name to the profit taker and stop loss child orders. Newer TWS versions seem to ignore those OCA group names, assign generic names, and consequently and correctly reject child order changes with error 10326 when the custom OCA name is used. It looks to TWS as if you want to change the OCA group membership of the order which is not allowed and causes error 10326. As the code samples for bracket orders in the TWS API documentation suggest, do not assign OCA group names in bracket orders, rather let IBKR assign them. And when you try to change an order, always start with the last Order object you received from IBKR through an openOrder() callback. That Order object will always be most up to date and complete. And in this case, will contain the OCA group name assigned by IBKR. 闯ü谤驳别苍 ?
?
On Thu, Mar 13, 2025 at 03:05 PM, wordd wrote:
|
Re: 10326 - OCA group revision is not allowed
Hi Jimmy thanks for the reply back in Nov.. curious if they ever got you a solution in ticket #804191? or if you got it working ever?
?
I've got an OCA Group type 2 and am trying to update stop price of one of the orders. Always getting this error:
Error 10326, reqId 40: OCA group revision is not allowed. Set parentId = 0, unticked any api order protection.. no dice. Going to try next using a different order object, rather than the original order I submitted, use the one passed back in the status.. sorta like 闯ü谤驳别苍 alluded to. I'll report back if I find anything. Anyway thanks in advance. |
Re: 10326 - OCA group revision is not allowed
I am glad that worked for you, Max. Interestingly, just before your post I was able to reproduce? your issue by assigning an OCA group name AND by reusing the original profit taker order. Apparently, TWS ignores the OCA group name from the initial order, still assigns a generic OCA group to the child orders, and returns Order objects with their generic OCA group names.
And it is very well possible that this behavior was introduced by newer TWS versions. But that validates my approach of:
闯ü谤驳别苍
? ? ?
On Thu, Mar 13, 2025 at 02:31 PM, Max Payne wrote:
|
Re: 10326 - OCA group revision is not allowed
闯ü谤驳别苍,
?
Success! And epiphany #1: when I skip setting ocaGroup (while keeping parentId as in initial order) the problem goes away. The execution engine is once again purring happily!
?
I appreciate your explanation of how you use openOrder(). I do use it (and the other callbacks you list) to track fills, cancellations, cross check positions etc., but it never occurred to me to look beyond .status and .totalQuantity.?
I am going to take a closer look at this as it has clear potential for debugging if nothing else. Some aspects of your PositionController have equivalents in my code, but this is a good opportunity for me to think it through again.
?
Thanks again, this has been most helpful. |