gatsby-yahoo-finance-api
Source plugin for pulling in market and individual stock data into Gatsby from the unofficial Yahoo Finance API hosted by Rapid API.
Yahoo deprecated their API in 2012, but it has since been made available on Rapid API and still provides valuable data for current and historical stock market information.
Available data
- Historical (and at the time of build) pricing data and metadata for an individual stock or many stocks.
- Balance sheet data for an individual stock
- "Market Mover" data. (x number of stocks with the largest gains, losses, and most active trading at time of build).
This is only a small subset of the data offered by the Yahoo Finance API, so if there's something missing that you'd like to see added please open an issue or create a pull request in Github!
Install
npm install --save gatsby-yahoo-finance-api
How to use
First you'll need to create an Rapid API account to retrieve an API key here.
Then in your gatsby-config.js
, add the following plugin configuration for Gatsby to pull in your data:
plugins: [
{
resolve: "gatsby-yahoo-finance-api",
options: {
key: "<YOUR_API_KEY>",
queries: [
{
type: "get-historical-data",
params: {
period1: "1431010482",
period2: "1588863282",
symbol: "TSLA",
frequency: "1d",
},
},
{
type: "get-balance-sheet",
params: {
symbol: "TSLA",
},
},
{
type: "get-movers",
params: {
region: "US",
lang: "en",
count: "10",
},
},
{
type: "get-charts",
params: {
symbol: "TSLA",
region: "US",
lang: "en",
range: "3mo",
interval: "1mo",
comparisons: "APPL,GOOG",
},
},
],
},
},
]
How to query
Once the build is done, the following node types will be available in your GraphQL queries (depending on which queries were made)
- stockHistoricalData
- stockBalanceSheet
- marketMovers
- marketCharts
You can query generated nodes like the following:
{
allStockHistoricalData {
edges {
node {
prices {
close
open
date
}
}
}
}
}