Skip to content

Simple Stocks Fetching API made with Node.js and Express.js

Notifications You must be signed in to change notification settings

Ignacio1996/stocks-simple-api

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

25 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Simple Stocks API made with Node.js

Node.js API to get updated stocks data. Limited to 5 requests per minute. Working with the Alphavantage API free version.

Very limited functionality for now

If you get CORS issues, just plug in https://cors-anywhere.herokuapp.com/ before the fetch url

const request = await fetch('https://cors-anywhere.herokuapp.com/https://stocksapi.herokuapp.com/stock' ... // code below

Sample single stock request with Javascript fetch:

const getStock = async ticker =>{
  console.log("Getting data");
  const request = await fetch('https://stocksapi.herokuapp.com/stock',{
    method: 'POST',
    headers: {
      'Content-Type': 'application/json'
    },

    body: JSON.stringify({
      'ticker': ticker,
      'type': 'daily'
    })
  })

  const data = await request.json()
  console.log(data);
  return data;
}

getStock('AAPL');

Sample multiple stocks request (with cors-anywhere to avoid CORS issues):

const getStocks = async tickersArray=>{
  console.log("Getting data");
  const request = await fetch('https://cors-anywhere.herokuapp.com/https://stocksapi.herokuapp.com/stocks',{
    method: 'POST', 
    headers: {
      'Content-Type': 'application/json'
      // 'Content-Type': 'application/x-www-form-urlencoded',
    },
    body: JSON.stringify({
      'tickers': tickersArray,
      'type': 'monthly'
    })
  })

  const data = await request.json()
  console.log(data);
  return data;
}

getStocks(['AAPL', 'MSFT', 'DIA']);

body params

types: 'monthly' 'daily'

ticker: 'any-ticker' //example 'AAPL' tickers: ['multiple', 'tickers', 'array']

About

Simple Stocks Fetching API made with Node.js and Express.js

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published