A Python CLI application for fetching real-time options trading data from Upstox API with Black-Scholes Greeks calculations
Project description
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
- Install dependencies:
pip install -r requirements.txt
-
Configure Upstox authentication:
Option A: OAuth Login (Recommended for Web App)
- Copy
.env.exampleto.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.exampleto.env - Add your access token to
.env:UPSTOX_ACCESS_TOKEN=your_access_token
- Copy
Usage
CLI Application
Run the CLI app:
python run.py
Web Application (with OAuth)
Run the web app:
python run_web.py
Then open http://localhost:8000 in your browser.
OAuth Flow:
- Click "Login with Upstox" button
- You'll be redirected to Upstox login page
- After successful login, you'll be redirected back
- Token is automatically managed (expires at 3:30 AM IST daily)
- No manual token entry needed!
Follow the prompts:
- Enter asset symbol (e.g., TCS, SBIN, NIFTY, BANKNIFTY)
- Type 'LIST' to see all supported F&O symbols
- Select expiry date from the list
- Enter strike price
- View the option chain data with Greeks
Testing
Run tests to verify everything works:
# 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
# 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
-
Ensure your repository contains:
Procfilewith:web: uvicorn web_app.app:app --host 0.0.0.0 --port ${PORT:-8000}.env.examplewithUPSTOX_ACCESS_TOKEN=requirements.txtincludingfastapi,uvicorn, andJinja2
-
On Railway:
- Create a new project and connect this repo.
- In Settings โ Variables, add
UPSTOX_ACCESS_TOKENwith your token. - Deploy. The service will listen on
$PORTautomatically.
-
Health check:
GET /healthzshould return{ "status": "ok" }.
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 theoprice-0.1.1.tar.gz.
File metadata
- Download URL: theoprice-0.1.1.tar.gz
- Upload date:
- Size: 24.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
803f5fc3095e472c0864d62c257a2a77c5e7e8d76c649aebe38b4849b63835a7
|
|
| MD5 |
44503923aeb81adedd4bfbbb2407357c
|
|
| BLAKE2b-256 |
88ef006817d7c72067a38f8820e467578fcbb3ee573c18d03bc7bdb1a206ba3f
|
File details
Details for the file theoprice-0.1.1-py3-none-any.whl.
File metadata
- Download URL: theoprice-0.1.1-py3-none-any.whl
- Upload date:
- Size: 22.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f7294c2f9dc2602feea2c7e9a34c9c588b4bd9bdeb78ace7574e40d3ae3b058b
|
|
| MD5 |
195b5a13c0a6a561022ad74dbd4402dd
|
|
| BLAKE2b-256 |
2746ee5728064667e0d5ecd8b09c2b1182b90be40b12e99d15b7ec35c48d511f
|