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

share-price

v1.0.8

Published

Completely free NPM library to get realtime Stock / Share Price

Downloads

12

Readme

share-price

NPM library to get realtime Share / Stock Price from Yahoo Finance Website. This library uses axios under the hood to make HTTP Call to Yahoo Finance.

Functions

Function getSharePrice(config, callbackFunction(sharePrice, error))

This function is used to retrieve the Share Price of a given Stock Symbol. stockSymbol is a mandatory property for config parameter of getSharePrice(config, callbackFunction(sharePrice, error)) function. You must pass valid values for the 2 config properties, otherwise the library function will retun error. If you are not sure of the exact stockSymbol for a Company, you can use the getStockSymbol() function to search it. You can optionally use any of the axios request config along with stockName and exchageCode

If you are using the library behind a coporate proxy please refer axios request config properties link on how to set your proxy settings.

Returns

  • A number sharePrice decimal value or error

Example

var sharePrice = require("share-price");
//Using a Promise.
sharePrice.getSharePrice({ stockSymbol: "AAPL" }).then(function(stockPrice) {
    console.log(stockPrice);
}).catch((error) => {
    console.log(error);
});

//Using a callback function.
sharePrice.getSharePrice({ stockSymbol: "AAPL" }, function(stockPrice, error) {
    if (error) {
        console.error(error);
    } else {
        console.log(stockPrice);
    }
});

Function getStockSymbol(config, callbackFunction(stockSymbolResult, error))

This function is used to search for Stock Symbols for a given Stock Name String. stockName is a mandatory property for config parameter of getStockSymbol(config, callbackFunction(stockSymbolResult, error)) function. . You must pass valid value for the config property, otherwise the library function will retun error. Optionally you can send another config property list as boolean value true or false. When list: true is sent, the function returns an array of matching Stock Symbols along with Full Company and Stock Exchange Names. You can optionally use any of the axios request config along with stockName and exchageCode

If you are using the library behind a coporate proxy please refer axios request config properties link on how to set your proxy settings.

Returns

  • A string stockSymbolResult containing only the best matched Stock symbol name if list config is not sent as true or error
  • An array stockSymbolResult containing a list of matching Stock symbol names along with Full Company and Stock Exchange Names if list config is not sent as true or error

Example

var sharePrice = require("share-price");
//Using a Promise retrieve list.
sharePrice.getStockSymbol({ stockName: "Apple Inc", list: true }).then(function(stockSymbolResult) {
    console.log(stockSymbolResult);
}).catch((error) => {
    console.log(error);
});

//Using a callback function rerieve best match.
sharePrice.getStockSymbol({ stockName: "Apple Inc" }, function(stockSymbolResult, error) {
    if (error) {
        console.error(error);
    } else {
        console.log(stockSymbolResult);
    }
});