Real integration notes for wiring NIFTY ML models to live broker data via Dhan. Research/
paper-trading context — not a live-trading recommendation.
Why Dhan
Dhan's API exposes direct option-chain access — exactly what an options-ML system needs:
-
POST /optionchain— full chain for an underlying -
POST /optionchain/expirylist— available expiries - Fields:
security_id,last_price,volume,oi,previous_oi,implied_volatility,top_bid_price,top_ask_price, and greeks (delta/theta/gamma/vega)
Security IDs are stable: NIFTY = 13 (IDX_I), BANKNIFTY = 10001 (IDX_I).
The Pipeline Shape
A research dashboard pulls live chain + underlying, runs the trained XGBoost model on each
new 15-minute bar, and displays:
- side score (CE/PE alignment)
- gate state (entry ready / blocked)
- contract quality scores
- a doctrine/backtest report
Keep the inference path separate from the execution path. The dashboard shows; a
permissioned, human-approved module places orders.
Paper Trade First
The DhanLiveTrader pattern: load the model, predict on each new bar, place long orders with
configurable SL/TP (default 1.0 ATR SL, 2.0 ATR TP), and run in paper mode first. Only
after stable out-of-sample + paper evidence should any execution module even be considered.
{
"client_id": "YOUR_DHAN_CLIENT_ID",
"access_token": "YOUR_DHAN_ACCESS_TOKEN",
"is_paper_trade": true,
"nifty_symbol": "NIFTY",
"quantity": 50,
"max_trades_per_day": 3,
"sl_atr_mult": 1.0,
"tp_atr_mult": 2.0
}
The Hard Part: Stops
A known footgun: using a Stop-Loss Limit (SL-L) order with price = sl − 0.05 means it
won't fill if price crashes through the stop. Prefer SL-Market for the protective stop.
Execution quality is its own research topic — don't bolt it on at the end.
Honest Status
The ML side of this stack showed real directional skill (60.5% top-decile accuracy) but the
fixed-SL backtest was still unprofitable (PF 0.53). A dashboard that displays an honest
"RESEARCH / PAPER" status is worth more than one that hides the gap.
Research only. Not investment advice. SEBI/compliance is a separate, required topic before live trading.
More From Shakti Tiwari
- 🌐 Websites: shaktitiwari.github.io/shakti-tiwari-nse · OptionTradingWithAI.in
- 📚 Books: Build Your Own AI · Option Trading with AI (on Amazon India) — practical guides from a Nifty options trader and ML practitioner.
- 💬 Community: Join the Discord for live discussion, code, and research.
- 💻 Code: GitHub/shaktitiwari — open research, models, and tools.
Top comments (0)