npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

yahoo-finance

v0.3.8

Published

Yahoo Finance historical quotes and snapshot data downloader written in Node.js

Downloads

4,400

Readme

yahoo-finance

yahoo-finance is Yahoo Finance historical quotes and snapshot data downloader written in Node.js.

The library handles fetching, parsing, and cleaning of CSV data and returns JSON result that is convenient and easy to work with. Both callback (last parameter) and promises (using Bluebird) styles are supported.

Also check out google-finance.

NB: v1 is feature frozen, v2 in beta

Please note that v1 is feature frozen. It has been stable for years, and we are no longer working on it (besides for any urgent security fixes). We have a v2 candidate in beta at https://github.com/gadicc/node-yahoo-finance2.

  • If you're just starting off, or are feeling adventurous, check out the v2 beta, which has a new API.

  • If you're an existing user, keep with the current stable version, and await official upgrade instructions. We anticipate a v2 stable release around July 2021.

Please submit feature requests only to https://github.com/gadicc/node-yahoo-finance2.

The rest of this README refers to v1 only.

Yahoo's 2017 API Change

This project is compatible with Yahoo's "new" (and internal) API from 2017-05-16. Please be aware that Yahoo stopped supporting their API for developers many years ago, so in theory this could stop working at any time and without prior notice. In practice, however, the magic of open-source has kept this project working reliably and continuously for years and years.

Regarding the package API:

  • historical() - should work as expected - please check the output and report any inconsistencies.

  • snapshot() - deprecated - returns the original format for SOME old options via a mapping layer. Since Yahoo's new API does not contain all the same data as the old version, 100% compatibility is impossible - but for the most common options, this should ease upgrade pains. When you can, transition to the new quote() API instead.

  • quote() - NEW API more faithful to Yahoo's new API. See below. This replaces snapshot() and we suggest you use it instead.

  • Note: your very first request will take a bit longer to return, as we need to first send an additional request to Yahoo to get a "crumb" that is used for all future quests.

Installation

$ npm install --save yahoo-finance

Usage

var yahooFinance = require('yahoo-finance');

yahooFinance.historical({
  symbol: 'AAPL',
  from: '2012-01-01',
  to: '2012-12-31',
  // period: 'd'  // 'd' (daily), 'w' (weekly), 'm' (monthly), 'v' (dividends only)
}, function (err, quotes) {
  //...
});

// This replaces the deprecated snapshot() API
yahooFinance.quote({
  symbol: 'AAPL',
  modules: [ 'price', 'summaryDetail' ] // see the docs for the full list
}, function (err, quotes) {
  // ...
});

API

Download Historical Data (single symbol)

yahooFinance.historical({
  symbol: SYMBOL,
  from: START_DATE,
  to: END_DATE
}, function (err, quotes) {
  /*
  [
    {
      date: Thu Nov 07 2013 00:00:00 GMT-0500 (EST),
      open: 45.1,
      high: 50.09,
      low: 44,
      close: 44.9,
      volume: 117701700,
      adjClose: 44.9,
      symbol: 'TWTR'
    },
    ...
    {
      date: Thu Nov 14 2013 00:00:00 GMT-0500 (EST),
      open: 42.34,
      high: 45.67,
      low: 42.24,
      close: 44.69,
      volume: 11090800,
      adjClose: 44.69,
      symbol: 'TWTR'
    }
  ]
  */
});

Download Historical Data (multiple symbols)

yahooFinance.historical({
  symbols: [SYMBOL1, SYMBOL2],
  from: START_DATE,
  to: END_DATE
}, function (err, result) {
  /*
  {
    YHOO: [
      {
        date: Fri Apr 12 1996 00:00:00 GMT-0400 (EDT),
        open: 25.25,
        high: 43,
        low: 24.5,
        close: 33,
        volume: 408720000,
        adjClose: 1.38,
        symbol: 'YHOO'
      },
      ...
      {
        date: Thu Nov 14 2013 00:00:00 GMT-0500 (EST),
        open: 35.07,
        high: 35.89,
        low: 34.76,
        close: 35.69,
        volume: 21368600,
        adjClose: 35.69,
        symbol: 'YHOO'
      }
    ],
    GOOGL: [
      {
        date: Thu Aug 19 2004 00:00:00 GMT-0400 (EDT),
        open: 100,
        high: 104.06,
        low: 95.96,
        close: 100.34,
        volume: 22351900,
        adjClose: 100.34,
        symbol: 'GOOGL'
      },
      ...
      {
        date: Thu Nov 14 2013 00:00:00 GMT-0500 (EST),
        open: 1033.92,
        high: 1039.75,
        low: 1030.35,
        close: 1035.23,
        volume: 1166700,
        adjClose: 1035.23,
        symbol: 'GOOGL'
      }
    ],
    ...
  }
  */
});

Specifying request options

Optionally request options (such as a proxy) can be specified by inserting an extra parameter just before the callback:

var httpRequestOptions = {
  proxy: 'http://localproxy.com'
};


yahooFinance.historical({
  symbol: SYMBOL,
  from: START_DATE,
  to: END_DATE
}, httpRequestOptions, function (err, quotes) {
  // Result
});


yahooFinance.quote({
  symbol: SYMBOL,
  modules: MODULES  // ex: ['price', 'summaryDetail']
}, httpRequestOptions, function (err, snapshot) {
  // Result
});

Credits

See the contributors.

  • Special thanks to @gadicc who brought the broken library back to life when Yahoo suddently changed their API. (check out his hero work at PR #37, #41, and #42)

License

Analytics