You are coming to the wrong conclusions, Greg.
The situation is very different when an existing subscription experiences errors 1100/1102 and when you subscribe to additional instruments. HMDS servers provide more than just ¡°historical data¡± and are involved during the subscription request, but they do not provide real-time data once the data feed has started. So it is safe for TWS/IBGW to disconnect HMDS farms at any point.
Here a quick overviw (as I understand it):
TWS/IBGW establish a connection to port 4001 of a ¡°primary server¡± at IBKR which is required to always be active. Primary servers are responsible for everything from login and account management to order processing, order status, and real-time data subscription permissions and management. They are located in several regions around the world, and their names look something like ndc1.ibllc.com.
TWS/IBGW is always prepared to switch over to one or two redundant hot-standby backup primary servers in a different region.
When the connection to the primary server is lost, TWS/IBGW will have very limited functions (or stop functioning all together). Error code 1100 is sent when the connection is lost, and connection restoration is indicated with codes 1101 (data and subscriptions may have been lost) or 1102 (no data or subscriptions have been impacted). Depending on the reason for the disconnection and in case it is brief, existing market data feeds may actually continue while the primary server is disconnected.
TWS/IBGW connect to various data servers (¡±farms¡±) as soon as data from those farms is needed. Under certain circumstances, TWS/IBGW will disconnect from those farms when they are no longer needed and indicates that with ¡°is inactive¡± codes 2107, 2108, and 2159. This has no impact on any subscribed services and connections will be reestablished transparently and instantaneously when the need arises. Your code can safely ignore these codes.
For a variety of reasons, connections to these farms can be lost while they are still in use. That can result in service disruption or delay and is indicated by the ¡°is broken¡± error codes 2103, 2105, and 2157. While it generally does not impact the subscription itself (data feed will restart and the connection is restored) your code may want to be aware of these codes and flag extended periods of disconnection especially outside of the daily IBKR maintenance/reset windows.
Once a connection is established to a farm (for the first time, after a period of inactivity, or after a broken connection), TWS/IBGW will send ¡°connection is OK¡± codes 2104, 2106, and 2158.
When you subscribe to a real-time market data feed TWS/IBGW perform the following steps:
- Unless already cached, TWS/IBGW makes a query to the sec-def server and retrieves more detailed information about the contract (instrument) you are trying to subscribe to. Only very few fields of the contract object you provide with your request are actually transferred to TWS/IBGW.
- The contract information retrieval from sec-def is followed by a ¡°ContractAdjustment1¡± query to the HMDS farm for that instrument. Apparently, certain volatile contract fields are maintained by the HMDS farm responsible for that instrument. TWS/IBGW may have to connect to the HMDS farm if it is not connected yet, and you will see an ¡°is connected¡± code 2106 for, in your case, euhmds.
- Once TWS/IBGW has all contract related information and your permission to subscribe is established, TWS/IBGW establishes a data feed from the market data farm that handles your instrument. If that farm is not connected, you will see an ¡°is connected¡± code 2104 for, in your case, eufarm.
- At this point, TWS/IBGW does not need the connection to the HMDS farm any longer and you may see ¡°is inactive¡± code 2107 for, in your case, euhmds. TWS/IBGW seems to review required connections during 1100/1102 reset sequences, unnecessary connections may be closed, and you are informed about such a disconnection in the text of the 1102 code (as you show in your example "The following farms are not connected: euhmds").
While there is an active market data subscription, TWS/IBGW will keep the market data farm connected and there is nothing you need to do. Once the last subscription handled by a farm is cancelled, you may see an ¡°is inactive¡± code 2108 for that farm.
A few thoughts on next steps for you.
If you experience stalling real-time market data subscriptions after a 1100/1102 sequence, I suggest you enable the ¡°Create API message log file¡± and the ¡°Include market data in API log file¡± options in TWS/IBGW for a while. That way you can verify that really no market data is being sent after 1102, or whether data is sent but the callback logic in your client is somehow malfunctioning.
I¡¯d reach out to IBKR for a solution if that log indeed shows that data was sent until 1100 but never restarted after 1102. We have never experienced that.
IBKR generally assigns your primary server based on your location and the kinds of instruments you work most with. But they can, if necessary, permanently assign your account(s) to a specific region. Your primary server defines when your daily server reset times are.
You will have the most stable service if your TWS/IBGW has reliable connections to all IBKR primary servers in the world (since at any point TWS/IBGW might have to switch over), but at least to the one assigned to your account. IBKR provides? a simple tool at you can use to verify that your TWS/IBGW machine can indeed connect to all of these servers.
If you want to learn more about how these things work (and you have some time on your hand) you can enable ¡°Help¡úTroubleshooting¡úEnable Verbose Logging¡± and ¡°Enable HMDS Logging¡± and follow a subscription and the subsequent data feed yourselves.
Here a quick overview about the "good" and 'bad" codes:
Type |
Relates to |
Code |
Message |
? |
? |
? |
? |
Error |
Primary |
1100 |
Connectivity between IB and the TWS has been lost. |
Error |
Primary |
1101 |
Connectivity between IB and TWS has been restored- data lost |
Info |
Primary |
1102 |
Connectivity between IB and TWS has been restored- data maintained. |
? |
? |
? |
? |
Error |
HMDS |
2105 |
HMDS data farm connection is broken:xxxxx |
Info |
HMDS |
2106 |
HMDS data farm connection is OK:xxxxx |
Info |
HMDS |
2107 |
HMDS data farm connection is inactive but should be available upon demand.xxxxx |
? |
? |
? |
? |
Error |
MD |
2103 |
Market data farm connection is broken: xxxxx |
Info |
MD |
2104 |
Market data farm connection is OK:xxxxx |
Info |
MD |
2108 |
Market data farm connection is inactive but should be available upon demand.xxxxx |
? |
? |
? |
? |
Error |
SECDEF |
2157 |
Sec-def data farm connection is broken:secdefnj |
Info |
SECDEF |
2158 |
Sec-def data farm connection is OK:xxxxx |
Info |
SECDEF |
2159 |
Sec-def data farm connection is inactive but should be available upon demand.xxxxx |
?
´³¨¹°ù²µ±ð²Ô