Skip to content

Instantly share code, notes, and snippets.

@marktellez
Created July 15, 2018 17:00
Show Gist options
  • Save marktellez/08353f7dc7dce8b1a1eb705219ec1b2c to your computer and use it in GitHub Desktop.
Save marktellez/08353f7dc7dce8b1a1eb705219ec1b2c to your computer and use it in GitHub Desktop.
Extract your tradingview paper trade journal into a csv file
trs = $($(".paper_trading table.balances")[2]).find(".tv-data-table__tbody tr").map((_, value) => $(value).find("td").map((_, value) => value.innerText))
trades = Object.values(trs.map((_, tr) => [Object.values(tr).slice(0,5)]))
var toTimestamp = val => {
var parts = val.split(' ')
switch(parts[1]) {
case "Minutes":
var d = new Date(new Date().getTime() - (parts[0] * 60 * 60))
break;
case "Hours":
var d = new Date(new Date().getTime() - (parts[0] * 60))
break;
case "Hour":
var d = new Date(new Date().getTime() - (60 * 60))
break;
default:
var d = new Date(`${val} ${new Date().getFullYear()}`)
break;
}
return `${d.getMonth()}/${d.getDate()}/${d.getFullYear()}`
}
trades = trades.slice(0, trades.length-3).map(trade => [toTimestamp(trade[0]), trade[1], trade[2], trade[3], trade[4]])
var csvContent = "data:text/csv;charset=utf-8,"
csvContent += ["Date", "Balance before", "Balance after", "Profit", "Notes"].join(', ') + "\r\n"
trades.forEach(rowArray => {
if(Array.isArray(rowArray)) {
var row = rowArray.join(",")
csvContent += row + "\r\n"
}
})
var encodedUri = encodeURI(csvContent)
window.open(encodedUri)
@Flexdirect
Copy link

Hi Mark, thanks for sharing. The code seems to be out dated now and not working, might you be able to update it please? Thank you

@wencio
Copy link

wencio commented May 29, 2023

Hi Mark, thanks for sharing. The code seems to be out dated now and not working, might you be able to update it please? Thank you

@marktellez
Copy link
Author

marktellez commented May 29, 2023 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment