¿ªÔÆÌåÓý

ctrl + shift + ? for shortcuts
© 2025 Groups.io

Intermittent IBGW connection problems 10.19.2a


 

¿ªÔÆÌåÓý

Since switching from IBGW 10.12.2v (support ends July, 18th) to 10.19.2a I observe intermittent disconnects between IBGW and the IB server.
It is therefore not possible e.g. to get a continuous realtime tick-by-tick data supply (EUREX Futures).
Remarkably, a second Paper account IBGW isnt' affected at the same time and continues to deliver tick-by-tick data.

Maybe someone has the same problems or kindly enlightens me that I overlook something.

Regards
Greg

Today (July 4th) my API log of the Live account says (requesting EUREX FDXM, GBL data):

00:55:17:693 -> ---15-1-Uxxxxxxx
00:55:17:700 -> ---9-1-1-
00:55:17:700 -> ---64-2--1-2104-Market data farm connection is OK:usfarm--
00:55:17:700 -> ---84-2--1-2105-HMDS data farm connection is broken:euhmds--
00:55:17:701 -> ---44-2--1-2106-HMDS data farm connection is OK:ushmds--
00:55:17:701 -> ---94-2--1-2158-Sec-def data farm connection is OK:secdefnj--

and the Paper account:

00:52:42:430 -> ---15-1-DUxxxxxxxx
00:52:42:445 -> ---9-1-1-
00:52:42:445 -> ---64-2--1-2104-Market data farm connection is OK:usfarm--
00:52:42:449 -> ---44-2--1-2106-HMDS data farm connection is OK:euhmds--
00:52:42:449 -> ---44-2--1-2106-HMDS data farm connection is OK:ushmds--
00:52:42:449 -> ---94-2--1-2158-Sec-def data farm connection is OK:secdefil--

Yesterday (July 3rd) tickdata ceases at 06:25:37 AM and the IBGW log says, that the connection to zdc1 disconnected.
Then, it never re-connects while ndc1 re-connects within a second and stays healthy:

2023-07-03 06:26:56.740 [YN] INFO? [JTS-AsyncNonLocked-31] - disconnectAndReconnect due to routing change for euhmds state:NATIVE default:ccp dataType:NONE points:[useccphost] nativeViaCcp:null
2023-07-03 06:26:56.740 [YN] INFO? [JTS-AsyncNonLocked-31] - Disconnecting zdc1.ibllc.com:4000 [disconnectDetails=DisconnectDetails[sessionID=8,endPoint=zdc1.ibllc.com:4000,reason=DISCONNECT_ON_BROKEN_SOCKET,cause=null,systemMessage=null,keepSocketOpen=false]]...
2023-07-03 06:26:56.741 [YN] INFO? [JTS-euhmdsListenerS8-148] - Socket or stream for connection zdc1.ibllc.com:4000 was closed by another thread.
2023-07-03 06:26:56.741 [YN] INFO? [JTS-AsyncNonLocked-31] - Socket closed.
2023-07-03 06:26:56.741 [YN] INFO? [JTS-AsyncNonLocked-31] - Interrupting dispatcher [sessionID=8]...
2023-07-03 06:26:56.741 [YN] INFO? [JTS-AsyncNonLocked-31] - Interrupting listener [sessionID=8,disconnectSocket=true]...
2023-07-03 06:26:56.741 [YN] INFO? [JTS-AsyncNonLocked-31] - AuthTimeoutMonitor-euhmds: deactivate
2023-07-03 06:26:56.742 [YN] INFO? [JTS-euhmdsListenerS8-148] - Listener thread terminating [sessionID=8] [seen=20591,totalShifted=20591,moreAvailable=0]
2023-07-03 06:26:56.743 [YN] INFO? [JTS-euhmdsServicePingS8-153] - Terminating ping thread
2023-07-03 06:26:56.743 [YN] INFO [JTS-euhmdsDispatcherS8-149S8-150] - Dispatcher thread terminating [sessionID=8,interrupted=true]...
2023-07-03 06:26:56.744 [YN] INFO? [JTS-ResubscribeMarketData-79] - Resubscribing market data. desubscribe=false
2023-07-03 06:26:56.747 [YN] INFO? [JTS-DisconnectedS8-275] - Farm euhmds/NATIVE: Lost active connection with disconnect status DISCONNECT_ON_BROKEN_SOCKET
2023-07-03 06:26:56.747 [YN] INFO? [JTS-DisconnectedS8-275] - Farm euhmds/NATIVE: Resetting
2023-07-03 06:26:56.747 [YN] INFO? [JTS-DisconnectedS8-275] - CONN CALC: Last connection attempt time is cleared!
2023-07-03 06:26:56.747 [YN] INFO? [JTS-DisconnectedS8-275] - CONN CALC: Last connection set as now:06:26:56:747
2023-07-03 06:26:56.747 [YN] INFO? [JTS-DisconnectedS8-275] - HTBP Disconnected from live peer!::0
2023-07-03 06:26:56.747 [YN] INFO? [JTS-DisconnectedS8-275] - CONN CALC: Last disconnect time set as now:06:26:56:747
2023-07-03 06:26:56.748 [YN] INFO? [JTS-AsyncNonLocked-31] - Keep-alive scheduled for:euhmds
2023-07-03 06:26:56.748 [YN] INFO? [JTS-AsyncNonLocked-31] - cdebug: ROUTING | connTracker:euhmds@ab43b00 | Disconnected | 1688358414043 | true
2023-07-03 06:26:56.748 [YN] INFO? [JTS-AsyncNonLocked-31] - cdebug: ROUTING | connTracker:euhmds@5110d232 | Disconnected | 1688358414043 | true
2023-07-03 06:26:56.918 [YN] INFO [JTS-ushmdsDispatcherS20-269S20-270] - Compatible routing data:

...

2023-07-03 06:28:07.052 [YN] INFO? [JTS-usfarmListenerS3-47] - Socket for connection ndc1.ibllc.com:4000 was closed by peer.
2023-07-03 06:28:07.052 [YN] INFO? [JTS-usfarmListenerS3-47] - Disconnecting ndc1.ibllc.com:4000 [disconnectDetails=DisconnectDetails[sessionID=3,endPoint=ndc1.ibllc.com:4000,reason=DISCONNECT_ON_BROKEN_SOCKET,cause=null,systemMessage=null,keepSocketOpen=false]]...
2023-07-03 06:28:07.053 [YN] INFO? [JTS-usfarmListenerS3-47] - Socket closed.
2023-07-03 06:28:07.053 [YN] INFO? [JTS-usfarmListenerS3-47] - Interrupting dispatcher [sessionID=3]...
2023-07-03 06:28:07.053 [YN] INFO? [JTS-usfarmListenerS3-47] - Interrupting listener [sessionID=3,disconnectSocket=true]...
2023-07-03 06:28:07.053 [YN] INFO? [JTS-usfarmListenerS3-47] - AuthTimeoutMonitor-usfarm: deactivate
2023-07-03 06:28:07.053 [YN] INFO [JTS-usfarmDispatcherS3-48S3-49] - Dispatcher thread terminating [sessionID=3,interrupted=true]...
2023-07-03 06:28:07.053 [YN] INFO? [JTS-usfarmServicePingS3-77] - Terminating ping thread
2023-07-03 06:28:07.056 [YN] INFO? [JTS-DisconnectedS3-277] - Farm usfarm/CCP: Lost active connection with disconnect status DISCONNECT_ON_BROKEN_SOCKET
2023-07-03 06:28:07.055 [YN] INFO? [JTS-usfarmListenerS3-47] - Listener thread terminating [sessionID=3] [seen=422875,totalShifted=422875,moreAvailable=0]
2023-07-03 06:28:07.057 [YN] INFO? [JTS-DisconnectedS3-277] - Farm usfarm/CCP: Resetting
2023-07-03 06:28:07.057 [YN] INFO? [JTS-DisconnectedS3-277] - CONN CALC: Last connection attempt time is cleared!
2023-07-03 06:28:07.057 [YN] INFO? [JTS-DisconnectedS3-277] - CONN CALC: Last connection set as now:06:28:07:057
2023-07-03 06:28:07.058 [YN] INFO? [JTS-DisconnectedS3-277] - HTBP Disconnected from live peer!::0
2023-07-03 06:28:07.058 [YN] INFO? [JTS-DisconnectedS3-277] - CONN CALC: Last disconnect time set as now:06:28:07:058
2023-07-03 06:28:07.061 [YN] INFO? [JTS-Fuse-usfarm-ccppause-278] - Farm usfarm/DISCONNECTED: Connecting via ccp conman (usfarm)...
2023-07-03 06:28:07.061 [YN] INFO? [JTS-Fuse-usfarm-ccppause-278] - AsyncDisconnectNotifiers: 1
2023-07-03 06:28:07.061 [YN] INFO? [JTS-Fuse-usfarm-ccppause-278] - Waiting asyncDisconnectNotifiers: JTS-DisconnectedS3-277
2023-07-03 06:28:07.063 [YN] INFO? [JTS-Fuse-usfarm-ccppause-278] - Connecting ndc1.ibllc.com:4000 timeout=0...
2023-07-03 06:28:07.063 [YN] INFO? [JTS-Fuse-usfarm-ccppause-278] - CONN CALC: Last connection set as now:06:28:07:063
2023-07-03 06:28:07.064 [YN] INFO? [JTS-AsyncNonLocked-31] - Keep-alive scheduled for:usfarm
2023-07-03 06:28:07.172 [YN] INFO? [JTS-Fuse-usfarm-ccppause-278] - Connected to ndc1.ibllc.com:4000 on local port 0 socket local addrs:port /192.168.178.50:50906



 

You saw this but did impact your code ? Otherwise said did you try to make a request anyway ?
I suspect a pattern where IB disconnect on lazy use, (a connection is expensive as a resource)
Real Account typically are less active than Paper account which allow more experiment hence more activity hiding some difference in timing and traffic, less traffic is not always a good thing.

Also HDMS are for quering Data, this should not impact your trading capabilities


 

¿ªÔÆÌåÓý

Well, a trading algorithm based on realtime tick-by-tick data can have a problem if the time series has gaps or even ceases.
While at less liquid market hours the time between two ticks can last a couple of minutes I think a lazy use shutdown here and there is not a good idea.
As I understand the API a realtime tick-by-tick request is active and continues until the subscription is canceled.
However, it would be interesting if the API allows in a timely manner to detect that the realtime tick-by-tick supply is broken so that a new request can be initiated.
All in all the last two days my data supply was flawless and I'm in good hope.

On 08.07.2023 21:33, Gordon Eldest via groups.io wrote:

You saw this but did impact your code ? Otherwise said did you try to make a request anyway ?
I suspect a pattern where IB disconnect on lazy use, (a connection is expensive as a resource)
Real Account typically are less active than Paper account which allow more experiment hence more activity hiding some difference in timing and traffic, less traffic is not always a good thing.

Also HDMS are for quering Data, this should not impact your trading capabilities


 

I maybe wrong,but from what I see and practice:

0- You can't compare status of farm with a 30 seconds delay as in your evaluation.
I assume that you probably stop your Real account and start paper but didn't have both running simultaneously.

1- HMDS is for Historical request, it is? doesn't seems the farm that feed ticks (this seems to be Marketdata)

2- Hence HMDS maybe disconnected when not used with no harm or very little (waking it up require ~400ms on the first call as a wake up call, then its back to normal speed for quit sometime, at least 10 min during RTH)

3- If you want, set a watch dog that make a dummy call for a 1 bar AAPL, (or also a DAX stocks as it looks like your concern its the disconnection of farm related to Europe while this maybe related to your server location more than your marketplace)
Do it once every 3 min is enough to keep it alive. But again this may only be an issue for Historical and I don't felt any need for that.
As per Europe: be careful that RTH are earlier than US and it looks to me like IB tolerance to unused connection is lower (faster disconnect) aside of Local RTH.

4- Try using TWS (which have more internal reason to keep and ongoing traffic with IB farms)

So my question was: practically did you experience or have a clue that this impact your code ?
I am not sure it does.
But I would agree that it's pretty difficult to get such a clue.

I did set a receiving time stamp and always compare it to supplied time stamp for sake of consistencies and sometime it show a small discrepancies (< 900ms) but I always find it related to complex market condition.
Otherwise said ticks can be late (they always are but how much you accept is another issue) but not lost.
In general Tick driven algo need to be sure that you are not loosing ticks, but the time critical part will be the time to send and process the order anyway. which is > 1 magnitude slower than any tick discrepancies

Note:
In general people on this forum that are using IB ticks + simultaneously another tick provider, complain that the other one could be couple of second late. Without being a proof it's a suspicion that IB is reliable enough in general.



 

Thanks for all informations which I carefully collect.
Some further questions came up which I found no answer for:

1) Is it harmful to operate the Real account and Paper account simultaneously with RTD supply (on different or same assets) with 2 IBGW/TWS operating?
2) The IB support told me, that European exchange data (Market or History) are always delivered from Switzerland server, independent where my account is hosted at.
???? When I request EUREX realtime tick-by-tick data (and nothing else) the IBGW GUI tells me
??? ??? Market Data Farm????? ON:usfarm
??? ??? Historical Data Farm? ON:ushmds, ON:euhmds? or ON:ushmds, OFF:euhmds when disconnected
??? So it seems to me, that realtime tick-by-tick data is delivered by EUHMDS (I guess Switzerland) and not 'EUFARM'
Then, according to Gordon's mail I have to keep (EU)HMDS alive, albeit I do not need historical data.
3) A good idea to test if the TWS API provides a more stable tick-by-tick data supply. The time-and-sales list would be fragmentary, otherwise.


 

If your server has enough memory, running multiple TWS/IBGW simultaneously works just fine. And sharing the same market data subscription between a TWS/IBGW real and paper account is no problem either. But you might want to take a quick look at this article:

Real-time tick-by-tick data feeds and subscriptions are very reliable and completely unaffected by occasional historical market data farm disconnects. We have never experienced any gaps in tick-by-tick data feeds as long as our clients were behaving correctly. You can find several posts related to tick-by-tick data in the group archive, some of them even with performance details (such as this one).

Your questions made me curios and I ran some additional stats on our 2023 tick-by-tick real-time data feeds:

  • We subscribe to 15 tick-by-tick feeds: three feeds each (Last, Midpoint, BidAsk) for five futures traded at CME in Chicago.
  • Real-time tick-by-tick messages make up just under 40% of all real-time data messages we receive. The rest of the data volume relates to a number of Level I feeds plus three market book Level II feeds.
  • Our virtual server is located in the east of the US in a data center with high-speed, high-availability, and low-latency networking.

So here the fun part. Year-to-date 2023 we received:

  • A total of 5,931,446,980 real-time market data related callbacks. That is an average of 531 callbacks each second for all 23hr CME trading sessions this year.
  • 2,287,378,131 of these were tick-by-tick callbacks (205 callbacks per second)
  • The arrival time gap between adjacent tick-by-tick callbacks was less than a second for 99.94% of all callbacks (2,286,012,479)
  • 99.999975% of back-to-back callbacks had a time gap of less than 10 seconds.
  • And only 427 callbacks or 0.00001865% had a gap of 10 seconds or more. These are mostly callbacks that happen during the nightly maintenance window when you receive error 1100 "Connectivity between IB and the TWS has been lost" and error 1102 "Connectivity between IB and TWS has been restored- data maintained" during account resets.

In my book that qualifies for rock-stable, considering the monthly data charge is negligible.

If you do experience any tick-by-tick data interruptions, I'd suggest the following next steps: This is my interpretation of what Gordon called in a different post "Respect the basic API concepts":

  • Make sure your client always uses TWS API in an asynchronous fashion. There is one or more callback for every request make sure you implement them all.
  • Respecting the asynchronous nature of the API requires that your client shall never (ever ever) call sleep() for synchronization between requests and their related response callbacks.
  • The API is very good at error reporting when something goes wrong. So make sure your client properly captures, handles, and possibly logs all TWS API error messages. There are three error callbacks with slightly different signatures.
  • Make sure your clients perform only minimal processing on the the thread that handles the tick-by-tick callbacks. Perform any time consuming processing on or storage operations of that data on a separate thread so that tick-by-tick callbacks can always be processed right away.
  • You will very likely get error 1100/1102 pairs during the daily maintenance and reset window. These are generally brief interruptions of data flow (several seconds), can happen more than once during the window, and you do not need to resubscribe your feeds. Just make sure your client is aware of these.
  • Look out for error 1100/1101 pairs, since 1101 is "Connectivity between IB and TWS has been restored- data lost." and you will need to re-subscribe to your market data feeds. We have never seen an error 1101 in all those years we use TWS API, but your code should be ready to perform re-subscriptions should such an error ever be reported.
  • You might get 21xx warning codes (via the error callback) that relate to data farm disconnection/connection events. They have no impact on the flow of tick-by-tick data streams and you don't have to engage any special code to keep those farms connected.

Pairs of error 1100/1102 can happen and disrupt real-time data flow outside of the maintenance window, too. In case you experience many of them during regular trading sessions, review the network connection between TWS/IBGW and IBKR. You can find some thoughts on that in this post.

´³¨¹°ù²µ±ð²Ô


 

That's impressive ´³¨¹°ù²µ±ð²Ô.

That's good to know for tick by tick data, what about lvl 1 reqMktData? same stats?

Would be interested to know your thoughts on orders and positions tracking please,
as neither work reliably in my humble experience:

- Positions can go wrong all of a sudden requiring a re-subscription or a full restart altogether,
so I just end up proactively cancelling and re-subscribing at regular intervals, which I find dirty.

- Order executions are difficult to track given they can be partially filled or the "Filled" status can not be triggered.
So I essentially track the execution of the order using a "done" Event and a timeout (the order validity end time),
and then check if order.filled has something in it, which I also find convoluted.

Thanks.

class Order_:
__slots__ =
...
def __init__(...):
...
def update(self, **kwargs):
for key, value in kwargs.items():
setattr(self, key, value)
if self.status in ('Filled', 'Cancelled', 'Inactive', 'ApiCancelled'):
if not self.done.is_set():
self.done.set()

def orderStatus(...):
...

self.orders[orderId].update(status=status, filled=filled, remaining=remaining, avgFillPrice=avgFillPrice)

def execution(self, order: Order_, timeout: int):
order.done.wait(timeout=timeout)
if order.filled > 0:
...




 

In general, reqMktData feeds seem to be quite stable and timely, too, John. Though we use them only to give context to our TickByTick and Level II data feeds, so we have less analysis for them. Keep in mind that most reqMktData feeds are aggregated over various time periods.

As an example, here a few highlights from a quick review of our June 2023 five second real-time bars (the ones you request via ). We get those for 50+ instruments and I looked at the arrival delay. Basically "arrival time" minus "bar time plus bar width":
  • The minimum delay we experience is 255ms. In other words it takes at least 255ms after the bar is closed for it to arrive in our TWS API client.
  • Indeces (SPX, SPW, DJI, ...) and very liquid front month futures had average/median delays around 750ms
  • Instruments with very little activity (such as futures expiring in 2024 and specialty instruments such as VXX.IV) had average/median delays around 1,100ms.
  • For our mix of instruments, average/median delay for all 2,016,969 five second real time bars in June 20023 was around 960ms.


We have experienced flaky position updates in V10 TWS versions (at least in paper accounts) that we had not seen in TWS 981 before. But TWS API is not at fault since the TWS GUI shows the same incorrect positions.

Our API clients are not impacted since we have our own implementation of ¡°Position¡± and ¡°PNL¡±. The IBKR implementations may make sense for human traders but never worked for us (even when they are correct). Our biggest problem is that PNL resets around midnight. We work in ¡°units¡± of CME futures trading sessions (17:00 to 16:00 US/Central next day) and API clients get confused when position PNL suddenly resets ¡°around midnight¡±.

We have found execution reports, commission reports, and even order status updates to be very reliable and timely. Our (Java) framework is multi-threaded, entirely event driven, broken into many small focused domain classes, models, and controllers/managers. It is completely separate from and unaware of TWS API. A thin adapter layer translates abstract framework operations (such as placing orders) into actual TWS API requests. That layer also converts TWS API responses into framework events that are independent of TWS API.

Certain framework events (such as market price update events) are broadcast so that position controllers can easily maintain their own notion of current PNL. We rarely have partial order fills, but TWS API order status events and execution reports are very accurate and timely so that position controllers can adequately model reality based on streams of order state, order status, execution and commission reports, and market price update events.

The framework uses a domain/class/model hierarchy that looks something like this:

Accounts ¡ú [1:*] Account ¡ú Positions ¡ú [0:*] Position ¡ú Trades ¡ú [0:*] Trade ¡ú Orders ¡ú [0:*] Order

Our API clients never have to restart or resubscribe during the trading session in response to TWS API activities. There are, however, controlled automatic daily restarts of TWS and API clients during the one hour per day when Chicago futures markets are closed.


I agree that your order.done and order.done.wait logic is convoluted and I can see many cases where that can lead to lockups or, in case timeouts are too short, cause other issues. You might need to make your clients more event driven and put more distance between your trade decision logic, execution, and order management on one side and the actual operation of TWS API on the other side (design approaches such as ¡°¡± and ¡°¡±).

You need to make sure your client does not assume any order or timing of events (order state, order status, execution reports, errors), can tolerate the occasional duplication of updates, takes all events into consideration (not just order status), and does not block the TWS API callback thread.

We make heavy use of the Java built-in concurrency features from , specifically the (a Java language concept, has nothing to do with CME future contracts). I believe some of those concepts are available in Python through the .

Another good source for ideas how you can better structure your Python clients may be Ewald de Wit¡¯s project.

But we are meandering away from the scope of this post and and the group.

´³¨¹°ù²µ±ð²Ô


On Wed, Jul 12, 2023 at 02:13 PM, John wrote:
That's impressive ´³¨¹°ù²µ±ð²Ô.

That's good to know for tick by tick data, what about lvl 1 reqMktData? same stats?

Would be interested to know your thoughts on orders and positions tracking please,
as neither work reliably in my humble experience:

- Positions can go wrong all of a sudden requiring a re-subscription or a full restart altogether,
so I just end up proactively cancelling and re-subscribing at regular intervals, which I find dirty.

- Order executions are difficult to track given they can be partially filled or the "Filled" status can not be triggered.
So I essentially track the execution of the order using a "done" Event and a timeout (the order validity end time),
and then check if order.filled has something in it, which I also find convoluted.

Thanks.


 

Thanks Jurgen for the detailed reply.

?uses a similar approach to mine, with the two below sets, and monitoring order.fills.
Unsure why Ewald chose to isolate the 'Inactive' state rather than adding it to the DoneStates btw.

? ? DoneStates: ClassVar[Set[str]] = {'Filled', 'Cancelled', 'ApiCancelled'}
? ? ActiveStates: ClassVar[Set[str]] = {'PendingSubmit', 'ApiPending', 'PreSubmitted', 'Submitted'}

I don't like the asyncio module, and prefer to use a tailored combinations of Threads, Events and Timers, but we are essentially doing the same thing.
I will play with the??to see if it adds any value over my current setup.

?We work in ¡°units¡± of CME futures trading sessions (17:00 to 16:00 US/Central next day)... TWS API order status events and execution reports are very accurate and timely so that position controllers can adequately model reality based on streams of order state, order status, execution and commission reports, and market price update events.
I also trade futures and restart daily after the close, "units" that's a very interesting concept.
I also considered monitoring positions myself, deducting them from order status updates,
especially useful when 2 strategies trade the same contract on the same account, it allows differentiation.

However I just preferred to avoid it so far in order to keep no stored info whatsoever on the client side, and rely solely on the server side info at all times.

Indeed not the topic of this thread, thanks for sharing insights anyways, much appreciated.


Ewald de Wit
 

On Sun, Jul 16, 2023 at 04:07 PM, John wrote:

Unsure why Ewald chose to isolate the 'Inactive' state rather than adding it to the DoneStates btw.

An "Inactive" order can become active again, so it's not certain that it's done yet.

-- Ewald