jessecooper / pyetrade

Python E-Trade API Wrapper
GNU General Public License v3.0
209 stars 97 forks source link

Question about Etrade API #80

Closed ajshastri closed 1 year ago

ajshastri commented 1 year ago

Hello,

I have a question about how the trade API Auth module works looking at Etrade API Docs

I always understood the workflow as below:

  1. The key and secret are obtained from etrade.
  2. We use the oauth.get_request_token (https://api.etrade.com/oauth/request_token) to get the "EtradeURL"
  3. I go to the "EtradeURL" (which I think is a bit of a garbage process), login, do all that fun stuff, and retrieve the access tokens.
  4. Use this access token with the oauth.get_access_token class to get the OAuth tokens.
  5. I use these Oauth tokens for all my scripting/programming needs.

So these are my questions:

  1. The Get Access Token page on the etrade API doc says "The production access token expires by default at midnight US Eastern time." Does that mean I only have to generate it once a day?
  2. The Renew Access Token page says I can renew the token, can I use this to renew my token at 12:01AM EST every night and I never have to go through with regenerating the oauth tokens ever again?

Please let me know.

Robert-Zacchigna commented 1 year ago
  1. My understanding is that you need to generate a new token everyday, however, i have noticed in my usage that if you wait awhile between requests (like in the early morning and then again in the late afternoon), there is a point in which it will expire and a new one will be needed (i.e. the renew function doesn't work).
    • I dont know the exact time frame but i have definitely needed to generate a totally new token if i wait long enough during the day (again not sure on exact time frame).
  2. That is an interesting idea, i haven't tried that but I'm not sure if Etrade just forces the token to expire regardless if you keep renewing it. I'd be interested to know if that works if you end up testing it yourself.
ajshastri commented 1 year ago

@kgstorm, in this discussion post, said this and I verified it. I'll close this ticket.

https://developer.etrade.com/getting-started/developer-guides

After 2 hours with no activity, the access token becomes ‘inactive’, but can be renewed. It will ‘expire’ at midnight Eastern, and a new token will be required.

You could also make a simple market call every hour and not require the renewal process. But the token will still expire at midnight.