Skip to content

Instantly share code, notes, and snippets.

@jozsefs
Created January 3, 2020 20:02
Show Gist options
  • Select an option

  • Save jozsefs/092795dc81fbe15ef494b6d3b12c6459 to your computer and use it in GitHub Desktop.

Select an option

Save jozsefs/092795dc81fbe15ef494b6d3b12c6459 to your computer and use it in GitHub Desktop.
etoro portfolio json export
const data = [...document.querySelectorAll('.ui-table-row')].map(row => ({
market: row.querySelector('.table-first-name').innerText,
units: +row.querySelector('[data-etoro-automation-id=portfolio-overview-table-cell-container-units]').innerText.split('\n')[0].replace(/,/g, ''),
avgOpen: +row.querySelector('[data-etoro-automation-id=portfolio-overview-table-cell-container-open-rate]').innerText,
invested: +row.querySelector('[data-etoro-automation-id=portfolio-overview-table-cell-container-invested]').innerText.slice(1).replace(/,/g, ''),
pl$: +row.querySelector('[data-etoro-automation-id=portfolio-overview-table-cell-container-container-profit]').innerText.replace(/[<,$]/g, ''),
plPercent: +row.querySelector('[data-etoro-automation-id=portfolio-overview-table-cell-container-gain]').innerText.replace(/[<,%]/g, ''),
value: +row.querySelector('[data-etoro-automation-id=portfolio-overview-table-cell-container-equity]').innerText.replace(/[<,$]/g, '')
}));
JSON.stringify(data, null, 2);
@jozsefs

jozsefs commented Nov 15, 2020

Copy link
Copy Markdown
Author

Hey, this is intended to run from the browser (console), if you'd like to run this from node use something like puppeteer

@guille2286

Copy link
Copy Markdown

Hey, thanks for sharing.
I've tried running it from the the browser but can`t make it work.
I get the following message:

VM54136:2 Uncaught TypeError: Cannot read property 'innerText' of null
at :2:49
at Array.map ()
at :1:62

Sorry if I'm not seeing anything obvious but I'm totally new at this.
Thanks!

@jozsefs

jozsefs commented Dec 2, 2020 •

Copy link
Copy Markdown
Author

You should run this on the /portfolio page while being logged in and having at least 1 portfolio row.
(for example I tried running it on the /portfolio/history page and I had the same error as you)

@guille2286

Copy link
Copy Markdown

I'll give it a try! thanks for your feedback!

@goulashsoup

goulashsoup commented Mar 9, 2024 •

Copy link
Copy Markdown

Export current portfolio history

Not optimized one-liner, only includes Buy/Sell actions, but no deposits, interest, withdrawels:

JSON.stringify($("div[automation-id='table-list']").children().map((index, el) => { const buy_sell_span = $(el).find('span.name').children()[0]; if(buy_sell_span) { return {'ticker': $(el).find('span.name').children()[1].innerHTML.trim(), 'action': buy_sell_span.innerHTML.trim(), 'is_cfd': $(el).find('span.cfd-tag').length > 0, 'invested': $(el).find("span[automation-id='cd-private-history-flat-item-invested']")[0].innerHTML, 'units': $(el).find("span[automation-id='cd-private-history-flat-item-units']")[0].innerHTML, 'open': $(el).find("span[automation-id='cd-private-history-flat-item-open-rate']")[0].innerHTML, 'close': $(el).find("span[automation-id='cd-private-history-flat-item-close-rate']")[0].innerHTML, 'open_date': $(el).find("div[automation-id='cd-private-history-flat-item-open-date']").children()[0].innerHTML, 'open_time': $(el).find("div[automation-id='cd-private-history-flat-item-open-date']").children()[1].innerHTML, 'close_date': $(el).find("div[automation-id='cd-private-history-flat-item-close-date']").children()[0].innerHTML, 'close_time': $(el).find("div[automation-id='cd-private-history-flat-item-close-date']").children()[1].innerHTML, 'profit_loss_amount': $(el).find("span[automation-id='cd-private-history-flat-item-profit']")[0].innerHTML, 'profit_loss_percentage': $(el).find("span[automation-id='cd-private-history-flat-item-gain']")[0].innerHTML}; } else { return null; }}).toArray());

Make sure to click "SHOW MORE" at the end of the history page to really export all trades in selected time frame!

@palsoft333

palsoft333 commented Nov 6, 2024 •

Copy link
Copy Markdown

Most recent version (make sure to replace € sign with $ or whatever currency you are using):

const data = [...document.querySelectorAll('.et-table-row')].map(row => ({
  market: row.querySelector('[automation-id=portfolio-overview-table-body-cell-market-name]').innerText,
  units: +row.querySelector('[automation-id=portfolio-overview-table-body-cell-units-value]').innerText.split('\n')[0].replace(/,/g, ''),
  avgOpen: +row.querySelector('[automation-id=portfolio-overview-table-body-cell-avg-open-rate]').innerText,
  invested: +row.querySelector('[automation-id=portfolio-overview-table-body-cell-invested-value]').innerText.slice(1).replace(/,/g, ''),
  pl$: +row.querySelector('[automation-id=portfolio-overview-table-body-cell-profit]').innerText.replace(/[<,€]/g, ''),
  plPercent: +row.querySelector('[automation-id=portfolio-overview-table-body-cell-gain]').innerText.replace(/[<,%]/g, ''),
  value: +row.querySelector('[automation-id=portfolio-overview-table-body-cell-equity]').innerText.slice(1).replace(/,/g, '')
}));

JSON.stringify(data, null, 2);

@sfnprg

sfnprg commented Jul 12, 2025

Copy link
Copy Markdown

While copying some traders innerText would throw an error, here a version including also asset name

const assets = [...document.querySelectorAll('.et-table-row-main')].map(row => ({
  market: row.querySelector('[automation-id=portfolio-overview-table-body-cell-market-name]').innerText,
  name: row.querySelector('[automation-id=portfolio-overview-table-body-cell-market-last-name]') ? row.querySelector('[automation-id=portfolio-overview-table-body-cell-market-last-name]').innerText : '',
  units: row.querySelector('[automation-id=portfolio-overview-table-body-cell-units-value]') ? +row.querySelector('[automation-id=portfolio-overview-table-body-cell-units-value]').innerText.split('\n')[0].replace(/,/g, '') : null,
  avgOpen: row.querySelector('[automation-id=portfolio-overview-table-body-cell-avg-open-rate]') ? +row.querySelector('[automation-id=portfolio-overview-table-body-cell-avg-open-rate]').innerText : 0,
  invested: row.querySelector('[automation-id=portfolio-overview-table-body-cell-invested-value]') ? +row.querySelector('[automation-id=portfolio-overview-table-body-cell-invested-value]').innerText.slice(1).replace(/,/g, '') : null,
  pl$: row.querySelector('[automation-id=portfolio-overview-table-body-cell-profit]') ? +row.querySelector('[automation-id=portfolio-overview-table-body-cell-profit]').innerText.replace(/[<,€]/g, '') : null,
  plPercent: row.querySelector('[automation-id=portfolio-overview-table-body-cell-gain]') ? +row.querySelector('[automation-id=portfolio-overview-table-body-cell-gain]').innerText.replace(/[<,%]/g, '') : null,
  value: row.querySelector('[automation-id=portfolio-overview-table-body-cell-equity]') ? +row.querySelector('[automation-id=portfolio-overview-table-body-cell-equity]').innerText.slice(1).replace(/,/g, '') : null,
}));

JSON.stringify(assets);

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