Skip to main content

Python module to get stock data from Yahoo! Finance

Project description

Python module to get stock data from Yahoo! Finance

Install

From PyPI with pip:

$ pip install yahoo-finance

From development repo (requires git)

$ git clone git://github.com/lukaszbanasiak/yahoo-finance.git
$ cd yahoo-finance
$ python setup.py install

Usage examples

Get shares data

Example: Yahoo! Inc. (YHOO)

>>> from yahoo_finance import Share
>>> yahoo = Share('YHOO')
>>> print yahoo.get_open()
'36.60'
>>> print yahoo.get_price()
'36.84'
>>> print yahoo.get_trade_datetime()
'2014-02-05 20:50:00 UTC+0000'

Refresh data from market

>>> yahoo.refresh()
>>> print yahoo.get_price()
'36.87'
>>> print yahoo.get_trade_datetime()
'2014-02-05 21:00:00 UTC+0000'

Historical data

>>> print yahoo.get_historical('2014-04-25', '2014-04-29')
[{u'Volume': u'28720000', u'Symbol': u'YHOO', u'Adj_Close': u'35.83', u'High': u'35.89', u'Low': u'34.12', u'Date': u'2014-04-29', u'Close': u'35.83', u'Open': u'34.37'}, {u'Volume': u'30422000', u'Symbol': u'YHOO', u'Adj_Close': u'33.99', u'High': u'35.00', u'Low': u'33.65', u'Date': u'2014-04-28', u'Close': u'33.99', u'Open': u'34.67'}, {u'Volume': u'19391100', u'Symbol': u'YHOO', u'Adj_Close': u'34.48', u'High': u'35.10', u'Low': u'34.29', u'Date': u'2014-04-25', u'Close': u'34.48', u'Open': u'35.03'}]

More readable output :)

>>> from pprint import pprint
>>> pprint(yahoo.get_historical('2014-04-25', '2014-04-29'))
[{u'Adj_Close': u'35.83',
  u'Close': u'35.83',
  u'Date': u'2014-04-29',
  u'High': u'35.89',
  u'Low': u'34.12',
  u'Open': u'34.37',
  u'Symbol': u'YHOO',
  u'Volume': u'28720000'},
 {u'Adj_Close': u'33.99',
  u'Close': u'33.99',
  u'Date': u'2014-04-28',
  u'High': u'35.00',
  u'Low': u'33.65',
  u'Open': u'34.67',
  u'Symbol': u'YHOO',
  u'Volume': u'30422000'},
 {u'Adj_Close': u'34.48',
  u'Close': u'34.48',
  u'Date': u'2014-04-25',
  u'High': u'35.10',
  u'Low': u'34.29',
  u'Open': u'35.03',
  u'Symbol': u'YHOO',
  u'Volume': u'19391100'}]

Summary information for our example

>>> from pprint import pprint
>>> pprint(yahoo.get_info())
{u'FullTimeEmployees': u'12200',
 u'Industry': u'Internet Information Providers',
 u'Sector': u'Technology',
 u'end': u'2014-05-03',
 u'start': u'1996-04-12',
 u'symbol': u'YHOO'}

Avalible methods

  • get_price()

  • get_change()

  • get_volume()

  • get_prev_close()

  • get_open()

  • get_avg_daily_volume()

  • get_stock_exchange()

  • get_market_cap()

  • get_book_value()

  • get_ebitda()

  • get_dividend_share()

  • get_dividend_yield()

  • get_earnings_share()

  • get_days_high()

  • get_days_low()

  • get_year_high()

  • get_year_low()

  • get_50day_moving_avg()

  • get_200day_moving_avg()

  • get_price_earnings_ratio()

  • get_price_earnings_growth_ratio()

  • get_price_sales()

  • get_price_book()

  • get_short_ratio()

  • get_trade_datetime()

  • get_historical(start_date, end_date)

  • get_info()

  • refresh()

Get currency data

Example: EUR/PLN (EURPLN=X)

>>> from yahoo_finance import Currency
>>> eur_pln = Currency('EURPLN')
>>> print eur_pln.get_bid()
'4.2007'
>>> print eur_pln.get_ask()
'4.2091'
>>> print eur_pln.get_rate()
'4.2049'
>>> print eur_pln.get_trade_datetime()
'2014-03-05 11:23:00 UTC+0000'

Refresh data from market

>>> eur_pln.refresh()
>>> print eur_pln.get_rate()
'4.2052'
>>> print eur_pln.get_trade_datetime()
'2014-03-05 11:27:00 UTC+0000'

Avalible methods

  • get_bid()

  • get_ask()

  • get_rate()

  • get_trade_datetime()

  • refresh()

Requirements

See requirements.txt

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

yahoo-finance-1.1.4.zip (12.2 kB view details)

Uploaded Source

File details

Details for the file yahoo-finance-1.1.4.zip.

File metadata

  • Download URL: yahoo-finance-1.1.4.zip
  • Upload date:
  • Size: 12.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for yahoo-finance-1.1.4.zip
Algorithm Hash digest
SHA256 c2f1ca516fa67a9fa50e960f98aa7a253d40b5fde6cdf2532194cbaefa4fcccb
MD5 1778c7078789a528751e45ca4e2b39ed
BLAKE2b-256 9e9b77799f9f4fa9578e5a6f52e8cfad7e1ae22a59dc4934d651ace4433fbc60

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page