Last active
August 22, 2022 17:49
-
-
Save jgonera/440a301d5883acd835c59b24bb59573f to your computer and use it in GitHub Desktop.
Save Vanguard activity (beyond last 18 months) as a CSV.
This file contains hidden or 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
var timer = setInterval(() => { | |
document.getElementById('account-0-showMoreLink').click(); | |
}, 1000); | |
clearInterval(timer); | |
function parse() { | |
const results = []; | |
document.querySelectorAll('#account-0-transaction-table > tbody > tr').forEach((node) => { | |
if (node.nodeType === Node.ELEMENT_NODE) { | |
const type = node.querySelector('[id$="-transactionType"] a').textContent.trim(); | |
const date = node.querySelector('[id$="-tradeDate"]').textContent.trim(); | |
const symbol = node.querySelector('[id$="-fundTicker"]').textContent.trim(); | |
const quantity = node.querySelector('[id$="-quantity"]').textContent.trim(); | |
const price = node.querySelector('[id$="-price"]').textContent.trim(); | |
const fees = node.querySelector('[id$="-commissionsAndFees"]').textContent.trim(); | |
const note = type === 'Reinvestment' ? 'Reinvestment' : ''; | |
// — is used for money market funds | |
if (!['Buy', 'Sell', 'Reinvestment'].includes(type) || symbol === '—') { | |
return; | |
} | |
results.push({ | |
date, | |
symbol, | |
type: type === 'Reinvestment' ? 'Buy' : type, | |
quantity, | |
price, | |
fees: fees.startsWith('$') ? fees : '$0.00', | |
note, | |
}); | |
} | |
}); | |
return results; | |
} | |
function toCSV(results) { | |
return [ | |
'Date,Symbol,Type,Quantity,Price,Fees,Note', | |
...results.map(({date, symbol, type, quantity, price, fees, note}) => | |
`"${date}","${symbol}","${type}","${quantity}","${price}","${fees}","${note}"`) | |
].join('\n'); | |
} | |
function download(content, fileName, contentType) { | |
const a = document.createElement('a'); | |
const file = new Blob([content], { | |
type: contentType | |
}); | |
a.href = URL.createObjectURL(file); | |
a.download = fileName; | |
a.click(); | |
} | |
download(toCSV(parse()), 'vanguard.csv', 'text/csv'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment