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);
setInterval(() => {
console.log('Updated value:', sp500.getMostRecent().value);
console.log('Updated at:', sp500.getMostRecent().timestamp);
}, 30 * 1000);
sp500.stopPolling();