# Option Chain Data Fetcher
A clean, interactive CLI app for fetching option chain data from Upstox API with Black-Scholes Greeks calculation.
## Features
- ✨ Interactive symbol selection with smart recognition
- 📊 Support for 180+ F&O enabled stocks
- 📈 Support for all major indices (NIFTY, BANKNIFTY, etc.)
- 📅 Automatic expiry date fetching
- 🎯 Strike price specific data filtering
- 🎨 Beautiful terminal UI with no clutter
- 📉 Displays both Call (CE) and Put (PE) options
- 📐 Shows comprehensive data: LTP, Volume, OI, Bid/Ask
- 🔬 Option Greeks: Delta, Gamma, Theta, Vega, IV
- 🔍 Built-in symbol search (type 'LIST' to see all supported symbols)
## Project Structure
```
bsholes_up/
├── src/ # Main application code
│ ├── __init__.py
│ ├── option_chain_app.py # Main application logic
│ ├── black_scholes.py # Black-Scholes calculator
│ ├── stock_mappings.py # Stock ISIN mappings
│ ├── instrument_manager.py # F&O instrument management
│ └── token_manager.py # OAuth & token management
├── web_app/ # Web application
│ ├── app.py # FastAPI backend with OAuth
│ ├── templates/
│ │ └── index.html # Frontend UI
│ └── static/
│ ├── app.js # Frontend logic
│ └── styles.css # UI styles
├── tests/ # Test files
│ ├── test_api_connection.py
│ ├── test_stock_validation.py
│ ├── test_option_chain_flow.py
│ ├── test_integration.py
│ ├── test_black_scholes.py
│ └── test_integration_bs.py
├── scripts/ # Debug and utility scripts
│ ├── debug_stock_options.py
│ ├── check_underlying.py
│ └── get_isin.py
├── run.py # CLI entry point
├── run_web.py # Web app entry point
├── requirements.txt # Python dependencies
├── .env.example # Environment variable template
└── README.md # This file
```
## Setup
1. Install dependencies:
```bash
pip install -r requirements.txt
```
2. Configure Upstox authentication:
**Option A: OAuth Login (Recommended for Web App)**
- Copy `.env.example` to `.env`
- Add your Upstox API credentials:
```
UPSTOX_CLIENT_ID=your_api_key
UPSTOX_CLIENT_SECRET=your_api_secret
UPSTOX_REDIRECT_URI=http://localhost:8000/auth/callback
```
- Get these from your Upstox Developer Console app settings
**Option B: Manual Token (CLI usage)**
- Copy `.env.example` to `.env`
- Add your access token to `.env`:
```
UPSTOX_ACCESS_TOKEN=your_access_token
```
## Usage
### CLI Application
Run the CLI app:
```bash
python run.py
```
### Web Application (with OAuth)
Run the web app:
```bash
python run_web.py
```
Then open http://localhost:8000 in your browser.
**OAuth Flow:**
1. Click "Login with Upstox" button
2. You'll be redirected to Upstox login page
3. After successful login, you'll be redirected back
4. Token is automatically managed (expires at 3:30 AM IST daily)
5. No manual token entry needed!
Follow the prompts:
1. Enter asset symbol (e.g., TCS, SBIN, NIFTY, BANKNIFTY)
- Type 'LIST' to see all supported F&O symbols
2. Select expiry date from the list
3. Enter strike price
4. View the option chain data with Greeks
## Testing
Run tests to verify everything works:
```bash
# Test API connection
python tests/test_api_connection.py
# Test stock validation
python tests/test_stock_validation.py
# Test option chain flow
python tests/test_option_chain_flow.py
# Integration tests
python tests/test_integration.py
# Test Black-Scholes calculations
python tests/test_black_scholes.py
# Test Black-Scholes integration
python tests/test_integration_bs.py
```
### Debug Scripts
```bash
# Debug stock options
python scripts/debug_stock_options.py
# Check underlying assets
python scripts/check_underlying.py
# Get ISIN for symbols
python scripts/get_isin.py
```
## Supported Symbols
### Indices
- NIFTY, BANKNIFTY, FINNIFTY, MIDCPNIFTY
### Stocks (180+ F&O enabled)
**Banking:** SBIN, HDFCBANK, ICICIBANK, AXISBANK, KOTAKBANK, and more
**IT:** TCS, INFY, WIPRO, HCLTECH, TECHM, and more
**Oil & Gas:** RELIANCE, ONGC, IOC, BPCL, and more
**Auto:** TATAMOTORS, MARUTI, M&M, BAJAJ-AUTO, and more
**Pharma:** SUNPHARMA, DRREDDY, CIPLA, DIVISLAB, and more
**FMCG:** HINDUNILVR, ITC, NESTLEIND, BRITANNIA, and more
Type 'LIST' in the app to see all supported symbols.
## Requirements
- Python 3.7+
- Upstox API access token
- Terminal with Unicode support for best display
## How It Works
The app uses ISIN (International Securities Identification Number) mappings to correctly identify F&O enabled stocks. For indices, it uses the standard index identifiers. This ensures accurate option chain data retrieval for all supported instruments.
## Deploying to Railway
1. Ensure your repository contains:
- `Procfile` with: `web: uvicorn web_app.app:app --host 0.0.0.0 --port ${PORT:-8000}`
- `.env.example` with `UPSTOX_ACCESS_TOKEN=`
- `requirements.txt` including `fastapi`, `uvicorn`, and `Jinja2`
2. On Railway:
- Create a new project and connect this repo.
- In Settings → Variables, add `UPSTOX_ACCESS_TOKEN` with your token.
- Deploy. The service will listen on `$PORT` automatically.
3. Health check: `GET /healthz` should return `{ "status": "ok" }`.
Raw data
{
"_id": null,
"home_page": "https://github.com/yourusername/theoprice",
"name": "theoprice",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.8",
"maintainer_email": null,
"keywords": "upstox, options, trading, black-scholes, greeks, indian-markets, cli",
"author": "princecodes",
"author_email": "princecodes <princecodes@duck.com>",
"download_url": "https://files.pythonhosted.org/packages/88/ef/006817d7c72067a38f8820e467578fcbb3ee573c18d03bc7bdb1a206ba3f/theoprice-0.1.1.tar.gz",
"platform": null,
"description": "# Option Chain Data Fetcher\n\nA clean, interactive CLI app for fetching option chain data from Upstox API with Black-Scholes Greeks calculation.\n\n## Features\n\n- \u2728 Interactive symbol selection with smart recognition\n- \ud83d\udcca Support for 180+ F&O enabled stocks\n- \ud83d\udcc8 Support for all major indices (NIFTY, BANKNIFTY, etc.)\n- \ud83d\udcc5 Automatic expiry date fetching\n- \ud83c\udfaf Strike price specific data filtering\n- \ud83c\udfa8 Beautiful terminal UI with no clutter\n- \ud83d\udcc9 Displays both Call (CE) and Put (PE) options\n- \ud83d\udcd0 Shows comprehensive data: LTP, Volume, OI, Bid/Ask\n- \ud83d\udd2c Option Greeks: Delta, Gamma, Theta, Vega, IV\n- \ud83d\udd0d Built-in symbol search (type 'LIST' to see all supported symbols)\n\n## Project Structure\n\n```\nbsholes_up/\n\u251c\u2500\u2500 src/ # Main application code\n\u2502 \u251c\u2500\u2500 __init__.py\n\u2502 \u251c\u2500\u2500 option_chain_app.py # Main application logic\n\u2502 \u251c\u2500\u2500 black_scholes.py # Black-Scholes calculator\n\u2502 \u251c\u2500\u2500 stock_mappings.py # Stock ISIN mappings\n\u2502 \u251c\u2500\u2500 instrument_manager.py # F&O instrument management\n\u2502 \u2514\u2500\u2500 token_manager.py # OAuth & token management\n\u251c\u2500\u2500 web_app/ # Web application\n\u2502 \u251c\u2500\u2500 app.py # FastAPI backend with OAuth\n\u2502 \u251c\u2500\u2500 templates/\n\u2502 \u2502 \u2514\u2500\u2500 index.html # Frontend UI\n\u2502 \u2514\u2500\u2500 static/\n\u2502 \u251c\u2500\u2500 app.js # Frontend logic\n\u2502 \u2514\u2500\u2500 styles.css # UI styles\n\u251c\u2500\u2500 tests/ # Test files\n\u2502 \u251c\u2500\u2500 test_api_connection.py\n\u2502 \u251c\u2500\u2500 test_stock_validation.py\n\u2502 \u251c\u2500\u2500 test_option_chain_flow.py\n\u2502 \u251c\u2500\u2500 test_integration.py\n\u2502 \u251c\u2500\u2500 test_black_scholes.py\n\u2502 \u2514\u2500\u2500 test_integration_bs.py\n\u251c\u2500\u2500 scripts/ # Debug and utility scripts\n\u2502 \u251c\u2500\u2500 debug_stock_options.py\n\u2502 \u251c\u2500\u2500 check_underlying.py\n\u2502 \u2514\u2500\u2500 get_isin.py\n\u251c\u2500\u2500 run.py # CLI entry point\n\u251c\u2500\u2500 run_web.py # Web app entry point\n\u251c\u2500\u2500 requirements.txt # Python dependencies\n\u251c\u2500\u2500 .env.example # Environment variable template\n\u2514\u2500\u2500 README.md # This file\n```\n\n## Setup\n\n1. Install dependencies:\n```bash\npip install -r requirements.txt\n```\n\n2. Configure Upstox authentication:\n\n **Option A: OAuth Login (Recommended for Web App)**\n - Copy `.env.example` to `.env`\n - Add your Upstox API credentials:\n ```\n UPSTOX_CLIENT_ID=your_api_key\n UPSTOX_CLIENT_SECRET=your_api_secret\n UPSTOX_REDIRECT_URI=http://localhost:8000/auth/callback\n ```\n - Get these from your Upstox Developer Console app settings\n \n **Option B: Manual Token (CLI usage)**\n - Copy `.env.example` to `.env`\n - Add your access token to `.env`:\n ```\n UPSTOX_ACCESS_TOKEN=your_access_token\n ```\n\n## Usage\n\n### CLI Application\nRun the CLI app:\n```bash\npython run.py\n```\n\n### Web Application (with OAuth)\nRun the web app:\n```bash\npython run_web.py\n```\nThen open http://localhost:8000 in your browser.\n\n**OAuth Flow:**\n1. Click \"Login with Upstox\" button\n2. You'll be redirected to Upstox login page\n3. After successful login, you'll be redirected back\n4. Token is automatically managed (expires at 3:30 AM IST daily)\n5. No manual token entry needed!\n\nFollow the prompts:\n1. Enter asset symbol (e.g., TCS, SBIN, NIFTY, BANKNIFTY)\n - Type 'LIST' to see all supported F&O symbols\n2. Select expiry date from the list\n3. Enter strike price\n4. View the option chain data with Greeks\n\n## Testing\n\nRun tests to verify everything works:\n```bash\n# Test API connection\npython tests/test_api_connection.py\n\n# Test stock validation\npython tests/test_stock_validation.py\n\n# Test option chain flow\npython tests/test_option_chain_flow.py\n\n# Integration tests\npython tests/test_integration.py\n\n# Test Black-Scholes calculations\npython tests/test_black_scholes.py\n\n# Test Black-Scholes integration\npython tests/test_integration_bs.py\n```\n\n### Debug Scripts\n```bash\n# Debug stock options\npython scripts/debug_stock_options.py\n\n# Check underlying assets\npython scripts/check_underlying.py\n\n# Get ISIN for symbols\npython scripts/get_isin.py\n```\n\n## Supported Symbols\n\n### Indices\n- NIFTY, BANKNIFTY, FINNIFTY, MIDCPNIFTY\n\n### Stocks (180+ F&O enabled)\n**Banking:** SBIN, HDFCBANK, ICICIBANK, AXISBANK, KOTAKBANK, and more \n**IT:** TCS, INFY, WIPRO, HCLTECH, TECHM, and more \n**Oil & Gas:** RELIANCE, ONGC, IOC, BPCL, and more \n**Auto:** TATAMOTORS, MARUTI, M&M, BAJAJ-AUTO, and more \n**Pharma:** SUNPHARMA, DRREDDY, CIPLA, DIVISLAB, and more \n**FMCG:** HINDUNILVR, ITC, NESTLEIND, BRITANNIA, and more \n\nType 'LIST' in the app to see all supported symbols.\n\n## Requirements\n\n- Python 3.7+\n- Upstox API access token\n- Terminal with Unicode support for best display\n\n## How It Works\n\nThe app uses ISIN (International Securities Identification Number) mappings to correctly identify F&O enabled stocks. For indices, it uses the standard index identifiers. This ensures accurate option chain data retrieval for all supported instruments.\n\n## Deploying to Railway\n\n1. Ensure your repository contains:\n - `Procfile` with: `web: uvicorn web_app.app:app --host 0.0.0.0 --port ${PORT:-8000}`\n - `.env.example` with `UPSTOX_ACCESS_TOKEN=`\n - `requirements.txt` including `fastapi`, `uvicorn`, and `Jinja2`\n\n2. On Railway:\n - Create a new project and connect this repo.\n - In Settings \u2192 Variables, add `UPSTOX_ACCESS_TOKEN` with your token.\n - Deploy. The service will listen on `$PORT` automatically.\n\n3. Health check: `GET /healthz` should return `{ \"status\": \"ok\" }`.\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "A Python CLI application for fetching real-time options trading data from Upstox API with Black-Scholes Greeks calculations",
"version": "0.1.1",
"project_urls": {
"Documentation": "https://github.com/yourusername/theoprice#readme",
"Homepage": "https://github.com/yourusername/theoprice",
"Issues": "https://github.com/yourusername/theoprice/issues",
"Repository": "https://github.com/yourusername/theoprice"
},
"split_keywords": [
"upstox",
" options",
" trading",
" black-scholes",
" greeks",
" indian-markets",
" cli"
],
"urls": [
{
"comment_text": null,
"digests": {
"blake2b_256": "2746ee5728064667e0d5ecd8b09c2b1182b90be40b12e99d15b7ec35c48d511f",
"md5": "195b5a13c0a6a561022ad74dbd4402dd",
"sha256": "f7294c2f9dc2602feea2c7e9a34c9c588b4bd9bdeb78ace7574e40d3ae3b058b"
},
"downloads": -1,
"filename": "theoprice-0.1.1-py3-none-any.whl",
"has_sig": false,
"md5_digest": "195b5a13c0a6a561022ad74dbd4402dd",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.8",
"size": 22507,
"upload_time": "2025-08-29T17:18:20",
"upload_time_iso_8601": "2025-08-29T17:18:20.315681Z",
"url": "https://files.pythonhosted.org/packages/27/46/ee5728064667e0d5ecd8b09c2b1182b90be40b12e99d15b7ec35c48d511f/theoprice-0.1.1-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": null,
"digests": {
"blake2b_256": "88ef006817d7c72067a38f8820e467578fcbb3ee573c18d03bc7bdb1a206ba3f",
"md5": "44503923aeb81adedd4bfbbb2407357c",
"sha256": "803f5fc3095e472c0864d62c257a2a77c5e7e8d76c649aebe38b4849b63835a7"
},
"downloads": -1,
"filename": "theoprice-0.1.1.tar.gz",
"has_sig": false,
"md5_digest": "44503923aeb81adedd4bfbbb2407357c",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.8",
"size": 24194,
"upload_time": "2025-08-29T17:18:21",
"upload_time_iso_8601": "2025-08-29T17:18:21.498623Z",
"url": "https://files.pythonhosted.org/packages/88/ef/006817d7c72067a38f8820e467578fcbb3ee573c18d03bc7bdb1a206ba3f/theoprice-0.1.1.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2025-08-29 17:18:21",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "yourusername",
"github_project": "theoprice",
"github_not_found": true,
"lcname": "theoprice"
}