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
1.03k stars 181 forks source link

stable version #250

Open giulyko00 opened 6 months ago

giulyko00 commented 6 months ago

Hi, I've been trying to understand what was the problem reading the "issues" page but without succeeding. I downloaded the "tws-stable-standalone-windows-x64" version but through IBC always the LATEST version gets started. Cattura

rlktradewright commented 6 months ago

That menu item doesn't show which version is running, it just gives you the option to switch.

If you want to check that the right version is running, look at the Help | About Trader Workstation menu item. That shows you the full version number that's actually running.

I can assure you that if you downloaded the Stable version, that's what you'll get (unless you use the menu item in your screenshot to switch it). IBC has no interest in or knowledge of the TWS version number: it just runs whatever you downloaded.

giulyko00 commented 6 months ago

Ok, I thought that was the reason why my tws crashes or gets restarted at unusual times. Right now for example. Can I share with you my logs?

rlktradewright commented 6 months ago

Yes, please do. Attach the IBC logfile to your reply (attach using the 'Paste,drop opr click to add files' link blow the editing area) , do not quote it inline.

Don't include the TWS logfile: they are generally only meaningful to IBKR.

giulyko00 commented 6 months ago

Last disconnection happened tonight, at 00:50 CET I received the second factor authentication notification on my phone, so I send you both the wednesday and the thursday logs. P.S.: I have your task to restart IBC on task scheduler enabled, I just changed the restart time. IBC-3.18.0_TWS-1019_WEDNESDAY.txt IBC-3.18.0_TWS-1019_THURSDAY.txt

rlktradewright commented 6 months ago

I don't see what the problem is here.

It started at 00:50:01 on Wednesday, ran through the day till 23:50 when it did an auro-restart (presumably this is because you have AutoRestart configured for 11:50 PM in the Lock and Exit section of the Global Configuration dialog).

After it restarted, at 23:51:57, you pressed Ctrl-C and killed it.

Then at 00:50:01 on Thursday it started up again, presumably started by Task Scheduler. But because this was a 'cold' restart, it initiated full 2FA again.

So everything worked exactly as it should.

Perhaps you were expecting login to complete automatically without 2FA when it was restarted by Task Scheduler? Well, sorry, that's a misunderstanding. Login without 2FA only happens after TWS has exited as a result of auto-restart, or use of the File | Restart ... menu entry.

giulyko00 commented 6 months ago

Yes I understand but why do you say " you pressed Ctrl-C and killed it"? I didn't (I mean, at least I didn't forget). Maybe my tws crashed?

rlktradewright commented 6 months ago

Here are the last two l;ines of the Wednesday logfile:

2024-03-20 23:51:57:649 IBC: detected frame entitled: Login; event=Closed ^C

^C is what is recorded when Ctrl-C is pressed. Pressing it causes the Java Virtual Machine to shut down (unless the event is caught and handled, but IBC doesn't do this), and before it exits it writes that text to StdErr, and it's then redirected to the IBC logfile. IBC itself is not involved in this sequence.

I've never seen this as a result of a TWS crash (in fact I haven't had a TWS crash for years), but I suppose it's possible.

I presume ending the task via Task Manager would have the same effect.

giulyko00 commented 6 months ago

It happened again, I didn't do anything and then the task scheduler restarted IBC at 00:50. Can you think of what the cause could be?

rlktradewright commented 6 months ago

Clearly something is shutting down or killing the IBC/TWS process just after the auto-restart. Here are some reasons this might happen:

I suspect the last of these is the most likely culprit, so have a careful look at that, and read the detailed description below to make sure you understand how this is all supposed to operate.

By the way I created a new version of the Scheduled Task template a few months back, because there were some things in the previous version that weren't quite right. I don't recall the details, but I advise you to base your task on the new template which you can find at:

https://github.com/IbcAlpha/IBC/blob/master/resources/Start%20TWS%20(autorestart).xml

The whole point of that task is that it's set up to automatically restart IBC if it shuts down. This enables it to keep IBC/TWS running all week even if something fails..

As far as Task Scheduler is concerned, the task is the running .bat file, not the IBC program. When TWS does its auto-restart, it creates the autorestart file that contains encrypted credentials, then shuts itself down (and IBC goes with it because it's in the same process as TWS), but the .bat file is still running, so Task Scheduler doesn't consider that the end of the task. The .bat then reloads IBC which starts a new instance of TWS,, and TWS completes the auto-relogin using the information in the autorestart file to avoid the need for 2FA..

But if TWS stops for any other reason, as listed above, then the .bat file also exits: Task Scheduler now conisders the task completed, so it restarts it after the specified interval. In this case, the autorestart file won't have been created, so TWS will do a full login requiring 2FA.

If you need to shut down TWS for a time for some reason without it restarting (for example to install a new version of TWS or IBC), then it's safest to disable the Schedule Task before closing TWS, do what you need to do, then run the Scheduled Task again to get it all gooing again.

giulyko00 commented 6 months ago

Ok thank you, for the moment.

giulyko00 commented 6 months ago

Now every night an additional instance of IBC gets started as you can see: image

rlktradewright commented 6 months ago

It might be helpful if you tell me what has changed. I'm not a mind reader...