itsjafer / schwab-api

A python library for placing trades on Charles Schwab
MIT License
201 stars 64 forks source link

add old API compatibility for login() to solve get_account_info() return 1 account issue #30

Closed cnMuggle closed 8 months ago

cnMuggle commented 8 months ago

workaround of this issue, use version 0.2.3 or similar or call get_account_info_v2() in latest version like 0.3.5. Below change provides an alternative. The major limitation is that by calling v1 or old API, the quote_v2() etc cannot be used.

mainly modify the def login() in schwab_api/authentication.py also add example/example_legacy_v1.py

either use get_account_info_v2() or add version='v1' as the login() parameter for get_account_info() to correctly return all schwab accounts info. For best backward compatibility , we should change the def login() default to 'version=v1' and explicit claim 'version=v2' for new API. I don't think I can make that decision and it will change the colab example as well.

example usage case

logged_in = api.login(
    username=username,
    password=password,
    totp_secret=totp_secret, # Get this using itsjafer.com/#/schwab.
    version='v1'   # or use 'old' 
)

# Get information about your accounts holdings
print("Getting account holdings information")
account_info = api.get_account_info()
WinesProof commented 8 months ago

@cnMuggle , can you try this alternative to solving the get_account_info problem: https://github.com/WinesProof/schwab-api/tree/get_account_info_all ?

Assuming it works for others, it would preserve compatibility between the v2 login process and get_account_info()

cnMuggle commented 8 months ago

@cnMuggle , can you try this alternative to solving the get_account_info problem: https://github.com/WinesProof/schwab-api/tree/get_account_info_all ?

Assuming it works for others, it would preserve compatibility between the v2 login process and get_account_info()

your solution is better. I will close this. @itsjafer I tested the https://github.com/WinesProof/schwab-api/tree/get_account_info_all from @WinesProof . It can solve the get_account_info() return 1 account issue without changing login()