Skip to main content

Fetch live and historical stock prices for Indian and American exchanges.

Project description

jyapystock

A Python library to fetch live and historical prices for Indian and American stocks.

Badges (overall + provider status):

CI

yfinance tests Alpha Vantage tests NASDAQ tests

Features

  • Live price and historical price support
  • Indian (NSE/BSE) and American (NYSE/NASDAQ) stocks
  • Multiple data sources: yfinance (default), Alpha Vantage (optional)
  • Multiple data sources: yfinance, Alpha Vantage (optional)
  • Auto-fallback: if source is not provided (or set to None or 'auto'), the provider will try available free sources in order: yfinance first, then Alpha Vantage if an API key is available.
  • Auto-fallback: if source is not provided (or set to None or 'auto'), the provider will try available free sources in order: yfinance first, then Alpha Vantage if an API key is available.
  • Country: StockPriceProvider now requires a country argument. Supported values: India, USA.
    • For India, when using yfinance the provider will try symbol variants in this order when the symbol has no exchange suffix: SYMBOL.NS, SYMBOL.BO, then SYMBOL.

Installation

pip install -r requirements.txt

Installing as a library (recommended)

This project is intended to be used as a Python library. To install locally (editable/development):

# install editable for development
pip install -e .

# or install for local use
pip install .

For development and CI reproducibility, install pinned dev dependencies:

pip install -r requirements-dev.txt

Usage

from jyapystock.stock_price_provider import StockPriceProvider
provider = StockPriceProvider(country="USA", source="yfinance")
hist = provider.get_historical_price("AAPL", "2023-01-01", "2023-01-31")
from jyapystock.stock_price_provider import StockPriceProvider
provider = StockPriceProvider(country="India", source="yfinance")
price_in = provider.get_live_price("RELIANCE")
hist = provider.get_historical_price("RELIANCE", "2023-01-01", "2023-01-31")
# Using Alpha Vantage (requires API key)
# Auto mode (recommended): omit `source` or set `source=None` / `source='auto'`.
provider_av = StockPriceProvider(country="USA", source="alphavantage", alpha_vantage_api_key="YOUR_API_KEY")
price_av = provider_av.get_live_price("AAPL")
hist_av = provider_av.get_historical_price("AAPL", "2023-01-01", "2023-01-31")

Note: start and end parameters accepted by get_historical_price may be either string dates (e.g. "2023-01-01") or datetime objects. All providers normalize these inputs internally.

Supported Sources

  • yfinance: Free, supports most global stocks
  • Alpha Vantage: Free tier, requires API key, supports global stocks
  • Polygon.io, IEX Cloud: Paid, US stocks (not implemented yet)

Testing

python -m unittest discover tests

License

MIT

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

jyapystock-0.1.0.tar.gz (9.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

jyapystock-0.1.0-py3-none-any.whl (8.8 kB view details)

Uploaded Python 3

File details

Details for the file jyapystock-0.1.0.tar.gz.

File metadata

  • Download URL: jyapystock-0.1.0.tar.gz
  • Upload date:
  • Size: 9.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.4

File hashes

Hashes for jyapystock-0.1.0.tar.gz
Algorithm Hash digest
SHA256 18f9a6ba2ad6161dc40a52c1254564e2fa841824a37b6313effd12f309c0994e
MD5 9befb60b8011c90174cc4cfe6f20debf
BLAKE2b-256 968ed01e9160b662f4eb745088d162b5023cead5ffbaaaf4560f1e9a687f388c

See more details on using hashes here.

File details

Details for the file jyapystock-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: jyapystock-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 8.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.4

File hashes

Hashes for jyapystock-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 9014fd24d719bf8f5747abdc7c6fec9f1dc8c40ad13a653f4cebc708f3b7bb6a
MD5 ef4f254bc67f8491330f43ea2fa4732f
BLAKE2b-256 bc1cda60414e1eb57748206a6c85a9cd3b2f9fe11dd35987eb611a94154d4830

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