Created
February 16, 2021 19:51
-
-
Save alexleekt/a43fd762e55fb7d98de15f83cf07ff32 to your computer and use it in GitHub Desktop.
robinhood history to excel and google sheets
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// exports robinhood history to tab-separated file which can be imported to excel and google sheets | |
// | |
// modified version of the script from https://medium.com/@anonovation/how-to-download-your-robinhood-transaction-history-357b1ff4df15 | |
// go to https://robinhood.com/account/history in Chrome | |
// Scroll down to the bottom to where it says “Show more items” and click that button (so that all transactions are shown) | |
// Open the Chrome Dev Tools window (Windows — Ctrl + Shift + I, Mac — Option + Cmd + I) | |
// Paste this code into the console | |
let csv = "Date\tType\tTotal\tPrice per share\tNumber of Shares\n"; | |
let sections = document.querySelectorAll('section'); | |
for (let i = 0; i < sections.length; i++) { | |
const transactions = sections[i].querySelectorAll(':scope > div') // | |
for (let j = 0; j < transactions.length; j++) { | |
const transaction = transactions[j].children[0].children[0]; | |
if (transaction == undefined) { | |
continue; | |
} | |
const date = transaction.children[0].innerText.split('\n')[1] | |
const name = transaction.children[0].children[0].textContent.replace(date, "") | |
const total = transaction.children[0].children[1]?.querySelector("h3").textContent.replace("+", ""); | |
let pps = ''; | |
let numberOfShares = ''; | |
const testTotal = transaction.children[0].children[1]?.textContent.replace("+", "").replace(total, ""); | |
if (testTotal) { | |
numberOfShares = testTotal.includes('shares') ? testTotal.split(' shares at ')[0] : ''; | |
pps = testTotal.includes('shares') ? testTotal.split(' shares at ')[1] : ''; | |
} | |
csv += `${date}\t${name}\t${total}\t${pps}\t${numberOfShares}\n` | |
} | |
} | |
function download(content, fileName, contentType) { | |
var a = document.createElement("a"); | |
var file = new Blob([content], { | |
type: contentType | |
}); | |
a.href = URL.createObjectURL(file); | |
a.download = fileName; | |
a.click(); | |
} | |
download(csv, 'transactions.tsv', 'text/plain'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This doesn't seem to work as of Feb 2022 -- I think the date var is one giant string with all of the information from each transaction.