Streaming
Streaming
Real-Time Financial Data Streaming
Our WebSocket API provides real-time financial data streaming with low latency for supported datasets. This guide covers connection setup, subscription management, and data handling using the VNX Quote Dataset as an example.
Quick Start
Connect to our WebSocket feed using the WSS protocol:
wss://api.marketsignal.six-group.com/v1/data/CORE/SIX_1BBO/<ISIN>?token=<YOUR_TOKEN>
Connection Examples
Node.js Example
const WebSocket = require('ws');
// Connection configuration
const ISIN = ':ISIN';
const TOKEN = 'your_access_token_here';
const uri = `wss://api.marketsignal.six-group.com/v1/data/CORE/SIX_1BBO/${ISIN}?token=${TOKEN}`;
// Create WebSocket connection
const ws = new WebSocket(uri);
// Connection event handlers
ws.on('open', () => {
console.log('✅ WebSocket connected successfully');
console.log(`📡 Subscribed to: ${ISIN}`);
});
ws.on('message', (data) => {
try {
const message = JSON.parse(data.toString());
console.log('📊 Received data:', message);
// Handle different message types
if (message.status) {
console.log(`📋 Status: ${message.status}`);
}
} catch (error) {
console.error('❌ Error parsing message:', error);
}
});
ws.on('error', (error) => {
console.error('❌ WebSocket error:', error.toString());
});
ws.on('close', (code, reason) => {
console.log(`🔌 Connection closed - Code: ${code}, Reason: ${reason}`);
});
// Graceful shutdown
process.on('SIGINT', () => {
console.log('🛑 Shutting down...');
ws.close();
process.exit(0);
});
Python Example
import asyncio import websockets import json import signal import sys async def connect_websocket(): ISIN = 'ISIN' TOKEN = 'your_access_token_here' uri = f"wss://api.marketsignal.six-group.com/v1/data/CORE/SIX_1BBO/{ISIN}?token={TOKEN}" try: async with websockets.connect(uri) as websocket: print("✅ WebSocket connected successfully") print(f"📡 Subscribed to: {ISIN}") async for message in websocket: try: data = json.loads(message) print(f"📊 Received data: {data}") if 'status' in data: print(f"📋 Status: {data['status']}") except json.JSONDecodeError as e: print(f"❌ Error parsing message: {e}") except websockets.exceptions.ConnectionClosed as e: print(f"🔌 Connection closed: {e}") except Exception as e: print(f"❌ Connection error: {e}") # Run the connection if __name__ == "__main__": asyncio.run(connect_websocket())
Initial Connection Response
Upon successful connection, you'll receive a confirmation message:
{ "status": "subscribed", "symbols": ["ISIN"] }
Subscription Management
Adding ISINs
Send a subscribe message to add ISINs to your feed. This operation is additive - new ISINs are added to your existing subscription:
{ "subscribe": { "token": "your_access_token_here", "symbols": ["ISIN", "ISIN2", "ISIN3"] } }
Response:
{ "status": "subscribed", "symbols": ["ISIN", "ISIN2", "ISIN3"] }
Removing ISINs
To remove specific ISINs, send an unsubscribe message:
{ "unsubscribe": { "token": "your_access_token_here", "symbols": ["ISIN"] } }
Complete Disconnection
To disconnect from the server:
{ "unsubscribe": "disconnect" }
Subscription Status
To retrieve the current subscription status and the list of subscribed ISINs, use the following:
{ "subscription_status": {} }
Multiple ISINs Connections
Initial Connection with Multiple ISINs
Connect to multiple ISINs at once using comma-separated values:
wss://api.marketsignal.six-group.com/v1/data/CORE/VNX_QUOTE/CH0038863350,ES0113900J37,GB00BVZK7T90?token=<YOUR_TOKEN>
Subscribing to All Available ISINs
To access all ISINs available under your subscription, connect without specifying ISINs:
wss://api.marketsignal.six-group.com/v1/data/CORE/SIX_1BBO?token=<YOUR_TOKEN>
Or send an empty symbols array after connection:
{ "subscribe": { "token": "your_access_token_here", "symbols": [] } }
Error Handling
Common Error Scenarios
- Invalid Token
{ "error": "Invalid token" } - No access to dataset
{ "error": "No subscription to premium dataset: <Dataset name>" } - Unauthorized Symbol
{ "error": "Symbol(s) <ISINs list> not allowed for your subscription." }
Connection Timeout
WebSocket connections are limited to 1-hour sessions. If your application needs to receive updates for longer periods, you should implement a reconnection strategy to automatically re-establish the connection when it times out.
Reconnection Strategy Example
const WebSocket = require('ws');
class WebSocketClient {
constructor(uri, options = {}) {
this.uri = uri;
this.options = options;
this.reconnectAttempts = 0;
this.maxReconnectAttempts = options.maxReconnectAttempts || 5;
this.reconnectDelay = options.reconnectDelay || 1000;
this.connect();
}
connect() {
this.ws = new WebSocket(this.uri);
this.ws.on('open', () => {
console.log('✅ Connected to WebSocket');
this.reconnectAttempts = 0;
});
this.ws.on('close', () => {
console.log('🔌 Connection closed');
this.attemptReconnect();
});
this.ws.on('error', (error) => {
console.error('❌ WebSocket error:', error);
});
}
attemptReconnect() {
if (this.reconnectAttempts < this.maxReconnectAttempts) {
this.reconnectAttempts++;
console.log(`🔄 Attempting reconnection ${this.reconnectAttempts}/${this.maxReconnectAttempts}`);
setTimeout(() => {
this.connect();
}, this.reconnectDelay * this.reconnectAttempts);
} else {
console.error('❌ Max reconnection attempts reached');
}
}
}
// Usage
const client = new WebSocketClient(
'wss://api.marketsignal.six-group.com/v1/data/EDGE/1BBO/<ISIN>?token=your_token',
{ maxReconnectAttempts: 5, reconnectDelay: 1000 }
);
Best Practices
- Always handle connection errors and implement reconnection logic
- Validate incoming messages before processing
- Monitor connection status and implement heartbeat mechanisms
- Use appropriate error handling for different message types
- Implement graceful shutdown procedures
- Keep your access token secure and rotate regularly