1 Prerequisites
-
✓
Python 3.10+ — check with
python3 --version - ✓ An Upstox Developer App — create one at developer.upstox.com ↗
-
✓
Your app's Redirect URI set to exactly:
http://127.0.0.1:8000/callback - ✓ An active Upstox trading account with market data subscription
2 Installation
Clone or download the project, then install dependencies:
cd /path/to/TraderX
pip install -r requirements.txt
python3 -m venv .venv
source .venv/bin/activate # macOS / Linux
.venv\Scripts\activate # Windows
pip install -r requirements.txt
3 Configuration
Open config.yaml and fill in your Upstox credentials:
upstox:
api_key: "YOUR_API_KEY" # client_id from Upstox dev portal
api_secret: "YOUR_API_SECRET" # client_secret from Upstox dev portal
redirect_uri: "http://127.0.0.1:8000/callback"
strategy:
target_pct: 20.0 # Exit at +20% from entry
stoploss_pct: 20.0 # Exit at -20% from entry
hard_exit_time: "09:32" # HH:MM IST — force-close all positions
max_positions: 3
server:
host: "127.0.0.1"
port: 8000
config.yaml contains your API secret — keep it local.
It is listed in .gitignore along with .upstox_token and traderx.db.
Alternatively, use environment variables (take priority over YAML):
export UPSTOX_API_KEY="your_api_key"
export UPSTOX_API_SECRET="your_api_secret"
4 Running the App
cd /path/to/TraderX
python3 -m uvicorn app:app --host 127.0.0.1 --port 8000
Then open your browser at:
▶ http://127.0.0.1:8000On startup you should see in the terminal:
TraderX — Paper Trading Dashboard
PAPER TRADING MODE — NO LIVE ORDERS WILL BE PLACED
============================================================
5 Upstox Authentication
Upstox uses OAuth 2.0. You need to log in once each trading day (tokens expire daily at midnight).
/callback. The token is exchanged and saved to .upstox_token automatically.6 Daily Workflow
Run the app and click "Login to Upstox" if not already authenticated. The green dot confirms you're live.
Watch price action for the first 2 minutes to identify your candidates.
Type up to 3 stock names (e.g. RELIANCE, TCS, INFY) in the input boxes and click ▶ Start Tracking. The app will:
- Look up each stock's current spot price
- Find the ATM Put option for the current weekly expiry
- Fetch the live LTP as entry price
- Calculate Target (+20%) and SL (−20%)
- Start streaming live LTP via Upstox WebSocket
Watch the 3 cards. Each one independently tracks whether it hits target, SL, or neither. A flash and badge update happens the moment any position exits.
Any positions still open are automatically closed at the current LTP with reason TIME_EXIT. The feed stops. No action needed from you.
Toggle "My actual pick" on whichever of the 3 you would have (or did) trade. This is used to filter the Stats panel to show your personal track record.
7 Dashboard Guide
● OPEN → ✓ TARGET HIT or ✕ SL HIT or ⏰ TIME EXIT. Card border glows the matching color.8 Strategy Parameters
All parameters are in config.yaml. Change them without touching any Python code:
| Parameter | Default | Description |
|---|---|---|
target_pct |
20.0 |
Exit position when LTP rises +N% above entry price |
stoploss_pct |
20.0 |
Exit position when LTP falls −N% below entry price |
hard_exit_time |
09:32 |
Force-close all open positions at this time IST (HH:MM) |
max_positions |
3 |
Maximum simultaneous candidate positions |
entry_window_start |
09:15 |
Earliest allowed entry time (informational) |
config.yaml for changes to take effect.
9 CLI Tools
You can run upstox_client.py directly to test the connection without starting the full dashboard:
python3 upstox_client.py --test "NSE_INDEX|Nifty 50"
python3 upstox_client.py --atm-pe RELIANCE
python3 upstox_client.py --code <AUTH_CODE_FROM_URL>
10 Troubleshooting
▸ "Not authenticated" — login button doesn't work
Make sure api_key and api_secret are filled in config.yaml. Also confirm the Redirect URI in your Upstox app settings is exactly http://127.0.0.1:8000/callback (no trailing slash).
▸ "Empty option chain" error when submitting stocks
This happens if the stock name doesn't match Upstox's instrument search, or there's no active option chain (e.g. entered outside trading hours). Try using the exact Upstox instrument key format: NSE_FO|<token>. You can find instrument keys in Upstox's instrument dump CSV.
▸ The red "data feed disconnected" banner keeps appearing
The WebSocket auto-reconnects with exponential backoff (up to 30s). Check your internet connection. If it persists, your Upstox token may have expired — re-login via the dashboard button.
▸ LTP shows 0.00 or doesn't update
The option may have zero liquidity or market is closed. Confirm you're within market hours (9:15 AM – 3:30 PM IST). The WebSocket feed only carries active ticks — illiquid options may be slow.
▸ Port 8000 is already in use
Change the port in config.yaml under server.port, and update the Redirect URI in both config.yaml and your Upstox app settings to match.
python3 -m uvicorn app:app --host 127.0.0.1 --port 8080
▸ "protobuf" import error on startup
Install the package manually: pip install protobuf. The app will fall back to JSON decoding if the compiled MarketDataFeed_pb2.py module fails — but having protobuf installed is required.