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.1.tar.gz (9.7 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.1-py3-none-any.whl (9.2 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: jyapystock-0.1.1.tar.gz
  • Upload date:
  • Size: 9.7 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.1.tar.gz
Algorithm Hash digest
SHA256 94e666186954dbe0cf33d91788b43c8909704aca72585157e8907773e64c35bc
MD5 2e63da2acd75a8697ba7eac0e93302b7
BLAKE2b-256 a674a525b59d268be990b9e130f950d566c4aee5a2ca990eb675944ab16bced5

See more details on using hashes here.

File details

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

File metadata

  • Download URL: jyapystock-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 9.2 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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 5de981d2b5e2f8de2fe523a2627c08d9bcbb5f804c892f4285a74cae7436efc6
MD5 e186a6e8fda4f12d8ef50cb0fbebe68c
BLAKE2b-256 d23d8ce3586a07331e7e4420fa23b6da330649a3bf040d48480bb113758d4643

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