Skip to content
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

Allow session to be cached to disk #56

Merged
merged 4 commits into from
Jun 27, 2024

Conversation

tristanpenman
Copy link
Contributor

@tristanpenman tristanpenman commented Mar 22, 2024

Raising this as a draft, for some early feedback. This is just my first pass at doing this, and I feel that some of the error cases are not yet handled well enough.

A quick summary of the changes so far:

  • Allows session cookies and headers to be cached to disk
  • Attempts another login if call to update_token fails
  • Session cache also stores hash for username, password, and TOTP secret, so that if any of the original unhashed values change, we know that the cached session cannot be used

Keen to hear what you think!

@tristanpenman tristanpenman marked this pull request as ready for review May 19, 2024 11:37
@tristanpenman
Copy link
Contributor Author

@itsjafer apologies for taking so long to get this ready for review. This has been on my TODO list for many weeks now, and I've just gone through and tidied up my changes. The main changes since I first raised the PR are:

  • Added a lazy parameter for the login method. I found that this was more practical when testing with my mini trading server. It ensures that the server starts up, even if the Schwab API is down. Login attempts will be performed lazily, on subsequent requests. This is the same as if the previous login credentials expire.

I've tried to ensure that this is all backwards compatible with the existing API.

As far as potential improvements go, I think it would be worth rate-limiting login attempts. However, I chose not to do that as part of this PR, to keep the changeset reasonably small. It is also possible for the async login process to get stuck when invalid credentials are used - I think this is pre-existing, so I'll raise an issue for that.

@itsjafer
Copy link
Owner

Thanks for the PR! I looked through the code and didn't find anything of note -- I'll test out the functionality locally sometime this week to confirm it works as expected, and then merge this in!

@itsjafer itsjafer merged commit 104129e into itsjafer:main Jun 27, 2024
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants