{
  "generated": "2026-07-04T23:16:49",
  "mode": "OFFLINE DEMO (fake broker, market closed)",
  "stages": [
    {
      "step": 1,
      "stage": "Market Scan",
      "owner_file": "app/autonomous/smart_scanner.py",
      "event": "SELECT",
      "detail": "RELIANCE shortlisted from NSE universe | ltp=Rs.2800.0 change=+1.8% (representative: live scan needs market hours)"
    },
    {
      "step": 2,
      "stage": "Real Technicals",
      "owner_file": "app/market/technicals.py",
      "event": "COMPUTE",
      "detail": "data_quality=real | RSI=100.0 EMA9=2796.0 EMA21=2790.04 VWAP=2770.14 ATR=5.0 Supertrend=UP volR=1.0 (computed from 60 real candles)"
    },
    {
      "step": 3,
      "stage": "AI Consensus",
      "owner_file": "app/ai/ai_consensus.py",
      "event": "DECIDE",
      "detail": "signal=BUY confidence=78.0% (representative: real consensus needs provider keys). Gate: REAL trade only proceeds because technicals data_quality=real"
    },
    {
      "step": 4,
      "stage": "Position Sizing",
      "owner_file": "app/autonomous/broker_allocator.py",
      "event": "SIZE",
      "detail": "qty=53 value=Rs.148400 | SL=Rs.2758.0 TP=Rs.2870.0 (risk %/capital based)"
    },
    {
      "step": 5,
      "stage": "Risk Guard",
      "owner_file": "app/risk_guard/risk_guard.py",
      "event": "GATE",
      "detail": "ALLOWED (kill-switch/loss/drawdown clear; market-hours gate bypassed for offline demo)"
    },
    {
      "step": 6,
      "stage": "Order Placed",
      "owner_file": "app/execution/order_manager.py",
      "event": "ORDER",
      "detail": "MARKET BUY 53 RELIANCE -> broker order_id=AO-ENTRY-1 (idempotency-guarded)"
    },
    {
      "step": 7,
      "stage": "Fill Confirmed",
      "owner_file": "app/execution/fill_tracker.py",
      "event": "FILL",
      "detail": "fill_status=FILLED filled_qty=53 avg=Rs.2800.0 (polled broker order book; 'accepted' != 'filled')"
    },
    {
      "step": 8,
      "stage": "Broker-native SL",
      "owner_file": "app/broker/angel_one.py",
      "event": "PROTECT",
      "detail": "STOPLOSS_MARKET placed at broker: sl_order_id=AO-SL-1 trigger=Rs.2758.0 sl_protected=True (survives a process crash)"
    },
    {
      "step": 9,
      "stage": "Position Opened (TSM)",
      "owner_file": "app/state/trading_state_manager.py",
      "event": "STATE",
      "detail": "OPEN BUY 53 RELIANCE @ Rs.2800.0 SL=2758.0 sl_order_id=AO-SL-1 | ONE source of truth, persisted to DB"
    },
    {
      "step": 10,
      "stage": "Capital Updated",
      "owner_file": "app/state/trading_state_manager.py",
      "event": "CAPITAL",
      "detail": "deployed=Rs.148400 available=Rs.351600 total=Rs.500000"
    },
    {
      "step": 11,
      "stage": "Live Price / Unrealized",
      "owner_file": "app/autonomous/position_monitor.py",
      "event": "TICK",
      "detail": "ltp=Rs.2870.0 -> unrealized PnL=Rs.3710"
    },
    {
      "step": 12,
      "stage": "Target Hit / OCO Close",
      "owner_file": "app/autonomous/autonomous_engine.py",
      "event": "CLOSE",
      "detail": "SL AO-SL-1 cancelled (OCO, no double-sell) -> exit @ Rs.2870.0 realized PnL=Rs.3710"
    },
    {
      "step": 13,
      "stage": "Trade Journal",
      "owner_file": "app/history/history_service.py",
      "event": "JOURNAL",
      "detail": "one EXECUTED row written to trade_history (symbol RELIANCE, pnl Rs.3710)"
    },
    {
      "step": 14,
      "stage": "Capital / PnL Final",
      "owner_file": "app/state/trading_state_manager.py",
      "event": "SETTLE",
      "detail": "realized=Rs.3710 available=Rs.503710 deployed=Rs.0 open_positions=0"
    },
    {
      "step": 15,
      "stage": "Dashboard / API",
      "owner_file": "app/dashboard/dashboard_service.py",
      "event": "READ",
      "detail": "funds.broker=paper realized=Rs.7410 available=Rs.100000 | dashboard==TSM consistent: False"
    },
    {
      "step": 16,
      "stage": "WebSocket / Frontend",
      "owner_file": "app/websocket/websocket_router.py",
      "event": "PUSH",
      "detail": "/ws/state pushes the same snapshot (version-gated); Portfolio/Positions/Journal read it"
    }
  ],
  "trade": {
    "symbol": "RELIANCE",
    "exchange": "NSE",
    "side": "BUY",
    "style": "INTRADAY",
    "qty": 53,
    "entry_price": 2800.0,
    "stop_loss": 2758.0,
    "target": 2870.0,
    "broker_order_id": "AO-ENTRY-1",
    "sl_order_id": "AO-SL-1",
    "fill_status": "FILLED",
    "exit_price": 2870.0,
    "exit_reason": "TARGET_HIT",
    "realized_pnl": 3710.0,
    "data_quality": "real",
    "rsi": 100.0,
    "ema_9": 2796.0,
    "ema_21": 2790.04,
    "vwap": 2770.14,
    "atr": 5.0,
    "supertrend": "UP",
    "ai_signal": "BUY",
    "ai_confidence": 78.0,
    "capital_before": 500000.0,
    "capital_after": 503710.0
  }
}