NIFTY Open Interest

Overview

This python code fetches and visualizes Open Interest (OI) profile for NIFTY options, helping traders identify support and resistance levels based on options market data.

Features

  • Real-time OI data for Call and Put options

  • Automatic ATM strike calculation

  • Batch processing with rate limiting

  • Interactive Plotly visualization

  • Error handling with retry logic

Full Python Code

Full Code Explaination

Configuration

Environment Variables

Parameters

Code Structure

1. ATM Strike Calculation

Fetches current NIFTY spot price and rounds to nearest strike.

2. Symbol Parsing

Extracts strike price and option type from symbol string.

3. Quote Fetching

Fetches quote data with retry logic for rate limits and timeouts.

4. Batch Data Collection

Processes symbols in batches to respect API rate limits.

5. Visualization

Creates interactive bar chart with hover details.

Usage

In Jupyter Notebook

As Python Script

Output

The script generates:

  • Interactive Plotly chart

  • Green bars for Call OI

  • Red bars for Put OI

  • Gray dashed line for ATM strike

  • Hover tooltips showing OI and LTP values

Error Handling

  • 429 errors: Automatic retry with backoff

  • Timeout errors: Retry with MAX_RETRIES limit

  • Invalid symbols: Skipped with warning

  • API failures: Graceful degradation

Data Structure

Output DataFrame contains:

  • strike: Strike price

  • type: Option type (CE/PE)

  • oi: Open Interest

  • ltp: Last Traded Price

Last updated

Was this helpful?