Skip to main content

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

EventDirectionPayload
download.progressServer → Client{ progress, log, status }
download.completeServer → Client{ status, eq_date, fo_date }
price.alertServer → Client{ symbol, price, condition }
chain.updateServer → ClientFull option chain snapshot

Proposed Stack

  • FastAPI WebSocket endpoints (/ws/download-progress)
  • React useWebSocket hook
  • Broadcasting via asyncio.Queue per client

Implemented in: v2.0 (planned)