Overview
The Data Stream WebSocket API provides real-time data streams for building dashboards, charts, and monitoring applications. It simulates stock market data with configurable update frequency and volatility to help developers test applications that rely on streaming data.
Key Features
- Real-time stock price updates with configurable update frequency
- Customizable price volatility to simulate different market conditions
- Market summary data including top gainers and losers
- Stock information with company name and industry details
- Realistic price movement simulation with percentage changes
Connection
To connect to the Data Stream WebSocket API, use the following endpoint:
wss://mockly.me/ws/stream/{client_id}
Replace {client_id}
with a unique identifier for your client. This helps identify your specific connection.
Configuration
After connecting, you can send a configuration JSON object to customize the data stream:
{
"frequency": 1.0, // Update frequency in seconds (min: 0.5, max: 10.0)
"volatility": 0.02 // Price volatility as decimal (min: 0.001, max: 0.1)
}
Message Formats
The API sends three types of messages, each with a different format. All messages include a type
field to distinguish between them.
Stock Information
Sent once for each stock when the connection is established:
{
"type": "stock_info",
"symbol": "AAPL",
"name": "Apple Inc.",
"industry": "Technology",
"timestamp": "2023-07-25T14:32:15.123456"
}
Price Update
Sent periodically based on the configured frequency:
{
"type": "price_update",
"symbol": "AAPL",
"price": 178.25,
"change_pct": 0.75,
"timestamp": "2023-07-25T14:33:15.123456"
}
Market Summary
Sent occasionally with aggregated market information:
{
"type": "market_summary",
"top_gainers": [
{"symbol": "TSLA", "price": 245.78},
{"symbol": "MSFT", "price": 325.42},
{"symbol": "AAPL", "price": 178.25}
],
"top_losers": [
{"symbol": "GOOGL", "price": 128.33},
{"symbol": "AMZN", "price": 132.67}
],
"market_sentiment": "bullish",
"timestamp": "2023-07-25T14:35:15.123456"
}
Events
The Data Stream WebSocket API generates the following key events:
Event | Description |
---|---|
Connection | When a client connects, they receive stock_info messages for each stock. |
Price Update | Periodically (based on frequency setting), price updates are sent for all stocks. |
Market Summary | Occasionally (20% chance on each update cycle), a market summary with top gainers and losers is sent. |
Disconnection | When a client disconnects, their connection is removed from the active connections list. |
Live Demo
Try out the WebSocket Stream API with this interactive demo. Connect to the stream and watch real-time data updates.
Stock Data Stream
Stock Prices
Market Summary
Meet Mockly Assistant
Your AI assistant for API testing, debugging and code generation. Access the power of mockly.me directly in ChatGPT.
- Generate code examples in your preferred language
- Get guidance for request/response handling and formatting
- Supercharged by ChatGPT Plus from OpenAI
"How do I send data to a POST endpoint"
"I can show you how to structure your request with headers and JSON — here's a code example..."