WebSocket
Connect to the WebSocket endpoint for real-time market data streaming. Receive quote updates as they happen with low-latency delivery.
Connection
Connect to the WebSocket endpoint and authenticate using your API token:
# WebSocket URL
wss://ws.marketpulse.io/v1/stream
Authentication
Send an authentication message immediately after connecting:
{
"type": "auth",
"token": "mp_live_aBcDeFgHiJkLmNoPqRsTuVwXyZ123456"
}Subscribing to Channels
Subscribe to receive real-time updates for specific symbols:
{
"type": "subscribe",
"channel": "quotes",
"symbols": ["EUR/USD", "GBP/USD", "XAU/USD"]
}Message Types
quoteQuote Update
Received when a subscribed symbol price changes.
heartbeatHeartbeat
Sent every 30 seconds to keep the connection alive.
errorError
Indicates an error with subscription or authentication.
Quote Message Format
This is what a real-time quote update looks like:
JavaScript Example
const ws = new WebSocket('wss://ws.marketpulse.io/v1/stream');
ws.onopen = () => {
// Authenticate
ws.send(JSON.stringify({
type: 'auth',
token: API_TOKEN
}));
// Subscribe to symbols
ws.send(JSON.stringify({
type: 'subscribe',
channel: 'quotes',
symbols: ['EUR/USD', 'GBP/USD']
}));
};
ws.onmessage = (event) => {
const message = JSON.parse(event.data);
if (message.type === 'quote') {
console.log('Quote update:', message);
}
};
ws.onerror = (error) => {
console.error('WebSocket error:', error);
};
ws.onclose = () => {
console.log('Connection closed');
};Next up
Error Codes