A lean and modern python library to fetch data from NSE
Project description
aynse
aynse is a lean, modern python library for fetching data from the national stock exchange (NSE) of india. it is a fork of the unmaintained jugaad-data library, aiming to provide a robust and regularly updated tool for financial data analysis.
features
- historical data: fetch historical stock and index data.
- derivatives data: download futures and options data.
- bhavcopy: download daily bhavcopy reports for equity, f&o, and indices.
- bulk deals: download bulk deals data for date ranges.
- live market data: get real-time stock quotes.
- bulk options analysis: concurrent fetching of option chains for multiple stocks.
- earnings analysis: specialized tools for analyzing options around earnings dates.
- holiday information: retrieve a list of trading holidays for a given year.
- command-line interface: a simple cli for quick data downloads.
- pandas integration: returns data as pandas dataframes for easy analysis.
etymology / musings
aynse is a portmanteau of "ayn" from miss ayn rand and "nse" from national stock exchange. ayn rand was a russian-american writer and philosopher known for her philosophy of objectivism, which emphasizes individualism and rational self-interest and among other things, she was a strong advocate for laissez-faire capitalism. the name serves as a fun ironical reminder of the library's purpose: to provide a tool for individuals to access and analyze financial data independently, without relying on large institutions or complex systems. in a cruel twist of fate, this open source library wouldn't be encouraged under ayn rand's philosophy, as she discouraged altruism and believed in the pursuit of one's own happiness as the highest moral purpose. and as the final act of irony, we gather to use this library to analyze financial markets while generating zero (and possibly, negative) intrinsic value for humans or human kind as a whole - this is capitalism.
installation
you can install aynse directly from PyPI:
pip install aynse
usage
here are a few examples of how to use aynse to fetch data.
get historical stock data
retrieve historical data for a stock as a pandas dataframe.
from datetime import date
import pandas as pd
from aynse.nse import stock_df
# set pandas display options to view all columns
pd.set_option('display.max_rows', None)
pd.set_option('display.max_columns', None)
pd.set_option('display.width', None)
# fetch data for reliance from january 1, 2024, to january 31, 2024
df = stock_df(symbol="RELIANCE",
from_date=date(2024, 1, 1),
to_date=date(2024, 1, 31))
print(df.head())
download daily bhavcopy
download the daily bhavcopy for a specific date to a local directory.
from datetime import date
from aynse.nse import bhavcopy_save
# download equity bhavcopy for july 26, 2024, into the "tmp" directory
bhavcopy_save(date(2024, 7, 26), "tmp")
get live stock quote
fetch live price information for a stock.
from aynse.nse import NSELive
n = NSELive()
quote = n.stock_quote("INFY")
print(quote['priceInfo'])
get trading holidays
get the list of trading holidays for a specific year.
from aynse.holidays import holidays
# get trading holidays for the year 2024
trading_holidays = holidays(2024)
print(trading_holidays)
download bulk deals
download bulk deals data for a date range.
from datetime import date
from aynse.nse import bulk_deals_raw, bulk_deals_save
# download bulk deals data as json for a date range
bulk_data = bulk_deals_raw(from_date=date(2024, 7, 1),
to_date=date(2024, 7, 31))
print(bulk_data['data'])
# save bulk deals data to a json file
bulk_deals_save(from_date=date(2024, 7, 1),
to_date=date(2024, 7, 31),
dest="tmp")
bulk options analysis
analyze option chains for multiple stocks concurrently.
from aynse.nse import NSELive
n = NSELive()
# fetch option chains for multiple stocks at once
symbols = ['RELIANCE', 'TCS', 'HDFCBANK']
bulk_options = n.bulk_equities_option_chain(symbols, max_workers=3)
for symbol in bulk_options['success']:
print(f"{symbol}: {len(bulk_options['success'][symbol]['records']['data'])} contracts")
earnings options analysis
analyze options around earnings dates for investment insights.
from datetime import date
from aynse.nse import NSELive
n = NSELive()
# analyze options around a specific date (e.g., earnings)
earnings_analysis = n.get_options_around_date('RELIANCE',
target_date=date(2024, 1, 19),
days_before=5,
days_after=5)
print(f"Relevant expiries: {earnings_analysis['relevant_expiries']}")
# bulk analyze multiple stocks and their earnings dates
symbols_and_dates = [
('RELIANCE', date(2024, 1, 19)),
('TCS', date(2024, 1, 11)),
('HDFCBANK', date(2024, 1, 20))
]
earnings_bulk = n.analyze_earnings_options(symbols_and_dates, max_workers=3)
command-line interface
aynse also comes with a simple command-line tool for quick downloads.
download today's bhavcopy:
aynse bhavcopy -d /path/to/your/directory
download bhavcopy for a specific date range:
aynse bhavcopy -d /path/to/your/directory -f 2024-01-01 -t 2024-01-31
download historical stock data:
aynse stock --symbol RELIANCE -f 2024-01-01 -t 2024-01-31 -o reliance_data.csv
contributing
contributions are welcome! if you find a bug or have a feature request, please open an issue on the github repository.
license
this project has a (custom) MIT* license but extends limitations. if you're a agency/corporate with >2 employees alongside of you, you cannot wrap this project or use it without prior written permission from me. if you're an individual, you can use it freely for personal projects. this project is not intended for commercial use without prior permission. if caught using this project in violation of the license, it may result in automated reporting and/or legal action. please see the license file for more details.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file aynse-1.0.2.tar.gz.
File metadata
- Download URL: aynse-1.0.2.tar.gz
- Upload date:
- Size: 43.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.10.18
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c862d23960427d3f0d92240274d51ffe4484bfc236cf2aa780955510b12470e1
|
|
| MD5 |
880a73f92a600598202ddcd5714d8c0d
|
|
| BLAKE2b-256 |
65abfd9632dfaa8a235e1a92d69ff8fce78f53ec3c5e5c853ed9d968746b25e5
|
File details
Details for the file aynse-1.0.2-py3-none-any.whl.
File metadata
- Download URL: aynse-1.0.2-py3-none-any.whl
- Upload date:
- Size: 27.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.10.18
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
78dcfb36068542c385d048040a61d78f6f7ef865928b2e72a48228511ce03b7c
|
|
| MD5 |
235b2e843cee8cd924b4e22ab5a4ace8
|
|
| BLAKE2b-256 |
b2405cbea3a7d261e3b7fa58a90e27e597e191e45db3bdbcaa12a4d0b915d9c1
|