# CV6 AI Trading OS — API Mapping Document
**Date:** 2026-06-30  
**Method:** File-by-file read of every frontend API call and every backend router  
**Source:** ACTUAL CODE — no estimates, no assumptions

---

## Files Read

### Frontend
- `frontend/src/api/client.ts` — axios base config, WS_BASE, JWT interceptor
- `frontend/src/api/dashboard.ts` — all 30 exported API functions
- `frontend/src/hooks/useWebSocket.ts` — WebSocket connection
- `frontend/src/pages/ChartsPage.tsx` — direct `api.get('/market/history')` call

### Backend
- `app/dashboard/dashboard_router.py` — prefix `/dashboard`
- `app/execution/execution_router.py` — prefix `/execution`
- `app/risk/risk_router.py` — prefix `/risk`
- `app/portfolio/portfolio_router.py` — prefix `/portfolio`
- `app/signal/signal_router.py` — prefix `/signal`
- `app/strategy/strategy_router.py` — prefix `/strategy`
- `app/indicators/indicator_router.py` — prefix `/indicator`
- `app/websocket/websocket_router.py` — no prefix (registers /ws/live, /ws/market, /ws/ticks, /ws/status)
- `app/ai/consensus_router.py` — prefix `/ai/consensus`
- `app/history/history_router.py` — prefix `/history`
- `app/paper_trading/paper_router.py` — prefix `/paper`
- `app/backtest/backtest_router.py` — prefix `/backtest`
- `app/api/market_api.py` — prefix `/market`
- `app/api/user_api.py` — prefix `/users`

---

## Full API Map

| # | Frontend Call | Method | Frontend URL | Backend URL | Auth | Status |
|---|--------------|--------|-------------|-------------|------|--------|
| 1 | `fetchDashboard` | GET | `/dashboard/` | `/dashboard/` | JWT | ✅ MATCH |
| 2 | `fetchFunds` | GET | `/dashboard/funds` | `/dashboard/funds` | JWT | ✅ MATCH |
| 3 | `fetchPnL` | GET | `/dashboard/pnl` | `/dashboard/pnl` | JWT | ✅ MATCH |
| 4 | `fetchRisk` | GET | `/dashboard/risk` | `/dashboard/risk` | JWT | ✅ MATCH |
| 5 | `fetchAIStatus` | GET | `/dashboard/ai` | `/dashboard/ai` | JWT | ✅ MATCH |
| 6 | `fetchMarket` | GET | `/dashboard/market` | `/dashboard/market` | JWT | ✅ MATCH |
| 7 | `fetchHealth` | GET | `/dashboard/health` | `/dashboard/health` | JWT | ✅ MATCH |
| 8 | `fetchPortfolio` | GET | `/dashboard/portfolio` | `/dashboard/portfolio` | JWT | ✅ MATCH |
| 9 | `fetchOrders` | GET | `/dashboard/orders` | `/dashboard/orders` | JWT | ✅ MATCH |
| 10 | `fetchPositions` | GET | `/dashboard/positions` | `/dashboard/positions` | JWT | ✅ MATCH |
| 11 | `fetchBrokerStatus` | GET | `/dashboard/broker` | `/dashboard/broker` | JWT | ✅ MATCH |
| 12 | `runConsensus` | POST | `/ai/consensus/analyze` | `/ai/consensus/analyze` | None | ✅ MATCH |
| 13 | `fetchConsensusModels` | GET | `/ai/consensus/models` | `/ai/consensus/models` | None | ✅ MATCH |
| 14 | `fetchHistory` | GET | `/history/` | `/history/` | None | ✅ MATCH |
| 15 | `fetchHistoryPnL` | GET | `/history/pnl` | `/history/pnl` | None | ✅ MATCH |
| 16 | `exportHistoryCSV` | GET | `/history/export` | `/history/export` | None | ✅ MATCH |
| 17 | `placeOrder` | POST | `/execution/place-order` | `/execution/place-order` | JWT | ✅ MATCH |
| 18 | `cancelOrder` | POST | `/execution/cancel-order` | `/execution/cancel-order` | JWT | ✅ MATCH |
| 19 | `modifyOrder` | POST | `/execution/modify-order` | `/execution/modify-order` | JWT | ✅ MATCH |
| 20 | `fetchExecutionOrders` | GET | `/execution/orders?broker=...` | `/execution/orders` (requires `broker` param) | JWT | ✅ MATCH |
| 21 | `calculateRisk` | POST | `/risk/calculate` | `/risk/calculate` | None | ✅ MATCH |
| 22 | `generateStrategy` | POST | `/strategy/generate` | `/strategy/generate` | None | ✅ MATCH |
| 23 | `runBacktest` | POST | `/backtest/run` | `/backtest/run` | None | ✅ MATCH |
| 24 | `paperTrade` | POST | `/paper/trade` | `/paper/trade` | JWT | ✅ MATCH |
| 25 | `fetchPaperAccount` | GET | `/paper/account` | `/paper/account` | JWT | ✅ MATCH |
| 26 | `fetchPaperHistory` | GET | `/paper/history` | `/paper/history` | JWT | ✅ MATCH |
| 27 | `cancelPaperPosition` | POST | `/paper/cancel` | `/paper/cancel` | JWT | ✅ MATCH |
| 28 | `resetPaperAccount` | POST | `/paper/reset` | `/paper/reset` | JWT | ✅ MATCH |
| 29 | `fetchWsStatus` | GET | `/ws/status` | `/ws/status` | None | ✅ MATCH |
| 30 | `fetchCandles` (ChartsPage) | GET | `/market/history` | `/market/history` | None | ✅ MATCH |

### WebSocket

| Frontend | Backend | Status |
|----------|---------|--------|
| `ws://127.0.0.1:8000/ws/ticks?symbols=NIFTY,BANKNIFTY,...` | `/ws/ticks` multi-symbol | ✅ CODE MATCH — ❌ RUNTIME FAIL (BUG-002) |

---

## Verdict: ZERO URL Mismatches

Every frontend API call exactly matches a registered backend endpoint. No URL corrections needed.

---

## Stability Sweep False Positives — Clarified

The previous stability report listed 7 "failing" endpoints. These were **wrong paths in the test script** (`stability_run.py`), NOT frontend-backend mismatches. The frontend does NOT call these paths.

| Test Script Path Tested | Actual Backend Path | Why Frontend Is Unaffected |
|------------------------|--------------------|-----------------------------|
| `GET /risk/metrics` | POST `/risk/calculate` only | Frontend calls POST `/risk/calculate` ✅ |
| `GET /portfolio/` | POST `/portfolio/calculate` only | Frontend calls GET `/dashboard/portfolio` ✅ |
| `GET /signal/latest` | POST `/signal/generate` only | Frontend does not call signal directly |
| `GET /strategy/` | POST `/strategy/generate` only | Frontend calls POST `/strategy/generate` ✅ |
| `GET /indicators/list` | POST `/indicator/ema\|rsi\|macd\|...` (prefix `/indicator`) | Frontend does not call indicator directly |
| `GET /execution/orders` (no param) | GET `/execution/orders?broker=...` | Frontend always passes `broker` param ✅ |
| `GET /market/status` | GET `/market/history` and POST `/market/data` | Frontend calls GET `/market/history` ✅ |

**BUG-004 is RESOLVED: The 7 failing endpoints were test script errors, not integration bugs.**

---

## Backend-Only Endpoints (No Frontend Call — Not Bugs)

These backend endpoints exist but are not called by the frontend. They are internal-use or broker-integration endpoints.

| Endpoint | Method | Router | Note |
|----------|--------|--------|------|
| `/users/register` | POST | user_api | Registration — frontend has Login page only |
| `/users/login` | POST | user_api | Called by frontend Login page via direct axios |
| `/execution/execute-trade` | POST | execution_router | Broker-specific, not in frontend API client |
| `/ws/live` | WS | websocket_router | Not used by frontend (uses /ws/ticks) |
| `/ws/market` | WS | websocket_router | Not used by frontend (uses /ws/ticks) |
| `/portfolio/calculate` | POST | portfolio_router | Internal calculation — dashboard serves portfolio data |
| `/signal/generate` | POST | signal_router | Internal — not called by frontend directly |
| `/indicator/ema\|rsi\|macd\|sma\|atr\|bollinger\|supertrend\|vwap` | POST | indicator_router | Internal — not called by frontend directly |
| `/market/data` | POST | market_api | Not called by frontend (uses /market/history) |
| `/history/{id}` | GET | history_router | Not called by frontend |
| `/history/` | POST | history_router | Internal write — not called by frontend directly |
| `/history/{id}` | PATCH | history_router | Internal — not called by frontend |

---

## Bug Status Update

| Bug | Status | Action |
|-----|--------|--------|
| BUG-001: UnicodeEncodeError (`→` in notes) | ✅ FIXED | Replaced `→` with `->` in `paper_router.py` |
| BUG-002: WebSocket dead (uvicorn[standard] missing) | OPEN | Requires `pip install "uvicorn[standard]"` — Task #47 |
| BUG-003: bcrypt `__about__` warning | OPEN | Low severity — no action required for paper trading |
| BUG-004: 7 endpoint 404s | ✅ RESOLVED | Test script errors — not frontend integration bugs |

---

## Summary

- **30 frontend API calls mapped** — all 30 match backend exactly
- **1 WebSocket endpoint** — code correct, fails at runtime (BUG-002, missing library)
- **0 URL mismatches** — no frontend URL fixes required
- **1 bug fixed** — BUG-001 (UnicodeEncodeError: `→` → `->`)
- **1 bug open** — BUG-002 (WebSocket: needs `pip install "uvicorn[standard]"`)

---
*Generated from ACTUAL CODE READ — every file listed above was read and verified.*  
*No estimates. No assumptions. No speculation.*
