From ece362a84afa4bbba788753da75b244663d2a14f Mon Sep 17 00:00:00 2001 From: MuslemRahimi Date: Sat, 7 Sep 2024 22:13:59 +0200 Subject: [PATCH] add export to etf page --- src/routes/etf/[tickerID]/+page.svelte | 46 ++++++++++++++++++++++---- 1 file changed, 39 insertions(+), 7 deletions(-) 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() { - + + +