This project is a web-based dashboard that provides a live, real-time view of Open Interest (OI) changes for NIFTY options. It is built with a Python Flask backend and a simple HTML/JavaScript frontend styled with Tailwind CSS. The application connects to the Upstox API to fetch live market data.
- Live Data: The dashboard auto-refreshes every 60 seconds to provide a near real-time view of the market.
- Expanded Data View: Tracks 7 strikes (ATM ± 3) for both Call and Put options.
- Multiple Time Intervals: Calculates and displays the percentage change in OI over 3, 5, 10, 15, and 30-minute intervals.
- Color-Coded Tables: Automatically highlights cells in red when OI changes exceed predefined thresholds, making it easy to spot significant movements.
- Audio Alerts: Plays a sound alert if more than 50% of the displayed cells are highlighted, ensuring you don't miss major market shifts.
- Automatic Expiry Selection: Intelligently detects and tracks the nearest weekly expiry date, so no manual configuration is needed.
- Easy Setup: Requires minimal setup with clear instructions for API credential configuration.
- Backend: Flask (Python)
- Frontend: HTML, Tailwind CSS, Vanilla JavaScript
- API: Upstox API
- Dependencies:
upstox-python-sdk,python-dotenv,gunicorn
Follow these steps to get the application running on your local machine.
- Python 3.8 or higher
- An active Upstox account with API access enabled.
First, clone this repository to your local machine.
git clone <repository-url>
cd <repository-directory>Install all the necessary Python packages using pip and the requirements.txt file.
pip install -r requirements.txtThe application uses a .env file to manage your Upstox API credentials.
-
Create the file: A
.envfile should be present in the root of the project. If not, you can create it. -
Fill in your details: Open the
.envfile and replace the placeholder values with your actual credentials.# Your Upstox API Key from the developer console. UPSTOX_API_KEY="YOUR_API_KEY" # Your Upstox API Secret from the developer console. UPSTOX_API_SECRET="YOUR_API_SECRET" # The access token you generate via the OAuth2 flow. UPSTOX_ACCESS_TOKEN="YOUR_ACCESS_TOKEN" # This must match the Redirect URI set in your Upstox developer app settings. UPSTOX_REDIRECT_URI="http://127.0.0.1:5000/callback"
The access token is temporary and needs to be generated via a login process. Follow these steps carefully.
-
Fill in your basic credentials in the
.envfile:UPSTOX_API_KEY,UPSTOX_API_SECRET, andUPSTOX_REDIRECT_URI. -
Create a
login.pyfile in the project directory and add the following code:import upstox_client import os from dotenv import load_dotenv load_dotenv() API_KEY = os.environ.get("UPSTOX_API_KEY") API_SECRET = os.environ.get("UPSTOX_API_SECRET") REDIRECT_URI = os.environ.get("UPSTOX_REDIRECT_URI") api_instance = upstox_client.LoginApi() api_response = api_instance.authorise(API_KEY, "v2", REDIRECT_URI) print(api_response)
-
Run
login.pyfrom your terminal to get the login URL:python login.py
-
Authorize and get the Auth Code: Copy the URL printed in the terminal and paste it into your web browser. Log in with your Upstox credentials. After successful login, you will be redirected to a new URL. Copy the
codevalue from this URL. It will look like this:http://127.0.0.1:5000/callback?code=YOUR_AUTH_CODE. -
Create a
get_token.pyfile and add the following code. Paste theAUTH_CODEyou copied in the previous step.import upstox_client import os from dotenv import load_dotenv load_dotenv() API_KEY = os.environ.get("UPSTOX_API_KEY") API_SECRET = os.environ.get("UPSTOX_API_SECRET") REDIRECT_URI = os.environ.get("UPSTOX_REDIRECT_URI") AUTH_CODE = "PASTE_YOUR_AUTH_CODE_HERE" configuration = upstox_client.Configuration() api_instance = upstox_client.LoginApi(upstox_client.ApiClient(configuration)) api_response = api_instance.token( api_version="v2", code=AUTH_CODE, client_id=API_KEY, client_secret=API_SECRET, redirect_uri=REDIRECT_URI, grant_type="authorization_code" ) print(api_response)
-
Run
get_token.pyto get your access token:python get_token.py
-
Set the Access Token: Copy the
access_tokenvalue from the output and paste it into theUPSTOX_ACCESS_TOKENfield in your.envfile.
You are now ready to run the main application!
Once your credentials are set up, you can run the application using the following command:
python app.pyThe server will start, and you can view the dashboard by opening your web browser and navigating to:
The application will start fetching data, and the dashboard will come to life. The status of the application will be displayed at the top of the page.
This README.md provides clear instructions for setting up and running the OI Tracker dashboard. Let me know if you would like any other sections or details added.