A comprehensive Python-based GUI application for real-time options trading analysis, specifically designed for Indian stock market indices (NIFTY and BANKNIFTY). This application provides live options chain data with advanced Open Interest (OI) analysis using Zerodha's KiteConnect API.
- Real-time Options Chain Display: Live options data for NIFTY 50 and BANKNIFTY indices
- Open Interest Analysis: Advanced OI tracking with change indicators
- Multi-timeframe Support: 5min, 10min, 15min, 30min, 60min, and daily charts
- Visual OI Indicators: Color-coded display based on OI changes
- Historical Data Integration: 7-day historical data for trend analysis
- Auto-expiry Detection: Automatic calculation of option expiry dates
- Interactive GUI: Built with tkinter for cross-platform compatibility
- Scrollable Options Chain: Handle large number of strike prices
- Color-coded Analysis:
- π’ Green: High OI increase (>500,000)
- π΄ Red: OI decrease
- π Orange: Moderate changes
- Real-time Updates: Live market data refresh
# Install from requirements file
pip install -r requirements.txt
# Or install manually:
pip install kiteconnect>=4.0.0
pip install python-dateutil>=2.8.0
# Note: tkinter and sqlite3 are usually included with Python
- Zerodha Kite API Account: You need an active Zerodha trading account
- API Key & Secret: Obtain from Zerodha Developer Console
- Request Token: Generated during authentication process
- Login to Kite Connect Developer Console
- Create a new app and get your
api_key
andapi_secret
- Update the following lines in
API.PY
:kite=KiteConnect(api_key="YOUR_API_KEY_HERE") data=kite.generate_session(request_token,api_secret="YOUR_API_SECRET_HERE")
# Install required packages
pip install -r requirements.txt
cd "TRADING list"
python API.PY
The application interface consists of several key areas:
-
Top Control Panel:
- Connection Status: Red "NOT CONNECTED" button (changes to green "CONNECTED")
- Index Selector: Dropdown to choose between NIFTY and BANKNIFTY
- Expiry Selector: Dropdown with available expiry dates
- Timeframe Selector: Choose from 5min to daily intervals
- Option Chain Button: Generate the options chain display
-
Options Chain Display:
[CE_OI] [LTP] [CHANGE] [STRIKE] [LTP] [CHANGE] [PE_OI]
- Left Side (CE): Call options data
- Center (STRIKE): Strike prices with current price highlighted
- Right Side (PE): Put options data
-
Color Coding System:
- Spring Green: Current market price strike
- Pale Green: High positive OI change (>500K)
- Red: Negative OI change
- Orange/Tomato: Moderate OI changes
- Click "NOT CONNECTED" button
- Popup window appears requesting Kite token
- Enter your request token and click "SUBMIT"
- Button updates to show "CONNECTED" status
- Expiry dates populate automatically
-
Authentication Process
- Click "NOT CONNECTED" button
- Enter your Kite request token
- Application authenticates and fetches available expiries
- Button changes to "CONNECTED" (green)
-
Options Chain Setup
- Select index: NIFTY or BANKNIFTY
- Choose expiry date from dropdown
- Select timeframe for analysis
- Click "OPTION CHAIN" to generate data
-
Data Display Structure
CE_OI | LTP | CHANGE | STRIKE | LTP | CHANGE | PE_OI
- CE: Call Options (Left side)
- PE: Put Options (Right side)
- OI: Open Interest values
- LTP: Last Traded Price
- CHANGE: OI change from previous period
-
Main GUI Window (
root
)- 700x550 pixel window with black background
- Uses winnative theme for professional appearance
-
Authentication System (
connectZerodha()
)- Popup window for token entry
- Session generation with Kite API
- Access token management
-
Expiry Calculation (
expiry()
)- Fetches current market price
- Rounds to nearest 100 (BANKNIFTY) or 50 (NIFTY)
- Calculates available expiry dates (30-day scan)
-
Options Chain Generation (
optionChain()
)- Creates scrollable frame with strike prices
- Fetches 20 strikes around current market price
- Displays Call and Put options symmetrically
-
Open Interest Analysis (
oi_data()
)- Fetches 7-day historical data
- Calculates OI changes
- Applies color coding based on significance
- Multi-threading: Separate threads for OI data fetching
- Batch API Calls: Multiple instruments fetched in single request
- Efficient UI Updates: Direct widget manipulation
if (oi_change > 500000):
color = "palegreen" # Significant bullish/bearish activity
elif (oi_change < 0):
color = "red" # Decreasing interest
else:
color = "tomato1" # Moderate activity
-
Initial Setup
- Launch the application
- Click "NOT CONNECTED" button
- Enter your Kite request token
- Wait for "CONNECTED" status
-
Market Analysis
- Select NIFTY or BANKNIFTY from dropdown
- Choose desired expiry date
- Select analysis timeframe
- Click "OPTION CHAIN"
-
Reading the Data
- Green Strikes: High activity zones (>500K OI change)
- Red Strikes: Reducing interest
- Current Price: Highlighted in springgreen
- Strike Price: Center column shows exercise prices
-
Interpretation Tips
- High Call OI: Potential resistance level
- High Put OI: Potential support level
- OI changes: Direction of market sentiment
The application uses threading for:
- Non-blocking UI updates
- Parallel data fetching
- Improved response times
- API connection failures
- Invalid token management
- Market data unavailability
- Date calculation edge cases
-
"Module not found" errors
# Install all dependencies pip install -r requirements.txt # For tkinter on Ubuntu/Debian sudo apt-get install python3-tk
-
Authentication failures
- Verify API key and secret are correct
- Check if request token is fresh (expires quickly)
- Ensure Zerodha account has API access enabled
-
No data showing
- Check market hours (9:15 AM - 3:30 PM IST)
- Verify network connectivity
- Check Zerodha API status
-
GUI not responsive
- Close and restart application
- Check system resources
- Verify threading is working properly
Run the validation script to check setup:
python validate.py
- Application works during NSE trading hours (9:15 AM - 3:30 PM IST)
- After-hours data may be limited or delayed
- Zerodha API has rate limits (3 requests/second)
- Application includes appropriate delays
- Real-time data subject to exchange delays
- OI data updates every few minutes during market hours
- GUI Framework: tkinter (cross-platform)
- API Client: kiteconnect (Zerodha official)
- Date Handling: datetime, dateutil
- Threading: Python threading module
- Data Storage: sqlite3 (for future enhancements)
Trading-with-python/
βββ README.md
βββ TRADING list/
βββ API.PY # Main application file
connectZerodha()
: API authenticationexpiry()
: Expiry date calculationoptionChain()
: Main options chain displayoi_data()
: Open Interest analysisstartThread()
: Threading management
This application is for educational and analysis purposes only. Always:
- Verify data accuracy before trading decisions
- Understand market risks
- Consult financial advisors for investment decisions
- Test thoroughly in paper trading before live use
This project is provided as-is for educational purposes. Users are responsible for their own trading decisions and API usage compliance.
Feel free to submit issues, fork the repository, and create pull requests for improvements.
Note: Ensure you have proper API credentials and understand the associated costs before using this application for live trading analysis.