import robin_stocks.robinhood as robinimport pyotplogin = robin.login("YOUR-EMAIL","YOUR-PASSWORD")totp = pyotp.TOTP("APP-KEY").now()print("Current OTP",totp)
run code then you can see OTP put into robinhood
python3robin.py
copy and save backup code for future
let's create secret file
vi./totp.txt
APP-KEY
USER-EMAIL
USER-PASSWORD
let's create python script
virobinhood.py
importrobin_stocks.robinhoodasrobinimportpyotpimportsysSP=20000.0lines=open('./totp.txt').read().splitlines()KEY=lines[0]EMAIL=lines[1]PASSWD=lines[2]totp=pyotp.TOTP(KEY).now()print("Current OTP",totp)login=robin.login(EMAIL,PASSWD,mfa_code=totp)my_stocks=robin.build_holdings()for key,value in my_stocks.items():print(key,value)
run and check output
Get Qoute / Buy / Sell
# my_stocks = robin.build_holdings()# for key,value in my_stocks.items():# print(key,value)defQoute(ticker): r = robin.get_latest_price(ticker)print(ticker.upper() +": $"+str(r[0]))defBuy(ticker,amount): r = robin.order_buy_market(ticker,amount)print(r)defSell(ticker,amount): r = robin.order_sell_market(ticker,amount)print(r)TICKER ="tsla"Qoute(TICKER)AMOUNT =1Buy(TICKER,AMOUNT)Sell(TICKER,AMOUNT)
Caution
You can only daytrade a limited number of times. Please note that