### Setup Development Environment (Bash) Source: https://github.com/vsjha18/nsetools/blob/master/README.md Provides shell commands to set up the development environment for the nsetools library. Includes creating a virtual environment, cloning the repository, and installing dependencies in development mode. ```bash python -m venv nsetools-dev # skip this if you already have a virtual environment cd source bin/activate git clone https://github.com/vsjha18/nsetools.git cd nsetools make dev # package will be installed in dev mode and all the dependencies will be installed ``` -------------------------------- ### Install Publishing Dependencies (Python) Source: https://github.com/vsjha18/nsetools/blob/master/tests/commands.md Installs Python packages required for building and publishing the package to repositories like PyPI, including tools for packaging and uploading. ```bash pip install requests dateutils wheel twine setuptools ``` -------------------------------- ### Install nsetools Python Library Source: https://github.com/vsjha18/nsetools/blob/master/README.md Installs the nsetools library using pip, the Python package installer. This command downloads and sets up the library and its dependencies. ```bash pip install nsetools ``` -------------------------------- ### Get All Index Quotes - nsetools Python Source: https://github.com/vsjha18/nsetools/blob/master/README.md Gets quotes for all indices in a single call. Example Output: ``` [ { 'key': 'BROAD MARKET INDICES', 'index': 'NIFTY 50', 'indexSymbol': 'NIFTY 50', 'last': 22508.75, 'variation': 111.55, 'percentChange': 0.5, # ... other fields }, { 'index': 'NIFTY BANK', 'indexSymbol': 'NIFTY BANK', # ... other fields }, # ... other indices ] ``` ```python nse.get_all_index_quote() ``` -------------------------------- ### Get Stock/Index Quote in Index (Python) Source: https://github.com/vsjha18/nsetools/blob/master/README.md Demonstrates how to use `nse.get_stock_quote_in_index` to fetch quotes for stocks within a specific index, including an option to include the index quote itself. Shows example output formats for both the index quote and a stock quote. ```python >>> quotes = nse.get_stock_quote_in_index("NIFTY BANK", include_index=True) >>> quotes[0] # Index quote when include_index=True { 'priority': 1, 'symbol': 'NIFTY BANK', 'identifier': 'NIFTYBANK', 'open': 44821.3, 'dayHigh': 45065.85, 'dayLow': 44752.95, 'lastPrice': 44991.95, 'previousClose': 44745.95, 'change': 246.0, 'pChange': 0.55, 'totalTradedVolume': 0, 'totalTradedValue': 0.0, 'lastUpdateTime': '23-Mar-2024 15:30:00', 'yearHigh': 48636.65, 'yearLow': 40563.65, 'perChange365d': 9.8, 'perChange30d': 0.62 } >>> # Stock quote example (either with include_index=True or False) >>> quotes[1] if include_index else quotes[0] # First stock quote { 'priority': 0, 'symbol': 'HDFCBANK', 'identifier': 'HDFCBANKEQN', 'series': 'EQ', 'open': 1460.0, 'dayHigh': 1469.8, 'dayLow': 1451.2, 'lastPrice': 1465.9, 'previousClose': 1453.35, 'change': 12.55, 'pChange': 0.86, 'totalTradedVolume': 5841960, 'totalTradedValue': 8557023518.4, 'lastUpdateTime': '23-Mar-2024 15:30:00', 'yearHigh': 1757.8, 'yearLow': 1427.05 } ``` -------------------------------- ### Install Development Dependencies (Python) Source: https://github.com/vsjha18/nsetools/blob/master/tests/commands.md Installs necessary Python packages for developing and testing the nsetools library, including debugging tools, testing frameworks, and utility libraries. ```bash pip install ipdb ipython pytest pytest-cov requests dateutils six ``` -------------------------------- ### Build Package with New Build System (Python) Source: https://github.com/vsjha18/nsetools/blob/master/tests/commands.md Installs the 'build' package and uses the standard Python build command to create package distributions, representing a modern alternative to setup.py. ```bash pip install build python -m build ``` -------------------------------- ### Get Top Gainers & Losers - nsetools Python Source: https://github.com/vsjha18/nsetools/blob/master/README.md Gets real-time data for stocks with highest gains/losses. Arguments: - `index` (str, optional): Index name for filtering. Defaults to "NIFTY". Valid values: - "NIFTY" or "NIFTY 50" - "BANKNIFTY" or "NIFTY BANK" - "NIFTYNEXT50" or "NIFTY NEXT 50" - "SECGTR20" (Securities > ₹20) - "SECLWR20" (Securities < ₹20) - "FNO" (Futures & Options) - "ALL" (All Securities) Returns: - `list[dict]`: List of dictionaries Example Output (Gainers): ``` { 'symbol': 'DRREDDY', 'series': 'EQ', 'openPrice': 1107.9, 'highPrice': 1154.1, 'lowPrice': 1101.5, 'ltp': 1151.5, 'previousPrice': 1107.95, 'net_price': 43.55, 'tradedQuantity': 2714559, 'turnoverInLakhs': 31016.01, 'lastCorpAnnouncement': 'Annual General Meeting', 'lastCorpAnnouncementDate': '28-Jul-2024', 'perChange': 3.93 } ``` Example Output (Losers): ``` { 'symbol': 'TATAMOTORS', 'series': 'EQ', 'openPrice': 375.0, 'highPrice': 375.0, 'lowPrice': 365.2, 'ltp': 367.8, 'previousPrice': 374.35, 'net_price': -6.55, 'tradedQuantity': 3714559, 'turnoverInLakhs': 41016.01, 'perChange': -1.75 } ``` ```python nse.get_top_gainers(index="NIFTY") nse.get_top_losers(index="NIFTY") ``` -------------------------------- ### Get Future Quote (Python) Source: https://github.com/vsjha18/nsetools/blob/master/README.md Fetches futures trading data for a given stock code. Can retrieve data for all expiries or a specific expiry date. Shows examples of calling the function and the expected list or dictionary return format. ```python nse.get_future_quote(code, expiry_date=None) ``` ```python >>> nse.get_future_quote('RELIANCE') [{ 'expiryDate': '27-Mar-2025', 'lastPrice': 1246, 'premium': 4.45, 'openPrice': 1245.25, 'highPrice': 1260.85, 'lowPrice': 1236.2, 'closePrice': 1247.9, 'prevClose': 1244.8, 'change': 1.2, 'pChange': 0.10, 'numberOfContractsTraded': 257812, 'totalTurnover': 3214.56, 'openInterest': 257812, 'changeInOpenInterest': 7144, 'pchangeinOpenInterest': 2.85, 'marketLot': 500, 'dailyVolatility': 14.2, 'annualisedVolatility': 22.4 }] ``` ```python >>> # With specific expiry date >>> nse.get_future_quote('RELIANCE', expiry_date='27-Mar-2025') { # Returns single dictionary instead of list 'expiryDate': '27-Mar-2025', # ... same fields as above } ``` -------------------------------- ### Run Tests with Coverage (Bash) Source: https://github.com/vsjha18/nsetools/blob/master/tests/commands.md Navigates to the project directory and executes pytest to run the test suite, generating a coverage report. Includes an example for running a specific test module. ```bash cd $VIRTUAL_ENV/nsetools pytest --cov=nsetools --cov-report=term -v # or if are specific on a test module pytest --cov=nsetools --cov-report=term tests/test_session.py -v ``` -------------------------------- ### Get Index List - nsetools Python Source: https://github.com/vsjha18/nsetools/blob/master/README.md Gets list of all NSE index symbols. Returns: - `list[str]`: List of index symbols (e.g., ['NIFTY 50', 'NIFTY BANK', ...]) Example Output: ``` ['NIFTY 50', 'NIFTY NEXT 50', 'NIFTY 100', 'NIFTY 200', 'NIFTY MIDCAP 50', 'NIFTY BANK', 'NIFTY AUTO', 'NIFTY IT', 'NIFTY FMCG', 'NIFTY PHARMA', ...] ``` ```python nse.get_index_list() ``` -------------------------------- ### Test Local Package Build (Bash) Source: https://github.com/vsjha18/nsetools/blob/master/tests/commands.md Provides commands to uninstall existing packages in a virtual environment and install a locally built package (.whl or .tar.gz) for testing purposes. ```bash pip freeze | xargs pip uninstall -y pip install /path/to/your/package.whl OR pip install /path/to/your/package.tar.gz ``` -------------------------------- ### Get Advances & Declines - nsetools Python Source: https://github.com/vsjha18/nsetools/blob/master/README.md Gets number of advancing and declining stocks in an index. Arguments: - `index` (str, optional): Name of the index. Defaults to 'nifty 50'. Valid values include 'NIFTY 50', 'NIFTY BANK', etc. Returns: - `dict`: Dictionary containing: - `advances`: Number of advancing stocks - `declines`: Number of declining stocks Example Output: ``` {'advances': 7, 'declines': 4} ``` ```python nse.get_advances_declines(index='nifty 50') ``` -------------------------------- ### Get Stocks in Index - nsetools Python Source: https://github.com/vsjha18/nsetools/blob/master/README.md Gets list of stock symbols that are constituents of a given index. Arguments: - `index` (str, optional): Name of the NSE index. Defaults to "NIFTY 50". Returns: - `list`: List of stock symbols that are part of the specified index Example Output: ``` ['AUBANK', 'AXISBANK', 'BANDHANBNK', 'FEDERALBNK', 'HDFCBANK', 'ICICIBANK', 'IDFCFIRSTB', 'INDUSINDBK', 'KOTAKBANK', 'PNB', 'SBIN', 'YESBANK'] ``` ```python nse.get_stocks_in_index(index="NIFTY 50") ``` -------------------------------- ### Getting 52 Week High/Low Stocks with nsetools (Python) Source: https://github.com/vsjha18/nsetools/blob/master/README.md Retrieves lists of stocks that have reached their 52-week high or low prices on the NSE, providing details for each stock. ```python nse.get_52_week_high() nse.get_52_week_low() ``` ```python >>> nse.get_52_week_high() [ { 'symbol': 'AVANTIFEED', 'series': 'EQ', 'companyName': 'Avanti Feeds Limited', 'new52WHL': 899, 'prev52WHL': 849.9, 'prevHLDate': '13-Mar-2025', 'ltp': 887, 'prevClose': 842.55, 'change': 44.45, 'pChange': 5.28 }, {...} ] ``` -------------------------------- ### Get Stock Quotes in Index - nsetools Python Source: https://github.com/vsjha18/nsetools/blob/master/README.md Gets detailed real-time quotes for all stocks in a given index. Arguments: - `index` (str, optional): The name of the index. Defaults to "NIFTY 50". ```python nse.get_stock_quote_in_index(index="NIFTY 50", include_index=False) ``` -------------------------------- ### Get Index Quote - nsetools Python Source: https://github.com/vsjha18/nsetools/blob/master/README.md Retrieves detailed quote information for a given index code from NSE. Arguments: - `index` (str): The index code/symbol (e.g., "NIFTY 50", "BANKNIFTY") Returns: - `dict`: Dictionary containing index quote details Example Output: ``` { 'key': 'BROAD MARKET INDICES', 'index': 'NIFTY 50', 'indexSymbol': 'NIFTY 50', 'last': 22508.75, 'variation': 111.55, 'percentChange': 0.5, 'open': 22353.15, 'high': 22577.0, 'low': 22353.15, 'previousClose': 22397.2, 'yearHigh': 26277.35, 'yearLow': 21281.45, 'pe': 26.45, 'pb': 4.01, 'dy': 1.2, 'advances': 35, 'declines': 15, 'unchanged': 0 } ``` ```python nse.get_index_quote(index="NIFTY 50") ``` -------------------------------- ### Getting Stock Quote with nsetools (Python) Source: https://github.com/vsjha18/nsetools/blob/master/README.md Fetches detailed quote data for a specified stock symbol from NSE. The level of detail can be controlled via the 'all_data' parameter. ```python nse.get_quote(code, all_data=False) ``` ```python >>> nse.get_quote('abb') { 'lastPrice': 5189.1, 'change': 70.55, 'pChange': 1.38, 'previousClose': 5118.55, 'open': 5160, 'close': 5187.65, 'vwap': 5162.91, 'stockIndClosePrice': 0, 'lowerCP': 4606.7, 'upperCP': 5630.4, 'pPriceBand': 'No Band', 'basePrice': 5118.55, 'intraDayHighLow': {'min': 5101, 'max': 5218.45, 'value': 5189.1}, 'weekHighLow': {'min': 4890} } ``` ```python >>> nse.get_quote('abb', all_data=True) { 'priceInfo': { ... }, 'securityInfo': { ... }, 'marketDeptOrderBook': { ... }, 'tradingInfo': { ... }, 'industryInfo': { ... } } ``` -------------------------------- ### Getting Stock Codes with nsetools (Python) Source: https://github.com/vsjha18/nsetools/blob/master/README.md Retrieves a list of all stock symbols currently traded on the National Stock Exchange (NSE) of India using the nsetools library. ```python nse.get_stock_codes() ``` ```python >>> nse.get_stock_codes() ['20MICRONS', '3IINFOTECH', '3MINDIA', '3PLAND', '63MOONS'] ``` -------------------------------- ### Build Python Package (Bash) Source: https://github.com/vsjha18/nsetools/blob/master/tests/commands.md Runs the setup.py script to create source distributions (.sdist) and built distributions (.bdist_wheel) of the Python package. ```bash python setup.py sdist bdist_wheel ``` -------------------------------- ### Upload Package to PyPI (Bash) Source: https://github.com/vsjha18/nsetools/blob/master/tests/commands.md Uses twine to upload the generated package distributions from the 'dist' directory to a package index, typically PyPI, using a token for authentication. ```bash twine upload --username __token__ --password dist/* ``` -------------------------------- ### Run Tests (Bash) Source: https://github.com/vsjha18/nsetools/blob/master/README.md Provides the shell command to execute the test suite for the nsetools library using the Makefile. ```bash make test ``` -------------------------------- ### Index Quote Response Format (Python) Source: https://github.com/vsjha18/nsetools/blob/master/README.md Illustrates the typical dictionary structure returned by APIs providing index quote data, including price information, advances, and declines. ```python { 'indexSymbol': 'NIFTY 50', 'lastPrice': 19500.0, 'change': 100.0, 'pChange': 0.52, 'advances': 35, 'declines': 15, # ... other fields } ``` -------------------------------- ### Stock Quote Response Format (Python) Source: https://github.com/vsjha18/nsetools/blob/master/README.md Illustrates the typical dictionary structure returned by APIs providing stock quote data, including price information and other relevant fields. ```python { 'priceInfo': { 'lastPrice': 2500.0, 'change': 50.0, 'pChange': 2.04, 'open': 2460.0, 'high': 2520.0, 'low': 2455.0, 'close': 2450.0, # ... additional fields when all_data=True } } ``` -------------------------------- ### Initialize Nse Object in Python Source: https://github.com/vsjha18/nsetools/blob/master/README.md Imports the Nse class from the nsetools library and creates an instance of it. This object is used to access the various NSE data retrieval methods provided by the library. ```python from nsetools import Nse nse = Nse() ``` -------------------------------- ### Validating Stock Code with nsetools (Python) Source: https://github.com/vsjha18/nsetools/blob/master/README.md Checks if a given stock symbol is a valid code traded on the NSE by comparing it against the list of known valid codes. ```python nse.is_valid_code(code) ``` ```python >>> nse.is_valid_code("INFY") True ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.