Published
Edited
Oct 21, 2021
Importers
1 star
Insert cell
Insert cell
Insert cell
getQuote = async (symbol) => {
const data = await (await fetch(
`https://cors-anywhere.herokuapp.com/https://query1.finance.yahoo.com/v7/finance/quote?symbols=${symbol}`
)).json()
return data.quoteResponse.result[0]
}
Insert cell
getQuoteHistory = async (symbol, days) => {
const startDate = new Date()
startDate.setDate(startDate.getDate() - days)
const data = await (await fetch(
`https://cors-anywhere.herokuapp.com/https://query1.finance.yahoo.com/v8/finance/chart/?symbol=${symbol}&period1=${Math.floor(startDate.getTime() / 1000)}&period2=${Date.now()}&interval=1d`
)).json()
const [chart] = data.chart.result
const [indicators] = chart.indicators.quote
return chart.timestamp.map((x, i) => ({
date: d3.timeParse('%s')(x),
open: indicators.open[i],
high: indicators.high[i],
low: indicators.low[i],
close: indicators.close[i],
volume: indicators.volume[i]
}))
}
Insert cell
symbols = {
const data = await d3.tsv(
"//cors-anywhere.herokuapp.com/https://www.sec.gov/include/ticker.txt"
);
return data.map((item) => item[Object.keys(item)[1]].toUpperCase());
}
Insert cell
Insert cell
// getQuote('SHOP')
Insert cell
// getQuoteHistory('SHOP', 5)
Insert cell
Insert cell
d3 = require('d3')
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more