Overview
Real-time market data streaming via WebSocket connections for Pakistan Stock Exchange (PSX).
The Live Feed API provides WebSocket-based connections for streaming real-time market data including:
- Snapshot ticks (price and volume updates)
- Order book data (bid/ask levels)
- Order details and execution information
- Multiple access levels (L0, L1, L2)
Endpoints
Socket Endpoints
| Endpoint | Access Level | Description |
|---|---|---|
/2.0/market/feed | L0 | Basic market data (indices and regular market limited) |
/2.0/market/feed/full | L1 | Full market data access |
/2.0/market/feed/l2 | L2 | Level 2 data including order book and individual orders |
Connection Environments
| Endpoint | Environment |
|---|---|
wss://uat.csapis.com | Staging |
wss://csapis.com | Production |
Authentication
- Type: Bearer Token (passed as query parameter or header)
- Required: Yes
Connection Limits
⚠️ Important: Only 2 concurrent connections are allowed per authentication token. Exceeding this limit will result in connection termination. Plan your backend infrastructure accordingly:
- Use a single persistent connection per backend service
- Implement connection pooling if multiple services need access
- Monitor active connections to avoid hitting the limit
- Implement proper reconnection logic to handle disconnections
Best Practices
- Backend Only: Always consume this endpoint from your backend services, never expose it directly to frontend clients
- Connection Management: Maintain a single persistent connection per authentication token and implement exponential backoff reconnection logic
- Connection Limits: Monitor to ensure you don't exceed the 2 concurrent connections per token limit
- Data Caching: Cache processed market data and distribute to frontend clients via REST/WebSocket endpoints
- Data Validation: Validate all incoming messages and handle partial data gracefully
- Performance: Process messages efficiently to avoid lag in live data streams
- Error Handling: Implement comprehensive error handling for network failures and graceful degradation
- Rate Limiting: Respect server rate limits and implement client-side throttling if needed
Use Cases
- Real-time Trading: Feed live market data to trading platforms
- Algorithmic Trading: Provide tick-by-tick data for automated strategies
- Market Monitoring: Real-time dashboard for market surveillance
- Order Execution: Support high-frequency trading systems