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

stocksocket

v2.1.2

Published

Real-time Yahoo Stock Prices

Downloads

132

Readme

StockSocket

Real-Time Yahoo Finance Stock data.

This module opens a Websocket connection with Yahoo for reliable, fast, and lightweight market data.

npm Build Status Maintenance codecov npm

const StockSocket = require("stocksocket");

StockSocket.addTicker("TSLA", stockPriceChanged);

function stockPriceChanged(data) {
  //Choose what to do with your data as it comes in.
  console.log(data);
}

Installation

This is a Node.js module available through the npm registry.

If this is a brand new project, make sure to create a package.json first with the npm init command.

Installation is done using the npm install command:

$ npm install stocksocket

How does it work?

  • Yahoo Finance uses Websockets to transfer stock data when you open their page on your browser.
  • This module leverages that functionality by opening its own direct WebSocket connection with Yahoo (skipping the need for the browser in the process).
  • As a result, this module is far more lightweight and quick than previous versions of this module (which used Puppeteer and inefficient web-scraping).

Sample Output

Pre-Market

{
  id: 'TSLA',
  price: 610.0977172851562,
  time: '1623352065000',
  exchange: 'NMS',
  quoteType: 'EQUITY',
  marketHours: 'PRE_MARKET',
  changePercent: 1.8901244401931763,
  change: 11.31768798828125,
  priceHint: '2'
}

Regular Market (Contains Real-Time Volume Updates)

{
  id: 'TSLA',
  price: 610.0977172851562,
  time: '1623352065000',
  exchange: 'NMS',
  quoteType: 'EQUITY',
  marketHours: 'REGULAR_MARKET',
  changePercent: 1.8901244401931763,
  dayVolume: '21090676',
  change: 11.31768798828125,
  priceHint: '2'
}

Post-Market

{
  id: 'TSLA',
  price: 610.0977172851562,
  time: '1623352065000',
  exchange: 'NMS',
  quoteType: 'EQUITY',
  marketHours: 'POST_MARKET',
  changePercent: 1.8901244401931763,
  change: 11.31768798828125,
  priceHint: '2'
}

Cryptocurrencies

{
  id: 'ETH-USD',
  price: 2465.013916015625,
  time: '1623352142000',
  currency: 'USD',
  exchange: 'CCC',
  quoteType: 'CRYPTOCURRENCY',
  marketHours: 'REGULAR_MARKET',
  changePercent: -4.241476535797119,
  dayVolume: '29413464064',
  dayHigh: 2615.832763671875,
  dayLow: 2463.379150390625,
  change: -109.18408203125,
  shortName: 'Ethereum USD',
  lastSize: '29413464064',
  priceHint: '2',
  vol_24hr: '29413464064',
  volAllCurrencies: '29413464064',
  fromcurrency: 'ETH',
  lastMarket: 'CoinMarketCap',
  circulatingSupply: 116236768,
  marketcap: 286525260000
}

Docs


addTicker(stockticker, callback)

Start data stream for a specific ticker

var stockticker = "TSLA";

StockSocket.addTicker(stockticker, stockPriceChanged);

function stockPriceChanged(data) {
  console.log(data);
}

stockticker (type: String)

String object containing a stock ticker to be added.

callback (type: Function)

Callback Function that receives each price update


addTickers([stocktickers], callback)

Start data stream for an array of tickers

var stocktickers = ["TSLA", "NNDM", "AAPL", "MARA"];

StockSocket.addTickers(stocktickers, stockPriceChanged);

function stockPriceChanged(data) {
  console.log(data);
}

stocktickers (type: Array)

Array of string objects containing the stock tickers

callback (type: Function)

Callback Function that receives each price update


removeTicker(stockticker)

Stop data stream for a specific ticker.

var stockticker = "TSLA";

StockSocket.removeTicker(stockticker);

stockticker (type: String)

String object containing a stock ticker to be added.


removeTickers([stocktickers])

Stop data stream for various tickers

var stocktickers = ["TSLA", "NNDM", "AAPL", "MARA"];

StockSocket.removeTickers(stocktickers);

stocktickers (type: Array)

Array of string objects containing the stock tickers to be removed.


removeAllTickers()

Stop data stream for all tickers

StockSocket.removeAllTickers();

License

MIT