sp500

Fetches the current S&P 500 price from Yahoo Finance API.


License
MIT
Install
npm install sp500@1.0.5

Documentation

sp500

This npm module provides a simple interface to fetch the current price of the S&P500 from the Yahoo Finance API.

It's used by my Inflation Calculator website, in particular the section on Real S&P return.

Install

npm install sp500

Usage

Basic usage via fetch:

const sp500 = require('sp500');
sp500.fetch((err, result) => {
  console.log('Current value is:', result);
});

Constant updates via getMostRecent:

sp500.startPolling(30 * 1000);   // Update every 30 seconds.
// sp500.startPolling();         // Defaults to updating once every 5 min.

// Elsewhere in your app...
setInterval(() => {
  console.log('Updated value:', sp500.getMostRecent().value);    // A Number
  console.log('Updated at:', sp500.getMostRecent().timestamp);   // A JS Date object
}, 30 * 1000);

// Eventually
sp500.stopPolling();