Automated Options Selling Bot Development

Job ID: 39497028

Budget: ₹12,500 – ₹37,500 INR

Project Proposal: Automated Options Selling Bot (Dhan Broker Integration)
________________________________________
1. Project Overview
We propose to develop a fully automated options selling bot that:
• Reads strategy parameters from a CSV (Excel) file.
• Connects to the Dhan Broker API for live quotes and order placement.
• Implements a “no-UI” architecture: all inputs (strike selection rules, position sizing, risk‐management thresholds) will be driven by CSV uploads.
• Executes strategy logic based on the PDFs provided (historical-volatility strike selection, return‐on‐capital ranking, daily entry/exit rules).
• Includes a paper‐trading/simulation mode for end‐to‐end validation before deployment to live markets.
• Is structured in modular code for future extensibility (e.g., adding new strategies or brokers).
Key Assumptions
• The client has or will obtain an active Dhan Data API subscription.
• The client will provide valid API credentials and a funded test account (minimum ₹1,000) for order placement validation.
• The CSV file format is agreed upon in advance (sample template will be provided in the first milestone).
________________________________________
2. Scope of Work
1. CSV‐Driven Parameter Ingestion
o Define a CSV template that includes:
Strategy selection (e.g., “Volatility → Safe Strike” or “Daily OTM Option Selling”)
Underlying asset (NIFTY, BANKNIFTY, GOLD)
Strike offsets or safe strikes (computed externally or via a preliminary Python worksheet)
Position‐sizing rules (e.g., 1 lot per ₹1.5 L capital, maximum order size)
Risk‐management thresholds (stop‐loss %, daily target %, time‐based exit).
o Implement a robust CSV‐parser module that validates inputs, applies default values where permissible, and raises clear errors if fields are missing/invalid.
2. Strategy Logic Implementation
Based on “Noor_Strategy.pdf” (Historical Volatility) & “Untitled document.pdf” (Daily OTM Selling):
o Part 1: Historical Volatility‐Based Strike Selection
Read monthly high/low drop percentage from CSV or precomputed table.
Calculate “safe strike” = (Current Price × (1 – Max Drop %)).
Verify that the safe strike is tradable (round to nearest valid strike) via Dhan Data API’s strike‐quote endpoint.
o Part 2: Return on Capital Ranking
For each potential safe strike, fetch live option premiums and margin requirements.
Compute Return % = (Premium ÷ Margin) × 100.
Select the strike with the highest Return %.
o Daily OTM Option Selling Workflow (if client elects the “Daily Inputs” strategy):
At market open (09:15 AM IST), select the underlying (NIFTY/BANKNIFTY/GOLD) with the highest return potential (based on CSV directives).
Selection of strike direction: CE | PE | BOTH
Choose an OTM strike (e.g., 1.5 %–2 % away) with:
Premium ≥ ₹20–₹25 (configurable).
High open interest (LIQUIDITY > threshold).
Bid–Ask spread < configurable max spread.
Position Sizing: 1 lot per ₹150,000 available capital (rounded down).
Risk Management:
Daily Stop‐Loss: If MTM ≤ –2 % of allocated capital → exit all positions.
Daily Target(On/off): If MTM ≥ +3 % of allocated capital → exit all positions.
Trailing stoploss(On/off): If enabled it will trails the stoploss X point from highest profit.
Ex- Suppose if position profit is 100 and trailing stoploss is 5 point then if current PnL goes below 95 we’ll exit the position
Exit Logic:
At 3:00 PM IST, square off any open positions (unless already exited).
o Logging & Alerts:
Log each trade (timestamp, underlying, strike, premium, margin, P&L).
Compute “Expense Ratio” per trade (brokerage + taxes; configurable via CSV cell).
Maintain cumulative gross vs. net P&L.
Send (optional) email/push notifications on entry, exit, stop‐loss, or target hit (using a simple SMTP or webhook).
3. Broker Integration (Dhan API)
o Market Data:
Connect to Dhan Data API (REST/WebSocket) for:
Underlying spot price (for safe‐strike calculation).
Option strike quotes (live premiums, bid/ask, open interest).
Margin requirements (fetch pre‐trade margin blocks).
o Order Placement:
Implement a Dhan REST client module to place market/limit orders, check order status, and cancel orders.
Handle order acknowledgments, fill‐reports, and partial fills.
Implement retry logic for transient failures (rate limits, network errors).
o Paper/SIM Mode:
A configuration flag (--paper_trade=True in CSV or config file) will cause the module to simulate order placements (no real orders sent).
Simulated executions will generate realistic fill‐times and slippage estimates based on last traded price.
4. Testing & Validation
o Unit Tests for:
CSV parsing (invalid/missing fields).
Strike‐selection formulas.
Return‐on‐capital ranking.
Risk‐management triggers (stop‐loss/target).
o Integration Tests (in Paper/SIM mode):
End‐to‐end workflow from CSV → safe‐strike computation → order‐placement simulation.
Edge‐cases (e.g., underlying gap vs. OTM distance, insufficient margin).
o Live Test (with ₹1,000 test‐account):
Verify that:
Orders flow correctly through Dhan (no rejections due to insufficient margin).
P&L calculations match the exchange reporting.
Automated exits occur at 3:00 PM IST, or upon SL/target.
o Documentation & Handover
Provide a self‐contained README.md and a parameterized CSV template (with example rows).
Inline code comments explaining core logic, especially around strike computations and risk checks.
A short “User Guide” PDF (1–2 pages) explaining:
1. How to configure the CSV.
2. How to run the bot in “paper” vs. “live” modes.
3. How to interpret logs and metrics.
4. How to deploy (cron or scheduled task).
________________________________________
3. Deliverables
1. Source Code Repository (Git) containing:
o csv_parser.py (validates/reads input parameters).
o strategy_engine.py (implements strike selection, return ranking, daily OTM rules).
o dhan_client.py (wraps Dhan Data API & Order API).
o paper_trade_simulator.py (mock‐broker wrapper).
o logger.py (P&L logger, expense‐calculator).
o tests/ (unit and integration tests).
o README.md (setup & execution instructions).
o csv_templates/ (example CSVs for both strategy flavors).
o Deployment scripts (e.g., run_bot.sh, requirements.txt, Dockerfile—optional).
2. User Guide (PDF)
o Explains CSV format, running modes, environment variables, and troubleshooting tips.
3. Demo Session (Screen‐share)
o Walkthrough of:
1. Configuring CSV.
2. Running in paper‐trade mode.
3. Live run (with test account).
4. Log interpretation (P&L summary, execution details).
________________________________________
4. Timeline & Milestones (10–12 Days Total)

________________________________________
6. Technical Stack & Environment
• Language: Python 3.10+
• Dependencies:
o pandas (CSV parsing, data frames)
o requests or httpx (Dhan REST calls)
o websocket-client (if Dhan offers real‐time WebSocket feeds)
o pydantic or cerberus (optional for CSV schema validation)
o pytest (unit/integration tests)
• Deployment (Optional, as it’s required monthly fixed cost):
o Local server or small cloud VM (Ubuntu 20.04).
o Environment variables for API keys (DHAN_API_KEY, DHAN_API_SECRET).
o (Optional) Docker container (Dockerfile included) for reproducibility.
________________________________________

________________________________________
Related categories: Project Management Analytics