WebSocket Flow
Current Implementation (Polling)
TradeEntry currently uses HTTP polling for real-time updates, as WebSocket was not required for the initial release.
How Polling Works
User triggers download
│
▼
POST /api/bhav-downloader/download
│
▼
FastAPI schedules BackgroundTask
│
▼ (HTTP response sent immediately)
Frontend starts polling every 1500ms
│
▼
GET /api/bhav-downloader/status
Returns JSON from stats.json
│
├── status == "RUNNING" → update progress bar, continue polling
│
└── status == "SUCCESS"/"FAILED" → stop polling, show result
stats.json Schema
{
"status": "RUNNING",
"progress": 45,
"last_log": "Downloading F&O bhav for 2025-01-14...",
"Logs": [
{
"message": "Starting update process...",
"source": "BhavDownloader",
"date": "2025-01-14",
"timestamp": "05:30:00 PM"
}
],
"history": [
{
"date": "2025-01-14",
"timestamp": "2025-01-14 05:35:00 PM",
"status": "SUCCESS",
"message": "Bhav copy ingested successfully."
}
]
}
Planned: WebSocket Migration (v2.0)
In v2.0, polling will be replaced with WebSocket for:
- Bhav download progress
- Live option chain updates
- Price alerts
Planned WebSocket Events
| Event | Direction | Payload |
|---|---|---|
download.progress | Server → Client | { progress, log, status } |
download.complete | Server → Client | { status, eq_date, fo_date } |
price.alert | Server → Client | { symbol, price, condition } |
chain.update | Server → Client | Full option chain snapshot |
Proposed Stack
- FastAPI WebSocket endpoints (
/ws/download-progress) - React
useWebSockethook - Broadcasting via
asyncio.Queueper client
Implemented in: v2.0 (planned)