Coder Social home page Coder Social logo

phamleduy04 / yahoo-stock-api Goto Github PK

View Code? Open in Web Editor NEW
35.0 4.0 14.0 214 KB

๐Ÿ’ฐ NPM package to get stock and historical price from finance.yahoo.com

Home Page: https://www.npmjs.com/package/yahoo-stock-api

License: MIT License

TypeScript 100.00%
nodejs npm yahoo-finance scraper cheerio stock-prices hacktoberfest

yahoo-stock-api's Introduction

yahoo-stock-api

๐Ÿ’ฐ NPM package to get stock and historical price from finance.yahoo.com

โš ๏ธ Breaking changes โš ๏ธ

v2.0.0 of this package have breaking changes and can affect your code, please review it and change according to the documentation below!

GitHub top language GitHub package.json version GitHub last commit GitHub issues GitHub Travis (.org) Node.js CI Code quality npm bundle size Snyk Vulnerabilities for npm package ![Visits Badge

Installaion

npm i yahoo-stock-api or yarn add yahoo-stock-api if you use yarn.

API

Everything in this API will return Promise so remember to use async/await or callback

getHistoricalPrices: async function({ startDate, endDate, symbol, frequency })

  • startDate: Date
  • endDate: Date
  • symbol: String (stock symbol)
  • frequency: String ('1d', '1wk' or '1mo' only)
    • 1d: 1day
    • 1wk: 1 week
    • 1mo: 1 month

Return Promise

Example

Code

const yahooStockAPI = require('yahoo-stock-api').default;

const yahoo = new yahooStockAPI();

const startDate = new Date('08/21/2020');
const endDate = new Date('08/26/2020');
yahoo.getHistoricalPrices({ startDate, endDate, symbol: 'AAPL', frequency: '1d' }).then(console.log);

Response

{
error: false,
currency: 'USD',
response: [
  {
    date: 1598418000,
    open: 126.18,
    high: 126.99,
    low: 125.08,
    close: 126.52,
    adjClose: 124.81,
    volume: 163022400
  },
  {
    date: 1598331600,
    open: 124.7,
    high: 125.18,
    low: 123.05,
    close: 124.82,
    adjClose: 123.13,
    volume: 211495600
  },
  {
    date: 1598245200,
    open: 128.7,
    high: 128.79,
    low: 123.94,
    close: 125.86,
    adjClose: 124.15,
    volume: 345937600
  },
  {
    date: 1597986000,
    open: 119.26,
    high: 124.87,
    low: 119.25,
    close: 124.37,
    adjClose: 122.68,
    volume: 338054800
  }
]
}

getSymbol({ symbol })

  • symbol: String (stock symbol)

Return Promise

Example

Code

const yahooStockAPI = require('yahoo-stock-api').default;

const yahoo = new yahooStockAPI();

yahoo.getSymbol({ symbol: 'AAPL' }).then(console.log);

Response

{
error: false,
currency: 'USD',
response: {
  updated: 1673486286910,
  previousClose: 130.73,
  open: 131.25,
  bid: { value: 133.42, shares: 900 },
  ask: { value: 133.47, shares: 1000 },
  dayRange: { low: 130.46, high: 133.49 },
  fiftyTwoWeekRange: { low: 124.17, high: 179.61 },
  volume: 69458949,
  avgVolume: 83633004,
  marketCap: 2124000000000,
  beta: 1.27,
  peRatio: 21.85,
  eps: 6.11,
  earningsDate: { start: 1675317600, end: undefined },
  forwardDividend: 0.92,
  forwardYield: 0.71,
  exDividendDate: 1667538000,
  oneYearTargetEst: 173.25
}
}

Test

Contributors โœจ

Thanks goes to these wonderful people (emoji key):

Duy Pham Le
Duy Pham Le

๐Ÿ’ป
Rajat
Rajat

๐Ÿค”
Tommy Tang
Tommy Tang

๐Ÿ’ป ๐Ÿ›
keiichi
keiichi

๐Ÿ’ป

This project follows the all-contributors specification. Contributions of any kind welcome!

License

FOSSA Status

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.