¿ªÔÆÌåÓý

ctrl + shift + ? for shortcuts
© 2025 ¿ªÔÆÌåÓý

Cannot connect to Production API, test is OK.


 

Hi All,

I suddenly (over the weekend) cannot connect on:
Call objTWSControl.m_TWSControl.Connect(connectionHost, connectionPort, clientId, False)
connectionHost is blank
connectionPort is correct in TWS API setup
clientId is correct and unique.

ONLY when trying to connect to Production.
I know we've all heard it before, but (to the absolute best of my knowledge) I've changed nothing.? This code is "as is" from IB and has not been changed ever.

If I simply switch (same XLS/VBA code) the connectionPort to the Test API port everything works.

My app (Excel/Win7/ActiveX) just hangs on the call. Old API code, don't know version.

Something changed over the weekend.

Thanks, as always, and Be Well,
Lou Dudka


 

We have not experienced any issues on our end, Lou, but then our setup is very different. Let me throw out a few thoughts, some or all of them you may have thought about yourself already:
  • Which version of TWS/IBGW are you running? Latest/Stable and Standalone/Autoupdate? Reason why I ask is that IBKR recently switched the stable track from the 981 level to the 10.12 level. There have been a lot of changes introduced in version 10 and I believe there are a couple new settings in the General API screen. Having said that, those TWS/IBGW changes should impact paper and real accounts equally.
  • Have you confirmed that the port for your real account in the TWS/IBGW API settings has not changed somehow? In other words, is the TWS/IBGW port really identical to the one you use in your client?
  • And finally, have you tried to get a "second opinion", meaning have you tried an API client that is very different from what you normally use? One that comes to mind is

Hope there is something here that gets you a step closer.

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

On Tue, Jul 5, 2022 at 06:36 PM, Lou Dudka wrote:

Hi All,

I suddenly (over the weekend) cannot connect on:
Call objTWSControl.m_TWSControl.Connect(connectionHost, connectionPort, clientId, False)
connectionHost is blank
connectionPort is correct in TWS API setup
clientId is correct and unique.

ONLY when trying to connect to Production.
I know we've all heard it before, but (to the absolute best of my knowledge) I've changed nothing.? This code is "as is" from IB and has not been changed ever.

If I simply switch (same XLS/VBA code) the connectionPort to the Test API port everything works.

My app (Excel/Win7/ActiveX) just hangs on the call. Old API code, don't know version.

Something changed over the weekend.

Thanks, as always, and Be Well,
Lou Dudka


 

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

Thanks, as always, for your complete and speedy response!

I'm (almost) ready to try replacing 981 with 10.12, simply because I've run out of ideas.

BTW both Prod and Test are running on the same machine, so all libraries, etc are the same.? I've even taken an XLS that's successfully connected to Test and changed the port to Prod and it hangs up. ? Any yes, as you pointed out, I double checked that the Ports are correct.? If I flip between the two (Prod and Test) API setup screens in TWS, they're exactly the same, with exception of the Port, as it should be.

The one thing I might try is bringing up another Prod TWS on the same machine and see if I can connect.? If I can, it would seem to point to the TWS connection itself.

I don't know what Richard's "Contract Inspector" is, but if the above fails, I'll spend some time researching it.

Thanks, as always, Be Well,udka
Lou Dudka


 

maybe firewall or antivirus updated?or changed?


El mi¨¦, 6 jul 2022 a las 3:15, Lou Dudka (<loududka@...>) escribi¨®:
´³¨¹°ù²µ±ð²Ô,

Thanks, as always, for your complete and speedy response!

I'm (almost) ready to try replacing 981 with 10.12, simply because I've run out of ideas.

BTW both Prod and Test are running on the same machine, so all libraries, etc are the same.? I've even taken an XLS that's successfully connected to Test and changed the port to Prod and it hangs up. ? Any yes, as you pointed out, I double checked that the Ports are correct.? If I flip between the two (Prod and Test) API setup screens in TWS, they're exactly the same, with exception of the Port, as it should be.

The one thing I might try is bringing up another Prod TWS on the same machine and see if I can connect.? If I can, it would seem to point to the TWS connection itself.

I don't know what Richard's "Contract Inspector" is, but if the above fails, I'll spend some time researching it.

Thanks, as always, Be Well,udka
Lou Dudka


 

joanmarcel119,

Thanks for your input.

It might be that except both Test and Prod are on the same computer using exactly the same code.

Thanks, as always, and Be Well,
Lou Dudka


 

Hi All,

Fixed (cannot say "solved").

Out of desperation I changed the Prod Port from 9707 to 9777 and it connected.

I then changed the Port back to 9707 and received errors.

Put it back to 9777 and will proceed as if nothing happened .... I have backups of TWS from last week and if I really wanted to I could start the TWS with them.? Ah, it's just not worth the trouble ...

Thanks to all, as always, Be Well,
Lou Dudka


 

But that sounds more like a network issue than a TWS issue, Lou.

  • As joanmarcel119? said firewall or antivirus related that prevents access to port 9707
  • Or even more subtle, a port clash with another service on your machine. If that clash happens on the TWS/IBGW machine, you should get an error message or at least a log entry.

What does your infrastructure between your client and TWS/IBGW look like?

And finally, any specific reason that you do not use the IBKR standard port assignments?

  • TWS_Paper_Account 7497
  • TWS_Live_Account 7496
  • IBG_Paper_Acctount 4002
  • IBG_Live_Account 4001
´³¨¹°ù²µ±ð²Ô


 

´³¨¹°ù²µ±ð²Ô and joanmarcel119,

Again, thanks for your input.

Firstly, I don't use IB's ports simply because we may (and do) run multiple TWS's on the same machine.

I bought up another TWS on the same machine and tried to assign port 9707.? TWS refused it and said it was in use, which it wasn't.

I ran? netstat -ano -p tcp and port 9707 did not show up.

I think it's an IB problem, not a "network" problem.? It appears IB doesn't think it "let go" of the port.

I'll guarantee you when I re-boot the machine this weekend and assign 9707 to the "offending" TWS it will work.

This is not a big deal (now) to me since I'm up and running.? I consider myself a trader first and a technician second, but it does intrigue me.

I'll keep you posted.

Thanks, as always, Be Well,
Lou Dudka


 

Happy hunting, Lou. My gut tells me that this is not an issue? with IB or TWS. It is sufficient that some defunct process holds on to port 9707 for TWS to be denied access to that port. Those sockets in that state may not show up in netstat listings of established connections. A couple ways to check this are:

  • My favorite command "lsof". Try it as " lsof -iTCP -n" so that it only shows you the processes that use TCP resources.
  • Or you could go to the horse's mouth with "cat /proc/nettcp" but make sure you convert to numbers from hex to decimal or look for port "25EB"
´³¨¹°ù²µ±ð²Ô


On Thu, Jul 7, 2022 at 09:00 AM, Lou Dudka wrote:
´³¨¹°ù²µ±ð²Ô and joanmarcel119,

Again, thanks for your input.

Firstly, I don't use IB's ports simply because we may (and do) run multiple TWS's on the same machine.

I bought up another TWS on the same machine and tried to assign port 9707.? TWS refused it and said it was in use, which it wasn't.

I ran? netstat -ano -p tcp and port 9707 did not show up.

I think it's an IB problem, not a "network" problem.? It appears IB doesn't think it "let go" of the port.

I'll guarantee you when I re-boot the machine this weekend and assign 9707 to the "offending" TWS it will work.

This is not a big deal (now) to me since I'm up and running.? I consider myself a trader first and a technician second, but it does intrigue me.

I'll keep you posted.

Thanks, as always, Be Well,
Lou Dudka


 

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

?I'd first like to thank you for the time and effort you put into this site, we are very fortunate to have you.
?
?Secondly, I like to especially thank you for the same time and effort you put into this particular problem I had on this topic.

Your technical knowledge is so immense it sometimes can overwhelm me.? I have 35 years professional IT experience, but I started with Mainframe IBM/Cobol.? Anything else has be self taught.
?
Having said that, I re-booted the computer, bought up TWS (Prod and Test with the same port that gave me trouble) and successfully connected.? I ran "netstat -ano -p tcp " and the port showed up, as it should.? Your " lsof -iTCP -n" and "cat /proc/nettcp" would not run on Win7, though thanks for the info.

?Somewhere in the cobwebs of my aging mind I seem to remember encountering this problem before? ...
.
?I have no reason to doubt your expertise so I will pay close attention to the ports that are in use and see if there is a conflict.
?
?Thanks, as always, and Be Well,
?Lou Dudka


 

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

OK, so Friday evening 07/08/22 I shut down everything and re-booted.? All times NYC.

I brought up both test and prod TWS.? Everything went fine, as expected, and there were no port conflicts.

Saturday, however, on the auto-reboot at 5:20 pm there was a port "conflict" on the test TWS this time.? I had a problem with prod last time.? "netstat -ano -p tcp " did not reveal any conflicts.

I brought down the test TWS and then up again.? No conflicts.? Both running on same machine.

I've been running with no conflicts ever since (Tuesday 07/12/22) with auto-reboots.

I'm leaning to a problem with TWS/auto-restart, and not a "real" networking port conflict.? I've had sporadic problems with TWS not coming up clean (thread #49333) and/or hanging on auto-restarts (no port conflicts) in the past.?? I've been trying to "watch" the auto-reboot live, but like a watched teapot, it never seems to boil ...

To the best of my knowledge I've changed nothing else (yeah, I know, we've all heard that one, LOL).

´³¨¹°ù²µ±ð²Ô, if I get another conflict I might take your suggestion to upgrade from 981.? I'm really short on time right now, so it would be a burden.

If all else fails I'll have to hang my head in shame from Richard and re-install IBC "on the sneak" and use Scheduler ... ah, those were the days, absolutely NO problems!

Thanks, as always, and Be Well,
Lou Dudka


 

Nothing is impossible, Lou, but my money is still on some application (real or defunct) holding the port. And it could simply be the old TWS during restart in case it does not completely terminate.

Next time, use a slightly different option for the netstat command. Use "netstat -qno -p tcp" instead of "netstat -ano -p tcp"

  • -a displays all connections and listening ports
  • -q? displays all connections, listening ports, and bound nonlistening TCP ports. Bound nonlistening ports may or may not be associated with an active connection.

On my Windows10 laptop, -a shows 88 ports in use, while -q shows 111 ports in use. Each port can only be used once and when some process uses 9707 as a "bound nonlistening port", TWS cannot get it as a listening port.

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


On Tue, Jul 12, 2022 at 05:33 PM, Lou Dudka wrote:
´³¨¹°ù²µ±ð²Ô,

OK, so Friday evening 07/08/22 I shut down everything and re-booted.? All times NYC.

I brought up both test and prod TWS.? Everything went fine, as expected, and there were no port conflicts.

Saturday, however, on the auto-reboot at 5:20 pm there was a port "conflict" on the test TWS this time.? I had a problem with prod last time.? "netstat -ano -p tcp " did not reveal any conflicts.

I brought down the test TWS and then up again.? No conflicts.? Both running on same machine.

I've been running with no conflicts ever since (Tuesday 07/12/22) with auto-reboots.

I'm leaning to a problem with TWS/auto-restart, and not a "real" networking port conflict.? I've had sporadic problems with TWS not coming up clean (thread #49333) and/or hanging on auto-restarts (no port conflicts) in the past.?? I've been trying to "watch" the auto-reboot live, but like a watched teapot, it never seems to boil ...

To the best of my knowledge I've changed nothing else (yeah, I know, we've all heard that one, LOL).

´³¨¹°ù²µ±ð²Ô, if I get another conflict I might take your suggestion to upgrade from 981.? I'm really short on time right now, so it would be a burden.

If all else fails I'll have to hang my head in shame from Richard and re-install IBC "on the sneak" and use Scheduler ... ah, those were the days, absolutely NO problems!

Thanks, as always, and Be Well,
Lou Dudka


 

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

The "q" netstat option in not supported on my Win7 machine.? Thanks for suggesting, though.

All's well so far ...

Thanks, as always, and Be Well,
Lou Dudka