diff --git a/src/routes/etf/[tickerID]/+page.svelte b/src/routes/etf/[tickerID]/+page.svelte index feb6fd79..94c4ce2f 100644 --- a/src/routes/etf/[tickerID]/+page.svelte +++ b/src/routes/etf/[tickerID]/+page.svelte @@ -714,6 +714,34 @@ async function initializePrice() { } } + + async function exportData() { + + await historicalPrice('max'); + + const csvRows = []; + + // Add headers row + csvRows.push('time,open,high,low,close'); + + // Add data rows + for (const row of output) { + const csvRow = `${row.time},${row.open},${row.high},${row.low},${row.close}`; + csvRows.push(csvRow); + } + + // Create CSV blob and trigger download + const csv = csvRows.join('\n'); + const blob = new Blob([csv], { type: 'text/csv' }); + const url = window.URL.createObjectURL(blob); + const a = document.createElement('a'); + a.setAttribute('hidden', ''); + a.setAttribute('href', url); + a.setAttribute('download', `${$etfTicker}.csv`); + document.body.appendChild(a); + a.click(); + document.body.removeChild(a); + } @@ -873,13 +901,17 @@ async function initializePrice() { - + + +