Skip to content

Instantly share code, notes, and snippets.

@weiw11
Last active September 8, 2022 04:58
Show Gist options
  • Save weiw11/17f7ad53563712a570b0446cb7a07b4c to your computer and use it in GitHub Desktop.
Save weiw11/17f7ad53563712a570b0446cb7a07b4c to your computer and use it in GitHub Desktop.
Export Robinhood Positions
# Prints your robinhood positions in (Symbol, Quantity, Avg_Price) format
# Example:
# AAPL, 100.00000000, 12.1234
# TTTT, ###.########, ##.####
import requests
robinhoodPositionsAPI = "https://api.robinhood.com/positions/?nonzero=true"
# Enter your authorization token here
# To get this, open robinhood and login
# Press F12 for dev tool and go to network tab
# Find any api access with Auth key and copy and paste it here.
# https://api.robinhood.com/marketdata/forex is a good endpoint
authToken =''
apiHeader = {
'Authorization': 'Bearer ' + authToken
}
# This may need to be changed/updated if you have a lot of positions
# Positions API response has 'next' key value pair.
apiResponse = requests.get(robinhoodPositionsAPI, headers=apiHeader)
data = apiResponse.json()
# Loops through positions json data for results array
for x in data['results']:
# InstrumentAPI request is needed to get ticker symbol
instrumentAPI = requests.get(x['instrument'])
symbol = instrumentAPI.json()['symbol']
# Prints out information
print(symbol + ", " + x['quantity'] + ", " + x['average_buy_price'])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment