Neolithic Programming Machine
    Have ideas to improve npm?Join in the discussion! »

    stocksocket

    2.1.0 • Public • Published

    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 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

    Regular Market (Contains Real-Time Volume Updates)

    Post-Market

    Cryptocurrencies

    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

    Install

    npm i stocksocket

    DownloadsWeekly Downloads

    45

    Version

    2.1.0

    License

    ISC

    Unpacked Size

    54.2 kB

    Total Files

    7

    Last publish

    Collaborators

    • avatar