WebSocket Protocol
Intotes provides three WebSocket endpoints for real-time data streaming. All use the standard WebSocket upgrade protocol.
Endpointsβ
| Endpoint | Purpose | Auth Required |
|---|---|---|
/api/v1/ws/trades | Live trades feed | No |
/api/v1/ws/events/{event_id}/chart | Live market price updates for an event | No |
/api/v1/ws/assets/{symbol}/price | Live crypto asset price updates | No |
Connectionβ
Connect using a standard WebSocket client:
const ws = new WebSocket('wss://intotes.com/api/v1/ws/trades');
ws.onopen = () => {
console.log('Connected to trades feed');
};
ws.onmessage = (event) => {
const data = JSON.parse(event.data);
console.log('New trade:', data);
};
ws.onclose = (event) => {
console.log('Disconnected:', event.code, event.reason);
};
Protocol Detailsβ
| Parameter | Value |
|---|---|
| Ping interval | 50 seconds (server sends ping) |
| Read deadline | 60 seconds (connection dropped if no pong) |
| Max message size (trades) | 512 bytes |
| Max message size (chart/asset) | 128 bytes |
| Max connections per hub | 10,000 |
The server sends WebSocket ping frames every 50 seconds. Clients must respond with pong frames (most WebSocket libraries handle this automatically). If no pong is received within 60 seconds, the connection is closed.
Initial Messageβ
Upon connection, the server sends an init message containing recent history:
Trades Feed Initβ
{
"type": "init",
"trades": [
{
"amount": 50000,
"name": "user123",
"token": "YES",
"event": "Will BTC hit $100k?",
"market": "Above $100k",
"avatar": "https://..."
}
]
}
Chart Feed Initβ
{
"type": "init",
"ratios": [
{"timestamp": "2024-01-15T10:00:00Z", "values": [0.65, 0.35]}
]
}
Message Typesβ
Trades Feedβ
New trade messages:
{
"type": "trade",
"trade": {
"amount": 50000,
"name": "user123",
"token": "YES",
"event": "Will BTC hit $100k?",
"market": "Above $100k",
"avatar": "https://..."
}
}
Chart Feedβ
Market probability updates:
{
"type": "chart_update",
"event_id": 42,
"ratios": [0.65, 0.35]
}
Asset Price Feedβ
Crypto price updates:
{
"type": "price_update",
"symbol": "BTCUSDT",
"price": 98500.50
}
Reconnectionβ
If the connection drops, implement reconnection with exponential backoff:
let reconnectDelay = 1000;
function connect() {
const ws = new WebSocket('wss://intotes.com/api/v1/ws/trades');
ws.onopen = () => {
reconnectDelay = 1000; // Reset on successful connect
};
ws.onclose = () => {
setTimeout(connect, reconnectDelay);
reconnectDelay = Math.min(reconnectDelay * 2, 30000);
};
ws.onmessage = (event) => {
handleMessage(JSON.parse(event.data));
};
}
connect();
Hubsβ
Internally, the server manages three separate WebSocket hubs:
| Hub | Scope | Message frequency |
|---|---|---|
| Trades | Global (all trades) | Per trade executed |
| Chart | Per event (event_id) | Per market price change |
| Asset Price | Per symbol (e.g., BTCUSDT) | Every few seconds |
Each hub maintains its own connection pool with independent limits.