Created
May 4, 2020 20:20
-
-
Save brotsky/0deb6189c35d6ebf9db7a3a7b5f28af9 to your computer and use it in GitHub Desktop.
Intraday Endpoint
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { NowRequest, NowResponse } from '@now/node' | |
import fetch from 'node-fetch' | |
import isNil from 'lodash/isNil' | |
const apiUrl = process.env.ALPHA_VANTAGE_API_URL | |
const apiKey = process.env.ALPHA_VANTAGE_API_KEY | |
const interval = process.env.ALPHA_VANTAGE_TIME_SERIES_INTERVAL | |
const apiFunction = 'TIME_SERIES_INTRADAY' | |
const apiOutputSize = 'full' | |
export default async (req: NowRequest, res: NowResponse) => { | |
const { symbol } = req.query | |
if (isNil(symbol)) res.status(400).send('Error: Missing "symbol" parameter') | |
const url = `${apiUrl}/query?function=${apiFunction}&symbol=${symbol}&apikey=${apiKey}&interval=${interval}&outputsize=${apiOutputSize}`; | |
const data = await fetch(url) | |
.then(response => response.json()); | |
res.json(data) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment