-
Notifications
You must be signed in to change notification settings - Fork 122
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[not an issue with ibeam] Account seems to be limited after a few days of running ('Gateway session active but not authenticated') #19
Comments
Hey @beanhedge welcome to IBeam! 😊 Thanks for reporting your issues. Unfortunately, like you correctly observe this doesn't seem to be IBeam failing but Gateway (or IBKR server) that's not handling authentication well. IBeam checks for that 'authenticated' flag and attempts to reauthenticate each time it sees it set to False. To highlight the importance of these issues and possibly accelerate improvements, I'd suggest you submit a ticket with IBKR support highlighting this problem. If you have any further information on why this issue seems to be appearing - for instance some repeated pattern - let us know. Otherwise the current advice is to just wait it through - it oftentimes resolves itself after some time. Let me know if I could help you in any way here 👍 |
The account issue resolved itself after a couple days. They did email me back and told me to try:
I didn't try it because my issue was already resolved. However, today I hit a new issue with the market data history endpoint: I ran a get request against "https://localhost:5000/v1/api/iserver/marketdata/unsubscribeall" and got {'unsubscribed': True} as well as the conid/unsubscribe endpoint but it didn't help. I emailed them again and will post what they say. |
That's useful, I'll see if using that different proxy URL helps at all - thanks a lot for posting this update. That new error you're running into sounds more like what the error itself says. Maybe try through TWS? |
I heard back from them today, I got:
So I guess there's nothing we can do. |
We have just started to play with this project, and are getting the above error straight off the bat. We are NOT getting the error however when running the windows gateway locally. Just to be clear, the docker container has never been able to successfully establish authentication it would seem. 2021-07-18 07:41:18,948|I| Gateway started with pid: 13 |
Hey @Greatsamps thanks for your contribution. It's interesting to hear that you notice the Gateway working correctly when initialised without IBeam. Could I ask you to run IBeam with LOG_LEVEL set to debug and pass over the program output produced? |
Like this: -e LOG_LEVEL=debug Made no difference to output.. |
Sorry for the confusion, running it in debug requires you to specify it as a variable used by the Python 'logging' module, therefore you need to put DEBUG in all caps. See here for more: https://github.com/Voyz/ibeam/wiki/IBeam-Configuration#debugging |
Ok got it working, it's IBEAM_LOG_LEVEL that needed to be set. incase this matters, this is a paper trading account. output below: WARNING: An illegal reflective access operation has occurred version: ed4af2592e9dd4a784d5403843bd18292fd441ea Fri, 9 Nov 2018 13:23:18 -0500 This is a Beta release of the Client Portal Gateway https://www.interactivebrokers.com/api/doc.html Open https://localhost:5000 to login |
Great, thanks for posting this. Everything seems to be in order, which would point at a similar issue that @beanhedge encountered. It's interesting that you say that running the Gateway manually doesn't cause this issue. In order to verify if that indeed is the case, could I ask you to do the following in short succession:
Thank you! |
Hi, Sorry for delay on this. Here is output from step 3: {"session":"b42059b2586ea798f8219b8ca26aa332","ssoExpires":594650,"collission":false,"userId":65305922,"iserver":{"tickle":true,"authStatus":{"authenticated":false,"competing":false,"connected":true,"message":"","MAC":"08:F1:EA:83:2D:DC"}}} It appears you are using the beta version of the GW whereas i am using the stable one. Could this be the difference? |
I have found something else strange. It seems running the GW locally i can't access any of the iserver endpoints. When i call iserver/auth/status i get the following: { This is a paper trading account, do you think that could be the problem, and perhaps this is also why IBeam is complaining? |
Thanks for doing this test and for passing over the results 👍 I don't think the paper account should have any influence on it, as I've noticed this error appearing on both paper and live accounts. We tried upgrading to beta version at some point but it didn't seem to solve the issues at hand so we reverted back to the stable from 9 Nov 2018 which I believe is the latest. That looks to me like the same issue as before - there's something failing at IBKR side, and even your vanilla Gateway fails to authenticate. I'd recommend you get in touch with the IBKR support and try to work with them to figure out why the authentication fails despite providing correct credentials. I'm sorry I cannot be of more help, but this is a known problem that we cannot jump over on IBeam side despite multiple attempts. Feel free to suggest any fixes if you can think of any. |
Hi Voyz, Need to start this out by thanking you for the hard work you've done; you've really done a huge addition to everyone trying to use IBKR's REST API. I faced this issue as well and I just contacted IBKR support. What they said is that it's a known issue and that they're working on it. But by the looks of this thread, this has been going on for months but to no avail. IBKR support requested me to try the beta version, but this thread has shown me that that won't work as well. Is there any suggestion we, as a community, can do to pressure Interactive Brokers to fixing this? |
hey @kavindu-athaudha welcome and thanks for your super kind words! 😊 Thanks for sharing your story about the conversation with IBKR. Indeed, we're around 7 months into these issues appearing regularly and there doesn't seem to be much improvement. I've tested the beta and stable versions and both appear to have this issue. From what I've read, IBKR never seemed to put retail investors and small firms, who probably will be primary users of the Web API, high up on their priority list - somewhat understandably.
And to answer your question - I honestly have no idea. I wouldn't want to act aggressively towards them (eg. on social media), and I don't know what methods there are to tackle behemoth companies into focusing on their underserved audience. If you (or anyone reading this) would have suggestions then please share them here. |
Yes, I agree on not doing anything aggressive. What I was thinking was something along the lines of getting more people (e.g. like the people in this thread) to all raise the issue with Interactive Brokers so they have a clearer picture of how important this issue is and maybe they would prioritize it more. |
Okay cool, @kavindu-athaudha and how would you suggest we could organise in such way? I advice all IBeam users to contact IBKR support when running into this issue, do you have any other ideas for how we could encourage them to submit a ticket? |
It looks that the gateway is subject to some obscure rate limits. Also it looks like that sending malformed requests also provokes de-authentication. |
@Voyz
@usr97629238
That is a very good idea, but I just went through their GitHub and unfortunately, it doesn't look as if it's very active. You could probably reach the developers directly but I'm doubtful (and I really hope I'm wrong) that we would get any fruitful replies. |
By the way, there is a new problem with the gateway, getting a 200 OK empty reply from /iserver/accounts (while /sso/validate and /portal/tickle report being authenticated)
They are indeed working somehow on the Gateway, at least https://gdcdyn.interactivebrokers.com/portal.proxy/v1/portal/swagger/swagger gets updates every two weeks. |
Thanks for your contributions @usr97629238 @kavindu-athaudha 👏
Indeed, this unfortunately all we've got so far. That accounts endpoint issue you're running into @usr97629238 is something new, I haven't seen that before, although I've seen endpoints randomly returning no data. Let us know if you've got any luck in reaching IBKR either through support ticket or privately over GitHub like you suggest. |
Been having these active but unauthenticated error cycles pretty frequently. latest one was lasting for the the past 10 hours. i switch proxy as below:
and it immediately worked when reloading the container...FYI |
hey @gmara13 thanks for following up on this - can I ask you if you're doing this every time the error appears, or do you mean that switching to it just once solves the issue for you forever? |
Thanks for reporting on these attempts, it's useful to know 👏 Seeing that
Thanks for suggesting this, but I'm not sure I'm following your proposal here - sorry. Do I understand you suggest to call |
my understanding too. however, gateway java app from IBKR might also be doing more than that, like caching some hashes that are time-dependent and keeping sending the same hash (until gateway restart and cache reset) to the load balancer, which in turn can cache it too server-side to identify client gateway sessions. the above is just a conjecture, but explains my observations when sometimes not even changing nodes (described above) and
having own gateway app that implements the three functions above and accepts load balancer node number as a (dynamic) parameter in a function (instead of reading it from static config file) would be a more lightweight method of resetting the session cache than the full-blown gateway app restart. |
Thanks for the rapid update! Will try out the new With the current version I've just observed calling |
Thanks for setting up this project @Voyz ! Great work. I've been working with the IBKR api and I see the same issue where, after a while, sso is authenticated, but the brokerage session will not authenticate for several hours. Reauthenticating through the https://localhost:5000/ page does not fix the issue. Short summary of what worked: I tried the suggestions from the comment above and so far it has been successful.
I did not change the proxyRemoteHost to N.api.ibkr.com. Just left it at the default. More details below: Note the requests with 200 response code (,200) resulted in successful brokerage session authentication.
I then did a POST to the gateway using https://localhost:5000/v1/portal/iserver/reauthenticate You can see the gateway attempts the ssodh authentication flow, in response to this post, but it's continuing to fail due to the 503 response from api.ibkr.com
Given the thread above I next did a logout when it was in this state of continuous 503 errors.
After that I did a reauthenticate:
I can see in the gateway logs it then completes an SSO reauthentication, then also attempts the brokerage session reauthentication with the ssodh endpoints. This time, ssodh/init returns a 200 response again, and the gateway is able to setup a new brokerage session.
I'm not sure if this is a 100% reliable workaround since I've not tried it that many times, but at least there was some success. |
@danielkrizian thanks for outlining your idea in more detail - that's very helpful and I understand it now 👍 At the moment I won't have time to investigate this idea further, but if you're successful in putting together some code that does such reauthentication then we could look at adding it into IBeam |
@isque03 thanks for bringing up your observations and outlining them in so much detail. Just to double check - which IBeam image are you using? I guess that adding a call to |
Hi @Voyz . I'm actually not using iBeam. I discovered this project after I already went down the rabbit hole of writing something similar in nodejs for my own project. Short answer: Yes, adding the reauthenticate after /logout seems fine. Note. It takes 20-40 seconds for the gateway to complete reauthentication. Long answer:
The "logout + reauthenticate" (not including SSO login) takes the gateway server between 25-40 seconds to complete (just looking through the logs and spot checking a few events). I also trigger the same 3 steps before any new trading event occurs so I can be reasonably sure that I'll be properly authenticated before attempting any orders. FWIW I don't restart the java gateway very often. The only state is seems to have are cookies that it holds after an SSO login. If you re-trigger an SSO login it will get new cookies So you might be able to save some time by just keeping it running. So far so good with that pattern. There is one more authenticate issue that I still see cropping up (Warning: perhaps a topic for a different issue/thread) The other thing that occurs is this:
Gateway logs show this:
The only workaround I have found so far is to manually log into IBKR on the mobile app (or I suppose web/desktop). It will say "another session is in use, disconnect?" I click "yes" to disconnect, then I explicitly click the logout in the mobile app. After this I'm able to get a properly working brokerage session from the logout/reauthenticate flow. My suspicion is that it's the call for brokerage session ssodh/init that the gateway makes. Specifically the compete param in here: `SSODH Init Request POST https://api.ibkr.com/v1/api/iserver/auth/ssodh/init The body, of type x-www-form-urlencoded, must have the following parameters:
The compete param here recommends setting it to false. What I think this does is trigger any other brokerage session to be invalidated, and allow a new one to be created. Setting compete "true" I beleive means that it will not kick out the other session. (Even though that seems sort of backwards from what you'd expect) Programmatic workarounds here? I think the only choices are:
|
Fantastic reply @isque03 thank you for writing it all up, that's a lot of very useful information 🙏 I understand that using your flow we could save ourselves from having to restart the Gateway after logging out. I'll put together a release where we do that instead of th restart and publish it when I find a moment.
How are you calling it? Through the Gateway? Or directly to IBKR servers? I'm using The 503 Service Unavailable issue has cropped up in a few places before, so along with your suggestion I've created a separate issue to discuss it: #38 |
The endpoint documentation says it's a POST. I never tried it as a GET. Yes, I call the gateway, not direct to IBKR. Here's how I call it from curl.
Interesting that GET works too. (I see the same response and behavior). Looks like the gateway is intercepting /v1/api/logout and proxying it on to api.ibkr.com. I'm not sure if there's a behavior difference between the two or not. Though GET requests really shouldn't be changing state, so POST is probably safer. A GET request might be cached by a proxy somewhere between the gateway and IBKR which would mean the logout actually never happened. You just got a cached "success" response from some proxy server along the way. |
@isque03 After reading this and also having had problems with the |
@JackD111 that's a great idea. See last comment in #38 . But the proxy would help with the "I don't have a session token" problem. It's also a much easier quick way to test if changing the compete property from true to false even works. I'll try some testing tonight to see if the compete=false even works. |
I was able to get the gateway to send a compete=false instead of true when creating the brokerage session. But it doesn't look like this helps solve the problem of forcing a new brokerage session to "win" and kick out any previous session. I setup two gateway clients. Logged in with one (Gateway A) and made sure that /v1/api/iserver/accounts returned a non empty response. Then I tried logging in using compete:false. The original Gateway A remained logged in. The second gateway (Gateway B) could not get a brokerage session. The /v1/api/iserver/accounts endpoint would just return {}. After about 30 seconds the /v1/api/tickle endpoint started reporting: I also did a few rounds of calling /v1/api/logout and /v1/api/reauthenticate. No difference. Gateway A consistently reported Went back to original settings with compete=true This time Gateway A was logged out after about a minute and its SSO session was invalid. Endpoints returned 401. I was able to regain an SSO and brokerage session on Gateway A by doing another SSO login again. FYI on the Proxy: It looks like the gateway uses a library valled Vertx. That library advertises a separate set of system properties for specifying the proxy server. But those didn't work either. Possibly the version of Vertx used by the gateway is too old and didn't support an http proxy at the time. There was also a bug reported in 2017. Maybe that's what I was running into, not sure: eclipse-vertx/vert.x#1944 https://docs.mitmproxy.org/stable/howto-transparent/ |
@isque03 Interesting findings. I've also tried mitmproxy yesterday and manged to get it working. Here is a rough outline of what I did but steps might be missing. I've executed all the commands inside the ibeam container to make it easier and manged to get it working that way in transparent mode. Looking at the traffic it also seems the gateway isn't using the full auth flow as descirbed in https://www.tradersinsight.news/ibkr-quant-news/tutorial-web-api-connect-to-brokerage-session/. I didn't see the compete param used anywhere in the auth requests. The ibeam container also has to be started with These were the commands to set the whole thing up:
|
@Voyz I want to say Thank You for Your code. Can you help me? |
Hey @andrey-ned thanks for the kind words and for using IBeam 😊 The issue you're encountering is the same as one everyone else is experiencing here. We're waiting for IBKR to solve it on their end, while some work is being done to mitigate its impact. You can read about it in this very issue, however there isn't any direct fix I can suggest right now. Stay tuned for more updates in the future 👍 |
Hi, @Voyz, so It's official problem on IBRK side ? |
@andrey-ned We don't know how official it is, but it is almost certainly a problem with Gateway and IBKR servers. |
Let us know how the 0.4.0 versions are working for you - has it helped with the repeated |
Not using ibeam (need to check it out). I ran into this issue after using the REST client portal API with the local gateway running in my Windows desktop. I changed proxyRemoteHost: to "https://1.api.ibkr.com" and it did resolve the lost authentication issue for me. Thanks everyone for your comments. |
To anyone involved - seeing I haven't heard back regarding this issue I'm going to be looking at merging the |
Closing this as |
First of all, thank you so much for this project, it's been a great help.
I just wanted to report that my account seems to have been limited after running the container 24/7 over 4 days. (This isn't a problem with ibeam because manually running the client has the same issue. I just wanted to put it here to warn others.)
It's been running fine the past few days with:
but today it started doing
I started the portal manually on my computer to check what was going on. Login through the web page still works, I still get "Client login succeeds". https://localhost:5000/v1/portal/sso/validate and https://localhost:5000/v1/portal/tickle, https://localhost:5000/v1/portal/portfolio/accounts still return 200. However, ticker shows "authenticated: false".
https://localhost:5000/v1/portal/iserver/marketdata/history and https://localhost:5000/v1/portal/iserver/accounts
gives
The text was updated successfully, but these errors were encountered: