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

Add auth_token argument to allow passing existing OAuth2/JWT token #66

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions Robinhood.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,11 @@ def login(self, username, password, device_token ,mfa_code=None):
self.headers['Authorization'] = 'Bearer ' + self.auth_token
return True

def use_token(self, access_token):
self.auth_token = access_token
self.headers['Authorization'] = 'Bearer ' + self.auth_token
return True

##############################
#GET DATA
##############################
Expand Down
9 changes: 8 additions & 1 deletion csv-export.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
'--mfa_code', help='your Robinhood mfa_code')
parser.add_argument(
'--device_token', help='your device token')
parser.add_argument(
'--auth_token', help='your oauth2 token')
parser.add_argument(
'--profit', action='store_true', help='calculate profit for each sale')
parser.add_argument(
Expand All @@ -32,13 +34,18 @@
password = args.password
mfa_code = args.mfa_code
device_token = args.device_token
auth_token = args.auth_token

load_dotenv(find_dotenv())

robinhood = Robinhood()

# login to Robinhood
logged_in = collect_login_data(robinhood_obj=robinhood, username=username, password=password, device_token=device_token, mfa_code=mfa_code)
if args.auth_token:
robinhood.use_token(args.auth_token)
logged_in = True
else:
logged_in = collect_login_data(robinhood_obj=robinhood, username=username, password=password, device_token=device_token, mfa_code=mfa_code)

print("Pulling trades. Please wait...")

Expand Down