⚡ Architecture
Cloudflare Worker
Strategy logic, cron triggers, D1 database, dashboard API. Runs every minute during market hours.
Oracle VPS Proxy
India-based static IP (80.225.223.87:3000). All Shoonya API calls routed through here. Auth via X-Secret-Key header.
Shoonya Broker
Finvasia's trading platform. REST API for orders, quotes, option chain. WebSocket for live ticks.
🎯 Entry Logic — Triple Filter (All 3 Must Pass)
| Filter | Condition | Why |
| Filter 1: CPR |
Spot breaks above TC (bullish) or below BC (bearish) |
Confirms trending day with directional breakout |
| Filter 2: OI Trap |
ATM CE OI drops >10% (for CE) or ATM PE OI drops >10% (for PE) |
Sellers unwinding = trapped shorts covering = momentum fuel |
| Filter 3: Premium |
Option LTP > VWAP AND Option LTP > EMA-9 |
Confirms premium is gaining momentum, not fading |
📊 Bonus confirmations (logged but don't block): RSI > 60 (CE) or < 40 (PE), Volume > 1.5x average
🚀 Exit Logic — Moonshot Trail Matrix
| Stage | Trigger | SL Moves To | Action |
| 0 | Entry | -15% from entry | Initial SL set |
| 1 | +20% profit | Breakeven (entry price) | Risk-free trade |
| 2 | +40% profit | Breakeven | 🔥 Exit 50% qty (lock profit) |
| 3 | +100% profit | +70% from entry | Trail remaining 50% |
| 4 | +200% profit | +150% from entry | Deep trail |
| 5 | +300% profit | +250% from entry | 🚀 Moonshot mode |
⏱ SL is checked every 5 seconds using Option LTP (not Spot). EOD auto square-off at 3:15 PM IST.
🛡️ Risk Management
Max Daily Losses
Bot stops after 2 consecutive losses in a day. No more trades until next day.
Max Daily Loss %
Bot stops if daily P&L drops below -10%. Capital protection first.
Entry Cutoff
No new trades after 1:30 PM IST. Theta decay accelerates in afternoon.
Exit Order Retry
Exit orders retry 3 times. If all fail, trade marked as EMERGENCY for manual intervention.
Session Management
Shoonya session auto-refreshes every 5 hours. Prevents mid-day auth failures.
Lot Size
Current Nifty lot size: 25 shares. Configurable via NIFTY_LOT_SIZE env var.
📐 Indicators Computed
CPR
Central Pivot Range from previous day's High/Low/Close. Narrow CPR = trending day.
VWAP
Volume Weighted Average Price. Option premium above VWAP = bullish momentum.
EMA-9
9-period Exponential Moving Average on option premium. Fast momentum indicator.
RSI-14
Relative Strength Index. >60 bullish, <40 bearish, 40-60 = "Theta Death Zone".
OI Change %
Open Interest change over last 2-3 readings. Drop >10% = seller trap detected.
ATM Strike
Nearest 50-point strike to current Nifty spot. Used as reference for option chain.
🔧 Controls
| Button | Action |
| ▶ STRATEGY ON / ⏸ PAUSE | Toggle trading. When paused, signals are logged but no orders placed. |
| ☠ PANIC EXIT | Immediately market-sells ALL open positions. Retries 3x. Cannot be undone. |
| ↻ RESET DAY | Clears daily loss counter, P&L tracking, and active trade state. |
| ATM / OTM Toggle | ATM = trade at-the-money strike. OTM = offset by configurable points (cheaper premium). |