Skip to main content

Yet another unofficial Yahoo Finance API, but with concurrent requests

Project description

Pyhoo

Code style: black Checked with mypy Build Status

Yet another unofficial Yahoo Finance API library but with concurrent requests.

Pyhoo is simple:

import pyhoo

tickers = ['FB', 'AAPL', 'AMZN', 'GOOGL']
start = '2020-02-01'
end = '2020-11-02'

stock_prices = pyhoo.get('chart', tickers, start=start, end=end, granularity="1d")
financial_reports = pyhoo.get('fundamentals', tickers, start=start, end=end)
options = pyhoo.get('options', tickers, strikeMax=400.0)

The result of pyhoo.get is a formatted pandas.DataFrame (here for stock prices):

timestamp high low volume open close adjclose currency symbol exchangeName instrumentType regularMarketPrice ...
0 1580481000 208.69 201.06 31359900 208.43 201.91 201.91 USD FB NMS EQUITY 286.95 ...
1 1580740200 205.14 202.5 15510500 203.44 204.19 204.19 USD FB NMS EQUITY 286.95 ...
2 1580826600 210.6 205.2 19628900 206.62 209.83 209.83 USD FB NMS EQUITY 286.95 ...
3 1580913000 212.73 208.71 12538200 212.51 210.11 210.11 USD FB NMS EQUITY 286.95 ...
4 1580999400 211.19 209.34 10567500 210.47 210.85 210.85 USD FB NMS EQUITY 286.95 ...
5 ... ... ... ... ... ... ... ... ... ... ... ... ...

Pyhoo is fast, it uses concurrency to fire multiple requests at the same time. You can request all the tickers of the S&P500 in one shot.

Pyhoo is still in development, feel free to add more endpoints thanks to the Config object !

Currently, it supports three endpoints:

  1. chart, for OHLC data, basically stock prices
  2. fundamentals, for financial data about the firm, see the list of available reports
  3. options, for detailed information on each call and put at each strike on specific tickers

Troubleshooting

If running from a Jupyter Notebook, you may encounter the following error:

RuntimeError: asyncio.run() cannot be called from a running event loop

This is because Jupyter Notebooks are running themselves in an event loop, and it is a known issue with asyncio.run.

There is a workaround, a bit hacky but gets the job done, using nest_asyncio.

pip install nest_asyncio

Then in the Notebook, before calling pyhoo.get:

import nest_asyncio
nest_asyncio.apply()

And you should be ok !

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

pyhoo-0.1.1.tar.gz (14.8 kB view details)

Uploaded Source

Built Distribution

pyhoo-0.1.1-py3-none-any.whl (18.5 kB view details)

Uploaded Python 3

File details

Details for the file pyhoo-0.1.1.tar.gz.

File metadata

  • Download URL: pyhoo-0.1.1.tar.gz
  • Upload date:
  • Size: 14.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.4 CPython/3.8.5 Linux/4.15.0-122-generic

File hashes

Hashes for pyhoo-0.1.1.tar.gz
Algorithm Hash digest
SHA256 a629a6628dc801aeb614d7213b28ca02875c9b82f45995785b72834d579e577b
MD5 7a94a1f4175790d7e19aa38e19d64341
BLAKE2b-256 86f7c3de418cc2d9eb2df5fd4b95f0a34881da50e42481a2a048b4f0a04d0ed5

See more details on using hashes here.

File details

Details for the file pyhoo-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: pyhoo-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 18.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.4 CPython/3.8.5 Linux/4.15.0-122-generic

File hashes

Hashes for pyhoo-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 078b4fa48d78b357bc5cee4993d665ef4122a87c5065170b2f7d0cbd436e898f
MD5 c18f57c2751db0dad837e174eeb6749d
BLAKE2b-256 74aff6366bcd96e0443dc95f572acd4e4c78acce469ae5f4a977f1a644fa78db

See more details on using hashes here.

Supported by

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