Skip to main content

WebSocket Protocol

Intotes provides three WebSocket endpoints for real-time data streaming. All use the standard WebSocket upgrade protocol.

Endpoints​

EndpointPurposeAuth Required
/api/v1/ws/tradesLive trades feedNo
/api/v1/ws/events/{event_id}/chartLive market price updates for an eventNo
/api/v1/ws/assets/{symbol}/priceLive crypto asset price updatesNo

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​

ParameterValue
Ping interval50 seconds (server sends ping)
Read deadline60 seconds (connection dropped if no pong)
Max message size (trades)512 bytes
Max message size (chart/asset)128 bytes
Max connections per hub10,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:

HubScopeMessage frequency
TradesGlobal (all trades)Per trade executed
ChartPer event (event_id)Per market price change
Asset PricePer symbol (e.g., BTCUSDT)Every few seconds

Each hub maintains its own connection pool with independent limits.