IbcAlpha / IBC

Automation of Interactive Brokers TWS. You can download the latest release here: https://github.com/ibcalpha/ibc/releases/latest
GNU General Public License v3.0
974 stars 174 forks source link

IBC Not selecting Second factor device 'IB Key' #255

Closed 1984-mike closed 1 month ago

1984-mike commented 2 months ago

Hi

I am having a problem where IBC is not selecting 'IB Key' as the 2nd factor device

Im running version 3.18.0

in the config.ini I have SecondFactorDevice=IB Key

Screenshot 2024-05-08 113629

I see this was marked as resolved in 3.12.0-beta.2, I have tried running 3.12.0-beta.2 and does not work, could this be the version on TWS im running?

Im running TWS Build 10.19.2l Screenshot 2024-05-08 114806

Below is the log file, any help would be appreciated.

tws_logs.txt

rlktradewright commented 2 months ago

First, the lBC log file is not much help: that's because you used the deprecated LogComponents=yes setting. This doesn't log any structure details for the Second Factor Authentication dialog, because in fact for some reason that dialog never raises an open event, so the structure logging routine ignores it ('yes' means log the open event only). LogComponents=all would have caught it, as would the preferred LogStructureScope=known with LogStructureWhen=activate.

However in fact I didn't need that structure information anyway: I know that the structure of this dialog has not been changed, because I also use SecondFactorDevice=IB Key all the time..

I also know that IBC handled the device selection correctly, because either it does or it writes one of several erro messages to the logfile - and there aren't any.

So what seems to be happening here is something I observe occasionally, where although the IB Key entry is correctly selected, the alert is not actually sent to the IBKR Mobile app. in these circumstances, trying again (ie shutting down IBC/TWS and starting again) usually succeeds.

To automate this retrying, set ReloginAfterSecondFactorAuthenticationTimeout=yes in config.ini. You'll also need to set --on2fatimeout=restart in the ibcstart.sh command, unless you have a periodic restart using cron or similar.

1984-mike commented 2 months ago

I have made the changes to config.ini you suggested as well as passing '--on2fatimeout=restart' to ibcstart.sh

TWS still waits in the Select second factor screen, nothing is sent to my phone. If I manually click the Ok button then I get the alert sent to my phone and I can log in.

Below ore the logs with the changes to config.ini

tws_logs.txt

rlktradewright commented 2 months ago

That latest logfile only covers about 11 seconds. Please give me a realistic one.

Start the thing up, and just wait. You need to wait for at least 3 minutes before intervening in any way. No time to explain why now.

1984-mike commented 2 months ago

@rlktradewright thanks for your help, I have left TWS running for 40-50 minutes, below are the logs

tws_logs (1).txt

rlktradewright commented 2 months ago

Ok, thanks for that. I'm beginning to understand what's going on here. In TWS 1016, IB changed the way the Second Factor Authentication dialog is generated: before that it was a separate dialog, but they changed it so that the Login dialog morphs into the Second Factor Authentication dialog by overlaying the relevant controls. This has the side effect that IBC doesn't receive the usual events notifying the opening of a dialog, so it fails to detect it, and therefore doesn't deal with it as it should.

So I had to develop a trick, whereby IBC monitors the title of the Login dialog and detects when it changes to "SECOND FACTOR AUTHENTICATION", after which it initiates the proper processing of the latter. Unfortunately this code is not being executed in all the cases where it should be, resulting in the failure to process the device selection.

It should be straightforward to correct this, but I won't do it until the weekend. So I hope I'll be able to publish a new release next week with the fix.

1984-mike commented 2 months ago

Thanks, really appreciate your help.

rlktradewright commented 1 month ago

Ok, I now have a new version that I should correct the problem. This is a beta version, IBC 3.19.0-beta.2.

If this fixes the problem, I'll publish a new full release, so let me know how it goes.

You can download the new version from here:

https://1drv.ms/f/s!AlqfLEOWDJ9Zh-klxayDSKUDSpj0Ow?e=VBgR6x

The only files you need to update from the zip are IBC.jar and version.

You may notice that there is a new ColdRestartTime setting in config.ini. This is not supported by the Linux scripts in this version, so please ignore it for now. I may include it in the next Release, or I may decide to drop it entirely.

1984-mike commented 1 month ago

Thank you so much for your help, it worked perfectly.

1984-mike commented 1 month ago

@rlktradewright would you be able to create a release with the changes?

rlktradewright commented 1 month ago

Yes indeed I've been trying to find a time to do this. Sorry for the delay.

I'm going to be absent for a few days starting on 24 June, so I'll try to do the release before that. I'm also trying to set up a VPN server so that I can access my systems while I'm away.

At the very least I'll push all the updates to GitHub so I should be able to complete the release while I'm away even if I can't access my systems.

rlktradewright commented 1 month ago

@1984-mike

Release 3.19.0 published today.

1984-mike commented 1 month ago

@rlktradewright Thanks again for all your help