Skip to content

Instantly share code, notes, and snippets.

@konecnyna
Created December 15, 2020 00:41
Show Gist options
  • Save konecnyna/d3a9e2091fa8deee5ac9ba27e4492250 to your computer and use it in GitHub Desktop.
Save konecnyna/d3a9e2091fa8deee5ac9ba27e4492250 to your computer and use it in GitHub Desktop.
// 1. Open https://robinhood.com/account/history
// 2. paste code into console
var parse = () => {
let csv = "Name,Action,Amount\n";
let sections = document.querySelectorAll("[class*=rh-expandable-item]")
let credit = 0;
let debit = 0;
let validActions = ["Buy", "Sell", "Expiration"]
for (let i = 0; i < sections.length; i++) {
const section = sections[i].querySelectorAll("h3");
const transactionSection = section[0];
const priceSection = section[1];
const amount = parseFloat(priceSection.innerText.replace("$", ""));
if (!transactionSection || !priceSection || !amount) {
continue;
}
const transactionParts = transactionSection.innerText.split(" ");
const action = transactionParts[transactionParts.length - 1];
if (!validActions.includes(action)) {
continue;
}
const name = transactionParts.slice(0, transactionParts.length - 1).join(" ");
if (action == "Buy") {
debit += amount;
} else if (action == "Sell") {
credit += amount;
}
csv += `${name},${action},${amount}\n`
}
return {
csv,
credit,
debit
};
}
var 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();
}
var { csv, credit, debit } = parse();
download(csv, 'transactions.csv', 'text/plain');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment