Skip to content

Instantly share code, notes, and snippets.

@brotsky
Created May 4, 2020 20:20
Show Gist options
  • Save brotsky/0deb6189c35d6ebf9db7a3a7b5f28af9 to your computer and use it in GitHub Desktop.
Save brotsky/0deb6189c35d6ebf9db7a3a7b5f28af9 to your computer and use it in GitHub Desktop.
Intraday Endpoint
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